|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65231 imap_append needs to return msg_imap_uid
Submitted: 2013-07-10 00:50 UTC Modified: 2013-07-31 03:37 UTC
Avg. Score:4.3 ± 1.5
Reproduced:5 of 6 (83.3%)
Same Version:2 (40.0%)
Same OS:3 (60.0%)
From: MQuinlan at cox dot net Assigned:
Status: Open Package: IMAP related
PHP Version: 5.4.17 OS: CentOS/All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-07-10 00:50 UTC] MQuinlan at cox dot net
Almost no imap call should use the msg_no.
This is way to risky on a really fast running imap server.
The calls:
imap_delete ( resource $imap_stream , int $msg_number [, int $options = 0 ] )

are taking a terrible chance the mailbox order hasn't changed from deletes, writes, new mail, etc. on the imap server.  the imap msg_uid is a much safer course to get the correct msg to delete or modify.

Adding a return field msg_uid to imap_append is needed to correct this problem.

The following article at stackoverflow illustrates this problem:
You can read it here:

It states:

PHP IMAP get uid after using imap append to add sent mail to imap mailbox

Id like to get the message uid for the message i appended. Here is the code, which is untested and am sure is wrong:
$imapStream = imap_open($imapPath,$imapUser,$imapPass);
$check = imap_check($imapStream);

Basically, what I do after the imap_append call is run an imap_check to get the message count, then i pass the message count into the imap_uid to get the message uid. This can't possibly be right, but this is the first time I've worked with imap and Im just trying to figure this out.

Any help would be greatly appreciated.

php imap 


asked May 30 at 2:32 




Nope, this is wrong -- you have a race condition in there which you will hit if another message arrives between the time you've APPENDed the message and the time you consult the number of messages.

You might want to use the UIDPLUS IMAP extension, if available, and consult the APPENDUID response code. If this is not available for some reason, your most reliable bet is sending a UID SEARCH command with one condition, a HEADER match for the Message-Id header of the message you've just appended. If you get none or more than one UIDs back, then you're screwed.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-31 03:37 UTC]
-Package: Scripting Engine problem +Package: IMAP related
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 11:01:28 2024 UTC