emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Mairix & Mutt
@ 2008-09-21  4:58 Russell Adams
  2008-09-21  8:24 ` [AvataR]
  2008-09-27 11:18 ` Friedrich Delgado Friedrichs
  0 siblings, 2 replies; 6+ messages in thread
From: Russell Adams @ 2008-09-21  4:58 UTC (permalink / raw)
  To: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 1074 bytes --]

Tonight I cobbled together a quick hack to let me store links from an
external mutt session directly into Org as a link via paste from the X
windows paste buffer.

I thought I would share. Documentation is in the comment header of the
script.

The workflow goes like this:

 - Reading email in Mutt, in index or pager
 - Trigger script via M-o in Mutt
 - Middle-click into my org-mode buffer pasting the link
 - Later visit the link and execute mairix to find message by ID
 - In current Mutt session, use M-` to jump to search folder and read
   message
   
Attached is the perl script which generates the link and populates the
paste buffer via xclip. It occurred to me I might be able to use
org-mairix.el and use a mairix style link instead of an exec, but this
suffices for the time being.

Enjoy!

------------------------------------------------------------------
Russell Adams                            RLAdams@AdamsInfoServ.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3

[-- Attachment #2: mutt2org.pl --]
[-- Type: text/x-perl, Size: 1945 bytes --]

#!/usr/bin/perl

######################################################################
# mutt2org.pl
#
# Read an email on STDIN and fetch headers to create an org-mode
# link which executes mairix to find the correct message.
#
# Later when the link is visited, mairix will find the message by id.
# Then the user can goto their search folder in mutt to view it.
#
# Licensed GPL v2: Russell Adams <rladams@adamsinfoserv.com>
#
# The following are excerpts from .muttrc to speed up mairix related
# activities.
#
# Given that the mairix folder is "=._Search/", the following allows
# M-` to jump directly to the search folder.
#
# ~/.muttrc:
# # Quick access to mairix search folder
# macro pager \e\` "<change-folder>=._Search/\n"
# macro index \e\` "<change-folder>=._Search/\n"
#
# Bind M-o to this perl script without pause in the index and pager
# allowing for quick paste into Org.
#
# ~/.muttrc:
# macro index \eo "\
# <enter-command>unset wait_key\n\
# <pipe-entry>~/.dotfiles/mutt/mutt2org.pl\n\
# <enter-command>set wait_key\n\
# " "Create Org link in X clipboard"
#
# macro pager \eo "\
# <enter-command>unset wait_key\n\
# <pipe-entry>~/.dotfiles/mutt/mutt2org.pl\n\
# <enter-command>set wait_key\n\
# " "Create Org link in X clipboard"
#
######################################################################


use strict;
use warnings;
use 5.010;


my ( $Subject , $From , $MID );

while (<STDIN>) {

	chomp;

	given ($_) {

		when (/^Subject: /)       { ( $Subject ) = $_ =~ m/^Subject: (.*)$/; };
		when (/^From: /)          { ( $From ) = $_ =~ m/^From: (.*)$/; };
		when (/^Message-ID:\s*/)  { ( $MID ) = $_ =~ m/^Message-ID:\s*<(.*)>\s*$/; };
		when (/^$/)               { break; }; # Header ends on first blank line

	}

};

# Compose link
my $Link = "[[shell:mairix \"m:$MID\"][$From / $Subject]]";

# Output to xclip, avoiding shell escape headaches with exec.
open(PIPE, "|/usr/bin/xclip");
say PIPE "$Link";
close(PIPE);

