SSilence / php-imap-client

a easy solution for simple IMAP email access in php
MIT License
268 stars 136 forks source link

getMessages() marks all messages as read. #161

Closed abdullahseba closed 7 years ago

abdullahseba commented 7 years ago

Hi getMessages() retrieves all the messages and marks them as read. So on the first run it will return the message as unread before marking it as read. So while I load this page which uses getMessages() I can see the messages been marked as read one by one in outlooks web app. image image

techie42 commented 7 years ago

The issue is the "imap_fetchbody" call in the "imapFetchbody" function in file "IncomingMessage.php", around line 506. According to the docs on php.net, FT_PEEK should be added as an option on the call in order to preserve the read status when fetching the message body. If FT_PEEK is not used, then imap_fetchbody will change the read status to SEEN.

For example, if I modify the original code to this:

return imap_fetchbody($this->imapStream, $this->id, $section, FT_PEEK);

Then, the issue disappears :)

mattparksjr commented 7 years ago

Thank you. I will add this as well as a comment so other devs know

techie42 commented 7 years ago

Thank you very much :) Great response. This library makes life so much easier :)

mattparksjr commented 7 years ago

Your welcome! I have just commited the update. Let me know if you have any other problems :)

abdullahseba commented 7 years ago

Cant try cuz of #163 :(

mattparksjr commented 7 years ago

Yes, I am working on this as we speak. I plan to have this fixed by today

abdullahseba commented 7 years ago

Yep it works :)

mattparksjr commented 7 years ago

:)