-
Notifications
You must be signed in to change notification settings - Fork 0
Fix IMAP mailMove crash on malformed MIME-encoded thread titles #156
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
base: main
Are you sure you want to change the base?
Changes from all commits
fd6ee25
c7f237c
6145da8
f172b72
1a38cb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| <?php | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Imap\ImapWrapper; | ||
|
|
||
| require_once __DIR__ . '/../class/Imap/ImapWrapper.php'; | ||
|
|
||
| class ImapWrapperUtf8Test extends TestCase | ||
| { | ||
| public function testUtf8WithNormalText() | ||
| { | ||
| $wrapper = new ImapWrapper(); | ||
| $text = 'Normal text'; | ||
| $result = $wrapper->utf8($text); | ||
|
|
||
| $this->assertEquals($text, $result); | ||
| } | ||
|
|
||
| public function testUtf8WithValidMimeEncodedString() | ||
| { | ||
| $wrapper = new ImapWrapper(); | ||
| // Valid MIME-encoded string: "Test Title" in UTF-8 base64 | ||
| $text = '=?UTF-8?B?VGVzdCBUaXRsZQ==?='; | ||
| $result = $wrapper->utf8($text); | ||
|
|
||
| // imap_utf8() should decode this properly | ||
| $this->assertEquals('Test Title', $result); | ||
| } | ||
|
|
||
| public function testUtf8WithMalformedMimeEncodedString() | ||
| { | ||
| $wrapper = new ImapWrapper(); | ||
| // Malformed MIME-encoded string from the error report | ||
| $text = '=?iso-8859-1?Q?axz5ZAFym5luZoxqfgeds8xO/E+PtRicCu3CXJTfFFl7/aub8+5SDA59PR? =?iso-'; | ||
|
|
||
| // This should not throw an exception | ||
| $result = $wrapper->utf8($text); | ||
|
|
||
| // Should return a string (may be the same as input if imap_utf8 can't decode it) | ||
| $this->assertIsString($result); | ||
| } | ||
|
Comment on lines
+30
to
+41
|
||
|
|
||
| public function testUtf8WithEmptyString() | ||
| { | ||
| $wrapper = new ImapWrapper(); | ||
| $text = ''; | ||
| $result = $wrapper->utf8($text); | ||
|
|
||
| $this->assertEquals('', $result); | ||
| } | ||
|
|
||
| public function testUtf8WithUtf8Text() | ||
| { | ||
| $wrapper = new ImapWrapper(); | ||
| // UTF-8 text with special characters | ||
| $text = 'Tëst wîth spëcîal çhâracters'; | ||
| $result = $wrapper->utf8($text); | ||
|
|
||
| // Should return the text as-is or decoded | ||
| $this->assertIsString($result); | ||
| } | ||
|
|
||
| public function testUtf8WithNordicCharacters() | ||
| { | ||
| $wrapper = new ImapWrapper(); | ||
| // Nordic characters | ||
| $text = 'Æble Øre Åre'; | ||
| $result = $wrapper->utf8($text); | ||
|
|
||
| // Should handle Nordic characters properly | ||
| $this->assertIsString($result); | ||
| $this->assertStringContainsString('ble', $result); | ||
| $this->assertStringContainsString('re', $result); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MIME decoding happens on the combined string
$entity_id . ' - ' . $thread->title. If the entity_id contains the marker=?, it would trigger unnecessary MIME decoding. While entity_ids are unlikely to contain such markers in practice, consider checking for MIME markers specifically in$thread->titlebefore combining, or document this assumption to prevent future issues.