5

I am subscribed to a mailing list that does not identify itself in the subject of mails sent via the list.
I would like to have list mail delivered to my main inbox, but still be able to identify them as arriving from the list at first glance.

My MTA (Dovecot) supports Sieve filters with most of the usual extensions.

How can I prepend a "[Foo-List]" tag to mails from this list?

1 Answer 1

7

It seems there is no standardised way to directly prepend or append a string to a message's Subject header, but there is a workaround using the editheaders and variables extensions:

require "editheader";
require "variables";

# Match/select your message as you see fit
if header :contains "List-Id" ["<foo.lists.example.net>"]
{
    # Match the entire subject ...
    if header :matches "Subject" "*" {
        # ... to get it in a match group that can then be stored in a variable:
        set "subject" "${1}";
    }

    # We can't "replace" a header, but we can delete (all instances of) it and
    # re-add (a single instance of) it:
    deleteheader "Subject";
    # Append/prepend as you see fit
    addheader :last "Subject" "[Foo-List] ${subject}";
    # Note that the header is added ":last" (so it won't appear before possible
    # "Received" headers).
}
1
  • 1
    Perfect, thanks. AFAIK, the Sieve editheader RFC simply doesn't allow for any other way (tools.ietf.org/html/rfc5293). So this is the best we get, it seems.
    – Phil
    Jun 23, 2020 at 20:36

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.