Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: None | Size: 1.23 KB | Hits: 78 | Expires: Never
Copy text to clipboard
  1.                 function get_line() {
  2.                         if($this->debug)
  3.                                 echo 'get_line()'."\n";
  4.                                
  5.                         $buffer = fgets($this->sock, 1024);
  6.                        
  7.                         if($this->debug)
  8.                                 echo "\t".rtrim($buffer)."\n";
  9.                        
  10.                         // Connexion lost
  11.                         if($buffer === false) {
  12.                                 @fclose($this->socket);
  13.                                 $this->socket = false;
  14.                                 return false;
  15.                         }
  16.                        
  17.                         return rtrim($buffer);
  18.                 }
  19.  
  20. function parse_header($id) {
  21.                         if($this->debug)
  22.                                 echo 'parse_header('.$id.')'."\n";
  23.                        
  24.                         if($id == '')
  25.                                 return 0;
  26.                         $this->put_line('TOP '.$id);
  27.                         $headers = array();
  28.                        
  29.                         if(!preg_match('/^\+OK/', $this->get_line()))
  30.                                 throw new Exception('Can\'t get mail\'s headers');
  31.                        
  32.                         $i = 0;
  33.                         while(1) {
  34.                                 $tmp = $this->get_line();
  35.                                 if($tmp === false || $tmp == '.')
  36.                                         break;
  37.                                 if(preg_match('/^\-ERR/', $tmp))
  38.                                         throw new Exception('Can\'t retreive mail');
  39.                                
  40.                                 if(preg_match('/^Date:/',$tmp)) {
  41.                                         $headers['date'] = $tmp;
  42.                                 } else if(preg_match('/^From:/', $tmp)) {
  43.                                         $headers['from'] = $tmp;
  44.                                 } else if(preg_match('/^Subject:/', $tmp)) {
  45.                                         $headers['subject'] = $tmp;
  46.                                 } else if(preg_match('/^To:/', $tmp)) {
  47.                                         $headers['to'] = $tmp;
  48.                                 }
  49.                         }
  50.                        
  51.                         if($this->debug)
  52.                                 print_r($headers);
  53.                         return $headers;
  54.                 }