* @license PHP License * @package WB * @subpackage MailMime */ WBClass::load('WBMail_Sendable' , 'WBMail_Mime_Storage' , 'WBMail_Mime_Part' , 'WBMail_Mime_Part_Address' , 'WBMail_Mime_Part_Attachment'); /** * Mime Mail data container class * * Simple data container class for mime e-mails * * @version 0.4.0 * @package WB * @subpackage MailMime */ class WBMail_Mime implements WBMail_Sendable { /** * Mime-mail id - default is "__new" * @var string */ protected $id = '__new'; /** * E-mail's subject * @var string */ protected $subject = ''; /** * Recipient * @var ndsMime-mailPart_Address */ protected $rcpt; /** * From address * @var ndsMime-mailPart_Address */ protected $from; /** * X-Sender address * @var ndsMime-mailPart_Address */ protected $xSender; /** * Return-Path address * @var ndsMime-mailPart_Address */ protected $returnPath; /** * reply to address * @var ndsMime-mailPart_Address */ protected $replyTo; /** * message's date * @var int timesamp */ protected $date; /** * generic e-mail header * @var array */ private $header; /** * plain text body * @var string */ protected $bodyPlain = ''; /** * HTML text body * @var string */ protected $bodyHtml = ''; /** * list of attachements * @var array */ protected $atts = array(); /** * deleted attachments * @var array */ protected $attsDel = array(); /** * Is the Mailer Template deletable or not? * * @var Integer */ protected $protected = 0; /** * Base64 encode string * * Auxilliary function to pack UTF-8 strings in base64 * * @param string $in * @return string */ public static function utf82base64($in) { return sprintf('=?utf-8?b?%s?=', base64_encode($in)); } /** * Fetch mail id * * @return string */ public function getId() { return $this->id; } /** * Set mail id * * @param string $id */ public function setId($id = '__new') { $this->id = $id; } /** * Get e-mail date * * Get date in ISO format * * @return string */ public function getDate() { $date = $this->date; if (empty($date)) { $date = time(); } return $date; } /** * Set e-mail's data * * Set date in ISO format * * @param string */ public function setDate($timestamp) { $this->date = $timestamp; } /** * Get e-mail subject * * @return string */ public function getSubject() { return $this->subject; } /** * Set e-mail subject * * @param string $subject */ public function setSubject($subject) { if (empty($subject)) { $subject = ''; } $this->subject = $subject; } /** * Set generic E-Mail-Header * * @param string * @param string */ public function setHeader($name, $value) { $this->header[$name] = $value; } /** * Get Generic E-Mail-Header * * @return array */ public function getHeader() { return $this->header; } /** * Set e-mail recipient * * @param WBMail_Mime_Part_Address */ public function setRcpt(WBMail_Mime_Part_Address $rcpt) { $this->rcpt = $rcpt; } /** * Get e-mail recipient * * @return WBMail_Mime_Part_Address */ public function getRcpt() { if (empty($this->rcpt)) { $this->rcpt = WBClass::create('WBMail_Mime_Part_Address'); } return $this->rcpt; } /** * Set e-mail from address * * @param WBMail_Mime_Part_Address */ public function setFrom(WBMail_Mime_Part_Address $from) { $this->from = $from; } /** * Get e-mail from address * * @return WBMail_Mime_Part_Address */ public function getFrom() { if (empty($this->from)) { $this->from = WBClass::create('WBMail_Mime_Part_Address'); } return $this->from; } /** * Set e-mail X-Sender address * * @param WBMail_Mime_Part_Address */ public function setXSender(WBMail_Mime_Part_Address $xSender) { $this->xSender = $xSender; } /** * Get e-mail x-sender address * * @return WBMail_Mime_Part_Address */ public function getXSender() { if (empty($this->xSender)) { $this->xSender = WBClass::create('WBMail_Mime_Part_Address'); } return $this->xSender; } /** * Set e-mail Return-Path address * * @param WBMail_Mime_Part_Address */ public function setReturnPath(WBMail_Mime_Part_Address $returnPath) { $this->returnPath = $returnPath; } /** * Get e-mail x-sender address * * @return WBMail_Mime_Part_Address */ public function getReturnPath() { if (empty($this->returnPath)) { $this->returnPath = WBClass::create('WBMail_Mime_Part_Address'); } return $this->returnPath; } /** * Set e-mail from address * * @param WBMail_Mime_Part_Address */ public function setReplyTo(WBMail_Mime_Part_Address $replyTo) { $this->replyTo = $replyTo; } /** * Get e-mail from address * * @return WBMail_Mime_Part_Address */ public function getReplyTo() { if (empty($this->replyTo)) { $this->replyTo = WBClass::create('WBMail_Mime_Part_Address'); } return $this->replyTo; } /** * Get e-mail's plain text body * * @return string */ public function getPlainBody() { return $this->bodyPlain; } /** * Set e-mail's plain body * * @param string */ public function setPlainBody($text) { if (empty($text)) { $text = ''; } $this->bodyPlain = $text; } /** * get e-mail's HTML body * * @return string */ public function getHtmlBody() { return $this->bodyHtml; } /** * set e-mail's HTML body * * @param string $html */ public function setHtmlBody( $html ) { if (empty($html)) { $html = ''; } $this->bodyHtml = $html; } /** * Get the delete protected flag * * --- no params --- * @return Integer $this->protected */ public function getFlagsProtected() { return $this->protected; } /** * Set the delete protected flag * * @param Integer $protected * @return void */ public function setFlagsProtected( $protected ) { $this->protected = 0; if ($protected == 1) { $this->protected = 1; } } /** * Add attachment to email * * @param WBMail_Mime_Part_Attachment $att */ public function addAttachment(WBMail_Mime_Part_Attachment $att) { $this->atts[] = $att; } /** * Get number of attachments * * @return int */ public function countAttachments() { return count($this->atts); } /** * Receive attachment * * Get e-mail attachment object * * @param int $index * @return WBMail_Mime_Part_Attachment */ public function getAttachment($index) { if (!isset($this->atts[$index])) { return; } return $this->atts[$index]; } /** * Get current attachments * * @return array WBMail_Mime_Part_Attachment */ public function getAttachments() { return $this->atts; } /** * Get removed attachments * * @return array WBMail_Mime_Part_Attachment */ public function getDeletedAttachments() { return $this->attsDel; } /** * Remove attachment * * Remove attachment from actual container * * @todo decide how to wipe out attachment data from storage * @param int $index */ public function deleteAttachment($index) { if (!isset($this->atts[$index])) { return; } $this->attsDel[] = $this->atts[$index]; unset($this->atts[$index]); $this->atts = array_values($this->atts); } }