本文整理汇总了PHP中Horde_Imap_Client_Fetch_Query::uid方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Imap_Client_Fetch_Query::uid方法的具体用法?PHP Horde_Imap_Client_Fetch_Query::uid怎么用?PHP Horde_Imap_Client_Fetch_Query::uid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Imap_Client_Fetch_Query
的用法示例。
在下文中一共展示了Horde_Imap_Client_Fetch_Query::uid方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMessages
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;
}
示例2: execute
/**
* 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;
}
示例3: fetchEnvelope
/**
*/
public function fetchEnvelope($indices)
{
if ($GLOBALS['registry']->hasMethod('mail/imapOb')) {
$query = new Horde_Imap_Client_Fetch_Query();
$query->envelope();
$query->uid();
try {
return $GLOBALS['registry']->call('mail/imapOb')->fetch($this->_getMboxOb(), $query, array('ids' => new Horde_Imap_Client_Ids($indices)));
} catch (Horde_Imap_Client_Exception $e) {
}
}
return false;
}
示例4: getMessages
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;
}
示例5: getmsg
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);
// }
}
示例6: _status
/**
*/
protected function _status($mboxes, $flags)
{
$out = $to_process = array();
$pipeline = $this->_pipeline();
$unseen_flags = array(Horde_Imap_Client::STATUS_FIRSTUNSEEN, Horde_Imap_Client::STATUS_UNSEEN);
foreach ($mboxes as $mailbox) {
/* If FLAGS/PERMFLAGS/UIDNOTSTICKY/FIRSTUNSEEN are needed, we must
* do a SELECT/EXAMINE to get this information (data will be
* caught in the code below). */
if ($flags & Horde_Imap_Client::STATUS_FIRSTUNSEEN || $flags & Horde_Imap_Client::STATUS_FLAGS || $flags & Horde_Imap_Client::STATUS_PERMFLAGS || $flags & Horde_Imap_Client::STATUS_UIDNOTSTICKY) {
$this->openMailbox($mailbox);
}
$mbox_ob = $this->_mailboxOb($mailbox);
$data = $query = array();
foreach ($this->_statusFields as $key => $val) {
if (!($val & $flags)) {
continue;
}
if ($val == Horde_Imap_Client::STATUS_HIGHESTMODSEQ) {
/* Don't include modseq returns if server does not support
* it. */
if (!$this->queryCapability('CONDSTORE')) {
continue;
}
/* Even though CONDSTORE is available, it may not yet have
* been enabled. */
if (!isset($this->_temp['enabled']['CONDSTORE'])) {
$this->_enabled(array('CONDSTORE'), 2);
}
}
if ($mailbox->equals($this->_selected)) {
if (!is_null($tmp = $mbox_ob->getStatus($val))) {
$data[$key] = $tmp;
} elseif ($val == Horde_Imap_Client::STATUS_UIDNEXT && $flags & Horde_Imap_Client::STATUS_UIDNEXT_FORCE) {
/* UIDNEXT is not mandatory. */
if ($mbox_ob->getStatus(Horde_Imap_Client::STATUS_MESSAGES) == 0) {
$data[$key] = 0;
} else {
$fquery = new Horde_Imap_Client_Fetch_Query();
$fquery->uid();
$fetch_res = $this->fetch($this->_selected, $fquery, array('ids' => $this->getIdsOb(Horde_Imap_Client_Ids::LARGEST)));
$data[$key] = $fetch_res->first()->getUid() + 1;
}
} elseif (in_array($val, $unseen_flags)) {
/* RFC 3501 [6.3.1] - FIRSTUNSEEN information is not
* mandatory. If missing in EXAMINE/SELECT results, we
* need to do a search. An UNSEEN count also requires
* a search. */
$squery = new Horde_Imap_Client_Search_Query();
$squery->flag(Horde_Imap_Client::FLAG_SEEN, false);
$search = $this->search($mailbox, $squery, array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MIN, Horde_Imap_Client::SEARCH_RESULTS_COUNT), 'sequence' => true));
$mbox_ob->setStatus(Horde_Imap_Client::STATUS_FIRSTUNSEEN, $search['min']);
$mbox_ob->setStatus(Horde_Imap_Client::STATUS_UNSEEN, $search['count']);
$data[$key] = $mbox_ob->getStatus($val);
}
} else {
$query[] = $key;
}
}
$out[strval($mailbox)] = $data;
if (count($query)) {
$pipeline->add($this->_command('STATUS')->add(array(new Horde_Imap_Client_Data_Format_Mailbox($mailbox), new Horde_Imap_Client_Data_Format_List(array_map('strtoupper', $query)))));
$to_process[] = array($query, $mailbox);
}
}
if (count($pipeline)) {
$this->_sendCmd($pipeline);
foreach ($to_process as $val) {
$out[strval($val[1])] += $this->_prepareStatusResponse($val[0], $val[1]);
}
}
return $out;
}
示例7: getMailboxArray
/**
* Build the array of message information.
*
* @param array $msgnum An array of index numbers.
* @param array $options Additional options:
* - headers: (boolean) Return info on the non-envelope headers
* 'Importance', 'List-Post', and 'X-Priority'.
* DEFAULT: false (only envelope headers returned)
* - preview: (mixed) Include preview information? If empty, add no
* preview information. If 1, uses value from prefs.
* If 2, forces addition of preview info.
* DEFAULT: No preview information.
* - type: (boolean) Return info on the MIME Content-Type of the base
* message part ('Content-Type' header).
* DEFAULT: false
*
* @return array An array with the following keys:
* - overview: (array) The overview information. Contains the following:
* - envelope: (Horde_Imap_Client_Data_Envelope) Envelope information
* returned from the IMAP server.
* - flags: (array) The list of IMAP flags returned from the server.
* - headers: (array) Horde_Mime_Headers objects containing header data
* if either $options['headers'] or $options['type'] are
* true.
* - idx: (integer) Array index of this message.
* - mailbox: (string) The mailbox containing the message.
* - preview: (string) If requested in $options['preview'], the preview
* text.
* - previewcut: (boolean) Has the preview text been cut?
* - size: (integer) The size of the message in bytes.
* - uid: (string) The unique ID of the message.
* - uids: (IMP_Indices) An indices object.
*/
public function getMailboxArray($msgnum, $options = array())
{
$this->_buildMailbox();
$headers = $overview = $to_process = $uids = array();
/* Build the list of mailboxes and messages. */
foreach ($msgnum as $i) {
/* Make sure that the index is actually in the slice of messages
we're looking at. If we're hiding deleted messages, for
example, there may be gaps here. */
if (isset($this->_sorted[$i - 1])) {
$to_process[strval($this->_getMbox($i - 1))][$i] = $this->_sorted[$i - 1];
}
}
$fetch_query = new Horde_Imap_Client_Fetch_Query();
$fetch_query->envelope();
$fetch_query->flags();
$fetch_query->size();
$fetch_query->uid();
if (!empty($options['headers'])) {
$headers = array_merge($headers, array('importance', 'list-post', 'x-priority'));
}
if (!empty($options['type'])) {
$headers[] = 'content-type';
}
if (!empty($headers)) {
$fetch_query->headers('imp', $headers, array('cache' => true, 'peek' => true));
}
if (empty($options['preview'])) {
$cache = null;
$options['preview'] = 0;
} else {
$cache = $this->_mailbox->imp_imap->getCache();
}
/* Retrieve information from each mailbox. */
foreach ($to_process as $mbox => $ids) {
try {
$imp_imap = IMP_Mailbox::get($mbox)->imp_imap;
$fetch_res = $imp_imap->fetch($mbox, $fetch_query, array('ids' => $imp_imap->getIdsOb($ids)));
if ($options['preview']) {
$preview_info = $tostore = array();
if ($cache) {
try {
$preview_info = $cache->get($mbox, $ids, array('IMPpreview', 'IMPpreviewc'));
} catch (IMP_Imap_Exception $e) {
}
}
}
$mbox_ids = array();
foreach ($ids as $k => $v) {
if (!isset($fetch_res[$v])) {
continue;
}
$f = $fetch_res[$v];
$uid = $f->getUid();
$v = array('envelope' => $f->getEnvelope(), 'flags' => $f->getFlags(), 'headers' => $f->getHeaders('imp', Horde_Imap_Client_Data_Fetch::HEADER_PARSE), 'idx' => $k, 'mailbox' => $mbox, 'size' => $f->getSize(), 'uid' => $uid);
if ($options['preview'] === 2 || $options['preview'] === 1 && (!$GLOBALS['prefs']->getValue('preview_show_unread') || !in_array(Horde_Imap_Client::FLAG_SEEN, $v['flags']))) {
if (empty($preview_info[$uid])) {
try {
$imp_contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($mbox, $uid));
$prev = $imp_contents->generatePreview();
$preview_info[$uid] = array('IMPpreview' => $prev['text'], 'IMPpreviewc' => $prev['cut']);
if (!is_null($cache)) {
$tostore[$uid] = $preview_info[$uid];
}
} catch (Exception $e) {
$preview_info[$uid] = array('IMPpreview' => '', 'IMPpreviewc' => false);
}
//.........这里部分代码省略.........
示例8: loadMessageBodies
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);
}
}
}
示例9: testComplexFetch
/**
* @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: <2008yhnujm@foo.example.com>', 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));
}
示例10: getMailboxArray
/**
* Build the array of message information.
*
* @param array $msgnum An array of index numbers.
*
* @return array An array with the following keys:
* <pre>
* - overview: (array) The overview information. Contains the following:
* - envelope: (Horde_Imap_Client_Data_Envelope) Envelope information
* returned from the IMAP server.
* - flags: (array) The list of IMAP flags returned from the server.
* - headers: (array) Horde_Mime_Headers objects containing header
* data for non-envelope headers.
* - idx: (integer) Array index of this message.
* - mailbox: (string) The mailbox containing the message.
* - size: (integer) The size of the message in bytes.
* - uid: (string) The unique ID of the message.
* - uids: (IMP_Indices) An indices object.
* </pre>
*/
public function getMailboxArray($msgnum)
{
$this->_buildMailbox();
$overview = $to_process = $uids = array();
/* Build the list of mailboxes and messages. */
foreach ($msgnum as $i) {
/* Make sure that the index is actually in the slice of messages
we're looking at. If we're hiding deleted messages, for
example, there may be gaps here. */
if (isset($this->_sorted[$i - 1])) {
$to_process[strval($this->_getMbox($i - 1))][$i] = $this->_sorted[$i - 1];
}
}
$fetch_query = new Horde_Imap_Client_Fetch_Query();
$fetch_query->envelope();
$fetch_query->flags();
$fetch_query->size();
$fetch_query->uid();
$fetch_query->headers('imp', array_merge(self::$headersUsed, IMP_Contents_Message::$headersUsed), array('cache' => true, 'peek' => true));
/* Retrieve information from each mailbox. */
foreach ($to_process as $mbox => $ids) {
try {
$imp_imap = IMP_Mailbox::get($mbox)->imp_imap;
if ($imp_imap->config->atc_structure) {
$query = clone $fetch_query;
$query->structure();
} else {
$query = $fetch_query;
}
$fetch_res = $imp_imap->fetch($mbox, $query, array('ids' => $imp_imap->getIdsOb($ids)));
$mbox_ids = array();
foreach ($ids as $k => $v) {
if (!isset($fetch_res[$v])) {
continue;
}
$f = $fetch_res[$v];
$uid = $f->getUid();
$v = array('envelope' => $f->getEnvelope(), 'flags' => $f->getFlags(), 'headers' => $f->getHeaders('imp', Horde_Imap_Client_Data_Fetch::HEADER_PARSE), 'idx' => $k, 'mailbox' => $mbox, 'size' => $f->getSize(), 'structure' => $f->getStructure(), 'uid' => $uid);
$overview[] = $v;
$mbox_ids[] = $uid;
}
$uids[$mbox] = $mbox_ids;
} catch (IMP_Imap_Exception $e) {
}
}
return array('overview' => $overview, 'uids' => new IMP_Indices($uids));
}
示例11: fetch
/**
* Fetch message data (see RFC 3501 [6.4.5]).
*
* @param mixed $mailbox The mailbox to search.
* Either a
* Horde_Imap_Client_Mailbox
* object or a string (UTF-8).
* @param Horde_Imap_Client_Fetch_Query $query Fetch query object.
* @param array $options Additional options:
* - changedsince: (integer) Only return messages that have a
* mod-sequence larger than this value. This option
* requires the CONDSTORE IMAP extension (if not present,
* this value is ignored). Additionally, the mailbox
* must support mod-sequences or an exception will be
* thrown. If valid, this option implicity adds the
* mod-sequence fetch criteria to the fetch command.
* DEFAULT: Mod-sequence values are ignored.
* - ids: (Horde_Imap_Client_Ids) A list of messages to fetch data from.
* DEFAULT: All messages in $mailbox will be fetched.
*
* @return Horde_Imap_Client_Fetch_Results A results object.
*
* @throws Horde_Imap_Client_Exception
* @throws Horde_Imap_Client_Exception_NoSupportExtension
*/
public function fetch($mailbox, $query, array $options = array())
{
$this->login();
$query = clone $query;
$cache_array = $header_cache = $new_query = array();
$res_seq = null;
if (empty($options['ids'])) {
$options['ids'] = $this->getIdsOb(Horde_Imap_Client_Ids::ALL);
} elseif ($options['ids']->isEmpty()) {
return new Horde_Imap_Client_Fetch_Results($this->_fetchDataClass);
} elseif ($options['ids']->search_res && !$this->queryCapability('SEARCHRES')) {
/* SEARCHRES requires server support. */
throw new Horde_Imap_Client_Exception_NoSupportExtension('SEARCHRES');
}
$this->openMailbox($mailbox, Horde_Imap_Client::OPEN_AUTO);
$cf = $this->_initCache(true) ? $this->_cacheFields() : array();
if (!empty($cf)) {
/* If using cache, we store by UID so we need to return UIDs. */
$query->uid();
}
if ($query->contains(Horde_Imap_Client::FETCH_MODSEQ) && !isset($this->_init['enabled']['CONDSTORE'])) {
unset($query[$k]);
}
/* Determine if caching is available and if anything in $query is
* cacheable.
* TODO: Re-add base headertext caching. */
foreach ($cf as $k => $v) {
if (isset($query[$k])) {
switch ($k) {
case Horde_Imap_Client::FETCH_ENVELOPE:
case Horde_Imap_Client::FETCH_FLAGS:
case Horde_Imap_Client::FETCH_IMAPDATE:
case Horde_Imap_Client::FETCH_SIZE:
case Horde_Imap_Client::FETCH_STRUCTURE:
$cache_array[$k] = $v;
break;
case Horde_Imap_Client::FETCH_HEADERS:
$this->_temp['headers_caching'] = array();
foreach ($query[$k] as $key => $val) {
/* Only cache if directly requested. Iterate through
* requests to ensure at least one can be cached. */
if (!empty($val['cache']) && !empty($val['peek'])) {
$cache_array[$k] = $v;
ksort($val);
$header_cache[$key] = hash('md5', serialize($val));
}
}
break;
}
}
}
$ret = new Horde_Imap_Client_Fetch_Results($this->_fetchDataClass, $options['ids']->sequence ? Horde_Imap_Client_Fetch_Results::SEQUENCE : Horde_Imap_Client_Fetch_Results::UID);
/* If nothing is cacheable, we can do a straight search. */
if (empty($cache_array)) {
$this->_fetch($ret, $query, $options);
return $ret;
}
/* If doing a changedsince search, limit the UIDs now. */
if (!empty($options['changedsince'])) {
$changed_query = new Horde_Imap_Client_Fetch_Query();
if ($options['ids']->sequence) {
$changed_query->seq();
} else {
$changed_query->uid();
}
$this->_fetch($ret, $changed_query, array('changedsince' => $options['changedsince'], 'ids' => $options['ids']));
if (!count($ret)) {
return $ret;
}
$options['ids'] = $this->getIdsOb($ret->ids(), $options['ids']->sequence);
}
/* Grab Seq -> UID lookup. */
$res_seq = $this->_getSeqUidLookup($options['ids']);
$ids = $options['ids']->sequence ? array_keys($res_seq['lookup']) : $res_seq['uids'];
/* Get the cached values. */
//.........这里部分代码省略.........
示例12: getMessages
/**
* @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());
}
}