Beispiel #1
0
 /**
  * processStoreDelete
  *
  * @param $store
  * @param $params
  */
 protected function processStoreDelete($store, &$params)
 {
     if (isset($params['delete_keys'])) {
         $deleteRecords = json_decode($params['delete_keys'], true);
         $deleteRecords = array_filter($deleteRecords, 'intval');
         $criteria = FindCriteria::newInstance();
         $criteria->addCondition('default', 0);
         $criteria->addInCondition('id', $deleteRecords);
         $findParams = FindParams::newInstance()->criteria($criteria);
         $stmt = Label::model()->find($findParams);
         $deleteRecords = array();
         while ($label = $stmt->fetch()) {
             $deleteRecords[] = $label->getPk();
         }
         if (!count($deleteRecords)) {
             $params['delete_keys'] = '[]';
         } else {
             $params['delete_keys'] = json_encode($deleteRecords);
         }
     }
     $store->processDeleteActions($params, $this->model);
     if (isset($params['delete_keys']) && !count($params['delete_keys'])) {
         $store->response['deleteSuccess'] = true;
     }
 }
Beispiel #2
0
 protected function actionStore($params)
 {
     $this->checkRequiredParameters(array('account_id'), $params);
     GO::session()->closeWriting();
     if (!isset($params['start'])) {
         $params['start'] = 0;
     }
     if (!isset($params['limit'])) {
         $params['limit'] = GO::user()->max_rows_list;
     }
     if (!isset($params['dir'])) {
         $params['dir'] = "ASC";
     }
     $query = isset($params['query']) ? $params['query'] : "";
     //passed when only unread should be shown
     if (!empty($params['unread'])) {
         $query = str_replace(array('UNSEEN', 'SEEN'), array('', ''), $query);
         if ($query == '') {
             $query .= 'UNSEEN';
         } else {
             $query .= ' UNSEEN';
         }
     }
     $account = Account::model()->findByPk($params['account_id']);
     if (!$account) {
         throw new \GO\Base\Exception\NotFound();
     }
     /* @var $account Account */
     $this->_filterMessages($params["mailbox"], $account);
     $imap = $account->openImapConnection($params["mailbox"]);
     $response['permission_level'] = $account->getPermissionLevel();
     // ADDED EXPUNGE SO THE FOLDER WILL BE UP TO DATE (When moving folders in THUNDERBIRD)
     $imap->expunge();
     $response['unseen'] = array();
     //special folder flags
     $response['sent'] = !empty($account->sent) && strpos($params['mailbox'], $account->sent) === 0;
     $response['drafts'] = !empty($account->drafts) && strpos($params['mailbox'], $account->drafts) === 0;
     $response['trash'] = !empty($account->trash) && strpos($params['mailbox'], $account->trash) === 0;
     $this->_moveMessages($imap, $params, $response, $account);
     $sort = isset($params['sort']) ? $params['sort'] : 'from';
     switch ($sort) {
         case 'from':
             $sortField = $response['sent'] ? Imap::SORT_TO : Imap::SORT_FROM;
             break;
         case 'arrival':
             $sortField = Imap::SORT_ARRIVAL;
             //arrival is faster on older mail servers
             break;
         case 'date':
             $sortField = Imap::SORT_DATE;
             //arrival is faster on older mail servers
             break;
         case 'subject':
             $sortField = Imap::SORT_SUBJECT;
             break;
         case 'size':
             $sortField = Imap::SORT_SIZE;
             break;
         default:
             $sortField = Imap::SORT_DATE;
     }
     //		$imap = $account->openImapConnection($params["mailbox"]);
     //
     if (!empty($params['delete_keys'])) {
         if (!$account->checkPermissionLevel(Acl::CREATE_PERMISSION)) {
             $response['deleteFeedback'] = GO::t('strUnauthorizedText');
         } else {
             $uids = json_decode($params['delete_keys']);
             if (!$response['trash'] && !empty($account->trash)) {
                 $imap->set_message_flag($uids, "\\Seen");
                 $response['deleteSuccess'] = $imap->move($uids, $account->trash);
             } else {
                 $response['deleteSuccess'] = $imap->delete($uids);
             }
             if (!$response['deleteSuccess']) {
                 $lasterror = $imap->last_error();
                 if (stripos($lasterror, 'quota') !== false) {
                     $response['deleteFeedback'] = GO::t('quotaError', 'email');
                 } else {
                     $response['deleteFeedback'] = GO::t('deleteError') . ":\n\n" . $lasterror . "\n\n" . GO::t('disable_trash_folder', 'email');
                 }
             }
         }
     }
     //make sure we are connected to the right mailbox after move and delete operations
     //		$imap = $account->openImapConnection($params["mailbox"]);
     $response['multipleFolders'] = false;
     $searchIn = 'current';
     //default to current if not set
     if (isset($params['searchIn']) && in_array($params['searchIn'], array('all', 'recursive'))) {
         $searchIn = $params['searchIn'];
         $response['multipleFolders'] = true;
     }
     $messages = \GO\Email\Model\ImapMessage::model()->find($account, $params['mailbox'], $params['start'], $params['limit'], $sortField, $params['dir'] != 'ASC', $query, $searchIn);
     $labels = Label::model()->getAccountLabels($account->id);
     $response["results"] = array();
     foreach ($messages as $message) {
         $record = $message->getAttributes(true);
         $record['account_id'] = $account->id;
         if (!isset($record['mailbox'])) {
             $record['mailbox'] = $params["mailbox"];
         }
         $record['labels'] = array();
         foreach ($message->labels as $label) {
             if (isset($labels[$label])) {
                 $record['labels'][] = array('name' => $labels[$label]->name, 'color' => $labels[$label]->color, 'flag' => $labels[$label]->flag);
             }
         }
         $addresses = $message->to->getAddresses();
         $to = array();
         foreach ($addresses as $email => $personal) {
             $to[] = empty($personal) ? $email : $personal;
         }
         $record['to'] = htmlspecialchars(implode(',', $to), ENT_COMPAT, 'UTF-8');
         if ($response['sent'] || $response['drafts']) {
             $to = $record['to'];
             $record['to'] = $record['from'];
             $record['from'] = $to;
         }
         if (empty($record['subject'])) {
             $record['subject'] = GO::t('no_subject', 'email');
         } else {
             $record['subject'] = htmlspecialchars($record['subject'], ENT_COMPAT, 'UTF-8');
         }
         $response["results"][] = $record;
     }
     $response['total'] = $imap->sort_count;
     //$unseen = $imap->get_unseen($params['mailbox']);
     $mailbox = new \GO\Email\Model\ImapMailbox($account, array('name' => $params['mailbox']));
     $mailbox->snoozeAlarm();
     $response['unseen'][$params['mailbox']] = $mailbox->unseen;
     //deletes must be confirmed if no trash folder is used or when we are in the trash folder to delete permanently
     $response['deleteConfirm'] = empty($account->trash) || $account->trash == $params['mailbox'];
     return $response;
 }
