Page 1 of 1

Getting Message headers one by one via Msg Number

Posted: Sun Feb 05, 2006 6:56 am
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

Posted: Sun Feb 05, 2006 7:29 am
by feyd

Posted: Sun Feb 05, 2006 8:38 am
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 ?

Posted: Sun Feb 05, 2006 8:40 am
by feyd
did you even look at the documentation to the functions I linked?

Posted: Sun Feb 05, 2006 8:51 am
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 ?

Posted: Sun Feb 05, 2006 9:42 am
by feyd
play with it.. :roll:

Posted: Sun Feb 05, 2006 10:12 am
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 !