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
313 stars 145 forks source link

Move command dont work #357

Open GamerClassN7 opened 1 year ago

GamerClassN7 commented 1 year ago

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 image

Desktop / Server (please complete the following information):

Additional context none

eduardom456 commented 1 year ago

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.

Webklex commented 1 year ago

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,

GamerClassN7 commented 1 year ago

Hi sorry for delay @Webklex i already tried mentioned stuff :( no change i see parsed folder in list you suggested image

$newFolder = $client->getFolder("parsed")

Returns correct folder but it still fails on move

GamerClassN7 commented 1 year ago

@Webklex any idea what can be wrong ?

GamerClassN7 commented 1 year ago

you can create free mail box if you want to test it your self :) https://email.seznam.cz/

GamerClassN7 commented 1 year ago

Hi @Webklex any idea where is the problem ?