Skip to content

Commit

Permalink
Merge branch '2023.11' into 2024.11
Browse files Browse the repository at this point in the history
  • Loading branch information
gitlabci committed Jan 16, 2024
2 parents 3d9e472 + 3461360 commit f41ac21
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/tine20/Admin/Frontend/Json/EmailAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testEmailAccountApi()
* @param array $data
* @return array
*/
public static function getSharedAccountData($sendgrant = true, $data = [])
public static function getSharedAccountData(bool $sendgrant = true, array $data = [])
{
return array_merge([
'name' => 'unittest shared account',
Expand Down
67 changes: 65 additions & 2 deletions tests/tine20/Felamimail/Frontend/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ public function testForwardAttachmentCachePdf()
'attachments' => $messageToSend['attachments']
));
Felamimail_Controller_Message_Send::getInstance()->sendMessage($forwardMessage);

$forwardMessage = $this->_searchForMessageBySubject('test forward with attachmnets');
$this->_foldersToClear = array('INBOX', $this->_account->sent_folder);
$fullMessage = Felamimail_Controller_Message::getInstance()->getCompleteMessage($forwardMessage['id']);
Expand Down Expand Up @@ -3248,7 +3248,70 @@ public function testMoveFolder()
$testFolder = Felamimail_Controller_Folder::getInstance()->getByBackendAndGlobalName($this->_account, $this->_testFolderName);
self::assertEquals(1, $testFolder->has_children, 'has_children should be 1');
}


/**
* 1. Folder "A" unter der Inbox erstellen.
* 2. Bei beiden Usern die Ordnerliste aktualisieren.
* 3. Bei UserA den Folder "A" löschen.
* 4. Bei UserB den Folder "B" unter den Folder "A" erstellen.
* 5. Bei beiden Usern die Ordnerliste aktualisieren.
*
* @return void
* @throws Tinebase_Exception_AccessDenied
* @throws Tinebase_Exception_InvalidArgument
* @throws Tinebase_Exception_NotFound
* @throws Tinebase_Exception_Record_DefinitionFailure
* @throws Tinebase_Exception_Record_Validation
*/
public function testDeleteFolderWithAnotherUserInSharedAccount()
{
$parent = 'INBOX';
$testFolder = 'subfolder';
$jsmith = $this->_personas['jsmith'];
$account = $this->_createSharedAccount(true, [
'grants' => [
[
'readGrant' => true,
'editGrant' => true,
'addGrant' => true,
'account_type' => 'user',
'account_id' => Tinebase_Core::getUser()->getId(),
], [
'readGrant' => true,
'editGrant' => true,
'addGrant' => true,
'account_type' => 'user',
'account_id' => $jsmith->getId(),
]
]
]);

try {
$this->_json->addFolder($parent, '', $account->getId());
} catch (Tinebase_Exception_SystemGeneric $tesg) {
// already exists
}
$folder = $this->_json->addFolder($testFolder, $parent, $account->getId());
$testFolderGlobalname = $folder['globalname'];

$this->_json->updateFolderCache($account->getId(), $parent);
Tinebase_Core::setUser($jsmith);
$this->_json->updateFolderCache($account->getId(), $parent);
Tinebase_Core::setUser($this->_originalTestUser);
$this->_json->deleteFolder($testFolderGlobalname, $account->getId());
Tinebase_Core::setUser($jsmith);
try {
$this->_json->addFolder('subfolder2', $testFolderGlobalname, $account->getId());
$result = $this->_json->updateFolderCache($account->getId(), $parent);
$folder = $result[0];
self::assertEquals(1, $folder['is_selectable'], 'folder should be selectable (or removed!): '
. print_r($folder, true));
} catch (Tinebase_Exception_NotFound $tenf) {
self::assertEquals('Could not create folder: parent folder INBOX.subfolder not found',
$tenf->getMessage());
}
}

