17 Apr 2005 16:06
flattening continuation lines
Paul Fox <pgf <at> foxharp.boston.ma.us>
2005-04-17 14:06:38 GMT
2005-04-17 14:06:38 GMT
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
(Continue reading)
RSS Feed