protected function actionMove($params) { $account = \GO\Email\Model\Account::model()->findByPk($params['account_id']); $sourceMailbox = new \GO\Email\Model\ImapMailbox($account, array("name" => $params["sourceMailbox"])); if ($sourceMailbox->isSpecial()) { throw new \Exception(\GO::t("cantMoveSpecialFolder", "email")); } $targetMailbox = new \GO\Email\Model\ImapMailbox($account, array("name" => $params["targetMailbox"])); $response['success'] = $sourceMailbox->move($targetMailbox); if (!$response['success']) { $response['feedback'] = "Could not move folder {$sourceMailbox} to {$targetMailbox}.<br /><br />" . $account->getImapConnection()->last_error(); } return $response; }
/** * Build the tree for the portlet folders * * @param array $params * @return array $response */ public function actionPortletTree($params) { \GO::session()->closeWriting(); $response = array(); if ($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'); $stmt = \GO\Email\Model\Account::model()->find($findParams); // Loop throught the found accounts and build the accounts root node. while ($account = $stmt->fetch()) { $alias = $account->getDefaultAlias(); if ($alias) { $nodeId = 'account_' . $account->id; $node = array('text' => $alias->email, 'name' => $alias->email, 'id' => $nodeId, 'isAccount' => true, 'hasError' => false, 'iconCls' => 'folder-account', 'expanded' => $this->_isExpanded($nodeId), 'noselect' => false, 'account_id' => $account->id, 'mailbox' => '', 'noinferiors' => false); // Try to find the children try { $account->openImapConnection(); if ($node['expanded']) { $node['children'] = $this->_getMailboxTreeNodes($account->getRootMailboxes(true)); } } catch (\Exception $e) { $this->_checkImapConnectException($e, $node); } $response[] = $node; } } } else { $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; }