diff options
Diffstat (limited to 'Postman/Postman-Mail/PostmanMessage.php')
-rw-r--r-- | Postman/Postman-Mail/PostmanMessage.php | 435 |
1 files changed, 216 insertions, 219 deletions
diff --git a/Postman/Postman-Mail/PostmanMessage.php b/Postman/Postman-Mail/PostmanMessage.php index bd852c4..f9b7dd3 100644 --- a/Postman/Postman-Mail/PostmanMessage.php +++ b/Postman/Postman-Mail/PostmanMessage.php @@ -1,8 +1,8 @@ <?php -if (! class_exists ( "PostmanMessage" )) { - +if ( ! class_exists( 'PostmanMessage' ) ) { + require_once 'PostmanEmailAddress.php'; - + /** * This class knows how to interface with Wordpress * including loading/saving to the database. @@ -11,14 +11,13 @@ if (! class_exists ( "PostmanMessage" )) { * http://framework.zend.com/manual/current/en/modules/zend.mail.smtp.options.html * * @author jasonhendriks - * */ class PostmanMessage { const EOL = "\r\n"; - + // logger for all concrete classes - populate with setLogger($logger) protected $logger; - + // set by the caller private $from; private $replyTo; @@ -33,44 +32,43 @@ if (! class_exists ( "PostmanMessage" )) { private $attachments; private $date; private $messageId; - + // determined by the send() method private $isTextHtml; private $contentType; private $charset; - - // + private $boundary; - + /** * No-argument constructor */ function __construct() { - $this->logger = new PostmanLogger ( get_class ( $this ) ); - $this->headers = array (); - $this->toRecipients = array (); - $this->ccRecipients = array (); - $this->bccRecipients = array (); + $this->logger = new PostmanLogger( get_class( $this ) ); + $this->headers = array(); + $this->toRecipients = array(); + $this->ccRecipients = array(); + $this->bccRecipients = array(); } - + /** * * @return boolean */ public function isBodyPartsEmpty() { - return empty ( $this->bodyTextPart ) && empty ( $this->bodyHtmlPart ); + return empty( $this->bodyTextPart ) && empty( $this->bodyHtmlPart ); } - + /** * - * @param PostmanModuleTransport $transport + * @param PostmanModuleTransport $transport */ - public function validate(PostmanModuleTransport $transport) { - if ($transport->isEmailValidationSupported ()) { - $this->internalValidate (); + public function validate( PostmanModuleTransport $transport ) { + if ( $transport->isEmailValidationSupported() ) { + $this->internalValidate(); } } - + /** * Create body parts based on content type * MyMail creates its own body parts @@ -78,176 +76,175 @@ if (! class_exists ( "PostmanMessage" )) { public function createBodyParts() { // modify the content-type to include the boundary - if (false !== stripos ( $this->contentType, 'multipart' ) && ! empty ( $this->boundary )) { + if ( false !== stripos( $this->contentType, 'multipart' ) && ! empty( $this->boundary ) ) { // Lines in email are terminated by CRLF ("\r\n") according to RFC2821 - $this->contentType = sprintf ( "%s;\r\n\t boundary=\"%s\"", $this->contentType, $this->getBoundary () ); + $this->contentType = sprintf( "%s;\r\n\t boundary=\"%s\"", $this->contentType, $this->getBoundary() ); } - - // - $body = $this->getBody (); - $contentType = $this->getContentType (); + + $body = $this->getBody(); + $contentType = $this->getContentType(); // add the message content as either text or html - if (empty ( $contentType ) || substr ( $contentType, 0, 10 ) === 'text/plain') { - $this->logger->debug ( 'Creating text body part' ); - $this->setBodyTextPart ( $body ); - } else if (substr ( $contentType, 0, 9 ) === 'text/html') { - $this->logger->debug ( 'Creating html body part' ); - $this->setBodyHtmlPart ( $body ); - } else if (substr ( $contentType, 0, 21 ) === 'multipart/alternative') { - $this->logger->debug ( 'Adding body as multipart/alternative' ); - $arr = explode ( PHP_EOL, $body ); + if ( empty( $contentType ) || substr( $contentType, 0, 10 ) === 'text/plain' ) { + $this->logger->debug( 'Creating text body part' ); + $this->setBodyTextPart( $body ); + } else if ( substr( $contentType, 0, 9 ) === 'text/html' ) { + $this->logger->debug( 'Creating html body part' ); + $this->setBodyHtmlPart( $body ); + } else if ( substr( $contentType, 0, 21 ) === 'multipart/alternative' ) { + $this->logger->debug( 'Adding body as multipart/alternative' ); + $arr = explode( PHP_EOL, $body ); $textBody = ''; $htmlBody = ''; $mode = ''; foreach ( $arr as $s ) { - $this->logger->trace ( 'mode: ' . $mode . ' bodyline: ' . $s ); - if (substr ( $s, 0, 25 ) === "Content-Type: text/plain;") { + $this->logger->trace( 'mode: ' . $mode . ' bodyline: ' . $s ); + if ( substr( $s, 0, 25 ) === 'Content-Type: text/plain;' ) { $mode = 'foundText'; - } else if (substr ( $s, 0, 24 ) === "Content-Type: text/html;") { + } else if ( substr( $s, 0, 24 ) === 'Content-Type: text/html;' ) { $mode = 'foundHtml'; - } else if ($mode == 'textReading') { + } else if ( $mode == 'textReading' ) { $textBody .= $s; - } else if ($mode == 'htmlReading') { + } else if ( $mode == 'htmlReading' ) { $htmlBody .= $s; - } else if ($mode == 'foundText') { - $trim = trim ( $s ); - if (empty ( $trim )) { + } else if ( $mode == 'foundText' ) { + $trim = trim( $s ); + if ( empty( $trim ) ) { $mode = 'textReading'; } - } else if ($mode == 'foundHtml') { - $trim = trim ( $s ); - if (empty ( $trim )) { + } else if ( $mode == 'foundHtml' ) { + $trim = trim( $s ); + if ( empty( $trim ) ) { $mode = 'htmlReading'; } } } - $this->setBodyHtmlPart ( $htmlBody ); - $this->setBodyTextPart ( $textBody ); + $this->setBodyHtmlPart( $htmlBody ); + $this->setBodyTextPart( $textBody ); } else { - $this->logger->error ( 'Unknown content-type: ' . $contentType ); - $this->setBodyTextPart ( $body ); + $this->logger->error( 'Unknown content-type: ' . $contentType ); + $this->setBodyTextPart( $body ); } } - + /** * Apply the WordPress filters to the email */ public function applyFilters() { - if ($this->logger->isDebug ()) { - $this->logger->debug ( 'Applying WordPress filters' ); + if ( $this->logger->isDebug() ) { + $this->logger->debug( 'Applying WordPress filters' ); } - + /** * Filter the email address to send from. * * @since 2.2.0 - * + * * @param string $from_email * Email address to send from. */ - $filteredEmail = apply_filters ( 'wp_mail_from', $this->getFromAddress ()->getEmail () ); - if ($this->logger->isTrace ()) { - $this->logger->trace ( 'wp_mail_from: ' . $filteredEmail ); + $filteredEmail = apply_filters( 'wp_mail_from', $this->getFromAddress()->getEmail() ); + if ( $this->logger->isTrace() ) { + $this->logger->trace( 'wp_mail_from: ' . $filteredEmail ); } - if ($this->getFromAddress ()->getEmail () !== $filteredEmail) { - $this->logger->debug ( sprintf ( 'Filtering From email address: before=%s after=%s', $this->getFromAddress ()->getEmail (), $filteredEmail ) ); - $this->getFromAddress ()->setEmail ( $filteredEmail ); + if ( $this->getFromAddress()->getEmail() !== $filteredEmail ) { + $this->logger->debug( sprintf( 'Filtering From email address: before=%s after=%s', $this->getFromAddress()->getEmail(), $filteredEmail ) ); + $this->getFromAddress()->setEmail( $filteredEmail ); } - + /** * Filter the name to associate with the "from" email address. * * @since 2.3.0 - * + * * @param string $from_name * Name associated with the "from" email address. */ - $filteredName = apply_filters ( 'wp_mail_from_name', $this->getFromAddress ()->getName () ); - if ($this->logger->isTrace ()) { - $this->logger->trace ( 'wp_mail_from_name: ' . $filteredName ); + $filteredName = apply_filters( 'wp_mail_from_name', $this->getFromAddress()->getName() ); + if ( $this->logger->isTrace() ) { + $this->logger->trace( 'wp_mail_from_name: ' . $filteredName ); } - if ($this->getFromAddress ()->getName () !== $filteredName) { - $this->logger->debug ( sprintf ( 'Filtering From email name: before=%s after=%s', $this->getFromAddress ()->getName (), $filteredName ) ); - $this->getFromAddress ()->setName ( $filteredName ); + if ( $this->getFromAddress()->getName() !== $filteredName ) { + $this->logger->debug( sprintf( 'Filtering From email name: before=%s after=%s', $this->getFromAddress()->getName(), $filteredName ) ); + $this->getFromAddress()->setName( $filteredName ); } - + /** * Filter the default wp_mail() charset. * * @since 2.3.0 - * + * * @param string $charset * Default email charset. */ - $filteredCharset = apply_filters ( 'wp_mail_charset', $this->getCharset () ); - if ($this->logger->isTrace ()) { - $this->logger->trace ( 'wp_mail_charset: ' . $filteredCharset ); + $filteredCharset = apply_filters( 'wp_mail_charset', $this->getCharset() ); + if ( $this->logger->isTrace() ) { + $this->logger->trace( 'wp_mail_charset: ' . $filteredCharset ); } - if ($this->getCharset () !== $filteredCharset) { - $this->logger->debug ( sprintf ( 'Filtering Charset: before=%s after=%s', $this->getCharset (), $filteredCharset ) ); - $this->setCharset ( $filteredCharset ); + if ( $this->getCharset() !== $filteredCharset ) { + $this->logger->debug( sprintf( 'Filtering Charset: before=%s after=%s', $this->getCharset(), $filteredCharset ) ); + $this->setCharset( $filteredCharset ); } - + /** * Filter the wp_mail() content type. * * @since 2.3.0 - * + * * @param string $content_type * Default wp_mail() content type. */ - $filteredContentType = apply_filters ( 'wp_mail_content_type', $this->getContentType () ); - if ($this->logger->isTrace ()) { - $this->logger->trace ( sprintf ( 'wp_mail_content_type: "%s"', $filteredContentType ) ); + $filteredContentType = apply_filters( 'wp_mail_content_type', $this->getContentType() ); + if ( $this->logger->isTrace() ) { + $this->logger->trace( sprintf( 'wp_mail_content_type: "%s"', $filteredContentType ) ); } - if ($this->getContentType () != $filteredContentType) { - $this->logger->debug ( sprintf ( 'Filtering Content-Type: before=%s after=%s', $this->getContentType (), $filteredContentType ) ); - $this->setContentType ( $filteredContentType ); + if ( $this->getContentType() != $filteredContentType ) { + $this->logger->debug( sprintf( 'Filtering Content-Type: before=%s after=%s', $this->getContentType(), $filteredContentType ) ); + $this->setContentType( $filteredContentType ); } - + // Postman has it's own 'user override' filter - $options = PostmanOptions::getInstance (); - $forcedEmailAddress = $options->getMessageSenderEmail (); - if ($options->isSenderEmailOverridePrevented () && $this->getFromAddress ()->getEmail () !== $forcedEmailAddress) { - $this->logger->debug ( sprintf ( 'Forced From email address: before=%s after=%s', $this->getFromAddress ()->getEmail (), $forcedEmailAddress ) ); - $this->getFromAddress ()->setEmail ( $forcedEmailAddress ); + $options = PostmanOptions::getInstance(); + $forcedEmailAddress = $options->getMessageSenderEmail(); + if ( $options->isSenderEmailOverridePrevented() && $this->getFromAddress()->getEmail() !== $forcedEmailAddress ) { + $this->logger->debug( sprintf( 'Forced From email address: before=%s after=%s', $this->getFromAddress()->getEmail(), $forcedEmailAddress ) ); + $this->getFromAddress()->setEmail( $forcedEmailAddress ); } - $forcedEmailName = $options->getMessageSenderName (); - if ($options->isSenderNameOverridePrevented () && $this->getFromAddress ()->getName () !== $forcedEmailName) { - $this->logger->debug ( sprintf ( 'Forced From email name: before=%s after=%s', $this->getFromAddress ()->getName (), $forcedEmailName ) ); - $this->getFromAddress ()->setName ( $forcedEmailName ); + $forcedEmailName = $options->getMessageSenderName(); + if ( $options->isSenderNameOverridePrevented() && $this->getFromAddress()->getName() !== $forcedEmailName ) { + $this->logger->debug( sprintf( 'Forced From email name: before=%s after=%s', $this->getFromAddress()->getName(), $forcedEmailName ) ); + $this->getFromAddress()->setName( $forcedEmailName ); } } - + /** * Check all email headers for errors * Throw an exception if an error is found */ private function internalValidate() { // check the reply-to address for errors - if (isset ( $this->replyTo )) { - $this->getReplyTo ()->validate ( 'Reply-To' ); + if ( isset( $this->replyTo ) ) { + $this->getReplyTo()->validate( 'Reply-To' ); } - + // check the from address for errors - $this->getFromAddress ()->validate ( 'From' ); - + $this->getFromAddress()->validate( 'From' ); + // validate the To recipients - foreach ( ( array ) $this->getToRecipients () as $toRecipient ) { - $toRecipient->validate ( 'To' ); + foreach ( ( array ) $this->getToRecipients() as $toRecipient ) { + $toRecipient->validate( 'To' ); } - + // validate the Cc recipients - foreach ( ( array ) $this->getCcRecipients () as $ccRecipient ) { - $ccRecipient->validate ( 'Cc' ); + foreach ( ( array ) $this->getCcRecipients() as $ccRecipient ) { + $ccRecipient->validate( 'Cc' ); } - + // validate the Bcc recipients - foreach ( ( array ) $this->getBccRecipients () as $bccRecipient ) { - $bccRecipient->validate ( 'Bcc' ); + foreach ( ( array ) $this->getBccRecipients() as $bccRecipient ) { + $bccRecipient->validate( 'Bcc' ); } } - + /** * * @return PostmanEmailAddress @@ -255,7 +252,7 @@ if (! class_exists ( "PostmanMessage" )) { public function getFromAddress() { return $this->from; } - + /** * Get the charset, checking first the WordPress bloginfo, then the header, then the wp_mail_charset filter. * @@ -264,16 +261,16 @@ if (! class_exists ( "PostmanMessage" )) { public function getCharset() { return $this->charset; } - + /** * Set the charset * - * @param unknown $charset + * @param unknown $charset */ - public function setCharset($charset) { + public function setCharset( $charset ) { $this->charset = $charset; } - + /** * Get the content type, checking first the header, then the wp_mail_content_type filter * @@ -282,7 +279,7 @@ if (! class_exists ( "PostmanMessage" )) { public function getContentType() { return $this->contentType; } - public function setContentType($contentType) { + public function setContentType( $contentType ) { $this->contentType = $contentType; } /** @@ -291,8 +288,8 @@ if (! class_exists ( "PostmanMessage" )) { * Array or comma-separated list of email addresses to send message. * @throws Exception */ - public function addTo($to) { - $this->addRecipients ( $this->toRecipients, $to ); + public function addTo( $to ) { + $this->addRecipients( $this->toRecipients, $to ); } /** * @@ -300,8 +297,8 @@ if (! class_exists ( "PostmanMessage" )) { * Array or comma-separated list of email addresses to send message. * @throws Exception */ - public function addCc($cc) { - $this->addRecipients ( $this->ccRecipients, $cc ); + public function addCc( $cc ) { + $this->addRecipients( $this->ccRecipients, $cc ); } /** * @@ -309,8 +306,8 @@ if (! class_exists ( "PostmanMessage" )) { * Array or comma-separated list of email addresses to send message. * @throws Exception */ - public function addBcc($bcc) { - $this->addRecipients ( $this->bccRecipients, $bcc ); + public function addBcc( $bcc ) { + $this->addRecipients( $this->bccRecipients, $bcc ); } /** * @@ -318,208 +315,208 @@ if (! class_exists ( "PostmanMessage" )) { * Array or comma-separated list of email addresses to send message. * @throws Exception */ - private function addRecipients(&$recipientList, $recipients) { - if (! empty ( $recipients )) { - $recipients = PostmanEmailAddress::convertToArray ( $recipients ); + private function addRecipients( &$recipientList, $recipients ) { + if ( ! empty( $recipients ) ) { + $recipients = PostmanEmailAddress::convertToArray( $recipients ); foreach ( $recipients as $recipient ) { - if (! empty ( $recipient )) { - $this->logger->debug ( sprintf ( 'User added recipient: "%s"', $recipient ) ); - array_push ( $recipientList, new PostmanEmailAddress ( $recipient ) ); + if ( ! empty( $recipient ) ) { + $this->logger->debug( sprintf( 'User added recipient: "%s"', $recipient ) ); + array_push( $recipientList, new PostmanEmailAddress( $recipient ) ); } } } } - + /** * For the string version, each header line (beginning with From:, Cc:, etc.) is delimited with a newline ("\r\n") */ - public function addHeaders($headers) { - if (! is_array ( $headers )) { + public function addHeaders( $headers ) { + if ( ! is_array( $headers ) ) { // WordPress may send a string where "each header line (beginning with From:, Cc:, etc.) is delimited with a newline ("\r\n") (advanced)" // this converts that string to an array - $headers = explode ( "\n", str_replace ( "\r\n", "\n", $headers ) ); + $headers = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); // $headers = explode ( PHP_EOL, $headers ); } // otherwise WordPress sends an array foreach ( $headers as $header ) { - if (! empty ( $header )) { + if ( ! empty( $header ) ) { // boundary may be in a header line, but it's not a header // eg. boundary="----=_NextPart_DC7E1BB5... - if (strpos ( $header, ':' ) === false) { - if (false !== stripos ( $header, 'boundary=' )) { - $parts = preg_split ( '/boundary=/i', trim ( $header ) ); - $this->boundary = trim ( str_replace ( array ( + if ( strpos( $header, ':' ) === false ) { + if ( false !== stripos( $header, 'boundary=' ) ) { + $parts = preg_split( '/boundary=/i', trim( $header ) ); + $this->boundary = trim( str_replace( array( "'", - '"' + '"', ), '', $parts [1] ) ); - $this->logger->debug ( sprintf ( 'Processing special boundary header \'%s\'', $this->getBoundary () ) ); + $this->logger->debug( sprintf( 'Processing special boundary header \'%s\'', $this->getBoundary() ) ); } else { - $this->logger->debug ( sprintf ( 'Ignoring broken header \'%s\'', $header ) ); + $this->logger->debug( sprintf( 'Ignoring broken header \'%s\'', $header ) ); } continue; } - list ( $name, $content ) = explode ( ':', trim ( $header ), 2 ); - $this->processHeader ( $name, $content ); + list ( $name, $content ) = explode( ':', trim( $header ), 2 ); + $this->processHeader( $name, $content ); } } } - + /** * Add the headers that were processed in processHeaders() * Zend requires that several headers are specially handled. * - * @param unknown $name - * @param unknown $value - * @param Postman_Zend_Mail $mail + * @param unknown $name + * @param unknown $value + * @param Postman_Zend_Mail $mail */ - private function processHeader($name, $content) { - $name = trim ( $name ); - $content = trim ( $content ); - switch (strtolower ( $name )) { + private function processHeader( $name, $content ) { + $name = trim( $name ); + $content = trim( $content ); + switch ( strtolower( $name ) ) { case 'content-type' : - $this->logProcessHeader ( 'Content-Type', $name, $content ); - if (strpos ( $content, ';' ) !== false) { - list ( $type, $charset ) = explode ( ';', $content ); - $this->setContentType ( trim ( $type ) ); - if (false !== stripos ( $charset, 'charset=' )) { - $charset = trim ( str_replace ( array ( + $this->logProcessHeader( 'Content-Type', $name, $content ); + if ( strpos( $content, ';' ) !== false ) { + list ( $type, $charset ) = explode( ';', $content ); + $this->setContentType( trim( $type ) ); + if ( false !== stripos( $charset, 'charset=' ) ) { + $charset = trim( str_replace( array( 'charset=', - '"' + '"', ), '', $charset ) ); - } elseif (false !== stripos ( $charset, 'boundary=' )) { - $this->boundary = trim ( str_replace ( array ( + } elseif ( false !== stripos( $charset, 'boundary=' ) ) { + $this->boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', - '"' + '"', ), '', $charset ) ); $charset = ''; } - if (! empty ( $charset )) { - $this->setCharset ( $charset ); + if ( ! empty( $charset ) ) { + $this->setCharset( $charset ); } } else { - $this->setContentType ( trim ( $content ) ); + $this->setContentType( trim( $content ) ); } break; case 'to' : - $this->logProcessHeader ( 'To', $name, $content ); - $this->addTo ( $content ); + $this->logProcessHeader( 'To', $name, $content ); + $this->addTo( $content ); break; case 'cc' : - $this->logProcessHeader ( 'Cc', $name, $content ); - $this->addCc ( $content ); + $this->logProcessHeader( 'Cc', $name, $content ); + $this->addCc( $content ); break; case 'bcc' : - $this->logProcessHeader ( 'Bcc', $name, $content ); - $this->addBcc ( $content ); + $this->logProcessHeader( 'Bcc', $name, $content ); + $this->addBcc( $content ); break; case 'from' : - $this->logProcessHeader ( 'From', $name, $content ); - $this->setFrom ( $content ); + $this->logProcessHeader( 'From', $name, $content ); + $this->setFrom( $content ); break; case 'subject' : - $this->logProcessHeader ( 'Subject', $name, $content ); - $this->setSubject ( $content ); + $this->logProcessHeader( 'Subject', $name, $content ); + $this->setSubject( $content ); break; case 'reply-to' : - $this->logProcessHeader ( 'Reply-To', $name, $content ); - $this->setReplyTo ( $content ); + $this->logProcessHeader( 'Reply-To', $name, $content ); + $this->setReplyTo( $content ); break; case 'sender' : - $this->logProcessHeader ( 'Sender', $name, $content ); - $this->logger->warn ( sprintf ( 'Ignoring Sender header \'%s\'', $content ) ); + $this->logProcessHeader( 'Sender', $name, $content ); + $this->logger->warn( sprintf( 'Ignoring Sender header \'%s\'', $content ) ); break; case 'return-path' : - $this->logProcessHeader ( 'Return-Path', $name, $content ); - $this->logger->warn ( sprintf ( 'Ignoring Return-Path header \'%s\'', $content ) ); + $this->logProcessHeader( 'Return-Path', $name, $content ); + $this->logger->warn( sprintf( 'Ignoring Return-Path header \'%s\'', $content ) ); break; case 'date' : - $this->logProcessHeader ( 'Date', $name, $content ); - $this->setDate ( $content ); + $this->logProcessHeader( 'Date', $name, $content ); + $this->setDate( $content ); break; case 'message-id' : - $this->logProcessHeader ( 'Message-Id', $name, $content ); - $this->setMessageId ( $content ); + $this->logProcessHeader( 'Message-Id', $name, $content ); + $this->setMessageId( $content ); break; default : // Add it to our grand headers array - $this->logProcessHeader ( 'other', $name, $content ); - array_push ( $this->headers, array ( + $this->logProcessHeader( 'other', $name, $content ); + array_push( $this->headers, array( 'name' => $name, - 'content' => $content + 'content' => $content, ) ); break; } } - + /** * - * @param unknown $desc - * @param unknown $name - * @param unknown $content + * @param unknown $desc + * @param unknown $name + * @param unknown $content */ - private function logProcessHeader($desc, $name, $content) { - $this->logger->debug ( 'Processing ' . $desc . ' Header - ' . $name . ': ' . $content ); + private function logProcessHeader( $desc, $name, $content ) { + $this->logger->debug( 'Processing ' . $desc . ' Header - ' . $name . ': ' . $content ); } - + /** * Add attachments to the message * - * @param Postman_Zend_Mail $mail + * @param Postman_Zend_Mail $mail */ - public function addAttachmentsToMail(Postman_Zend_Mail $mail) { + public function addAttachmentsToMail( Postman_Zend_Mail $mail ) { $attachments = $this->attachments; - if (! is_array ( $attachments )) { + if ( ! is_array( $attachments ) ) { // WordPress may a single filename or a newline-delimited string list of multiple filenames - $attArray = explode ( PHP_EOL, $attachments ); + $attArray = explode( PHP_EOL, $attachments ); } else { $attArray = $attachments; } // otherwise WordPress sends an array foreach ( $attArray as $file ) { - if (! empty ( $file )) { - $this->logger->debug ( "Adding attachment: " . $file ); - $at = new Postman_Zend_Mime_Part ( file_get_contents ( $file ) ); + if ( ! empty( $file ) ) { + $this->logger->debug( 'Adding attachment: ' . $file ); + $at = new Postman_Zend_Mime_Part( file_get_contents( $file ) ); // $at->type = 'image/gif'; $at->disposition = Postman_Zend_Mime::DISPOSITION_ATTACHMENT; $at->encoding = Postman_Zend_Mime::ENCODING_BASE64; - $at->filename = basename ( $file ); - $mail->addAttachment ( $at ); + $at->filename = basename( $file ); + $mail->addAttachment( $at ); } } } - function setBody($body) { + function setBody( $body ) { $this->body = $body; } - function setBodyTextPart($bodyTextPart) { + function setBodyTextPart( $bodyTextPart ) { $this->bodyTextPart = $bodyTextPart; } - function setBodyHtmlPart($bodyHtmlPart) { + function setBodyHtmlPart( $bodyHtmlPart ) { $this->bodyHtmlPart = $bodyHtmlPart; } - function setSubject($subject) { + function setSubject( $subject ) { $this->subject = $subject; } - function setAttachments($attachments) { + function setAttachments( $attachments ) { $this->attachments = $attachments; } - function setFrom($email, $name = null) { - if (! empty ( $email )) { - $this->from = new PostmanEmailAddress ( $email, $name ); + function setFrom( $email, $name = null ) { + if ( ! empty( $email ) ) { + $this->from = new PostmanEmailAddress( $email, $name ); } } - function setReplyTo($replyTo) { - if (! empty ( $replyTo )) { - $this->replyTo = new PostmanEmailAddress ( $replyTo ); + function setReplyTo( $replyTo ) { + if ( ! empty( $replyTo ) ) { + $this->replyTo = new PostmanEmailAddress( $replyTo ); } } - function setMessageId($messageId) { + function setMessageId( $messageId ) { $this->messageId = $messageId; } - function setDate($date) { + function setDate( $date ) { $this->date = $date; } - + // return the headers public function getHeaders() { return $this->headers; |