procmail setup

get your hands dirty

install

see procmail-install

a good start

Maildir

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

MH

MAILDIR=$HOME/mailbox/.
ORGMAIL=$HOME/mailbox/inbox/.
DEFAULT=$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"

Templates

assuming Mbox

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

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

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

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

Plan A with Postfix

this may conflict with virtual mboxen

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

Plan B with user trickery

vi ~/.forward

# debian / ubuntu
p=/usr/bin/procmail

# netbsd
p=/usr/pkg/bin/procmail

# mbox
"|IFS=' ' && test -f $p && exec $p -f - || exit 75"
"|IFS=' ' && test -f $p && exec $p -f %F || exit 75"

# maildir
"|IFS=' ' && test -f $p && exec $p || exit 75"

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 reprocess

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

Additional notes

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 - autonomous mail processor https://linux.die.net/man/1/procmail

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

Introductory procmail http://www.cs.toronto.edu/~flaps/procmail/introprocmail.html

https://wiki.archlinux.org/title/Procmail#Flags_and_lockfile –> :0: for mbox and :0 for maildir

conditions

check with procmail if a file exists and set a option https://serverfault.com/questions/579215/check-with-procmail-if-a-file-exists-and-set-a-option

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

troubles

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 | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun