From 08efcf7d20b96378c0eebe39c04d44c6e81c1de8 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Thu, 14 Aug 2014 07:38:32 +0000 Subject: [PATCH] Backport commit r48041, committed by Nathan Gray. Some more speed improvements for get_rows: - Specify & cache headers we want instead of reading all headers --- .../inc/class.emailadmin_imapbase.inc.php | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/emailadmin/inc/class.emailadmin_imapbase.inc.php b/emailadmin/inc/class.emailadmin_imapbase.inc.php index 38454ed228..82aa87259b 100644 --- a/emailadmin/inc/class.emailadmin_imapbase.inc.php +++ b/emailadmin/inc/class.emailadmin_imapbase.inc.php @@ -1364,10 +1364,18 @@ class emailadmin_imapbase $uidsToFetch->add($sortResult); $fquery = new Horde_Imap_Client_Fetch_Query(); - // as we need the prio, we are not using the Envelope (which is not providing it) - // fetching both headers and envelope takes too much time - $fquery->headerText(array('peek'=>true)); // needed for getHeaderText; needed for X-Priority - //$fquery->envelope(); + + // Pre-cache the headers we want, 'fetchHeaders' is a label into the cache + $fquery->headers('fetchHeaders',array( + 'DISPOSITION-NOTIFICATION-TO','RETURN-RECEIPT-TO','X-CONFIRM-READING-TO', + 'DATE','SUBJECT','FROM','TO','CC', + 'X-PRIORITY' + ),array( + // Cache headers, we'll look at them below + 'cache' => true, + // Set peek so messages are not flagged as read + 'peek' => true + )); $fquery->size(); $fquery->structure(); $fquery->flags(); @@ -1405,9 +1413,9 @@ class emailadmin_imapbase $headerObject['MSG_NUM'] = $_headerObject->getSeq(); $headerObject['SIZE'] = $_headerObject->getSize(); $headerObject['INTERNALDATE'] = $_headerObject->getImapDate(); - // as we need the prio, we are not using the Envelope (which is not providing it) - // fetching both headers and envelope takes too much time - $headerForPrio = array_change_key_case($_headerObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER); + + // Get already cached headers, 'fetchHeaders' is a label matchimg above + $headerForPrio = array_change_key_case($_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER); //error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio)); if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) { $headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));