#!/usr/bin/perl

$u=0;

while(<>) {
	if($u==0 && /^Content-Type: text\/html; charset=\"iso-8859-1\"/) {
		$u=2;
	} elsif ($u=2 && s/^(Content-Transfer-Encoding:) base64/\1 8bit/) {
		print;
		loop1: while(<>) {print; if(/^$/) {last loop1;}}
		open(FH,'|-','mimencode -u');
		$brk=0;
		loop2: while(<>) {print FH; if(/^$/){if($brk){last loop2;}}else{$brk=1;}}
		close(FH);
		print;
	} elsif ($u=2 && s/^(Content-Transfer-Encoding:) quoted-printable/\1 8bit/) {
		print;
		loop1: while(<>) {
			if(/^--/) {last loop1;}
			s/\=[\012\015]*$//;
			s/\=([a-fA-F0-9]{2})/pack("C",hex($1))/eg;
			print;
		}
	} else {$u=0};
	print;
}