email - PHP IMAP library - Retrieving a limited list of messages from a mailbox -


i'm using php's built in imap functions build bare-bones webmail client (will used accessing gmail accounts). i've hit road block in mailbox list views, displaying paginated list of messages in mailbox sorted date (ascending or descending).

my initial implementation retrieved messages mailbox imap_headers() , sorted array based on date, returned segment of array corresponded current page of list user wanted view. worked ok mailboxes small number of messages performance decreased size of mailbox grew (for mailbox ~600 messages, execution time on average around 10 seconds). , of users of client, 600 messages small number mailbox, between 5 , 10 thousand messages in inbox.

so second stab @ problem instead of retrieving headers messages in mailbox, got total number of messages imap_num_msg() , using number constructed loop, loop counter used message number. , each iteration call imap_headerinfo() message number.

this works better, under impression message number corresponded directly when message recieved, message no. 1 oldest message, , number returned imap_num_msg() message number of newest message. using still provide sorting date within paginated list. after testing seems message number not correspond date recieved, , have no clue how assigned.

any or direction appreciated.

i have been playing , here snips of im doing, pagination working nice getting few mails per page. wont paste code, main parts. hope helps :)

// main method mails __getformattedbasics() calls imap_hearderinfo() loop runs backwards default newest first private function __getmails($model, $query) {             $pagination = $this->_figurepagination($query);              $mails = array();             ($i = $pagination['start']; $i > $pagination['end']; $i--) {                 $mails[] = $this->__getformattedbasics($model, $i);             }              unset($mail);              return $mails;         }  // uses current page number, limit per page , figures start/end loop above can sort in other direction passing asc/desc protected function _figurepagination($query) {             $count = $this->_mailcount($query); // total mails             $pages = ceil($count / $query['limit']); // total pages             $query['page'] = $query['page'] <= $pages ? $query['page'] : $pages; // dont let page more available pages              $return = array(                 'start' => $query['page'] == 1                     ? $count    // start @ end                     : ($pages - $query['page'] + 1) * $query['limit'], // start @ end - x pages             );              $return['end'] = $query['limit'] >= $count                 ? 0                 : $return['start'] - $query['limit'];              $return['end'] = $return['end'] >= 0 ? $return['end'] : 0;              if (isset($query['order']['date']) && $query['order']['date'] == 'asc') {                 return array(                     'start' => $return['end'],                     'end' => $return['start'],                 );             }              return $return;         }      private function __getformattedbasics($model, $message_id) {         $mail = imap_headerinfo($this->mailserver, $message_id);         $structure = imap_fetchstructure($this->mailserver, $mail->msgno);          $toname = isset($mail->to[0]->personal) ? $mail->to[0]->personal : $mail->to[0]->mailbox;         $fromname = isset($mail->from[0]->personal) ? $mail->from[0]->personal : $mail->from[0]->mailbox;         $replytoname = isset($mail->reply_to[0]->personal) ? $mail->reply_to[0]->personal : $mail->reply_to[0]->mailbox; 

....


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -