2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::TestCommon;
9 use_ok 'PublicInbox::LeiToMail';
10 my $from = "Content-Length: 10\nSubject: x\n\nFrom hell\n";
11 my $noeol = "Subject: x\n\nFrom hell";
14 my $kw = [qw(seen answered flagged)];
15 for my $mbox (qw(mboxrd mboxo mboxcl mboxcl2)) {
17 my $cb = PublicInbox::LeiToMail->can($m);
18 my $s = $cb->(PublicInbox::Eml->new($from), $kw);
19 is(substr($$s, -1, 1), "\n", "trailing LF in normal $mbox");
20 my $eml = PublicInbox::Eml->new($s);
21 is($eml->header('Status'), 'R', "Status: set by $m");
22 is($eml->header('X-Status'), 'AF', "X-Status: set by $m");
23 if ($mbox eq 'mboxcl2') {
24 like($eml->body_raw, qr/^From /, "From not escaped $m");
26 like($eml->body_raw, qr/^>From /, "From escaped once by $m");
28 my @cl = $eml->header('Content-Length');
29 if ($mbox =~ /mboxcl/) {
30 is(scalar(@cl), 1, "$m only has one Content-Length header");
31 is($cl[0] + length("\n"),
32 length($eml->body_raw), "$m Content-Length matches");
34 is(scalar(@cl), 0, "$m clobbered Content-Length");
36 $s = $cb->(PublicInbox::Eml->new($noeol), $kw);
37 is(substr($$s, -1, 1), "\n",
38 "trailing LF added by $m when original lacks EOL");
39 $eml = PublicInbox::Eml->new($s);
40 if ($mbox eq 'mboxcl2') {
41 is($eml->body_raw, "From hell\n", "From not escaped by $m");
43 is($eml->body_raw, ">From hell\n", "From escaped once by $m");
45 $s = $cb->(PublicInbox::Eml->new($crlf), $kw);
46 is(substr($$s, -2, 2), "\r\n",
47 "trailing CRLF added $m by original lacks EOL");
48 $eml = PublicInbox::Eml->new($s);
49 if ($mbox eq 'mboxcl2') {
50 is($eml->body_raw, "From hell\r\n", "From not escaped by $m");
52 is($eml->body_raw, ">From hell\r\n", "From escaped once by $m");
54 if ($mbox =~ /mboxcl/) {
55 is($eml->header('Content-Length') + length("\r\n"),
56 length($eml->body_raw), "$m Content-Length matches");
57 } elsif ($mbox eq 'mboxrd') {
58 $s = $cb->($eml, $kw);
59 $eml = PublicInbox::Eml->new($s);
61 ">>From hell\r\n\r\n", "From escaped again by $m");