#!/usr/bin/perl # anti-outlook, wycina zalaczniki, html itd. # wojtekka@bydg.pdi.net, 20000912 $line = <>; push @orig_header, $line; chomp ($line); while ($line) { $next_line = <>; push @orig_header, $next_line; chomp ($next_line); while ($next_line =~ /^\s/) { $line .= $next_line; $next_line = <>; push @orig_header, $next_line; chomp ($next_line); } if ($line =~ /^Content-type:\s*([a-z\-\/]*)(.*)$/i) { $content = $1; $boundary = ""; $foo = $2; if ($foo =~ /boundary\s*=\s*(.*)/) { $foo = $1; if ($foo =~ /^\"(.*)/) { $foo = $1; if ($foo =~ /(.*[^\\])\"/) { $boundary = $1; } else { $boundary = $foo; } $boundary =~ s/\\(.)/$1/g; } else { $foo =~ s/\;.*//; $boundary = $foo; } } } push @header, $line; if ($line =~ /^$/) { break; } $line = $next_line; } if ($content =~ m|text/plain|i) { print @orig_header; while (<>) { print $_; } exit; } if ($content =~ m|multipart/mixed|i || $content =~ m|multipart/alternative|i) { MAIN: while (<>) { if (/^--$boundary/) { $line = <>; chomp ($line); while ($line) { $next_line = <>; chomp ($next_line); while ($next_line =~ /^\s/) { $line .= $next_line; $next_line = <>; chomp ($next_line); } if ($line =~ /^$/) { break; } if ($line =~ /Content-type:\s*([a-z\-\/]+)(.*)/i) { $content = $1; $content_params = $2; } if ($line =~ /Content-transfer-encoding:\s*(.*)/i) { $encoding = $1; } $line = $next_line; } if ($content =~ m|text/plain|i) { while (<>) { if (/^--$boundary/) { last MAIN; } push @body, $_; } break MAIN; } else { exit 1; } } } $indent = 0; foreach $line (@orig_header) { if ($indent && $line =~ /^[ \t]/) { next; } $indent = 0; $line =~ s|multipart/[a-z]+|text/plain|; if ($line =~ /^Content-type/i) { $line = "Content-Type: $content$content_params\n"; $indent = 1; } if ($line =~ /^Content-transfer-encoding/i) { $line = "Content-Transfer-Encoding: $encoding\n"; $encoding = ""; $indent = 1; } if ($line =~ /^\n$/) { if ($indent) { print "Content-Transfer-Encoding: $encoding\n"; } print "X-Notice: All parts except first text/plain have been removed.\n"; } print $line; } print @body; exit; } exit 1;