emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] integration between Org, remember, and Mutt


From: Friedrich Delgado Friedrichs
Subject: Re: [Orgmode] integration between Org, remember, and Mutt
Date: Wed, 11 Nov 2009 19:53:12 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

Hi, again!

Ok, today I took some time to reconsider my integration of mutt with
org-mode.

One move was to put my archive of private mail onto an imap server
(with regular mirrors to my local harddisk via rsync, in case the
network breaks down), and the relevant steps in my mutt configuration.

The other side of this is that I simplified my mail links with the
'mutt:' link type.

This is what I use (you probably won't like this, but it serves to
illustrate my approach).

In mutt, I use the following keys:

,----
# Save EVERYTHING in +Archive, thanks Merlin Mann! :)
save-hook . +Archive

set my_pipe_decode=$pipe_decode;
set my_wait_key=$wait_key;
macro index,pager <f9>r "<enter-command>set pipe_decode=no;set 
wait_key=no<enter><pipe-message>mutt2remember.pl remember 
+Archive<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 store-link 
+Archive<enter><enter-command>set wait_key=\$my_wait_key ;set 
pipe_decode=\$my_pipe_decode<enter>" "copy url to mail in emacs";
# How do I search for message with same Message-ID in another folder? That 
would be handy for the following macro:
macro index,pager <f9>a "<change-folder>+Archive<enter>"
`----

I used to have a more complicated setup, which also figured out the
current folder with some clever hooks and lots of trickery, however
this was annoying, since I had to
 - save the mail
 - go to the new folder, find that mail again
 - then press my hotkey

This way (with just a single archive folder) I can just press <fn>n
and then save the mail, and I don't have to find the mail again, just
to get the proper link.

It seems like this isn't fully scriptable in mutt, at least I didn't
manage to come up with a macro that does all of the following in one
go:

 - save mail to folder, allowing the user to specify any folder
 - then somehow save the name of *that* folder and use it to generate
   the link for emacs

Then I have a perl script mutt2remember.pl which handles both
directions, adapted from a proposal by Russell Adams:
,----[ mutt2remember.pl ]
#!/usr/bin/perl

# $Id: mutt2remember.pl,v 1.5 2008/09/27 11:25:41 friedel Exp friedel $

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

$ENV{TMPDIR} = $ENV{TMP};

# 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 store-link 
\$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-protocol.el is loaded in your org config

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

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

use strict;
use warnings;

use URI::Escape qw/ uri_escape uri_escape_utf8 /;
use File::Temp qw/ mkstemp /;
use Encode qw/encode decode/;

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

if ($action eq "remember" or $action eq "store-link") {

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

  while (<STDIN>) {

    chomp;

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

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

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

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


  $From = uri_escape_utf8(decode('MIME-Header', $From));
  $Subject = uri_escape_utf8(decode('MIME-Header', $Subject));

  $folder =~ tr/=/+/;

  my $uri = "mutt:"
    . $folder
      . " "
        . $MID;

  $uri = uri_escape_utf8($uri);

  my $Link = "org-protocol://" . $action . "://" . $uri . "/Mail From $From: 
$Subject";
  system ("emacsclient", $Link);
} 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;

}
`----

And finally the relevant parts of my org-mode config (thanks to you):
,----
(defcustom org-mutt-link-terminal-emulator "xterm -e"
  "Terminal emulator to use for opening running mutt"
    :group 'org-config
    :type 'string)

(org-add-link-type "mutt" 'open-mail-in-mutt)

(defun open-mail-in-mutt (folder+message-id)
  (message folder+message-id)
  (save-window-excursion
    (save-excursion
      (shell-command
       (concat
        (format "%s mutt2remember.pl open %s &"
                org-mutt-link-terminal-emulator
                folder+message-id))))))
`----

I think you will find this lacking since it doesn't support searching,
but only links to specific mails in specific folders, which are
hardwired.

It's good enough for me, and I think I won't need to improve this for
the next few years now! ;)

Maybe this gives you an idea.

Stefano Zacchiroli schrieb:
> Fair enough.
> However, to go forward, we need to establish some kind of goal.
> 
> In particular, what do you consider lacking in the solution I proposed?
> Similarly, what your solution has that mine lacks? I believe it is time
> to find a merger between the various available solutions ...
---Zitatende---

-- 
        Friedrich Delgado Friedrichs <address@hidden>
                             TauPan on Ircnet and Freenode ;)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]