php-imap
php-imap copied to clipboard
Return $uid when adding post to imap
Could you please add $uid return when adding post to imap
Return $uid after $folder->appendMessage( $message, NULL, $ date);
Now I do it like this
Hi @AnastasiaDolgopolova , many thanks for your question. Unfortunately the uid isn't returned by the server. So there is no way of actually returning it. However, you could try something like this, if you are okay with it not being 100% precise:
$status = $folder->select();
if (!isset($status['uidnext'])) {
$this->fail("No UIDNEXT returned");
}
$response = $folder->appendMessage($message);
$valid_response = false;
foreach ($response as $line) {
if (str_starts_with($line, 'OK')) {
$valid_response = true;
break;
}
}
if (!$valid_response) {
die("Failed to append message: ".implode("\n", $response));
}
$message = $folder->messages()->getMessageByUid($status['uidnext']);
Best regards and happy coding,