Minor bug-fix you might want to apply by hand.

From: Bjarni R. Einarsson (
Date: Fim 21 Des 2000 - 17:13:07 UTC

Note: the following fix shouldn't break any of the standard testcases.

Also, you should remove the STDERR debug-line before updating your
sanitizer - I left it in there by accident. :-)

----- Forwarded message from "Bjarni R. Einarsson" <> -----

Date: Thu, 21 Dec 2000 17:10:17 +0000
From: "Bjarni R. Einarsson" <>
To: Michael Kellen
Subject: Re: Another Outlook MIME Problem (FIX)
X-Mailer: Mutt 0.95.4i

The following replacement for the DecodeBase64 routine in
should fix the problem with top-level Base64-encoded attachments getting
corrupted. This fix will be included in revision 1.34, so if you don't
want to hand-patch your sanitizer then just wait a few days... :-)

sub DecodeBase64
        my $reader = shift;
        my $line = shift;

        # This hacks the decoder to handle mangled Base64 text properly, by
        # properly ignoring white space etc. Note that this will lose the
        # last 1-3 bytes of data if it isn't properly padded. We also record
        # the encoded line-length, so we can re-encode stuff using the same
        # length.
        if (!$reader->{"DecodeBase64llen"})
                $line =~ s/[^A-Za-z0-9\/+\n=]+//gs;
                my $nlpos = int((3*(index($line, "\n") + 1)) / 4);
                $line =~ s/\n//gs;

                my $llen = int((3*length($line)) / 4);
                my $t = $llen;
                $t = $nlpos if (($nlpos < $llen) && ($nlpos > 0));

                $reader->{"DecodeBase64llen"} = $t;
                print STDERR "Set llen to $t (data=$llen, nl=$nlpos)\n";
                $line =~ s/[^A-Za-z0-9\/+=]+//gs;
        $line = $reader->{"DecodeBase64"} . $line;
        $line =~ s/^((?:....)*)(.*?)$/$1/s;
        $reader->{"DecodeBase64"} = $2;

        return decode_base64($line);

Bjarni R. Einarsson                           PGP: 02764305, B7A3AB89                -><-    

Check out my open-source email sanitizer:

-- This mailing list's home page is: There you can find subscription instructions and possibly an archive. is a free Icelandic mailing list service.

hosted by