Debian Codegraph @

upstream/debian-unstable/man5/procmailex.5

raw
1 .\"if n .pl +(135i-\n(.pu)
2 .de Id
3 .ds Rv \\$3
4 .ds Dt \\$4
5 ..
6 .Id $Id: procmailex.man,v 1.54 2001/08/04 06:08:20 guenther Exp $
7 .TH PROCMAILEX 5 \*(Dt BuGless
8 .rn SH Sh
9 .de SH
10 .br
11 .ne 11
12 .Sh "\\$1"
13 ..
14 .rn SS Ss
15 .de SS
16 .br
17 .ne 10
18 .Ss "\\$1"
19 ..
20 .rn TP Tp
21 .de TP
22 .br
23 .ne 9
24 .Tp \\$1
25 ..
26 .rn RS Rs
27 .de RS
28 .na
29 .nf
30 .Rs
31 ..
32 .rn RE Re
33 .de RE
34 .Re
35 .fi
36 .ad
37 ..
38 .de Sx
39 .PP
40 .ne \\$1
41 .RS
42 ..
43 .de Ex
44 .RE
45 .PP
46 ..
47 .na
48 .SH NAME
49 procmailex \- procmail rcfile examples
50 .SH SYNOPSIS
51 .B $HOME/.procmailrc examples
52 .ad
53 .SH DESCRIPTION
54 For a description of the rcfile format see
55 .BR procmailrc (5).
56 .PP
57 The weighted scoring technique is described in detail in the
58 .BR procmailsc (5)
59 man page.
60 .PP
61 This man page shows several example recipes. For examples of complete rcfiles
62 you can check the NOTES section in
63 .BR procmail (1),
64 or look at the example rcfiles in /usr/share/doc/procmail/examples.
65 .SH EXAMPLES
66 Sort out all mail coming from the scuba-dive mailing list into the mailfolder
67 scubafile (uses the locallockfile scubafile.lock).
68 .Sx 3
69 :0:
70 * ^TOscuba
71 scubafile
72 .Ex
73 Forward all mail from peter about compilers to william (and keep a copy
74 of it here in petcompil).
75 .Sx 10
76 :0
77 * ^From.*peter
78 * ^Subject:.*compilers
79 {
80 :0 c
81 ! [email protected]
82
83 :0
84 petcompil
85 }
86 .Ex
87 An equivalent solution that accomplishes the same:
88 .Sx 7
89 :0 c
90 * ^From.*peter
91 * ^Subject:.*compilers
92 ! [email protected]
93
94 :0 A
95 petcompil
96 .Ex
97 An equivalent, but slightly slower solution that accomplishes the same:
98 .Sx 9
99 :0 c
100 * ^From.*peter
101 * ^Subject:.*compilers
102 ! [email protected]
103
104 :0
105 * ^From.*peter
106 * ^Subject:.*compilers
107 petcompil
108 .Ex
109 If you are fairly new to procmail and plan to experiment a little bit
110 it often helps to have a
111 .I safety net
112 of some sort. Inserting the following two recipes above all other recipes
113 will make sure that of all arriving mail always the last 32 messages will
114 be preserved. In order for it to work as intended, you have to create
115 a directory named `backup' in $MAILDIR prior to inserting these two recipes.
116 .Sx 5
117 :0 c
118 backup
119
120 :0 ic
121 | cd backup && rm \-f dummy `ls \-t msg.* | sed \-e 1,32d`
122 .Ex
123 If your system doesn't generate or generates incorrect leading `From '
124 lines on every mail, you can fix this by calling up procmail with
125 the \-f- option. To fix the same problem by
126 different means, you could have inserted the following two
127 recipes above all other recipes in your rcfile. They will filter the header
128 of any mail through formail which will strip any leading `From ', and
129 automatically regenerates it subsequently.
130 .Sx 2
131 :0 fhw
132 | formail \-I "From " \-a "From "
133 .Ex
134 Add the headers of all messages that didn't come from the postmaster
135 to your private header collection (for
136 statistics or mail debugging); and use the lockfile `headc.lock'. In order
137 to make sure the lockfile is not removed until the pipe has finished,
138 you have to specify option `w'; otherwise the lockfile would be
139 removed as soon as the pipe has accepted the mail.
140 .Sx 3
141 :0 hwc:
142 * !^FROM_MAILER
143 | uncompress headc.Z; cat >>headc; compress headc
144 .Ex
145 Or, if you would use the more efficient gzip instead of compress:
146 .Sx 3
147 :0 hwc:
148 * !^FROM_MAILER
149 | gzip >>headc.gz
150 .Ex
151 Forward all mails shorter than 1000 bytes to my home address (no lockfile
152 needed on this recipe).
153 .Sx 3
154 :0
155 * < 1000
156 ! myname@home
157 .Ex
158 Split up incoming digests from the surfing mailing list into their individual
159 messages, and store them into surfing, using surfing.lock as the locallockfile.
160 .Sx 3
161 :0:
162 * ^Subject:.*surfing.*Digest
163 | formail +1 \-ds >>surfing
164 .Ex
165 Store everything coming from the postmaster or mailer-daemon (like bounced
166 mail) into the file postm, using postm.lock as the locallockfile.
167 .Sx 3
168 :0:
169 * ^FROM_MAILER
170 postm
171 .Ex
172 A simple autoreply recipe. It makes sure that neither mail from any daemon
173 (like bouncing mail or mail from mailing-lists), nor autoreplies coming from
174 yourself will be autoreplied to. If this precaution would not be taken,
175 disaster could result (`ringing' mail). In order for this recipe to autoreply
176 to all the incoming mail, you should of course insert it before all other
177 recipes in your rcfile. However, it is advisable to put it
178 .I after
179 any recipes that process the mails from subscribed mailinglists; it generally
180 is not a good idea to generate autoreplies to mailinglists (yes, the
181 !^FROM_DAEMON regexp should already catch those, but if the mailinglist
182 doesn't follow accepted conventions, this might
183 .I not
184 be
185 .IR enough ).
186 .Sx 6
187 :0 h c
188 * !^FROM_DAEMON
189 * !^X-Loop: [email protected]
190 | (formail \-r \-I"Precedence: junk" \e
191 \-A"X-Loop: [email protected]" ; \e
192 echo "Mail received.") | $SENDMAIL \-t
193 .Ex
194 A more complicated autoreply recipe that implements the functional equivalent
195 of the well known
196 .BR vacation (1)
197 program. This recipe is based on the same principles as the last one (prevent
198 `ringing' mail). In addition to that however, it maintains a vacation database
199 by extracting the name of the sender and inserting it in the vacation.cache
200 file if the name was new (the vacation.cache file is maintained by formail
201 which will make sure that it always contains the most recent names, the size
202 of the file is limited to a maximum of approximately 8192 bytes). If the name
203 was new, an autoreply will be sent.
204 .PP
205 As you can see, the following recipe has comments
206 .B between
207 the conditions.
208 This is allowed. Do
209 .B not
210 put comments on the same line as a condition though.
211 .Sx 18
212 SHELL=/bin/sh # for other shells, this might need adjustment
213
214 :0 Whc: vacation.lock
215 # Perform a quick check to see if the mail was addressed to us
216 * $^To:.*\e<$\eLOGNAME\e>
217 # Don't reply to daemons and mailinglists
218 * !^FROM_DAEMON
219 # Mail loops are evil
220 * !^X-Loop: [email protected]
221 | formail \-rD 8192 vacation.cache
222
223 :0 ehc # if the name was not in the cache
224 | (formail \-rI"Precedence: junk" \e
225 \-A"X-Loop: [email protected]" ; \e
226 echo "I received your mail,"; \e
227 echo "but I won't be back until Monday."; \e
228 echo "-- "; cat $HOME/.signature \e
229 ) | $SENDMAIL \-oi \-t
230 .Ex
231 Store all messages concerning TeX in separate, unique filenames, in a directory
232 named texmail (this directory has to exist); there is no need to use lockfiles
233 in this case, so we won't.
234 .Sx 3
235 :0
236 * (^TO|^Subject:.*)TeX[^t]
237 texmail
238 .Ex
239 The same as above, except now we store the mails in numbered files (MH mail
240 folder).
241 .Sx 3
242 :0
243 * (^TO|^Subject:.*)TeX[^t]
244 texmail/.
245 .Ex
246 Or you could file the mail in several directory folders at the same time.
247 The following recipe will deliver the mail to two MH-folders and one
248 directory folder. It is actually only one file with two extra hardlinks.
249 .Sx 3
250 :0
251 * (^TO|^Subject:.*)TeX[^t]
252 texmail/. wordprocessing dtp/.
253 .Ex
254 Store all the messages about meetings in a folder that is in a directory
255 that changes every month. E.g. if it were January 1994, the folder
256 would have the name `94-01/meeting' and the locallockfile would be
257 `94-01/meeting.lock'.
258 .Sx 3
259 :0:
260 * meeting
261 `date +%y-%m`/meeting
262 .Ex
263 The same as above, but, if the `94-01' directory wouldn't have existed, it
264 is created automatically:
265 .Sx 9
266 MONTHFOLDER=`date +%y-%m`
267
268 :0 Wic
269 * ? test ! \-d $MONTHFOLDER
270 | mkdir $MONTHFOLDER
271
272 :0:
273 * meeting
274 ${MONTHFOLDER}/meeting
275 .Ex
276 The same as above, but now by slightly different means:
277 .Sx 6
278 MONTHFOLDER=`date +%y-%m`
279 DUMMY=`test \-d $MONTHFOLDER || mkdir $MONTHFOLDER`
280
281 :0:
282 * meeting
283 ${MONTHFOLDER}/meeting
284 .Ex
285 If you are subscribed to several mailinglists and people cross-post to
286 some of them, you usually receive several duplicate mails (one from every
287 list). The following simple recipe eliminates duplicate mails. It tells
288 formail to keep an 8KB cache file in which it will store the Message-IDs of
289 the most recent mails you received. Since Message-IDs are guaranteed to
290 be unique for every new mail, they are ideally suited to weed out duplicate
291 mails. Simply put the following recipe at the top of your rcfile, and
292 no duplicate mail will get past it.
293 .Sx 2
294 :0 Wh: msgid.lock
295 | formail \-D 8192 msgid.cache
296 .Ex
297 .B Beware
298 if you have delivery problems in recipes below this one and procmail tries
299 to requeue the mail, then on the next queue run, this mail will be considered
300 a duplicate and will be thrown away. For those not quite so confident in
301 their own scripting capabilities, you can use the following recipe instead.
302 It puts duplicates in a separate folder instead of throwing them away.
303 It is up to you to periodically empty the folder of course.
304 .Sx 5
305 :0 Whc: msgid.lock
306 | formail \-D 8192 msgid.cache
307
308 :0 a:
309 duplicates
310 .Ex
311 Procmail can deliver to MH folders directly, but, it does not update
312 the unseen sequences the real MH manages. If you want procmail to
313 update those as well, use a recipe like the following which will file
314 everything that contains the word spam in the body of the mail into an
315 MH folder called spamfold. Note the local lockfile, which is needed
316 because MH programs do not lock the sequences file. Asynchronous
317 invocations of MH programs that change the sequences file may therefore
318 corrupt it or silently lose changes. Unfortunately, the lockfile
319 doesn't completely solve the problem as rcvstore could be invoked while
320 `show' or `mark' or some other MH program is running. This problem is
321 expected to be fixed in some future version of MH, but until then,
322 you'll have to balance the risk of lost or corrupt sequences against
323 the benefits of the unseen sequence.
324 .Sx 3
325 :0 :spamfold/$LOCKEXT
326 * B ?? spam
327 | rcvstore +spamfold
328 .Ex
329 When delivering to emacs folders (i.e., mailfolders managed by any emacs
330 mail package, e.g., RMAIL or VM) directly, you should use emacs-compatible
331 lockfiles. The emacs mailers are a bit braindamaged in that respect, they get
332 very upset if someone delivers to mailfolders which they already have in their
333 internal buffers. The following recipe assumes that $HOME equals /home/john.
334 .Sx 5
335 MAILDIR=Mail
336
337 :0:/usr/local/lib/emacs/lock/!home!john!Mail!mailbox
338 * ^Subject:.*whatever
339 mailbox
340 .Ex
341 Alternatively, you can have procmail deliver into its own set of mailboxes,
342 which you then periodically empty and copy over to your emacs files using
343 .BR movemail .
344 Movemail uses mailbox.lock local lockfiles per mailbox. This actually is
345 the preferred mode of operation in conjunction with procmail.
346 .PP
347 To extract certain headers from a mail and put them into environment
348 variables you can use any of the following constructs:
349 .Sx 5
350 SUBJECT=`formail \-xSubject:` # regular field
351 FROM=`formail \-rt \-xTo:` # special case
352
353 :0 h # alternate method
354 KEYWORDS=| formail \-xKeywords:
355 .Ex
356 If you are using temporary files in a procmailrc file, and want to make
357 sure that they are removed just before procmail exits, you could use
358 something along the lines of:
359 .Sx 2
360 TEMPORARY=$HOME/tmp/pmail.$$
361 TRAP="/bin/rm \-f $TEMPORARY"
362 .Ex
363 The TRAP keyword can also be used to change the exitcode of procmail.
364 I.e. if you want procmail to return an exitcode of `1' instead of its
365 regular exitcodes, you could use:
366 .Sx 3
367 EXITCODE=""
368 TRAP="exit 1;" # The trailing semi-colon is important
369 # since exit is not a standalone program
370 .Ex
371 Or, if the exitcode does not need to depend on the programs run from
372 the TRAP, you can use a mere:
373 .Sx 1
374 EXITCODE=1
375 .Ex
376 The following recipe prints every incoming mail that looks like a postscript
377 file.
378 .Sx 3
379 :0 Bb
380 * ^^%!
381 | lpr
382 .Ex
383 The following recipe does the same, but is a bit more selective. It only
384 prints the postscript file if it comes from the print-server. The first
385 condition matches only if it is found in the header. The second condition
386 only matches at the start of the body.
387 .Sx 4
388 :0 b
389 * ^From[ :].*print-server
390 * B ?? ^^%!
391 | lpr
392 .Ex
393 The same as above, but now by slightly different means:
394 .Sx 7
395 :0
396 * ^From[ :].*print-server
397 {
398 :0 B b
399 * ^^%!
400 | lpr
401 }
402 .Ex
403 Likewise:
404 .Sx 4
405 :0 HB b
406 * ^^(.+$)*From[ :].*print-server
407 * ^^(.+$)*^%!
408 | lpr
409 .Ex
410 Suppose you have two accounts, you use both accounts regularly, but they are
411 in very distinct places (i.e., you can only read mail that arrived at either one
412 of the accounts). You would like to forward mail arriving at account one to
413 account two, and the other way around. The first thing that comes to mind is
414 using .forward files at both sites; this won't work of course, since you will
415 be creating a mail loop. This mail loop can be avoided by inserting the
416 following recipe in front of all other recipes in the $HOME/.procmailrc files on
417 both sites. If you make sure that you add the same X-Loop: field at both
418 sites, mail can now safely be forwarded to the other account from either of
419 them.
420 .Sx 4
421 :0 c
422 * !^X-Loop: [email protected]
423 | formail \-A "X-Loop: [email protected]" | \e
424 $SENDMAIL \-oi [email protected]
425 .Ex
426 If someone sends you a mail with the word `retrieve' in the subject, the
427 following will automatically send back the contents of info_file to the
428 sender. Like in all recipes where we send mail, we watch out for mail
429 loops.
430 .Sx 6
431 :0
432 * !^From +YOUR_USERNAME
433 * !^Subject:.*Re:
434 * !^FROM_DAEMON
435 * ^Subject:.*retrieve
436 | (formail \-r ; cat info_file) | $SENDMAIL \-oi \-t
437 .Ex
438 Now follows an example for a very simple fileserver accessible by mail.
439 For more demanding applications, I suggest you take a look at
440 .B SmartList
441 (available from the same place as the procmail distribution).
442 As listed, this fileserver sends back at most one file per request, it
443 ignores the body of incoming mails, the Subject: line has to look
444 like "Subject: send file the_file_you_want" (the blanks are significant),
445 it does not return files that have names starting with a dot, nor does
446 it allow files to be retrieved that are outside the fileserver directory
447 tree (if you decide to munge this example, make sure you do not inadvertently
448 loosen this last restriction).
449 .Sx 18
450 :0
451 * ^Subject: send file [0-9a-z]
452 * !^X-Loop: [email protected]
453 * !^Subject:.*Re:
454 * !^FROM_DAEMON
455 * !^Subject: send file .*[/.]\e.
456 {
457 MAILDIR=$HOME/fileserver # chdir to the fileserver directory
458
459 :0 fhw # reverse mailheader and extract name
460 * ^Subject: send file \e/[^ ]*
461 | formail \-rA "X-Loop: [email protected]"
462
463 FILE="$MATCH" # the requested filename
464
465 :0 ah
466 | cat \- ./$FILE 2>&1 | $SENDMAIL \-oi \-t
467 }
468 .Ex
469 The following example preconverts all plain-text mail arriving in certain
470 encoded MIME formats into a more compact 8-bit format which can be used
471 and displayed more easily by most programs. The
472 .BR mimencode (1)
473 program is part of Nathaniel Borenstein's metamail package.
474 .Sx 17
475 :0
476 * ^Content-Type: *text/plain
477 {
478 :0 fbw
479 * ^Content-Transfer-Encoding: *quoted-printable
480 | mimencode \-u \-q
481
482 :0 Afhw
483 | formail \-I "Content-Transfer-Encoding: 8bit"
484
485 :0 fbw
486 * ^Content-Transfer-Encoding: *base64
487 | mimencode \-u \-b
488
489 :0 Afhw
490 | formail \-I "Content-Transfer-Encoding: 8bit"
491 }
492 .Ex
493 The following one is rather exotic, but it only serves to demonstrate a
494 feature. Suppose you have a file in your HOME directory called ".urgent",
495 and the (one) person named in that file is the sender of an incoming mail,
496 you'd like that mail to be stored in $MAILDIR/urgent instead of in any of the
497 normal mailfolders it would have been sorted in. Then this is what you could
498 do (beware, the filelength of $HOME/.urgent should be well below $LINEBUF,
499 increase LINEBUF if necessary):
500 .Sx 5
501 URGMATCH=`cat $HOME/.urgent`
502
503 :0:
504 * $^From.*${URGMATCH}
505 urgent
506 .Ex
507 An entirely different application for procmail would be to conditionally
508 apply filters to a certain (outgoing) text or mail. A typical example
509 would be a filter through which you pipe all outgoing mail, in order
510 to make sure that it will be MIME encoded only if it needs to be.
511 I.e. in this case you could start procmail in the middle of a pipe like:
512 .Sx 1
513 cat newtext | procmail ./mimeconvert | mail [email protected]
514 .Ex
515 The
516 .B mimeconvert
517 rcfile could contain something like (the =0x80= and =0xff= should
518 be substituted with the real 8-bit characters):
519 .Sx 10
520 DEFAULT=| # pipe to stdout instead of
521 # delivering mail as usual
522 :0 Bfbw
523 * [=0x80=-=0xff=]
524 | mimencode \-q
525
526 :0 Afhw
527 | formail \-I 'MIME-Version: 1.0' \e
528 \-I 'Content-Type: text/plain; charset=ISO-8859-1' \e
529 \-I 'Content-Transfer-Encoding: quoted-printable'
530 .Ex
531 .SH "SEE ALSO"
532 .na
533 .nh
534 .BR procmail (1),
535 .BR procmailrc (5),
536 .BR procmailsc (5),
537 .BR sh (1),
538 .BR csh (1),
539 .BR mail (1),
540 .BR mailx (1),
541 .BR uucp (1),
542 .BR aliases (5),
543 .BR sendmail (8),
544 .BR egrep (1),
545 .BR grep (1),
546 .BR biff (1),
547 .BR comsat (8),
548 .BR mimencode (1),
549 .BR lockfile (1),
550 .BR formail (1)
551 .hy
552 .ad
553 .SH AUTHORS
554 Stephen R. van den Berg
555 .RS
556 <[email protected]>
557 .RE
558 Philip A. Guenther
559 .RS
560 <[email protected]>
561 .RE
562 .\".if n .pl -(\n(.tu-1i)
563 .rm SH
564 .rn Sh SH
565 .rm SS
566 .rn Ss SS
567 .rm TP
568 .rn Tp TP
569 .rm RS
570 .rn Rs RS
571 .rm RE
572 .rn Re RE