File: 58clone.t

package info (click to toggle)
libmail-box-perl 2.117-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,828 kB
  • ctags: 1,564
  • sloc: perl: 23,381; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env perl
#
# Test cloning messages
#

use strict;
use warnings;

use lib qw(. .. tests);
use Tools;

use Test::More tests => 10;
use IO::Scalar;
use Mail::Address;

use Mail::Message;
use Mail::Message::Construct;
use Mail::Message::Body::Lines;
use Mail::Message::Body::Multipart;
use Mail::Message::Body::Nested;

my $p1 = Mail::Message::Body::Lines->new
 ( data      => [ "line of text in part 1" ]
 , mime_type => 'text/plain'
 );

my $p2 = Mail::Message::Body::Lines->new
 ( data      => [ "line of html in part 2" ]
 , mime_type => 'text/html'
 );

my $p3 = Mail::Message::Body::Lines->new
 ( data      => [ "I know this is not postscript" ]
 , mime_type => 'application/postscript'
 );

my $p4 = Mail::Message::Body::Nested->new
 ( nested => $p3
 );

my $mp = Mail::Message::Body::Multipart->new
 ( parts => [ $p1, $p2, $p4 ]
 );

my $msg = Mail::Message->buildFromBody
 ( $mp
 , To   => 'you@home.com'
 , From => 'me@perl.org'
 );

#$msg->printStructure(\*STDERR);
ok(!defined $msg->partNumber, 'part number');
my @parts = $msg->parts;
cmp_ok($parts[0]->partNumber, 'eq', 1);
cmp_ok($parts[1]->partNumber, 'eq', 2);
cmp_ok($parts[2]->partNumber, 'eq', 3);
cmp_ok($parts[2]->body->nested->partNumber, 'eq', 3);

my $msg2 = $msg->clone;
ok($msg2);
cmp_ok($msg2->parts , "==",  3);
ok($mp->part(-1)->body->isNested);

my $orig_text  = '';
my $orig       = IO::Scalar->new(\$orig_text);
$msg->print($orig);
$orig->close;

my $clone_text = '';
my $clone      = IO::Scalar->new(\$clone_text);
$msg2->print($clone);
$clone->close;

ok(length $orig_text);
is($orig_text, $clone_text);