I'm trying to parse emails on a yahoo server, which does not have IMAP. The only code that seems to work is the following:
<?
function getPOPMessageCount($username, $password, $server, $port = 110, $timeout = 30){
$sock = @fsockopen($server, $port, $errno, $errstr, $timeout);
if (!$sock) die("Error opening socket ($errno): $errstr");
if (substr(fgets($sock), 0, 3) != '+OK') die('Server did not respond OK.');
fwrite($sock, "USER $username\r\n");
if (substr(fgets($sock), 0, 3) != '+OK') die('Server did not accept username.');
fwrite($sock, "PASS $password\r\n");
if (substr(fgets($sock), 0, 3) != '+OK') die('Server did not accept password.');
fwrite($sock, "STAT\r\n");
$response = fgets($sock);
if (substr($response, 0, 3) != '+OK') die('Server sent invalid STAT response.');
fwrite($sock, "QUIT\r\n");
fclose($sock);
return intval(substr($response, 4, strlen($response)));
}
print getPOPMessageCount('name@email.com', 'pass', 'server.com');
?>
This returns the number of messages in the account, but I want to parse the subject and body. Any ideas?