File: 116fieldu-userid.t

package info (click to toggle)
libmail-message-perl 3.017-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 1,632 kB
  • sloc: perl: 11,156; makefile: 4
file content (123 lines) | stat: -rw-r--r-- 2,966 bytes parent folder | download | duplicates (4)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env perl
#
# Test processing in combination with User::Identity as documented in
# Mail::Message::Field.
#

use strict;
use warnings;

use Mail::Message::Test;
use Mail::Message::Field::Fast;
use User::Identity;

use Test::More tests => 22;

my $mmf = 'Mail::Message::Field::Fast';

# A user's identity

my $patrik = User::Identity->new
 ( "patrik"
 , full_name => "Patrik Fltstrm"  # from rfc
 , charset   => "ISO-8859-1"
 );

isa_ok($patrik, 'User::Identity');

my $email1 = $patrik->add
 ( email     => 'home'
 , address   => 'him@home.net'
 );

isa_ok($email1, 'Mail::Identity');

# address based on Mail::Identity with user

my $f1 = $mmf->new(To => $email1);
isa_ok($f1, $mmf);
is($f1, '=?ISO-8859-1?q?Patrik_F=E4ltstr=F6m?= <him@home.net>');

my $f1b = $mmf->new(To => $patrik);
isa_ok($f1b, $mmf);
is($f1b, '=?ISO-8859-1?q?Patrik_F=E4ltstr=F6m?= <him@home.net>');

# address based on Mail::Identity without user

require Mail::Identity;
my $email2 = Mail::Identity->new
 ( 'work'
 , address   => 'somewhere@example.com'
 );
my $f2 = $mmf->new(To => $email2);
is($f2, 'somewhere@example.com');

# A very complex address

my $email3 = Mail::Identity->new
 ( 'work'
 , address   => 'somehow@example.com'
 , phrase    => 'my " quote'
 , comment   => 'make it ) hard'
 );
my $f3 = $mmf->new(To => $email3);
is($f3, qq["my \\" quote" <somehow\@example.com> (make it \\) hard)]);

# A collection of e-mails

$patrik->add(email => $email3);
my $emails = $patrik->collection('emails');
isa_ok($emails, 'User::Identity::Collection::Emails');
cmp_ok(@$emails, '==', 2);

# An array of addresses

my $f4 = $mmf->new
  ( To =>
     [ $email1
     , "aap\@hok.nl"
     , $email2
     , $patrik->find(email => 'work')
     ]
  );

is($f4->string, <<'FOLDED');
To: =?ISO-8859-1?q?Patrik_F=E4ltstr=F6m?= <him@home.net>, aap@hok.nl,
 somewhere@example.com, "my \" quote" <somehow@example.com> (make it \) hard)
FOLDED

# Test a collection which is linked to user

my $f5 = $mmf->new(To => $emails);
is($f5->string, <<'TWO');
To: emails: "my \" quote" <somehow@example.com> (make it \) hard),
 =?ISO-8859-1?q?Patrik_F=E4ltstr=F6m?= <him@home.net>;
TWO

require Mail::Message::Field::AddrGroup;

# test a collection which is not linked to a user

my $mmfg = 'Mail::Message::Field::AddrGroup';
my $g = $mmfg->new(name => 'groupie');
isa_ok($g, $mmfg);
is($g->name, 'groupie');
my @addrs = $g->addresses;
cmp_ok(scalar @addrs, '==', 0);
is($g->string, "groupie: ;");

$g->addAddress($email1);
@addrs = $g->addresses;
cmp_ok(scalar @addrs, '==', 1);
is($g->string, 'groupie: him@home.net;');

$g->addAddress($email3);
@addrs = $g->addresses;
cmp_ok(scalar @addrs, '==', 2);
is($g->string, 'groupie: "my \" quote" <somehow@example.com> (make it \) hard), him@home.net;');

$g->addAddress('aap@hok.nl');
@addrs = $g->addresses;
cmp_ok(scalar @addrs, '==', 3);
is($g->string, 'groupie: "my \" quote" <somehow@example.com> (make it \) hard), aap@hok.nl, him@home.net;');