Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-10-2008, 03:10 PM POP3 Sorted?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Is it possible to ensure the same order when fetching mails from POP3 servers? I'm trying to interface with GMail using the code below, but the order changes (i.e. message #1 isn't always the same). In between calls of the script, I make no changes (including email receipt) to GMail, so I'm not sure why the order is changing or, more importantly, how to stop it.

Any help is greatly appreciated.

PHP Code:
<?php

require_once "Net/POP3.php";
require_once 
"Mail/mimeDecode.php";

$pop3 =& new Net_POP3();

$ia_configuration_data['ia_email'] = '********';
$ia_configuration_data['ia_password']  = '++++++++++';
$ia_configuration_data['ia_server']  = 'pop.gmail.com';
$ia_configuration_data['port']  = '995';
if (!
$pop3->connect('ssl://'.$ia_configuration_data['ia_server'], $ia_configuration_data['port'])) {
  
//unable to connect to mail server.
  
echo __file__.':'.__line__.'<br />';
  print 
'<pre>'.print_r($pop3,true).'</pre>';
  exit();
}
if (
$pop3->login($ia_configuration_data['ia_email'], $ia_configuration_data['ia_password']) !== true) {
  
//invalid login credentials
  
echo __file__.':'.__line__.'<br />';
  print 
'<pre>'.print_r($pop3,true).'</pre>';
  exit();
}

$params['include_bodies'] = true;
$params['decode_bodies']  = true;
$params['decode_headers'] = true;

$num_messages $pop3->numMsg();
$start_message 1;
$end_message min(10,$num_messages);

for (
$counter=$start_message;$counter<=$end_message;$counter++) {
  
$message_details $pop3->getMsg($counter);
  
$decoder = new Mail_mimeDecode($message_details);
  
$structure $decoder->decode($params);
  
  
//Do stuff
}
/*
* Disconnect
*/
$pop3->disconnect();
?>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
 
Register now for full access!
Old 09-10-2008, 04:03 PM Re: POP3 Sorted?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Couldn't you pop them into an array and sort them by the date?
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 09-10-2008, 04:05 PM Re: POP3 Sorted?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Well, I'm writing this for someone who hasn't checked their email in a year and has 10k+ emails, so I need to do them a little bit at a time and can't load all into memory b/c I'd run out or else that'd be a perfect solution.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 09-10-2008, 04:35 PM Re: POP3 Sorted?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Its possible to merge sort without having all of the items in memory at once.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-10-2008, 04:37 PM Re: POP3 Sorted?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
OK. You've piqued my interest -- what are you talking about?
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 09-11-2008, 02:44 PM Re: POP3 Sorted?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
http://en.wikipedia.org/wiki/Merge_sort

Merge sort works by taking a list of unsorted items and splitting it into sublists. Normally you would do this by taking your origional list and recursively dividing it in half until your ideal list size is reached. But in your case you will most likely have to just come up with a maximum list size and then gather that many items from pop3. Then sort that list however you choose and repeat. Once you have all of your sub lists sorted, compare all of the smallest entries from your sublists, the smallest of these will be the smallest entry in the entire list. You can just continue doing this until you have a completely sorted list.

In your case the "smallest" entry will be the one that was sent most recently. Your biggest challenge will be storing all of the sublists, but this can be accomplished using a database.

What might work better than merge sort in this case would be to just feed all of your emails into a database and then let the database sort them.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-11-2008, 02:47 PM Re: POP3 Sorted?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Oh. Thanks for the clarification. I should have been more clear. I'm wanting to retrieve them already sorted (I don't care by what, so long as message #1 is always message #1) so that I can fetch only messages 1-10 the first time the script runs, 11-20 the second, and so on. I read up on the POP3 spec and apparently this isn't supported, so I don't have a choice here.

Thanks again for the clarification.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 09-11-2008, 03:01 PM Re: POP3 Sorted?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Could you mark them read after you retrieve them and then only retrieve unread messages?
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Reply     « Reply to POP3 Sorted?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31015 seconds with 12 queries