Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2019-10-07 15:07:51 +0300
committerGitHub <noreply@github.com>2019-10-07 15:07:51 +0300
commit18a76774eb0f0e00b5a3ddfbea8d2e980219b642 (patch)
tree72b07864b1dd615fefc686eee76f7648d3fbae2c /lib/Mailbox.php
parent4e2ebfa08d809ab01de113eb895757fb7b5a02ca (diff)
Clean up searching for messages (#2058)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Mailbox.php')
-rw-r--r--lib/Mailbox.php120
1 files changed, 0 insertions, 120 deletions
diff --git a/lib/Mailbox.php b/lib/Mailbox.php
index eac4f6754..c213a4f1c 100644
--- a/lib/Mailbox.php
+++ b/lib/Mailbox.php
@@ -93,126 +93,6 @@ class Mailbox implements IMailBox {
}
/**
- * @param string|Horde_Imap_Client_Search_Query $filter
- * @param int $cursor
- */
- private function getSearchIds($filter, $cursor = null) {
- if ($filter instanceof Horde_Imap_Client_Search_Query) {
- $query = $filter;
- } else {
- $searchHelper = new SearchHelper();
- $query = $searchHelper->parseFilterString($filter);
- }
- if ($this->getSpecialRole() !== 'trash') {
- $query->flag(Horde_Imap_Client::FLAG_DELETED, false);
- }
- if (!is_null($cursor)) {
- $query->dateTimeSearch(DateTime::createFromFormat("U", $cursor), Horde_Imap_Client_Search_Query::DATE_BEFORE);
- }
-
- try {
- $result = $this->conn->search($this->mailBox, $query, [
- 'sort' => [
- Horde_Imap_Client::SORT_DATE
- ],
- ]);
- } catch (Horde_Imap_Client_Exception $e) {
- // maybe the server's advertisment of SORT was a fake
- // see https://github.com/nextcloud/mail/issues/50
- // try again without SORT
- return $this->getFetchIds($cursor);
- }
-
- return array_reverse($result['match']->ids);
- }
-
- /**
- * @param int $cursor
- * @return type
- */
- private function getFetchIds($cursor = null) {
- $q = new Horde_Imap_Client_Fetch_Query();
- $q->uid();
- $q->imapDate();
-
- $result = $this->conn->fetch($this->mailBox, $q);
- $uidMap = [];
- foreach ($result as $r) {
- $ts = $r->getImapDate()->getTimeStamp();
- if (is_null($cursor) || $ts < $cursor) {
- $uidMap[$r->getUid()] = $ts;
- }
- }
- // sort by time
- uasort($uidMap, function($a, $b) {
- return $a < $b;
- });
- return array_keys($uidMap);
- }
-
- /**
- * Get message page
- *
- * Build the list of UIDs for the current page on the client side
- *
- * This is done by fetching a list of *all* UIDs and their data, sorting them
- * respectively and selecting the appropriate page. The page starts once UID after
- * the cursorId, if given. The size of the page is limited to 20.
- *
- * @param string|Horde_Imap_Client_Search_Query $filter
- * @param int $cursor time stamp of the oldest message on the client
- * @return array
- */
- public function getMessages($filter = null, int $cursor = null): array {
- if (!$this->conn->capability->query('SORT') && (is_null($filter) || $filter === '')) {
- $ids = $this->getFetchIds($cursor);
- } else {
- $ids = $this->getSearchIds($filter, $cursor);
- }
- $page = new Horde_Imap_Client_Ids(array_slice($ids, 0, 20, true));
-
- $fetchQuery = new Horde_Imap_Client_Fetch_Query();
- $fetchQuery->envelope();
- $fetchQuery->flags();
- $fetchQuery->size();
- $fetchQuery->uid();
- $fetchQuery->imapDate();
- $fetchQuery->structure();
-
- $headers = [
- 'importance',
- 'list-post',
- 'x-priority',
- 'content-type',
- ];
-
- $fetchQuery->headers('imp', $headers, [
- 'cache' => true,
- 'peek' => true
- ]);
-
- $options = ['ids' => $page];
- // $list is an array of Horde_Imap_Client_Data_Fetch objects.
- $fetchResult = $this->conn->fetch($this->mailBox, $fetchQuery, $options);
-
- ob_start(); // fix for Horde warnings
- $messages = [];
- foreach ($fetchResult->ids() as $messageId) {
- $header = $fetchResult[$messageId];
- $message = new IMAPMessage($this->conn, $this->mailBox, $messageId, $header);
- $messages[] = $message->jsonSerialize();
- }
- ob_get_clean();
-
- // sort by time
- usort($messages, function($a, $b) {
- return $a['dateInt'] < $b['dateInt'];
- });
-
- return $messages;
- }
-
- /**
* @return array
*/
public function attributes() {