1

I have a procmail recipe which stores email and forwards it, after changing a header:

:0c
${DEFAULT}

:0fhw
| formail -i "From: changedemail@address.com"

:0
* !^From:.*\<donforward@domain\.com\>
{
 ! other@recipient.net    # That's exclamation mark, address to forward to
}

Now I would like to only forward if not from a certain address, but I cannot get it to work, somehow it never seems to match.

What do I need to add to get it to work, and also not store the email twice (which is also what happened when experimenting with solutions, I think because the recipe continued into some sort of default behaviour)

tripleee
  • 175,061
  • 34
  • 275
  • 318
Maarten
  • 4,643
  • 7
  • 37
  • 51

1 Answers1

1

The braces around the action are a syntax error.

:0  # is the address spelled correctly?  not don_T_forward?
* !^From:.*\<donforward@domain\.com\>
! other@recipient.net

(Or, alternatively but superfluously,

:0
* !^From:.*\<donforward@domain\.com\>
{
 :0
 ! other@recipient.net
}

Also, see below.)

However, this can never actually match, because you change the From: address in the previous recipe. Maybe add some logic to preserve the original From:, or combine the actions in braces after all:

:0c
${DEFAULT}

:0
* !^From:.*\<donforward@domain\.com\>
{
  :0fhw
  | formail -i "From: changedemail@address.com"
  :0
  ! other@recipient.net
}

And yes, the default action is to deliver to $DEFAULT if the message was not successfully delivered by any recipe. You might want to invert the :0c logic so that the original is delivered to your regular inbox (provided you don't have any later recipe which delivers it elsewhere) and the copy gets forwarded.

# Drop the $DEFAULT delivery from above
:0c
* !^From:.*\<donforward@domain\.com\>
{
  :0fhw
  | formail -i "From: changedemail@address.com"
  :0
  ! other@recipient.net
}

For troubleshooting, it makes sense to run with VERBOSE=yes. Add this directive before the problematic recipe, then examine the log output when a message arrives. For (much) more, see http://porkmail.org/era/mail/procmail-debug.html

slm
  • 15,396
  • 12
  • 109
  • 124
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Thanks for this very useful solution. I implemented it and debugged a bit more because it wasn't working yet, and I found out the email is forwarded to this box by another account, leading to two From: headers in the email. Can I somehow strip the first From header, as that is always the one from the forwarding one and not the original one I want to match on...? – Maarten Nov 26 '12 at 15:58
  • Sounds wrong, are you sure there isn't one `From` (space) pseudo-header and only one `From:` header? The first is the envelope sender; but, given this distinction, it's easy to filter on the one you want (presumably the envelope sender). If you have access to the forwarding account, for robustness, you might want to put in a real RFC822 header (maybe something like `X-Forwarded-By:`)? – tripleee Nov 26 '12 at 18:42
  • You're right, it's without the colon, so I guess that's not the problem then. Somehow my mails aren't being matched, and I can't really understand why not. The from line is like this: 'From: " Companyname | Support" ', I'd think that'd match..? – Maarten Nov 27 '12 at 07:47
  • If you have copy/pasted correctly, you are missing the `t` between `don` and `forward@domain.com` ... – tripleee Nov 27 '12 at 08:39
  • No that was just an example unfortunately – Maarten Nov 28 '12 at 10:59