]> Sergey Matveev's repositories - public-inbox.git/blob - t/reply.t
41d72db22c6586eb771009c056b413123ddae77c
[public-inbox.git] / t / reply.t
1 #!perl -w
2 # Copyright (C) 2017-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use Test::More;
6 use PublicInbox::Config;
7 use PublicInbox::Eml;
8 use_ok 'PublicInbox::Reply';
9
10 my @q = (
11         'foo@bar', 'foo@bar',
12         'a b', "'a b'",
13         "a'b", "'a'\\''b'",
14 );
15
16 while (@q) {
17         my $input = shift @q;
18         my $expect = shift @q;
19         my $res = PublicInbox::Config::squote_maybe($input);
20         is($res, $expect, "quote $input => $res");
21 }
22
23 my $mime = PublicInbox::Eml->new(<<'EOF');
24 From: from <from@example.com>
25 To: to <to@example.com>
26 Cc: cc@example.com
27 Message-Id: <blah@example.com>
28 Subject: hihi
29
30 EOF
31
32 my $hdr = $mime->header_obj;
33 my $ibx = { -primary_address => 'primary@example.com' };
34
35 my ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
36 my $exp = [
37     '--in-reply-to=blah@example.com',
38     '--to=from@example.com',
39     '--cc=cc@example.com',
40     '--cc=to@example.com',
41     "--subject='Re: hihi'"
42 ];
43
44 is_deeply($arg, $exp, 'default reply is to :all');
45 $ibx->{replyto} = ':all';
46 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
47 is_deeply($arg, $exp, '":all" also works');
48
49 $exp = [ '--in-reply-to=blah@example.com', '--to=primary@example.com',
50         "--subject='Re: hihi'" ];
51 $ibx->{replyto} = ':list';
52 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
53 is_deeply($arg, $exp, '":list" works for centralized lists');
54
55 $exp = [
56          '--in-reply-to=blah@example.com',
57          '--to=primary@example.com',
58          '--cc=cc@example.com',
59          '--cc=to@example.com',
60         "--subject='Re: hihi'"
61 ];
62 $ibx->{replyto} = ':list,Cc,To';
63 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
64 is_deeply($arg, $exp, '":list,Cc,To" works for kinda centralized lists');
65
66 $ibx->{replyto} = 'new@example.com';
67 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
68 $exp = [ '--in-reply-to=blah@example.com', '--to=new@example.com',
69         "--subject='Re: hihi'"
70 ];
71 is_deeply($arg, $exp, 'explicit address works, too');
72
73 $ibx->{replyto} = ':all';
74 $ibx->{obfuscate} = 1;
75 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
76 $exp = [
77     '--in-reply-to=blah@example.com',
78     '--to=from@example$(echo .)com',
79     '--cc=cc@example$(echo .)com',
80     '--cc=to@example$(echo .)com',
81     "--subject='Re: hihi'"
82 ];
83 is_deeply($arg, $exp, 'address obfuscation works');
84 is($link, '', 'no mailto: link given');
85
86 $ibx->{replyto} = ':none=dead list';
87 $ibx->{obfuscate} = 1;
88 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
89 is($$arg, 'dead list', ':none= works');
90
91 done_testing();