Untitled
By: a guest | Mar 20th, 2010 | Syntax:
None | Size: 1.23 KB | Hits: 78 | Expires: Never
function get_line() {
if($this->debug)
echo 'get_line()'."\n";
$buffer = fgets($this->sock, 1024);
if($this->debug)
echo "\t".rtrim($buffer)."\n";
// Connexion lost
if($buffer === false) {
@fclose($this->socket);
$this->socket = false;
return false;
}
return rtrim($buffer);
}
function parse_header($id) {
if($this->debug)
echo 'parse_header('.$id.')'."\n";
if($id == '')
return 0;
$this->put_line('TOP '.$id);
$headers = array();
if(!preg_match('/^\+OK/', $this->get_line()))
throw new Exception('Can\'t get mail\'s headers');
$i = 0;
while(1) {
$tmp = $this->get_line();
if($tmp === false || $tmp == '.')
break;
if(preg_match('/^\-ERR/', $tmp))
throw new Exception('Can\'t retreive mail');
if(preg_match('/^Date:/',$tmp)) {
$headers['date'] = $tmp;
} else if(preg_match('/^From:/', $tmp)) {
$headers['from'] = $tmp;
} else if(preg_match('/^Subject:/', $tmp)) {
$headers['subject'] = $tmp;
} else if(preg_match('/^To:/', $tmp)) {
$headers['to'] = $tmp;
}
}
if($this->debug)
print_r($headers);
return $headers;
}