procmail
[Top] [All Lists]

Re: How to apply multiple recipes to a single email?

2009-09-21 07:39:40
Use the 'f' option on your recipe. This makes the recipe a 'filter'
that modifies the message. Then the action line pipes to 'formail'
to add the headers.

Thanks for that. This approach makes things a little easier. I've put
my solution here for the future record. I've set up my procmailrc file
to have non-delivery filter messages like this (in the examples the
custom header "X-PMERule" is just a header I'm adding which won't
already exist in the email - PME is my initials):

  :0 wf
   # Check if email is to wife's address.
   * ^TO_wife(_at_)example(_dot_)com(_dot_)*
   | formail -A "X-PMERule: wife email address"

  :0 wf
   # Check if email is to husband's address.
   * ^TO_husband(_at_)example(_dot_)com(_dot_)*
   | formail -A "X-PMERule: husband email address"

  :0
   | /usr/libexec/dovecot/deliver -d mailuser

So if someone sends an email to both of us it will get 2 custom
headers added. My .dovecot.sieve file for the user "mailuser" will
then check the headers and deliver to husband's imap folder AND wife's
imap folder like this:

  if header :contains "X-PMERule" "wife email address" {
     fileinto "Wife_folder";
  }

  if header :contains "X-PMERule" "husband email address" {
     fileinto "Husband_folder";
  }


Also, for the record, some will notice a potential flaw here - what if
an email comes in procmail doesn't match and no custom header is
added? Well, in that scenario (eg BCC emails) the .dovecot.sieve file
has a test to see if the "X-PMERule" header is not present and if so
files it in the default imap folder:

  if not exists "X-PMERule" {
     keep;        # Keep is the same as filing into Inbox
  }

Thanks for your help on the procmail part of this. This is working
very well for me now and is pretty simple to maintain, add new rules,
addresses etc.

Regards,
Phill
____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>