Beispiel #3
0
 /**
  * Returns MIME fields contained in this class's instance as an associative
  * array.
  *
  * @param boolean $html Whether or not to return the HTML body. The alternative is
  * plain text. Defaults to true.
  *
  * @return Array
  */
 public function toOutputArray($html = true, $recipientsAsString = false, $noMaxBodySize = false, $useHtmlSpecialChars = true)
 {
     $from = $this->from->getAddresses();
     $response['notification'] = $this->disposition_notification_to;
     //seen is expensive because it can't be recovered from cache.
     // We'll use the grid to check if a message was seen or not.
     //$response['seen']=$this->seen;
     $from = $this->from->getAddress();
     $response['seen'] = $this->seen;
     $response['forwarded'] = $this->forwarded;
     $response['flagged'] = $this->flagged;
     $response['answered'] = $this->answered;
     $response['from'] = $from['personal'];
     $response['sender'] = $from['email'];
     $response['to'] = $recipientsAsString ? (string) $this->to : $this->_convertRecipientArray($this->to->getAddresses());
     $response['cc'] = $recipientsAsString ? (string) $this->cc : $this->_convertRecipientArray($this->cc->getAddresses());
     $response['bcc'] = $recipientsAsString ? (string) $this->bcc : $this->_convertRecipientArray($this->bcc->getAddresses());
     $response['reply_to'] = (string) $this->reply_to;
     $response['message_id'] = $this->message_id;
     $response['date'] = $this->date;
     $response['to_string'] = (string) $this->to;
     if (!$recipientsAsString && empty($response['to'])) {
         $response['to'][] = array('email' => '', 'personal' => \GO::t('no_recipients', 'email'));
     }
     $response['full_from'] = (string) $this->from;
     $response['priority'] = intval($this->x_priority);
     $response['udate'] = $this->udate;
     $response['date'] = \GO\Base\Util\Date::get_timestamp($this->udate);
     $response['size'] = $this->size;
     $labels = array();
     if (property_exists($this, 'account')) {
         $labels = \GO\Email\Model\Label::model()->getAccountLabels($this->account->id);
     }
     $response['labels'] = array();
     if (!empty($this->labels)) {
         foreach ($this->labels as $label) {
             if (isset($labels[$label])) {
                 $response['labels'][] = array('name' => $labels[$label]->name, 'color' => $labels[$label]->color);
             }
         }
     }
     $response['attachments'] = array();
     $response['zip_of_attachments_url'] = $this->getZipOfAttachmentsUrl();
     $response['inlineAttachments'] = array();
     if ($html) {
         $response['htmlbody'] = $this->getHtmlBody(false, $noMaxBodySize);
     } else {
         $response['plainbody'] = $this->getPlainBody(false, $noMaxBodySize);
     }
     if ($useHtmlSpecialChars) {
         $response['subject'] = htmlspecialchars($this->subject, ENT_COMPAT, 'UTF-8');
     } else {
         $response['subject'] = $this->subject;
     }
     $response['body_truncated'] = $this->bodyIsTruncated();
     $response['smime_signed'] = isset($this->content_type_attributes['smime-type']) && $this->content_type_attributes['smime-type'] == 'signed-data';
     $attachments = $this->getAttachments();
     foreach ($attachments as $att) {
         if ($html && $att->disposition != 'attachment') {
             if ($att->mime == 'text/html') {
                 $htmlPartStr = $att->getData();
                 $htmlPartStr = \GO\Base\Util\String::convertLinks($htmlPartStr);
                 $htmlPartStr = \GO\Base\Util\String::sanitizeHtml($htmlPartStr);
                 $response['htmlbody'] .= '<hr />' . $htmlPartStr;
                 continue;
             } else {
                 if ($att->mime == 'text/plain') {
                     $htmlPartStr = $att->getData();
                     $htmlPartStr = \GO\Base\Util\String::text_to_html($htmlPartStr);
                     $response['htmlbody'] .= '<hr />' . $htmlPartStr;
                     continue;
                 }
             }
         }
         $replaceCount = 0;
         $a = $att->getAttributes();
         //add unique token for detecting precense of inline attachment when we submit the message in handleFormInput
         $a['token'] = md5($a['tmp_file']);
         $a['url'] .= '&amp;token=' . $a['token'];
         if ($html && !empty($a['content_id'])) {
             $response['htmlbody'] = str_replace('cid:' . $a['content_id'], $a['url'], $response['htmlbody'], $replaceCount);
         }
         if ($a['name'] == 'smime.p7s') {
             $response['smime_signed'] = true;
             continue;
         }
         if (!$replaceCount) {
             $response['attachments'][] = $a;
         } else {
             $response['inlineAttachments'][] = $a;
         }
     }
     $response['contact_name'] = "";
     $response['contact_thumb_url'] = GO::config()->host . 'modules/addressbook/themes/Default/images/unknown-person.png';
     $response['blocked_images'] = 0;
     $response['xssDetected'] = false;
     $this->fireEvent('tooutputarray', array(&$response, $this));
     return $response;
 }
Beispiel #4
0
 protected function afterDelete()
 {
     Label::model()->deleteAccountLabels($this->id);
     return true;
 }
Beispiel #5
0
 public function getAccountLabels($account_id)
 {
     $labels = array();
     $stmt = Label::model()->findByAttribute('account_id', (int) $account_id);
     while ($label = $stmt->fetch()) {
         $labels[$label->flag] = $label;
     }
     return $labels;
 }