php-imap
php-imap copied to clipboard
Help needed moving a message "command not permitted with UID"
I'm trying to move a message to a different folder using the following code
$client = Client::account("default");
$client->connect();
/** @var \Webklex\PHPIMAP\Support\FolderCollection $folders */
$folder = $client->getFolder('INBOX');
if (empty($folder)) {
$this->error('Folder not found');
return 1;
}
$query = $folder->query()->since(now()->subDays(1))->limit(1)->get();
$query->each(function($message) use ($client) {
dump('before mvoe');
$message->move('INBOX/Ai-Parse/Legits');
die();
CleanInboxJob::dispatch($message);
});
But receive the following logs, and the message is not moved
"before mvoe" // app/Console/Commands/CleanInbox.php:44
>> TAG11 SELECT "INBOX/Ai-Parse/Legits"
<< * 0 EXISTS
<< * 0 RECENT
<< * OK [UIDVALIDITY 1002634] UIDs are valid for this mailbox
<< * OK [UIDNEXT 236772] next expected UID is 236772
<< * 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 1002634] modseq tracked on this mailbox
<< TAG11 OK [READ-WRITE] SELECT completed
>> TAG12 EXAMINE "INBOX/Ai-Parse/Legits"
<< * 0 EXISTS
<< * 0 RECENT
<< * OK [UIDVALIDITY 1002634] UIDs are valid for this mailbox
<< * OK [UIDNEXT 236772] next expected UID is 236772
<< * FLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $MDNSent Forwarded $Junk $NotJunk Junk JunkRecorded NonJunk NotJunk)
<< * OK [PERMANENTFLAGS ()] junk-related flags are not permanent
<< * OK [HIGHESTMODSEQ 1002634] modseq tracked on this mailbox
<< TAG12 OK [READ-ONLY] EXAMINE completed
>> TAG13 LIST "" "*"
<< * LIST (\HasNoChildren \Drafts) "/" "Drafts"
<< * LIST (\HasChildren) "/" "INBOX"
<< * LIST (\HasChildren) "/" "INBOX/Ai-Parse"
<< * LIST (\HasNoChildren) "/" "INBOX/Ai-Parse/Legit"
<< * LIST (\HasNoChildren) "/" "INBOX/Ai-Parse/Legits"
<< * LIST (\HasNoChildren) "/" "INBOX/Ai-Parse/Spam"
<< * LIST (\NoInferiors \Junk) "/" "Junk"
<< * LIST (\HasNoChildren) "/" "Lions"
<< * LIST (\HasChildren) "/" "Mailspring"
<< * LIST (\HasNoChildren) "/" "Mailspring/Snoozed"
<< * LIST (\HasNoChildren \Sent) "/" "Sent"
<< * LIST (\HasNoChildren \Trash) "/" "Trash"
<< TAG13 OK LIST completed
>> TAG14 SELECT "INBOX"
<< * 42858 EXISTS
<< * 0 RECENT
<< * OK [UNSEEN 9998] mailbox contains unseen messages
<< * OK [UIDVALIDITY 1] UIDs are valid for this mailbox
<< * OK [UIDNEXT 236769] next expected UID is 236769
<< * FLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $MDNSent Forwarded $Junk $NotJunk Junk JunkRecorded NonJunk NotJunk $MailFlagBit0)
<< * OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $MDNSent Forwarded $MailFlagBit0 \*)] junk-related flags are not permanent
<< * OK [HIGHESTMODSEQ 1002654] modseq tracked on this mailbox
<< TAG14 OK [READ-WRITE] SELECT completed
>> TAG15 UID MOVE 236730 "INBOX/Ai-Parse/Legits"
<< TAG15 BAD parse error: command not permitted with UID
>> TAG16 LOGOUT
<< * BYE zcsnocm105.telenet-ops.be Zimbra IMAP4rev1 server closing connection
<< TAG16 OK LOGOUT completed
command not permitted with UID=> is this an issue in the package, my code, or my email provider?, I'm using IMAP (not pop or other ones)
We have the same issue with our Zimbra server. Currently we solve it by using copy & delete (instead of move) and also catching the exception 'no headers found':
try {
# For unknown reason, after copying, php-imap fetch the header of the copied mail which fails.
$message->copy('targetfolder');
} catch (\Exception $e) {
if($e->getMessage() !='no headers found') {
throw new Exception("Error moving message: " . $e->getMessage() );
}
}
$message->delete();