Getting Message headers one by one via Msg Number

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Getting Message headers one by one via Msg Number

Post by anjanesh »

Hi

I need an alternative to $arr = imap_headers ($mbox);
My mailbox has over 10K msgs and its taking a lot of time to get the headers alone. Plus memory etc.
How do I get it like the way we can get data from a mysql table ? $msgno= get_imap_msgs($mbox) and then iterate it via its msg nos - $info = imap_headerinfo($mbox, $msgno); ?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

<?php
$mbox = imap_open("{mail.domain.com:110/pop3}INBOX", "username", "password");
// $a = imap_headers ($mbox); // This I dont want !
$res = get_imap_msgs($mbox);
while ($row = get_imap_email($res)
 {
         echo $row['msgno'].' - '.$row['subject']."\n";
 }
imap_close ($mbox);
?>
imap_headers is taking forever to get 10K headers ! I dont want the entire list in one go. Is the above code possible ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

did you even look at the documentation to the functions I linked?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Yes I did - but the 1st two functions require the Msg Numbers - how do I get that ?
If imap_num_msg returns 10,000 does that mean the msgnos start from 1 and end with 10000 ?
If there were 20K msgs and 10K got deleted in the middle here and there and 10K are left - do the msgnos get re-sorted ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

play with it.. :roll:
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

I just tested with a test email address.
Sent 4 mails - all got received - msgids were 1, 2, 3 and 4.
I deleted Email 2 (in Squirrel Mail) manually and when I tried to read msgid 2 it gave Bad message number in...
So if there are 10,000 emails in a mail box how do I iterate though each header one by one ? Now after my test, obviously 1 to 10,000 wont be the right iteration - so how do I do a obj->getNextMsgId() in php ?

imap_status has something called SA_UIDNEXT called by $status->uidnext which is what I want - but says imap_status -- This function returns status information on a mailbox other than the current one - and I want for the current one !
Post Reply