]> Sergey Matveev's repositories - public-inbox.git/blob - t/reply.t
git-send-email-reply: Append subject
[public-inbox.git] / t / reply.t
1 # Copyright (C) 2017-2021 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 PublicInbox::Eml;
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 = PublicInbox::Eml->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     "--subject='Re: hihi'"
41 ];
42
43 is_deeply($arg, $exp, 'default reply is to :all');
44 $ibx->{replyto} = ':all';
45 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
46 is_deeply($arg, $exp, '":all" also works');
47
48 $exp = [ '--in-reply-to=blah@example.com', '--to=primary@example.com',
49         "--subject='Re: hihi'" ];
50 $ibx->{replyto} = ':list';
51 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
52 is_deeply($arg, $exp, '":list" works for centralized lists');
53
54 $exp = [
55          '--in-reply-to=blah@example.com',
56          '--to=primary@example.com',
57          '--cc=cc@example.com',
58          '--cc=to@example.com',
59         "--subject='Re: hihi'"
60 ];
61 $ibx->{replyto} = ':list,Cc,To';
62 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
63 is_deeply($arg, $exp, '":list,Cc,To" works for kinda centralized lists');
64
65 $ibx->{replyto} = 'new@example.com';
66 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
67 $exp = [ '--in-reply-to=blah@example.com', '--to=new@example.com',
68         "--subject='Re: hihi'"
69 ];
70 is_deeply($arg, $exp, 'explicit address works, too');
71
72 $ibx->{replyto} = ':all';
73 $ibx->{obfuscate} = 1;
74 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
75 $exp = [
76     '--in-reply-to=blah@example.com',
77     '--to=from@example$(echo .)com',
78     '--cc=cc@example$(echo .)com',
79     '--cc=to@example$(echo .)com',
80     "--subject='Re: hihi'"
81 ];
82 is_deeply($arg, $exp, 'address obfuscation works');
83 is($link, '', 'no mailto: link given');
84
85 $ibx->{replyto} = ':none=dead list';
86 $ibx->{obfuscate} = 1;
87 ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
88 is($$arg, 'dead list', ':none= works');
89
90 done_testing();