note 45126 deleted from function.imap-uid by tomsommer

From: Date: Thu, 26 Aug 2004 20:40:37 +0000
Subject: note 45126 deleted from function.imap-uid by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75356@lists.php.net to get a copy of this message
Note Submitter: nando at porfavornospaaaam dot ecurso dot net ---- My two cents to the function that "robert dot blanch at hsc dot utah dot edu" proposed, and "thomas at bytefreak dot de" refined: My server returns a UID that is longer than 30 characters (I think the lenght depends on the implementation of the pop3 service). RFC 1725 states that the response of UIDL is something of the form: +OK 10 7685a9ebdb428f073ec10cca13e652a1 for the mssg_no = 10. It's specified that the UID is not followed by anything (except of CRLF, I suppose), so we could ommit the lenght atribute in the final substr(). On the other hand we should take care of which one is the correct starting character in the string. If we are talking of message number 1 to 9, it is, as Robert wrote, character 6. If is mssge 10-99, well, it's char 7, and so on. So I'll use a function like this: <?php function fetch_UID ($POPMAILSERVER, $account, $password, $message_number) { $retval = 0; $fp = fsockopen($POPMAILSERVER, 110); if ($fp > 0) { $buf = fgets($fp, 1024); fputs($fp, "USER ".$account."\r\n"); $buf = fgets($fp, 1024); fputs($fp, "PASS ".$password."\r\n"); $buf = fgets($fp, 1024); fputs($fp, "UIDL ".$message_number."\r\n"); $retval=fgets($fp, 1024); fputs($fp, "QUIT\r\n"); $buf = fgets($fp,1024); $retval=explode(" ", $retval); fclose($fp); } return trim($retval[2]); } ?> I would also check for the values of $fp to see if operations are being succesfull, but I'll let this to someone with more expertise on the pop3 standards. Also NOTE: the pop3 function UIDL, wich is the one that is indeed giving us the uid, is defined as OPTIONAL in the RFC 1725, so it isn't supossed to be in every pop3 server. This means that this function should work almost, but NOT always!

« previous php.notes (#75356) next »