-
Notifications
You must be signed in to change notification settings - Fork 7
N°4281 - Add RFC-2045-Compliant Way of Handling Filenames in Attachments #16
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
Open
mraenker
wants to merge
9
commits into
Combodo:master
Choose a base branch
from
itomig-de:issue/4281
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
51f688b
N°4281 - "Content Type" and "Content Disposition" RFC 2045-compliant…
itomig-martin ed5577f
Remove trim() before the final results, as it is not necessary anymore.
mraenker 81bd7fe
Remove redundant part of comment
mraenker b660fb2
Moved the Regex into a class var + Testcases
itomig-martin 610c2f3
Change Namespace in test/TestRegexAttachmentNames.php
mraenker f0521eb
Regex is now a const, and its uses are factorized in a dedicated method
piRGoif 5dc779c
Merge branch 'Combodo:master' into issue/4281
mraenker 541bf57
:art: Fix formatting
piRGoif 3158cf5
:art: Fix formatting again
piRGoif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
| /* | ||
| * @copyright Copyright (C) 2010-2021 Combodo SARL | ||
| * @license http://opensource.org/licenses/AGPL-3.0 | ||
| */ | ||
|
|
||
|
|
||
| namespace Combodo\iTop\Test\UnitTest\Module\CombodoEmailSynchro; | ||
|
|
||
| use Combodo\iTop\Test\UnitTest\ItopTestCase; | ||
| use RawEmailMessage; | ||
|
|
||
| /** | ||
| * Class TestRegexAttachmentNames | ||
| * | ||
| * @package Combodo\iTop\Test\UnitTest\CombodoEmailSynchro | ||
| */ | ||
| class TestRegexAttachmentNames extends ItopTestCase | ||
| { | ||
| public function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| require_once(APPROOT.'env-production/combodo-email-synchro/classes/rawemailmessage.class.inc.php'); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider AttachmentFilenameProvider | ||
| * @covers RawEmailMessage::GetAttachments | ||
| * | ||
| * @param string $sInput | ||
| * @param string $sExceptedAttachmentName | ||
| */ | ||
| public function testNormalizeAttachmentName(string $sInput, string $sExpectedAttachmentName) | ||
| { | ||
| $aMatches = array(); | ||
| $sNormalizedAttachmentName = null; | ||
| if (preg_match(RawEmailMessage::FILENAME_REGEX, $sInput, $aMatches)) { | ||
| $sNormalizedAttachmentName = end($aMatches); | ||
| $this->assertEquals($sExpectedAttachmentName, $sNormalizedAttachmentName, "Attachmentname for '".bin2hex($sInput)."' doesn't match. Got'".bin2hex($sNormalizedAttachmentName)."', expected '$sExpectedAttachmentName'."); | ||
| } else { | ||
| $this->AssertNull($sNormalizedAttachmentName); | ||
| } | ||
| } | ||
|
|
||
| public function AttachmentFilenameProvider() | ||
| { | ||
| return [ | ||
| 'All allowed Chars' => [ | ||
| "!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~", | ||
| "!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~", | ||
| ], | ||
| // Something is odd here: x2C (comma) is not in the list of allowed | ||
| // chars in {@see RawEmailMessage::FILENAME_REGEX}, but nevertheless is | ||
| // not filtered by the Regex, resulting in this test case is failing. | ||
| // I have no clue, as to why this is happening. | ||
| 'All not allowed Chars (from the ASCII Table)' => [ | ||
| "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x17\x18\x19\x1A\x1B\x1C\x1E\x1F\x20\x22\x28\x29\x2C\x2F\x3A\x3B\x3C\x3D\x3E\x3F\x40\x5B\x5C\x5D\x7F", | ||
| "", | ||
| ], | ||
| 'Single Quotes delimit filename' => [ | ||
| "'End 'before'", | ||
| "End ", | ||
| ], | ||
| 'Double Quotes delimit filename' => [ | ||
| '"End "before"', | ||
| 'End ', | ||
| ], | ||
| 'Empty String' => [ | ||
| '', | ||
| '', | ||
| ], | ||
| 'Name with a Space' => [ | ||
| 'OQL Queries', | ||
| 'OQL', | ||
| ], | ||
| // Same problem as in test for not allowed chars: The comma somehow slips through. | ||
| 'Name with a Comma' => [ | ||
| 'OQL,Queries', | ||
| 'OQL', | ||
| ], | ||
| ]; | ||
| } | ||
| } |
97 changes: 97 additions & 0 deletions
97
test/emailsSample/email_with_and_without_quotes_around_attachment_name.eml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| Return-Path: <[email protected]> | ||
| Received: from www192.your-server.de | ||
| by www192.your-server.de with LMTP | ||
| id cANPJDAmYmNaVQEAUXDXKw | ||
| (envelope-from <[email protected]>); Wed, 02 Nov 2022 09:11:28 +0100 | ||
| Envelope-to: [email protected] | ||
| Delivery-date: Wed, 02 Nov 2022 09:11:28 +0100 | ||
| Authentication-Results: www192.your-server.de; | ||
| iprev=pass (localhost) smtp.remote-ip=127.0.0.1; | ||
| spf=pass smtp.mailfrom=itomig.de; | ||
| dkim=pass header.d=itomig.de header.s=default2012 header.a=rsa-sha256; | ||
| dmarc=skipped | ||
| Received: from localhost ([127.0.0.1] helo=www192.your-server.de) | ||
| by www192.your-server.de with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 | ||
| (Exim 4.94.2) | ||
| (envelope-from <[email protected]>) | ||
| id 1oq8qO-000NG0-7r | ||
| for [email protected]; Wed, 02 Nov 2022 09:11:28 +0100 | ||
| DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=itomig.de; | ||
| s=default2012; h=Subject:From:To:MIME-Version:Date:Message-ID:Content-Type: | ||
| Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: | ||
| Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: | ||
| In-Reply-To:References; bh=qfsa/c5xPqZ3d+6wNfzUExTW0ZNkPkALI3o0hp2R85A=; b=r5 | ||
| zbg+7XSo/HBfaFAqqdBD0gDiOIa8ujhqmikWoXps5jf9oMJVJ6af5ynLdfZPbxkpWss5t6os7LhO/ | ||
| w/ZdvjR8sOpvIX5nkR3DJxnG76Z28p0aFtpBz1OSIXpWe7LmSj8mBwsXBuh6jTLLH2xRGY3gBEIU9 | ||
| fkOlRbJQ6lU3qhS9Xa9cgSGECPfhIvZzdM/Rb0vdvvERCmrpvr9TylqFb+3RA05pQJBOvG3i/ih7O | ||
| 5a9RytEsd5rpN1IabPoMV6UJFhKaxPY4hMG4qdgzI2GQZAcoK5kNm/IrUxeHQ8KLy5HigJ1I11e9e | ||
| kzqzy6hT0ZKrELFcqh6Y8L6EzgtC+aOg==; | ||
| Received: from [95.90.147.54] (helo=[192.168.0.103]) | ||
| by www192.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 | ||
| (Exim 4.94.2) | ||
| (envelope-from <[email protected]>) | ||
| id 1oq8qO-000NFs-3t | ||
| for [email protected]; Wed, 02 Nov 2022 09:11:28 +0100 | ||
| Content-Type: multipart/mixed; boundary="------------8PrwbWLJ6Ep94lElB18RfVAR" | ||
| Message-ID: <[email protected]> | ||
| Date: Wed, 2 Nov 2022 09:11:25 +0100 | ||
| MIME-Version: 1.0 | ||
| User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 | ||
| Thunderbird/102.2.2 | ||
| Content-Language: en-US | ||
| To: [email protected] | ||
| From: Martin Raenker <[email protected]> | ||
| Subject: test for attachments with unquoted name | ||
| X-Authenticated-Sender: [email protected] | ||
| X-Virus-Scanned: Clear (ClamAV 0.103.7/26707/Tue Nov 1 21:23:26 2022) | ||
| X-local-sign: yes | ||
| X-DKIM-Status: pass [(itomig.de) - 127.0.0.1] | ||
| Delivered-To: [email protected] | ||
|
|
||
| This is a multi-part message in MIME format. | ||
| --------------8PrwbWLJ6Ep94lElB18RfVAR | ||
| Content-Type: text/plain; charset=UTF-8; format=flowed | ||
| Content-Transfer-Encoding: 7bit | ||
|
|
||
| testbody | ||
| --------------8PrwbWLJ6Ep94lElB18RfVAR | ||
| Content-Type: application/octet-stream; charset=UTF-8; name="example_attachment_mail.csv" | ||
| Content-Disposition: attachment; | ||
| Content-Transfer-Encoding: base64 | ||
|
|
||
| InRlc3QiLCJ0b3N0Igo= | ||
|
|
||
| --------------8PrwbWLJ6Ep94lElB18RfVAR | ||
| Content-Type: application/octet-stream; charset=UTF-8; name='example_attachment_mail.csv' | ||
| Content-Disposition: attachment; | ||
| Content-Transfer-Encoding: base64 | ||
|
|
||
| InRlc3QiLCJ0b3N0Igo= | ||
|
|
||
| --------------8PrwbWLJ6Ep94lElB18RfVAR | ||
| Content-Type: application/octet-stream; charset=UTF-8; name=example_attachment_mail.csv | ||
| Content-Disposition: attachment; | ||
| Content-Transfer-Encoding: base64 | ||
|
|
||
| InRlc3QiLCJ0b3N0Igo= | ||
|
|
||
| --------------8PrwbWLJ6Ep94lElB18RfVAR | ||
| Content-Type: application/octet-stream; charset=UTF-8; | ||
| Content-Disposition: attachment; filename="example_attachment_mail.csv" | ||
| Content-Transfer-Encoding: base64 | ||
|
|
||
| InRlc3QiLCJ0b3N0Igo= | ||
|
|
||
| --------------8PrwbWLJ6Ep94lElB18RfVAR | ||
| Content-Type: application/octet-stream; charset=UTF-8; | ||
| Content-Disposition: attachment; filename='example_attachment_mail.csv' | ||
| Content-Transfer-Encoding: base64 | ||
|
|
||
| InRlc3QiLCJ0b3N0Igo= | ||
|
|
||
| --------------8PrwbWLJ6Ep94lElB18RfVAR | ||
| Content-Type: application/octet-stream; charset=UTF-8; | ||
| Content-Disposition: attachment; filename=example_attachment_mail.csv | ||
| Content-Transfer-Encoding: base64 | ||
|
|
||
| InRlc3QiLCJ0b3N0Igo= |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.