Default save mailbox from a script

Jon LaBadie mutter at jgcomp.com
Mon Jul 31 06:42:57 UTC 2023


On Sun, Jul 30, 2023 at 03:59:57PM +0200, Nicolas George wrote:
>Hi.
>
>I want to use an external command to decide in what mailbox to save
>messages.
>
>When I hit ‘s’ with its default action of save-message, mutt asks
>“Save to mailbox ('?' for list): =ml/debian”, with the default being
>chosen from save-hooks or from the author of the mail.
>
>What I want is that it invokes an external command to set the default.
>The idea is that the external command has access to an index of my
>mailboxes and implements heuristics of my choosing to store the mail,
>but I can still use Mutt's user interface to make a different decision.
>
>What I want could look a little bit like:
>
>save-hook * `~/local/lib/guess_mailbox`
>
>Except it does not work in two ways:
>
>- the backticks are evaluated once when loading the configuration, they
>  need to be evaluated when saving the message, each time;
>
>- the command in the backticks need access to the content of the mail.
>
>I am considering a solution based on a macro that pipes the message to
>the command and generate a temporary configuration file, then sources it
>then saves normally.
>
>Also, I would like to avoid any solution that would slow down Mutt when
>I am not trying to save a message. A message-hook invoking guess_mailbox
>would probably not be acceptable, for example.
>
>Any advice?

An alternative approach that I'm not sure is possible.

If during delivery of your mail it is passes through
a filter like "procmail" before hitting your Inbox,
have the filter invoke your hueristics program "guess".
Guess could use something like "formail" to add a header

  X-guess: <suggested-save-folder>

This would move the slow aspect to before you read the
message.

The save "s" command could then be macro'ed to: 
  - if no X-guess header invoke regular <save> cmd
  - if X-guess header present extract suggested folder
    and save there

jl

-- 
Jon H. LaBadie                 jon at labadie.us
  154 Milkweed Dr                 (540) 868-8052 (H)
  Lake Frederick, VA 22630        (703) 935-6720 (M)



More information about the Mutt-users mailing list