Preface:

For a very long time, this was my email setup at home:

  • Mutt : MUA (Mail User Agent)
  • postfix : MTA (Message transfer agent)
  • fetchmail : MRA (Mail retrieval agent)
  • procmail : MDA (Message delivery agent)

Procmail was used to sort my email in Maildir folders depending on rules defined in .procmailrc.

I’ve replaced my ~/.procmailrc with a bash script. Now my setup is:

  • Mutt : MUA
  • postfix : MTA
  • fetchmail : MRA
  • mda.sh : MDA

Why?

Although procmail worked fine, there were also drawbacks, such as a confusing syntax.

After reading “procmail considered harmful”, I had put replacing procmail on my TODO list. And like so many things, it stayed on my TODO list, probably because I didn’t feel like learning a new syntax to filter my email.

And then I read “writing a custom MDA”, which described how an MDA could be written as a shell script.

So, I’ve written my own mda.sh based on this “writing a custom MDA” post.

Why???, Because:

  • It’s fun ;)
  • I don’t have to learn a new syntax and can improve my shell scripting skills.

How?

I’m not going to post my complete setup here, because it contains too much personal information. But there are some things I want to highlight.

Postfix

In /etc/postfix/main.cf, I’ve changed the line mailbox_command = procmail with mailbox_command = /home/jan/mda/mda.sh. This way, postfix will call my bash script instead of procmail to deliver mail locally.

Email headers

In procmail, I was filtering on certain email headers like From:, To:, Subject:, List-Id:. But how to do it in a bash script?

I use this sed oneliner (sed -e '/^$/q;/'"$1"'/!d;n;:c;/^\s/!d;n;bc' "$TMP") found on stackoverflow.

After extracting an email header, I use a case esac statement to filter, for example:

case "$LISTID" in                                                                                                                                                                   
*suckless*)                                                                                                                                                                         
        write "$MAILDIR"/.dwm                                                                                                                                                    
        ;;                                                                                                                                                                          
*debian*)                                                                                                                                                                           
        write "$MAILDIR"/.debian                                                                                                                                                  
        ;;                                                                                                                                                                          
*sxmo*)                                                                                                                                                                             
        write "$MAILDIR"/.sxmo                                                                                                                                                   
        ;;                                                                                                                                                                          
esac          

SpamAssassin

To filter spam, I use SpamAssassin/spamc.

spamc -c <"$TMP" || write "$MAILDIR"/.spam

Good idea?

Is it a good idea to write a custom mda in bash? Probably not… but this is just my personal setup at home, where I can do stupid things if I like to ;)