File: 10mailint.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 (100 lines) | stat: -rw-r--r-- 1,928 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
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env perl
#
# Test conversions between Mail::Internet and Mail::Message
#

use strict;
use warnings;

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

use Test::More;

use Mail::Message;
use Mail::Message::Convert::MailInternet;

BEGIN
{   eval {require Mail::Internet};
    if($@)
    {   warn "requires Mail::Internet.\n";
        plan tests => 0;
        exit 0;
    }
    plan tests => 21;
}

my $mi = Mail::Internet->new(\*DATA);
ok($mi);

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

#
# Convert Mail::Internet to Mail::Message
#

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

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

my @fields = sort $head->names;
cmp_ok(@fields, "==", 5);
is($fields[0], 'again');
is($fields[1], 'from');
is($fields[2], 'in-reply-to');
is($fields[3], 'subject');
is($fields[4], 'to');

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

my @again = $head->get('again');
cmp_ok(@again, "==", 3);

my $body  = $msg->body;
ok($body);
my @lines = $body->lines;
cmp_ok(@lines, "==", 6);
is($lines[-1], "that.\n");

#
# Convert message back to a Mail::Internet
#

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

@fields  = $head->tags;
cmp_ok(@fields, "==", 5);
is($head->get('to'), "the users\n");

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

@again   = $head->get('again');
cmp_ok(@again, "==", 3);

$body = $back->body;
cmp_ok(@$body, "==", 6);

1;

__DATA__
From: mailtools@overmeer.net
To: the users
Subject: use Mail::Box
In-Reply-To: <023984hjlur29420@sruoiu.nl>
Again: repeating header
Again: repeating header again
Again: repeating header and again

Mail::Internet was conceived in 1995, or even earlier, and
written by Graham Barr.  At that time, e-mail was not very
wide-spread (the beginning of WWW) and e-mails where not
poluted by graphics.  Attachments were even so rare that
Mail::Internet cannot handle them: see MIME::Entity for
that.