[H-GEN] Reading signed emails using OE

Michael Anthon michael at anthon.net
Tue Jun 3 23:48:23 EDT 2003


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

From: "Greg Black" <gjb at gbch.net>

>I wonder how it would go if you changed the sed substitute
>command to this:
>
>   's/.*boundary="\(.*\)".*/\1/'
>
>That seems to extract the correct marker for me on the set of
>test messages I tried; your version failed on some of them.  Of
>course, this might be an artifact of variant sed implementations
>(which I haven't investigated).  My sed version can be inferred
>from one of the "X-" headers.

It does seem to be working well enough although your response pointed out an
error in my original regex.  My current incantation is

BOUNDARY=`formail -x Content-Type -c | sed -e
's/.*boundary="\([^"]\+\)".*/\1/'`

This add the .* after the closing " for the boundary value and should
prevent failure when there is anything after the boundary value.

I was hesitant to use the regex as you wrote it (pretty much what I
originally had in my first pass) since I've been stung before with the
greediness factor in regex.  For example, suppose we had a header like

Content-Type: multipart/signed; boundary="Qo8f1a4rgWw9S/zY";
micalg="pgp-sha1"

Will the first .* in your regex match Qo8f1a4rgWw9S/zY, Qo8f1a4rgWw9S/zY";
micalg= or Qo8f1a4rgWw9S/zY"; micalg="pgp-sha1
I believe it probably matches the last one but I don't know that it is
always the case so I used [^"]+ instead.  You could probably also force the
greediness of the correct pattern as well to achieve the same result (or is
greediness just a perl thing? I can't find any reference to it in the
standard regex doco)

mca at belial:~$ cat sedtest | sed -e 's/.*boundary="\(.*\)".*/\1/'
Qo8f1a4rgWw9S/zY"; micalg="pgp-sha1

mca at belial:~$ cat sedtest | sed -e 's/.*boundary="\([^"]\+\)".*/\1/'
Qo8f1a4rgWw9S/zY

Have you got any examples of where my original pattern fails, and does the
new one fix those?

Cheers
Michael


--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list