Maarten
Maarten

Reputation: 4671

Don't forward if from certain address

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

:0c
${DEFAULT}

:0fhw
| formail -i "From: [email protected]"

:0
* !^From:.*\<donforward@domain\.com\>
{
 ! [email protected]    # 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)

Upvotes: 1

Views: 743

Answers (1)

tripleee
tripleee

Reputation: 189789

The braces around the action are a syntax error.

:0  # is the address spelled correctly?  not don_T_forward?
* !^From:.*\<donforward@domain\.com\>
! [email protected]

(Or, alternatively but superfluously,

:0
* !^From:.*\<donforward@domain\.com\>
{
 :0
 ! [email protected]
}

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: [email protected]"
  :0
  ! [email protected]
}

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: [email protected]"
  :0
  ! [email protected]
}

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

Upvotes: 1

Related Questions