procmail
[Top] [All Lists]

Re: Separate pipes for header and body?

1998-05-20 01:05:42
On Tue, 19 May 1998 23:59:55 +0200, Martin Schulze
<joey(_at_)kuolema(_dot_)Infodrom(_dot_)North(_dot_)DE> wrote:
If you want to mix up header and body I think you'll need to pipe
the whole thing into a script.  I might be mistaken.
:0 fw:
| pipe-for-header-and-body
pipe-for-header-and-body
#! /bin/sh
tmp=temp-file
cat - > $tmp
cat $tmp | sed '/^$/,$d' # This is the header
echo                     # This divides header from body
cat $tmp | sed '1,/^$/d' # And this is the body, voila

Well, since you're using a temp file anyway, why not use two of them? 
Then you don't have to split out the stuff you just had joined
together for you:

    LOCKFILE=/tmp/$$.1.lock
    :0b
    | cat >/tmp/$$.1
    :0hfw
    | script-which-reads-stdin-for-header-and-gets-body-from /tmp/$$.1 ;\
      rm /tmp/$$.1
    LOCKFILE=

Dirk's fundamental questions, about how to replace uuencode in the
body, for example, still lend themselves to separate filtering if I
read them correctly. This is just pseudocode, and above all
illustrates how this is not so much a Procmail problem:

    :0fwh
    | mangle-header

    :0fwb  # I had a typo in my original response; forgot the f flag
    | replace-uuencode-if-present

There is a program called Emil which can do some replacing of various
encoded types (for example, uuencode to MIME) which might be helpful
here. Anyway, it all boils down to shell scripting tasks, many of
which have repeatedly been discussed on this list. 

On Tue, 19 May 1998 12:21:17 +0200 (SAT), Dirk Laurie
<dirk(_at_)calvyn(_dot_)puk(_dot_)ac(_dot_)za> wrote:
I get a lot of in-house mail created on a system (let's call it MSW) that
I myself don't like and don't use, so I make my ID on MSW (which I never
log into) forward all messages to my workstation.  Among the many demerits
of MSW are: the original message is enclosed in a wrapper that makes the
message look as if I sent it from that system; I get a full list of all
100 other recipients on the "To:" line; the contents may be a UUencoded
binary of one MSW's own, eccentric, incompatible word-processing files.
I wish to edit the header so the original sender is restored and the
long list of recipients is removed, and join it to the body if that
body is readable, and then put it in some mail folder.  If the body 
is one of those binaries, I wish to save the body only under a new
name in some directory where I can look at it later with appropriate
software.

An example message to look at would be helpful before any reasonably
good attempts at solving this can be made, but let's give it a shot
anyway. 

    # Replace the wrapper's From: line with something we glean out of
    #  the body, i.e. the wrapped message. This will grab the first
    #  line in the body of the wrapper matching the regular
    #  expression, putting whatever matches the part after \/ into
    #  the MATCH pseudovariable which we then use in the filter
    # The To: line is replaced with a simpler one of our own

    :0fwBh  # Replace the From: line with something we glean out of the body
    * ^\/From:.*
    | formail -I "$MATCH" -I "To: dirk(_at_)calvyn(_dot_)puk(_dot_)ac(_dot_)za"

I don't exactly understand the part about "joining" the body with the
headers. I assume you want the wrapped message's headers to the parts
that they are applicable, but I'm wondering if this whole thing would
be easier if you just took whatever is at the top of the body (as long
as it looks like it's a bunch of headers) and replace the original
headers with that instead. Then you don't have to do the above formail
stuff either.

    :0fwB  # Do this if the body has at least two header-ish lines at the top
    * ^^([a-z][-a-z]+[a-z]:.*$)([a-z][-a-z]+[a-z]:.*$)
    | sed -e '1,/^$/d'

Of course, if MSW does some nastier wrapping (such as adding a footer
as well, or MIME-encapsulating it all [which actually is less nasty
than using proprietary encodings, no matter what they say]) you should
construct a decoder for this format and feed the whole message to this
decoder instead. I suppose the decoder program could take care of all
the reformatting you want while you're at it.

If that's not a good solution for you, replacing uuencoded bodies with
something more readable should probably be attempted with one of the
existing decoder programs. Like I said, Emil is one (it's old and
clunky and probably has a lot of stuff you don't need, but it's there
if you want it) but perhaps something you already use for actually
decoding the stuff yourself could be used instead.

Hope this helps,

/* era */

-- 
 Paparazzi of the Net: No matter what you do to protect your privacy,
  they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>