How to program Mutt to take an action upon new email arriving?
Asked Answered
B

2

6

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.

Bemock answered 1/10, 2014 at 11:16 Comment(8)
Sounds painful compared to Procmail or some sort of biff notifier. Do you specifically require Mutt to be the driver?Thorbert
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.Bemock
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.Thorbert
See dev.mutt.org/trac/wiki/MuttFaq/Misc and look for "How to trigger a script on new mail?"Remarque
@glenn Why this is as a comment?Bemock
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.Remarque
@glenn please check the question edit.Bemock
edit 2 should really be an answer.Ledger
P
3

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

NeoMutt can: see it's new_mail_command.

Phrasal answered 25/8, 2017 at 8:50 Comment(0)
O
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

Ochone answered 29/7, 2022 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.