procmail
[Top] [All Lists]

RE: Reading a list of email addresses from a flat file and piping the same to a procmail recipe

2010-09-24 12:44:04
Hello Sean!

 

Thank you for the detailed email. While I may not be able to use this
right away, I am trying to work on this to apply it later.

 

I got this recipe updated with some changes, but am still unable to find
a match in the CCMATCH field.

 

Here's my updated recipe.

# Define some variable for pre_checking

FORMAIL=/opt/local/bin/formail

EGREP=/bin/egrep

GREP=/usr/xpg4/bin/grep

HOME=/home/cem

PMDIR=$HOME/recipe-dev

NL="

"

# Capture the To field in the TO variable.

:0

* ^To:(.*\<)\/[^  ].*

{ TO=$MATCH }

 

 

CCMATCH=`($FORMAIL -xCc: | tr ',' '\n' | $GREP -i -w -f
$PMDIR/rc.routingAddressList) | 

tr '\n' ',' | sed -e 's/^[         ]*//' -e 's/[   ]*,$//'`

 

# if the string isn't empty, there was a match - do something

:0

* ! CCMATCH ?? ^^^^

{

        # concatenate the original To: 

         # after the matched Cc: entries

        :0

        * TO ?? ^^^^

        {

               # To: is empty, so new to is just the match from Cc:

               TOREPLACE=$CCMATCH

        }

 

        :0E

        {

               # To: is not empty, concatenate match from Cc:

               TOREPLACE="$TO, $CCMATCH"

        }

 

        # you just want to modify the header, so flag accordingly.

        :0hf

        | $FORMAIL -I"To: $TOREPLACE"

}

 

The file rc.routingAddressList contains the following list of addresses:

japan-tac-test

cem-tac-dev

cem-japan-dev

cem-korea-dev

 

My test email was sent to my personal address (tkomal(_at_)att(_dot_)net) with 
a Cc
to cem-japan-dev address (the third item in the flat file containing my
white list).

 

However, procmail log reported that it could not find a match. See
output below.

procmail: Assigning
"INCLUDERC=/home/cem/recipe-dev/rc.komal_test_reading_from_file"

procmail: Assigning "PATT_IN_RC_BLOCK=NO"

procmail: Assigning "FORMAIL=/opt/local/bin/formail"

procmail: Assigning "EGREP=/bin/egrep"

procmail: Assigning "GREP=/usr/xpg4/bin/grep"

procmail: Assigning "HOME=/home/cem"

procmail: Assigning "PMDIR=/home/cem/recipe-dev"

procmail: Assigning "NL=

"

procmail: Assigning "MATCH="

procmail: Matched "<tkomal(_at_)att(_dot_)net>"

procmail: Match on "^To:(.*\<)\/[^  ].*"

procmail: Assigning "TO=<tkomal(_at_)att(_dot_)net>"

procmail: Executing "($FORMAIL -xCc: | tr ',' '\n' | $GREP -i -w -f
$PMDIR/rc.routingAddressList) | 

tr '\n' ',' | sed -e 's/^[         ]*//' -e 's/[   ]*,$//'"

procmail: Assigning "CCMATCH="

procmail: No match on ! "^^^^"

 

Not sure what I am doing wrong here.

 

Regards,

Komal

________________________________

-----Original Message-----
From: procmail-bounces(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
[mailto:procmail-bounces(_at_)lists(_dot_)RWTH-Aachen(_dot_)de] On Behalf Of 
Professional
Software Engineering
Sent: Friday, September 24, 2010 1:25 AM
To: procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
Subject: Re: Reading a list of email addresses from a flat file and
piping thesame to a procmail recipe

 

At 20:58 2010-09-21, Komal Tagdiwala (ktagdiwa) wrote:

I have a requirement where I need to read a huge list of email 

addresses (a kind of white list) from a FLAT file and PIPE the results 

to my procmail recipe's filter condition for Cc field. If one or more 

addresses matches with the value in the Cc field of the incoming email,


I need to append that matched address to the To: field.

 

Grep can do this for you, with a bit of help to massage the results.
I'd have posted this sooner, but you know, I didn't have this just
kicking around, and hoped someone else might post.  I've been trying to
avoid doing other people's work, but since you posted a recipe showing
that you'd _tried_ to accomplish the task yourself, I figured you at
least werent' one of the many that just post asking someone else to
write everything for them because they're unwilling to try.

 

Good luck with it, and hopefully you're getting this in time for
whatever implementation you need.

 

# this pipes your message to formail to extract the Cc: header, then #
converts comma delimiters to newlines (so each apparent Cc: recipient #
is a separate line for matching), greps against a wordlist file (your #
address list), translates newlines to commas, removes leading
whitespace, # and trailing whitespace/comma (for last in list).  The
results are # captured into $CCMATCH.

CCMATCH=`(formail -xCc: | tr ',' '\n' | grep -i -w -f addressfile) | 

tr '\n' ',' | sed -e 's/^[         ]*//' -e 's/[   ]*,$//'`

 

# if the string isn't empty, there was a match - do something

:0

* ! CCMATCH ?? ^^^^

{

         # concatenate the original To: (extracted in my sandbox
framework)

         # after the matched Cc: entries

         :0

         * TO ?? ^^^^

         {

                 # To: is empty, so new to is just the match from Cc:

                 TOREPLACE=$CCMATCH

         }

 

         :0E

         {

                 # To: is not empty, concatenate match from Cc:

                 TOREPLACE="${TO}, ${CCMATCH}"

         }

 

         # you just want to modify the header, so flag accordingly.

         :0hf

         | formail -I"To: ${TOREPLACE}"

}

 

# at this point, either you have the original message that didn't have
any # matching entries in the CC, or the message has been modified to
put the # matching addresses into the To:

 

 

caveats:

         * the insertion recipe relies upon a $TO variable which is
captured by my sandbox config (simple operation - see the link in my
.sig).  I point you to my sandbox rather than cite the simple
extraction, because I think you'll find other benefit from reviewing the
sandbox and its purpose.

 

         * no effort is made to remove the addresses from the Cc: header

 

         * commas within the address comment portions could be
problematic

 

---

  Sean B. Straw / Professional Software Engineering

 

  Procmail disclaimer:
<http://www.professional.org/procmail/disclaimer.html
<http://www.professional.org/procmail/disclaimer.html> >

  Please DO NOT carbon me on list replies.  I'll get my copy from the
list.

 

____________________________________________________________

procmail mailing list   Procmail homepage: http://www.procmail.org/
<http://www.procmail.org/> 

procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de 
<mailto:procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de> 

http://mailman.rwth-aachen.de/mailman/listinfo/procmail
<http://mailman.rwth-aachen.de/mailman/listinfo/procmail> 

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail
<Prev in Thread] Current Thread [Next in Thread>