/** * Send a mail using this transport * * @param Postman_Zend_Mail $mail * @access public * @return void * @throws Postman_Zend_Mail_Transport_Exception if mail is empty */ public function send(Postman_Zend_Mail $mail) { $this->_isMultipart = false; $this->_mail = $mail; $this->_parts = $mail->getParts(); $mime = $mail->getMime(); // Build body content $this->_buildBody(); // Determine number of parts and boundary $count = count($this->_parts); $boundary = null; if ($count < 1) { /** * @see Postman_Zend_Mail_Transport_Exception */ require_once 'Exception.php'; throw new Postman_Zend_Mail_Transport_Exception('Empty mail cannot be sent'); } if ($count > 1) { // Multipart message; create new MIME object and boundary $mime = new Postman_Zend_Mime($this->_mail->getMimeBoundary()); $boundary = $mime->boundary(); } elseif ($this->_isMultipart) { // multipart/alternative -- grab boundary $boundary = $this->_parts[0]->boundary; } // Determine recipients, and prepare headers $this->recipients = implode(',', $mail->getRecipients()); $this->_prepareHeaders($this->_getHeaders($boundary)); // Create message body // This is done so that the same Postman_Zend_Mail object can be used in // multiple transports $message = new Postman_Zend_Mime_Message(); $message->setParts($this->_parts); $message->setMime($mime); $this->body = $message->generateMessage($this->EOL); // Send to transport! $this->_sendMail(); }
/** * Encode header fields * * Encodes header content according to RFC1522 if it contains non-printable * characters. * * @param string $value * @return string */ protected function _encodeHeader($value) { if (Postman_Zend_Mime::isPrintable($value) === false) { if ($this->getHeaderEncoding() === Postman_Zend_Mime::ENCODING_QUOTEDPRINTABLE) { $value = Postman_Zend_Mime::encodeQuotedPrintableHeader($value, $this->getCharset(), Postman_Zend_Mime::LINELENGTH, Postman_Zend_Mime::LINEEND); } else { $value = Postman_Zend_Mime::encodeBase64Header($value, $this->getCharset(), Postman_Zend_Mime::LINELENGTH, Postman_Zend_Mime::LINEEND); } } return $value; }
/** * Get the Content of the current Mime Part in the given encoding. * * @param string $EOL Line end; defaults to {@link Postman_Zend_Mime::LINEEND} * @throws Postman_Zend_Mime_Exception * @return string */ public function getContent($EOL = Postman_Zend_Mime::LINEEND) { if ($this->_isStream) { return stream_get_contents($this->getEncodedStream()); } else { return Postman_Zend_Mime::encode($this->_content, $this->encoding, $EOL); } }