예제 #1
0
 /**
  * Send a message
  *
  * @param   peer.mail.Message message the Message object to send
  * @return  bool TRUE in case of success
  * @throws  peer.mail.transport.TransportException to indicate an error occured
  */
 public function send(Message $message)
 {
     try {
         $this->_sockcmd('MAIL FROM: %s', $message->from->getAddress(), 250);
         foreach ([TO, CC, BCC] as $type) {
             foreach ($message->getRecipients($type) as $r) {
                 $this->_sockcmd('RCPT TO: %s', $r->getAddress(), [250, 251]);
             }
         }
         // Content: Headers and body. Make sure lines containing a dot by itself are
         // properly escaped.
         $this->_sockcmd('DATA', 354);
         $this->_sockcmd('%s', $message->getHeaderString(), false);
         $this->_sockcmd('%s', preg_replace('/(^|[\\r\\n])([\\.]+)([\\r\\n]|$)/', '$1.$2$3', $message->getBody()), false);
     } catch (\lang\XPException $e) {
         throw new TransportException('Sending message failed', $e);
     }
     return (bool) $this->_sockcmd('.', 250);
 }