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

Commit

Permalink
fix(Felamimail/Folder): always check if folder supports condstore on …
Browse files Browse the repository at this point in the history
…create

- also fix field value on folder update, if still null
  • Loading branch information
pschuele committed Nov 23, 2021
1 parent ed12e3b commit ad900e4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 41 deletions.
2 changes: 1 addition & 1 deletion tests/tine20/Felamimail/Frontend/JsonTest.php
Expand Up @@ -942,7 +942,7 @@ public function testCopyMessageToAnotherFolderDisabled()
self::fail('copy should not be possible');
} catch (Exception $e) {
$translation = Tinebase_Translation::getTranslation('Felamimail');
self::assertEquals($translation->_('It is not allowed to copy e-mails in the same account.'), $e->getMessage());
self::assertEquals($translation->_('It is not allowed to copy e-mails in the same account.'), $e->getMessage(), $e);
}

Felamimail_Config::getInstance()->set(Felamimail_Config::PREVENT_COPY_OF_MAILS_IN_SAME_ACCOUNT, false);
Expand Down
38 changes: 3 additions & 35 deletions tine20/Felamimail/Controller/Cache/Folder.php
Expand Up @@ -324,7 +324,7 @@ protected function _getOrCreateFolders(array $_folders, $_account, $_parentFolde
$folder = Felamimail_Controller_Folder::getInstance()->getByBackendAndGlobalName($_account->getId(), $folderData['globalName']);

$folder->is_selectable = $isSelectable;
$folder->supports_condstore = $this->_supportsCondStore($folder, $_account);
$folder->supports_condstore = Felamimail_Controller_Folder::getInstance()->supportsCondStore($folder, $_account);
$folder->imap_status = Felamimail_Model_Folder::IMAP_STATUS_OK;
$folder->has_children = ($folderData['hasChildren'] == '1');
$folder->parent = $parentFolder;
Expand All @@ -346,7 +346,8 @@ protected function _getOrCreateFolders(array $_folders, $_account, $_parentFolde
'localname' => $folderData['localName'],
'globalname' => $folderData['globalName'],
'is_selectable' => $isSelectable,
'supports_condstore' => $this->_supportsCondStore($folderData['globalName'], $_account),
'supports_condstore' => Felamimail_Controller_Folder::getInstance()->supportsCondStore(
$folderData['globalName'], $_account),
'has_children' => ($folderData['hasChildren'] == '1'),
'account_id' => $_account->getId(),
'imap_timestamp' => Tinebase_DateTime::now(),
Expand Down Expand Up @@ -380,39 +381,6 @@ protected function _getOrCreateFolders(array $_folders, $_account, $_parentFolde
return $result;
}

/**
* check if folder support condstore: try to exmime folder on imap server if supports_condstore is null
*
* @param string|Felamimail_Model_Folder $folder
* @param Felamimail_Model_Account $_account
* @return boolean
*/
protected function _supportsCondStore($folder, $account)
{
if (is_string($folder) || $folder->supports_condstore === null) {
$folderName = is_string($folder) ? $folder : $folder->globalname;

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

try {
$folderData = $imap->examineFolder(Felamimail_Model_Folder::encodeFolderName($folderName));

$result = isset($folderData['highestmodseq']) || array_key_exists('highestmodseq', $folderData);
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .
' Folder ' . $folderName . ' supports condstore: ' . intval($result));

return $result;

} catch (Zend_Mail_Storage_Exception $zmse) {
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(
__METHOD__ . '::' . __LINE__ . " Could not examine folder $folderName. Skipping it.");
return null;
}
}

return $folder->supports_condstore;
}

/**
* check if folder is selectable: try to select folder on imap server if isSelectable is false/not set
* - courier imap servers subfolder have isSelectable = 0 but they still can be selected
Expand Down
55 changes: 50 additions & 5 deletions tine20/Felamimail/Controller/Folder.php
Expand Up @@ -234,11 +234,12 @@ public function create($_accountId, $_folderName, $_parentFolder = '')

// create new folder
$folder = new Felamimail_Model_Folder(array(
'localname' => $foldername,
'globalname' => $globalname,
'account_id' => $account->getId(),
'parent' => $_parentFolder
'localname' => $foldername,
'globalname' => $globalname,
'account_id' => $account->getId(),
'parent' => $_parentFolder,
));
$folder->supports_condstore = $this->supportsCondStore($folder, $account, $imap);

$folder = $this->_backend->create($folder);

Expand Down Expand Up @@ -272,7 +273,50 @@ public function create($_accountId, $_folderName, $_parentFolder = '')

return $folder;
}


/**
* check if folder support condstore: try to exmime folder on imap server if supports_condstore is null
*
* @param string|Felamimail_Model_Folder $folder
* @param Felamimail_Model_Account|null $_account
* @param Felamimail_Backend_ImapProxy|null $imap
* @return boolean
*/
public function supportsCondStore($folder, Felamimail_Model_Account $account = null, $imap = null)
{
if (is_string($folder) || $folder->supports_condstore === null) {
$folderName = is_string($folder) ? $folder : $folder->globalname;

if (! $imap) {
if (!$account) {
if ($folder instanceof Felamimail_Model_Folder) {
$account = Felamimail_Controller_Account::getInstance()->get($folder->account_id);
} else {
throw new Felamimail_Exception('no valid account found for folder');
}
}
$imap = Felamimail_Backend_ImapFactory::factory($account);
}

try {
$folderData = $imap->examineFolder(Felamimail_Model_Folder::encodeFolderName($folderName));

$result = isset($folderData['highestmodseq']) || array_key_exists('highestmodseq', $folderData);
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .
' Folder ' . $folderName . ' supports condstore: ' . intval($result));

return $result;

} catch (Zend_Mail_Storage_Exception $zmse) {
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(
__METHOD__ . '::' . __LINE__ . " Could not examine folder $folderName. Skipping it.");
return null;
}
}

return $folder->supports_condstore;
}

/**
* prepare foldername given by user (remove some bad chars)
*
Expand All @@ -294,6 +338,7 @@ protected function _prepareFolderName($_folderName)
*/
public function update(Felamimail_Model_Folder $_folder)
{
$_folder->supports_condstore = $this->supportsCondStore($_folder);
return $this->_backend->update($_folder);
}

Expand Down

0 comments on commit ad900e4

Please sign in to comment.