/** * * @return \ImapMailbox */ public function getAllMailboxes($hierarchy = true, $withStatus = false) { $imap = $this->openImapConnection(); $folders = $imap->list_folders(true, $withStatus, '', '*', true); //$node= array('name'=>'','children'=>array()); $rootMailboxes = array(); $mailboxModels = array(); foreach ($folders as $folder) { $mailbox = new ImapMailbox($this, $folder); if ($hierarchy) { $mailboxModels[$folder['name']] = $mailbox; $parentName = $mailbox->getParentName(); if ($parentName === false) { $rootMailboxes[] = $mailbox; } else { $mailboxModels[$parentName]->addChild($mailbox); } } else { $rootMailboxes[] = $mailbox; } } return $rootMailboxes; }
/** * Add a flag to one or multiple messages * * @param array $params * - int account_id: the id of the GO email account * - string messages: the json encoded mail messages * - string mailbox: the mailbox the find the messages in * - string flag: the flag to set. eg "FLAG" * - boolean clear: true is the other flags should be removed * @return type */ protected function actionSetFlag($params) { GO::session()->closeWriting(); $messages = json_decode($params['messages']); $account = Account::model()->findByPk($params['account_id']); $requiredPermissionLevel = $params["flag"] == 'Seen' && !empty($params["clear"]) ? Acl::CREATE_PERMISSION : Account::ACL_DELEGATED_PERMISSION; if (!$account->checkPermissionLevel($requiredPermissionLevel)) { throw new \GO\Base\Exception\AccessDenied(); } $imap = $account->openImapConnection($params["mailbox"]); if (in_array(ucfirst($params['flag']), Imap::$systemFlags)) { $params["flag"] = "\\" . ucfirst($params["flag"]); } $response['success'] = $imap->set_message_flag($messages, $params["flag"], !empty($params["clear"])); $mailbox = new \GO\Email\Model\ImapMailbox($account, array('name' => $params['mailbox'])); $mailbox->snoozeAlarm(); $response['unseen'] = $mailbox->unseen; return $response; }
public function actionTree($params) { \GO::session()->closeWriting(); $response = array(); if (!isset($params['node'])) { return $response; } elseif ($params['node'] == 'root') { $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*')->joinModel(array('model' => 'GO\\Email\\Model\\AccountSort', 'foreignField' => 'account_id', 'localField' => 'id', 'type' => 'LEFT', 'tableAlias' => 's', 'criteria' => \GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', \GO::user()->id, '=', 's')))->ignoreAdminGroup()->order('order', 'DESC'); if (isset($params['permissionLevel'])) { $findParams->permissionLevel($params['permissionLevel']); } $stmt = \GO\Email\Model\Account::model()->find($findParams); while ($account = $stmt->fetch()) { $alias = $account->getDefaultAlias(); if ($alias) { $nodeId = base64_encode('account_' . $account->id); $node = array('text' => $alias->email, 'name' => $alias->email, 'id' => $nodeId, 'isAccount' => true, 'permission_level' => $account->getPermissionLevel(), 'hasError' => false, 'iconCls' => 'folder-account', 'expanded' => $this->_isExpanded($nodeId), 'noselect' => false, 'account_id' => $account->id, 'mailbox' => rtrim($account->mbroot, "./"), 'noinferiors' => false); if ($node['permission_level'] <= \GO\Base\Model\Acl::READ_PERMISSION) { $node['cls'] = 'em-readonly'; } // try{ // if($node['expanded']){ // $account->openImapConnection(); // $rootMailboxes = $account->getRootMailboxes(true); // $node['children']=$this->_getMailboxTreeNodes($rootMailboxes); // } // // }catch(\GO\Base\Mail\ImapAuthenticationFailedException $e){ // //$this->_checkImapConnectException($e,$node); // $node['isAccount'] = false; // $node['hasError'] = true; // $node['text'] .= ' ('.\GO::t('error').')'; // $node['children']=array(); // $node['expanded']=true; // $node['qtipCfg'] = array('title'=>\GO::t('error'), 'text' =>htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8')); // } $response[] = $node; } } } else { // $this->_setExpanded($params['node']); $params['node'] = base64_decode($params['node']); $parts = explode('_', $params['node']); $type = array_shift($parts); $accountId = array_shift($parts); $mailboxName = implode('_', $parts); $account = \GO\Email\Model\Account::model()->findByPk($accountId); if ($type == "account") { $response = $this->_getMailboxTreeNodes($account->getRootMailboxes(true)); } else { $mailbox = new \GO\Email\Model\ImapMailbox($account, array('name' => $mailboxName)); $response = $this->_getMailboxTreeNodes($mailbox->getChildren()); } } return $response; }