[-- Attachment #3: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Mairix & Mutt
  2008-09-21  4:58 Mairix & Mutt Russell Adams
@ 2008-09-21  8:24 ` [AvataR]
  2008-09-21 14:22   ` Russell Adams
  2008-09-27 11:18 ` Friedrich Delgado Friedrichs
  1 sibling, 1 reply; 6+ messages in thread
From: [AvataR] @ 2008-09-21  8:24 UTC (permalink / raw)
  To: Org Mode List

Hi list!

Is there any way to make visual (OSD/whatelse) notifications about
upcoming events present in my .org lists? 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Mairix & Mutt
  2008-09-21  8:24 ` [AvataR]
@ 2008-09-21 14:22   ` Russell Adams
  0 siblings, 0 replies; 6+ messages in thread
From: Russell Adams @ 2008-09-21 14:22 UTC (permalink / raw)
  To: emacs-orgmode

On Sun, Sep 21, 2008 at 11:24:27AM +0300, [AvataR] wrote:
> Hi list!
> 
> Is there any way to make visual (OSD/whatelse) notifications about
> upcoming events present in my .org lists? 

See this thread:

http://www.mail-archive.com/emacs-orgmode@gnu.org/msg05634.html




------------------------------------------------------------------
Russell Adams                            RLAdams@AdamsInfoServ.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Mairix & Mutt
  2008-09-21  4:58 Mairix & Mutt Russell Adams
  2008-09-21  8:24 ` [AvataR]
@ 2008-09-27 11:18 ` Friedrich Delgado Friedrichs
  2008-09-27 12:16   ` Russell Adams
  1 sibling, 1 reply; 6+ messages in thread
From: Friedrich Delgado Friedrichs @ 2008-09-27 11:18 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1.1: Type: text/plain, Size: 2607 bytes --]

Hi!

I was thinking about how to interface mutt and org-mode for quite some
time now but didn't really get around to it.

I've tried to use many emacs MUAs for this purpose (mh-e, wanderlust,
mew and finally the great scary GNUs) but they're not quite to my
taste.

Your proposal gave me the necessary hacktivation energy to come up
with my version of this prototype. I also borrowed some of your code,
but backported it to perl 5.8.

