procmail
[Top] [All Lists]

Re: Using Formail to remove headers

2005-08-01 04:12:49
On Sun, Jul 31, 2005 at 06:19:12PM -0500, David W. Tamkin wrote:

Dallman suggested to Stephen,

One way: Save the headers you want into vars, remove all headers,
put the headers you want back.

  :0
  * ^\/From:.*
  { H_FROM = $MATCH }


  :0
  * ^\/Subject:.*
  { H_SUBJ = $MATCH }

 [. . . .]


  :0
  | formail -I ""         \
            -I "$H_FROM"  \
            -I "$H_SUBJ"  \
            -I "$H_CTYPE" \
            -I "$H_MIME"  \
            -I "$H_CTE"   \
            -I "$H_DISPO" \
  | $SENDMAIL $SENDMAILFLAGS -t someone(_at_)somewhere

Oy.  Why all the saving into variables?

  :0
  | formail -kz -X From: -X Subject: -X Content-Type: \
    -X MIME-Version: -X Content-Transfer-Encoding: \
    -X Content-Disposition: | \
    "$SENDMAIL" $SENDMAILFLAGS -t someone(_at_)somewhere(_dot_)else

Yes, very clever; thanks, David.  I actually tried with the -k
flag along with the -r flag, as my first idea.  I couldn't figure
out how to get -k not to prepend a quote character on the body
lines, though, so I gave up on that idea.  I think your -z switch
is pushing what otherwise would be a space back over to the left
margin?  Good.  Anyway, I wasn't thinking at the time that formail
would have read in the original headers, anyway, though, so know
what their contents is, even though we are deleting them in the
same action.  Good thinking.

As for the OP's issue with the From header's being the original
user, the solution for him is to use the -f option with sendmail,
if his system will honor it.  (Mine does.)

  | "$SENDMAIL" "$SENDMAILFLAGS" -f "$MYADDRESS" -t

The quotes aren't really necessary, as you implied in a follow-up
message.  But I have quotes around "$SENDMAILFLAGS" in working
operation, and it does not cause a problem; so your inference
in that companion posting about the quote marks there being an
issue does not seem to be the case.  Do you have other experience
with that?

Dallman

____________________________________________________________
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