예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 protected function actionCheckUnseen($params)
 {
     $response = array("success" => true);
     $response['email_status']['total_unseen'] = 0;
     $response['email_status']['unseen'] = array();
     \GO::session()->closeWriting();
     $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAdminGroup()->select('t.*');
     $stmt = \GO\Email\Model\Account::model()->find($findParams);
     while ($account = $stmt->fetch()) {
         try {
             if ($account->getDefaultAlias()) {
                 $checkMailboxArray = $account->getAutoCheckMailboxes();
                 //$imap = $account->openImapConnection();
                 $existingCheckMailboxArray = array();
                 foreach ($checkMailboxArray as $checkMailboxName) {
                     if (!empty($checkMailboxName)) {
                         $mailbox = new \GO\Email\Model\ImapMailbox($account, array('name' => $checkMailboxName));
                         if ($mailbox->exists()) {
                             if (!isset($response['email_status']['has_new']) && $mailbox->hasAlarm()) {
                                 $response['email_status']['has_new'] = true;
                             }
                             $mailbox->snoozeAlarm();
                             $response['email_status']['unseen'][] = array('account_id' => $account->id, 'mailbox' => $checkMailboxName, 'unseen' => $mailbox->unseen);
                             $response['email_status']['total_unseen'] += $mailbox->unseen;
                             $existingCheckMailboxArray[] = $checkMailboxName;
                         }
                     }
                 }
                 $account->check_mailboxes = implode(',', $existingCheckMailboxArray);
                 if ($account->isModified("check_mailboxes")) {
                     $account->save();
                 }
                 if ($imap = $account->getImapConnection()) {
                     $imap->disconnect();
                 }
             }
         } catch (\Exception $e) {
             \GO::debug($e->getMessage());
         }
     }
     \GO::debug("Total unseen: " . $response['email_status']['total_unseen']);
     //$response['email_status']['has_new']=true;
     return $response;
 }