procmail
[Top] [All Lists]

Re: forwarding to two places, and appending info to header

2002-11-21 13:55:26
Terry asked:
    # check the "live" list for approved addresses and header keywords
    :0c:
    * ? formail -x"From" -x"From:" -x"Sender:" -x"Reply-To:" -x"Return-Path:" 
-x"To:" -x"Received:" -x"Subject:" | grep -iF --file=live.txt
    ${MAILDIR}/regular.mail

    # Also forward it to web mail (how to combine both actions?)
    :0
    * ? formail -x"From" -x"From:" -x"Sender:" -x"Reply-To:" -x"Return-Path:" 
-x"To:" -x"Received:" -x"Subject:"| grep -iF --file=live.txt
    !blisterpeanuts(_at_)yahoo(_dot_)com

This works fine, but is there a way I can refactor these two actions
into one simple statement?

Yup. You can either use the "A" flag (see the procmailrc manpage for
details) on the second recipe instead of repeating the condition:

  :0 c:
  * ? formail ...
  ${MAILDIR]/regular.mail

  :0 A
  ! blisterpeanuts(_at_)yahoo(_dot_)com

or use braces:

  :0
  * ? formail ...
  {
    :0 c:
    ${MAILDIR]/regular.mail

    :0
    ! blisterpeanuts(_at_)yahoo(_dot_)com
  }

My second question concerns modifying the subject line.  Yahoo lets
you filter on subject lines but nothing else, so I figure if I can
append some string to the subject line of my forwarded mail, I can
filter that into the inbox and filter everything else into bulkmail.
Hence:
       Subject:  Your Verizon Bill
would become
       Subject:  Your Verizon Bill [*FWD*]
Or something similar.  How do you do this using the ! notation as
described above?  I've tried -I"Subject: ${SUBJECT} ${TAG}" but it
doesn't work in that context.  What does work (but is useless to me)
is the following:

:0fhw
| formail -I "Subject: ${SUBJECT} ${SUBJECT_TAG}"

It's not useless: do that first, then forward the modified
message. Thus (assuming that SUBJECT and SUBJECT_TAG have been set
already):

  :0 c:
  * ? formail ...
  ${MAILDIR]/regular.mail

  # Before forwarding, run the message through formail to add the
  # tag to the subject line.

  :0 A fhw
  | formail -I "Subject: ${SUBJECT} ${SUBJECT_TAG}"

  # From this point on, we're not dealing with the original message
  # any longer; the subject line has been changed.

  :0 A
  ! blisterpeanuts(_at_)yahoo(_dot_)com

The same with braces is left as an exercise to the reader. :-)

/HW

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail