-
-
Notifications
You must be signed in to change notification settings - Fork 252
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
Added bulk set / clear flags functionality for mailbox messages #225
Conversation
src/Mailbox.php
Outdated
* Bulk Set Flag for Messages. | ||
* | ||
* @param $flag \Seen, \Answered, \Flagged, \Deleted, and \Draft | ||
* @param array Message numbers |
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.
It should be:
@param string $flag \Seen, \Answered, \Flagged, \Deleted, and \Draft
@param array $numbers Message numbers
Same rule goes for clearFlag
src/Mailbox.php
Outdated
{ | ||
$this->init(); | ||
|
||
$result = \imap_setflag_full($this->resource->getStream(), (string) \implode(',', $numbers), $flag, \ST_UID); |
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.
You can directly return the result.
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.
Return type of implode
is already a string, no need for the type casting
src/Mailbox.php
Outdated
{ | ||
$this->init(); | ||
|
||
$result = \imap_setflag_full($this->resource->getStream(), (string) \implode(',', $numbers), $flag, \ST_UID); |
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.
Return type of implode
is already a string, no need for the type casting
src/Mailbox.php
Outdated
@@ -120,6 +120,36 @@ public function getStatus(int $flags = null): \stdClass | |||
} | |||
|
|||
/** | |||
* Bulk Set Flag for Messages. | |||
* | |||
* @param $flag \Seen, \Answered, \Flagged, \Deleted, and \Draft |
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.
$flag param misses the string type
Hi, thank you for this PR.
The user can seamlessly write: $mailbox->setFlag('\\Seen', [
'1',
'2',
'3:10',
'11,12,15',
]); And the code would work as it's expected. But if I can write sequences by hand, what is the added benefit of requesting the parameter to be an array? $mailbox->setFlag('\\Seen', ['1,2,3:10,11,12,15']); Bypassing the check. The only benefit I see is we can save an |
tests/MailboxTest.php
Outdated
$this->assertFalse($message->isFlagged()); | ||
} | ||
|
||
$this->mailbox->setFlag('\\Flagged', \array_keys($messages)); |
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.
I've tested that creating the messages in different mailboxes and using the setFlag method on a random mailbox, the flags are changed to all the UIDs specificed because, as the name said, the flags are changed by UIDs regardless on the mailbox the mails are in.
As such I find misleading to have these two new methods in the Mailbox
class since they don't depend on it.
What about moving the code (and the test) to the Connection
?
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.
Check 189815a, UIDs are related with specific mailbox. Moving functionality to Connection
would require a mailboxName
parameter.
Can you rebase the PR please? |
6decb3a
to
c401737
Compare
@Slamdunk Done |
Hi, I have another API doubt. In the test you write: $message = $mailbox->getMessage('1');
var_dump($message->isSeen()); // True
$mailbox->clearFlag('\\Seen', '1');
$message = $mailbox->getMessage('1');
var_dump($message->isSeen()); // False And this works correctly because each $message = $mailbox->getMessage('1');
var_dump($message->isSeen()); // True
$mailbox->clearFlag('\\Seen', '1');
var_dump($message->isSeen()); // True The user can be fooled by reusing the same previous message, and this is because the internal Message cache was not cleared. As far as I can see, the only solution to this would be to couple Message instances to the Mailbox, calculate the sequence number provided to the new two methods and clear related caches: too complex, doesn't worth the effort. So lets go for an easier path: @wujku plese update the README.md Mailboxes chapter showing the new functionalities and add a warning about this edge behaviour that we are not going to address: the user must be aware of it and retrieve new Message instances if they want to set bulk flags and refresh the single Messages flags. |
Another thing: please don't squash the commits, only rebase it. Squash makes review code changes harder. I'll squash anyway the PR before merge. |
@Slamdunk What to do with the Scrutinizer error? I did nothing with composer packages. |
Just ignore it: look only at Travis, your PR is fine 👍 |
@wujku I'll mere this PR as soon as you commit and push the changes to README.md I underlined:
|
Thank you @wujku |
No description provided.