Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is the first time using procmail and I've got the following recipe,

SENDMAIL=/opt/zimbra/postfix/sbin/sendmail
SHELL=/bin/sh
PATH=$HOME/bin:/usr/bin:/bin:.
MAILDIR=/opt/zimbra/procmail/
DEFAULT=$MAILDIR
LOGFILE=.procmaillog
LOCKFILE=.procmaillock
VERBOSE=yes

#Get the recipient's address
TO_=`formail -xTo: \
         | expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`

#Get the recipient's local-part, e.g. fax number
FAXNO_=`echo "${TO_}" | awk -F@ '{ print $1 }'`


LOCALPART=${FAXNO_}
DOMAIN=faxservice.com

# Forward the email
:0
! ${LOCALPART}@${DOMAIN}

The recipe gets the TO email header, parses it and builds the forwarding email address.

PROBLEM

The problem with the recipe is that the email is rejected by the recipient because the Return-Path header is modified.

TRIED SOLUTIONS

  1. I added the following to the top of the recipe,

    SENDMAILFLAGS="-oi -f \"$SENDER\""

    this makes the Return-Path header blank and the recipient still rejects the email.

  2. I found this serverfault question and modified my recipe as follows,

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

    procmail's log file shows an error that there is no match,

    procmail: No match on "^Return-Path:[   ]*\/[^  ].+"
    

QUESTIONS

I don't know whether to make a change to the postfix pipe,

   procmail-fax-send unix    -   n   n   -   -   pipe
   flags=    user=zimbra argv=/usr/bin/procmail  /opt/zimbra/procmail/procmailrc

Or how to change my recipe, so that the original sender is not modified after procmail processes the email.

share|improve this question
    
Using a global lock file with LOCKFILE=.procmaillock serves no useful purpose here, as far as I can discern. Running multiple Procmail instances should be safe unless (for example) you have replaced your real Sendmail with a hack of your own which tries to save something to a database with exclusive write access or something like that. –  tripleee Apr 2 '13 at 12:36
    
You cannot have two actions, so the double exclamation marks in your edited recipe are a syntax error. If there isn't a Return-Path: header in the incoming message, then of course, you cannot extract it, so the error is never reached anyway. –  tripleee Apr 2 '13 at 13:06
    
If SENDER is an acceptable envelope sender, just replace ${env+-f "$env"} with -f "$SENDER" and you're done (modulo the syntax error changes which will have to be undone, of course). –  tripleee Apr 2 '13 at 13:23
add comment

1 Answer

Without attempting to address the Postfix part of the question, here is an attempt at fixing the Procmail problems and doing away with the multiple external processes just to extract the token before the @ sign in the To: address.

# Do you really need to much with SENDMAIL?
SENDMAIL=/opt/zimbra/postfix/sbin/sendmail
SHELL=/bin/sh
# Don't muck with PATH
#PATH=$HOME/bin:/usr/bin:/bin:.
MAILDIR=/opt/zimbra/procmail/
# Don't muck with DEFAULT
#DEFAULT=$MAILDIR
LOGFILE=.procmaillog
VERBOSE=yes

# Get the local part of the recipient's address
:0  # note: whitespace is [ ^ space tab @ ]
* ^To:.*\<\/[^  <>@]+@
{
  :0
  * MATCH ?? ()\/[^@]+
  { LOCALPART=$MATCH }
}
DOMAIN=faxservice.com

# Forward the email
:0  # note: whitespace is [ space tab ] and [ ^ space tab ]
* ^Return-Path:[    ]*\/[^  ].+
{ env=$MATCH }
:0
! ${env+-f "$env"} ${LOCALPART}@${DOMAIN}

If there is no Return-Path: header, the env assignment should end up empty, and the message should be forwarded with whatever envelope sender your Postfix generates.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.