imapDate() public method

Return the internal (IMAP) date of the message.
public imapDate ( )
Beispiel #1
0
 public function getMessages($from = 0, $count = 2)
 {
     $total = $this->getTotalMessages();
     if ($from + $count > $total) {
         $count = $total - $from;
     }
     $headers = array();
     $fetch_query = new \Horde_Imap_Client_Fetch_Query();
     $fetch_query->envelope();
     $fetch_query->flags();
     $fetch_query->seq();
     $fetch_query->size();
     $fetch_query->uid();
     $fetch_query->imapDate();
     $headers = array_merge($headers, array('importance', 'list-post', 'x-priority'));
     $headers[] = 'content-type';
     $fetch_query->headers('imp', $headers, array('cache' => true, 'peek' => true));
     $opt = array('ids' => $from + 1 . ':' . ($from + 1 + $count));
     $opt = array();
     // $list is an array of Horde_Imap_Client_Data_Fetch objects.
     $headers = $this->conn->fetch($this->folder_id, $fetch_query, $opt);
     ob_start();
     // fix for Horde warnings
     $messages = array();
     foreach ($headers as $message_id => $header) {
         $message = new Message($this->conn, $this->folder_id, $message_id);
         $message->setInfo($header);
         $messages[] = $message->getListArray();
     }
     ob_clean();
     return $messages;
 }
 /**
  * Renames the old sent-mail mailboxes.
  *
  * Mailbox name: sent-mail-month-year
  *   month = English:         3 letter abbreviation
  *           Other Languages: Month value (01-12)
  *   year  = 4 digit year
  *
  * The mailbox name needs to be in this specific format (as opposed to a
  * user-defined one) to ensure that 'delete_sentmail_monthly' processing
  * can accurately find all the old sent-mail mailboxes.
  *
  * @return boolean  Whether all sent-mail mailboxes were renamed.
  */
 public function execute()
 {
     global $notification;
     $date_format = substr($GLOBALS['language'], 0, 2) == 'en' ? 'M-Y' : 'm-Y';
     $datetime = new DateTime();
     $now = $datetime->format($date_format);
     foreach ($this->_getSentmail() as $sent) {
         /* Display a message to the user and rename the mailbox.
          * Only do this if sent-mail mailbox currently exists. */
         if ($sent->exists) {
             $notification->push(sprintf(_("\"%s\" mailbox being renamed at the start of the month."), $sent->display), 'horde.message');
             $query = new Horde_Imap_Client_Fetch_Query();
             $query->imapDate();
             $query->uid();
             $imp_imap = $sent->imp_imap;
             $res = $imp_imap->fetch($sent, $query);
             $msgs = array();
             foreach ($res as $val) {
                 $date_string = $val->getImapDate()->format($date_format);
                 if (!isset($msgs[$date_string])) {
                     $msgs[$date_string] = $imp_imap->getIdsOb();
                 }
                 $msgs[$date_string]->add($val->getUid());
             }
             unset($msgs[$now]);
             foreach ($msgs as $key => $val) {
                 $new_mbox = IMP_Mailbox::get(strval($sent) . '-' . Horde_String::lower($key));
                 $imp_imap->copy($sent, $new_mbox, array('create' => true, 'ids' => $val, 'move' => true));
             }
         }
     }
     return true;
 }
