public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob 099587f86147470c89153d12accecfc6a45e3b0d 2921 bytes (raw)
$ git show HEAD:t/eml_content_disposition.t	# shows this blob on the CLI

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
 
#!perl -w
# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
# Copyright (C) 2004- Simon Cozens, Casey West, Ricardo SIGNES
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
# License: GPL-1.0+ or Artistic-1.0-Perl
#  <https://www.gnu.org/licenses/gpl-1.0.txt>
#  <https://dev.perl.org/licenses/artistic.html>
use strict;
use Test::More;
use PublicInbox::EmlContentFoo qw(parse_content_disposition);

my %cd_tests = (
	'' => { type => 'attachment', attributes => {} },
	'inline' => { type => 'inline', attributes => {} },
	'attachment' => { type => 'attachment', attributes => {} },

	'attachment; filename=genome.jpeg;' .
	' modification-date="Wed, 12 Feb 1997 16:29:51 -0500"' => {
		type => 'attachment',
		attributes => {
			filename => 'genome.jpeg',
			'modification-date' => 'Wed, 12 Feb 1997 16:29:51 -0500'
		}
	},

	q(attachment; filename*=UTF-8''genome.jpeg;) .
	q( modification-date="Wed, 12 Feb 1997 16:29:51 -0500") => {
		type => 'attachment',
		attributes => {
			filename => 'genome.jpeg',
			'modification-date' => 'Wed, 12 Feb 1997 16:29:51 -0500'
		}
	},

	q(attachment; filename*0*=us-ascii'en'This%20is%20even%20more%20;) .
	q( filename*1*=%2A%2A%2Afun%2A%2A%2A%20; filename*2="isn't it!") => {
		type => 'attachment',
		attributes => {
			filename => "This is even more ***fun*** isn't it!"
		}
	},

	q(attachment; filename*0*='en'This%20is%20even%20more%20;) .
	q( filename*1*=%2A%2A%2Afun%2A%2A%2A%20; filename*2="isn't it!") => {
		type => 'attachment',
		attributes => {
			filename => "This is even more ***fun*** isn't it!"
		}
	},

	q(attachment; filename*0*=''This%20is%20even%20more%20;) .
	q( filename*1*=%2A%2A%2Afun%2A%2A%2A%20; filename*2="isn't it!") => {
		type => 'attachment',
		attributes => {
			filename => "This is even more ***fun*** isn't it!"
		}
	},

	q(attachment; filename*0*=us-ascii''This%20is%20even%20more%20;).
	q( filename*1*=%2A%2A%2Afun%2A%2A%2A%20; filename*2="isn't it!") => {
		type => 'attachment',
		attributes => {
			filename => "This is even more ***fun*** isn't it!"
		}
	},
);

my %non_strict_cd_tests = (
	'attachment; filename=genome.jpeg;' .
	' modification-date="Wed, 12 Feb 1997 16:29:51 -0500";' => {
		type => 'attachment',
		attributes => {
			filename => 'genome.jpeg',
			'modification-date' =>
				'Wed, 12 Feb 1997 16:29:51 -0500'
		}
	},
);

sub test {
	my ($string, $expect, $info) = @_;
	local $_;
	$info =~ s/\r/\\r/g;
	$info =~ s/\n/\\n/g;
	is_deeply(parse_content_disposition($string), $expect, $info);
}

for (sort keys %cd_tests) {
	test($_, $cd_tests{$_}, "Can parse C-D <$_>");
}

local $PublicInbox::EmlContentFoo::STRICT_PARAMS = 0;
for (sort keys %cd_tests) {
	test($_, $cd_tests{$_}, "Can parse non-strict C-D <$_>");
}
for (sort keys %non_strict_cd_tests) {
	test($_, $non_strict_cd_tests{$_}, "Can parse non-strict C-D <$_>");
}

done_testing;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git