Webklex / php-imap

PHP-IMAP is a wrapper for common IMAP communication without the need to have the php-imap module installed / enabled. The protocol is completely integrated and therefore supports IMAP IDLE operation and the "new" oAuth authentication process as well.
https://www.php-imap.com
MIT License
309 stars 145 forks source link

Messages not moved with Courier IMAP #309

Open rmontagud opened 1 year ago

rmontagud commented 1 year ago

Describe the bug I have a server running Courier IMAP, deleting messages and sending an expunge works perfectly but because I'm required to keep the messages on the server, move them to a folder and let the customer delete them afterwards.

Code to Reproduce

            $folder->getClient()->getConnection()->enableDebug();
            $message = $folder->messages()->getMessage($msgid);
            if ($account->isImap()) {
                $message->move('INBOX'.$folder->delimiter.'procesados');
            } else {
                $message->delete();
            }

Expected behavior Move the message to the "processed" folder.

Desktop / Server (please complete the following information):

Here's the protocol exchange since the moment i'm trying to move the message:

>> TAG16 SELECT "INBOX.procesados"
<< * FLAGS (\Draft \Answered \Flagged \Deleted \Seen \Recent)
<< * OK [PERMANENTFLAGS (\* \Draft \Answered \Flagged \Deleted \Seen)] Limited
<< * 0 EXISTS
<< * 0 RECENT
<< * OK [UIDVALIDITY 664533991] Ok
<< * OK [MYRIGHTS "acdilrsw"] ACL
<< TAG16 OK [READ-WRITE] Ok
>> TAG17 EXAMINE "INBOX.procesados"
<< * FLAGS (\Draft \Answered \Flagged \Deleted \Seen \Recent)
<< * OK [PERMANENTFLAGS ()] No permanent flags permitted
<< * 0 EXISTS
<< * 0 RECENT
<< * OK [UIDVALIDITY 664533991] Ok
<< * OK [MYRIGHTS "acdilrsw"] ACL
<< TAG17 OK [READ-ONLY] Ok
>> TAG18 EXPUNGE
<< TAG18 NO Cannot expunge read-only mailbox.
>> TAG19 LOGOUT
<< * BYE Courier-IMAP server shutting down
<< TAG19 OK LOGOUT completed
Webklex commented 1 year ago

Hi @rmontagud , many thanks for your detailed report. This looks like the folder you are trying to move to is in a "read-only" mode: TAG18 NO Cannot expunge read-only mailbox.. At least that how I would read this error message. Can you move the message to a folder which isn't in "read-only" mode?

Best regards,

rmontagud commented 1 year ago

Hi @Webklex ,

I've tried to move the message using roundcube and i've been able to do it so it doesn't seem a read-only issue... i've changed the destination folder to "Drafts" in my code and the result is the same

>> TAG14 SELECT "INBOX.Drafts"
<< * FLAGS (\Draft \Answered \Flagged \Deleted \Seen \Recent)
<< * OK [PERMANENTFLAGS (\* \Draft \Answered \Flagged \Deleted \Seen)] Limited
<< * 0 EXISTS
<< * 0 RECENT
<< * OK [UIDVALIDITY 666948962] Ok
<< * OK [MYRIGHTS "acdilrsw"] ACL
<< TAG14 OK [READ-WRITE] Ok
>> TAG15 EXAMINE "INBOX.Drafts"
<< * FLAGS (\Draft \Answered \Flagged \Deleted \Seen \Recent)
<< * OK [PERMANENTFLAGS ()] No permanent flags permitted
<< * 0 EXISTS
<< * 0 RECENT
<< * OK [UIDVALIDITY 666948962] Ok
<< * OK [MYRIGHTS "acdilrsw"] ACL
<< TAG15 OK [READ-ONLY] Ok
>> TAG16 EXPUNGE
<< TAG16 NO Cannot expunge read-only mailbox.
>> TAG17 LOGOUT
<< * BYE Courier-IMAP server shutting down
<< TAG17 OK LOGOUT completed

After a google search I ended in a bugreport from MailKit where it seems that if you send the EXAMINE command the folder stays as read-only (which might match the answer to TAG15?).

Also, I've noticed $message->move('INBOX'.$folder->delimiter.'procesados'); returns null, so I suspect the actual MOVE command has not been sent at all because Message::move() cannot determine the "uidnext".