4
use Test::More tests => 31;
13
# Set the counter, for filenames:
16
# Check and clear the output directory:
17
my $DIR = "./testout";
18
((-d $DIR) && (-w $DIR)) or die "no output directory $DIR";
19
unlink globby("$DIR/[a-z]*");
22
#------------------------------------------------------------
24
#------------------------------------------------------------
34
#------------------------------------------------------------
36
@MyParser::ISA = qw(MIME::Parser);
38
my ($parser, $head) = @_;
40
# Get the recommended filename:
41
my $filename = $head->recommended_filename;
42
if (defined($filename) && $parser->evil_filename($filename)) {
43
## diag("Parser.t: ignoring an evil recommended filename ($filename)");
44
$filename = undef; # forget it: it was evil
46
if (!defined($filename)) { # either no name or an evil name
48
$filename = "message-$Counter.dat";
51
# Get the output filename:
52
my $outdir = $parser->output_dir;
57
#------------------------------------------------------------
59
$parser = new MyParser;
60
$parser->output_dir($DIR);
62
#------------------------------------------------------------
63
##diag("Read a nested multipart MIME message");
64
#------------------------------------------------------------
65
open IN, "./testmsgs/multi-nested.msg" or die "open: $!";
66
$entity = $parser->parse(\*IN);
67
ok($entity, "parse of nested multipart");
69
#------------------------------------------------------------
70
##diag("Check the various output files");
71
#------------------------------------------------------------
72
is(-s "$DIR/3d-vise.gif", 419, "vise gif size ok");
73
is(-s "$DIR/3d-eye.gif" , 357, "3d-eye gif size ok");
75
ok(-s "$DIR/message-$msgno.dat", "message $msgno has a size");
78
#------------------------------------------------------------
79
##diag("Same message, but CRLF-terminated and no output path hook");
80
#------------------------------------------------------------
81
$parser = new MIME::Parser;
82
$parser->output_dir($DIR);
83
open IN, "./testmsgs/multi-nested2.msg" or die "open: $!";
84
$entity = $parser->parse(\*IN);
85
ok($entity, "parse of CRLF-terminated message");
87
#------------------------------------------------------------
88
##diag("Read a simple in-core MIME message, three ways");
89
#------------------------------------------------------------
90
my $data_scalar = <<EOF;
91
Content-type: text/html
93
<H1>This is test one.</H1>
96
my $data_scalarref = \$data_scalar;
97
my $data_arrayref = [ map { "$_\n" } (split "\n", $data_scalar) ];
99
$parser->output_to_core('ALL');
100
foreach my $data_test ($data_scalar, $data_scalarref, $data_arrayref) {
101
$entity = $parser->parse_data($data_test);
102
isa_ok($entity, 'MIME::Entity');
103
is($entity->head->mime_type, 'text/html', 'type is text/html');
105
$parser->output_to_core('NONE');
108
#------------------------------------------------------------
109
##diag("Simple message, in two parts");
110
#------------------------------------------------------------
111
$entity = $parser->parse_two("./testin/simple.msgh", "./testin/simple.msgb");
112
my $es = ($entity ? $entity->head->get('subject',0) : '');
113
like($es, qr/^Request for Leave$/, " parse of 2-part simple message (subj <$es>)");
116
# diag('new_tmpfile(), with real temp file');
120
local $parser->{MP5_TmpToCore} = 0;
121
$fh = $parser->new_tmpfile();
123
ok( ! $@, '->new_tmpfile() lives');
124
ok( $fh->print("testing\n"), '->print on fh ok');
126
ok( $fh->seek(0,0), '->seek on fh ok');
128
is( $line, "testing\n", 'Read line back in OK');
131
# diag('new_tmpfile(), with in-core temp file');
135
local $parser->{MP5_TmpToCore} = 1;
136
$fh = $parser->new_tmpfile();
138
ok( ! $@, '->new_tmpfile() lives');
139
ok( $fh->print("testing\n"), '->print on fh ok');
141
ok( $fh->seek(0,0), '->seek on fh ok');
143
is( $line, "testing\n", 'Read line back in OK');
146
# diag('new_tmpfile(), with temp files elsewhere');
150
local $parser->{MP5_TmpDir} = $DIR;
151
$fh = $parser->new_tmpfile();
153
ok( ! $@, '->new_tmpfile() lives');
154
ok( $fh->print("testing\n"), '->print on fh ok');
156
ok( $fh->seek(0,0), '->seek on fh ok');
158
is( $line, "testing\n", 'Read line back in OK');
161
# diag('native_handle() on various things we might get');
163
my $io_file_scalar = IO::File->new( do { my $foo = ''; \$foo }, '>:' );
164
ok( MIME::Parser::Reader::native_handle( $io_file_scalar ), 'FH on scalar is OK');
166
my $io_file_real = IO::File->new_tmpfile();
167
ok( MIME::Parser::Reader::native_handle( $io_file_real ), 'FH on real file is OK');
169
my $globref = \*STDOUT;
170
ok( MIME::Parser::Reader::native_handle( $globref ), 'globref is OK');
174
# diag('tmp_recycling() exists again, as a no-op');
176
my $rc = $parser->tmp_recycling(1);
177
is( $rc, undef, 'tmp_recycling no-op method returned undef');