Beispiel #3
0
 /**
  * Generates a string that can be saved out to an mbox format mailbox file
  * for a mailbox (or set of mailboxes), optionally including all
  * subfolders of the selected mailbox(es) as well. All mailboxes will be
  * output in the same string.
  *
  * @param mixed $mboxes  A mailbox name (UTF-8), or list of mailbox names,
  *                       to generate a mbox file for.
  *
  * @return resource  A stream resource containing the text of a mbox
  *                   format mailbox file.
  */
 public function generate($mboxes)
 {
     $body = fopen('php://temp', 'r+');
     if (!is_array($mboxes)) {
         if (!strlen($mboxes)) {
             return $body;
         }
         $mboxes = array($mboxes);
     }
     if (empty($mboxes)) {
         return $body;
     }
     $query = new Horde_Imap_Client_Fetch_Query();
     $query->envelope();
     $query->imapDate();
     $query->headerText(array('peek' => true));
     $query->bodyText(array('peek' => true));
     foreach (IMP_Mailbox::get($mboxes) as $val) {
         $imp_imap = $val->imp_imap;
         $slices = $imp_imap->getSlices($val, $imp_imap->getIdsOb(Horde_Imap_Client_Ids::ALL, true));
         foreach ($slices as $slice) {
             try {
                 $res = $imp_imap->fetch($val, $query, array('ids' => $slice, 'nocache' => true));
             } catch (IMP_Imap_Exception $e) {
                 continue;
             }
             foreach ($res as $ptr) {
                 $from_env = $ptr->getEnvelope()->from;
                 $from = count($from_env) ? $from_env[0]->bare_address : '<>';
                 /* We need this long command since some MUAs (e.g. pine)
                  * require a space in front of single digit days. */
                 $imap_date = $ptr->getImapDate();
                 $date = sprintf('%s %2s %s', $imap_date->format('D M'), $imap_date->format('j'), $imap_date->format('H:i:s Y'));
                 fwrite($body, 'From ' . $from . ' ' . $date . "\r\n");
                 /* Remove spurious 'From ' line in headers. */
                 $stream = $ptr->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
                 while (!feof($stream)) {
                     $line = fgets($stream);
                     if (substr($line, 0, 5) != 'From ') {
                         fwrite($body, $line);
                     }
                 }
                 fwrite($body, "\r\n");
                 /* Add Body text. */
                 $stream = $ptr->getBodyText(0, true);
                 while (!feof($stream)) {
                     fwrite($body, fread($stream, 8192));
                 }
                 fwrite($body, "\r\n");
             }
         }
     }
     return $body;
 }
Beispiel #4
0
 /**
  * Sort search results client side if the server does not support the SORT
  * IMAP extension (RFC 5256).
  *
  * @param Horde_Imap_Client_Ids $res  The search results.
  * @param array $opts                 The options to _search().
  *
  * @return array  The sort results.
  *
  * @throws Horde_Imap_Client_Exception
  */
 public function clientSort($res, $opts)
 {
     if (!count($res)) {
         return $res;
     }
     /* Generate the FETCH command needed. */
     $query = new Horde_Imap_Client_Fetch_Query();
     foreach ($opts['sort'] as $val) {
         switch ($val) {
             case Horde_Imap_Client::SORT_ARRIVAL:
                 $query->imapDate();
                 break;
             case Horde_Imap_Client::SORT_DATE:
                 $query->imapDate();
                 $query->envelope();
                 break;
             case Horde_Imap_Client::SORT_CC:
             case Horde_Imap_Client::SORT_DISPLAYFROM:
             case Horde_Imap_Client::SORT_DISPLAYTO:
             case Horde_Imap_Client::SORT_FROM:
             case Horde_Imap_Client::SORT_SUBJECT:
             case Horde_Imap_Client::SORT_TO:
                 $query->envelope();
                 break;
             case Horde_Imap_Client::SORT_SEQUENCE:
                 $query->seq();
                 break;
             case Horde_Imap_Client::SORT_SIZE:
                 $query->size();
                 break;
         }
     }
     if (!count($query)) {
         return $res;
     }
     $mbox = $this->_socket->currentMailbox();
     $fetch_res = $this->_socket->fetch($mbox['mailbox'], $query, array('ids' => $res));
     return $this->_clientSortProcess($res->ids, $fetch_res, $opts['sort']);
 }
