-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
problem with ->moveToFolder() and multiple moves #31
Comments
Hi @mundanet , Best regards |
HI @Webklex I have tested a solution:
in Message.php
and it is working. |
@Webklex |
It seems the problem is coming from calling I don't know if it is a bug, i.e. should have been PS; Thanks for the effort in creating and maintaining this library. I like the idea of having message and attachment objects. |
I'm having a similar problem. namespace App\Console\Commands;
use Illuminate\Console\Command;
use Webklex\IMAP\Client as ImapClient;
class ImapTest extends Command
{
protected $signature = 'ImapTest';
public function handle()
{
$oClient = new ImapClient([
'host' => 'imap.gmail.com',
'port' => 993,
'encryption' => 'ssl',
'validate_cert' => true,
'username' => env( 'EMAIL_USERNAME' ),
'password' => env( 'EMAIL_APP_PASSWORD' ),
'protocol' => 'imap'
]);
$folder = $oClient->getFolder('INBOX');
/**
* @var \Webklex\IMAP\Support\MessageCollection $messages
*/
$messages = $folder->messages()->limit(1)->get();
/**
* @var \Webklex\IMAP\Message $message
*/
foreach( $messages as $message ) {
$message->moveToFolder('processing');
sleep(5);
$message->moveToFolder('review');
}
}
} |
@gareth-ib Use I think after moving the message to the processing folder, you could reload the message object (as it likely will be referencing the message in the initial folder) before moving to the review folder or you could call Either way, checking imap errors should help you identify the problem. |
I tried your idea... $message->moveToFolder('processing');
sleep(5);
$oClient->expunge();
$message->moveToFolder('review');
$error = imap_last_error();
dump($error);
$oClient->expunge();
$message->move('review');
$error = imap_last_error();
dump($error); and got...
with the email still sitting in the |
Comment out I fixed the issue I was having with lost connection by commenting that code out. I don't think a call to /**
* Move the Message into an other Folder
* @param string $mailbox
*
* @return bool
* @throws Exceptions\ConnectionFailedException
*/
public function moveToFolder($mailbox = 'INBOX') {
//$this->client->createFolder($mailbox); /*Todo: Reference: https://github.com/Webklex/laravel-imap/issues/31*/
return imap_mail_move($this->client->getConnection(), $this->uid, $mailbox, CP_UID);
} |
with the
and the mail is still in the |
Hi @gareth-ib , You might also want to update to the latest version or perhaps the master for futher investigation :) Best regards |
@Webklex ok I apparently was on 1.2, so I upgraded to 1.4... no prefix...
|
Hi @gareth-ib, The MessageID or UID changes by moving the message. Therefore it wasn't possible to move the same Message/UID again. The provided patch does exactly that. Please give the current master version a try. If it works as expected I will release a new version :) Best regards |
okay I've got it updated... - Removing webklex/laravel-imap (1.4.0)
- Installing webklex/laravel-imap (dev-master 6990abb): Downloading (100%) and the code... $message->moveToFolder('processing');
sleep(5);
$oClient->expunge();
$message->moveToFolder('review');
$error = imap_last_error();
dump($error);
$oClient->expunge();
$message->move('review');
$error = imap_last_error();
dump($error); output ( same result if I remove the
|
this is on Gmail by the way, if that helps |
Remember Message::moveToFolder() returns the new Message (the moved instance). The old instance is now no longer valid. echo "message UID: ".$message->uid."\n";
$processing_message = $message->moveToFolder('processing', true, false);
sleep(5);
if($processing_message !== null){
echo "processing UID: ". $processing_message->uid."\n";
$review_message = $processing_message->moveToFolder('review', true, false);
if($review_message !== null){
echo "review UID: ". $review_message->uid."\n";
}else{
dd(imap_last_error());
}
}else{
dd(imap_last_error());
} Best regards |
I added an echo into the if($status === true){
if($expunge) $this->client->expunge();
echo __LINE__.':'.$target_status->uidnext."\n";
return $target_folder->getMessage($target_status->uidnext);
} and ran the code... $movedMessage = $message->moveToFolder('processing');
dd($movedMessage);
sleep(5);
$movedMessage->moveToFolder('review'); and the result is... 967:15
null |
And if you use this it's still $movedMessage = $message->moveToFolder('processing', true, false); By the way do you do anything else with |
yeah ran it with your demo test code and the result is...
|
oh no I don't do anything to the $message before the move, it's just like the loop I posted originally |
I found an other issue when handling with multiple connections. This should get rid of it and finally solve your problem :) |
hooraayy! thanks! looks like it was a lot of changes! haha |
oh I confirmed it works btw :) |
found a problem with the returned message not having attachments like the orig message did. submitted PR #209 |
->moveToFolder() works perfectly when moving a single email in a single session.
But it fails to move correct emails when moving more than one email per session.
Debugging with xdebug I can confirm that the sequence numbers got confused when expunging messages.
I find the affirmations at the following link to be correct:
http://gabijack.com/moving-and-deleting-messages-with-php-imap/
May I request a fix?
The text was updated successfully, but these errors were encountered: