Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(Felamimail/Spam): move message to sub folder
Browse files Browse the repository at this point in the history
Change-Id: I92eac13524e6b2d94a18d885160aa09e2551ccb2
Reviewed-on: http://gerrit.tine20.com/customers/18649
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
  • Loading branch information
ccheng-dev authored and pschuele committed Dec 7, 2020
1 parent 088e715 commit d214ec3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
40 changes: 29 additions & 11 deletions tests/tine20/Felamimail/Model/MessagePipeTest.php
Expand Up @@ -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' => [
Expand All @@ -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);


}

/**
Expand Down Expand Up @@ -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)
{
Expand All @@ -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';

Expand Down
6 changes: 4 additions & 2 deletions tine20/Felamimail/Model/MessagePipeMove.php
Expand Up @@ -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;
Expand Down

0 comments on commit d214ec3

Please sign in to comment.