John Levine | 9 Jul 2011 05:15

Re: MIME headers in Procmail

>The 'milter' interface is expressly _designed_ to let client applications
>do things like that.  There are specific milter library calls to let you
>'add', 'delete', or 'replace' _any_ header,  Or to change the message
>body.

I don't use an MTA that supports milters and in any event, I don't
want to rewrite the message, since it still needs to be delivered.  I
want procmail to act as though the headers are pure UTF-8 when doing
the pattern matches.

R's,
John
Jostein Berntsen | 9 Jul 2011 08:46
Picon
Favicon
Gravatar

Re: MIME headers in Procmail

On 09.07.11,03:15, John Levine wrote:
> >The 'milter' interface is expressly _designed_ to let client applications
> >do things like that.  There are specific milter library calls to let you
> >'add', 'delete', or 'replace' _any_ header,  Or to change the message
> >body.
> 
> I don't use an MTA that supports milters and in any event, I don't
> want to rewrite the message, since it still needs to be delivered.  I
> want procmail to act as though the headers are pure UTF-8 when doing
> the pattern matches.
> 

Have you tried to pipe the "From", "To" and "Subject" headers through 
formail -x with "perl -MEncode -ne 'print 
encode("UTF8",decode("MIME-Header",$_))'" to encode the message? 

The perl script posted here previously in the thread should work nicely 
with a procmail rule as well:

http://people.eisenbits.com/~stf/fsd/download/conv2047/

Jostein
John Levine | 9 Jul 2011 18:19

Re: MIME headers in Procmail

>Have you tried to pipe the "From", "To" and "Subject" headers through 
>formail -x with "perl -MEncode -ne 'print 
>encode("UTF8",decode("MIME-Header",$_))'" to encode the message? 

I could do something like this:

:0 c
| formail -xsubject |perl -Mencode -ne 'print encode("UTF8",decode("MIME-Header",$_))' > /tmp/junk$$

SUBJ=`cat /tmp/junk$$`

and then do matches like

* SUBJ ?? pattern

but, uh, bletch.

For those that haven't been paying attention, I do NOT want to rewrite
the mail that gets delivered, since my MUAs handle MIME just dandy.

R's,
John
David W. Tamkin | 9 Jul 2011 23:43
Picon
Favicon

Re: MIME headers in Procmail

John Levine wrote:

> I could do something like this:
>
> :0 c
> | formail -xsubject |perl -Mencode -ne 'print encode("UTF8",decode("MIME-Header",$_))'>  /tmp/junk$$
>
> SUBJ=`cat /tmp/junk$$`
>
> but, uh, bletch.

Then wouldn't the foillowing do the job?  (Sorry, not sure how my mailer 
will wrap this, so I have to break the line in a way to get sane results.)

:0
SUBJ=| formail -xsubject |perl -Mencode -ne \
  'print encode("UTF8",decode("MIME-Header",$_))'

> and then do matches like
>
> * SUBJ ?? pattern

as you said?

At least you wouldn't have that nasty temp file.
John Levine | 10 Jul 2011 01:58

Re: MIME headers in Procmail

>Then wouldn't the foillowing do the job?  (Sorry, not sure how my mailer 
>will wrap this, so I have to break the line in a way to get sane results.)
>
>:0
>SUBJ=| formail -xsubject |perl -Mencode -ne \
>  'print encode("UTF8",decode("MIME-Header",$_))'
>
>> and then do matches like
>>
>> * SUBJ ?? pattern
>
>as you said?

You're right, that works. (Nobody ever said the procmail documentation
was any good.)  But it still fires up a shell, formail, and a copy of
perl, rather a lot of work, and you'd have to do it separately for
each header line you'd want to match.

R's,
John
Ruud H.G. van Tol | 10 Jul 2011 06:52
Picon

Re: MIME headers in Procmail

On 2011-07-10 01:58, John Levine wrote:
 > attribution dammit! wrote:

>> Then wouldn't the foillowing do the job?  (Sorry, not sure how my mailer
>> will wrap this, so I have to break the line in a way to get sane results.)
>>
>> :0
>> SUBJ=| formail -xsubject |perl -Mencode -ne \
>>   'print encode("UTF8",decode("MIME-Header",$_))'
>>
>>> and then do matches like
>>>
>>> * SUBJ ?? pattern
>>
>> as you said?
>
> You're right, that works. (Nobody ever said the procmail documentation
> was any good.)  But it still fires up a shell, formail, and a copy of
> perl, rather a lot of work, and you'd have to do it separately for
> each header line you'd want to match.

Too obvious: only call it if the message header contains non-ASCII, and 
make it do the full header in one call.

--

-- 
Ruud
John Levine | 10 Jul 2011 15:58

Re: MIME headers in Procmail

>> You're right, that works. (Nobody ever said the procmail documentation
>> was any good.)  But it still fires up a shell, formail, and a copy of
>> perl, rather a lot of work, and you'd have to do it separately for
>> each header line you'd want to match.
>
>Too obvious: only call it if the message header contains non-ASCII,

