Procmail – Preventing Addition of Return-Path

procmail

I'm storing and forwarding (to google apps) emails using the following procmail recipe:

# set vars
USERNAME=local_username
LOCALPART=realemaillocalpart

:0
# Avoid email loops
* ! ^X-Loop: ${USERNAME}@domain\.nl
{
  :0c:   #Preserve a copy of the email
  ${DEFAULT}
  :0fwh  #Adjust some headers before forwarding
  | formail -A"X-Loop: ${USERNAME}@domain.nl" \
  # Forward the email
  :0
  !${LOCALPART}@apps.domain.nl
}

This works, but when I set up an 'out of office' message in gmail it returns the email to the forwarding system instead of to the original sender.

This probably has to do with the forwarding system adding or replacing a Return-path line and putting the local username and the servername in there.

My question is thus how can I prevent that from happening?

Best Answer

Try

# Forward the email
:0
* ^Return-Path:[  ]*\/[^  ].+
{ env=$MATCH }
:0
! ${env+-f "$env"} ${LOCALPART}@apps.domain.nl

As is customary in Procmail recipes, the whitespace inside the square brackets should consist of a space and a tab (both places where the Return-Path header is being matched. I could not write literal tabs from the mobile device I'm typing on).