File: 30emsimp.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 (90 lines) | stat: -rw-r--r-- 1,912 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl
# Test conversions between Mail::Message and Email::Simple
#
# The tests are stolen from the MIME::Entity test-script, which
# makes the content bogus.

use strict;
use warnings;

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

use Test::More;
use Mail::Message;

BEGIN
{   eval {require Email::Simple};
    if($@)
    {   plan skip_all => "requires Email::Simple.";
        exit 0;
    }

    require Mail::Message::Convert::EmailSimple;
    plan tests => 15;
}

my $email = Email::Simple->new(<<'END_MESSAGE');
From: mailtools@overmeer.net
To: the users
Subject: use Mail::Box
In-Reply-To: <023984hjlur29420@sruoiu.nl>
X-Again: repeating header
X-Again: repeating header again
X-Again: repeating header and again

MIME::Entity is written by Eriq, and extends Mail::Internet with many
new capabilities, like multipart bodies.  Actually, although it says
to extend, it more or less reimplements most methods and conflicts
with the other.  Even the Mail::Internet constructor does not work:
only the build() can be used to safely construct a message.  Do not
use it anymore!
END_MESSAGE

isa_ok($email, 'Email::Simple');

my $convert = Mail::Message::Convert::EmailSimple->new;
ok($convert);

#
# Convert Email::Simple to Mail::Message
#

my $msg = $convert->from($email);
ok($msg);

my $head = $msg->head;
ok($head);

my @from  = $head->get('From');
cmp_ok(@from, "==", 1);

my @again = $head->get('X-again');
is(@again, 3);

my $body  = $msg->body;
ok($body);
my @lines = $body->lines;
cmp_ok(@lines, "==", 6);
is($lines[-1], "use it anymore!\n");

#
# Convert message back to an Email::Simple
#

my $back = $convert->export($msg);
ok(defined $back);

is($back->header('to'), "the users");

@from    = $back->header('from');
cmp_ok(@from, "==", 1);

@again   = $back->header('x-again');
cmp_ok(@again, "==", 3);

$body = $back->body;
ok($body);

@lines = split /\n/, $body;
cmp_ok(@lines, "==", 6);