-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
Moving a Mail removes original and creates a copy of another, old message #29
Comments
Okay, tried it on another mail server and got the same behavior... // message uid is = 2800
// Folder *INBOX* has 'uidnext' = 2801
// Folder *my/target* has 'uidnext' = 496
$next_uid = $status["uidnext"];
[...]
$message_num = $this->client->getConnection()->getMessageNumber($next_uid);
//after this step the imap server responds with another message this results in a I have no idea why this happens, my best guess is that my mailservers behave somehow different than yours, so the uid_next is not set while copying a message? I have no clue at all 😢 |
I can move mails with this, recieveing the copy still fails...: ImapProtocol.php added this function public function moveTobbel($folder, $from, $to = null) {
\Log::debug(print_r(['folder' => $folder, 'from' => $from,'to' => $to], true));
$set = (int)$from;
if ($to !== null) {
$set .= ':' . ($to == INF ? '*' : (int)$to);
}
\Log::debug(print_r(['set' => $set], true));
\Log::debug(print_r(['requestAndResponse' => ['MOVE', [$set, $this->escapeString($folder)], true]], true));
return $this->requestAndResponse('MOVE', [$set, $this->escapeString($folder)], true);
} Message.php added also a moveTobbel and altered the public function moveTobbel($folder) {
$folder = $this->client->getFolder($folder);
$copy = $this->client->getConnection()->moveTobbel($folder->path, $this->msgn);
\Log::debug(print_r(['move tobbel' => $copy], true));
if (is_array($copy) && (stripos($copy[0], "ok")) !== false) {
//preg_match('/.*OK.*\[(.*)\]/i', $copy[0], $matches);
preg_match('/.*OK.*\[(.*) (\d+)\]/i', $copy[0], $matches);
$response = $matches[2];
\Log::debug(print_r(['move tobbel - response' => $response], true));
$message_num = $this->client->getConnection()->getUid($response);
\Log::debug(print_r(['message_num' => $message_num], true));
$message = $folder->query()->getMessage($message_num);
// ------------ THIS FAILS *
$event = $this->getEvent("message", "copied");
$event::dispatch($this, $message);
return $message;
}
return $copy;
}
public function move($folder, $expunge = false) {
\Log::debug(print_r([ "message before copy" => ['message_no' => $this->message_no, 'msgn' => $this->msgn, 'msglist' => $this->msglist, 'uid' => $this->uid, 'folder_path' => $this->folder_path, 'message_id' => $this->header->message_id]], true));
$message = $this->moveTobbel($folder);
\Log::debug(print_r([ "message after moveTobbel" => $message], true));
return $message;
} *: in my target folder are about 140 messages, but the function getMessageNumber->getUid just fetches (exactly) 40 messages/uids - and that list does not contain my moved UID ... So the Fetch of that new message number fails .... |
Hi @DasTobbel , public function copy($folder_path) {
$this->client->openFolder($folder_path);
$status = $this->client->getConnection()->examineFolder($folder_path);
if (isset($status["uidnext"])) {
$next_uid = $status["uidnext"];
/** @var Folder $folder */
$folder = $this->client->getFolder($folder_path);
$this->client->openFolder($this->folder_path);
if ($this->client->getConnection()->copyMessage($folder->path, $this->msgn) == true) {
$this->client->expunge();
$this->client->openFolder($folder->path);
$message_num = $this->client->getConnection()->getMessageNumber($next_uid);
$message = $folder->query()->getMessage($message_num);
$event = $this->getEvent("message", "copied");
$event::dispatch($this, $message);
return $message;
}
}
return null;
} ..and try again. Best regards, |
P.s.: you are correct there might also be a Adding the following in public function moveMessage($folder, $from, $to = null) {
$set = (int)$from;
if ($to !== null) {
$set .= ':' . ($to == INF ? '*' : (int)$to);
}
return $this->requestAndResponse('MOVE', [$set, $this->escapeString($folder)], true);
} .. and using it directly should also work. The problem seemed to be that |
Hi @Webklex
I looked a bit into the rfc3501 but i did not find any hint or function suggestion pointing to that - but, if its working i'm not going to blame anyone ;-) Thank you for your effort and nice work with this! |
Describe the bug
While using the
$message->move("someFolder, true)
method i saw that the mail i wanted to move is deleted and in the target folder a old mail is duplicated.To Reproduce
Steps to reproduce the behavior:
I realy dont know if you can reproduce this, or if thats a "messed up" mail server ...
$message
$message
it to ( in my case nested ) folder: fromINBOX
tomy/target
Expected behavior
see Additional for context
The correct "next_uid" should be picked and actually copy the origin mail to the folder insted of copying another mail inside the target folder... Or at least thats what i think should happen, dont know the "COPY" command of imap - need to check it
Desktop / Server (please complete the following information):
Additional context
My logging:
src/Message.php :661
src/Connection/Protocols/ImapProtocol.php:799
The text was updated successfully, but these errors were encountered: