nmh-workers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nmh-workers] flattening continuation lines


From: Paul Fox
Subject: [Nmh-workers] flattening continuation lines
Date: Sun, 17 Apr 2005 10:06:38 -0400

i have what feels like a simple problem.

i want to post-process the output of mhbuild to add a "Content-disposition"
header after any Content-type header that matches some criteria.

i have this pretty much working, with the following:

    #!/bin/sh

    # add a Content-disposition field for every Content-Type that ends
    # in "name=<filename>".  Content-disposition is always attachment,
    # and filename is duplicated.

    draft=$1
    cat $1 |
        mhbuild - |
        sed 's/^Content-Type:.* name=\([^;= ]*\)$/&\
    Content-disposition: attachment; filename=\1/' >$1.new && \
        mv $1.new $1

but this will of course break if the Content-type header spans
multiple lines, if the first of those lines happens to match my
pattern.  so i'd like to flatten continuation lines before running
sed.  i've found jerry peek's little sed script to flatten such
lines:

    function join_header_continuations()
    {
       sed -n -e '
        /^$/,$p

        1,/^$/ {
          # Join continuation lines:
          /^[   ]/ {
            x
            G
            s/\n[ ]*/ /
            h
            b
          }
          # This is a non-continuation line.
          # Hold it and output previous line
          # (except line 1, when nothing is held):
          x
          1!p
        }
        '
    }

but i can't seem to modify this in a way that it will a) flatten
continuations in the headers, _and_ b) leave the rest of the file
untouched.

does anyone have a solution?  i'm happy to hear about alternate
solutions for any part of my problem -- adding Content-disposition,
getting mhbuild to not split long headers in the first place, or
the sed question at the end...

any help appreciated...

paul
=---------------------
 paul fox, address@hidden (arlington, ma, where it's 57.0 degrees)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]