note 22517 modified in function.imap-uid by nlopess
| From: | nlopess@php.net | Date: | Wed, 19 Jul 2006 10:40:12 +0000 |
| Subject: | note 22517 modified in function.imap-uid by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114923@lists.php.net to get a copy of this message | ||
For those using a POP3 mailbox, this function, as noted, does not work.
One way around this is to use direct FTP communication with the mail server. For example, the
following function takes a mailbox/password and message sequence number, and from this returns the
message UID.
function fetch_UID($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);
fclose($fp);
}
return substr($retval,6,30);
}
Note: 110 is the TCP port commonly associated with a POP3 mailbox. Also the substr() function is
used to trim the +OK and the message number from the beginning of the server's response.
I'm sure there are other (better) ways to do this. But after a fruitless search of the
internet, this is what I came up with, and it seems to work for me.
--was--
For those using a POP3 mailbox, this function, as noted, does not work.
One way around this is to use direct FTP communication with the mail server. For example, the
following function takes a mailbox/password and message sequence number, and from this returns the
message UID.
function fetch_UID($account, $password, $message_number)
{
$retval = 0;
$fp = fsockopen($POPMAILSERVER, 110);
if ($fp > 0)
{
$buf = fgets($fp, 1024);
fputs($fp, "USER ".$account."\n");
$buf = fgets($fp, 1024);
fputs($fp, "PASS ".$password."\n");
$buf = fgets($fp, 1024);
fputs($fp, "UIDL ".$message_number."\n");
$retval=fgets($fp, 1024);
fputs($fp, "QUIT\n");
$buf = fgets($fp,1024);
fclose($fp);
}
return substr($retval,6,30);
}
Note: 110 is the TCP port commonly associated with a POP3 mailbox. Also the substr() function is
used to trim the +OK and the message number from the beginning of the server's response.
I'm sure there are other (better) ways to do this. But after a fruitless search of the
internet, this is what I came up with, and it seems to work for me.
http://php.net/manual/en/function.imap-uid.php