Penguin
Blame: procmailex(5)
EditPageHistoryDiffInfoLikePages
Annotated edit history of procmailex(5) version 2, including all changes. View license author blame.
Rev Author # Line
1 perry 1 PROCMAILEX
2 !!!PROCMAILEX
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 EXAMPLES
7 SEE ALSO
8 AUTHORS
9 ----
10 !!NAME
11
12
13 procmailex - procmail rcfile examples
14 !!SYNOPSIS
15
16
17 __$HOME/.procmailrc examples__
18 !!DESCRIPTION
19
20
21 For a description of the rcfile format see
22 procmailrc(5).
23
24
25 The weighted scoring technique is described in detail in the
26 procmailsc(5) man page.
27
28
29 This man page shows several example recipes. For examples of
30 complete rcfiles you can check the NOTES section in
31 procmail(1), or look at the example rcfiles part of
32 the procmail source distribution
33 (procmail*/examples/?procmailrc).
34 !!EXAMPLES
35
36
37 Sort out all mail coming from the scuba-dive mailing list
38 into the mailfolder scubafile (uses the locallockfile
39 scubafile.lock).
40
41
42 :0:
43 * ^TOscuba
44 scubafile
45 Forward all mail from peter about compilers to william (and keep a copy of it here in petcompil).
46
47
48 :0
49 * ^From.*peter
50 * ^Subject:.*compilers
51 {
52 :0 c
53 ! william@somewhere.edu
54 :0
55 petcompil
56 }
57 An equivalent solution that accomplishes the same:
58
59
60 :0 c
61 * ^From.*peter
62 * ^Subject:.*compilers
63 ! william@somewhere.edu
64 :0 A
65 petcompil
66 An equivalent, but slightly slower solution that accomplishes the same:
67
68
69 :0 c
70 * ^From.*peter
71 * ^Subject:.*compilers
72 ! william@somewhere.edu
73 :0
74 * ^From.*peter
75 * ^Subject:.*compilers
76 petcompil
77 If you are fairly new to procmail and plan to experiment a little bit it often helps to have a ''safety net'' of some sort. Inserting the following two recipes above all other recipes will make sure that of all arriving mail always the last 32 messages will be preserved. In order for it to work as intended, you have to create a directory named `backup' in $MAILDIR prior to inserting these two recipes.
78
79
80 :0 c
81 backup
82 :0 ic
83 | cd backup
84 If your system doesn't generate or generates incorrect leading `From ' lines on every mail, you can fix this by calling up procmail with the -f- option. To fix the same problem by different means, you could have inserted the following two recipes above all other recipes in your rcfile. They will filter the header of any mail through formail which will strip any leading `From ', and automatically regenerates it subsequently.
85
86
87 :0 fhw
88 | formail -I
89 Add the headers of all messages that didn't come from the postmaster to your private header collection (for statistics or mail debugging); and use the lockfile `headc.lock'. In order to make sure the lockfile is not removed until the pipe has finished, you have to specify option `w'; otherwise the lockfile would be removed as soon as the pipe has accepted the mail.
90
91
92 :0 hwc:
93 * !^FROM_MAILER
94 | uncompress headc.Z; cat
95 Or, if you would use the more efficient gzip instead of compress:
96
97
98 :0 hwc:
99 * !^FROM_MAILER
100 | gzip
101 Forward all mails shorter than 1000 bytes to my home address (no lockfile needed on this recipe).
102
103
104 :0
105 *
106 Split up incoming digests from the surfing mailing list into their individual messages, and store them into surfing, using surfing.lock as the locallockfile.
107
108
109 :0:
110 * ^Subject:.*surfing.*Digest
111 | formail +1 -ds
112 Store everything coming from the postmaster or mailer-daemon (like bounced mail) into the file postm, using postm.lock as the locallockfile.
113
114
115 :0:
116 * ^FROM_MAILER
117 postm
118 A simple autoreply recipe. It makes sure that neither mail from any daemon (like bouncing mail or mail from mailing-lists), nor autoreplies coming from yourself will be autoreplied to. If this precaution would not be taken, disaster could result (`ringing' mail). In order for this recipe to autoreply to all the incoming mail, you should of course insert it before all other recipes in your rcfile. However, it is advisable to put it ''after'' any recipes that process the mails from subscribed mailinglists; it generally is not a good idea to generate autoreplies to mailinglists (yes, the !^FROM_DAEMON regexp should already catch those, but if the mailinglist doesn't follow accepted conventions, this might ''not'' be ''enough'').
119
120
121 :0 h c
122 * !^FROM_DAEMON
123 * !^X-Loop: your@own.mail.address
124 | (formail -r -I
125 A more complicated autoreply recipe that implements the functional equivalent of the well known vacation(1) program. This recipe is based on the same principles as the last one (prevent `ringing' mail). In addition to that however, it maintains a vacation database by extracting the name of the sender and inserting it in the vacation.cache file if the name was new (the vacation.cache file is maintained by formail which will make sure that it always contains the most recent names, the size of the file is limited to a maximum of approximately 8192 bytes). If the name was new, an autoreply will be sent.
126
127
128 As you can see, the following recipe has comments
129 __between__ the conditions. This is allowed. Do
130 __not__ put comments on the same line as a condition
131 though.
132
133
134 SHELL=/bin/sh # for other shells, this might need adjustment
135 :0 Whc: vacation.lock
136 # Perform a quick check to see if the mail was addressed to us
137 * $^To:.*
138 Store all messages concerning TeX in separate, unique filenames, in a directory named texmail (this directory has to exist); there is no need to use lockfiles in this case, so we won't.
139
140
141 :0
142 * (^TO|^Subject:.*)TeX[[^t]
143 texmail
144 The same as above, except now we store the mails in numbered files (MH mail folder).
145
146
147 :0
148 * (^TO|^Subject:.*)TeX[[^t]
149 texmail/.
150 Or you could file the mail in several directory folders at the same time. The following recipe will deliver the mail to two MH-folders and one directory folder. It is actually only one file with two extra hardlinks.
151
152
153 :0
154 * (^TO|^Subject:.*)TeX[[^t]
155 texmail/. wordprocessing dtp/.
156 Store all the messages about meetings in a folder that is in a directory that changes every month. E.g. if it were January 1994, the folder would have the name `94-01/meeting' and the locallockfile would be `94-01/meeting.lock'.
157
158
159 :0:
160 * meeting
161 `date +%y-%m`/meeting
162 The same as above, but, if the `94-01' directory wouldn't have existed, it is created automatically:
163
164
165 MONTHFOLDER=`date +%y-%m`
166 :0 Wic
167 * ? test ! -d $MONTHFOLDER
168 | mkdir $MONTHFOLDER
169 :0:
170 * meeting
171 ${MONTHFOLDER}/meeting
172 The same as above, but now by slightly different means:
173
174
175 MONTHFOLDER=`date +%y-%m`
176 DUMMY=`test -d $MONTHFOLDER || mkdir $MONTHFOLDER`
177 :0:
178 * meeting
179 ${MONTHFOLDER}/meeting
180 If you are subscribed to several mailinglists and people cross-post to some of them, you usually receive several duplicate mails (one from every list). The following simple recipe eliminates duplicate mails. It tells formail to keep an 8KB cache file in which it will store the Message-IDs of the most recent mails you received. Since Message-IDs are guaranteed to be unique for every new mail, they are ideally suited to weed out duplicate mails. Simply put the following recipe at the top of your rcfile, and no duplicate mail will get past it.
181
182
183 :0 Wh: msgid.lock
184 | formail -D 8192 msgid.cache
185 __Beware__ if you have delivery problems in recipes below this one and procmail tries to requeue the mail, then on the next queue run, this mail will be considered a duplicate and will be thrown away. For those not quite so confident in their own scripting capabilities, you can use the following recipe instead. It puts duplicates in a separate folder instead of throwing them away. It is up to you to periodically empty the folder of course.
186
187
188 :0 Whc: msgid.lock
189 | formail -D 8192 msgid.cache
190 :0 a:
191 duplicates
192 Procmail can deliver to MH folders directly, but, it does not update the unseen sequences the real MH manages. If you want procmail to update those as well, use a recipe like the following which will file everything that contains the word spam in the body of the mail into an MH folder called spamfold. Note the local lockfile, which is needed because MH programs do not lock the sequences file. Asynchronous invocations of MH programs that change the sequences file may therefore corrupt it or silently lose changes. Unfortunately, the lockfile doesn't completely solve the problem as rcvstore could be invoked while `show' or `mark' or some other MH program is running. This problem is expected to be fixed in some future version of MH, but until then, you'll have to balance the risk of lost or corrupt sequences against the benefits of the unseen sequence.
193
194
195 :0 :spamfold/$LOCKEXT
196 * B ?? spam
197 | rcvstore +spamfold
198 When delivering to emacs folders (i.e., mailfolders managed by any emacs mail package, e.g., RMAIL or VM) directly, you should use emacs-compatible lockfiles. The emacs mailers are a bit braindamaged in that respect, they get very upset if someone delivers to mailfolders which they already have in their internal buffers. The following recipe assumes that $HOME equals /home/john.
199
200
201 MAILDIR=Mail
202 :0:/usr/local/lib/emacs/lock/!home!john!Mail!mailbox
203 * ^Subject:.*whatever
204 mailbox
205 Alternatively, you can have procmail deliver into its own set of mailboxes, which you then periodically empty and copy over to your emacs files using __movemail__. Movemail uses mailbox.lock local lockfiles per mailbox. This actually is the preferred mode of operation in conjunction with procmail.
206
207
208 To extract certain headers from a mail and put them into
209 environment variables you can use any of the following
210 constructs:
211
212
213 SUBJECT=`formail -xSubject:` # regular field
214 FROM=`formail -rt -xTo:` # special case
215 :0 h # alternate method
216 KEYWORDS=| formail -xKeywords:
217 If you are using temporary files in a procmailrc file, and want to make sure that they are removed just before procmail exits, you could use something along the lines of:
218
219
220 TEMPORARY=$HOME/tmp/pmail.$$
221 TRAP=
222 The TRAP keyword can also be used to change the exitcode of procmail. I.e. if you want procmail to return an exitcode of `1' instead of its regular exitcodes, you could use:
223
224
225 EXITCODE=
226 Or, if the exitcode does not need to depend on the programs run from the TRAP, you can use a mere:
227
228
229 EXITCODE=1
230 The following recipe prints every incoming mail that looks like a postscript file.
231
232
233 :0 Bb
234 * ^^%!
235 | lpr
236 The following recipe does the same, but is a bit more selective. It only prints the postscript file if it comes from the print-server. The first condition matches only if it is found in the header. The second condition only matches at the start of the body.
237
238
239 :0 b
240 * ^From[[ :].*print-server
241 * B ?? ^^%!
242 | lpr
243 The same as above, but now by slightly different means:
244
245
246 :0
247 * ^From[[ :].*print-server
248 {
249 :0 B b
250 * ^^%!
251 | lpr
252 }
253 Likewise:
254
255
256 :0 HB b
257 * ^^(.+$)*From[[ :].*print-server
258 * ^^(.+$)*^%!
259 | lpr
260 Suppose you have two accounts, you use both accounts regularly, but they are in very distinct places (i.e., you can only read mail that arrived at either one of the accounts). You would like to forward mail arriving at account one to account two, and the other way around. The first thing that comes to mind is using .forward files at both sites; this won't work of course, since you will be creating a mail loop. This mail loop can be avoided by inserting the following recipe in front of all other recipes in the $HOME/.procmailrc files on both sites. If you make sure that you add the same X-Loop: field at both sites, mail can now safely be forwarded to the other account from either of them.
261
262
263 :0 c
264 * !^X-Loop: yourname@your.main.mail.address
265 | formail -A
266 If someone sends you a mail with the word `retrieve' in the subject, the following will automatically send back the contents of info_file to the sender. Like in all recipes where we send mail, we watch out for mail loops.
267
268
269 :0
270 * !^From +YOUR_USERNAME
271 * !^Subject:.*Re:
272 * !^FROM_DAEMON
273 * ^Subject:.*retrieve
274 | (formail -r ; cat info_file) | $SENDMAIL -oi -t
2 perry 275 Now follows an example for a very simple fileserver accessible by mail. For more demanding applications, I suggest you take a look at __!SmartList__ (available from the same place as the procmail distribution). As listed, this fileserver sends back at most one file per request, it ignores the body of incoming mails, the Subject: line has to look like __
1 perry 276
277
278 :0
279 * ^Subject: send file [[0-9a-z]
280 * !^X-Loop: yourname@your.main.mail.address
281 * !^Subject:.*Re:
282 * !^FROM_DAEMON
283 * !^Subject: send file .*[[/.].
284 {
285 MAILDIR=$HOME/fileserver # chdir to the fileserver directory
286 :0 fhw # reverse mailheader and extract name
287 * ^Subject: send file /[[^ ]*
288 | formail -rA
289 The following example preconverts all plain-text mail arriving in certain encoded MIME formats into a more compact 8-bit format which can be used and displayed more easily by most programs. The mimencode(1) program is part of Nathaniel Borenstein's metamail package.
290
291
292 :0
293 * ^Content-Type: *text/plain
294 {
295 :0 fbw
296 * ^Content-Transfer-Encoding: *quoted-printable
297 | mimencode -u -q
298 :0 Afhw
299 | formail -I
300 The following one is rather exotic, but it only serves to demonstrate a feature. Suppose you have a file in your HOME directory called
301
302
303 URGMATCH=`cat $HOME/.urgent`
304 :0:
305 * $^From.*${URGMATCH}
306 urgent
307 An entirely different application for procmail would be to conditionally apply filters to a certain (outgoing) text or mail. A typical example would be a filter through which you pipe all outgoing mail, in order to make sure that it will be MIME encoded only if it needs to be. I.e. in this case you could start procmail in the middle of a pipe like:
308
309
310 cat newtext | procmail ./mimeconvert | mail chris@where.ever
311 The __mimeconvert__ rcfile could contain something like (the =0x80= and =0xff= should be substituted with the real 8-bit characters):
312
313
314 DEFAULT=| # pipe to stdout instead of
315 # delivering mail as usual
316 :0 Bfbw
317 * [[=0x80=-=0xff=]
318 | mimencode -q
319 :0 Afhw
320 | formail -I 'MIME-Version: 1.0' \
321 -I 'Content-Type: text/plain; charset=ISO-8859-1' \
322 -I 'Content-Transfer-Encoding: quoted-printable'
323 !!SEE ALSO
324
325
326 procmail(1), procmailrc(5),
327 procmailsc(5), sh(1), csh(1),
328 mail(1), mailx(1), binmail(1),
329 uucp(1), aliases(5), sendmail(8),
330 egrep(1), grep(1), biff(1),
331 comsat(8), mimencode(1), lockfile(1),
332 formail(1)
333 !!AUTHORS
334
335
336 Stephen R. van den Berg
337
338
339
340 Philip A. Guenther
341
342
343
344 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.