Then I have to do two versions of everything else in the procmail
file, one to match the plain subject (or whatever) line and one to
match the flattened variable.

> and make it do the full header in one call.

Keeping in mind that the goal is to have something that I can match
in subsequent recipes, please show sample code.  This doesn't do anything
useful, since you can't predict which order the headers will be in (it's
whatever order they are in the incoming message), and the perl module
won't pick up the MIME cruft unless it's the first thing on the first line:

:0 H
SUBJ=| formail -xsubject -xfrom |perl -MEncode -ne 'print encode("UTF8",decode("MIME-Header",$_))'

R's,
John
Ruud H.G. van Tol | 11 Jul 2011 10:07
Picon

Re: MIME headers in Procmail

On 2011-07-10 15:58, John Levine wrote:

John, you really need to keep the attribution, or you will get ignored 
yourself too.

>>> You're right, that works. (Nobody ever said the procmail documentation
>>> was any good.)  But it still fires up a shell, formail, and a copy of
>>> perl, rather a lot of work, and you'd have to do it separately for
>>> each header line you'd want to match.
>>
>> Too obvious: only call it if the message header contains non-ASCII,
>
> Then I have to do two versions of everything else in the procmail
> file, one to match the plain subject (or whatever) line and one to
> match the flattened variable.

Tsk. Just "normalize" the full mail header in an early step. After that, 
all of your recipes only see the "normalized" version of the header.

> This doesn't do anything useful,

You are whining again. Stop that. And take a holiday of at least a few 
weeks.

> since you can't predict which order the headers will be in (it's
> whatever order they are in the incoming message), and the perl module
> won't pick up the MIME cruft unless it's the first thing on the first line:

Tsk again. And again (some people need it at least thrice): filter the 
full mail header using Perl, and work it out from there.
(Continue reading)

John Levine | 12 Jul 2011 05:43

Re: MIME headers in Procmail

>You are whining again. Stop that. And take a holiday of at least a few 
>weeks.

Oh, all right.  Leaving for the Dordogne tomorrow, will be back around
the 24th.

R's,
John

PS: really.
David W. Tamkin | 10 Jul 2011 16:26
Picon
Favicon

Re: MIME headers in Procmail

Ruud H.G. van Tol wrote:

> On 2011-07-10 01:58, John Levine wrote:

>> You're right, that works. (Nobody ever said the procmail documentation
>> was any good.) But it still fires up a shell, formail, and a copy of
>> perl, rather a lot of work, and you'd have to do it separately for
>> each header line you'd want to match.
>
> Too obvious: only call it if the message header contains non-ASCII, and
> make it do the full header in one call.

And then, since the headerfield names are still there (formail -X would 
have kept them as well, but if you're not calling formail at all in order 
to save the formail and shell calls, they'll certainly be there), you can 
use procmail's internal parsing to extract SUBJ, TO, FROM, or whatever 
other variables you want, and then use them in subsequent conditions.

So we're down from firing up formail, a shell, and perl for each desired 
header to firing up perl once for each message that needs the work.
John Levine | 10 Jul 2011 18:28

Re: MIME headers in Procmail

>And then, since the headerfield names are still there (formail -X would 
>have kept them as well, but if you're not calling formail at all in order 
>to save the formail and shell calls, they'll certainly be there), you can 
>use procmail's internal parsing to extract SUBJ, TO, FROM, or whatever 
>other variables you want, and then use them in subsequent conditions.

Hm, this more or less seems to work.  Ugh.

:0 H
SUBJ=| formail -fXsubject -Xfrom |perl -MEncode -ne 'print encode("UTF8",decode("MIME-Header",$_))'

:0 ci
* SUBJ ?? Subject:\/.*
| echo "subject is $MATCH"

:0 ci
* SUBJ ?? From:\/.*
| echo "from is $MATCH"
David W. Tamkin | 11 Jul 2011 18:59
Picon
Favicon

Re: MIME headers in Procmail

John Levine wrote:

> Hm, this more or less seems to work.  Ugh.
>
> :0 H
> SUBJ=| formail -fXsubject -Xfrom |perl -MEncode -ne 'print encode("UTF8",decode("MIME-Header",$_))'

I know next to nothing about perl, but can't it discard the other lines 
besides Subject: and From: and save the calls to formail and the shell?

> :0 ci
> * SUBJ ?? Subject:\/.*
> | echo "subject is $MATCH"

Where is the output of echo going?  If you're writing it to the logfile,

  :0c
  * SUBJ ?? Subject:\/.*
  LOG="subject is $MATCH
"

will be a bit more streamlined.  I'd recommend that for "from is" as well, 
but also,

> :0 ci
> * SUBJ ?? From:\/.*
> | echo "from is $MATCH"

Just in case "From:" appears in the subject and Subject: precedes From:, 
you should left-anchor the regexp in that condition:
(Continue reading)


Gmane