]> Sergey Matveev's repositories - public-inbox.git/blob - t/reply.t
replyto parameter support
[public-inbox.git] / t / reply.t
1 # Copyright (C) 2017 all contributors <meta@public-inbox.org>
2 # License: AGPL-3+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use Email::MIME;
7 use_ok 'PublicInbox::Reply';
8
9 my @q = (
10         'foo@bar', 'foo@bar',
11         'a b', "'a b'",
12         "a'b", "'a'\\''b'",
13 );
14
15 while (@q) {
16         my $input = shift @q;
17         my $expect = shift @q;
18         my $res = PublicInbox::Reply::squote_maybe($input);
19         is($res, $expect, "quote $input => $res");
20 }
21
22 my $mime = Email::MIME->new(<<'EOF');
23 From: from <from@example.com>
24 To: to <to@example.com>
25 Cc: cc@example.com
26 Message-Id: <blah@example.com>
27 Subject: hihi
28
29 EOF
30
31 my $hdr = $mime->header_obj;
32 my $ibx = { -primary_address => 'primary@example.com' };
33
34 my ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
35 my $exp = [
36     '--in-reply-to=blah@example.com',
37     '--to=from@example.com',
38     '--cc=cc@example.com',
39     '--cc=to@example.com'
40 ];
41
42 is_deeply($arg, $exp, 'default reply is to :all');
43 $ibx->{replyto} = ':all';
44 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
45 is_deeply($arg, $exp, '":all" also works');
46
47 $exp = [ '--in-reply-to=blah@example.com', '--to=primary@example.com' ];
48 $ibx->{replyto} = ':list';
49 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
50 is_deeply($arg, $exp, '":list" works for centralized lists');
51
52 $exp = [
53          '--in-reply-to=blah@example.com',
54          '--to=primary@example.com',
55          '--cc=cc@example.com',
56          '--cc=to@example.com'
57 ];
58 $ibx->{replyto} = ':list,Cc,To';
59 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
60 is_deeply($arg, $exp, '":list,Cc,To" works for kinda centralized lists');
61
62 $ibx->{replyto} = 'new@example.com';
63 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
64 $exp = [ '--in-reply-to=blah@example.com', '--to=new@example.com' ];
65 is_deeply($arg, $exp, 'explicit address works, too');
66
67 done_testing();