procmail
[Top] [All Lists]

Re: Dekoding eight-bit characters in headers

1997-05-09 10:07:00
Philip Guenther writes on 8 May 1997 at 14:27:39
"J. Daniel Smith" <DanS(_at_)bristol(_dot_)com> writes:
Philip Guenther writes on 19 April 1997 at 18:55:26
Robin S Socha <uzs8kb(_at_)uni-bonn(_dot_)de> writes:
On Fri, 18 Apr 1997, Philip Guenther wrote:
I seem to be one of the lucky few that never get to enjoy the interesting
recipes ;-/

 >If you don't have libwww, just perl5, then the following _should_ work:
[...]
   :0 fh
   * =\?ISO-8859-[0-9]+\?Q\?
[...]
"formail" option is the best place to deal with this, although I can
see that adding smarts about charsets and the like could add a fair
amount of overhead.

The above decoding is actually incorrect (it fails several cases
[...]
Adding the above capabilities to formail is totally inappropriate, as

While I understand the reasons for not wanting to do this in
formail...I find that "formail" is handy utility and have used it in
several other shell scripts (i.e., not just in my ~/.procmailrc file).
By way of example, I've included a quick-and-dirty implementation of
"frm" (normally provided with Elm I think).

"formail -czx" lets you easily get the contents of any header field,
it sure would be convenient at times if "formail -MIME -czx" or
something could decode that field as well.  This way, my "frm" program
would print out the decoded Subject: and From: fields.

But given all the complexities of doing this correctly (the ISO-8859-*
cases are easy I guess--just a 7 to 8-bit conversion, not so for other
charsets) it's probably best left to a tool better suited for the job.

   Dan
------------------- message is author's opinion only ------------------
J. Daniel Smith <DanS(_at_)bristol(_dot_)com>        
http://www.bristol.com/~DanS
Bristol Technology B.V.                   +31 33 450 50 50, ...51 (FAX)
Amersfoort, The Netherlands               {info,jobs}(_at_)bristol(_dot_)com
-----
#!/bin/ksh
if [ "$1" != "" ] ; then
   formail -cXFrom: -XSubject: | exec awk -f $1
else
   prog=`basename $0`
   awkf=/tmp/$prog_awk_$$
   cat <<\EOF >$awkf
BEGIN {from = subject = ""; }
{
  if ($1 == "From:") {
    from = substr($0, length($1) + 2)
    if (i = index(from, "<"))
    {
       from = substr(from, 1, i-1);
       if (i = index(from, "\""))
         from = substr(from, 2)
       if (i = index(from, "\""))
         from = substr(from, 1, i-1)
    }
    else if (i = index(from, "("))
    {
      from = substr(from, i+1);
      if (i = index(from, ")"))
         from = substr(from, 1, i-1);
    }
    if (from == "")
      from = $2
  }
  else if ($1 == "Subject:") subject = substr($0, length($1) + 2)
  else 
     subject = subject $0
}
END {
   if ((from != "") || (subject != ""))
     printf "%-20s\t%s\n", from, subject
}
EOF
   formail -s $0 $awkf < /usr/mail/$LOGNAME
   exec rm -f $awkf
fi

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