php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

Return $uid when adding post to imap

Open AnastasiaDolgopolova opened this issue 3 years ago • 1 comments

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

Снимок

AnastasiaDolgopolova avatar Dec 03 '21 07:12 AnastasiaDolgopolova

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,

Webklex avatar Jun 23 '23 23:06 Webklex