#!/usr/bin/perl -w
use MIME::Base64 qw(decode_base64);
while(<>){
    unless (/Content-Transfer-Encoding:\s*base64/i){
        print;
    }else{
        s/$/ (decoded)/;
        print;
        $sigil=0;
        while(<>){
            print;
            if (/^$/){ #blank line
                $sigil=1;
                last;
            }
        }
        die unless $sigil;
        $sigil=0;
        $line="";
        while(<>){
            if(/^--/){
                $sigil=1;
                print "",decode_base64($line),"\n\n";
                print;
                last
            }
            $line.=$_;
        }
        die unless $sigil;$sigil=0;
    }
}
