本文整理汇总了PHP中Horde_Imap_Client_Fetch_Query::flags方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Imap_Client_Fetch_Query::flags方法的具体用法?PHP Horde_Imap_Client_Fetch_Query::flags怎么用?PHP Horde_Imap_Client_Fetch_Query::flags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Imap_Client_Fetch_Query
的用法示例。
在下文中一共展示了Horde_Imap_Client_Fetch_Query::flags方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: getLog
/**
*/
public function getLog(IMP_Maillog_Message $msg, array $types = array())
{
$log_ob = new IMP_Maillog_Log_Mdn();
if (!empty($types) && !in_array('IMP_Maillog_Log_Mdn', $types) || !$this->isAvailable($msg, $log_ob)) {
return array();
}
list($mbox, $uid) = $msg->indices->getSingle();
$imp_imap = $mbox->imp_imap;
$query = new Horde_Imap_Client_Fetch_Query();
$query->flags();
try {
$flags = $imp_imap->fetch($mbox, $query, array('ids' => $imp_imap->getIdsOb($uid)))->first()->getFlags();
} catch (IMP_Imap_Exception $e) {
$flags = array();
}
return in_array(Horde_Imap_Client::FLAG_MDNSENT, $flags) ? array($log_ob) : array();
}
示例4: getLog
/**
*/
public function getLog(IMP_Maillog_Message $msg, array $filter = array())
{
if (!$msg->indices || in_array('mdn', $filter)) {
return array();
}
list($mbox, $uid) = $msg->indices->getSingle();
if (!$mbox->permflags->allowed(Horde_Imap_Client::FLAG_MDNSENT)) {
return array();
}
$query = new Horde_Imap_Client_Fetch_Query();
$query->flags();
$imp_imap = $mbox->imp_imap;
try {
$flags = $imp_imap->fetch($mbox, $query, array('ids' => $imp_imap->getIdsOb($uid)))->first()->getFlags();
} catch (IMP_Imap_Exception $e) {
$flags = array();
}
return in_array(Horde_Imap_Client::FLAG_MDNSENT, $flags) ? array(new IMP_Maillog_Log_Mdn()) : array();
}
示例5: getChanges
/**
* Return a folder object containing all IMAP server change information.
*
* @param array $options An array of options.
* @see Horde_ActiveSync_Imap_Adapter::getMessageChanges
*
* @return Horde_ActiveSync_Folder_Base The populated folder object.
*/
public function getChanges(array $options)
{
$this->_logger->info(sprintf('[%s] NO CONDSTORE or per mailbox MODSEQ. minuid: %s, total_messages: %s', $this->_procid, $this->_folder->minuid(), $this->_status['messages']));
$query = new Horde_Imap_Client_Search_Query();
if (!empty($options['sincedate'])) {
$query->dateSearch(new Horde_Date($options['sincedate']), Horde_Imap_Client_Search_Query::DATE_SINCE);
}
try {
$search_ret = $this->_imap_ob->search($this->_mbox, $query, array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH)));
} catch (Horde_Imap_Client_Exception $e) {
$this->_logger->err($e->getMessage());
throw new Horde_ActiveSync_Exception($e);
}
$cnt = $search_ret['count'] / Horde_ActiveSync_Imap_Adapter::MAX_FETCH + 1;
$query = new Horde_Imap_Client_Fetch_Query();
$query->flags();
$flags = array();
for ($i = 0; $i <= $cnt; $i++) {
$ids = new Horde_Imap_Client_Ids(array_slice($search_ret['match']->ids, $i * Horde_ActiveSync_Imap_Adapter::MAX_FETCH, Horde_ActiveSync_Imap_Adapter::MAX_FETCH));
try {
$fetch_ret = $this->_imap_ob->fetch($this->_mbox, $query, array('ids' => $ids));
} catch (Horde_Imap_Client_Exception $e) {
$this->_logger->err($e->getMessage());
throw new Horde_ActiveSync_Exception($e);
}
foreach ($fetch_ret as $uid => $data) {
$flags[$uid] = array('read' => array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false ? 1 : 0);
if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWOFIVE) {
$flags[$uid]['flagged'] = array_search(Horde_Imap_Client::FLAG_FLAGGED, $data->getFlags()) !== false ? 1 : 0;
}
}
}
if (!empty($flags)) {
$this->_folder->setChanges($search_ret['match']->ids, $flags);
}
$this->_folder->setRemoved($this->_imap_ob->vanished($this->_mbox, null, array('ids' => new Horde_Imap_Client_Ids($this->_folder->messages())))->ids);
return $this->_folder;
}
示例6: 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);
// }
}
示例7: message_has_flag
/**
* Check whether the message has the specified flag
*
* @param mixed $messageid
* @param string $flag The flag to check
* @return bool
*/
private function message_has_flag($messageid, $flag)
{
// Get the current mailbox.
$mailbox = $this->get_mailbox();
// Grab messagedata including flags.
$query = new \Horde_Imap_Client_Fetch_Query();
$query->flags();
$query->structure();
$messagedata = $this->client->fetch($mailbox, $query, array('ids' => $messageid))->first();
$flags = $messagedata->getFlags();
return in_array($flag, $flags);
}
示例8: _init
/**
* URL Parameters:
* a: (string) Action ID.
* allto: (boolean) View all To addresses?
* buid: (string) Browser UID.
* t: (string) Token.
*/
protected function _init()
{
global $injector, $notification, $page_output, $prefs, $session;
$imp_mailbox = $this->indices->mailbox->list_ob;
$imp_mailbox->setIndex($this->indices);
$mailbox_url = IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox));
/* Make sure we have a valid index. */
if (!$imp_mailbox->isValidIndex()) {
$mailbox_url->add('a', 'm')->redirect();
}
$imp_ui = $injector->getInstance('IMP_Message_Ui');
/* Run through action handlers */
$msg_delete = false;
switch ($this->vars->a) {
// 'd' = delete message
case 'd':
$old_index = $imp_mailbox->getIndex();
try {
$session->checkToken($this->vars->t);
$msg_delete = (bool) $injector->getInstance('IMP_Message')->delete($this->indices, array('mailboxob' => $imp_mailbox));
} catch (Horde_Exception $e) {
$notification->push($e);
}
break;
// 'u' = undelete message
// 'u' = undelete message
case 'u':
$old_index = $imp_mailbox->getIndex();
$injector->getInstance('IMP_Message')->undelete($this->indices);
break;
// 'rs' = report spam
// 'ri' = report innocent
// 'rs' = report spam
// 'ri' = report innocent
case 'rs':
case 'ri':
$old_index = $imp_mailbox->getIndex();
$msg_delete = $injector->getInstance('IMP_Factory_Spam')->create($this->vars->a == 'rs' ? IMP_Spam::SPAM : IMP_Spam::INNOCENT)->report($this->indices, array('mailboxob' => $imp_mailbox)) === 1;
break;
}
if ($msg_delete && $imp_ui->moveAfterAction($this->indices->mailbox)) {
$imp_mailbox->setIndex(1);
}
/* We may have done processing that has taken us past the end of the
* message array, so we will return to the mailbox. */
if (!$imp_mailbox->isValidIndex() || $msg_delete && $prefs->getValue('mailbox_return')) {
$mailbox_url->add('s', $old_index)->redirect();
}
/* Now that we are done processing, get the index and array index of
* the current message. */
$msg_index = $imp_mailbox[$imp_mailbox->getIndex()];
$mailbox = $msg_index['m'];
$uid = $msg_index['u'];
$buid = $imp_mailbox->getBuid($mailbox, $uid);
/* Get envelope/flag/header information. */
try {
$imp_imap = $mailbox->imp_imap;
/* Need to fetch flags before HEADERTEXT, because SEEN flag might
* be set before we can grab it. */
$query = new Horde_Imap_Client_Fetch_Query();
$query->flags();
$flags_ret = $imp_imap->fetch($mailbox, $query, array('ids' => $imp_imap->getIdsOb($uid)));
$query = new Horde_Imap_Client_Fetch_Query();
$query->envelope();
$fetch_ret = $imp_imap->fetch($mailbox, $query, array('ids' => $imp_imap->getIdsOb($uid)));
} catch (IMP_Imap_Exception $e) {
$mailbox_url->add('a', 'm')->redirect();
}
$envelope = $fetch_ret->first()->getEnvelope();
$flags = $flags_ret->first()->getFlags();
/* Parse the message. */
try {
$imp_contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($imp_mailbox));
$mime_headers = $imp_contents->getHeaderAndMarkAsSeen();
} catch (IMP_Exception $e) {
$mailbox_url->add('a', 'm')->redirect();
}
/* Get the starting index for the current message and the message
* count. */
$msgindex = $imp_mailbox->getIndex();
$msgcount = count($imp_mailbox);
/* Generate the mailbox link. */
$mailbox_link = $mailbox_url->add('s', $msgindex);
$self_link = self::url(array('buid' => $buid, 'mailbox' => $this->indices->mailbox));
/* Create the Identity object. */
$user_identity = $injector->getInstance('IMP_Identity');
/* Develop the list of headers to display. */
$basic_headers = $imp_ui->basicHeaders();
$display_headers = $msgAddresses = array();
if ($subject = $mime_headers->getValue('subject')) {
/* Filter the subject text, if requested. */
$subject = Horde_String::truncate(IMP::filterText($subject), 50);
} else {
//.........这里部分代码省略.........
示例9: _condstoreSync
/**
* Synchronizes the current mailbox cache with the server (using CONDSTORE
* or QRESYNC).
*/
protected function _condstoreSync()
{
$mbox_ob = $this->_mailboxOb();
/* Check that modseqs are available in mailbox. */
if (!($highestmodseq = $mbox_ob->getStatus(Horde_Imap_Client::STATUS_HIGHESTMODSEQ)) || !($modseq = $this->_updateModSeq($highestmodseq))) {
$mbox_ob->sync = true;
}
if ($mbox_ob->sync) {
return;
}
$uids_ob = $this->getIdsOb($this->_cache->get($this->_selected, array(), array(), $mbox_ob->getStatus(Horde_Imap_Client::STATUS_UIDVALIDITY)));
if (!count($uids_ob)) {
$mbox_ob->sync = true;
return;
}
/* Are we caching flags? */
if (array_key_exists(Horde_Imap_Client::FETCH_FLAGS, $this->_cacheFields())) {
$fquery = new Horde_Imap_Client_Fetch_Query();
$fquery->flags();
/* Update flags in cache. Cache will be updated in _fetch(). */
$this->_fetch(new Horde_Imap_Client_Fetch_Results(), array(array('_query' => $fquery, 'changedsince' => $modseq, 'ids' => $uids_ob)));
}
/* Search for deleted messages, and remove from cache. */
$vanished = $this->vanished($this->_selected, $modseq, array('ids' => $uids_ob));
$disappear = array_diff($uids_ob->ids, $vanished->ids);
if (!empty($disappear)) {
$this->_deleteMsgs($this->_selected, $this->getIdsOb($disappear));
}
$mbox_ob->sync = true;
}
示例10: _init
/**
*/
protected function _init()
{
global $conf, $injector, $notification, $page_output, $prefs, $registry, $session;
$mailbox = $this->indices->mailbox;
$imp_imap = $mailbox->imp_imap;
/* We know we are going to be exclusively dealing with this mailbox,
* so select it on the IMAP server (saves some STATUS calls). Open R/W
* to clear the RECENT flag. */
$imp_imap->openMailbox($mailbox, Horde_Imap_Client::OPEN_READWRITE);
/* Make sure we have a valid index. */
$imp_mailbox = $mailbox->list_ob;
$imp_mailbox->setIndex($this->indices);
if (!$imp_mailbox->isValidIndex()) {
$this->_returnToMailbox(null, 'message_missing');
return;
}
$imp_flags = $injector->getInstance('IMP_Flags');
$imp_identity = $injector->getInstance('IMP_Identity');
$imp_message = $injector->getInstance('IMP_Message');
$imp_ui = $injector->getInstance('IMP_Message_Ui');
/* Run through action handlers. */
if ($this->vars->actionID) {
try {
$session->getToken($this->vars->token);
} catch (Horde_Exception $e) {
$notification->push($e);
$this->vars->actionID = null;
}
}
$readonly = $mailbox->readonly;
$peek = false;
switch ($this->vars->actionID) {
case 'blacklist':
case 'whitelist':
if ($this->vars->actionID == 'blacklist') {
$injector->getInstance('IMP_Filter')->blacklistMessage($this->indices);
} else {
$injector->getInstance('IMP_Filter')->whitelistMessage($this->indices);
}
break;
case 'delete_message':
$imp_message->delete($this->indices, array('mailboxob' => $imp_mailbox));
if ($prefs->getValue('mailbox_return')) {
$this->_returnToMailbox($imp_mailbox->getIndex());
return;
}
if ($imp_ui->moveAfterAction($mailbox)) {
$imp_mailbox->setIndex(1);
}
break;
case 'undelete_message':
$imp_message->undelete($this->indices);
break;
case 'move_message':
case 'copy_message':
if (isset($this->vars->targetMbox) && (!$readonly || $this->vars->actionID == 'copy_message')) {
if ($this->vars->newMbox) {
$targetMbox = IMP_Mailbox::prefFrom($this->vars->targetMbox);
$newMbox = true;
} else {
$targetMbox = IMP_Mailbox::formFrom($this->vars->targetMbox);
$newMbox = false;
}
$imp_message->copy($targetMbox, $this->vars->actionID == 'move_message' ? 'move' : 'copy', $this->indices, array('create' => $newMbox, 'mailboxob' => $imp_mailbox));
if ($prefs->getValue('mailbox_return')) {
$this->_returnToMailbox($imp_mailbox->getIndex());
return;
}
}
break;
case 'innocent_report':
case 'spam_report':
$res = $injector->getInstance('IMP_Factory_Spam')->create($this->vars->actionID == 'spam_report' ? IMP_Spam::SPAM : IMP_Spam::INNOCENT)->report($this->indices, array('mailbox' => $imp_mailbox));
switch ($res) {
case 1:
if ($imp_ui->moveAfterAction($mailbox)) {
$imp_mailbox->setIndex(1);
}
break;
}
if ($prefs->getValue('mailbox_return')) {
$this->_returnToMailbox($imp_mailbox->getIndex());
return;
}
break;
case 'flag_message':
if (!$readonly && isset($this->vars->flag) && count($this->indices)) {
$peek = true;
$flag = $imp_flags->parseFormId($this->vars->flag);
$imp_message->flag(array($flag['set'] ? 'add' : 'remove' => array($flag['flag'])), $this->indices);
if ($prefs->getValue('mailbox_return')) {
$this->_returnToMailbox($imp_mailbox->getIndex());
return;
}
}
break;
case 'add_address':
try {
//.........这里部分代码省略.........
示例11: 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);
}
}
}
示例12: _syncMailbox
/**
* Synchronizes the current mailbox cache with the server.
*/
protected function _syncMailbox()
{
$status = $this->status($this->_selected, Horde_Imap_Client::STATUS_UIDVALIDITY | Horde_Imap_Client::STATUS_HIGHESTMODSEQ);
/* Check that modseqs are available in mailbox. */
if (empty($status['highestmodseq'])) {
return;
}
/* Grab all flags updated since the cached modseq. */
$md = $this->_cache->getMetaData($this->_selected, $status['uidvalidity'], array(self::CACHE_MODSEQ));
if (!isset($md[self::CACHE_MODSEQ]) || $md[self::CACHE_MODSEQ] == $status['highestmodseq']) {
return;
}
$uids = $this->_cache->get($this->_selected, array(), array(), $status['uidvalidity']);
if (!empty($uids)) {
$uids_ob = $this->getIdsOb($uids);
/* Are we caching flags? */
if (array_key_exists(Horde_Imap_Client::FETCH_FLAGS, $this->_cacheFields())) {
$fquery = new Horde_Imap_Client_Fetch_Query();
$fquery->flags();
/* Update flags in cache. Cache will be updated in _fetch(). */
$this->_fetch(new Horde_Imap_Client_Fetch_Results(), $fquery, array('changedsince' => $md[self::CACHE_MODSEQ], 'ids' => $uids_ob));
}
/* Search for deleted messages, and remove from cache. */
$squery = new Horde_Imap_Client_Search_Query();
$squery->ids($this->getIdsOb($uids_ob->range_string));
$search = $this->search($this->_selected, $squery, array('nocache' => true));
$deleted = array_diff($uids_ob->ids, $search['match']->ids);
if (!empty($deleted)) {
$this->_deleteMsgs($this->_selected, $deleted);
}
}
$this->_updateMetaData($this->_selected, array(self::CACHE_MODSEQ => $status['highestmodseq']), $status['uidvalidity']);
}
示例13: stripPart
/**
* 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;
}
示例14: 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);
}
//.........这里部分代码省略.........
示例15: getChanges
/**
* Return a folder object containing all IMAP server change information.
*
* @param array $options An array of options.
* @see Horde_ActiveSync_Imap_Adapter::getMessageChanges
*
* @return Horde_ActiveSync_Folder_Base The populated folder object.
*/
public function getChanges(array $options)
{
$this->_logger->info(sprintf('[%s] CONDSTORE and CHANGES', $this->_procid));
$flags = array();
$current_modseq = $this->_status[Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ];
$query = new Horde_Imap_Client_Search_Query();
// Increment since $imap->search uses >= operator.
if ($this->_modseq_valid) {
$query->modseq($this->_folder->modseq() + 1);
}
if (!empty($options['sincedate'])) {
$query->dateSearch(new Horde_Date($options['sincedate']), Horde_Imap_Client_Search_Query::DATE_SINCE);
}
$search_ret = $this->_imap_ob->search($this->_mbox, $query, array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH)));
$search_uids = $search_ret['count'] ? $search_ret['match']->ids : array();
// Catch changes to FILTERTYPE.
if (!empty($options['refreshfilter'])) {
$this->_logger->info(sprintf('[%s] Checking for additional messages within the new FilterType parameters.', $this->_procid));
$search_ret = $this->_searchQuery($options, false);
if ($search_ret['count']) {
$this->_logger->info(sprintf('[%s] Found %d messages that are now outside FilterType.', $this->_procid, $search_ret['count']));
$search_uids = array_merge($search_uids, $search_ret['match']->ids);
}
}
// Protect against very large change sets.
$cnt = count($search_uids) / Horde_ActiveSync_Imap_Adapter::MAX_FETCH + 1;
$query = new Horde_Imap_Client_Fetch_Query();
if ($this->_modseq_valid) {
$query->modseq();
}
$query->flags();
$changes = array();
$categories = array();
for ($i = 0; $i <= $cnt; $i++) {
$ids = new Horde_Imap_Client_Ids(array_slice($search_uids, $i * Horde_ActiveSync_Imap_Adapter::MAX_FETCH, Horde_ActiveSync_Imap_Adapter::MAX_FETCH));
try {
$fetch_ret = $this->_imap_ob->fetch($this->_mbox, $query, array('ids' => $ids));
} catch (Horde_Imap_Client_Exception $e) {
$this->_logger->err($e->getMessage());
throw new Horde_ActiveSync_Exception($e);
}
$this->_buildModSeqChanges($changes, $flags, $categories, $fetch_ret, $options, $current_modseq);
}
// Set the changes in the folder object.
$this->_folder->setChanges($changes, $flags, $categories, !empty($options['softdelete']) || !empty($options['refreshfilter']));
// Check for deleted messages.
try {
$deleted = $this->_imap_ob->vanished($this->_mbox, $this->_folder->modseq(), array('ids' => new Horde_Imap_Client_Ids($this->_folder->messages())));
} catch (Horde_Imap_Client_Excetion $e) {
$this->_logger->err($e->getMessage());
throw new Horde_ActiveSync_Exception($e);
}
$this->_folder->setRemoved($deleted->ids);
$this->_logger->info(sprintf('[%s] Found %d deleted messages.', $this->_procid, $deleted->count()));
// Check for SOFTDELETE messages.
if (!empty($options['sincedate']) && (!empty($options['softdelete']) || !empty($options['refreshfilter']))) {
$this->_logger->info(sprintf('[%s] Polling for SOFTDELETE in %s before %d', $this->_procid, $this->_folder->serverid(), $options['sincedate']));
$search_ret = $this->_searchQuery($options, true);
if ($search_ret['count']) {
$this->_logger->info(sprintf('[%s] Found %d messages to SOFTDELETE.', $this->_procid, count($search_ret['match']->ids)));
$this->_folder->setSoftDeleted($search_ret['match']->ids);
}
$this->_folder->setSoftDeleteTimes($options['sincedate'], time());
}
return $this->_folder;
}