本文整理汇总了PHP中Horde_Imap_Client_Fetch_Query::headers方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Imap_Client_Fetch_Query::headers方法的具体用法?PHP Horde_Imap_Client_Fetch_Query::headers怎么用?PHP Horde_Imap_Client_Fetch_Query::headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Imap_Client_Fetch_Query
的用法示例。
在下文中一共展示了Horde_Imap_Client_Fetch_Query::headers方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param IMP_Indices $indices The index of the message.
* @param boolean $peek Don't set seen flag?
*/
public function __construct(IMP_Indices $indices, $peek = false)
{
global $injector;
/* Get envelope/header information. We don't use flags in this
* view. */
try {
list($mbox, $uid) = $indices->getSingle();
if (!$uid) {
throw new Exception();
}
$query = new Horde_Imap_Client_Fetch_Query();
$query->envelope();
$query->headers('imp', self::$headersUsed, array('cache' => true, 'peek' => true));
$imp_imap = $mbox->imp_imap;
$imp_imap->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE);
$ret = $imp_imap->fetch($mbox, $query, array('ids' => $imp_imap->getIdsOb($uid)));
if (!($ob = $ret->first())) {
throw new Exception();
}
$this->contents = $injector->getInstance('IMP_Factory_Contents')->create($indices);
if (!$peek) {
$this->_loadHeaders();
}
} catch (Exception $e) {
throw new IMP_Exception(_("Requested message not found."));
}
$this->_envelope = $ob->getEnvelope();
$this->_headers = $ob->getHeaders('imp', Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
$this->_indices = $indices;
$this->_peek = $peek;
}
示例2: 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;
}
示例3: fetchFromUrl
/**
* Given an IMAP URL, fetches the corresponding part.
*
* @param Horde_Imap_Client_Url_Imap $url An IMAP URL.
*
* @return resource The section contents in a stream. Returns null if
* the part could not be found.
*
* @throws Horde_Imap_Client_Exception
*/
public function fetchFromUrl(Horde_Imap_Client_Url_Imap $url)
{
$ids_ob = $this->_socket->getIdsOb($url->uid);
// BODY[]
if (is_null($url->section)) {
$query = new Horde_Imap_Client_Fetch_Query();
$query->fullText(array('peek' => true));
$fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
return $fetch[$url->uid]->getFullMsg(true);
}
$section = trim($url->section);
// BODY[<#.>HEADER.FIELDS<.NOT>()]
if (($pos = stripos($section, 'HEADER.FIELDS')) !== false) {
$hdr_pos = strpos($section, '(');
$cmd = substr($section, 0, $hdr_pos);
$query = new Horde_Imap_Client_Fetch_Query();
$query->headers('section', explode(' ', substr($section, $hdr_pos + 1, strrpos($section, ')') - $hdr_pos)), array('id' => $pos ? substr($section, 0, $pos - 1) : 0, 'notsearch' => stripos($cmd, '.NOT') !== false, 'peek' => true));
$fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
return $fetch[$url->uid]->getHeaders('section', Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
}
// BODY[#]
if (is_numeric(substr($section, -1))) {
$query = new Horde_Imap_Client_Fetch_Query();
$query->bodyPart($section, array('peek' => true));
$fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
return $fetch[$url->uid]->getBodyPart($section, true);
}
// BODY[<#.>HEADER]
if (($pos = stripos($section, 'HEADER')) !== false) {
$id = $pos ? substr($section, 0, $pos - 1) : 0;
$query = new Horde_Imap_Client_Fetch_Query();
$query->headerText(array('id' => $id, 'peek' => true));
$fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
return $fetch[$url->uid]->getHeaderText($id, Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
}
// BODY[<#.>TEXT]
if (($pos = stripos($section, 'TEXT')) !== false) {
$id = $pos ? substr($section, 0, $pos - 1) : 0;
$query = new Horde_Imap_Client_Fetch_Query();
$query->bodyText(array('id' => $id, 'peek' => true));
$fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
return $fetch[$url->uid]->getBodyText($id, true);
}
// BODY[<#.>MIMEHEADER]
if (($pos = stripos($section, 'MIME')) !== false) {
$id = $pos ? substr($section, 0, $pos - 1) : 0;
$query = new Horde_Imap_Client_Fetch_Query();
$query->mimeHeader($id, array('peek' => true));
$fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
return $fetch[$url->uid]->getMimeHeader($id, Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
}
return null;
}
示例4: load
private function load()
{
$headers = [];
$fetch_query = new \Horde_Imap_Client_Fetch_Query();
$fetch_query->bodyPart($this->attachmentId);
$fetch_query->mimeHeader($this->attachmentId);
$headers = array_merge($headers, ['importance', 'list-post', 'x-priority']);
$headers[] = 'content-type';
$fetch_query->headers('imp', $headers, ['cache' => 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 */
if (!isset($headers[$this->messageId])) {
throw new DoesNotExistException('Unable to load the attachment.');
}
$fetch = $headers[$this->messageId];
$mimeHeaders = $fetch->getMimeHeader($this->attachmentId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
$this->mimePart = new \Horde_Mime_Part();
// To prevent potential problems with the SOP we serve all files with the
// MIME type "application/octet-stream"
$this->mimePart->setType('application/octet-stream');
// Serve all files with a content-disposition of "attachment" to prevent Cross-Site Scripting
$this->mimePart->setDisposition('attachment');
// Extract headers from part
$contentDisposition = $mimeHeaders->getValue('content-disposition', \Horde_Mime_Headers::VALUE_PARAMS);
if (!is_null($contentDisposition)) {
$vars = ['filename'];
foreach ($contentDisposition as $key => $val) {
if (in_array($key, $vars)) {
$this->mimePart->setDispositionParameter($key, $val);
}
}
} else {
$contentDisposition = $mimeHeaders->getValue('content-type', \Horde_Mime_Headers::VALUE_PARAMS);
$vars = ['name'];
foreach ($contentDisposition as $key => $val) {
if (in_array($key, $vars)) {
$this->mimePart->setContentTypeParameter($key, $val);
}
}
}
/* Content transfer encoding. */
if ($tmp = $mimeHeaders->getValue('content-transfer-encoding')) {
$this->mimePart->setTransferEncoding($tmp);
}
$body = $fetch->getBodyPart($this->attachmentId);
$this->mimePart->setContents($body);
}
示例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: 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);
}
//.........这里部分代码省略.........
示例7: 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;
}
示例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: loadMessageBodies
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);
}
}
}
示例11: 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));
}
示例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());
}
}