Procmail: canalizar al programa; de lo contrario, devolver el error al remitente

Procmail: canalizar al programa; de lo contrario, devolver el error al remitente

Estoy intentando usar procmail paraenviar todos los mensajespara que un determinado dominioRT(Solicitud de seguimiento). Sin embargo, esta es más una pregunta sobre el archivo .procmailrc.

Aquí está mi archivo .procmailrc actual:

#Preliminaries
SHELL=/bin/sh               #Use the Bourne shell (check your path!)
MAILDIR=${HOME}        #First check what your mail directory is!
LOGFILE=${MAILDIR}/procmail.log
LOG="--- Logging ${LOGFILE} for ${LOGNAME}, "
VERBOSE=yes
MAILDOMAIN='rt.mydomain.com'
RT_MAILGATE="/opt/rt3/bin/rt-mailgate"
RT_URL="http://rt.mydomain.com/"

LOGABSTRACT=all

### Trying to  process using the rt-mailgate script
:0
{
# the following line extracts the recipient from Received-headers.
# Simply using the To: does not work, as tickets are often created
# by sending a CC/BCC to RT
TO=`formail -c -xReceived: |grep $MAILDOMAIN |sed -e 's/.*for *<*\(.*\)>* *;.*$/\1/'`
QUEUE=`echo $TO| $HOME/get_queue.pl`
ACTION=`echo $TO| $HOME/get_action.pl`
:0 h b w 
|/usr/bin/perl $RT_MAILGATE --queue $QUEUE --action $ACTION --url $RT_URL
}


### Upon failure, I want to send back an error message to the user, saying
###   "Queue does not exist." I took this code from the procmailex manpage.
:0 Wh: no-queue.lock
{
## Reply if error
* !^FROM_DAEMON
* !^X-Loop: [email protected]
| formail -rD 8192 no-queue.cache

  :0 ehc
  |(formail -rI"Precedence: junk" -A"X-Loop: [email protected]" ; \
    echo "The Queue or Action was invalid."; echo "--" \
    ) | $SENDMAIL -oi -t

}

¿Ves algún problema con mi archivo .procmailrc? Funciona bien si la cola existe, pero después de ese punto, simplemente envía el correo a /var/mail/nombre de usuario. Quiero tirar el correo electrónico y devolver un mensaje de error.

Respuesta1

Sinceramente, hace tiempo que no uso procmail, así que me disculpo si esto no funciona de inmediato.

En primer lugar, el anidamiento en el script que tenías estaba causando problemas porque prácticamente cortaba la receta a la mitad. De todos modos no son necesarios, así que los eliminé. También simplifiqué la estructura y la configuré para que nunca caiga en el buzón local.

#Preliminaries
SHELL=/bin/sh               #Use the Bourne shell (check your path!)
MAILDIR=${HOME}        #First check what your mail directory is!
LOGFILE=${MAILDIR}/procmail.log
LOG="--- Logging ${LOGFILE} for ${LOGNAME}, "
VERBOSE=yes
MAILDOMAIN='\(help\|rt\)\.\(ncom\|networklubbock\)\.com'
RT_MAILGATE="/opt/rt3/bin/rt-mailgate"
RT_URL="http://rt.ncom.com/"

LOGABSTRACT=all

### Trying to  process using the rt-mailgate script
# the following line extracts the recipient from Received-headers.
# Simply using the To: does not work, as tickets are often created
# by sending a CC/BCC to RT
TO=`formail -c -xReceived: |grep $MAILDOMAIN |sed -e 's/.*for *<*\(.*\)>* *;.*$/\1/'`
QUEUE=`echo $TO| $HOME/get_queue.pl`
ACTION=`echo $TO| $HOME/get_action.pl`
:0w 
|/usr/bin/perl $RT_MAILGATE --queue $QUEUE --action $ACTION --url $RT_URL

# the formail command below looks at the message sender and basically
# swallows the message if it's seen the sender before.  The number
# is the size of the cache file of seen addresses.  A lock file is
# used because multiple formail processes editing that cache will
# corrupt it.
:0w:no-queue.lock
| formail -rD 8192 no-queue.cache

### Upon failure, I want to send back an error message to the user, saying
###   "Queue does not exist." I took this code from the procmailex manpage.
# Don't send if this was a bounce from a mailer, and don't send if this
# message contains the header put there to indicate a loop.
:0
* !^FROM_DAEMON
* !^X-Loop: [email protected]
|(formail -rI"Precedence: junk" -A"X-Loop: [email protected]" ; \
  echo "The Queue or Action was invalid."; echo "--" \
  ) | $SENDMAIL -oi -t

# trash anything that falls all the way through.  This should only ever
# happen if the message was a bounce or if it was a loop.
:0
/dev/null

Espero que ayude. Por favor comente si tiene preguntas sobre alguna parte e intentaré explicarla. O descubrir cómo cometí un error si no funciona.

información relacionada