/** * Transforms an imap Zend_Mail_Storage_Folder to an instance * of Conjoon_Modules_Groupware_Email_Folder_Dto. * * @param Zend_Mail_Storage_Folder $folder * @param boolean $lookupStandardNames Whether standard names like "INBOX" * and trash should be looked up and addiotnal properties adjusted for them. * @param array $config A preset set of config properties which are used * for the properties of the created FolderDto. By now, only the id, the * idForPath and the pendingCount property are considered. * * @return Conjoon_Modules_Groupware_Email_Folder_Dto */ public static function transformToFolderDto(Zend_Mail_Storage_Folder $folder, $lookupStandardNames = false, array $config = array()) { /** * @see Conjoon_Modules_Groupware_Email_Folder_Dto */ require_once 'Conjoon/Modules/Groupware/Email/Folder/Dto.php'; $tmpFolder = new Conjoon_Modules_Groupware_Email_Folder_Dto(); // go through predefined variables if (isset($config['id'])) { $tmpFolder->id = $config['id']; } else { $tmpFolder->id = $folder->getGlobalName(); } if (isset($config['idForPath'])) { $tmpFolder->idForPath = $config['idForPath']; } else { $tmpFolder->idForPath = $folder->getGlobalName(); } if (isset($config['pendingCount'])) { $tmpFolder->pendingCount = $config['pendingCount']; } $childCount = 0; if (isset($config['childCount'])) { $childCount = $config['childCount']; } $tmpFolder->type = $config['type']; $tmpFolder->name = $folder->getLocalName(); $tmpFolder->isChildAllowed = 1; $tmpFolder->isLocked = 0; //hasChildren doesnt seem to work $tmpFolder->childCount = $childCount; $tmpFolder->isSelectable = $folder->isSelectable() ? 1 : 0; return $tmpFolder; }
/** * Gathers all needed information to tranform an imap folder to a * Conjoon_Modules_Groupware_Email_Folder_Dto obejct. * * @param Zend_Mail_Storage_Folder $folder * @param Conjoon_Modules_Groupware_Email_Account_Dto $account * @param Zend_Mail_Protocol_Imap $protocol * @param boolean $isRootLevel Whether the folder is on the first level of * the mailbox hierarchy * * @return Conjoon_Modules_Groupware_Email_Folder_Dto */ private function _transformImapFolder(Zend_Mail_Storage_Folder $folder, Conjoon_Modules_Groupware_Email_Account_Dto $account, Zend_Mail_Protocol_Imap $protocol, $isRootLevel = false, $type = 'folder') { $delim = Conjoon_Modules_Groupware_Email_ImapHelper::getFolderDelimiterForImapAccount($account); $globalName = $folder->getGlobalName(); $path = explode($delim, $globalName); $path = $path[count($path) - 1]; $pendingCount = 0; if (!$this->itemListRequestFacade) { $this->itemListRequestFacade = Conjoon_Modules_Groupware_Email_Item_ItemListRequestFacade::getInstance(); } if ($folder->isSelectable()) { try { $pendingCount = $this->itemListRequestFacade->getPendingCountForGlobalName($account, $globalName); } catch (Exception $e) { // ignore } } $childCount = 0; if (!$folder->isLeaf()) { $protocol = Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($account); /** * @see Zend_Mail_Storage_Imap */ require_once 'Zend/Mail/Storage/Imap.php'; $imap = new Zend_Mail_Storage_Imap($protocol); /** * @ticket CN-595 */ if ($globalName === "INBOX") { $iFolders = $imap->getFolders(null)->getChildren(); } else { $iFolders = $imap->getFolders($globalName)->getChildren(); } foreach ($iFolders as $tmpFolder) { $childCount++; } } return Conjoon_Modules_Groupware_Email_ImapHelper::transformToFolderDto($folder, $isRootLevel, array('id' => $account->id . '_' . $globalName, 'idForPath' => $path, 'pendingCount' => $pendingCount, 'type' => $type, 'childCount' => $childCount)); }