Title: Using Procmail
1Using Procmail
- Charles Duan
- Harvard Univ. Computer Services
- March 27, 2002
2Using Procmail
- What is procmail?
- Basic procmailrc recipes
- Using patterns
- Recipe options
- File locking
3Using Procmail
- What is procmail?
- Basic procmailrc recipes
- Using patterns
- Recipe options
- File locking
4What is Procmail?
- Procmail is a processor of e-mail
- Filter mail by headers/content
- Multiple delivery possibilities
- Mailboxes
- Forwarding Addresses
- Programs
5Procmail 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)
6Procmailrc Syntax
A basic .procmailrc
0 Header
From ksdavis_at_fas Patterns
Important-folder Action
0 Header
Subject \UA\ Patterns
lt 1024 Patterns
! my_at_email.com Action
7Delivering Mail with Procmail
Mail Received
Add to .inbox
8Using Procmail
- What is procmail?
- Basic procmailrc recipes
- Using patterns
- Recipe options
- File locking
9Basic Procmail Recipes
- Sorting Recipes
- Forwarding Recipes
- Program Recipes
10Sorting Recipes
Sorting
0
Subject \UA\ If Subject contains UA
uas-mail Put it in mailbox uas-mail
- Most common recipe used
- Multiple patterns accepted
11Forwarding Recipes
Forwarding
0 Header (no trailing colon)
From ksdavis If its from Kevin
! my_at_email.com Send it to my_at_email.com
- Multiple forwarding addresses accepted
- Multiple patterns accepted
- To keep a copy yourself, use 0c
12Program Recipes
Forwarding
0
Subject Survey If its for the survey
runstats.pl Run my program on it
- Used for processing online forms
- Very powerful proceed with caution
- Ill talk later about 0 v. 0
13Exercise
14Using Procmail
- What is procmail?
- Basic procmailrc recipes
- Using patterns
- Recipe options
- File locking
15E-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
16E-mail Structure Example
From cduan_at_fas... From line
From Aaron Lee ltlee42_at_... Header
To uas_at_fas.harvard.edu Header
Subject Interesting ... Header
Date Sun, 10 Feb 2002... Header
Blank line
I send you this file in Body
order to have your advice Body
I hope you can help me Body
- From line separates messages
17Regular Expressions
- Completely compatible with egrep
- By default, matches only header
- Watch out for spaces
- From cduan_at_fas Wrong
- From cduan_at_fas Right!
- (Thats a space and a tab in )
18Other Special Patterns
- ! Invert the pattern
- ? Run a program, use the exit code
- lt Under specified number of bytes
- gt Over specified number of bytes
- Evaluate quotes like /bin/sh
19Using Procmail
- What is procmail?
- Basic procmailrc recipes
- Using patterns
- Recipe options
- File locking
20Recipe 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
21Another Exercise
22Using Procmail
- What is procmail?
- Basic procmailrc recipes
- Using patterns
- Recipe options
- File locking
23File 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 (?)
24Hints and Tips
- Test your recipes before using them
- Resources for more information
- man procmail, procmailrc, procmailex
- www.procmail.org
- Have fun using procmail!
25The Last Blank Slide