5

There is an option beep_new in the Mutt's configuration variables, which causes Mutt to issue a beep when new email arrives. Also there is <shell_esc> command, which executes a command in internal shell. Is there a way to cause Mutt to execute some user defined action (shell command) when new email arrives? Maybe <pipe-message> can help? (One can use <pipe-message> in a configuration file to call a shell command. Is there a way to do this in running Mutt?)

EDIT: as per Glenn advice, a script from Mutt can be called by configuring the custom status format in the .muttrc file:

set status_format="/some/script.sh '%r %f (%L) |"

But I can't figure out how to use this for new email detection, since the "New mail in..." notification appears on the command line, and not in the status line. And if the email arrived to a mailbox that is not the current, then the status line doesn't change at all.

EDIT 2: OK, the %b variable in the status_format did the thing.

Al Berger
  • 1,048
  • 14
  • 35
  • 3
    Sounds painful compared to Procmail or some sort of `biff` notifier. Do you specifically require Mutt to be the driver? – tripleee Oct 01 '14 at 11:25
  • Isn't running a separate program for such a simple task more cumbersome? Especially if calling a command from Mutt can actually be performed with a simple instruction. – Al Berger Oct 01 '14 at 12:56
  • Your question sounds like "how do I make the computer play *'You've got mail'*" but if you want something radically different, maybe elaborate your question. If you are always running Mutt and you can figure out a way for it to interact with incoming email without messing up its interaction with you, by all means feel free to pursue that attack angle. – tripleee Oct 01 '14 at 13:14
  • 1
    See http://dev.mutt.org/trac/wiki/MuttFaq/Misc and look for "How to trigger a script on new mail?" – glenn jackman Oct 01 '14 at 18:48
  • @glenn Why this is as a comment? – Al Berger Oct 02 '14 at 00:19
  • 2
    Because it's just a link. If you take it as an answer, my advice is to document the steps you took, contribute an answer to your own question and accept it. That's the best way to help others. – glenn jackman Oct 02 '14 at 00:51
  • @glenn please check the question edit. – Al Berger Oct 02 '14 at 05:46
  • edit 2 should really be an answer. – isedev Oct 02 '14 at 08:25

2 Answers2

3

Mutt can't do this (at least not without some workaround).

NeoMutt can: see it's new_mail_command.

ideasman42
  • 42,413
  • 44
  • 197
  • 320
0

You can achieve that through inotifywait as the mutt manual suggests.

  1. Install inotify
    (example for Debian based distros: apt install inotify-tools)

  2. Watch mutt folder and run your script
    (bash script example:

while : ; do inotifywait -e modify -r ~/.mutt ; /my_facy/script ; done

desgua
  • 182
  • 1
  • 7