Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47097 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67862 invoked from network); 10 Mar 2010 03:45:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Mar 2010 03:45:07 -0000 Received: from [127.0.0.1] ([127.0.0.1:25495]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id B8/50-64184-3C5179B4 for ; Tue, 09 Mar 2010 22:45:07 -0500 X-Host-Fingerprint: 143.166.197.6 unknown Received: from [143.166.197.6] ([143.166.197.6:15332] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C7/00-64184-72B079B4 for ; Tue, 09 Mar 2010 21:59:51 -0500 To: internals@lists.php.net Message-ID: <4B970964.6000909@Dell.com> Date: Tue, 09 Mar 2010 20:52:20 -0600 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 CC: Charles_Duffy@dell.com Content-Type: multipart/mixed; boundary="------------090605070204000808060208" X-Posted-By: 143.166.197.6 Subject: [PATCH] Implementation of #35638 [include update timestamp in imap overview data] From: Charles_Duffy@Dell.com (Charles Duffy) --------------090605070204000808060208 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit imap_fetch_overview() presently does not include any information on when the remote store has last been updated. Not having this information can force IMAP clients to make more requests than should strictly be necessary, and a ticket requesting it has been open since 2006. (As an aside -- my employer's predecessor-in-interest developed a patch for this issue internally in 2004, but failed to file a ticket or report the issue upstream; unfortunately, I've been unable to track down the (ir)responsible party to give them a good yelling-at). Unlike the version attached in the bugtracker (which is presently down), this one updates the test suite, and also reduces a bit of code duplication between the various imap_fetch_overview_* tests. If any further updates would be necessary to help this patch be promptly adopted, please let me know. Thank you kindly! --------------090605070204000808060208 Content-Type: text/x-patch; name="php-imap-udate-r2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="php-imap-udate-r2.patch" diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 5e47510..5432d84 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -3420,6 +3420,7 @@ PHP_FUNCTION(imap_fetch_overview) add_property_long(myoverview, "deleted", elt->deleted); add_property_long(myoverview, "seen", elt->seen); add_property_long(myoverview, "draft", elt->draft); + add_property_long(myoverview, "udate", mail_longdate(elt)); add_next_index_object(return_value, myoverview TSRMLS_CC); } } diff --git a/ext/imap/tests/imap_fetch_overview_basic.phpt b/ext/imap/tests/imap_fetch_overview_basic.phpt index 2b4623f..83fab12 100644 --- a/ext/imap/tests/imap_fetch_overview_basic.phpt +++ b/ext/imap/tests/imap_fetch_overview_basic.phpt @@ -23,28 +23,11 @@ $stream_id = setup_test_mailbox('', 2, $mailbox, 'notSimple'); $msg_no = imap_uid($stream_id, 1); $options = FT_UID; -//Set mandatory response fields -$mandatoryFields = array( - 'size', - 'uid', - 'msgno', - 'recent', - 'flagged', - 'answered', - 'deleted', - 'seen', - 'draft', - ); - // Calling imap_fetch_overview() with all possible arguments echo "\n-- All possible arguments --\n"; $a = imap_fetch_overview($stream_id, "$msg_no", $options) ; echo "\n--> Object #1\n"; -foreach ($mandatoryFields as $mf) -{ - $z = $a[0]->$mf; - echo "$mf is $z\n"; -} +displayOverviewFields($a[0]); // Calling imap_fetch_overview() with mandatory arguments echo "\n-- Mandatory arguments --\n"; @@ -52,19 +35,11 @@ $a = imap_fetch_overview($stream_id, '1:2') ; //first object in array echo "\n--> Object #1\n"; -foreach ($mandatoryFields as $mf) -{ - $z = $a[0]->$mf; - echo "$mf is $z\n"; -} +displayOverviewFields($a[0]); //Second object in array echo "\n--> Object #2\n"; -foreach ($mandatoryFields as $mf) -{ - $z = $a[1]->$mf; - echo "$mf is $z\n"; -} +displayOverviewFields($a[1]); imap_close($stream_id); @@ -91,6 +66,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK -- Mandatory arguments -- @@ -104,6 +80,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK --> Object #2 size is %d @@ -115,4 +92,5 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK ===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_variation2.phpt b/ext/imap/tests/imap_fetch_overview_variation2.phpt index 8634cef..086885f 100644 --- a/ext/imap/tests/imap_fetch_overview_variation2.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation2.phpt @@ -22,20 +22,6 @@ require_once(dirname(__FILE__).'/imap_include.inc'); // Initialise function arguments not being substituted $stream_id = setup_test_mailbox('', 1, $mailbox, 'notSimple'); // set up temp mailbox with 1 msg -//Set mandatory response fields -$mandatoryFields = array( - 'size', - 'uid', - 'msgno', - 'recent', - 'flagged', - 'answered', - 'deleted', - 'seen', - 'draft', - ); - - //get an unset variable $unset_var = 10; unset ($unset_var); @@ -114,11 +100,7 @@ foreach($inputs as $input) { if (!$overview) { echo imap_last_error() . "\n"; } else { - foreach ($mandatoryFields as $mf) - { - $z = $overview[0]->$mf; - echo "$mf is $z\n"; - } + displayOverviewFields($overview[0]); } $iterator++; }; @@ -151,6 +133,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK -- Testing with second argument value: int(12345) Sequence out of range @@ -189,6 +172,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK -- Testing with second argument value: bool(false) Sequence out of range @@ -203,6 +187,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK -- Testing with second argument value: bool(false) Sequence out of range diff --git a/ext/imap/tests/imap_fetch_overview_variation5.phpt b/ext/imap/tests/imap_fetch_overview_variation5.phpt index d5bc888..5feeedb 100644 --- a/ext/imap/tests/imap_fetch_overview_variation5.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation5.phpt @@ -22,19 +22,6 @@ require_once(dirname(__FILE__).'/imap_include.inc'); $stream_id = setup_test_mailbox('', 3, $mailbox, 'notSimple'); // set up temp mailbox with 3 msgs -//Set mandatory response fields -$mandatoryFields = array( - 'size', - 'uid', - 'msgno', - 'recent', - 'flagged', - 'answered', - 'deleted', - 'seen', - 'draft', - ); - $sequences = array (0, 4, '4', // out of range '2', '1,3', '1, 2', '1:3'); // pass uid without setting FT_UID option @@ -47,11 +34,7 @@ foreach($sequences as $msg_no) { } else { foreach($overview as $ov) { echo "\n"; - foreach ($mandatoryFields as $mf) - { - $z = $ov->$mf; - echo "$mf is $z\n"; - } + displayOverviewFields($ov); } } } @@ -89,6 +72,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK -- $msg_no is 1,3 -- @@ -101,6 +85,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK size is %d uid is %d @@ -111,6 +96,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK -- $msg_no is 1, 2 -- Syntax error in sequence @@ -126,6 +112,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK size is %d uid is %d @@ -136,6 +123,7 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK size is %d uid is %d @@ -146,4 +134,5 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK ===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_variation6.phpt b/ext/imap/tests/imap_fetch_overview_variation6.phpt index 6ee65f6..bdf0557 100644 --- a/ext/imap/tests/imap_fetch_overview_variation6.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation6.phpt @@ -22,30 +22,13 @@ require_once(dirname(__FILE__).'/imap_include.inc'); $stream_id = setup_test_mailbox('', 0, $mailbox); // setup temp mailbox create_multipart_message($stream_id, $mailbox); -//Set mandatory response fields -$mandatoryFields = array( - 'size', - 'uid', - 'msgno', - 'recent', - 'flagged', - 'answered', - 'deleted', - 'seen', - 'draft', - ); - // refresh msg numbers imap_check($stream_id); $msg_no = 1; $a = imap_fetch_overview($stream_id, $msg_no); echo "\n--> Object #1\n"; -foreach ($mandatoryFields as $mf) -{ - $z = $a[0]->$mf; - echo "$mf is $z\n"; -} +displayOverviewFields($a[0]); @@ -122,4 +105,5 @@ answered is 0 deleted is 0 seen is 0 draft is 0 +udate is OK ===DONE=== diff --git a/ext/imap/tests/imap_include.inc b/ext/imap/tests/imap_include.inc index 3f98454..ed36239 100644 --- a/ext/imap/tests/imap_include.inc +++ b/ext/imap/tests/imap_include.inc @@ -9,10 +9,56 @@ $password = 'p4ssw0rd'; $users = array("webmaster", "info", "admin", "foo"); // tests require 4 valid userids $mailbox_prefix = "phpttest"; // name used for test mailbox +// record test start time (used by displayOverviewFields()) +$start_time = time(); + +// list of fields to expect +$mandatory_overview_fields = array( + 'size', + 'uid', + 'msgno', + 'recent', + 'flagged', + 'answered', + 'deleted', + 'seen', + 'draft', + 'udate', + ); + +/** + * Display all fields in an element from an imap_fetch_overview() response + * + * Special handling for 'udate', which will vary run-to-run; assumes an IMAP + * server with its clock synced to the current system, which is consistent with + * setup instructions in ext/imap/tests/README + * + * @param array resp element from the return value of imap_fetch_overview() + */ +function displayOverviewFields($resp, $fields=null) { + global $mandatory_overview_fields; + global $start_time; + + foreach ($fields ? $fields : $mandatory_overview_fields as $mf) + { + $z = $resp->$mf; + if ($mf == 'udate') { + if (($z >= $start_time) && ($z <= time())) { + echo "$mf is OK\n"; + } else { + echo "$mf is BAD ($z)\n"; + } + } else { + echo "$mf is $z\n"; + } + } +} + + /** * Create a test mailbox and populate with msgs * - * @para, string mailbox_suffix Suffix used to uniquely identify mailboxes + * @param string mailbox_suffix Suffix used to uniquely identify mailboxes * @param int message_count number of test msgs to be written to new mailbox * * @return IMAP stream to new mailbox on sucesss; FALSE on failure --------------090605070204000808060208--