简体   繁体   中英

Put email multiple folder in case of multiple recipients using procmail

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: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org

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!

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.)

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].*linux-janitors@vger.kernel.org
    | DoItSomethingWithIt

    :0Ac:
    * ^[To|Cc].*linux-kernel@vger.kernel.org
    | DoItSomethingWithIt2

    :0                             
    * LASTFOLDER ?? .
    | DoItSomethingWithIt3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM