php.net |  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
Votes:6
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
40 - 20 = ?
Subscribe to this entry?

 
 [2013-07-10 00:50 UTC] MQuinlan at cox dot net
Description:
------------
Almost no imap call should use the msg_no.
This is way to risky on a really fast running imap server.
The calls:
imap_append
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:
http://stackoverflow.com/questions/16827028/php-imap-get-uid-after-using-imap-append-to-add-sent-mail-to-imap-mailbox

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);
imap_append($imapStream,$imapPath,$mail->getMailString(),"\\Seen");
$check = imap_check($imapStream);
$uid=imap_uid($imapStream,$check->Nmsgs);
imap_close($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.
 



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-31 03:37 UTC] reeze@php.net
-Package: Scripting Engine problem +Package: IMAP related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC