procmail
[Top] [All Lists]

Re: Problem with missing "Message-ID:"

2005-04-28 09:09:29
On Thu, Apr 28, 2005 at 04:07:34PM +0200, Michelle Konzack wrote:

Am 2005-04-28 15:21:21, schrieb Ruud H.G. van Tol:
Klaus Johannes Rusch schreef:

 |/usr/bin/perl5 -n -p -e 's/^Message-Id: (.*)$/Message-Id: <$1>/'

Aaargh, please learn formail.

But Formail wiil remove the "Message-ID:" Header and write a new one.
I want to keep the "Message-ID" and add only the "< >" to it.

Ruud already showed what he had in mind.  No perl, no sed, no
formail, just procmail to grab the header and test it.  But his
comment to Klaus was for *replacing* the existing bad Message-Id.

In that case we're not using formail to throw out the existing
Message-Id.  As the man page says, a new one will only be generated
if there wasn't one to begin with.

One could also just use formail to extract Message-Id like any
other header:

 5:10pm [~/Mail] 377[0]> formail -zx Message-Id < $SPAMPLE   
<03n502517105768tresco(_dot_)net(_at_)tresco(_dot_)net>

Presuming the Message-Id was defective -- I'll edit $SPAMPLE and
make it so -- then:

  H_MSGID = `formail -zx Message-Id`

  :0 h wf
  * ! H_MSGID ?? ^^<.*>^^
  | formail -i Message-Id "<$H_MSGID>"


That's not bad, but it's two calls to formail.  We only need one,
actually, as Ruud showed.  Here's how I might do it:
  
  :0 h fw   # in brackets just below are caret, space, & tab
  * ^Message-Id:.*\/[^  ]+
  * ! MATCH ?? ^^<.*>^^
  *   MATCH ?? ()\/[^><]+
  | formail -i "Message-ID: <$MATCH>"

(Tested.)


But why perl if

    |sed 's/^Message-Id: (.*)$/Message-Id: <$1>/'

Because we don't need anything more than formail, practically
speaking.  (There's a way to do it with only procmail, as Ruud
knows, but something like the above is the best practical
compromise.)  This type of task is exactly what formail was
designed to do: manipulate headers!

-- 
dman

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