Sockets Problems

software development

#1

The RETR and LIST functions only list the first line and not the rest of the message???
What am I missing?


$fp = fsockopen ($host, $port, $errno, $errstr);
// if a handle is not returned
if (!$fp)
{
die(“Error: could not open socket connection\n”);
}
else
{
// get the welcome message
$welcome = fgets ($fp, 150);
// check for success code
if (substr($welcome, 0, 3) == “+OK”)
{
// send username and read response
fputs ($fp, “USER $user\n”);
fgets($fp, 50);
// send password and read response
fputs ($fp, “PASS $pass\n”);
$ack = fgets($fp, 50);
// check for success code

if (substr($ack, 0, 3) == “+OK”)
{

// send status request and read response
fputs ($fp, “STAT\n”);
$status = fgets($fp, 50);

if (substr($status, 0, 3) == “+OK”)
{

fputs ($fp, “RETR 1\r\r\n”);
$retr = fgets($fp, 500);
// shut down connection
fputs ($fp, “QUIT\n”);
fclose ($fp);
}
// error getting status
else
{
die (“Server said: $status”);
}
}
// auth failure
else
{
die (“Server said: $ack”);
}
}
// bad welcome message
else
{
die (“Bad connection string\n”);
}
// get status string
// split by spaces
$arr = explode(" “, $status);
// the second element contains the total number of messages
echo $arr[1] . " messages in mailbox $retr”;

}