Commit c3c27da1 authored by VERDIN David's avatar VERDIN David

In some cases, a message will start with a multipart/related including a...

In some cases, a message will start with a multipart/related including a multipart/alternative; In that case, with the current code the multipart/related was urlized as a 'msg.0.bin' attachment, which was wrong.
Fixing this behaviour by:
1- allowing to go down two levels of multiparts
2- preventing any urlization if the part is not included in a 'multipart/mixed' parent to prevent urlizing the content of multipart/related or multipart/alternative.
parent 72451a0a
......@@ -2088,7 +2088,7 @@ sub _urlize_parts {
## Only multipart/mixed messages are modified.
my $eff_type = $entity->effective_type || 'text/plain';
unless ($eff_type eq 'multipart/mixed' or $eff_type eq 'multipart/alternative') {
unless ($eff_type eq 'multipart/mixed' or $eff_type eq 'multipart/alternative' or $eff_type eq 'multipart/related') {
return undef;
}
......@@ -2106,7 +2106,7 @@ sub _urlize_parts {
$expl, $dir1);
return 0;
}
return _urlize_sub_parts($entity, $list, $message_id, $dir1, 0, 0);
return _urlize_sub_parts($entity, $list, $message_id, $dir1, 0);
}
sub _urlize_sub_parts {
......@@ -2114,22 +2114,22 @@ sub _urlize_sub_parts {
my $list = shift;
my $message_id = shift;
my $directory = shift;
my $is_sub_part = shift;
my $i = shift;
my @parts = ();
use Data::Dumper;
my $parent_eff_type = $entity->effective_type();
foreach my $part ($entity->parts) {
my $eff_type = $part->effective_type || 'text/plain';
if ($eff_type eq 'multipart/mixed') {
my $p = _urlize_sub_parts($part->dup, $list, $message_id, $directory, 0, $i);
push @parts, $p;
$i++;
} elsif ($eff_type eq 'multipart/alternative' and !$is_sub_part) {
my $p = _urlize_sub_parts($part->dup, $list, $message_id, $directory, 1, $i);
my $p = _urlize_sub_parts($part->dup, $list, $message_id, $directory, $i);
push @parts, $p;
} elsif (($eff_type eq 'multipart/alternative' or $eff_type eq 'multipart/related') and $i < 2) {
$i++;
my $p = _urlize_sub_parts($part->dup, $list, $message_id, $directory, $i);
push @parts, $p;
} else {
my $p = _urlize_one_part($part->dup, $list, $directory, $i);
my $p = _urlize_one_part($part->dup, $list, $directory, $i, $parent_eff_type);
if (defined $p) {
push @parts, $p;
$i++;
......@@ -2144,10 +2144,13 @@ sub _urlize_sub_parts {
}
sub _urlize_one_part {
my $entity = shift;
my $list = shift;
my $dir = shift;
my $i = shift;
my $entity = shift;
my $list = shift;
my $dir = shift;
my $i = shift;
my $parent_eff_type = shift;
return undef unless ($parent_eff_type eq 'multipart/mixed');
my $expl = $list->{'dir'} . '/urlized';
my $listname = $list->{'name'};
......
......@@ -153,13 +153,26 @@ my @to_urlize = (
escaped_name => 'W%25c3%25bcrzburg.txt',
},
{
name => 'msg.1.bin',
escaped_name => 'msg.1.bin',
name => 'msg.3.bin',
escaped_name => 'msg.3.bin',
},
],
dirname => 'deep-nested@domain.tld',
escaped_dirname => 'deep-nested%40domain.tld',
},
{
test_case => 'Related/alternative nested message',
filename => 't/samples/urlize-nested-alternative-and-related.eml',
attachments =>
[
{
name => 'document.pdf',
escaped_name => 'document.pdf',
},
],
dirname => 'alt-nested@domain.tld',
escaped_dirname => 'alt-nested%40domain.tld',
},
);
......
Return-Path: sender@domain.tld
From: Ye Olde Sender <sender@domain.tld>
Subject: =?UTF-8?Q?Message_=c3=a0_urlizer?=
To: my list <test@lists.example.com>
Message-ID: <alt-nested@domain.tld>
Date: Thu, 19 Dec 2019 11:03:19 +0100
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="________boundary-level1"
This is a multi-part attachment message with nested multipart/related and multipart/alternative.
--________boundary-level1
Content-Type: multipart/related;
boundary="________boundary-level2";
type="multipart/alternative"
This is a multipart/related containing a multipart/alternative and an image
--________boundary-level2
Content-Type: multipart/alternative;
boundary="________boundary-level3"
This is a multipart/alternative containing a text/plain and a text/html.
--________boundary-level3
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
This is the text/palin part.
--________boundary-level3
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html><head/><body>This is the text/html part.</body></html>
--________boundary-level3--
--________boundary-level2
Content-Type: image/jpeg; name="image.jpg"
Content-Description: image.jpg
Content-Disposition: inline; filename="image.jpg"; size=2236;
creation-date="Mon, 03 Feb 2020 08:18:35 GMT";
modification-date="Mon, 03 Feb 2020 08:18:35 GMT"
Content-ID: <image.jpg@01D5DA72.E8F8BD00>
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwkHBgoJCAkLCwoMDxkQDw4ODx4WFxIZJCAmJSMg
--________boundary-level2--
--________boundary-level1
Content-Type: application/pdf; name="document.pdf"
Content-Description: document.pdf
Content-Disposition: attachment;
filename="document.pdf"; size=99013;
creation-date="Mon, 03 Feb 2020 07:59:24 GMT";
modification-date="Mon, 03 Feb 2020 07:59:26 GMT"
Content-Transfer-Encoding: base64
JVBERi0xLjQKJcfsj6IKOSAwIG9iago8PC9MaW5lYXJpemVkIDEvTCA5OTAxMy9IWyA5NDg3NiAx
--________boundary-level1--
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment