Re: Loading a notmuch email buffer in Emacs from the command line

Subject: Re: Loading a notmuch email buffer in Emacs from the command line

Date: Wed, 24 Feb 2016 22:51:45 +0530



From: Suvayu Ali

On Sat, Feb 20, 2016 at 12:16:33PM +0200, Tomi Ollila wrote:
> On Sat, Feb 20 2016, Neeum Zawan <> wrote:
> >
> > Is there a way (e.g. with emacsclient) to load up a particular email
> > thread or email message buffer from the command line?
> quick test yields that at least
>   emacs -f notmuch --eval '(notmuch-search "")'
> works (maybe not exactly as desired, but based on that more should
> be able to be achieved with moderate ease...)

I use the attached script to open the mail I'm reading in Mutt in Emacs
so that I can link to it in my Org mode notes, etc.  You could write a
function that calls the required capture templates and use it in place
of the call to notmuch-show.  Probably you also want to remove the GNU
Screen related stuff (call to screen select and the check for $STY).

Hope this helps,


Open source is the future. It sets us free.

# set -o xtrace

# FIXME: handle cases when not invoked from within screen
declare -a emacsen=(/tmp/emacs$UID/*) screens=(/var/run/screen/S-$USER/*)
# NOTE: look at screen -Q for querying

# FIXME: cleaner way of switching to threads (something like mutt-search)
declare thread=$1

[[ -n $STY ]] && { \
    screen -X select nwc;	# emacsclient window name for me

    # NB: reading from PIPE; and it's ok to remove all <, >, or
    # spaces, they are not allowed in a Message-ID
    msgid=$(formail -c -x Message-ID | sed -e 's/[<> ]//g')
    if [[ -n $thread ]]; then
	query=$(notmuch search --output=threads -- "id:$msgid")
	emacsclient --eval "(notmuch-tree \"$query\")"
	emacsclient --eval "(notmuch-show \"$query\")"