Using Procmail Charles Duan Harvard Univ Computer Services

  • Slides: 25
Download presentation
Using Procmail 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 •

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns • Recipe options • File locking

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns •

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns • Recipe options • File locking

What is Procmail? • Procmail is a processor of e-mail • Filter mail by

What is Procmail? • Procmail is a processor of e-mail • Filter mail by headers/content • Multiple delivery possibilities – Mailboxes – Forwarding Addresses – Programs

Procmail Recipes • Procmail filters e-mails based on recipes in the. procmailrc file •

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)

Procmailrc Syntax # A basic. procmailrc : 0: * ^From: ksdavis@fas Important-folder : 0:

Procmailrc Syntax # A basic. procmailrc : 0: * ^From: ksdavis@fas Important-folder : 0: * ^Subject: *[UA] * < 1024 ! my@email. com Header Patterns Action

Delivering Mail with Procmail Mail Received Run. procmailrc Add to. inbox No more recipes

Delivering Mail with Procmail Mail Received Run. procmailrc Add to. inbox No more recipes Read a “recipe” Match No match Execute action

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns •

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns • Recipe options • File locking

Basic Procmail Recipes • Sorting Recipes • Forwarding Recipes • Program Recipes

Basic Procmail Recipes • Sorting Recipes • Forwarding Recipes • Program Recipes

Sorting Recipes # Sorting : 0: * ^Subject: *[UA] uas-mail If Subject contains “[UA]”

Sorting Recipes # Sorting : 0: * ^Subject: *[UA] uas-mail If Subject contains “[UA]” Put it in mailbox “uas-mail” • Most common recipe used • Multiple patterns accepted

Forwarding Recipes # Forwarding : 0 * ^From: *ksdavis ! my@email. com Header (no

Forwarding Recipes # Forwarding : 0 * ^From: *ksdavis ! my@email. com Header (no trailing colon) If it’s from Kevin Send it to “my@email. com” • Multiple forwarding addresses accepted • Multiple patterns accepted • To keep a copy yourself, use “: 0 c”

Program Recipes # Forwarding : 0 * ^Subject: *Survey | runstats. pl If it’s

Program Recipes # Forwarding : 0 * ^Subject: *Survey | runstats. pl If it’s for the survey Run my program on it • Used for processing online forms • Very powerful; proceed with caution • I’ll talk later about “: 0: ” v. “: 0”

Exercise

Exercise

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns •

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns • Recipe options • File locking

E-mail Structure • Two parts: header and body • Separated by an empty line

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

E-mail Structure Example From cduan@fas. . . From: Aaron Lee <lee 42@. . .

E-mail Structure Example From cduan@fas. . . From: Aaron Lee <lee 42@. . . To: uas@fas. harvard. edu Subject: Interesting. . . Date: Sun, 10 Feb 2002. . . “From” line Header Blank line I send you this file in order to have your advice I hope you can help me Body • “From” line separates messages

Regular Expressions • “Completely” compatible with egrep • By default, matches only header •

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 [ ])

Other Special Patterns • ! Invert the pattern • ? Run a program, use

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

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns •

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns • Recipe options • File locking

Recipe Options • Options placed after zero in header • Aa. Ee: Run based

Recipe Options • Options placed after zero in header • Aa. Ee: Run based on previous recipe • f: Change (filter) the mail • c: Continue through this recipe • Read “man procmailrc”

Another Exercise

Another Exercise

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns •

Using Procmail • What is procmail? • Basic procmailrc recipes • Using patterns • Recipe options • File locking

File Locking • Prevents procmail processes from corrupting mailboxes • Locking type depends on

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 forwarding, programs (? )

Hints and Tips • Test your recipes before using them • Resources for more

Hints and Tips • Test your recipes before using them • Resources for more information – man procmail, procmailrc, procmailex – www. procmail. org • Have fun using procmail!

The Last Blank Slide

The Last Blank Slide