* integration between Org, remember, and Mutt
@ 2009-10-31 17:12 Stefano Zacchiroli
2009-11-01 15:23 ` Friedrich Delgado Friedrichs
0 siblings, 1 reply; 6+ messages in thread
From: Stefano Zacchiroli @ 2009-10-31 17:12 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2682 bytes --]
Hi all,
I'm new to Org, but I fell in love with it quite quickly :-) As my
mail user agent has nothing to do with Emacs---it is Mutt---I was envy
to integrate it with Org, and I've actually done that.
With this mail, I'm wondering whether there were past/alternative
success stories about Mutt <-> Org integration (I've found nothing on
the Web).
Also, if you like the proposed way to integration, I'm looking forward
for advices on where to document it so that other people can take
inspiration (and avoid reinventing wheels, as I might have done).
Mutt <-> Org integration
------------------------
The link between Mutt and Org is the Message-ID of emails that I store
in a set of recursive Maildirs.
Those mails are indexed by mu (http://code.google.com/p/mu0/), an
alternative to mairix and nmzmail that I find more convenient. Just in
case you wonder, mail indexes are updated regularly with the following
cron entry (which takes just a few seconds, usually):
31 */2 * * * on_ac_power && mu-index -q
The attached script mutt-open is able to fire up Mutt on a message
specified by Message-ID (or path, FWIW) by looking it up via
mu-find. After finding the path, the script basically guesses the
corresponding Maildir, run mutt on it, and by sending some keys (via the
"push" command) open the given mail.
From Org-mode, I can then follow "mutt:" links by using the following in
my Emacs conf:
;; add support for "mutt:ID" links
(org-add-link-type "mutt" 'open-mail-in-mutt)
(defun open-mail-in-mutt (message)
"Open a mail message in Mutt, inside a terminal.
Message can be specified either by a path pointing inside a
Maildir, or by Message-ID."
(interactive "MPath or Message-ID: ")
(shell-command
(concat
(format "x-terminal-emulator -e \"%s %s\""
(substitute-in-file-name "$HOME/bin/mutt-open") message))))
Finally, I've a macro to remember in Org a mail that I'm reading in
mutt:
macro index \eR "|~/bin/remember-mail\n"
The corresponding script remember-mail is in attachment. It just
extracts from the piped mail the needed info to invoke Org protocol
appropriately via emacsclient. The corresponding remember template is
trivially as follows:
("Mail" ?m "* %?\n\n Source: %u, %c\n %i" nil "Note (mail)")
Any comment is welcome!
--
Stefano Zacchiroli -o- PhD in Computer Science \ PostDoc @ Univ. Paris 7
zack@{upsilon.cc,pps.jussieu.fr,debian.org} -<>- http://upsilon.cc/zack/
Dietro un grande uomo c'è ..| . |. Et ne m'en veux pas si je te tutoie
sempre uno zaino ...........| ..: |.... Je dis tu à tous ceux que j'aime
[-- Attachment #2: mutt-open --]
[-- Type: text/plain, Size: 2100 bytes --]
#!/bin/bash
#
# Fire up mutt on a given mail, located in some Maildir
# Mail can be specified either by path or by Messsage-ID; in the latter case
# file lookup is performed using some mail indexing tool.
#
# Copyright: © 2009 Stefano Zacchiroli <zack@upsilon.cc>
# License: GNU General Public License (GPL), version 3 or above
MUTT=mutt
MUTT_FLAGS="-R"
HIDE_SIDEBAR_CMD="B" # set to empty string if sidebar is not used
# Sample output of 'mu-find -f P i:MESSAGE-ID', which gets passed to mutt-open
# /home/zack/Maildir/INBOX/cur/1256673179_0.8700.usha,U=37420,FMD5=7e33429f656f1e6e9d79b29c3f82c57e:2,S
die_usage () {
echo "Usage: mutt-open FILE" 1>&2
echo " mutt-open MESSAGE-ID" 1>&2
echo 'E.g.: mutt-open `mu-find -f P m:MESSAGE-ID`' 1>&2
echo ' mutt-open 20091030112543.GA4230@usha.takhisis.invalid' 1>&2
exit 3
}
# Lookup: Message-ID -> mail path. Store results in global $fname
lookup_msgid () {
fname=$(mu-find --format P m:"$1" | head -n 1)
}
dump_info () {
echo "fname: $fname"
echo "msgid: $msgid"
}
if [ -z "$1" -o "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ] ; then
die_usage
fi
if (echo "$1" | grep -q /) && test -f "$1" ; then # arg is a file
fname="$1"
msgid=$(egrep -i '^message-id:' "$fname" | cut -f 2 -d':' | sed 's/[ <>]//g')
elif ! (echo "$1" | grep -q /) ; then # arg is a Message-ID
msgid="$1"
lookup_msgid "$msgid" # side-effect: set $fname
fi
# dump_info ; exit 3
if ! dirname "$fname" | egrep -q '/(cur|new|tmp)$' ; then
echo "Path not pointing inside a maildir: $fname" 1>&2
exit 2
fi
maildir=$(dirname $(dirname "$fname"))
if ! [ -d "$maildir" ] ; then
echo "Not a (mail)dir: $maildir" 1>&1
exit 2
fi
# UGLY HACK: without sleep, push keys do not reach mutt, I _guess_ that there
# might be some terminal-related issue here, since also waiting for an input
# with "read" similarly "solves" the problem
sleep 0.1
mutt_keys="$HIDE_SIDEBAR_CMD/~i$msgid\n\n"
exec $MUTT $MUTT_FLAGS -f "$maildir/" -e "push $mutt_keys"
[-- Attachment #3: remember-mail --]
[-- Type: text/plain, Size: 758 bytes --]
#!/usr/bin/perl -w
#
# Helper for mutt to remember mails in Emacs' Org mode
#
# Copyright: © 2009 Stefano Zacchiroli <zack@upsilon.cc>
# License: GNU General Public License (GPL), version 3 or above
#
# Example of mutt macro to invoke this hitting ESC-R (to be put in ~/.muttrc):
# macro index \eR "|~/bin/remember-mail\n"
use strict;
use Mail::Internet;
use URI::Escape;
my $msg = Mail::Internet->new(\*STDIN);
$msg->head->get('message-id') =~ /^<(.*)>$/;
my $mid = $1;
my $subject = $msg->head->get('subject') || "";
my $from = $msg->head->get('from') || "";
chomp ($subject, $from);
my $note_body = uri_escape(" Subject: $subject\n From: $from");
exec("emacsclient -c org-protocol:/remember:/m/mutt:$mid/mail/$note_body");
[-- Attachment #4: 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: integration between Org, remember, and Mutt
2009-10-31 17:12 integration between Org, remember, and Mutt Stefano Zacchiroli
@ 2009-11-01 15:23 ` Friedrich Delgado Friedrichs
2009-11-01 16:14 ` Stefano Zacchiroli
0 siblings, 1 reply; 6+ messages in thread
From: Friedrich Delgado Friedrichs @ 2009-11-01 15:23 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 896 bytes --]
Hi!
I use something similar, but I wasn't aware that adding link types to
org is that simple. Thanks! ;)
My scripts and snippets won't be very interesting I guess, since I've
resorted to store all my Emails in one single +Archive Folder (as
recommended by Merlin Mann), so it doesn't do any smart things like
guessing the right folders.
Stefano Zacchiroli schrieb:
> Those mails are indexed by mu (http://code.google.com/p/mu0/), an
> alternative to mairix and nmzmail that I find more convenient. Just in
> case you wonder, mail indexes are updated regularly with the following
> cron entry (which takes just a few seconds, usually):
This is off-topic, but mu strikes as quite similar to mairix. What do
you find more convenient about it?
--
Friedrich Delgado Friedrichs <friedel@nomaden.org>
TauPan on Ircnet and Freenode ;)
[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 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: integration between Org, remember, and Mutt
2009-11-01 15:23 ` Friedrich Delgado Friedrichs
@ 2009-11-01 16:14 ` Stefano Zacchiroli
2009-11-01 16:54 ` Friedrich Delgado Friedrichs
0 siblings, 1 reply; 6+ messages in thread
From: Stefano Zacchiroli @ 2009-11-01 16:14 UTC (permalink / raw)
To: emacs-orgmode
On Sun, Nov 01, 2009 at 04:23:35PM +0100, Friedrich Delgado Friedrichs wrote:
> I use something similar, but I wasn't aware that adding link types to
> org is that simple. Thanks! ;)
You're more than welcome.
Since we are at least 2 needing this kind of stuff :-) , if you have any
suggestion about where to document this let me know. I'll blog about it
in the next few days, but having it somewhere Org-mode-related (maybe
Word?) would be probably better.
> Stefano Zacchiroli schrieb:
> > Those mails are indexed by mu (http://code.google.com/p/mu0/), an
> > alternative to mairix and nmzmail that I find more convenient. Just in
> > case you wonder, mail indexes are updated regularly with the following
> > cron entry (which takes just a few seconds, usually):
>
> This is off-topic, but mu strikes as quite similar to mairix. What do
> you find more convenient about it?
Given that would be off-topic, I'll just give you a pointer to a blog
post of mine where I've recently explained my choice (considering
nmzmail as well):
http://upsilon.cc/~zack/blog/posts/2009/10/mail_indexing_for_mutt/
Cheers.
--
Stefano Zacchiroli -o- PhD in Computer Science \ PostDoc @ Univ. Paris 7
zack@{upsilon.cc,pps.jussieu.fr,debian.org} -<>- http://upsilon.cc/zack/
Dietro un grande uomo c'è ..| . |. Et ne m'en veux pas si je te tutoie
sempre uno zaino ...........| ..: |.... Je dis tu à tous ceux que j'aime
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: integration between Org, remember, and Mutt
2009-11-01 16:14 ` Stefano Zacchiroli
@ 2009-11-01 16:54 ` Friedrich Delgado Friedrichs
2009-11-01 17:41 ` Stefano Zacchiroli
0 siblings, 1 reply; 6+ messages in thread
From: Friedrich Delgado Friedrichs @ 2009-11-01 16:54 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 1008 bytes --]
Stefano Zacchiroli schrieb:
> On Sun, Nov 01, 2009 at 04:23:35PM +0100, Friedrich Delgado Friedrichs wrote:
> > I use something similar, but I wasn't aware that adding link types to
> > org is that simple. Thanks! ;)
> You're more than welcome.
> Since we are at least 2 needing this kind of stuff :-) , if you have any
> suggestion about where to document this let me know. I'll blog about it
> in the next few days, but having it somewhere Org-mode-related (maybe
> Word?) would be probably better.
---Zitatende---
I think if and when we or one of us finds a good and scalable
solution, Worg would be the appropriate place.
But this is an unfinished project for me and for the moment just
keeping track of some mail threads and pointers is sufficient. I don't
feel the need to perfect this at the moment, as my current hack works
sufficiently well for me.
--
Friedrich Delgado Friedrichs <friedel@nomaden.org>
TauPan on Ircnet and Freenode ;)
[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 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: integration between Org, remember, and Mutt
2009-11-01 16:54 ` Friedrich Delgado Friedrichs
@ 2009-11-01 17:41 ` Stefano Zacchiroli
2009-11-11 18:53 ` Friedrich Delgado Friedrichs
0 siblings, 1 reply; 6+ messages in thread
From: Stefano Zacchiroli @ 2009-11-01 17:41 UTC (permalink / raw)
To: emacs-orgmode
On Sun, Nov 01, 2009 at 05:54:30PM +0100, Friedrich Delgado Friedrichs wrote:
> I think if and when we or one of us finds a good and scalable
> solution, Worg would be the appropriate place.
>
> But this is an unfinished project for me and for the moment just
> keeping track of some mail threads and pointers is sufficient. I don't
> feel the need to perfect this at the moment, as my current hack works
> sufficiently well for me.
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 ...
Cheers.
--
Stefano Zacchiroli -o- PhD in Computer Science \ PostDoc @ Univ. Paris 7
zack@{upsilon.cc,pps.jussieu.fr,debian.org} -<>- http://upsilon.cc/zack/
Dietro un grande uomo c'è ..| . |. Et ne m'en veux pas si je te tutoie
sempre uno zaino ...........| ..: |.... Je dis tu à tous ceux que j'aime
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: integration between Org, remember, and Mutt
2009-11-01 17:41 ` Stefano Zacchiroli
@ 2009-11-11 18:53 ` Friedrich Delgado Friedrichs
0 siblings, 0 replies; 6+ messages in thread
From: Friedrich Delgado Friedrichs @ 2009-11-11 18:53 UTC (permalink / raw)
To: emacs-orgmode
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 <friedel@nomaden.org>
TauPan on Ircnet and Freenode ;)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-11-11 18:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-31 17:12 integration between Org, remember, and Mutt Stefano Zacchiroli
2009-11-01 15:23 ` Friedrich Delgado Friedrichs
2009-11-01 16:14 ` Stefano Zacchiroli
2009-11-01 16:54 ` Friedrich Delgado Friedrichs
2009-11-01 17:41 ` Stefano Zacchiroli
2009-11-11 18:53 ` Friedrich Delgado Friedrichs
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.