Search code examples
procmail

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: [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!


Solution

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