Charles Duan Harvard Univ. Computer Services March 27, 2002 Using Procmail Charles Duan Harvard Univ. Computer Services March 27, 2002
Using Procmail What is procmail? Basic procmailrc recipes Using patterns Recipe options File locking September 12, 2017September 12, 2017
Using Procmail What is procmail? Basic procmailrc recipes Using patterns Recipe options File locking September 12, 2017September 12, 2017
What is Procmail? Procmail is a processor of e-mail Filter mail by headers/content Multiple delivery possibilities Mailboxes Forwarding Addresses Programs September 12, 2017September 12, 2017
Procmail Recipes Procmail filters e-mails based on recipes in the .procmailrc file Recipes contain: What kind of e-mail the recipe handles What to do with the e-mail At most one recipe executes (unless otherwise specified) September 12, 2017September 12, 2017
Procmailrc Syntax Header Patterns Action # A basic .procmailrc :0: * ^From: ksdavis@fas Patterns Important-folder Action * ^Subject: *\[UA\] * < 1024 ! my@email.com September 12, 2017September 12, 2017
Delivering Mail with Procmail Mail Received Run .procmailrc Add to .inbox Read a “recipe” No more recipes No match Execute action Match September 12, 2017September 12, 2017
Using Procmail What is procmail? Basic procmailrc recipes Using patterns Recipe options File locking September 12, 2017September 12, 2017
Basic Procmail Recipes Sorting Recipes Forwarding Recipes Program Recipes September 12, 2017September 12, 2017
Sorting Recipes Most common recipe used Multiple patterns accepted :0: * ^Subject: *\[UA\] If Subject contains “[UA]” uas-mail Put it in mailbox “uas-mail” Most common recipe used Multiple patterns accepted September 12, 2017September 12, 2017
Forwarding Recipes Multiple forwarding addresses accepted :0 Header (no trailing colon) * ^From: *ksdavis If it’s from Kevin ! my@email.com Send it to “my@email.com” Multiple forwarding addresses accepted Multiple patterns accepted To keep a copy yourself, use “:0c” September 12, 2017September 12, 2017
Program Recipes Used for processing online forms # Forwarding :0 * ^Subject: *Survey If it’s for the survey | runstats.pl Run my program on it Used for processing online forms Very powerful; proceed with caution I’ll talk later about “:0:” v. “:0” September 12, 2017September 12, 2017
Exercise September 12, 2017September 12, 2017
Using Procmail What is procmail? Basic procmailrc recipes Using patterns Recipe options File locking September 12, 2017September 12, 2017
E-mail Structure Two parts: header and body Separated by an empty line Each line of header is “Field: Value” Special “From” line Based on Berkeley mbox format September 12, 2017September 12, 2017
E-mail Structure Example From cduan@fas... “From” line From: Aaron Lee <lee42@... Header To: uas@fas.harvard.edu Subject: Interesting ... Date: Sun, 10 Feb 2002... Blank line I send you this file in Body order to have your advice I hope you can help me “From” line separates messages September 12, 2017September 12, 2017
Regular Expressions “Completely” compatible with egrep By default, matches only header Watch out for spaces * From: cduan@fas Wrong * From:[ ]*cduan@fas Right! (That’s a space and a tab in [ ]) September 12, 2017September 12, 2017
Other Special Patterns ! Invert the pattern ? Run a program, use the exit code < Under specified number of bytes > Over specified number of bytes $ Evaluate quotes like /bin/sh September 12, 2017September 12, 2017
Using Procmail What is procmail? Basic procmailrc recipes Using patterns Recipe options File locking September 12, 2017September 12, 2017
Recipe Options Options placed after zero in header AaEe: Run based on previous recipe f: Change (filter) the mail c: Continue through this recipe Read “man procmailrc” September 12, 2017September 12, 2017
Another Exercise September 12, 2017September 12, 2017
Using Procmail What is procmail? Basic procmailrc recipes Using patterns Recipe options File locking September 12, 2017September 12, 2017
File Locking Prevents procmail processes from corrupting mailboxes Locking type depends on header :0 No locking :0: Default lock :0: lock Lock the file lock Not for forwarding, programs (?) September 12, 2017September 12, 2017
Hints and Tips Test your recipes before using them Resources for more information man procmail, procmailrc, procmailex www.procmail.org Have fun using procmail! September 12, 2017September 12, 2017
The Last Blank Slide September 12, 2017September 12, 2017