php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34289 IMAP uid and message number confusion
Submitted: 2005-08-28 16:24 UTC Modified: 2005-08-28 17:07 UTC
From: npeelman at cfl dot rr dot com Assigned:
Status: Not a bug Package: IMAP related
PHP Version: 4.4.0 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: npeelman at cfl dot rr dot com
New email:
PHP Version: OS:

 

 [2005-08-28 16:24 UTC] npeelman at cfl dot rr dot com
Description:
------------
IMAP_UID does not return correct information.

In relation to bugs (7486, 10850, 12954) which seem to be several years old, as of PHP4.3.4RC3-dev (I am developing GTK apps and this is the supplied version), also tested with PHP5.0.2:

There appears to be confusion as to the difference between 'Message No#' and 'Message-Id'.

Message No# is a temporary number and can change as messages are deleted and added. As an example: you have messages numbering from 1 - 5 and you delete number 3. You will now have a new number 3 and no number 5 as 4 becomes 3 and 5 becomes 4.

Message-Id is a unique id generated by the server and does not change over time. Technically speaking, no two messages generated from the same server should ever have the same Message-Id. This is stored withing the message headers.

Message No# is more of a general (read loose) pointer where-as Message-Id is more of a direct pointer to a specific message.

This appears to be a multi-part problem:

#1 imap_uid($imap_stream, $msg_no) returns (as an INT) the 'Message No#' as defined above. This is conflicting with the very definition of this command. We already know the Message No# as it is a required parameter to this function.

#2 The 'Message-Id' as defined in RFC822 is a STRING (possibly containing more than just numbers), not an INT. This automatically breaks 'imap_msgno($imap_stream, $uid), 'imap_body', and any other function that can accept Message-Id, as $uid is expected to be an INT by these functions, but is not.

#3 The following snippet will retrieve the Message-Id (uid) from the message $msg_no (Message No# as defined above) if it is present:

$header = imap_headerinfo($imap_stream, $msg_no);
return $header->message_id;

This returns a STRING as defined in RFC822 but is unusable by functions stated in #2 above.

Excerpt from BUG: #7486
[27 Oct 2000 3:30am CEST] rick at alpinenetworking dot com 
When I call connect to a qmail pop server and call imap_uid all it does
is return the message number back to me.  It DOES NOT return the uid.  I
have to call imap_header for that and it is very slow.

[3 May 2001 3:36pm CEST] chagenbu@php.net 
You might have the wrong idea of what uid is - what do you expect it to
be? On pop servers the message uid will very likely just _be_ the
message number...

[3 May 2001 5:14pm CEST] chagenbu@php.net 
From: "Rick Gigger" <rick@alpinenetworking.com>

All email messages have a unique identifier.  It is a long string that
ususally contains a domiain name or ip address.  It is unique to all
email addresses in the world.  It would be much, much more useful if
imap_uid
would return that instead.

[3 May 2001 5:16pm CEST] chagenbu@php.net 
That's the Message-ID header. The uid which imap_uid() is intended to
return is a unique identifier of that that message in that mailbox that
won't change over time. It has nothing to do with the Message-ID header.
---

As per this last message by chagenbu@php.net:
Huh? The Message-Id header IS the one that won't change over time, this entry contradicts itself and it IS the one that imap_uid should be intending to return. A thought to back this up is that you don't really need a function to determine a Message No# but you do need one to determine the Message-Id.


Reproduce code:
---------------
$imap = imap_open($mailbox,$user,$password);
$num_msgs = imap_num_msg($imap);
for ($loop = 1; $loop <= $num_msgs; $loop++)
{
   $uid = imap_uid($imap, $loop);
   echo "Message: $loop -> $uid \n\r";
   $header = imap_headerinfo($this->imap, $loop);
   echo "Msg UID: $loop -> $header->message_id \n\r";
   $body = imap_body($imap, $uid, FT_UID);
   echo "Msg body: \n\r $body \n\r\n\r";
}
 

Expected result:
----------------
For $num_msgs = 1:

Message: 1 -> <20050828021030.8587.errors-npeelman-cfl-rr-com@phpclasses.org>
Msg UID: 1 -> <20050828021030.8587.errors-npeelman-cfl-rr-com@phpclasses.org>
Msg body:
Message body here...


Actual result:
--------------
For $num_msgs = 1:

Message: 1 -> 1
Msg UID: 1 -> <20050828021030.8587.errors-npeelman-cfl-rr-com@phpclasses.org>
Msg body:
Warning: imap_body(): Bad message number in path:\to\source.php on line # (line containing imap_body() function)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-28 16:30 UTC] sniper@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2005-08-28 17:07 UTC] npeelman at cfl dot rr dot com
Please delete this bug report - posted in error.
npeelman@cfl.rr.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC