getSingle() public method

Returns mailbox/UID information for the first index.
public getSingle ( $all = false ) : array
return array $all If true, returns all UIDs for the first index in an array. If false, returns the first UID for the first index as a string.
Esempio n. 1
0
 /**
  * Check if we need to send a MDN, and send if needed.
  *
  * @param IMP_Indices $indices         Indices object of the message.
  * @param Horde_Mime_Headers $headers  The headers of the message.
  * @param boolean $confirmed           Has the MDN request been confirmed?
  *
  * @return boolean  True if the MDN request needs to be confirmed.
  */
 public function MDNCheck(IMP_Indices $indices, $headers, $confirmed = false)
 {
     global $conf, $injector, $prefs;
     $maillog = $injector->getInstance('IMP_Maillog');
     $pref_val = $prefs->getValue('send_mdn');
     list($mbox, ) = $indices->getSingle();
     if (!$pref_val || $mbox->readonly) {
         return false;
     }
     /* Check to see if an MDN has been requested. */
     $mdn = new Horde_Mime_Mdn($headers);
     if (!($return_addr = $mdn->getMdnReturnAddr())) {
         return false;
     }
     $log_msg = new IMP_Maillog_Message($indices);
     if (count($maillog->getLog($log_msg, array('forward', 'redirect', 'reply_all', 'reply_list', 'reply')))) {
         return false;
     }
     /* See if we need to query the user. */
     if (!$confirmed && (intval($pref_val) == 1 || $mdn->userConfirmationNeeded())) {
         try {
             if ($injector->getInstance('Horde_Core_Hooks')->callHook('mdn_check', 'imp', array($headers))) {
                 return true;
             }
         } catch (Horde_Exception_HookNotSet $e) {
             return true;
         }
     }
     /* Send out the MDN now. */
     $success = false;
     try {
         $mdn->generate(false, $confirmed, 'displayed', $conf['server']['name'], $injector->getInstance('IMP_Mail'), array('charset' => 'UTF-8', 'from_addr' => $injector->getInstance('Horde_Core_Factory_Identity')->create()->getDefaultFromAddress()));
         $maillog->log($log_msg, new IMP_Maillog_Log_Mdn());
         $success = true;
     } catch (Exception $e) {
     }
     $injector->getInstance('IMP_Sentmail')->log(IMP_Sentmail::MDN, '', $return_addr, $success);
     return false;
 }
Esempio n. 2
0
 /**
  * Create an indices object from a list of browser-UIDs.
  *
  * @param IMP_Indices|array $buids  Browser-UIDs.
  *
  * @return IMP_Indices  An indices object.
  */
 public function fromBuids($buids)
 {
     if (is_array($buids)) {
         $buids = new IMP_Indices($this->_mbox, $buids);
     }
     $buid_list = $buids->getSingle(true);
     $out = new IMP_Indices();
     if ($buid_list[1]) {
         $list_ob = $this->list_ob;
         foreach ($buid_list[1] as $buid) {
             if ($resolve = $list_ob->resolveBuid($buid)) {
                 $out->add($resolve['m'], $resolve['u']);
             }
         }
     }
     return $out;
 }
Esempio n. 3
0
 /**
  * Return the save link for the message source.
  *
  * @return Horde_Url  URL for the save link.
  */
 public function getSaveAs()
 {
     list($bmbox, $buid) = $this->_indices instanceof IMP_Indices_Mailbox ? $this->_indices->buids->getSingle() : $this->_indices->getSingle();
     $subject = $this->getSubject();
     return IMP_Contents_View::downloadUrl(htmlspecialchars_decode($subject['subject']), array_merge(array('actionID' => 'save_message'), $bmbox->urlParams($buid)));
 }
Esempio n. 4
0
 /**
  * Create the object used to display the message.
  *
  * @param array $args  Configuration parameters:
  *   - headers: (array) The headers desired in the returned headers array
  *              (only used with non-preview view).
  *   - preview: (boolean) Is this the preview view?
  *
  * @return array  Array with the following keys:
  *   - atc_download: The download all link
  *   - atc_label: The label to use for Attachments
  *   - atc_list: The list (HTML code) of attachments
  *   - bcc (FULL): The Bcc addresses
  *   - cc: The CC addresses
  *   - fulldate (FULL): The full canonical date.
  *   - from: The From addresses
  *   - headers (FULL): An array of headers (not including basic headers)
  *   - js: Javascript code to run on display
  *   - list_info (FULL): List information.
  *   - localdate (PREVIEW): The date formatted to the user's timezone
  *   - md: Metadata
  *   - msgtext: The text of the message
  *   - onepart: True if message only contains one part.
  *   - replyTo (FULL): The Reply-to addresses
  *   - save_as: The save link
  *   - subject: The subject
  *   - subjectlink: The subject with linked URLs/email addresses (defaults
  *                  to 'subject')
  *   - title (FULL): The title of the page
  *   - to: The To addresses
  *
  * @throws IMP_Exception
  */
 public function showMessage($args)
 {
     global $injector, $page_output, $prefs, $registry, $session;
     $preview = !empty($args['preview']);
     $result = array();
     $mime_headers = $this->_peek ? $this->_contents->getHeader() : $this->_contents->getHeaderAndMarkAsSeen();
     $headers = array();
     $imp_ui = $injector->getInstance('IMP_Message_Ui');
     /* Develop the list of Headers to display now. Deal with the 'basic'
      * header information first since there are various manipulations
      * done to them. */
     $basic_headers = $imp_ui->basicHeaders();
     if (empty($args['headers'])) {
         $args['headers'] = array('from', 'date', 'to', 'cc', 'bcc');
     }
     $headers_list = array_intersect_key($basic_headers, array_flip($args['headers']));
     /* Build From/To/Cc/Bcc/Reply-To links. */
     foreach (array('from', 'to', 'cc', 'bcc', 'reply-to') as $val) {
         if (isset($headers_list[$val]) && (!$preview || $val != 'reply-to')) {
             if ($tmp = $this->getAddressHeader($val)) {
                 $result[$val] = $tmp;
             }
             if ($preview) {
                 unset($headers_list[$val]);
             }
         }
     }
     /* Build the rest of the headers. */
     foreach ($headers_list as $head => $str) {
         if ($val = $mime_headers->getValue($head)) {
             if ($head == 'date') {
                 /* Add local time to date header. */
                 $date_ob = new IMP_Message_Date($this->_envelope->date);
                 $val = htmlspecialchars($date_ob->format($date_ob::DATE_LOCAL));
                 if ($preview) {
                     $result['localdate'] = $val;
                 } else {
                     $result['fulldate'] = $date_ob->format($date_ob::DATE_FORCE);
                 }
             } elseif (!$preview) {
                 $val = htmlspecialchars($val);
             }
             if (!$preview) {
                 $headers[$head] = array('id' => Horde_String::ucfirst($head), 'name' => $str, 'value' => $val);
             }
         }
     }
     if (empty($result['reply-to']) || $result['from']['addr'][0]->b == $result['reply-to']['addr'][0]->b) {
         unset($result['reply-to'], $headers['reply-to']);
     }
     /* JS requires camelized name for reply-to. */
     if (!$preview && isset($headers['reply-to'])) {
         $result['replyTo'] = $result['reply-to'];
         $headers['reply-to']['id'] = 'ReplyTo';
         unset($result['reply-to']);
     }
     /* Maillog information. */
     $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
     $ajax_queue->maillog($this->_indices);
     if (!$preview) {
         /* Display the user-specified headers for the current identity. */
         $user_hdrs = $imp_ui->getUserHeaders();
         foreach ($user_hdrs as $user_hdr) {
             $user_val = $mime_headers->getValue($user_hdr);
             if (!empty($user_val)) {
                 if (!is_array($user_val)) {
                     $user_val = array($user_val);
                 }
                 foreach ($user_val as $val) {
                     $headers[] = array('name' => $user_hdr, 'value' => htmlspecialchars($val));
                 }
             }
         }
         $result['headers'] = array_values($headers);
     }
     /* Process the subject. */
     $subject = $mime_headers->getValue('subject');
     if ($subject) {
         $text_filter = $injector->getInstance('Horde_Core_Factory_TextFilter');
         $filtered_subject = preg_replace("/\\b\\s+\\b/", ' ', IMP::filterText($subject));
         $result['subject'] = $text_filter->filter($filtered_subject, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::NOHTML));
         $subjectlink = $text_filter->filter($filtered_subject, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
         if ($subjectlink != $result['subject']) {
             $result['subjectlink'] = $subjectlink;
         }
         if (!$preview) {
             $result['title'] = $subject;
         }
     } else {
         $result['subject'] = _("[No Subject]");
         if (!$preview) {
             $result['title'] = _("[No Subject]");
         }
     }
     // Create message text and attachment list.
     $result['msgtext'] = '';
     $show_parts = $prefs->getValue('parts_display');
     switch ($registry->getView()) {
         case $registry::VIEW_SMARTMOBILE:
             $contents_mask = 0;
             break;
         default:
             $contents_mask = IMP_Contents::SUMMARY_BYTES | IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_ICON | IMP_Contents::SUMMARY_DESCRIP_LINK | IMP_Contents::SUMMARY_DOWNLOAD | IMP_Contents::SUMMARY_DOWNLOAD_ZIP | IMP_Contents::SUMMARY_PRINT_STUB;
             break;
     }
     $part_info = $part_info_display = array('icon', 'description', 'size', 'download', 'download_zip');
     $part_info_display[] = 'print';
     list($mbox, $uid) = $this->_indices->getSingle();
     /* Do MDN processing now. */
     switch ($registry->getView()) {
         case $registry::VIEW_DYNAMIC:
             if ($imp_ui->MDNCheck(new IMP_Indices($mbox, $uid), $mime_headers)) {
                 $status = new IMP_Mime_Status(array(_("The sender of this message is requesting notification from you when you have read this message."), sprintf(_("Click %s to send the notification message."), Horde::link('#', '', '', '', '', '', '', array('id' => 'send_mdn_link')) . _("HERE") . '</a>')));
                 $status->domid('sendMdnMessage');
                 $result['msgtext'] .= strval($status);
             }
     }
     /* Build body text. This needs to be done before we build the
      * attachment list. */
     $session->close();
     $inlineout = $this->_contents->getInlineOutput(array('mask' => $contents_mask, 'part_info_display' => $part_info_display, 'show_parts' => $show_parts));
     $session->start();
     $result['md'] = $inlineout['metadata'];
     $result['msgtext'] .= $inlineout['msgtext'];
     if ($inlineout['one_part']) {
         $result['onepart'] = true;
     }
     if (count($inlineout['atc_parts']) || $show_parts == 'all' && count($inlineout['display_ids']) > 2) {
         $result['atc_label'] = $show_parts == 'all' ? _("Parts") : sprintf(ngettext("%d Attachment", "%d Attachments", count($inlineout['atc_parts'])), count($inlineout['atc_parts']));
         if (count($inlineout['atc_parts']) > 2) {
             $result['atc_download'] = Horde::link($this->_contents->urlView($this->_contents->getMIMEMessage(), 'download_all')) . '[' . _("Save All") . ']</a>';
         }
     }
     /* Show attachment information in headers? */
     if (!empty($inlineout['atc_parts'])) {
         $partlist = array();
         if ($show_parts == 'all') {
             array_unshift($part_info, 'id');
         }
         foreach ($inlineout['atc_parts'] as $id) {
             $contents_mask |= IMP_Contents::SUMMARY_DESCRIP | IMP_Contents::SUMMARY_DOWNLOAD | IMP_Contents::SUMMARY_ICON | IMP_Contents::SUMMARY_SIZE;
             $part_info[] = 'description_raw';
             $part_info[] = 'download_url';
             $summary = $this->_contents->getSummary($id, $contents_mask);
             $tmp = array();
             foreach ($part_info as $val) {
                 if (isset($summary[$val])) {
                     $tmp[$val] = $summary[$val] instanceof Horde_Url ? strval($summary[$val]->setRaw(true)) : $summary[$val];
                 }
             }
             $partlist[] = array_filter($tmp);
         }
         $result['atc_list'] = $partlist;
     }
     $result['save_as'] = IMP_Contents_View::downloadUrl(htmlspecialchars_decode($result['subject']), array_merge(array('actionID' => 'save_message'), $mbox->urlParams($uid)));
     if ($preview) {
         /* Need to grab cached inline scripts. */
         Horde::startBuffer();
         $page_output->outputInlineScript(true);
         if ($js_inline = Horde::endBuffer()) {
             $result['js'] = array($js_inline);
         }
         $result['save_as'] = strval($result['save_as']->setRaw(true));
     } else {
         $list_info = $imp_ui->getListInformation($mime_headers);
         if (!empty($list_info['exists'])) {
             $result['list_info'] = $list_info;
         }
     }
     /* Add changed flag information. */
     if (!$this->_peek && $mbox->is_imap) {
         $status = $mbox->imp_imap->status($mbox, Horde_Imap_Client::STATUS_PERMFLAGS);
         if (in_array(Horde_Imap_Client::FLAG_SEEN, $status['permflags'])) {
             $ajax_queue->flag(array(Horde_Imap_Client::FLAG_SEEN), true, $this->_indices);
         }
     }
     return array_filter($result);
 }
Esempio n. 5
0
 /**
  * Returns a list of messages for use with ViewPort.
  *
  * @var array $args  TODO
  *   - applyfilter: (boolean) If true, apply filters to mailbox.
  *   - change: (boolean) True if the cache value has changed.
  *   - initial: (boolean) Is this the initial load of the view?
  *   - mbox: (string) The mailbox of the view.
  *   - qsearch: (string) The quicksearch search string.
  *   - qsearchfield: (string) The quicksearch search criteria.
  *   - qsearchmbox: (string) The mailbox to do the quicksearch in
  *                  (base64url encoded).
  *   - qsearchfilter: TODO
  *
  * @return IMP_Ajax_Application_Viewport  Viewport data object.
  */
 public function listMessages($args)
 {
     global $injector, $notification, $prefs;
     $is_search = false;
     $mbox = IMP_Mailbox::get($args['mbox']);
     $sortpref = $mbox->getSort(true);
     /* Create the base object. */
     $result = new IMP_Ajax_Application_Viewport($mbox);
     /* Check for quicksearch request. */
     if (strlen($args['qsearchmbox'])) {
         $qsearch_mbox = IMP_Mailbox::formFrom($args['qsearchmbox']);
         /* Sanity checking: qsearchmbox cannot be a search mailbox
          * itself. */
         if ($qsearch_mbox->search) {
             $notification->push(_("Error in displaying search results."), 'horde.error');
             return $result;
         }
         if (strlen($args['qsearchfilter'])) {
             $injector->getInstance('IMP_Search')->applyFilter($args['qsearchfilter'], array($qsearch_mbox), $mbox);
             $is_search = true;
         } else {
             /* Create the search query. */
             $c_list = array();
             if (strlen($args['qsearchflag'])) {
                 $c_list[] = new IMP_Search_Element_Flag($args['qsearchflag'], empty($args['qsearchflagnot']));
                 $is_search = true;
             } elseif (strlen($args['qsearch'])) {
                 $is_search = true;
                 switch ($args['qsearchfield']) {
                     case 'all':
                     case 'body':
                         $c_list[] = new IMP_Search_Element_Text($args['qsearch'], $args['qsearchfield'] == 'body');
                         break;
                     case 'from':
                     case 'subject':
                         $c_list[] = new IMP_Search_Element_Header($args['qsearch'], $args['qsearchfield']);
                         break;
                     case 'recip':
                         $c_list[] = new IMP_Search_Element_Recipient($args['qsearch']);
                         break;
                     default:
                         $is_search = false;
                         break;
                 }
             }
             /* Store the search in the session. */
             if ($is_search) {
                 $injector->getInstance('IMP_Search')->createQuery($c_list, array('id' => $mbox, 'mboxes' => array($qsearch_mbox), 'type' => IMP_Search::CREATE_QUERY));
             }
         }
     } else {
         $is_search = $mbox->search;
     }
     /* Run filters now. */
     if (!empty($args['applyfilter'])) {
         $mbox->filter();
     } elseif ($mbox->inbox) {
         $mbox->filterOnDisplay();
     }
     $result->label = $mbox->label;
     /* Optimization: saves at least a STATUS and an EXAMINE call since
      * we will eventually open mailbox READ-WRITE. */
     $imp_imap = $mbox->imp_imap;
     $imp_imap->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE);
     if ($is_search) {
         /* For search mailboxes, we need to invalidate all browser data
          * and repopulate on force update, since BUIDs may have
          * changed (TODO: only do this if search mailbox has changed?). */
         if (!empty($args['change'])) {
             $args['cache'] = array();
             $args['change'] = true;
             $result->data_reset = $result->rowlist_reset = true;
         }
     } elseif (!$args['initial'] && $args['cacheid'] && $args['cache']) {
         /* Check for UIDVALIDITY expiration. If it has changed, we need to
          * purge the cached items on the browser. */
         $parsed = $imp_imap->parseCacheId($args['cacheid']);
         $uid_expire = true;
         if ($parsed['date'] == date('z')) {
             try {
                 $imp_imap->sync($mbox, $parsed['token'], array('criteria' => Horde_Imap_Client::SYNC_UIDVALIDITY));
                 $uid_expire = false;
             } catch (Horde_Imap_Client_Exception_Sync $e) {
             }
         }
         if ($uid_expire) {
             $args['cache'] = array();
             $args['initial'] = true;
             $result->data_reset = $result->metadata_reset = true;
         }
     } else {
         $parsed = null;
     }
     /* Mail-specific viewport information. */
     if ($args['initial'] || isset($args['delhide']) && !is_null($args['delhide']) || !is_null($args['sortby'])) {
         $result->setMetadata('delhide', $mbox->hideDeletedMsgs(true));
     }
     if ($args['initial'] || !is_null($args['sortby']) || !is_null($args['sortdir'])) {
         $result->setMetadata('sortby', $sortpref->sortby);
         $result->setMetadata('sortdir', $sortpref->sortdir);
     }
     /* Actions only done on 'initial' request. */
     if ($args['initial']) {
         /* Load quota information on original request. */
         $injector->getInstance('IMP_Ajax_Queue')->quota($mbox, true);
         if (!$mbox->is_imap) {
             $result->setMetadata('nodeleteshow', 1);
             $result->setMetadata('noundelete', 1);
             $result->setMetadata('pop3', 1);
         }
         if ($sortpref->sortby_locked) {
             $result->setMetadata('sortbylock', 1);
         }
         if ($sortpref->sortdir_locked) {
             $result->setMetadata('sortdirlock', 1);
         }
         if (!$mbox->access_sortthread) {
             $result->setMetadata('nothread', 1);
         }
         if ($mbox->special_outgoing) {
             $result->setMetadata('special', 1);
             if ($mbox->drafts) {
                 $result->setMetadata('drafts', 1);
             } elseif ($mbox->templates) {
                 $result->setMetadata('templates', 1);
             }
         } elseif ($mbox->spam) {
             $result->setMetadata('innocent_show', 1);
             if ($mbox->spam_show) {
                 $result->setMetadata('spam_show', 1);
             }
         } else {
             if ($mbox->innocent_show) {
                 $result->setMetadata('innocent_show', 1);
             }
             $result->setMetadata('spam_show', 1);
         }
         if ($is_search) {
             $result->setMetadata('innocent_show', 1);
             $result->setMetadata('search', 1);
             $result->setMetadata('spam_show', 1);
         }
         if ($prefs->getValue('use_trash')) {
             $result->setMetadata('nodeleteshow', 1);
             if (!$mbox->vtrash) {
                 $result->setMetadata('noundelete', 1);
             }
         }
         $result->addFlagMetadata();
     }
     /* The search query may have changed. */
     if ($is_search && ($args['initial'] || strlen($args['qsearchmbox']))) {
         $imp_search = $injector->getInstance('IMP_Search');
         if ($mbox->vfolder) {
             $result->setMetadata('slabel', $imp_search[$mbox]->label);
             $result->setMetadata('vfolder', 1);
             if (!$imp_search->isVFolder($mbox, true)) {
                 $result->setMetadata('noedit', 1);
             }
         } else {
             $result->setMetadata('slabel', $imp_search[$mbox]->querytext);
         }
     }
     /* These entries may change during a session, so always need to
      * update them. */
     if ($mbox->readonly) {
         $result->setMetadata('readonly', 1);
         $result->setMetadata('nodelete', 1);
         $result->setMetadata('nodeleteshow', 1);
         $result->setMetadata('noundelete', 1);
     } else {
         if (!$mbox->access_deletemsgs) {
             $result->setMetadata('nodelete', 1);
         }
         if (!$mbox->access_expunge) {
             $result->setMetadata('noexpunge', 1);
         }
     }
     /* Generate the sorted mailbox list now. */
     $mailbox_list = $mbox->list_ob;
     if ($is_search && (!empty($args['change']) || $args['initial'])) {
         $mailbox_list->rebuild(true);
     }
     $msgcount = count($mailbox_list);
     /* Check for mailbox existence now. If there are no messages, there
      * is a chance that the mailbox doesn't exist. If there is at least
      * 1 message, we don't need this check. */
     if (empty($msgcount) && !$is_search) {
         if (!$mbox->exists) {
             $notification->push(sprintf(_("Mailbox %s does not exist."), $mbox->label), 'horde.error');
             $result = new IMP_Ajax_Application_Viewport_Error($mbox);
         }
         if (!empty($args['change'])) {
             $result->data_reset = true;
             $result->rowlist_reset = true;
         }
         return $result;
     }
     $result->totalrows = $msgcount;
     /* TODO: This can potentially be optimized for arrival time sort - if
      * the cache ID changes, we know the changes must occur at end of
      * mailbox. */
     if (!$result->data_reset && !empty($args['change'])) {
         $result->rowlist_reset = true;
     }
     /* Get the cached list. */
     if (empty($args['cache'])) {
         $cached = array();
     } else {
         $cache_indices = new IMP_Indices($mbox, $args['cache']);
         $cache_uids = $cache_indices->getSingle(true);
         $cached = array_flip($cache_uids[1]);
     }
     if (!$is_search && !empty($args['search_unseen'])) {
         /* Do an unseen search.  We know what messages the browser
          * doesn't have based on $cached. Thus, search for the first
          * unseen message not located in $cached. */
         $unseen_search = $mailbox_list->unseenMessages(Horde_Imap_Client::SEARCH_RESULTS_MATCH, array('uids' => true));
         if (!($uid_search = array_diff($unseen_search['match']->ids, array_keys($cached)))) {
             return $result;
         }
         $rownum = $mailbox_list->getArrayIndex(reset($uid_search));
     } elseif (!empty($args['search_buid'])) {
         $search_buid = $mailbox_list->resolveBuid($args['search_buid']);
         $rownum = $mailbox_list->getArrayIndex($search_buid['u'], $search_buid['m']);
     }
     /* If this is the initial request for a mailbox, figure out the
      * starting location based on user's preferences. */
     $rownum = $args['initial'] && !isset($rownum) || isset($rownum) && is_null($rownum) ? intval($mailbox_list->mailboxStart($msgcount)) : (isset($rownum) ? $rownum + 1 : null);
     /* Determine the row slice to process. */
     if (is_null($rownum) || isset($args['slice_start'])) {
         $slice_start = $args['slice_start'];
         $slice_end = $args['slice_end'];
     } else {
         $slice_start = $rownum - $args['before'];
         $slice_end = $rownum + $args['after'];
         if ($slice_start < 1) {
             $slice_end += abs($slice_start) + 1;
         } elseif ($slice_end > $msgcount) {
             $slice_start -= $slice_end - $msgcount;
         }
     }
     if (!is_null($rownum)) {
         $result->rownum = $rownum;
     }
     $slice_start = max(1, $slice_start);
     $slice_end = min($msgcount, $slice_end);
     /* Generate BUID list. */
     $buidlist = $changed = $data = $msglist = $rowlist = array();
     foreach ($mailbox_list as $val) {
         $buidlist[] = $mailbox_list->getBuid($val['m'], $val['u']);
     }
     /* If we are updating the rowlist on the browser, and we have cached
      * browser data information, we need to send a list of messages that
      * have 'disappeared'. */
     if (!empty($cached) && $result->rowlist_reset) {
         $disappear = array();
         foreach (array_diff(array_keys($cached), $buidlist) as $uid) {
             $disappear[] = $uid;
             unset($cached[$uid]);
         }
         if (!empty($disappear)) {
             $result->disappear = $disappear;
         }
     }
     /* Check for cached entries marked as changed. If changed, resend the
      * entire entry to update the browser cache (done below). */
     if (!empty($cached) && !$is_search && !is_null($parsed)) {
         $sync_ob = $imp_imap->sync($mbox, $parsed['token'], array('criteria' => Horde_Imap_Client::SYNC_FLAGSUIDS, 'ids' => $imp_imap->getIdsOb(array_keys($cached))));
         $changed = array_flip($sync_ob->flagsuids->ids);
     }
     foreach (array_slice($buidlist, $slice_start - 1, $slice_end - $slice_start + 1, true) as $key => $uid) {
         $seq = ++$key;
         $msglist[$seq] = $mailbox_list[$seq]['u'];
         $rowlist[$uid] = $seq;
         /* Send browser message data if not already cached or if CONDSTORE
          * has indicated that data has changed. */
         if (!isset($cached[$uid]) || isset($changed[$uid])) {
             $data[$seq] = 1;
         }
     }
     /* Build the list for rangeslice information. */
     if ($args['rangeslice']) {
         $slice = new IMP_Ajax_Application_Viewport($mbox);
         $slice->rangelist = array_keys($rowlist);
         return $slice;
     }
     $result->rowlist = $rowlist;
     /* Build the overview list. */
     $result->data = $this->_getOverviewData($mbox, array_keys($data));
     /* Get thread information. */
     if ($sortpref->sortby == Horde_Imap_Client::SORT_THREAD) {
         $thread = new stdClass();
         foreach ($msglist as $key => $val) {
             $tmp = $mailbox_list->getThreadOb($key);
             $thread->{$val} = $sortpref->sortdir ? $tmp->reverse_raw : $tmp->raw;
         }
         $result->setMetadata('thread', $thread);
     }
     return $result;
 }
Esempio n. 6
0
 /**
  * Strips one or all MIME parts out of a message.
  * Handles search mailboxes.
  *
  * @param IMP_Indices $indices  An indices object.
  * @param string $partid        The MIME ID of the part to strip. All
  *                              parts are stripped if null.
  * @param array $opts           Additional options:
  *   - mailboxob: (IMP_Mailbox_List) Update this mailbox object.
  *                DEFAULT: No update.
  *
  * @return IMP_Indices  Returns the new indices object.
  * @throws IMP_Exception
  */
 public function stripPart(IMP_Indices $indices, $partid = null, array $opts = array())
 {
     global $injector;
     list($mbox, $uid) = $indices->getSingle();
     if (!$uid) {
         return;
     }
     if ($mbox->readonly) {
         throw new IMP_Exception(_("Cannot strip the MIME part as the mailbox is read-only."));
     }
     $uidvalidity = $mbox->uidvalid;
     $contents = $injector->getInstance('IMP_Factory_Contents')->create($indices);
     $message = $contents->getMIMEMessage();
     $boundary = trim($message->getContentTypeParameter('boundary'), '"');
     $url = new Horde_Imap_Client_Url();
     $url->mailbox = $mbox;
     $url->uid = $uid;
     $url->uidvalidity = $uidvalidity;
     $imp_imap = $mbox->imp_imap;
     /* Always add the header to output. */
     $url->section = 'HEADER';
     $parts = array(array('t' => 'url', 'v' => strval($url)));
     for ($id = 1;; ++$id) {
         $part = $message->getPart($id);
         if (!$part) {
             break;
         }
         $parts[] = array('t' => 'text', 'v' => "\r\n--" . $boundary . "\r\n");
         if ($id != 1 && is_null($partid) || $id == $partid) {
             $newPart = new Horde_Mime_Part();
             $newPart->setType('text/plain');
             /* Need to make sure all text is in the correct charset. */
             $newPart->setCharset('UTF-8');
             $newPart->setContents(sprintf(_("[Attachment stripped: Original attachment type: %s, name: %s]"), $part->getType(), $contents->getPartName($part)));
             $newPart->setDisposition('attachment');
             $parts[] = array('t' => 'text', 'v' => $newPart->toString(array('canonical' => true, 'headers' => true, 'stream' => true)));
         } else {
             $url->section = $id . '.MIME';
             $parts[] = array('t' => 'url', 'v' => strval($url));
             $url->section = $id;
             $parts[] = array('t' => 'url', 'v' => strval($url));
         }
     }
     $parts[] = array('t' => 'text', 'v' => "\r\n--" . $boundary . "--\r\n");
     /* Get the headers for the message. */
     $query = new Horde_Imap_Client_Fetch_Query();
     $query->imapDate();
     $query->flags();
     try {
         $res = $imp_imap->fetch($mbox, $query, array('ids' => $imp_imap->getIdsOb($uid)))->first();
         if (is_null($res)) {
             throw new IMP_Imap_Exception();
         }
         $flags = $res->getFlags();
         /* If in Virtual Inbox, we need to reset flag to unseen so that it
          * appears again in the mailbox list. */
         if ($mbox->vinbox) {
             $flags = array_values(array_diff($flags, array(Horde_Imap_Client::FLAG_SEEN)));
         }
         $new_uid = $imp_imap->append($mbox, array(array('data' => $parts, 'flags' => $flags, 'internaldate' => $res->getImapDate())))->ids;
         $new_uid = reset($new_uid);
     } catch (IMP_Imap_Exception $e) {
         throw new IMP_Exception(_("An error occured while attempting to strip the attachment."));
     }
     $this->delete($indices, array('keeplog' => true, 'mailboxob' => empty($opts['mailboxob']) ? null : $opts['mailboxob'], 'nuke' => true));
     $indices_ob = $mbox->getIndicesOb($new_uid);
     if (!empty($opts['mailboxob'])) {
         $opts['mailboxob']->setIndex($indices_ob);
     }
     /* We need to replace the old UID(s) in the URL params. */
     $vars = $injector->getInstance('Horde_Variables');
     if (isset($vars->buid)) {
         list(, $vars->buid) = $mbox->toBuids($indices_ob)->getSingle();
     }
     if (isset($vars->uid)) {
         $vars->uid = $new_uid;
     }
     return $indices_ob;
 }