0

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!

tripleee
  • 175,061
  • 34
  • 275
  • 318
AndrasCsanyi
  • 3,943
  • 8
  • 45
  • 77

2 Answers2

1

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

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • My first attempt at an answer was rather off the mark, so I just want to point out that if you read my reply immediately after I wrote it, you might want to revisit. Sorry about that. – tripleee Mar 09 '12 at 08:17
  • You are right it seems a little bit hackish but I think it can solve my issue. I'm going to take a try and I will inform you here about the result. Thank you very much your help! – AndrasCsanyi Mar 09 '12 at 09:58
0

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
AndrasCsanyi
  • 3,943
  • 8
  • 45
  • 77
  • The regex `[To|Cc]` is incorrect, it matches a single character from the enumerated set `T` `o` `|` `c` (I'm omitting the uppercase C because matching is case-insensitive). I think you want the special macro `^TO_` like in my response. – tripleee Mar 12 '12 at 07:15
  • Oh, and for a pipe action, you need a named lockfile, or no lockfile at all. In other words, the second colon on the delivering actions is wrong, either way. http://www.iki.fi/era/procmail/mini-faq.html#locking – tripleee Mar 12 '12 at 07:19