Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad Content-ID formatting handling in DetectAttachment filter fixed #413

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Kernel/System/PostMaster/Filter/DetectAttachment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ sub Run {
)
{
my ($ImageID) = ( $Attachment->{ContentID} =~ m{^<(.*)>$}ixms );
if ( grep { $_->{Content} =~ m{<img.*src=.*['|"]cid:\Q$ImageID\E['|"].*>}xms } @Attachments ) {
$AttachmentInline = 1;

# Tolerate ContentID without surrounding <>.
if ( !defined $ImageID ) {
$ImageID = $Attachment->{ContentID};
}

# Inline image must not have empty ContentID (<>).
if ( length $ImageID ) {
if ( grep { $_->{Content} =~ m{<img.*src=.*['|"]cid:\Q$ImageID\E['|"].*>}ixms } @Attachments ) {
$AttachmentInline = 1;
}
}
}

Expand Down
34 changes: 34 additions & 0 deletions scripts/test/PostMaster/Attachments.t
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ my $EmailInlineImage = $MainObject->FileRead(
Result => 'ARRAY',
);

# Read email content that contains inline image with bad Content-ID formatting.
my $EmailInlineImageBadContentIDFormatting = $MainObject->FileRead(
Location => $ConfigObject->Get('Home') . '/scripts/test/sample/PostMaster/InlineImage1.box',
Result => 'ARRAY',
);

# Workaround due used email have not a From value
unshift @{$EmailAttachment}, 'From: Sender <sender@example.com>';

Expand Down Expand Up @@ -229,6 +235,34 @@ my @Tests = (
},
Email => $EmailInlineImage,
},
{
Name => '#4 - With Inline Images and bad Content-ID formatting',
Match => [
{
Key => 'X-OTRS-AttachmentExists',
Value => 'yes',
},
{
Key => 'X-OTRS-AttachmentCount',
Value => 1,
}
],
Set => [
{
Key => 'X-OTRS-DynamicField-TicketFreeText1',
Value => 'This should not be set',
},
{
Key => 'X-OTRS-DynamicField-TicketFreeText2',
Value => 'This should not be set',
},
],
Check => {
DynamicField_TicketFreeText1 => undef,
DynamicField_TicketFreeText2 => undef,
},
Email => $EmailInlineImageBadContentIDFormatting,
},
);

$Kernel::OM->ObjectsDiscard( Objects => ['Kernel::System::PostMaster::Filter'] );
Expand Down
50 changes: 50 additions & 0 deletions scripts/test/sample/PostMaster/InlineImage1.box
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
From: test <test@test.com>
Subject: test
To: test1 <test1@test.com>
Message-ID: <test104@test.com>
Date: Fri, 28 Jul 2017 12:25:43 +0200
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="------------09D1E0375BAA13EBAAD61733"
Content-Language: pl

This is a multi-part message in MIME format.
--------------09D1E0375BAA13EBAAD61733
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

test img:


--------------09D1E0375BAA13EBAAD61733
Content-Type: multipart/related;
boundary="------------040237935DECF5A5EBB29292"


--------------040237935DECF5A5EBB29292
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><font size="-1"><font face="Verdana">test img: <img
src="cid:image1@test.com" alt="" class=""></font></font></p>
</body>
</html>

--------------040237935DECF5A5EBB29292
Content-Type: image/png;
name="test.png"
Content-Transfer-Encoding: base64
Content-ID: image1@test.com
Content-Disposition: attachment;
filename="test.png"

iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeAQMAAAAB/jzhAAAAA1BMVEVV5ytwjk3qAAAADElE
QVQI12NgGIwAAACWAAFiFg3SAAAAAElFTkSuQmCC
--------------040237935DECF5A5EBB29292--

--------------09D1E0375BAA13EBAAD61733--