procmail recipie help
am 03.12.2005 23:21:58 von dennisj
I'm hoping someone can help me sort out a messy procmail task that is
causing me to pull my hair out:
1) Copy mail to an external address if mail arrives from
(support|support-bounces)@somedomain.com
2) Copy mail to an external address if mail arrives with importance
set to high
3) Stop processing after step 1 if a message is sent.
Here's what I've got so far (and this seems to work for pattern
matching, but mail is never sent):
-------------
SHELL = /bin/sh
MAILDIR = $HOME/.procmail
LOGFILE = log
VERBOSE = yes
# Forward if from support
:0
* ^FROM_DAEMON.*(support|support-bounces)@somedomain\.com
* :0c \
! address@forward.com
{
# Don't continue
:0i
| /bin/false
}
# Forward if importance high
:0
* ^Importance: *High
* :0c \
! address@forward.com
{
# Don't continue
:0i
| /bin/false
}
-------------
Any help would be sincerely appreciated.
Re: procmail recipie help
am 04.12.2005 05:27:20 von AK
dennisj@gmail.com wrote:
> I'm hoping someone can help me sort out a messy procmail task that is
> causing me to pull my hair out:
>
> 1) Copy mail to an external address if mail arrives from
> (support|support-bounces)@somedomain.com
>
> 2) Copy mail to an external address if mail arrives with importance
> set to high
>
> 3) Stop processing after step 1 if a message is sent.
>
> Here's what I've got so far (and this seems to work for pattern
> matching, but mail is never sent):
>
> -------------
> SHELL = /bin/sh
> MAILDIR = $HOME/.procmail
> LOGFILE = log
> VERBOSE = yes
>
> # Forward if from support
> :0
> * ^FROM_DAEMON.*(support|support-bounces)@somedomain\.com
> * :0c \
> ! address@forward.com
> {
> # Don't continue
> :0i
> | /bin/false
> }
>
>
> # Forward if importance high
> :0
> * ^Importance: *High
> * :0c \
> ! address@forward.com
> {
> # Don't continue
> :0i
> | /bin/false
> }
> -------------
>
> Any help would be sincerely appreciated.
>
FROM_DAEMON is a specific pattern match predifined macro dealing with
Automated notifiers. The man pages for procmail define all the macros.
# Forward if from support
:0c
* ^(FROM|Return-Path):.*(support|support-bounces)@somedomain\. com
! address@forward.com
# Forward if importance high
:0cE
* ^Importance: *High
! address@forward.com
#default Falls through the above and is delivered to the mailbox
:0
$DEFALT
c means it will generate a copy. (omit the c flag if you need the
message to be redirected.)
E means that if the script prior to it matched, this script will not be
checked. This will prevent messages from support with a High Priority
from being forwarded twice. If the addresses to which the messages
should be forwarded are different, then you should take out the E.
AK
Re: procmail recipie help
am 04.12.2005 10:43:24 von Garen Erdoisa
dennisj@gmail.com wrote:
> I'm hoping someone can help me sort out a messy procmail task that is
> causing me to pull my hair out:
>
> 1) Copy mail to an external address if mail arrives from
> (support|support-bounces)@somedomain.com
>
> 2) Copy mail to an external address if mail arrives with importance
> set to high
>
> 3) Stop processing after step 1 if a message is sent.
>
> Here's what I've got so far (and this seems to work for pattern
> matching, but mail is never sent):
>
> -------------
> SHELL = /bin/sh
> MAILDIR = $HOME/.procmail
> LOGFILE = log
> VERBOSE = yes
>
> # Forward if from support
> :0
> * ^FROM_DAEMON.*(support|support-bounces)@somedomain\.com
> * :0c \
Syntax Error here: the ':0c' denotes the beginning of a new procmail
recipe that forks a carbon copy of the current pipeline being processed
into a new sub-process. It needs to be on a line by itself with whatever
recipe flags you want.
A procmail line beginning with '*' denotes the beginning of a regular
expression or command execution condition that must be met for a given
procmail recipe to proceed. If all the specified condition(s) are not
met, that recipe will be skipped.
> ! address@forward.com
> {
> # Don't continue
> :0i
> | /bin/false
The above should read as follows to just dump the message in the bit
bucket. It will avoid generating a procmail broken pipe error thus
removing the need to use the 'i' recipe flag. Also note that a broken
pipe error depending on your environment setup can generate a bounce
message back to the apparent sender.
# Don't continue.
:0
/dev/null
> }
>
>
> # Forward if importance high
> :0
> * ^Importance: *High
> * :0c \
Another syntax error here.
> ! address@forward.com
> {
> # Don't continue
> :0i
> | /bin/false
Should read:
# Don't continue
:0
/dev/null
> }
> -------------
So, with the syntax errors and logic corrected the above recipe should
read something like the following to achieve your desired effect.
SHELL=/bin/sh
MAILDIR=$HOME/.procmail
LOGFILE=log
VERBOSE=yes
# Forward if from support
:0
* ^FROM_DAEMON.*(support|support-bounces)@somedomain\.com
{
# forward a CC to the following address:
:0c
! address@forward.com
# file the original email in the bit bucket.
:0
* ^some regexp pattern you don't like
/dev/null
# else file the support email in a folder using an implied lockfile
:0 E:
${MAILDIR}/supportfolder
}
# Forward if importance high
:0
* ^Importance: *High
{
# forward a cc to some other address
:0c
! address@forward.com
# Don't continue (file the email in the bit bucket)
:0i
* ^Some regexp pattern you don't like
/dev/null
# else file the mail in a folder using an implied lockfile
:0 E:
${MAILDIR}/importantstuff
}
Once the email in the main procmail pipeline is filed, procmail will
stop processing any further recipes beyond that point.
>
> Any help would be sincerely appreciated.
>
Garen
Re: procmail recipie help
am 05.12.2005 01:48:31 von dennisj
Thanks to all for the great explanations -- they were extremely
helpful.
In case it might help someone in the future, I've included my final
script below. It forwards based on sender, and also if various
priority headers are set to 'high'.
--------------
SHELL=/bin/sh
MAILDIR=$HOME/.procmail
LOGFILE=log
VERBOSE=yes
# Forward if from support@somedomain.com or
support-bounces@somedomain.com
:0c
* ^(FROM|Return-Path):.*(support|support-bounces)@somedomain\. com
! email@address.com
# Forward if Importance = High
:0cE
* ^Importance: *High
! email@address.com
# Forward if X-Priority = 1
:0cE
* ^X-Priority: 1*
! email@address.com
# Forward if X-MSMail-Priority = High
:0cE
* ^X-MSMail-Priority: *High
! email@address.com
# If recipies above do not match, do nothing
:0
$DEFAULT