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