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?

  • 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

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.

| 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
  • 1
    @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
  • Using o I also get the sort prompt. For me the following command opens the message: mutt -e "push l~i${MSGID}\n<enter>" – nyi Aug 11 '18 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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