Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the value of the Message ID header of a particular message in my mutt's inbox and I want to open it with a one shot mutt command, read and close.

Currently, I open mutt, do a with ~i <the-message-id>, which lists just one message, and then open it with o (My keybinding to open a message).

Is there a way I can create a shell function/script to enable a usage like

mutt-open-message <the-message-id>

and the message opens up in mutt? I tried playing around with the -e option of mutt but couldn't get this functionality working.

Any ideas on this?

share|improve this question
Do I understand you correctly that mutt-open-message should just output the message and directly return without any user interaction? Or do you want to remote control and already running mutt instance? – maxschlepzig Oct 5 '11 at 8:28
@maxschlepzig, you understand correct. I only need to read the message, whether it be by opening mutt or less or vim whatever pager. Not controlling an already running mutt instance. – Shrikant Sharat Oct 5 '11 at 9:21
up vote 3 down vote accepted

Not the prettiest solution but this seems to work (using mutt 1.5.20), with a message ID taken from my inbox in $MSGID:

mutt -e "macro index - 'l~i${MSGID}'; push -\n"

If you already use the '-' key for something in the index choose a different key instead.

share|improve this answer
Slightly modified, to open the message directly: mutt -e "macro index - 'l~i${MSGID}'; push -\no". Ofcourse one would use \n in place of the o to open the message. – Shrikant Sharat Oct 5 '11 at 9:28
Ha! Thanks for this answer, I came to know about push. A macro isn't really needed actually. Just mutt -e "push l~i${MSGID}\no" works just fine – Shrikant Sharat Oct 5 '11 at 10:10
@ShrikantSharat this gives me the prompt of how to sort. Do I need to change folders to "All mail" first? How do I do that with the command? – Xu Wang Apr 9 '15 at 7:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.