public function testRefreshFolder()
{
$folder = $this->_getFolder($this->_testFolderName);
Expand Down
7 changes: 4 additions & 3 deletions tests/tine20/Felamimail/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,18 @@ protected function _sieveTestHelper(array $_sieveData, bool $_isMime = false, ?s

/**
* @param bool $sendgrant
* @return Tinebase_Record_Interface
* @return Felamimail_Model_Account
* @throws Tinebase_Exception_AccessDenied
* @throws Tinebase_Exception_InvalidArgument
* @throws Tinebase_Exception_NotFound
* @throws Tinebase_Exception_Record_DefinitionFailure
* @throws Tinebase_Exception_Record_Validation
*/
protected function _createSharedAccount($sendgrant = true)
protected function _createSharedAccount(bool $sendgrant = true, array $data = [])
{
Tinebase_EmailUser::clearCaches();
$sharedAccountData = Admin_Frontend_Json_EmailAccountTest::getSharedAccountData($sendgrant);
$sharedAccountData = Admin_Frontend_Json_EmailAccountTest::getSharedAccountData($sendgrant, $data);
/* @var Felamimail_Model_Account $sharedAccount */
$sharedAccount = Admin_Controller_EmailAccount::getInstance()->create(new Felamimail_Model_Account($sharedAccountData));
// we need to commit so imap user is in imap db
Tinebase_TransactionManager::getInstance()->commitTransaction($this->_transactionId);
Expand Down
1 change: 1 addition & 0 deletions tine20/Felamimail/Backend/ImapProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @method examineFolder($globalName)
* @method removeMessage($id)
* @method getChangedFlags($modseq)
* @method createFolder($name, $parentFolder = null, $_delimiter = '/')
*/
class Felamimail_Backend_ImapProxy
{
Expand Down
41 changes: 31 additions & 10 deletions tine20/Felamimail/Controller/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,46 @@ public function getByBackendAndGlobalName($_accountId, $_globalName)
* create folder
*
* @param string|Felamimail_Model_Account $_accountId
* @param string $_folderName to create
* @param string $_parentFolder parent folder globalname
* @param string $_folderName
* @param string $_parentFolder
* @return Felamimail_Model_Folder
* @throws Felamimail_Exception
* @throws Felamimail_Exception_IMAPInvalidCredentials
* @throws Felamimail_Exception_IMAPServiceUnavailable
* @throws Tinebase_Exception_NotFound
* @throws Tinebase_Exception_Record_DefinitionFailure
* @throws Tinebase_Exception_Record_Validation
* @throws Tinebase_Exception_SystemGeneric
*/
public function create($_accountId, $_folderName, $_parentFolder = '')
public function create($_accountId, string $_folderName, string $_parentFolder = ''): Felamimail_Model_Folder
{
$account = ($_accountId instanceof Felamimail_Model_Account) ? $_accountId : Felamimail_Controller_Account::getInstance()->get($_accountId);
$account = ($_accountId instanceof Felamimail_Model_Account)
? $_accountId
: Felamimail_Controller_Account::getInstance()->get($_accountId);
$this->_delimiter = $account->delimiter;

$foldername = $this->_prepareFolderName($_folderName);
$globalname = (empty($_parentFolder)) ? $foldername : $_parentFolder . $this->_delimiter . $foldername;
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Trying to create new folder: ' . $globalname . ' (parent: ' . $_parentFolder . ')');
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(
__METHOD__ . '::' . __LINE__ . ' Trying to create new folder: ' . $globalname
. ' (parent: ' . $_parentFolder . ')');

$imap = Felamimail_Backend_ImapFactory::factory($account);


// check if parent folder exists
if (! empty($_parentFolder)) {
try {
$imap->examineFolder($_parentFolder);
} catch (Zend_Mail_Storage_Exception $zmse) {
throw new Tinebase_Exception_NotFound('Could not create folder: parent folder '
. $_parentFolder . ' not found');
}
}

try {
$imap->createFolder(
Felamimail_Model_Folder::encodeFolderName($foldername),
(empty($_parentFolder)) ? NULL : Felamimail_Model_Folder::encodeFolderName($_parentFolder),
(empty($_parentFolder)) ? null : Felamimail_Model_Folder::encodeFolderName($_parentFolder),
$this->_delimiter
);

Expand All @@ -247,7 +266,8 @@ public function create($_accountId, $_folderName, $_parentFolder = '')
'parent' => $_parentFolder,
));
$folder->supports_condstore = $this->supportsCondStore($folder, $account, $imap);


/* @var Felamimail_Model_Folder $folder */
$folder = $this->_backend->create($folder);

if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(
Expand All @@ -256,12 +276,13 @@ public function create($_accountId, $_folderName, $_parentFolder = '')
} catch (Zend_Mail_Storage_Exception $zmse) {
// perhaps the folder already exists
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(
__METHOD__ . '::' . __LINE__ . ' Could not create new folder: ' . $globalname . ' (' . $zmse->getMessage() . ')');
__METHOD__ . '::' . __LINE__ . ' Could not create new folder: ' . $globalname
. ' (' . $zmse->getMessage() . ')');

// reload folder cache of parent
$parentSubs = $this->_cacheController->update($account, $_parentFolder);
$folder = $parentSubs->filter('globalname', $globalname)->getFirstRecord();
if ($folder === NULL) {
if ($folder === null) {
throw new Felamimail_Exception_IMAPServiceUnavailable($zmse->getMessage());
}

Expand Down

0 comments on commit f41ac21

Please sign in to comment.