-
Notifications
You must be signed in to change notification settings - Fork 8
Added option for setting fetched emails \\seen flag to seen #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,12 @@ class Client | |
| */ | ||
| private $emailFactory; | ||
|
|
||
| /** | ||
| * | ||
| * @var boolean | ||
| */ | ||
| private $peek; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not store state into a property in this class. The You should instead pass the |
||
|
|
||
| public function __construct(Horde_Imap_Client_Socket $hordeClient, EmailFactory $emailFactory = null) | ||
| { | ||
| $this->hordeClient = $hordeClient; | ||
|
|
@@ -63,24 +69,24 @@ public function getFolders() : array | |
| return array_keys($this->hordeClient->listMailboxes('*')); | ||
| } | ||
|
|
||
| /** | ||
| /** | ||
| * Finds the emails matching the query. If $query is null, then it will fetch the emails in the inbox. | ||
| * | ||
| * @param boolean $peek sets the peek option, "false" fetched emails' state will be set to seen "true" no change of state default is true | ||
| * @return Email[] | ||
| */ | ||
| public function getEmails(Query $query = null) : array | ||
| public function getEmails(Query $query = null, bool $peek = true): array | ||
| { | ||
| $hordeQuery = new Horde_Imap_Client_Search_Query(); | ||
|
|
||
| $query = $query ?: new Query; | ||
|
|
||
| if ($query->getYoungerThan() !== null) { | ||
| $hordeQuery->intervalSearch( | ||
| $query->getYoungerThan(), | ||
| Horde_Imap_Client_Search_Query::INTERVAL_YOUNGER | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are those lines changed? Those were formatted to follow PSR-2.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDE
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please revert those changes? |
||
| $query->getYoungerThan(), | ||
| Horde_Imap_Client_Search_Query::INTERVAL_YOUNGER | ||
| ); | ||
| } | ||
|
|
||
| $this->setPeek($peek); | ||
| $this->setFlags($hordeQuery, $query); | ||
| return $this->searchAndFetch($query->getFolder(), $hordeQuery); | ||
| } | ||
|
|
@@ -89,42 +95,50 @@ public function getEmails(Query $query = null) : array | |
| * Finds the email Ids matching the query. If $query is null, then it will fetch the email Ids in the inbox. | ||
| * | ||
| * This method is obviously more efficient than getEmails() if you want to synchronize local mails. | ||
| * | ||
| * | ||
| * @param boolean $peek sets the peek option, "false" fetched emails' state will be set to seen "true" no change of state default is true | ||
| * @return string[] | ||
| */ | ||
| public function getEmailIds(Query $query = null) : array | ||
| public function getEmailIds(Query $query = null, bool $peek = true): array | ||
| { | ||
| $hordeQuery = new Horde_Imap_Client_Search_Query(); | ||
|
|
||
| $query = $query ?: new Query; | ||
|
|
||
| if ($query->getYoungerThan() !== null) { | ||
| $hordeQuery->intervalSearch( | ||
| $query->getYoungerThan(), | ||
| Horde_Imap_Client_Search_Query::INTERVAL_YOUNGER | ||
| $query->getYoungerThan(), | ||
| Horde_Imap_Client_Search_Query::INTERVAL_YOUNGER | ||
| ); | ||
| } | ||
|
|
||
| $this->setPeek($peek); | ||
| $this->setFlags($hordeQuery, $query); | ||
| return $this->search($query->getFolder(), $hordeQuery); | ||
| } | ||
|
|
||
| /** | ||
| * @param String $folder the folder to get email from | ||
| * @param boolean $peek sets the peek option, "false" fetched emails' state will be set to seen "true" no change of state default is true | ||
| * @return Email|null Returns null if the email was not found. | ||
| */ | ||
| public function getEmailFromId(string $id, string $folder = 'INBOX') | ||
| public function getEmailFromId(string $id, string $folder = 'INBOX', bool $peek = true) | ||
| { | ||
| $this->setPeek($peek); | ||
| $emails = $this->fetchEmails($folder, [$id]); | ||
|
|
||
| return (count($emails) > 0) ? $emails[0] : null; | ||
| } | ||
|
|
||
| /** | ||
| * @param string[] $ids | ||
| * @param String $folder the folder to get emails from | ||
| * @param boolean $peek sets the peek option, "false" fetched emails' state will be set to seen "true" no change of state default is true | ||
| * @return Email[] | ||
| */ | ||
| public function getEmailsFromId(array $ids, string $folder = 'INBOX') : array | ||
| public function getEmailsFromId(array $ids, string $folder = 'INBOX', bool $peek = true) : array | ||
| { | ||
| $this->setPeek($peek); | ||
| return $this->fetchEmails($folder, $ids); | ||
| } | ||
|
|
||
|
|
@@ -178,7 +192,7 @@ private function fetchEmails(string $folder, array $ids) : array | |
| $query = new Horde_Imap_Client_Fetch_Query(); | ||
| $query->envelope(); | ||
| $query->fullText([ | ||
| 'peek' => true, | ||
| 'peek' => $this->getPeek(), | ||
| ]); | ||
| $query->flags(); | ||
|
|
||
|
|
@@ -220,4 +234,17 @@ private function setFlags(Horde_Imap_Client_Search_Query $hordeQuery,Query $quer | |
| } | ||
| } | ||
| } | ||
| /** | ||
| * | ||
| * @param boolean $peek | ||
| */ | ||
| public function setPeek($peek) | ||
| { | ||
| $this->peek = $peek; | ||
| } | ||
|
|
||
| public function getPeek() | ||
| { | ||
| return $this->peek; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,16 @@ class Query | |
| * @var int | ||
| */ | ||
| private $youngerThan; | ||
| private $flags = []; | ||
|
|
||
| public function getFolder() : string | ||
| const FLAG_ANSWERED = 'ANSWERED'; | ||
| const FLAG_DELETED = 'DELETED'; | ||
| const FLAG_DRAFT = 'DRAFT'; | ||
| const FLAG_FLAGED = 'FLAGGED'; | ||
| const FLAG_RECENT = 'RECENT'; | ||
| const FLAG_SEEN = 'SEEN'; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for fixing this! |
||
|
|
||
| public function getFolder(): string | ||
| { | ||
| return $this->folder; | ||
| } | ||
|
|
@@ -46,11 +54,13 @@ public function setYoungerThan(int $youngerThan) | |
| $this->youngerThan = $youngerThan; | ||
| } | ||
|
|
||
| public function setFlags($key,$value){ | ||
| public function setFlags($key,$value) | ||
| { | ||
| $this->flags[$key] = $value; | ||
| } | ||
|
|
||
| public function getFlags(){ | ||
| public function getFlags() | ||
| { | ||
| return $this->flags; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a space between
$query,'INBOX'Also could you put the comment at the start of the line above? That will be easier to read, else there will be a scrollbar on GitHub.