-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fMailbox - Get latest emails #188
Comments
Let me know if you need a patch. |
found this solution, works pretty good fMailbox.php public function listMessages($limit=NULL, $page=NULL, $order='newest') Add this to IMAP and POP function inside listMessages $total_messages = 0;
$response = $this->write('STATUS "'.$folder.'" (MESSAGES)');
foreach ($response as $line) {
if (preg_match('#^\s*\*\s+STATUS\s+"?'.$folder.'"?\s+\((.*)\)$#', $line, $match)) {
$details = self::parseResponse($match[1], TRUE);
$total_messages = $details['messages'];
}
}
if (!$limit) {
$start = 1;
$end = '*';
} else {
if (!$page) {
$page = 1;
}
if ($order == 'newest') {
$start = $total_messages - $limit * $page + 1;
$end = $start + $limit - 1;
} else {
$start = ($limit * ($page-1)) + 1;
$end = $start + $limit - 1;
}
} and just above the return $output, add this if ($order == 'newest') {
arsort($output);
} if you try it out, please tell us how the performance was, I'm grabbing 10 emails from a inbox with 4000 messages in 1 second. |
@novastream Where does $folder come from? |
oh sorry forgot that... public function listMessages($limit=NULL, $page=NULL, $order='newest', $folder=NULL) and than just above the larger pice of code add if(!isset($folder)) {
$folder = 'INBOX';
} if you want to fetch other folders just pass them in $folder like $folder = 'INBOX.SENT'; if you want you can check out my updated fMailbox.php, I've added sorting, folders and counting messages. |
@novastream Thanks for your fork! 👍 But one thing you have missed is to select the folder, bacause that is required to fetch the messages from the folder: Line 1239 - https://github.com/novastream/flourish-imap/blob/master/flourish/fMailbox.php#L1239 $this->write('SELECT "'.$folder.'"'); Here I found a very nice cheatsheet: http://donsutherland.org/crib/imap |
Hi Tom, Haven't updated the Flourish library in a while BUT have some changes that I can commit soon. There's a lot of bug fixes. Med vänlig hälsning / Best regards Jonathan Lindgren Kanslihusvägen 13A vSphere ESXi | pfSense | Zimbra | CollabNet Från: "Tom Witkowski" [email protected] @novastream Thanks for your fork! But one thing you have missed is to select the folder, bacause that is required to fetch the messages from the folder: Line 1239 - https://github.com/novastream/flourish-imap/blob/master/flourish/fMailbox.php#L1239 — |
Have you added any function to get a list of all folders? And would be cool if you can push all the changes you made - and I think that the Folder change is something that can be merged in the main repo!? |
I'm writing a app that needs to get the latest 10 emails from a huge inbox.
Using your class is very good, but it needs to parse all mesages in the inbox.
I could really need a function that could get me the latest 10 UIDs which I can the itterate over.
I could imagine that others also needed this.
The text was updated successfully, but these errors were encountered: