Indy 10 - problem in IDCoderHeader DecodeHeader

Giganews Newsgroups
Subject: Indy 10 - problem in IDCoderHeader DecodeHeader
Posted by:  Andrew Lockwood (andrew.lockwo…@fsbdial.co.uk)
Date: Sat, 3 Jul 2004

We (unfortunately!) received the following e-mail which the current
DecodeHeader function cannot handle correctly.

The problem is that although the Subject and From appear to be encoded, they
are not.  This puts the DecodeHeader into an endless loop.

I have written the following code to deal with this particular problem, but
because I do not know enough about e-mail formats, I do not know how useful
it would be.

    function DecodeHeader(Header: string):string;

        ..............
        ..............
        ..............

                //now Substring needs to end with '?=' otherwise give up!
{Do not Localize}
                if Copy(substring,Length(substring)-1,2)<>'?=' then    {Do
not Localize}
                  begin
                    EncodingFound := false;
                  end;
              end

      MY ADDITIONAL CODE

            else // AML - added to cope with messages that appear to be
encoded, but actually are not.
              begin
                substring := Header;
                for i := 1 to 3 do
                  begin
                    l := Pos('?', substring);  {Do not Localize}
                    substring := Copy(substring, l+1, Length(substring) - l
+ 1 );
                    if i = 1 then
                      begin
                        HeaderCharSet := Copy(substring, 1, Pos('?',
substring)-1)  {Do not Localize}
                      end
                    else if i = 2 then
                      begin
                        HeaderEncoding := copy(substring,1,1);
                      end;
                  end; // for i :=

                // check to see if ?= are also somewhere in the string -
normally they would be at the end, but not always ...
                l := Pos('?=', substring);
                if l > 0 then // ?= found
                  begin
                    if length(substring) > l + 1 then
                      substring := copy(substring, 1, l - 1) +
copy(substring, l + 2, length(substring))
                    else
                      substring := copy(substring, 1, Length(substring) -2);
                  end;
                header := substring;
              end;

ived: from 212.176.41.6 by newserver ([192.168.1.100] running VPOP3)
with ESMTP for <ma…@acousticdesign.co.uk>; Thu, 24 Jun 2004 21:19:47 +0100
Received: (qmail 9537 invoked by uid 514); 24 Jun 2004 20:08:55 -0000
X-Virus-Scan: Scanned by clamdmail 0.15 on mail.rin.ru (no viruses); Fri, 25
Jun 2004 00:08:56 +0400
Received: from unknown (HELO localhost) (127.0.0.1) by localhost with SMTP;
24 Jun 2004 20:08:54 -0000
Content-type: text/plain;charset=koi8-r;
Date: Fri, 25 Jun 2004 00:08 +0400
Content-transfer-encoding: quoted-printable
Mime-version: 1.0
X-sender-ip: 81.199.85.145
Return-path: <primestim…@rin.ru>
To: ospectra37…@netscape.net
From: =?KOI8-R?Q?Muhammed Abacha?= <primestim…@rin.ru>
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on mail.rin.ru
X-Spam-Level: ****
X-Spam-Status: No, hits=4.9 required=5.0
tests=BAYES_01,NIGERIAN_BODY1,NIGERIAN_BODY2,NIGERIAN_BODY3 autolearn=no
version=2.63 * -1.5 BAYES_01 BODY: Bayesian spam probability is 1 to 10% *
[score: 0.0692] *  0.7 NIGERIAN_BODY2 Message body looks like a Nigerian
spam message 2+ *  5.0 NIGERIAN_BODY1 Message body looks like a Nigerian
spam message 1+ *  0.7 NIGERIAN_BODY3 Message body looks like a Nigerian
spam message 3+
Message-Id: <VPOP31.5.0g.20040624211947.536.1e.1.006e9325@newserver>
X-Server: VPOP3 V1.5.0g - Registered
Subject: =?KOI8-R?Q?Please Reply me soonest?=

      VERY URGENT AND STRICTLY CONFIDENTIAL BUSINESS PROPOSAL.

Hope this is useful.

Andrew Lockwood

Replies