Webklex / laravel-imap

Laravel IMAP is an easy way to integrate both the native php-imap module and an extended custom imap protocol into your Laravel app.
https://www.php-imap.com
MIT License
617 stars 177 forks source link

Error when copying a message. #489

Open aon4o opened 5 months ago

aon4o commented 5 months ago

Describe the bug I'm developing a Mail Importer artisan command in a Laravel app. I'm using Zimbra as a mail server and the IMAP protocol to connect to it. At first glance, it looks like it's working. I'm connecting to the mailbox, getting the wanted folder, parsing the mails, etc. But when I have to move the parsed message to another folder, there comes a problem: The Zimbra server uses an IMAP version that doesn't support the MOVE instruction. I thought that if I could use the MOVE, I could use copy & delete.

That worked, the message is copied to the correct folder, but for some reason, the library throws an error and I can't understand why.

The Exception I get is:

   Webklex\PHPIMAP\Exceptions\ResponseException 

  Command failed to process:
Causes:
        - Empty response
Commands send:
        TAG17 UID FETCH 639 (FLAGS)\r\n
Responses received:
        TAG17 OK UID FETCH completed\r\n
Error occurred

  at vendor/webklex/php-imap/src/Exceptions/ResponseException.php:53
     49▕         foreach($response->getStack() as $_response) {
     50▕             $exception = self::make($_response, $debug, $exception);
     51▕         }
     52▕ 
  ➜  53▕         return new self($message."Error occurred", 0, $exception);
     54▕     }
     55▕ 
     56▕     /**
     57▕      * Generate a debug message containing all commands send and responses received

      +7 vendor frames 

  8   modules/Tickets/Console/ImportMails.php:240
      Webklex\PHPIMAP\Message::copy()
      +1 vendor frames 

  10  modules/Tickets/Console/ImportMails.php:194
      Illuminate\Console\Command::withProgressBar()

The strange thing for me is that the response says OK. Isn't that what should happen?

I have enabled the debug mode and it shows as follows:

>> TAG15 UID COPY 639 "Processed"

<< TAG15 OK [COPYUID 61 639 640] UID COPY completed
>> TAG16 SELECT "Processed"

<< * 2 EXISTS
<< * 1 RECENT
<< * OK [UIDVALIDITY 61] UIDs are valid for this mailbox
<< * OK [UIDNEXT 641] next expected UID is 641
<< * FLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $MDNSent Forwarded $Junk $NotJunk Junk JunkRecorded NonJunk NotJunk)
<< * OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $MDNSent Forwarded \*)] junk-related flags are not permanent
<< * OK [HIGHESTMODSEQ 1393] modseq tracked on this mailbox
<< TAG16 OK [READ-WRITE] SELECT completed
>> TAG17 UID FETCH 639 (FLAGS)

<< TAG17 OK UID FETCH completed
--------------------------------------- Here the exception happens --------------------------------------------------------------
>> TAG18 LOGOUT

<< * BYE mail.delta.bg Zimbra IMAP4rev1 server closing connection
<< TAG18 OK LOGOUT completed

Siplified version of the code I use:

$mail_client = MailHelper::getMailbox($department);

$processed_folder = $mail_client->getFolder('Processed');
if (empty($folder)) {
    $processed_folder = $mail_client->createFolder('Processed');
}

foreach ($inbox_folder->messages()->all()->get() as $message) {
    // Message parsing...

    $message->copy($processed_folder->path);
    $message->delete();
}

Desktop: