コード例 #1
0
 public function __construct($body = null, Parser $parser = null)
 {
     $this->parser = $parser;
     if ($parser instanceof Parser) {
         if ($html = $this->parser->getMessageBody('html')) {
             $this->body = $this->toPlainText($html);
         } else {
             $this->body = $this->getParser()->getMessageBody('text');
         }
     } else {
         $this->body = $this->toPlainText($body);
     }
     $this->splitLines();
     $this->processLines();
     $this->joinLines();
 }
コード例 #2
0
 /**
  * @param  Parser $parser
  * @return array
  */
 private static function getHeadersRelevantForMailerDetectionEml(Parser &$parser)
 {
     return self::filterHeaders(['x-mailer' => $parser->getHeader('x-mailer'), 'message-id' => $parser->getHeader('message-id'), 'received' => $parser->getHeader('received'), 'mime-version' => $parser->getHeader('mime-version'), 'user-agent' => $parser->getHeader('user-agent')]);
 }
コード例 #3
0
ファイル: Client.php プロジェクト: mambaru/smtpd
 public function msgHandle($msgRaw)
 {
     #$this->log('debug', 'client '.$this->id.' raw: /'.$msgRaw.'/');
     $rv = '';
     $str = new StringParser($msgRaw);
     $args = $str->parse();
     //print_r($args);
     $command = array_shift($args);
     $commandcmp = strtolower($command);
     if ($commandcmp == 'helo') {
         #$this->log('debug', 'client '.$this->id.' helo');
         $this->setStatus('hasHello', true);
         return $this->sendOk('localhost.localdomain');
     } elseif ($commandcmp == 'ehlo') {
         #$this->log('debug', 'client '.$this->id.' helo');
         return $this->sendCommandNotImplemented();
     } elseif ($commandcmp == 'mail') {
         #$this->log('debug', 'client '.$this->id.' mail');
         #ve($args);
         if ($this->getStatus('hasHello')) {
             if (isset($args[0]) && $args[0]) {
                 $this->setStatus('hasMail', true);
                 $from = count($args) > 1 ? $args[1] : $args[0];
                 if (substr(strtolower($from), 0, 6) == 'from:<') {
                     $from = substr(substr($from, 6), 0, -1);
                 } elseif (substr(strtolower($from), 0, 1) == '<') {
                     $from = substr(substr($from, 1), 0, -1);
                 }
                 #$this->log('debug', 'client '.$this->id.' from: /'.$from.'/');
                 $this->from = $from;
                 $this->mail = '';
                 return $this->sendOk();
             } else {
                 return $this->sendSyntaxErrorInParameters();
             }
         } else {
             return $this->sendSyntaxErrorCommandUnrecognized();
         }
     } elseif ($commandcmp == 'rcpt') {
         #$this->log('debug', 'client '.$this->id.' rcpt');
         #ve($args);
         if ($this->getStatus('hasHello')) {
             if (isset($args[0]) && $args[0]) {
                 $this->setStatus('hasMail', true);
                 $rcpt = count($args) > 1 ? $args[1] : $args[0];
                 if (substr(strtolower($rcpt), 0, 4) == 'to:<') {
                     $rcpt = substr(substr($rcpt, 4), 0, -1);
                 } elseif (substr(strtolower($rcpt), 0, 1) == '<') {
                     $rcpt = substr(substr($rcpt, 1), 0, -1);
                 }
                 $this->rcpt[] = $rcpt;
                 #$this->log('debug', 'client '.$this->id.' rcpt: /'.$rcpt.'/');
                 return $this->sendOk();
             } else {
                 return $this->sendSyntaxErrorInParameters();
             }
         } else {
             return $this->sendSyntaxErrorCommandUnrecognized();
         }
     } elseif ($commandcmp == 'data') {
         #$this->log('debug', 'client '.$this->id.' data');
         if ($this->getStatus('hasHello')) {
             $this->setStatus('hasData', true);
             return $this->sendDataResponse();
         } else {
             return $this->sendSyntaxErrorCommandUnrecognized();
         }
     } elseif ($commandcmp == 'noop') {
         return $this->sendOk();
     } elseif ($commandcmp == 'quit') {
         $rv .= $this->sendQuit();
         $this->shutdown();
     } else {
         if ($this->getStatus('hasData')) {
             if ($msgRaw == '.') {
                 $this->mail = substr($this->mail, 0, -strlen(static::MSG_SEPARATOR));
                 $parser = new Parser();
                 $parser->setText($this->mail);
                 //$parser = Message::fromString($this->mail);
                 $this->getServer()->mailNew($this->from, $this->rcpt, $parser);
                 $this->from = '';
                 $this->rcpt = array();
                 $this->mail = '';
                 return $this->sendOk();
             } else {
                 $this->mail .= $msgRaw . static::MSG_SEPARATOR;
             }
         } else {
             $this->log('debug', 'client ' . $this->id . ' not implemented: /' . $command . '/ - /' . join('/ /', $args) . '/');
             return $this->sendSyntaxErrorCommandUnrecognized();
         }
     }
     return $rv;
 }