Hi!

TMimeDec does NOT ignore MIME preamble and epilogue, so it fails to decode
correctly complex multipart message from RFC 2049 Appendix A. Specifically,
when it sees ending boundary ("--boundary--") it starts another part.

Disabling preamble parsing as text/plain is very simple, just have to
check in OnHeaderEnd if the ContentType starts with "multipart/" - if so,
we have to ignore next "part". With preambles and epilogues of embedded
parts is far worse. Let's see the ProcessPartLine:

procedure TMimeDecode.ProcessPartLine; { ##ERIC }
var
    Len : Integer;
    t   : Integer;
    s   : String;            { ##ERIC }
begin
    { Check if end of part (boundary line found) }
    if (FCurrentData <> nil) and (FCurrentData^ <> #0) then begin
        s := LowerCase(StrPas(FCurrentData));
        if (s = FBoundary) then begin
                PreparePart;
                exit;
        end
        else if (s = (FBoundary + '--')) then begin
            FEndOfMime := TRUE;
            PreparePart;
            exit;
        end
        else begin
            for t := 0 to FEmbeddedBoundary.Count - 1 do begin
                if (s = FEmbeddedBoundary[t]) or
                   (s = (FEmbeddedBoundary[t] + '--')) then begin
                    { we now have to wait for the next part }
                    PreparePart;
                    exit;
                end
            end;
        end;
    end;
[..]  

What do we see? When we hit epilogue of *the message*, we get information
about that we're done with MIME (whatever that should mean...). We don't
get *any* information if we crossed the ending boundary ("--boundary--")
and start parsing epilogue. TMimeDec simply starts another part! My fix:

procedure TMimeDecode.ProcessPartLine; { ##ERIC }
var
    Len : Integer;
    t   : Integer;
    s   : String;            { ##ERIC }
begin
    { Check if end of part (boundary line found) }
    if (FCurrentData <> nil) and (FCurrentData^ <> #0) then begin
        s := LowerCase(StrPas(FCurrentData));
        if (s = FBoundary) then begin
                PreparePart;
                exit;
        end
        else if (s = (FBoundary + '--')) then begin
            FPartOpened := False; //phd
            TriggerPartEnd;       //phd
            exit;
        end
        else begin
            for t := 0 to FEmbeddedBoundary.Count - 1 do begin
                if s = FEmbeddedBoundary[t] then begin //phd
                    PreparePart; //phd
                    Exit; //phd
                end else if s=(FEmbeddedBoundary[t] + '--')) then begin 
                    FPartOpened := False; /phd
                    TriggerPartEnd; //phd
                    exit; //phd
                end
            end;
        end;
    end;
[..]  

And I propose that we throw away that FEndOfMime. From my point of view,
it's useless, and still eats that byte or four (if compiler aligns variables
on dword boundaries).

-- 
Piotr "Hellrayzer" Dalek
Author of ICS-Based Hellcore Mailer - an Outlook Express killer
http://www.hcm.prv.pl
[EMAIL PROTECTED]

----------------------------------------------------------------------
Najlepszy serwis MOTO w Polsce! >>> http://link.interia.pl/f18a8

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to