* @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.1.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; /** * message's date * @var int timesamp */ protected $date; /** * 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($data)) { $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; } /** * 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 recipient * * @param WBMail_Mime_Part_Address */ public function setRcpt(WBMail_Mime_Part_Address $rcpt) { $this->rcpt = $rcpt; } /** * 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 from address * * @param WBMail_Mime_Part_Address */ public function setFrom(WBMail_Mime_Part_Address $from) { $this->from = $from; } /** * 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); } }