]> Sergey Matveev's repositories - public-inbox.git/blob - t/eml_content_disposition.t
imap: quiet uninitialized variable warning on FETCH
[public-inbox.git] / t / eml_content_disposition.t
1 #!perl -w
2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # Copyright (C) 2004- Simon Cozens, Casey West, Ricardo SIGNES
4 # This library is free software; you can redistribute it and/or modify
5 # it under the same terms as Perl itself.
6 #
7 # License: GPL-1.0+ or Artistic-1.0-Perl
8 #  <https://www.gnu.org/licenses/gpl-1.0.txt>
9 #  <https://dev.perl.org/licenses/artistic.html>
10 use strict;
11 use Test::More;
12 use PublicInbox::EmlContentFoo qw(parse_content_disposition);
13
14 my %cd_tests = (
15         '' => { type => 'attachment', attributes => {} },
16         'inline' => { type => 'inline', attributes => {} },
17         'attachment' => { type => 'attachment', attributes => {} },
18
19         'attachment; filename=genome.jpeg;' .
20         ' modification-date="Wed, 12 Feb 1997 16:29:51 -0500"' => {
21                 type => 'attachment',
22                 attributes => {
23                         filename => 'genome.jpeg',
24                         'modification-date' => 'Wed, 12 Feb 1997 16:29:51 -0500'
25                 }
26         },
27
28         q(attachment; filename*=UTF-8''genome.jpeg;) .
29         q( modification-date="Wed, 12 Feb 1997 16:29:51 -0500") => {
30                 type => 'attachment',
31                 attributes => {
32                         filename => 'genome.jpeg',
33                         'modification-date' => 'Wed, 12 Feb 1997 16:29:51 -0500'
34                 }
35         },
36
37         q(attachment; filename*0*=us-ascii'en'This%20is%20even%20more%20;) .
38         q( filename*1*=%2A%2A%2Afun%2A%2A%2A%20; filename*2="isn't it!") => {
39                 type => 'attachment',
40                 attributes => {
41                         filename => "This is even more ***fun*** isn't it!"
42                 }
43         },
44
45         q(attachment; filename*0*='en'This%20is%20even%20more%20;) .
46         q( filename*1*=%2A%2A%2Afun%2A%2A%2A%20; filename*2="isn't it!") => {
47                 type => 'attachment',
48                 attributes => {
49                         filename => "This is even more ***fun*** isn't it!"
50                 }
51         },
52
53         q(attachment; filename*0*=''This%20is%20even%20more%20;) .
54         q( filename*1*=%2A%2A%2Afun%2A%2A%2A%20; filename*2="isn't it!") => {
55                 type => 'attachment',
56                 attributes => {
57                         filename => "This is even more ***fun*** isn't it!"
58                 }
59         },
60
61         q(attachment; filename*0*=us-ascii''This%20is%20even%20more%20;).
62         q( filename*1*=%2A%2A%2Afun%2A%2A%2A%20; filename*2="isn't it!") => {
63                 type => 'attachment',
64                 attributes => {
65                         filename => "This is even more ***fun*** isn't it!"
66                 }
67         },
68 );
69
70 my %non_strict_cd_tests = (
71         'attachment; filename=genome.jpeg;' .
72         ' modification-date="Wed, 12 Feb 1997 16:29:51 -0500";' => {
73                 type => 'attachment',
74                 attributes => {
75                         filename => 'genome.jpeg',
76                         'modification-date' =>
77                                 'Wed, 12 Feb 1997 16:29:51 -0500'
78                 }
79         },
80 );
81
82 sub test {
83         my ($string, $expect, $info) = @_;
84         local $_;
85         $info =~ s/\r/\\r/g;
86         $info =~ s/\n/\\n/g;
87         is_deeply(parse_content_disposition($string), $expect, $info);
88 }
89
90 for (sort keys %cd_tests) {
91         test($_, $cd_tests{$_}, "Can parse C-D <$_>");
92 }
93
94 local $PublicInbox::EmlContentFoo::STRICT_PARAMS = 0;
95 for (sort keys %cd_tests) {
96         test($_, $cd_tests{$_}, "Can parse non-strict C-D <$_>");
97 }
98 for (sort keys %non_strict_cd_tests) {
99         test($_, $non_strict_cd_tests{$_}, "Can parse non-strict C-D <$_>");
100 }
101
102 done_testing;