procmail
[Top] [All Lists]

Re: Folding E-mail Headers

2006-04-23 09:58:50
Hi Craig,

What about using "fold -w 72" on your E-Mails?
It is not realy funny to read your message on a Text-terminal...


Am 2006-04-18 17:51:56, schrieb Craig:
Hi there,

Have tried to figure this out from reading the man page for "fold",
searching through the archives of this list, and a general Web search,
but haven't had any success. Almost all of the hits when searching for
"fold" relate to redirecting messages to pagers, and that's not what
I'm trying to do here.

I would like to use Procmail to (among other things) insert an "X-"
header with a relatively long string of text (including the header name
it's 575 characters) into messages passing through a recipe. I've had
no problems doing this, but I'd like to fold this long line to comply
with RFC 2822, which suggests folding after 78 characters.

I have this in my recipe, which inserts the header without folding it:

:0 fh w
| formail -i "X-My-Header: Long string of text here."

You should know, that folding a Header require:

X-Header: some long text here which should be folded after certain widht of 
characters whitout breaking whole words into parts...

Would be

X-Header: some long text here which should be folded after certain
<tab><space>width of characters whitout breaking whole words into parts...

So what you could do is 

----8<-------------------------------------------------
#!/bin/bash

HEADERNAME="X-Header:"
LONGTEXT="some very long text here which should be folded after certain width 
(e.g. 70) of characters whitout breaking whole words into parts..."


(echo "$HEADERNAME $LONGTEXT" |fold -s -w 70) |
while read VAL ; do
  if [ "`echo \"$VAL\" |grep \"$HEADERNAME \"`" != "" ] ; then
    echo "$VAL" >>/tmp/TMPFILE
  else
    echo "       $VAL" >>/tmp/TMPFILE
  fi
done

HEADER=`cat /tmp/TMPFILE`

cat $1 |formail -i "$HEADER"

rm -f /tmp/TMPFILE
----8<-------------------------------------------------

which I have tested and it is working

I'm guessing that I need to pipe this into fold somehow, but I'm not
"getting" how to do it. The fold syntax, if the header I want to
insert is in a file, would be:

fold -s -w78 x_my_header.txt

Which is correct

I could assign this to a variable in the recipe, which would make
things easier, like this:

x_my_header = 'X-My-Header: Long string of text here.'

OK

But trying:

fold -s -w78 $x_my_header

"fold" NEED an inputfile OR STDIN which mean:

    fold -s -w78 $FILE
or
    echo "$STRING" |fold -s -w78

causes fold to choke. Plus, of course, I still haven't figured out
where exactly this should go in the Procmail recipe relative to
formail, so I'm not getting anywhere.

Any pointers in the right direction with respect to getting fold to
fold the long header and then getting formail to take the output from
fold and insert the header would be much appreciated. Thanks very much.


Craig

Greetings
    Michelle Konzack


-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
                   50, rue de Soultz         MSM LinuxMichi
0033/3/88452356    67100 Strasbourg/France   IRC #Debian (irc.icq.com)


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>