Beispiel #5
0
 public function getMessages($from = 0, $count = 2, $filter = '')
 {
     if ($filter instanceof Horde_Imap_Client_Search_Query) {
         $query = $filter;
     } else {
         $query = new Horde_Imap_Client_Search_Query();
         if ($filter) {
             $query->text($filter, false);
         }
     }
     if ($this->getSpecialRole() !== 'trash') {
         $query->flag(Horde_Imap_Client::FLAG_DELETED, false);
     }
     $result = $this->conn->search($this->mailBox, $query, ['sort' => [Horde_Imap_Client::SORT_DATE]]);
     $ids = array_reverse($result['match']->ids);
     if ($from >= 0 && $count >= 0) {
         $ids = array_slice($ids, $from, $count);
     }
     $ids = new \Horde_Imap_Client_Ids($ids, false);
     $headers = [];
     $fetch_query = new \Horde_Imap_Client_Fetch_Query();
     $fetch_query->envelope();
     $fetch_query->flags();
     $fetch_query->size();
     $fetch_query->uid();
     $fetch_query->imapDate();
     $fetch_query->structure();
     $headers = array_merge($headers, ['importance', 'list-post', 'x-priority']);
     $headers[] = 'content-type';
     $fetch_query->headers('imp', $headers, ['cache' => true, 'peek' => true]);
     $options = ['ids' => $ids];
     // $list is an array of Horde_Imap_Client_Data_Fetch objects.
     $headers = $this->conn->fetch($this->mailBox, $fetch_query, $options);
     ob_start();
     // fix for Horde warnings
     $messages = [];
     foreach ($headers->ids() as $message_id) {
         $header = $headers[$message_id];
         $message = new Message($this->conn, $this->mailBox, $message_id, $header);
         $messages[] = $message->getListArray();
     }
     ob_get_clean();
     // sort by time
     usort($messages, function ($a, $b) {
         return $a['dateInt'] < $b['dateInt'];
     });
     return $messages;
 }
Beispiel #6
0
 private function getmsg()
 {
     $headers = array();
     $fetch_query = new \Horde_Imap_Client_Fetch_Query();
     $fetch_query->envelope();
     //		$fetch_query->fullText();
     $fetch_query->bodyText();
     $fetch_query->flags();
     $fetch_query->seq();
     $fetch_query->size();
     $fetch_query->uid();
     $fetch_query->imapDate();
     $headers = array_merge($headers, array('importance', 'list-post', 'x-priority'));
     $headers[] = 'content-type';
     $fetch_query->headers('imp', $headers, array('cache' => true, 'peek' => true));
     // $list is an array of Horde_Imap_Client_Data_Fetch objects.
     $ids = new \Horde_Imap_Client_Ids($this->message_id);
     $headers = $this->conn->fetch($this->folder_id, $fetch_query, array('ids' => $ids));
     $this->plainmsg = $headers[$this->message_id]->getBodyText();
     //
     //		// HEADER
     //		$this->header = $this->conn->fetchHeader($this->folder_id, $this->message_id);
     //
     //		// BODY
     //		$bodystructure= $this->conn->getStructure($this->folder_id, $this->message_id);
     //		$a= \rcube_imap_generic::getStructurePartData($bodystructure, 0);
     //		if ($a['type'] == 'multipart') {
     //			for ($i=0; $i < count($bodystructure); $i++) {
     //				if (!is_array($bodystructure[$i]))
     //					break;
     //				$this->getpart($bodystructure[$i],$i+1);
     //			}
     //		} else {
     //			// get part no 1
     //			$this->getpart($bodystructure,1);
     //		}
 }
Beispiel #7
0
 /**
  * @throws Horde_Imap_Client_Exception_NoSupportExtension
  */
 protected function _thread($options)
 {
     $thread_criteria = array(Horde_Imap_Client::THREAD_ORDEREDSUBJECT => 'ORDEREDSUBJECT', Horde_Imap_Client::THREAD_REFERENCES => 'REFERENCES', Horde_Imap_Client::THREAD_REFS => 'REFS');
     $tsort = isset($options['criteria']) ? is_string($options['criteria']) ? strtoupper($options['criteria']) : $thread_criteria[$options['criteria']] : 'ORDEREDSUBJECT';
     $cap = $this->queryCapability('THREAD');
     if (!$cap || !in_array($tsort, $cap)) {
         switch ($tsort) {
             case 'ORDEREDSUBJECT':
                 if (empty($options['search'])) {
                     $ids = $this->getIdsOb(Horde_Imap_Client_Ids::ALL, !empty($options['sequence']));
                 } else {
                     $search_res = $this->search($this->_selected, $options['search'], array('sequence' => !empty($options['sequence'])));
                     $ids = $search_res['match'];
                 }
                 /* Do client-side ORDEREDSUBJECT threading. */
                 $query = new Horde_Imap_Client_Fetch_Query();
                 $query->envelope();
                 $query->imapDate();
                 $fetch_res = $this->fetch($this->_selected, $query, array('ids' => $ids));
                 if (!isset($this->_temp['clientsort'])) {
                     $this->_temp['clientsort'] = new Horde_Imap_Client_Socket_ClientSort($this);
                 }
                 return $this->_temp['clientsort']->threadOrderedSubject($fetch_res, empty($options['sequence']));
             case 'REFERENCES':
             case 'REFS':
                 throw new Horde_Imap_Client_Exception_NoSupportExtension('THREAD', sprintf('Server does not support "%s" thread sort.', $tsort));
         }
     }
     $cmd = $this->_command(empty($options['sequence']) ? 'UID THREAD' : 'THREAD')->add($tsort);
     if (empty($options['search'])) {
         $cmd->add(array('US-ASCII', 'ALL'));
     } else {
         $search_query = $options['search']->build();
         $cmd->add(is_null($search_query['charset']) ? 'US-ASCII' : $search_query['charset']);
         $cmd->add($search_query['query'], true);
     }
     return new Horde_Imap_Client_Data_Thread($this->_sendCmd($cmd)->data['threadparse'], empty($options['sequence']) ? 'uid' : 'sequence');
 }