Russell Adams schrieb:
> The workflow goes like this:
>
>  - Reading email in Mutt, in index or pager
>  - Trigger script via M-o in Mutt
>  - Middle-click into my org-mode buffer pasting the link
>  - Later visit the link and execute mairix to find message by ID
>  - In current Mutt session, use M-` to jump to search folder and read
>    message
---Zitatende---

Those are a few steps too many for me. I wanted to press <f9>t in the
index or pager and then pop up an emacs window with remember.

As org-annotation-helper.el does this already, I decided to use it.

Also mutt is able to search its own mailboxes, not as flexible as
mairix, because it can only search a single folder, but I only really
want to link back to a certain mail for now.

I also had a long conversation with pdmef on channel #mutt on
freenode.net, who gave me the two crucial ideas how to configure this
in mutt.

The main idea is to use the path-type variable record to get the name
of the current folder and store it in the two keyboard macros. The
keyboard macros change every time you change a folder in mutt.

This is a rough prototype still. I'd like to get rid of the (y/n)
prompt and therefore I'd like to have a link-type "mutt:" in org,
which means some of the functionality of the perl-script would have to
get implemented in emacs-lisp. But that would give me the benefit of a
customisable terminal and maybe get everything a bit less hairy...

You'll notice that calling mutt with a mail is not very straight
forward. In theory,

mutt -f $mailbox -e "push <search>~i$msgid<enter><display-message>"

should be sufficient. However if it's started via xterm -e, the
keystrokes don't arrive, maybe because xterm does some terminal
initialisations after mutt has started (or my window manager sends a
resize signal a bit too late, something like that). That's why I'm
writing the keystrokes to a temporary file. Not elegant, but does the
job.

Maybe we get the next guy inspired to hack on this now :)

-- 
        Friedrich Delgado Friedrichs <friedel@nomaden.org>
Laziness led to the invention of the most useful tools.

[-- Attachment #1.1.2: mutt2remember.pl --]
[-- Type: text/x-perl, Size: 2626 bytes --]

#!/usr/bin/perl

# $Id: mutt2remember.pl,v 1.4 2008/09/27 11:15:04 friedel Exp $

# Variations on a theme given by Russell Adams http://lists.gnu.org/archive/html/emacs-orgmode/2008-09/msg00300.html

my $terminal="xterm -e";

# Install:
# ========

# 1.) put the following in your muttrc:

my $muttrc_snippet = <<END;
folder-hook . " \
set my_record=\$record; \
set my_pipe_decode=\$pipe_decode; \
set my_wait_key=\$wait_key; \
set record=^; \
macro index,pager <f9>t \"<enter-command>set pipe_decode=no;set wait_key=no<enter><pipe-message>mutt2remember.pl remember \$record<enter><enter-command>set wait_key=\$my_wait_key ;set pipe_decode=\$my_pipe_decode<enter>\" \"remember mail in emacs\"; \
macro index,pager <f9>n \"<enter-command>set pipe_decode=no;set wait_key=no<enter><pipe-message>mutt2remember.pl annotation \$record<enter><enter-command>set wait_key=\$my_wait_key ;set pipe_decode=\$my_pipe_decode<enter>\" \"copy url to mail in emacs\"; \
set record=\$my_record;"
END

# 2) put this file into your $HOME/bin and make it executable.

# 3) make sure org-annotation-helper.el is loaded in your org config

# 4) optionally: set $terminal above to something you prefer.

# 5) press <f9>n in the pager or index to annotate a mail url,
#    press <f9>t to *remember* it

# 6) follow the generated link in emacs to open the mail in mutt.

use strict;
use warnings;

use URI::Escape qw/ uri_escape /;
use File::Temp qw/ mkstemp /;


my $action=$ARGV[0];
my $folder=$ARGV[1];

if ($action eq "remember" or $action eq "annotation") {

  my ( $Subject , $From , $MID );

  while (<STDIN>) {

    chomp;

    if (/^Subject: /) {
      ( $Subject ) = $_ =~ m/^Subject: (.*)$/;
    }

    if (/^From: /) {
      ( $From ) = $_ =~ m/^From: (.*)$/;
    }

    if (/^Message-ID:\s*/) {
      ( $MID ) = $_ =~ m/^Message-ID:\s*<(.*)>\s*$/;
    }

    if (/^$/) {
      last; # Header ends on first blank line
    }
  }


  $From = uri_escape($From);
  $Subject = uri_escape($Subject);

  $folder =~ tr/=/+/;

  my $uri = "shell:"
    . $terminal
      . " mutt2remember.pl open "
        . $folder
          . " "
            . $MID;

  $uri = uri_escape($uri);

  my $Link = $action . ":" . $uri . "::remember::Mail From $From: $Subject";

  system ("emacsclient", "--eval", "(progn (bzg/org-annotation-helper \"$Link\") nil)");
} elsif ($action eq "open") {
  my $msgid=$ARGV[2];
  my ($tmp, $tmpfile) = mkstemp(($ENV{TMP} or "/tmp") . "/mutt2rememberXXXXXXXX");

  printf $tmp "push \"<search>~i$msgid<enter><display-message>\"";
  system("mutt", "-f", $folder, "-e", "source $tmpfile");

  close $tmp;

  unlink $tmpfile;

}



[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Mairix & Mutt
  2008-09-27 11:18 ` Friedrich Delgado Friedrichs
@ 2008-09-27 12:16   ` Russell Adams
  2008-09-27 13:02     ` Friedrich Delgado Friedrichs
  0 siblings, 1 reply; 6+ messages in thread
From: Russell Adams @ 2008-09-27 12:16 UTC (permalink / raw)
  To: emacs-orgmode

On Sat, Sep 27, 2008 at 01:18:17PM +0200, Friedrich Delgado Friedrichs wrote:
> Hi!
> 
> I was thinking about how to interface mutt and org-mode for quite some
> time now but didn't really get around to it.
> 
> I've tried to use many emacs MUAs for this purpose (mh-e, wanderlust,
> mew and finally the great scary GNUs) but they're not quite to my
> taste.

Mutt is my preferred client as well.

> Your proposal gave me the necessary hacktivation energy to come up
> with my version of this prototype. I also borrowed some of your code,
> but backported it to perl 5.8.

Hacker twin powers activate!

