1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#!/usr/bin/env perl
#
# $FML$
#
use strict;
use File::Basename;
use vars qw(%opts);
my $debug = defined $ENV{'debug'} ? 1 : 0;
use Getopt::Std;
getopts('d', \%opts);
my $dir = dirname($0);
$| = 1;
my $msg = shift @ARGV || "$dir/msg_mp";
use FileHandle;
my $fh = new FileHandle $msg;
my $header;
my $boundary;
my $content_type;
my $body;
while (<$fh>) {
s/\r\n$/\n/;
if (1 .. /^$/) {
$header .= $_;
if (/boundary=\"(.*)\"/) {
$boundary = $1;
}
if (/Content-Type: (\S+\/\S+\w)/) {
$content_type = $1;
}
}
else {
$body .= $_;
}
}
my $original_length = length($body);
use Mail::Message;
my $m = new Mail::Message {
content_type => ($content_type || 'multipart/mixed'),
boundary => $boundary,
content => \$body,
debug => 1,
};
$m->print;
my $mp = $m->get_first_plaintext_message ;
print "// first plain/text message\n";
$mp->print;
print "//\n";
debug( $mp );
exit 0;
sub debug
{
my ($m) = @_;
unless (defined $m) {
use Carp;
croak("debug gets non-object\n");
}
my $p;
my $total=0;
my $i = 0;
for ($p = $m; defined $p ; $p = $p->{ next }) {
my $size = $p->size;
my $h = $p->get_content_header;
$size += length($h) if defined $h;
$total += $size;
$i++;
print STDERR "--------- $i ---------\n";
print STDERR "num_p:", $p->num_paragraph, "\n\n";
next;
print STDERR "type: ", $p->get_content_type, "\n";
print STDERR " hdr:{", $h, "}\n";
print STDERR "body:{", $p->get_content_body, "}\n";
print STDERR "size: ", $size, " / $total (<= $original_length)\n";
print STDERR "\n";
sleep 3;
}
}
|