procmail
[Top] [All Lists]

Re: tagging mail with procmail?

2008-06-22 06:37:06
On Sun, 22 Jun 2008, Eugeny N Dzhurinsky wrote:

END> Hello everybody!
END> 
END> Could somebody please advice how is it possible to add tags to e-mail 
messages
END> matching certain pattern? Looks like it should be possible with formail, 
but
END> probably there are some better ways?
END> 

I use 

#######################################################
BACNREASON_HEADER="X-Mundungus-Bacn-Reason: "

OLDVERBOSE=${VERBOSE:-off}
VERBOSE=on
######  Add reason header lines for selecting as bacn  #####
# remove the variable
BACNREASON

:0
* ^to:*(_dot_)alan\+crystal(_at_)clifford\(_dot_)example
{
  nl
  nl=${BACNREASON+"$NL"}
  BACNREASON="${BACNREASON}${nl}${BACNREASON_HEADER}#0001 Crystal Dive"
}

:0 E
* ^received:(_dot_)*reading(_at_)clifford(_dot_)example
* ^to:(_dot_)*alumni(_dot_)*(_at_)read\(_dot_)ac\(_dot_)uk
{
  nl
  nl=${BACNREASON+"$NL"}
  BACNREASON="${BACNREASON}${nl}${BACNREASON_HEADER}#0011 Reading alumni"
}

0 E
* ^to:(_dot_)*alan\+wanderlust(_at_)clifford\(_dot_)example
{
  nl
  nl=${BACNREASON+"$NL"}
  BACNREASON="${BACNREASON}${nl}${BACNREASON_HEADER}#0150 Wanderlust"
}



# Add reason headers and deliver bacn

# Add the bacn reason headers
:0 fhw
* ! BACNREASON ?? ^^^^
| formail -A "${BACNREASON}"

# deliver bacn
:0:
* ! BACNREASON ?? ^^^^
IN.bacn


VERBOSE=${OLDVERBOSE}
#######################################################


You can comment out the verbose stuff. You can put any text you want in 
BACNREASON_HEADER= but make sure there is a space after the colon. I see 
that the final delivery stuff is a tad inefficient - I do the same test 
twice, but never mind.

These recipes check for a match and put the text you want in the tag in a 
variable.  The E stops further tests.  The mail is tagged and delivered to 
IN.bacn if the variable is not empty.

If you notice syntax and recipes in this example from elsewhere, 
particularly from this list, that is because they probably are.


You get something like this in the header:

X-Mundungus-Bacn-Reason: #0130 Nikon


-- 
Alan

( Please do not email me AS WELL as replying to the list.  Please
  address personal email to alan+1@ as lists@ is not read. )

____________________________________________________________
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>