Get your hands dirty with Procmail

Preliminary notes

NetBSD and Debian/Ubuntu have /var/mail/ while Slackware has a symlink pointing to /var/spool/mail/.

Mbox format is the default. Maildir format starts with ., add trailing / and folder separator is .. MH format add trailing /.. A lock may be used with mbox (:0:) and probably MH as well, while it is not required for Maildir.

Templates

assuming Mbox

Dotfile template w/ auto-archives (tune USERNAME and DOMAIN.TLD accordingly)

https://pub.nethence.com/dotfiles/dot.procmailrc.txt

System-wide template for postfix virtual mbox integration (out-of-the-box)

https://pub.nethence.com/dotfiles/procmailrc.yearly.txt

Ready to go plan A - Postfix

this may conflict with virtual mboxen

slackware

slackpkg install procmail alpine

netbsd

pkg_add procmail alpine

debian/ubuntu

apt install procmail ksh alpine

from the MTA directly e.g. w/ Postfix

vi /etc/postfix/main.cf

mailbox_command = /usr/bin/procmail
#mailbox_command = /usr/pkg/bin/procmail
#mailbox_command = /usr/local/bin/procmail

Ready to go plan B - user trickery

vi ~/.forward

netbsd

"|IFS=' '&&p=/usr/pkg/bin/procmail&&test -f $p&&exec $p -f-||exit 75"

debian/ubuntu

"|IFS=' '&&p=/usr/bin/procmail&&test -f $p&&exec $p -f %F||exit 75"

Ready to go plan C - during POP3 retrieval

with Fetchmail

mda "/usr/bin/procmail -f %F"

Acceptance

tail -100 -F ~/procmail.log.`date +%Y`

Additional notes

this might be incompatible with heavy re-processing (header might be added multiple times)

# @sales
:0 hfw
* ^(To|Cc):.*sales@nethence.com
* ^Subject:\/.+
| formail -i "Subject: [sales]$MATCH"

# @abuse
:0 hfw
* ^(To|Cc):.*abuse@nethence\.com
* ^Subject:\/.+
| formail -i "Subject: [abuse]$MATCH"

# @contact @info
:0 hfw
* ^(To|Cc):.*contact@nethence\.com
* ^(To|Cc):.*info@nethence\.com
* ^Subject:\/.+
| formail -i "Subject: [contact]$MATCH"

Re-processing & format conversions

see procmail.reproc

Troubleshooting & Repairs

Find broken messages

looking for new line and Return-Path instead of From

15:12:51 < geirha> elge: awk -v RS= '!/^From/' mbox
15:13:17 < geirha> or awk -v RS= '/^Return-Path/'
15:13:45 < geirha> and maybe throw in   -v ORS='\n\n'  too

==> the second one works out of the box

Trash

Maildir

draft

MAILDIR=$HOME/Maildir/
ORGMAIL=$HOME/Maildir/

MH

draft

MAILDIR=$HOME/mailbox/.
ORGMAIL=$HOME/mailbox/inbox/.

note - using an inbox inside the mail folder in view to avoid this error

procmail: Lock failure on "/var/spool/mail/USERNAME.lock"

this should not happen, as we are the MX and we block spam at session time, but it does not harm

    :0
    * ^X-Spam-Status: Yes
    spam

Resources

Procmail FAQ http://porkmail.org/era/procmail/mini-faq.html

Procmail Tips & Tricks http://novosial.org/procmail/

Automatic folders for mailing lists using procmail https://blog.sandipb.net/2011/05/06/automatic-folders-for-mailing-lists-using-procmail/

Jari’s Procmail Tips Page https://www.howtoforge.com/procmail_tips_recipes

prevent procmail from adding Return-path https://serverfault.com/questions/408849/prevent-procmail-from-adding-return-path

PROCMAIL QUICK START http://www.ii.com/internet/robots/procmail/qs/#DEFAULT

Maildir

Converting Mbox mailboxes to Maildir format http://batleth.sapienti-sat.org/projects/mb2md/

Maildir Configuration https://wiki.debian.org/MaildirConfiguration

procmail is creating Maildir files instead of mbox https://groups.google.com/forum/#!topic/comp.mail.misc/GbGwg31uDk4

Troubleshooting

3.0 Dry run testing http://pm-doc.sourceforge.net/doc/#dry_run_testing

Debugging Procmail Recipes: Some Tips http://porkmail.org/era/mail/procmail-debug.html

procmail: lock file failures https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=160753

Procmail lock failures and errors while writing https://serverfault.com/questions/212794/procmail-lock-failures-and-errors-while-writing

How to Open MBOX files in Thunderbird. https://www.wintips.org/how-to-open-mbox-files-in-thunderbird/


HOME | GUIDES | BENCHMARKS | html