email - How to limit result on php-imap -


i'm getting mails php-imap using php-imap-client, script work without problems want limit number of mails server.

this script:

<?php  require_once "imap.php";  $mailbox = 'imap-mail.outlook.com'; $username = 'myemail@outlook.it'; $password = 'mypassword'; $encryption = 'ssl'; // or ssl or ''  // open connection $imap = new imap($mailbox, $username, $password, $encryption);  // stop on error if($imap->isconnected()===false)     die($imap->geterror());  // folders array of strings $folders = $imap->getfolders(); foreach($folders $folder)     echo $folder;  // select folder inbox $imap->selectfolder('inbox');  // count messages in current folder $overallmessages = $imap->countmessages(); $unreadmessages = $imap->countunreadmessages();  // fetch messages in current folder $emails = $imap->getmessages($withbody = false); var_dump($emails);  // add new folder archive $imap->addfolder('archive');  // move first email archive $imap->movemessage($emails[0]['id'], 'archive');  // delete second message $imap->deletemessage($emails[1]['id']); 

the script i'm using: https://github.com/ssilence/php-imap-client

how can it?

looking @ descriptions, functions not seem have way limit number of messages collected since use id of message , not general count. reason, may have varied list of ids. take example dump, have id 15 , id 14. next 1 in list id 10 user may have deleted 13, 12, , 11.

so can collect initial list, , iterate on $imap->getmessage($id); this:

$overallmessages = $imap->countmessages(); $unreadmessages = $imap->countunreadmessages();  $limitcount = 20; $partialemailidlist = array();  // fetch messages in current folder $emails = $imap->getmessages($withbody = false);  if($limitcount < $overallmessages){     for($i=0; $i<$limitcount; $++){         // populate array ids         $partialemailidlist[] = $emails[$i]['id'];     } } else {     foreach($emails $email){         $partialemailidlist[] = $email['id'];     } } foreach($partialemailidlist $mid){         $message = $imap->getmessage($mid);         // stuff... } 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -