0
votes

I'm going to build an email system at home and I'm subscribed to a lot of mailing list. The emails fetched to my local machine by fetchmail and filtered by procmail. But, there is a situation which is not possible to solve with my current knowledge. I have been googling for 2-3 hours to find a solution without any result.

What I want is that, I get an email with multiple recipients and I would like to copy this email to different folders. Here is an example:

Cc: [email protected], [email protected]

I would like to put this email into linux-kernel and linux-kernel-janitors folder. How can I do it by procmail?

Thanks in advance!

2

2 Answers

1
votes

You can make Procmail loop on the list of recipients by using SWITCHRC= but this is rather hackish. Or, if you have a limited list of folders you want to process, you can deliver into each separately, and drop the message if you have delivered it at least once.

LASTFOLDER=
:0c:
* ^TO_linux-kernel@vger\.kernel\.org\>
linux-kernel
:0c:
* ^TO_kernel-janitors@vger\.kernel\.org\>
kernel-janitors
# ... repeat for other addresses you want to multiplex ...
# If it was delivered, LASTFOLDER will be set
:0
* LASTFOLDER ?? .
/dev/null

If you may have copied into additional inboxes before reaching this section, you want to explicitly set LASTFOLDER to the empty string. It should not be necessary otherwise, but I left it in as a precaution. (This variable contains the name of the latest folder the message was delivered to.)

0
votes

The solution looks like this:

First of all, an If statement is needed because my .procmailrc file contains not just kernel mailing list filter conditions. If it matches than there is another list of conditions. I think by the time it will be more fine-grained.

:0
 * [To|Cc].*vger.kernel.org
   LASTFOLDER=

    :0Ac:
    * ^[To|Cc].*[email protected]
    | DoItSomethingWithIt

    :0Ac:
    * ^[To|Cc].*[email protected]
    | DoItSomethingWithIt2

    :0                             
    * LASTFOLDER ?? .
    | DoItSomethingWithIt3