Beispiel #8
0
 /**
  * Strips one or all MIME parts out of a message.
  *
  * @param string $partid  The MIME ID of the part to strip. All parts are
  *                        stripped if null.
  *
  * @return IMP_Indices  Returns the new indices object.
  * @throws IMP_Exception
  */
 public function stripPart($partid = null)
 {
     global $injector;
     list($mbox, $uid) = $this->getSingle();
     if (!$uid) {
         return;
     }
     if ($mbox->readonly) {
         throw new IMP_Exception(_("Cannot strip the part as the mailbox is read-only."));
     }
     $uidvalidity = $mbox->uidvalid;
     $contents = $injector->getInstance('IMP_Factory_Contents')->create($this);
     $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) {
         if (!($part = $message[$id])) {
             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(_("[Part stripped: Original part 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 part."));
     }
     $this->delete(array('keeplog' => true, 'nuke' => true));
     $indices_ob = $mbox->getIndicesOb($new_uid);
     /* 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;
 }
Beispiel #9
0
 /**
  * Process a message to retrieve it's header data without body and attachemnts.
  *
  * @param \Horde_Imap_Client_Data_Envelope $envelope The Envelope of the message
  * @param \Horde_Imap_Client_Data_Fetch $basemessagedata The structure and part of the message body
  * @param string|\Horde_Imap_Client_Ids $messageid The Hore message Uid
  * @return \stdClass The current value of the messagedata
  */
 private function process_message_data(\Horde_Imap_Client_Data_Envelope $envelope, \Horde_Imap_Client_Data_Fetch $basemessagedata, $messageid)
 {
     // Get the current mailbox.
     $mailbox = $this->get_mailbox();
     // We need the structure at various points below.
     $structure = $basemessagedata->getStructure();
     // Now fetch the rest of the message content.
     $query = new \Horde_Imap_Client_Fetch_Query();
     $query->imapDate();
     // Fetch the message header.
     $query->headerText();
     // Retrieve the message with the above components.
     $messagedata = $this->client->fetch($mailbox, $query, array('ids' => $messageid))->first();
     if (!$messagedata) {
         // Message was not found! Somehow it has been removed or is no longer returned.
         return null;
     }
     // The message ID should always be in the first part.
     $data = new \stdClass();
     $data->messageid = $messagedata->getHeaderText(0, \Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->getValue('Message-ID');
     $data->subject = $envelope->subject;
     $data->timestamp = $messagedata->getImapDate()->__toString();
     $data->envelope = $envelope;
     $data->data = $this->addressmanager->get_data();
     $data->headers = $messagedata->getHeaderText();
     $this->currentmessagedata = $data;
     return $this->currentmessagedata;
 }
 /**
  * Process a message to retrieve it's header data without body and attachemnts.
  *
  * @param Horde_Imap_Client_Data_Envelope $envelope The Envelope of the message
  * @param Horde_Imap_Client_Data_Fetch $messagedata The structure and part of the message body
  * @param string|Horde_Imap_Client_Ids $messageid The Hore message Uid
  * @return \stdClass The current value of the messagedata
  */
 private function process_message_data(\Horde_Imap_Client_Data_Envelope $envelope, \Horde_Imap_Client_Data_Fetch $basemessagedata, $messageid)
 {
     // Get the current mailbox.
     $mailbox = $this->get_mailbox();
     // We need the structure at various points below.
     $structure = $basemessagedata->getStructure();
     // Now fetch the rest of the message content.
     $query = new \Horde_Imap_Client_Fetch_Query();
     $query->imapDate();
     // Fetch all of the message parts too.
     $typemap = $structure->contentTypeMap();
     foreach ($typemap as $part => $type) {
         // The header.
         $query->headerText(array('id' => $part));
     }
     $messagedata = $this->client->fetch($mailbox, $query, array('ids' => $messageid))->first();
     // Store the data for this message.
     $headers = '';
     foreach ($typemap as $part => $type) {
         // Grab all of the header data into a string.
         $headers .= $messagedata->getHeaderText($part);
         // We don't handle any of the other MIME content at this stage.
     }
     $data = new \stdClass();
     // The message ID should always be in the first part.
     $data->messageid = $messagedata->getHeaderText(0, \Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->getValue('Message-ID');
     $data->subject = $envelope->subject;
     $data->timestamp = $messagedata->getImapDate()->__toString();
     $data->envelope = $envelope;
     $data->data = $this->addressmanager->get_data();
     $data->headers = $headers;
     $this->currentmessagedata = $data;
     return $this->currentmessagedata;
 }
Beispiel #11
0
 private function loadMessageBodies()
 {
     $headers = array();
     $fetch_query = new \Horde_Imap_Client_Fetch_Query();
     $fetch_query->envelope();
     $fetch_query->structure();
     $fetch_query->flags();
     $fetch_query->seq();
     $fetch_query->size();
     $fetch_query->uid();
     $fetch_query->imapDate();
     $headers = array_merge($headers, array('importance', 'list-post', 'x-priority'));
     $headers[] = 'content-type';
     $fetch_query->headers('imp', $headers, array('cache' => true, 'peek' => true));
     // $list is an array of Horde_Imap_Client_Data_Fetch objects.
     $ids = new \Horde_Imap_Client_Ids($this->message_id);
     $headers = $this->conn->fetch($this->folder_id, $fetch_query, array('ids' => $ids));
     $fetch = $headers[$this->message_id];
     // set $this->fetch to get to, from ...
     $this->fetch = $fetch;
     // analyse the body part
     $structure = $fetch->getStructure();
     // debugging below
     $structure_type = $structure->getPrimaryType();
     if ($structure_type == 'multipart') {
         $i = 1;
         foreach ($structure->getParts() as $p) {
             $this->getpart($p, $i++);
         }
     } else {
         if ($structure->findBody() != null) {
             // get the body from the server
             $partId = $structure->findBody();
             $this->queryBodyPart($partId);
         }
     }
 }
Beispiel #12
0
 /**
  * @depends testOptimizedSearches
  */
 public function testComplexFetch()
 {
     // Fetching message information from complex MIME message.
     $complex_fetch = new Horde_Imap_Client_Fetch_Query();
     $complex_fetch->fullText(array('length' => 100, 'peek' => true));
     // Header of entire message
     $complex_fetch->headerText(array('length' => 100, 'peek' => true));
     // Header of message/rfc822 part
     $complex_fetch->headerText(array('id' => 2, 'length' => 100, 'peek' => true));
     // Body text of entire message
     $complex_fetch->bodyText(array('length' => 100, 'peek' => true));
     // Body text of message/rfc822 part
     $complex_fetch->bodyText(array('id' => 2, 'length' => 100, 'peek' => true));
     // MIME Header of multipart/alternative part
     $complex_fetch->mimeHeader('1', array('length' => 100, 'peek' => true));
     // MIME Header of text/plain part embedded in message/rfc822 part
     $complex_fetch->mimeHeader('2.1', array('length' => 100, 'peek' => true));
     // Body text of multipart/alternative part
     $complex_fetch->bodyPart('1', array('length' => 100, 'peek' => true));
     // Body text of image/png part embedded in message/rfc822 part
     // Try to do server-side decoding, if available
     $complex_fetch->mimeHeader('2.2', array('decode' => true, 'length' => 100, 'peek' => true));
     // If supported, return decoded body part size
     $complex_fetch->bodyPartSize('2.2');
     // Select message-id header from base message header
     $complex_fetch->headers('headersearch1', array('message-id'), array('length' => 100, 'peek' => true));
     // Select everything but message-id header from message/rfc822 header
     $complex_fetch->headers('headersearch2', array('message-id'), array('id' => '2', 'length' => 100, 'notsearch' => true, 'peek' => true));
     $complex_fetch->structure();
     $complex_fetch->flags();
     $complex_fetch->imapDate();
     $complex_fetch->size();
     $complex_fetch->uid();
     if (self::$live->capability->query('CONDSTORE')) {
         $complex_fetch->modseq();
     }
     try {
         $res = self::$live->fetch(self::$test_mbox, $complex_fetch, array('ids' => new Horde_Imap_Client_Ids(3, true)));
     } catch (Horde_Imap_Client_Exception $e) {
         if ($e->getCode() === $e::MBOXNOMODSEQ) {
             $this->markTestSkipped('Mailbox does not support MODSEQ.');
         }
         throw $e;
     }
     $this->assertInstanceOf('Horde_Imap_Client_Fetch_Results', $res);
     $this->assertEquals(1, count($res));
     $this->assertEquals('Message-ID: <*****@*****.**>', trim($res[3]->getHeaders('headersearch1')));
     /* Return stream instead. */
     $this->assertInternalType('resource', $res[3]->getHeaders('headersearch1', Horde_Imap_Client_Data_Fetch::HEADER_STREAM));
     /* Parse headers instead. */
     $this->assertInstanceOf('Horde_Mime_Headers', $res[3]->getHeaders('headersearch1', Horde_Imap_Client_Data_Fetch::HEADER_PARSE));
 }
Beispiel #13
0
 private function loadMessageBodies()
 {
     $headers = [];
     $fetch_query = new \Horde_Imap_Client_Fetch_Query();
     $fetch_query->envelope();
     $fetch_query->structure();
     $fetch_query->flags();
     $fetch_query->size();
     $fetch_query->imapDate();
     $headers = array_merge($headers, ['importance', 'list-post', 'x-priority']);
     $headers[] = 'content-type';
     $fetch_query->headers('imp', $headers, ['cache' => true, 'peek' => true]);
     // $list is an array of Horde_Imap_Client_Data_Fetch objects.
     $ids = new \Horde_Imap_Client_Ids($this->messageId);
     $headers = $this->conn->fetch($this->mailBox, $fetch_query, ['ids' => $ids]);
     /** @var $fetch \Horde_Imap_Client_Data_Fetch */
     $fetch = $headers[$this->messageId];
     if (is_null($fetch)) {
         throw new DoesNotExistException("This email ({$this->messageId}) can't be found. Probably it was deleted from the server recently. Please reload.");
     }
     // set $this->fetch to get to, from ...
     $this->fetch = $fetch;
     // analyse the body part
     $structure = $fetch->getStructure();
     // debugging below
     $structure_type = $structure->getPrimaryType();
     if ($structure_type == 'multipart') {
         $i = 1;
         foreach ($structure->getParts() as $p) {
             $this->getPart($p, $i++);
         }
     } else {
         if ($structure->findBody() != null) {
             // get the body from the server
             $partId = $structure->findBody();
             $this->getPart($structure->getPart($partId), $partId);
         }
     }
 }
Beispiel #14
0
 /**
  * @static
  * @param $user_id
  * @param $account_id
  * @param $folder_id
  * @param int $from
  * @param int $count
  * @return array
  */
 public static function getMessages($user_id, $account_id, $folder_id, $from = 0, $count = 20)
 {
     // get the account
     $account = App::getAccount($user_id, $account_id);
     if (!$account) {
         #TODO: i18n
         return array('error' => 'unknown account');
     }
     try {
         // connect to the imap server
         $conn = App::getImapConnection($account);
         $messages = array();
         //			$mb = new \Horde_Imap_Client_Mailbox($folder_id);
         $status = $conn->status($folder_id, \Horde_Imap_Client::STATUS_MESSAGES);
         $total = $status['messages'];
         if ($from + $count > $total) {
             $count = $total - $from;
         }
         $headers = array();
         $fetch_query = new \Horde_Imap_Client_Fetch_Query();
         $fetch_query->envelope();
         $fetch_query->flags();
         $fetch_query->seq();
         $fetch_query->size();
         $fetch_query->uid();
         $fetch_query->imapDate();
         $headers = array_merge($headers, array('importance', 'list-post', 'x-priority'));
         $headers[] = 'content-type';
         $fetch_query->headers('imp', $headers, array('cache' => true, 'peek' => true));
         $opt = array('ids' => $from + 1 . ':' . ($from + 1 + $count));
         // $list is an array of Horde_Imap_Client_Data_Fetch objects.
         $headers = $conn->fetch($folder_id, $fetch_query);
         foreach ($headers as $header) {
             $flags = array('SEEN' => True, 'ANSWERED' => False, 'FORWARDED' => False, 'DRAFT' => False, 'HAS_ATTACHMENTS' => True);
             //					\Horde_Imap_Client_Data_Fetch::HEADER_PARSE
             $f = $header->getFlags();
             $date = $header->getImapDate()->format('U');
             $id = $header->getUid();
             $e = $header->getEnvelope();
             $flags = array();
             $to = $e->to_decoded[0];
             $to = $to['personal'];
             //."<".$to['mailbox']."@".$to['host'].">";
             $from = $e->from_decoded[0];
             $from = $from['personal'];
             //."<".$from['mailbox']."@".$from['host'].">";
             $messages[] = array('id' => $id, 'from' => $from, 'to' => $to, 'subject' => $e->subject_decoded, 'date' => $date, 'size' => $header->getSize(), 'flags' => $flags);
         }
         return array('account_id' => $account_id, 'folder_id' => $folder_id, 'messages' => $messages);
     } catch (\Horde_Imap_Client_Exception $e) {
         return array('error' => $e->getMessage());
     }
 }