-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug where some messages could get malformed in an import from a M…
…BOX file (#9510)
- Loading branch information
Showing
5 changed files
with
193 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Roundcube\Tests\Actions\Mail; | ||
|
||
use Roundcube\Tests\ActionTestCase; | ||
use Roundcube\Tests\OutputJsonMock; | ||
|
||
/** | ||
* Test class to test rcmail_action_mail_import | ||
|
@@ -14,8 +15,94 @@ class ImportTest extends ActionTestCase | |
*/ | ||
public function test_class() | ||
{ | ||
$object = new \rcmail_action_mail_import(); | ||
$action = new \rcmail_action_mail_import(); | ||
$output = $this->initOutput(\rcmail_action::MODE_AJAX, 'mail', 'import'); | ||
|
||
$this->assertInstanceOf(\rcmail_action::class, $object); | ||
$this->assertInstanceOf(\rcmail_action::class, $action); | ||
$this->assertTrue($action->checks()); | ||
|
||
$_SERVER['REQUEST_METHOD'] = 'POST'; | ||
|
||
// No files uploaded case | ||
$this->runAndAssert($action, OutputJsonMock::E_EXIT); | ||
|
||
$result = $output->getOutput(); | ||
|
||
$this->assertSame(['Content-Type: application/json; charset=UTF-8'], $output->headers); | ||
$this->assertSame('import', $result['action']); | ||
// TODO: Assert error message | ||
// $this->assertTrue(strpos($result['exec'], '') !== false); | ||
|
||
// Upload a EML file | ||
$_POST = [ | ||
'_mbox' => 'Test', | ||
]; | ||
$_FILES['_file'] = [ | ||
'name' => ['import.eml'], | ||
'type' => ['message/rfc822'], | ||
'tmp_name' => [__DIR__ . '/../../src/filename.eml'], | ||
'error' => [null], | ||
'size' => [123], | ||
'id' => [123], | ||
]; | ||
|
||
// Set expected storage function calls/results | ||
$storage = self::mockStorage() | ||
->registerFunction('get_folder', 'Test') | ||
->registerFunction('save_message', 123); | ||
|
||
$this->runAndAssert($action, OutputJsonMock::E_EXIT); | ||
|
||
$result = $output->getOutput(); | ||
|
||
$this->assertTrue(strpos($result['exec'], 'Successfully imported 1 messages') !== false); | ||
$this->assertTrue(strpos($result['exec'], 'this.command("list")') !== false); | ||
|
||
$args = $storage->methodCalls[1]['args']; | ||
$this->assertSame('Test', $args[0]); | ||
$this->assertTrue(strpos($args[1], 'From: "Thomas B." <[email protected]>') === 0); | ||
|
||
// Upload a MBOX file | ||
$_FILES['_file'] = [ | ||
'name' => ['import.eml'], | ||
'type' => ['text/plain'], | ||
'tmp_name' => [__DIR__ . '/../../src/import.mbox'], | ||
'error' => [null], | ||
'size' => [123], | ||
'id' => [123], | ||
]; | ||
|
||
// Set expected storage function calls/results | ||
$storage = self::mockStorage() | ||
->registerFunction('get_folder', 'Test') | ||
->registerFunction('save_message', 1) | ||
->registerFunction('save_message', 2) | ||
->registerFunction('save_message', 3); | ||
|
||
$this->runAndAssert($action, OutputJsonMock::E_EXIT); | ||
|
||
$result = $output->getOutput(); | ||
|
||
$this->assertTrue(strpos($result['exec'], 'Successfully imported 3 messages') !== false); | ||
$this->assertTrue(strpos($result['exec'], 'this.command("list")') !== false); | ||
|
||
$args = $storage->methodCalls[1]['args']; | ||
$this->assertSame('Test', $args[0]); | ||
$this->assertTrue(strpos($args[1], 'From: [email protected]') === 0); | ||
$this->assertStringContainsString('1234', $args[1]); | ||
|
||
$args = $storage->methodCalls[2]['args']; | ||
$this->assertSame('Test', $args[0]); | ||
$this->assertTrue(strpos($args[1], 'From: [email protected]') === 0); | ||
$this->assertTrue(strpos($args[1], "\nFrom me") !== false); | ||
|
||
$args = $storage->methodCalls[3]['args']; | ||
$this->assertSame('Test', $args[0]); | ||
$this->assertTrue(strpos($args[1], 'From: [email protected]') === 0); | ||
$this->assertStringContainsString('XXXX', $args[1]); | ||
|
||
// TODO: Test error handling | ||
// TODO: Test ZIP file input | ||
$this->markTestIncomplete(); | ||
} | ||
} |
This file contains 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,30 @@ | ||
From [email protected] Sun Jul 16 15:06:25 2023 | ||
From: [email protected] | ||
To: Tom Tester <[email protected]> | ||
Subject: Import 1 | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; | ||
Date: Fri, 23 May 2014 19:44:50 +0200 | ||
Message-ID: <[email protected]> | ||
|
||
1234 | ||
From [email protected] Sun Jul 16 15:06:25 2023 | ||
From: [email protected] | ||
To: Tom Tester <[email protected]> | ||
Subject: Import 2 | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; | ||
Date: Fri, 23 May 2014 19:44:50 +0200 | ||
Message-ID: <[email protected]> | ||
|
||
>From me | ||
From [email protected] Sun Jul 16 15:06:25 2023 | ||
From: [email protected] | ||
To: Tom Tester <[email protected]> | ||
Subject: Import 3 | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; | ||
Date: Fri, 23 May 2014 19:44:50 +0200 | ||
Message-ID: <[email protected]> | ||
|
||
XXXX |