procmail
[Top] [All Lists]

Duplicate Messages to First Name

1997-03-27 04:43:31
I found this whilst scanning the archives (I've just joined the list). I
can't see any other replies to it so I hope this is not going over old
ground.

POLYMNIA(_at_)aol(_dot_)com was stumped:
I have created a .procmailrc  file and have it located in the root directory.
It is forwarding my mail OK, except for one situation. If someone sends an
email addressed like this:
     To: name1(_at_)domain(_dot_)com, name2(_at_)domain(_dot_)com, 
name3(_at_)domain(_dot_)com
Name1 will receive 3 copies of the message, while name2 and name3 will
receive nothing?

I assume this is because the procmail matching is not looking for a
specific account name. I have a similar setup on my website, where all
mail that is not dealt with by specific rules is caught by the last rule
and dealt with. 

This certainly seems to work for multiple recipients in the To: line
itself, logically it ought to work for Cc: and all other related lines
covered by the TO expansions. If anyone has a better way of achieving
this (or comments on my style (or lack thereof) please let me know).

I hope this helps

regards
Neil Horlock
neil(_at_)devserver(_dot_)ft(_dot_)com


It should be noted that this particualr recipe only extracts the account
name only (I know what my domain is!).

If you have N users mentioned in the To: line (or related lines for that
matter) you will be delivered N copies of the message so the first thing
you need to do is set up a cache and remove the duplicates as we are
going to deal with all the users from the first message. This is shown
below and ought to be very near the top of your recipes! I think this is
in procmailex for a better explanation.

# 
# Cache Message Ids to kill dups
#

DISCARD=/dev/null
CACHEFILE=$MAILDIR/.cache
CACHESIZE=1000

# First we grab the Message-Id:
:0 cW: $CACHEFILE.lock
|formail -D $CACHESIZE $CACHEFILE

# This recipe should kill something if its Message-Id is in the 
# cachefile
:0 a: 
$DUPFILE


Now we have ensured that we will get the message only once we need to
send separate messages to each user. Note that because formail will use
the same Message-ID unless we tell it otherwise we MUST use -I
"Message-ID:" to generate a new one or end up in the garbage with our
mouldy old spams :).

:0
* ^TO\/.*
#* ! ^FROM_DAEMON
* $ ! ^X-Loop: postmaster(_at_)$THISDOMAIN
{
# First of all we extract the first mail address in the TO field(s)
# The first rule pulls out the full email address the second trims off
the @domain
        :0
        * $ ^TO.*<?\/[^(_at_)]+@$THISDOMAIN
        * MATCH ?? ^[ ]*\/[^@ ]+
        {
           TOMAIL=$MATCH
        }

# Are there any more addresses for this domain?
# If any further addresses exist in the TO fields then we must send
# a new message with the remainder of the TO line only
# The first rule trims off the address we matched above
# The second just checks to see if there are any more references to this
# domain
        :0
        * $ ^TO<?[^@ ]+(_at_)$THISDOMAIN>?,\/.*
        * $ MATCH ?? @$THISDOMAIN
        {
           ONWARDMAIL=$MATCH
#          DUMMY=`echo "Multiple targets in this domain pass onward with To ==
$ONWARDMAIL" >> $LOGFILE`
           :0 c
           | formail -I "Message-ID:" -I "To: $ONWARDMAIL" | $SENDMAIL
-oi -t
           
        }
#
# Now do processing for the first address as extracted         
#
        :0
        * $ TOMAIL ?? (SET|OF|ADDRESSES|THAT|YOU|ALLOW)
        {
# This is a valid recipient so let's do all the things we need and
# finish up with a formail | sendmail to send it on to them.
            :0
            | formail  -I "Message-ID:" +ANY_OTHER_FIELDS | $SENDMAIL
-oi -t
        }
# Otherwise we have an unknown addressee. So deal with it accordingly
#
        :0 Eh
        {
# Removed for brevity.
        }
}

<Prev in Thread] Current Thread [Next in Thread>
  • Duplicate Messages to First Name, Neil Horlock <=