public function __construct(Zend_Mail_Message $message) { $controller = $message->getHeader('to', 'string'); $controller = $this->formatControllerName($controller); $this->setParam($this->getControllerKey(), $controller); $action = $message->getHeader('subject', 'string'); $action = $this->formatActionName($action); $this->setParam($this->getActionKey(), $action); $params = $message->getContent(); $params = $this->formatParams($params); foreach ($params as $key => $value) { $this->setParam($key, $value); } }
public function getHeader($name, $format = null) { $result = parent::getHeader($name, $format); if ('array' !== $format && function_exists('mb_decode_mimeheader')) { $result = mb_decode_mimeheader($result); } if ('from' === strtolower($name) || 'to' === strtolower($name)) { $result = $this->extractAddrSpec($result); } return $result; }
/** * get meta data (like contentype, charset, ...) from zmm and set it in zmp * * @param Zend_Mail_Message $zmm * @param Zend_Mime_Part $zmp */ protected static function _getMetaDataFromZMM(Zend_Mail_Message $zmm, Zend_Mime_Part $zmp) { if ($zmm->headerExists('content-transfer-encoding')) { $zmp->encoding = $zmm->getHeader('content-transfer-encoding'); } else { $zmp->encoding = Zend_Mime::ENCODING_7BIT; } if ($zmm->headerExists('content-type')) { $contentTypeHeader = Zend_Mime_Decode::splitHeaderField($zmm->getHeader('content-type')); $zmp->type = $contentTypeHeader[0]; if (isset($contentTypeHeader['boundary'])) { $zmp->boundary = $contentTypeHeader['boundary']; } if (isset($contentTypeHeader['charset'])) { $zmp->charset = $contentTypeHeader['charset']; } } else { $zmp->type = Zend_Mime::TYPE_TEXT; } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Encoding: ' . $zmp->encoding . ' / type: ' . $zmp->type . ' / charset: ' . $zmp->charset); } }
/** * メール読み取り */ public static function readMail() { // 標準入力から読み取り $message = new Zend_Mail_Message(array('file' => 'php://stdin')); $obj = array(); // 差出人 $obj['from'] = self::getMailAddress($message->from); // 宛先 $obj['to'] = self::getMailAddress($message->to); // 件名 if ($message->getHeader('subject')) { $obj['subject'] = $message->subject; } else { $obj['subject'] = ''; } // 本文 $obj['body'] = $message->getContent(); // 不正なメールアドレスなので無視 if (preg_match("/^MAILER\\-DAEMON\\@/i", $obj['from']) || preg_match("/^postmaster\\@/i", $obj['from']) || $obj['from'] === '*****@*****.**' || strlen($obj['from']) === 0 || !preg_match("/.+\\@[a-zA-Z0-9][a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]+\$/", $obj['from'])) { exit; } // 添付ファイル処理 if ($message->isMultipart()) { // 添付ファイル数 $obj['files'] = $message->countParts() - 1; // 添付ファイル for ($i = 2; $i <= $message->countParts(); $i++) { $obj['files_type_' . ($i - 2)] = $message->getPart($i)->getHeader('content-type'); $obj['files_body_' . ($i - 2)] = $message->getPart($i)->getContent(); } } else { // 添付ファイル数 $obj['files'] = 0; } return $obj; }
public function testMultipleHeader() { $raw = file_get_contents($this->_file); $raw = "sUBject: test\nSubJect: test2\n" . $raw; $message = new Zend_Mail_Message(array('raw' => $raw)); $this->assertEquals($message->getHeader('subject', 'string'), "test\r\ntest2\r\nmultipart"); $this->assertEquals($message->getHeader('subject'), array('test', 'test2', 'multipart')); }
/** * send email * * @param resource $inputStream * @param boolean $saveInSent * @throws Syncroton_Exception */ public function sendEmail($inputStream, $saveInSent) { $defaultAccountId = Tinebase_Core::getPreference('Expressomail')->{Expressomail_Preference::DEFAULTACCOUNT}; try { $account = Expressomail_Controller_Account::getInstance()->get($defaultAccountId); } catch (Tinebase_Exception_NotFound $ten) { if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " no email account configured"); } throw new Syncroton_Exception('no email account configured'); } if (empty(Tinebase_Core::getUser()->accountEmailAddress)) { throw new Syncroton_Exception('no email address set for current user'); } if (!is_resource($inputStream)) { $stream = fopen("php://temp", 'r+'); fwrite($stream, $inputStream); $inputStream = $stream; rewind($inputStream); } if ($this->_debugEmail == true) { $debugStream = fopen("php://temp", 'r+'); stream_copy_to_stream($inputStream, $debugStream); rewind($debugStream); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " email to send:" . stream_get_contents($debugStream)); } //replace original stream wirh debug stream, as php://input can't be rewinded $inputStream = $debugStream; rewind($inputStream); } $incomingMessage = new Zend_Mail_Message(array('file' => $inputStream)); $subject = $incomingMessage->headerExists('subject') ? $incomingMessage->getHeader('subject') : null; if (Tinebase_Mail::isiMIPMail($incomingMessage)) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Do not send iMIP message with subject "' . $subject . '". The server should handle those.'); } } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Send Message with subject " . $subject . " (saveInSent: " . $saveInSent . ")"); } $mail = Tinebase_Mail::createFromZMM($incomingMessage); Expressomail_Controller_Message_Send::getInstance()->sendZendMail($account, $mail, (bool) $saveInSent); } }
/** * create Tinebase_Mail from Zend_Mail_Message * * @param Zend_Mail_Message $_zmm * @param string $_replyBody * @return Tinebase_Mail */ public static function createFromZMM(Zend_Mail_Message $_zmm, $_replyBody = null) { $contentStream = fopen("php://temp", 'r+'); if (preg_match('/application\\/(x\\-){0,1}pkcs7-mime/i', $_zmm->getHeader('content-type')) > 0) { $mp = new Zend_Mime_Part($_zmm->getContent()); } else { fputs($contentStream, $_zmm->getContent()); rewind($contentStream); $mp = new Zend_Mime_Part($contentStream); } if ($_zmm->headerExists('content-transfer-encoding')) { $mp->encoding = $_zmm->getHeader('content-transfer-encoding'); $mp->decodeContent(); } else { $mp->encoding = Zend_Mime::ENCODING_7BIT; } // append old body when no multipart/mixed if ($_replyBody !== null && $_zmm->headerExists('content-transfer-encoding')) { $mp = self::_appendReplyBody($mp, $_replyBody); $mp->encoding = $_zmm->getHeader('content-transfer-encoding'); } if ($_zmm->headerExists('content-type')) { $contentTypeHeader = Zend_Mime_Decode::splitHeaderField($_zmm->getHeader('content-type')); if ($mp->type = strtolower($contentTypeHeader[0]) === 'application/pkcs7-mime') { $mp->type = $_zmm->getHeader('content-type'); } else { $mp->type = $contentTypeHeader[0]; } if (isset($contentTypeHeader['boundary'])) { $mp->boundary = $contentTypeHeader['boundary']; } if (isset($contentTypeHeader['charset'])) { $mp->charset = $contentTypeHeader['charset']; } } else { $mp->type = Zend_Mime::TYPE_TEXT; } $result = new Expressomail_Mail('utf-8'); $result->setBodyText($mp); foreach ($_zmm->getHeaders() as $header => $values) { foreach ((array) $values as $value) { switch ($header) { case 'content-transfer-encoding': // these are implicitly set by Zend_Mail_Transport_Abstract::_getHeaders() // these are implicitly set by Zend_Mail_Transport_Abstract::_getHeaders() case 'content-type': case 'mime-version': // do nothing break; case 'bcc': $addresses = Expressomail_Message::parseAdresslist($value); foreach ($addresses as $address) { $result->addBcc($address['address'], $address['name']); } break; case 'cc': $addresses = Expressomail_Message::parseAdresslist($value); foreach ($addresses as $address) { $result->addCc($address['address'], $address['name']); } break; case 'date': try { $result->setDate($value); } catch (Zend_Mail_Exception $zme) { if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " Could not set date: " . $value); } if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " " . $zme); } $result->setDate(); } break; case 'from': $addresses = Expressomail_Message::parseAdresslist($value); foreach ($addresses as $address) { $result->setFrom($address['address'], $address['name']); } break; case 'message-id': $result->setMessageId($value); break; case 'return-path': $result->setReturnPath($value); break; case 'subject': $result->setSubject($value); break; case 'to': $addresses = Expressomail_Message::parseAdresslist($value); foreach ($addresses as $address) { $result->addTo($address['address'], $address['name']); } break; default: $result->addHeader($header, $value); break; } } } return $result; }