Be careful using this function with a pop3 server, if you have an array of mails you want to handle in a loop.
If you want wo handle the mailcontent to use it in your application and use i.e.
$messages = imap_sort($connection, SORTARRIVAL, FALSE);
and have an loop like
foreach($messages as $i) {
// do something with the content
imap_delete($i);
imap_expunge($connection);
}
every 2nd mail will be left untouched.
the first will be read, deleted, the second becomes #1, but due to the loop-condition #2, which was #3 as you started, will be left and #4 - which is #3 now, will be read instead.
the pop3-protocol has no expunge-method, so i assume they disconnect to delete the flagges mails and reconnect.
:-((
So you have to you the number 1 for all ....