php-imap
php-imap copied to clipboard
Move command dont work
Describe the bug I am unable to move email to folder over imap
Used config default
Code to Reproduce The troubling code section which produces the reported bug.
$client = Client::make([
'host' => $imapSetting['tasks.imap_host'],
'port' => $imapSetting['tasks.imap_port'],
'encryption' => 'ssl',
'validate_cert' => true,
'username' => $imapSetting['tasks.imap_username'],
'password' => $imapSetting['tasks.imap_password'],
'protocol' => 'imap'
]);
$client->connect();
$unseenEmails = $client->getFolder("INBOX")->messages()->unseen()->get();
$this->error(count($unseenEmails) . "unseenEmails");
file_put_contents(storage_path('logs/scheduler.log'), count($unseenEmails) . "unseenEmails" . "\n", FILE_APPEND);
foreach ($unseenEmails as $email) {
$email->unsetFlag('SEEN');
$client->expunge();
dump($client->getFolder("parsed"));
if ($email->move($client->getFolder("parsed")->path) == true) {
echo 'Message has been moved';
} else {
echo 'Message could not moved';
}
}
$client->disconnect();
Expected behavior folder to be moved to folder
Screenshots

Desktop / Server (please complete the following information):
- OS: ubuntu 20
- PHP: [8.1.0
- Version latest
- Provider [e.g. Gmail, Outlook, Dovecot]
Additional context none
Maybe the destination folder name isn't just "parsed", but maybe something like "INBOX/parsed".
Use the command
$folders = $client->getFolders();
To list all folders in the email, and confirm the name of the folder in question.
Hi @GamerClassN7 , please try to specify the issue you are facing. If you are receiving an exception please share it with us :)
Please try to "fetch" the folder before, in order to reduce your load and in order to verify that it does indeed exist:
$newFolder = $client->getFolder("INBOX/parsed")
If this folder doesn't exists, please try to use a different delimiter such as "." instead:
$newFolder = $client->getFolder("INBOX.parsed")
Afterwards you can verify if your folder exist and perhaps create it if it doesn't:
if ($newFolder == null) {
// Create new folder
}
I hope this will help you solve the issue :)
Best regards & happy coding,
Hi sorry for delay @Webklex i already tried mentioned stuff :( no change i see parsed folder in list you suggested

$newFolder = $client->getFolder("parsed")
Returns correct folder but it still fails on move
@Webklex any idea what can be wrong ?
you can create free mail box if you want to test it your self :) https://email.seznam.cz/
Hi @Webklex any idea where is the problem ?