sub scan_mail { my $mailref = shift; $$mailref =~ s/\012\.\./\012\./g; # un-byte-stuff my $mail = Email::Simple->new($$mailref); if ($mail->header("Content-type") =~ /Multipart\/Alternative/i) { # seperate the parts my ($boundary) = $mail->header("Content-type") =~ /boundary=\"(.*?)\"/; my $body = $mail->body; my @part = split /\-\-$boundary\n/, $body; #find the part that's plain text foreach (@part) { next if (!/text\/plain/) ; $body = $_ ; last; } #Change the messages headers and remove them from the message # This has gotten a bit ugly again, but it works again while ($body =~ /(^Content.*?): (.*)\n/mig) { my ($header,$content, $extra_content) = ($1,$2); if ($content =~ /\;/) { ($extra_content) = $body =~ /\G^(.*)$/m; } $mail->header_set($header, $content.$extra_content); $body =~ s/$header: $content\n$extra_content//; } #finish up and put things back where they go $mail->body_set($body); } $$mailref = $mail->as_string; $$mailref =~ s/\012\./\012\.\./g; # byte-stuff }