From d214ec3097e70d580200183ea6782eb9f70b2ccc Mon Sep 17 00:00:00 2001 From: Ching En Cheng Date: Fri, 4 Dec 2020 13:37:04 +0100 Subject: [PATCH] fix(Felamimail/Spam): move message to sub folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I92eac13524e6b2d94a18d885160aa09e2551ccb2 Reviewed-on: http://gerrit.tine20.com/customers/18649 Tested-by: Jenkins CI (http://ci.tine20.com/) Reviewed-by: Philipp Schüle --- .../Felamimail/Model/MessagePipeTest.php | 40 ++++++++++++++----- tine20/Felamimail/Model/MessagePipeMove.php | 6 ++- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/tests/tine20/Felamimail/Model/MessagePipeTest.php b/tests/tine20/Felamimail/Model/MessagePipeTest.php index b5c1b7ff5a0..80322ad4cf3 100644 --- a/tests/tine20/Felamimail/Model/MessagePipeTest.php +++ b/tests/tine20/Felamimail/Model/MessagePipeTest.php @@ -23,9 +23,8 @@ class Felamimail_Model_MessagePipeTest extends Felamimail_TestCase */ public function testMessagePipeCopyToAnotherAccount() { - $pipe = 'spam'; // both 'spam/ham pipe implement the same strategy - $targetFolder = 'spam'; // 'spam': folder called spam , '#spam': user configured spam folder - $account = $this->_createSharedAccount(); // create shared account + // create shared account + $account = $this->_createSharedAccount(); $config = [ 'spam' => [ @@ -48,11 +47,32 @@ public function testMessagePipeCopyToAnotherAccount() ] ]; - // send message and copy to other folder of shared aacount + // move to root + $pipe = 'spam'; + // 'spam': folder called spam , '#spam': user configured spam folder + $targetFolder = 'spam'; $message = $this->_messagePipeTestHelper($config[$pipe], $targetFolder, $account); - - $this->_assertMessageInFolder('INBOX', $message['subject']); $this->_assertMessageInFolder($targetFolder, $message['subject'], $account); + + $pipe = 'ham'; + $targetFolder = 'ham'; + $message = $this->_messagePipeTestHelper($config[$pipe], $targetFolder, $account); + $this->_assertMessageInFolder($targetFolder, $message['subject'], $account); + + // move to sub folder + $pipe = 'spam'; + $targetFolder = 'INBOX.SPAM'; // 'spam': folder called spam , '#spam': user configured spam folder + $config[$pipe]['config']['target']['folder'] = 'INBOX/SPAM'; + $message = $this->_messagePipeTestHelper($config[$pipe], $targetFolder, $account); + $this->_assertMessageInFolder($targetFolder, $message['subject'], $account); + + $pipe = 'ham'; + $targetFolder = 'INBOX.HAM'; + $config[$pipe]['config']['target']['folder'] = 'INBOX/HAM'; + $message = $this->_messagePipeTestHelper($config[$pipe], $targetFolder, $account); + $this->_assertMessageInFolder($targetFolder, $message['subject'], $account); + + } /** @@ -169,17 +189,15 @@ public function testMessagePipeRewriteSubject() * * @param array $_config * @param string $_folderName - * @param Felamimail_Model_Account $_account + * @param Felamimail_Model_Account|null $_account * * @return Felamimail_Model_Message|NULL * - * @throws Felamimail_Exception_IMAPServiceUnavailable * @throws Tinebase_Exception_InvalidArgument * @throws Tinebase_Exception_NotFound * @throws Tinebase_Exception_Record_DefinitionFailure * @throws Tinebase_Exception_Record_NotAllowed * @throws Tinebase_Exception_Record_Validation - * @throws Zend_Mail_Transport_Exception */ public function _messagePipeTestHelper($_config, $_folderName, Felamimail_Model_Account $_account = null) { @@ -190,9 +208,9 @@ public function _messagePipeTestHelper($_config, $_folderName, Felamimail_Model_ 'pattern' => '/^SPAM\? \(.+\) \*\*\* /', ]; Felamimail_Config::getInstance()->set(Felamimail_Config::SPAM_SUSPICION_STRATEGY_CONFIG, $config); - + + $this->_getFolder('INBOX', true, $_account); $this->_foldersToClear[] = ['INBOX', 'Sent', 'Trash']; - $this->_getFolder($_folderName, true, $_account); $subject = 'SPAM? (15) *** test messagePipe'; diff --git a/tine20/Felamimail/Model/MessagePipeMove.php b/tine20/Felamimail/Model/MessagePipeMove.php index 19f9819e955..9bde770c1c4 100644 --- a/tine20/Felamimail/Model/MessagePipeMove.php +++ b/tine20/Felamimail/Model/MessagePipeMove.php @@ -76,13 +76,15 @@ public static function getTargetFolder($_account, $_targetFolder) } $_targetFolder = $_account->{$propertyName}; } - + try { + $_targetFolder = str_replace('/', '.', $_targetFolder); $folder = Felamimail_Controller_Folder::getInstance() ->getByBackendAndGlobalName($_account['id'], $_targetFolder); } catch (Tinebase_Exception_NotFound $e) { + $splitFolderName = Felamimail_Model_Folder::extractLocalnameAndParent($_targetFolder, '.'); $folder = Felamimail_Controller_Folder::getInstance() - ->create($_account['id'], $_targetFolder); + ->create($_account['id'], $splitFolderName['localname'], $splitFolderName['parent']); } return $folder;