root/t/20list-headers.t

Revision 303:6f57b7328cb8, 5.8 KB (checked in by Anselm Lingnau <anselm@…>, 9 months ago)

The Great Renaming: Change all command names to 'pl-*' and directory to '.pl'.
The idea behind this is to emphasise that the software is called ?*Project*
Lancelot? as opposed to plain ?Lancelot?. There is apparently a KDE tool that
goes by the name of ?Lancelot?, and we want to make clear that this is separate
and different. Also, Project Lancelot has been around for a lot longer!

Line 
1#!/usr/bin/perl -w
2
3use strict;
4
5BEGIN { chdir 't' if -d 't' }
6use lib '../lib';
7
8use Test::More tests => 35;
9use File::Path;
10
11use Lancelot::DB;
12use Lancelot::Message;
13
14sub copy_msg {
15    return Lancelot::Message->new($_[0]->as_string);
16}
17
18BEGIN { use_ok('Lancelot::Module::list_headers'); }
19
20my $listname = 'pl-testlist@example.com';
21
22rmtree("$ENV{HOME}/.pl/$listname", 0);
23
24my $db = new Lancelot::DB $listname, { create => 1 };
25$db->set_config('list.name', 'Pl-testlist');
26$db->set_config('mail.delimiter', '+');
27
28# Check RFC2919 (List-ID)
29
30my $msg = Lancelot::Message->new('From: hugo@example.com
31To: susi@example.net
32Subject: Test
33Foo: bar
34Baz: quux
35
36This is a test.
37');
38
39$db->set_config('mail.listid', '<pl-testlist.example.com>');
40my $tmsg = copy_msg($msg);
41my $result = Lancelot::Module::list_headers::execute($db, $tmsg);
42is($tmsg->header('List-ID'), '<pl-testlist.example.com>', 'explicit list ID');
43
44$db->delete_configs('mail.listid');
45$tmsg = copy_msg($msg);
46$result = Lancelot::Module::list_headers::execute($db, $tmsg);
47is($tmsg->header('List-ID'), '<pl-testlist.list-id.example.com>',
48   'default list ID');
49
50# Check RFC2369 (List headers)
51
52$db->delete_configs('mail.listheaders');
53$tmsg = copy_msg($msg);
54$result = Lancelot::Module::list_headers::execute($db, $tmsg);
55my @hdrs = qw/help owner subscribe unsubscribe/;
56foreach my $h (@hdrs) {
57    ok(! defined $tmsg->header('List-'.ucfirst($h)),
58       "List-\u$h should be undefined");
59}
60
61$db->set_config('mail.listheaders', 1);
62$tmsg = copy_msg($msg);
63$result = Lancelot::Module::list_headers::execute($db, $tmsg);
64@hdrs = qw/help owner subscribe unsubscribe/;
65foreach my $h (@hdrs) {
66    is($tmsg->header('List-'.ucfirst($h)),
67       "<mailto:pl-testlist+$h\@example.com>",
68       "List-\u$h value");
69}
70
71$db->delete_configs('mail.delimiter');
72$tmsg = copy_msg($msg);
73$result = Lancelot::Module::list_headers::execute($db, $tmsg);
74@hdrs = qw/help owner subscribe unsubscribe/;
75foreach my $h (@hdrs) {
76    is($tmsg->header('List-'.ucfirst($h)),
77       "<mailto:pl-testlist-$h\@example.com>",
78       "List-\u$h value (default mail.delimiter)");
79}
80
81# mail.removeheaders
82
83$db->set_config('mail.removeheaders', 'foo');
84$db->delete_configs('mail.listheaders');
85$tmsg = copy_msg($msg);
86my $hcount = $tmsg->header_names();
87$result = Lancelot::Module::list_headers::execute($db, $tmsg);
88ok(! defined $tmsg->header('Foo'),
89   "removeheaders 1: foo should be removed");
90is(scalar($tmsg->header_names()), $hcount,
91   "removeheaders 1: all other headers still there");
92
93$db->set_config('mail.removeheaders', 'foo baz');
94$tmsg = copy_msg($msg);
95$result = Lancelot::Module::list_headers::execute($db, $tmsg);
96ok(! defined $tmsg->header('Foo'),
97   "removeheaders 2: foo should be removed");
98ok(! defined $tmsg->header('Baz'),
99   "removeheaders 2: baz should be removed");
100is(scalar($tmsg->header_names()), $hcount-1,
101   "removeheaders 1: all other headers still there");
102
103$db->delete_configs('mail.listheaders');
104$db->set_config('mail.removeheaders', '');
105$tmsg = copy_msg($msg);
106$result = Lancelot::Module::list_headers::execute($db, $tmsg);
107# $hcount+1 because List-ID will always be generated
108is(scalar($tmsg->header_names()), $hcount+1,
109   "removeheaders 3: all headers still there");
110
111$db->delete_configs('mail.removeheaders');
112
113# mail.addheaders
114
115$db->set_config('mail.addheaders', 'abc');
116$db->set_config('mail.header.abc', 'xyzzy');
117$tmsg = copy_msg($msg);
118$result = Lancelot::Module::list_headers::execute($db, $tmsg);
119is(scalar($tmsg->header_names()), $hcount+2,
120   "addheaders 1: one more header");
121is($tmsg->header('Abc'), 'xyzzy', 'new abc header value');
122
123# Add one header, second header to be added does not exist
124$db->set_config('mail.addheaders', 'abc xyz');
125$db->set_config('mail.header.abc', 'xyzzy');
126$tmsg = copy_msg($msg);
127$result = Lancelot::Module::list_headers::execute($db, $tmsg);
128is(scalar($tmsg->header_names()), $hcount+2,
129   "addheaders 1: one more header");
130is($tmsg->header('Abc'), 'xyzzy', 'new abc header value');
131ok(!defined $tmsg->header('Xyz'), 'new (nonexistent) xyz header value');
132
133# Add two new headers
134$db->set_config('mail.addheaders', 'abc def');
135$db->set_config('mail.header.def', 'zyxxy');
136$tmsg = copy_msg($msg);
137$result = Lancelot::Module::list_headers::execute($db, $tmsg);
138is(scalar($tmsg->header_names()), $hcount+3,
139   "addheaders 1: two more headers");
140is($tmsg->header('Abc'), 'xyzzy', 'new abc header value');
141is($tmsg->header('Def'), 'zyxxy', 'new def header value');
142
143$db->delete_configs(qw/mail.addheaders mail.header.abc mail.header.def/);
144
145# subject header munging
146
147$db->set_config('mail.subjecttag', '[List] ');
148$tmsg = copy_msg($msg);
149$result = Lancelot::Module::list_headers::execute($db, $tmsg);
150is($tmsg->header('Subject'), '[List] Test', 'with subject tag');
151
152$tmsg = copy_msg($msg);
153$tmsg->header_set('Subject', 'Re: Re: [List] Test');
154$result = Lancelot::Module::list_headers::execute($db, $tmsg);
155is($tmsg->header('Subject'), 'Re: Re: [List] Test', 'with prefixes');
156
157$tmsg = copy_msg($msg);
158$tmsg->header_set('Subject', 'RE: [List] AW: [List] Test');
159$result = Lancelot::Module::list_headers::execute($db, $tmsg);
160is($tmsg->header('Subject'), 'RE: [List] AW: [List] Test', 'with prefixes 2');
161
162$db->delete_configs('mail.subjecttag');
163
164# reply-to munging
165
166$db->set_config('mail.replyto', 'pl-testlist@example.com');
167$db->set_config('mail.forcereplyto', 0);
168$tmsg = copy_msg($msg);
169$result = Lancelot::Module::list_headers::execute($db, $tmsg);
170is($tmsg->header('Reply-To'), 'pl-testlist@example.com',
171   'optional list reply-to');
172
173$tmsg = copy_msg($msg);
174$tmsg->header_set('Reply-To', 'hugo@example.com');
175$result = Lancelot::Module::list_headers::execute($db, $tmsg);
176is($tmsg->header('Reply-To'), 'hugo@example.com', 'message reply-to');
177
178$db->set_config('mail.forcereplyto', 1);
179$result = Lancelot::Module::list_headers::execute($db, $tmsg);
180is($tmsg->header('Reply-To'), 'pl-testlist@example.com',
181   'forced list reply-to');
182
183$db->delete_configs('mail.replyto');
Note: See TracBrowser for help on using the browser.