> 
> Russell Adams schrieb:
> > The workflow goes like this:
> >
> >  - Reading email in Mutt, in index or pager
> >  - Trigger script via M-o in Mutt
> >  - Middle-click into my org-mode buffer pasting the link
> >  - Later visit the link and execute mairix to find message by ID
> >  - In current Mutt session, use M-` to jump to search folder and read
> >    message
> ---Zitatende---
> 
> Those are a few steps too many for me. I wanted to press <f9>t in the
> index or pager and then pop up an emacs window with remember.

I typically have mutt & emacs/org open at the same time in separate
windows. I don't do "popup" anything. ;]

> As org-annotation-helper.el does this already, I decided to use it.
> 
> Also mutt is able to search its own mailboxes, not as flexible as
> mairix, because it can only search a single folder, but I only really
> want to link back to a certain mail for now.

I use Maildir style directories and a lovely script which
auto-archives anything older than 2 weeks that isn't flagged.

Due to the automated movement, search via mairix is a must for me.

> I also had a long conversation with pdmef on channel #mutt on
> freenode.net, who gave me the two crucial ideas how to configure this
> in mutt.
> 
> The main idea is to use the path-type variable record to get the name
> of the current folder and store it in the two keyboard macros. The
> keyboard macros change every time you change a folder in mutt.
> 
> This is a rough prototype still. I'd like to get rid of the (y/n)
> prompt and therefore I'd like to have a link-type "mutt:" in org,
> which means some of the functionality of the perl-script would have to
> get implemented in emacs-lisp. But that would give me the benefit of a
> customisable terminal and maybe get everything a bit less hairy...
> 
> You'll notice that calling mutt with a mail is not very straight
> forward. In theory,
> 
> mutt -f $mailbox -e "push <search>~i$msgid<enter><display-message>"
> 
> should be sufficient. However if it's started via xterm -e, the
> keystrokes don't arrive, maybe because xterm does some terminal
> initialisations after mutt has started (or my window manager sends a
> resize signal a bit too late, something like that). That's why I'm
> writing the keystrokes to a temporary file. Not elegant, but does the
> job.
> 

Thats why my workflow just had mairix update the search folder, and
since Mutt was already open I just press a key to jump to my search folder.

Glad to see you're able to adapt it to your needs.


------------------------------------------------------------------
Russell Adams                            RLAdams@AdamsInfoServ.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Mairix & Mutt
  2008-09-27 12:16   ` Russell Adams
@ 2008-09-27 13:02     ` Friedrich Delgado Friedrichs
  0 siblings, 0 replies; 6+ messages in thread
From: Friedrich Delgado Friedrichs @ 2008-09-27 13:02 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1062 bytes --]

Hiho!

Russell Adams schrieb:
> Hacker twin powers activate!

;-)

> I typically have mutt & emacs/org open at the same time in separate
> windows. I don't do "popup" anything. ;]

Well I simplified a bit, my emacs doesn't really pop up or anything,
just quietly opens a remember buffer.

> I use Maildir style directories and a lovely script which
> auto-archives anything older than 2 weeks that isn't flagged.

> Due to the automated movement, search via mairix is a must for me.

Yes, my guess was that your requirements were a bit different than
mine.

I start + close mutt several times a day, but emacs is running all the
time. I usually move mail out of my inbox completely and then it stays
in a subfolder forever, etc.

I think if this ever (!) mutates into org-mutt.el one day, we'd have
to take care to take such preferences into account, i.e. whether to
use mairix or not.

Kind regards
     FDF
-- 
        Friedrich Delgado Friedrichs <friedel@nomaden.org>
Laziness led to the invention of the most useful tools.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-09-27 13:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-21  4:58 Mairix & Mutt Russell Adams
2008-09-21  8:24 ` [AvataR]
2008-09-21 14:22   ` Russell Adams
2008-09-27 11:18 ` Friedrich Delgado Friedrichs
2008-09-27 12:16   ` Russell Adams
2008-09-27 13:02     ` Friedrich Delgado Friedrichs

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).