#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. :0 c backup :0 ic | cd backup && rm -f dummy ‘ls -t msg.* | sed -e 1,32d‘ #Next two lines are generally required MAILDIR=$HOME/Mail LOGFILE=$HOME/.procmail-log #Example 1 #Note this is a zero on next line :0HB: * ^Sender: double-bounce@maths.ox.ac.uk Postfix #Example 2 :0H: * ^Subject:.*test Test #Example 3 :0H: * ^From:.*manager@mybank.com * ^Subject:.*Financial Finance #Example 4 :0B: * .*computer IT #Example 5: Spam Filter :0H: * ^X-Bogosity: Yes, tests=bogofilter Spam-jail #Example 6: Vacation Responder SHELL=/bin/sh :0 Whc: $HOME/.vacation.lock * $^(To:.*$LOGNAME|CC:.*$LOGNAME) * !^FROM_DAEMON * !^List- * !^(Mailing-List|Approved-By|BestServHost|Resent-(Message-ID|Sender)): * !^Sender: (.*-errors@|owner-) * !^X-[^:]*-List: * !^X-(Authentication-Warning|Loop|Sent-To|(Listprocessor|Mailman)- Version): * !$^From +$LOGNAME(@| |$) | /local/bin/formail -rD 8192 $HOME/.vacation.cache :0 ehc | (/local/bin/formail -rI"Precedence: junk" \ -A"X-Loop: $LOGNAME@maths.ox.ac.uk" ; \ cat $HOME/.vacation.msg ) | $SENDMAIL -t #Example 7: Forward copies of messages under a certain size to a second address :0c * < 4000 ! me@other.address # This one looks for the string "foofoofoo" in the body of the message and sends it to /dev/null. :0 B * foofoofoo /dev/null #This one looks for the string "cyberpromo.com" in the From: line and sends it to #/dev/null. grep'ing the headers is the default, so you can do it with or without the "H" #in the first line. :0 H * ^From:.*cyberpromo\.com /dev/null #Forward email to me@inch.com to me@aol.com :0 * ^TOme@inch\.com ! me@aol.com #This looks for anything from johndoe and sends the contents of the file #received_your_message.txt back to the sender. It also quotes the contents of their #message, and places the original in your inbox folder. :0 c * ^From.*johndoe |(/usr/local/bin/formail -k -r ; \ cat $HOME/can/received_your_message.txt) | $SENDMAIL -t :0 A inbox # Too many recipients #This says "Look at the lines that begin with To: or Cc: and count the number of @ signs. If #the message is addressed to 12 people (or more), throw it away unread." :0 * ^(To|Cc):.*@.*@.*@.*@.*@.*@.*@.*@.*@.*@.*@.*@ /dev/null #The ^ mark means "the start of the line." The (a|b) syntax means a or b. The .* means any #number of any character. The : and @ are literal, meaning that they stand for themselves. If #you want to test for the presence of a character that has a special meaning, like a literal #period, you have to 'escape' it with a backslash. So, to ensure that you always receive mail #sent from "cannon@example.com" you would write it as: # Accept all mail from that nice cannon chap :0 * ^From.*cannon@example\.com ${DEFAULT} #And if you want to receive mail from me even if I sent it to twelve other people, you would #put this test BEFORE the one for "too many recipients." The first recipe that 'delivers' the #message, whether to a mailbox or to the wastebasket, is the LAST test that will be done. #You can even test the body of the message, but that's more 'expensive' and should be a #last resort. To do that, replace the :0 above with :0 B #If you simply discard mail that doesn't have a "To:.*porkchop" header (and isn't from a list #you subscribed to, of course), that will kill 90% of spam, according to some reports. To do #that, use an exclamation point, which is the procmail way of saying "NOT!": :0 * !^To:.*porkchop@example\.com $HOME/junk # Here's one way to make sure you see messages about a certain subject: # Tell your friends to put this "magic word" (Brahms) on the subject # line of mail they send you. :0 * ^Subject:.*Brahms { LOG="Brahms " :0 ${DEFAULT} } # Tell your friends to put this "magic word" on the subject # line of mail they send you. #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. :0 * (^TO|^Subject:.*)TeX[^t] texmail #The same as above, except now we store the mails in numbered files (MH mail folder). :0 * (^TO|^Subject:.*)TeX[^t] texmail/. ####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’. :0: * meeting ‘date +%y-%m‘/meeting #########The same as above, but, if the ‘94-01’ directory wouldn’t have existed, it is created automatically: MONTHFOLDER=‘date +%y-%m‘ :0 Wic * ? test ! -d $MONTHFOLDER | mkdir $MONTHFOLDER :0: * meeting ${MONTHFOLDER}/meeting ######The same as above, but now by slightly different means: MONTHFOLDER=‘date +%y-%m‘ DUMMY=‘test -d $MONTHFOLDER || mkdir $MONTHFOLDER‘ :0: * meeting ${MONTHFOLDER}/meeting