/** * get folder status/values from imap server and update folder cache record in database * * @param string $_folderID * @return Expressomail_Model_Folder * * @todo It should'nt access Imap Backend directly. Method should be at Expressomail_Backend_Folder */ public function getIMAPFolderCounter($_folderID) { $folderData = Expressomail_Backend_Folder::decodeFolderUid($_folderID); $imap = Expressomail_Backend_ImapFactory::factory($folderData['accountId']); // get folder values / status from imap server $counter = $imap->examineFolder($folderData['globalName']); if ($counter['recent'] > 0) { $imap->selectFolder($folderData['globalName']); $idsInFolder = $imap->sort(array('DATE'), array('RECENT')); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($counter, TRUE)); } $folder = new Expressomail_Model_Folder(); // check validity $folder->id = $_folderID; $folder->globalname = $folderData['globalName']; $folder->cache_recentcount = $counter['recent']; $folder->imap_uidvalidity = $counter['uidvalidity']; $folder->imap_totalcount = $counter['exists']; $folder->imap_status = Expressomail_Model_Folder::IMAP_STATUS_OK; $folder->imap_timestamp = Tinebase_DateTime::now(); return $folder; }
/** * Deletes entries * * @param string|integer|Tinebase_Record_Interface|array $_id * @return void * @return int The number of affected rows. */ public function delete($_id) { $_id = $_id instanceof Expressomail_Model_Message ? array($_id->getId()) : $_id; if (is_array($_id)) { foreach ($_id as $id) { $decodedIds = self::decodeMessageId($id); $globalname = Expressomail_Backend_Folder::decodeFolderUid($decodedIds['folderId']); $accountId = $decodedIds['accountId']; $imap = Expressomail_Backend_ImapFactory::factory($accountId); $imap->expunge($globalname['globalName']); $return = count($_id); } } return $return; }
/** * Update folderBackend imapstatus * @param Syncroton_Model_IFolder $folder * @return true | false | null on exception */ public function setFolderImapStatus(Syncroton_Model_IFolder $folder) { $folderDecoded = Expressomail_Backend_Folder::decodeFolderUid($folder->bigfolderid); $imapStatus = Expressomail_Controller_Folder::getFolderImapStatus($folderDecoded['accountId'], $folderDecoded['globalName']); if ($imapStatus === false) { return null; } // Exception Raised if (serialize($imapStatus) !== $folder->imapstatus) { $folderBackend = Syncroton_Registry::getFolderBackend(); $folder->imapstatus = serialize($imapStatus); $updateStatus = $folderBackend->update($folder); return true; } return false; }
/** * Compare order of Expressomail_Model_Message acording to Tinebase_Model_Pagination * @param Expressomail_Model_Message $msg1 * @param Expressomail_Model_Message $msg2 * @return int * * @todo Convert int security value in Expressomail_Smime to corresponding string type */ public function compare($msg1, $msg2) { switch ($this->_pagination->sort) { case 'received': // Integer $value1 = $msg1[$this->_pagination->sort]; $value2 = $msg2[$this->_pagination->sort]; case 'sent': // Integer $value1 = isset($value1) ? $value1 : $msg1['header']['date']; $value2 = isset($value2) ? $value2 : $msg2['header']['date']; $value1 = intval(Expressomail_Message::convertDate($value1)->format("U")); $value2 = intval(Expressomail_Message::convertDate($value2)->format("U")); case 'size': // Integer $value1 = isset($value1) ? $value1 : intval($msg1[$this->_pagination->sort]); $value2 = isset($value2) ? $value2 : intval($msg2[$this->_pagination->sort]); return $this->compareIntegers($value1, $value2); case 'folder_id': // Strings $folders = array(); $translate = Tinebase_Translation::getTranslation('Expressomail'); foreach (array($msg1, $msg2) as $msg) { $folder = Expressomail_Backend_Folder::decodeFolderUid($msg[$this->_pagination->sort]); // Optimization! Only create the account object once for every sort operation. $account = array_key_exists($folder['accountId'], $this->_accountMap) ? $this->_accountMap[$folder['accountId']] : ($this->_accountMap[$folder['accountId']] = Expressomail_Controller_Account::getInstance()->get($folder['accountId'])); $aux1 = explode('/', $folder['globalName']); $aux2 = ''; foreach ($aux1 as $value) { $aux2 .= $translate->_($value) . '/'; } $folders[] = $account->name . '/' . substr($aux2, 0, strlen($aux2) - 1); } list($value1, $value2) = $folders; //TODO: Should use a static method implemented on Model_Message or Expressomail_Smime //TODO: Should use a static method implemented on Model_Message or Expressomail_Smime case 'smime': $value1 = isset($value1) ? $value1 : $this->processSmimeValue($msg1['structure']); $value2 = isset($value2) ? $value2 : $this->processSmimeValue($msg2['structure']); case 'flags': // Strings if (!isset($value1)) { sort($msg1['flags']); $value1 = implode(',', $msg1['flags']); } if (!isset($value2)) { sort($msg2['flags']); $value2 = implode(',', $msg2['flags']); } case 'subject': // Strings $value1 = isset($value1) ? $value1 : $msg1['header'][$this->_pagination->sort]; $value2 = isset($value2) ? $value2 : $msg2['header'][$this->_pagination->sort]; case 'id': // Strings $value1 = isset($value1) ? $value1 : $msg1[$this->_pagination->sort]; $value2 = isset($value2) ? $value2 : $msg2[$this->_pagination->sort]; return $this->compareStrings($value1, $value2); case 'sender': case 'to': case 'from_name': case 'from_email': // Strings list($header, $field) = explode('_', $this->_pagination->sort); $field = empty($field) ? 'email' : $field; $address1 = Expressomail_Message::convertAddresses($msg1['header'][$header]); $address2 = Expressomail_Message::convertAddresses($msg2['header'][$header]); return $this->compareStrings(isset($address1[0]) && array_key_exists($field, $address1[0]) ? $address1[0][$field] : '', isset($address2[0]) && array_key_exists($field, $address2[0]) ? $address2[0][$field] : ''); } }