My procmail recipe will only filter out the emails that have number "60" in their subject. After that formail will execute taking out the sender's email address and its subject before forwarding it together with its content to the "myemail" directory.

Can someone help me to construct a procmail recipe to filter incoming mails into different directories if there are multiple "60" seperated by commas in the subjects?

(For example,the email with subject 6010,6011,6012,.. the 6010 will go into 6010 folder,6011 will go into 6011 and so on.)

The numbers in the subject are phone numbers, there can be a large number of different ones so enumerating all the possible matches is not really an option.

The script in the backticks will output something like 60123456789/ (newline) 609876543210/ (newline) -- as many as there are phone numbers; each one is treated as a folder name, and the message is delivered to all of those folders.

(I'm sure the egrep | sed could be refactored into a single sed script. Adding a slash after each folder name is necessary for Procmail to treat the delivery action as a directory delivery. You cannot deliver into multiple mbox folders at the same time.)

My original answer follows below the line.

What you are asking about is fairly tricky to do in Procmail. There is no facility for looping over a set of matches. A somewhat desperate workaround would be to collect the matches into a variable, then INCLUDERC= to a different recipe file which will process one value from the beginning of the variable, then SWITCHRC= to itself again while there are values left in the variable. It doesn't have to be very complicated but it's decidedly hackish, to the point where you have to ask if Procmail is really the right tool for the job.

Of course, there is also the brute-force option; create a sequence of recipes to handle each possible 60xx pattern.

:0c
* ^Subject:.*6000
myinbox/6000/

etc for 6001, 6002. This presupposes that you have a limited number of these, or if you need to handle each case from 00 to 99, perhaps generate the recipes with a simple script.

i don't think that this is possible.Because actually the information on the subject represent the phone number of the customers.So the number that available in the "Subject" are very random.The only constant between these numbers are 60 which are country code.Perhaps I can use the sed / awk in the recipe to filter this?
–
user119720Jan 2 '13 at 2:53

The problem is not the extraction, but the handling of multiple matches. For a single match, grab it with * ^Subject:.*\/60[0-9]+ and you will have the number in $MATCH.
–
tripleeeJan 2 '13 at 5:36