I want to change subject for all subscription list emails by adding [BULK] to its.
Looks like global /etc/procmailrc file is the best place to do it.
But this filter also drops all headers for some emails (my changes separated by dashes):
LOGFILE=/var/log/procmail.log
TRAP=/etc/webmin/virtual-server/procmail-logger.pl
:0wi
VIRTUALMIN=|/etc/webmin/virtual-server/lookup-domain.pl --exitcode 73 $LOGNAME
EXITCODE=$?
:0
* ?/bin/test "$EXITCODE" = "73"
/dev/null
EXITCODE=0
:0
* ?/bin/test "$VIRTUALMIN" != ""
{
INCLUDERC=/etc/webmin/virtual-server/procmail/$VIRTUALMIN
}
-----
:0
* ^List-Unsubscribe:.*
{
:0 hw
SUBJECT=| formail -xSubject:
:0 hfw
* ^List-Unsubscribe:.*
| /usr/bin/formail -i "Subject: [BULKMAIL] $SUBJECT"
}
-----
DEFAULT=$HOME/Maildir/
ORGMAIL=$HOME/Maildir/
DROPPRIVS=yes
Individual .procmailrc in user home dir rules with this code works perfect but its hard to manage.
Best Answer
I am unable to reproduce your problem, and you are not posting any diagnostics, but I can suggest a different recipe which might avoid a couple of possible error conditions.
There is no reason to repeat the
List-Unsubscribe:
conditions inside the braces -- if you are inside the braces, you know it matched.The convention to hard-code the path to
formail
seems clunky (and you fail to do that in one of the places where you call it) but if Procmail gets invoked with a really wonkyPATH
that could be a reason you see failure when you don't specify fully the path/usr/bin/formail
.Anyway, you want to avoid external processes as far as possible. Procmail can extract the Subject: header into
MATCH
and then you just need a singleformail
invocation for the entire recipe to succeed.The special operator
\/
causes Procmail to collect the matching string into the variableMATCH
, and we then use that instead of the externalformail -xSubject:
you were running. This is hardly a crucial change, but should be more efficient, as well as easier to read and debug.(The trailing wildcard
.*
is superfluous in the first regex; Procmail is satisfied if a match is found anywhere in a line.)You can test from the command line (but this of course requires that your recipe file doesn't override
DEFAULT
):If you still can't get this to work, updating your question with a similar transcript whould be most helpful. Further troubleshooting tips can be found e.g. at http://www.iki.fi/era/mail/procmail-debug.html
Once you are satisfied that your code works, maybe you'll want to prefer
formail -I
overformail -i
which leaves the now rather uselessOld-Subject:
in the headers.(Your prose description says
BULK
but the code saysBULKMAIL
. It is obviously easy to change if your code was wrong.)The Webmin stuff is truly atrocious but apparently it's not your own code. Somebody should supply the Webmin folks with a hint that Procmail contains a regex engine, so calling
/bin/test
to compare two strings is really, really inefficient and generally horrendous.