public function send(MailMessage $m) { if (mail($m->getTo(), $m->getSubjectLine(), $m->getContent(), $m->getHeader())) { return true; } else { throw new Exception('Mail could not be sent.'); } }
/** * @param MailMessage $mimePart */ function SearchMimeParts(&$mimePart) { if ($mimePart->GetSubParts() == null) { $this->AddToCollection($mimePart); } else { for ($i = 0, $c = $mimePart->_subParts->List->Count(); $i < $c; $i++) { $subPart =& $mimePart->_subParts->List->Get($i); $this->SearchMimeParts($subPart); } } }
public function sendMessage(MailMessage $message) { @(require_once 'Mail.php'); $headers = array('From' => config::get('lepton.net.mail.from'), 'To' => join(',', $message->getRecipients()), 'Subject' => $message->getSubject()); $params = array('host' => config::get('lepton.net.mail.smtpserver', 'localhost'), 'port' => config::get('lepton.net.mail.smtpport', 25), 'localhost' => config::get('lepton.net.mail.localhost', 'localhost')); try { $omail =& Mail::factory('smtp', $params); $omail->send($message->getRecipients(), $headers, $message->getMessage()); } catch (Exception $e) { throw new MailException("Sending of mail failed"); } }
/** * Get Html Mail with a view. * @param type $mailView * @param type $params * @param type $to * @param type $from * @param type $subject * @return \flowcode\pachamama\domain\Mail * @throws MailViewException */ public static function getHtmlMail($mailView, $params, $to, $from, $subject) { if (file_exists($mailView)) { ob_start(); require_once $mailView; $body = ob_get_contents(); ob_end_clean(); } else { throw new MailViewException($mailView); } $mail = new MailMessage($to, $from, $body, $subject); $headers = "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n" . "From: =?UTF-8?B?" . base64_encode($params["from_name"]) . "?= <" . $from . ">\r\n" . "X-Mailer: PHP/" . phpversion(); $mail->setHeaders($headers); return $mail; }
/** * @covers flowcode\pachamama\domain\MailMessage::getPlainMail */ public function testgetPlainMail_simpleText_testOk() { $to = ""; $from = ""; $subject = ""; $body = "hello"; $mail = MailMessage::getPlainMail($to, $from, $body, $subject); $this->assertEquals($from, $mail->getFrom()); $this->assertEquals("hello", $mail->getBody()); }
public static function retrieve($id) { $box = self::getInstance(); $id = intval($id); if (!isset($box->indexes[$id])) { return null; } fseek($box->storage, $box->indexes[$id]['offset']); if (($mail = @fread($box->storage, $box->indexes[$id]['length'])) === false) { return false; } return MailMessage::parse($mail); }
/** * @param MailMessage $paren * @return MailMessage */ function &CreateNewMixedMail($paren = null) { $newMail =& new MailMessage(); if ($paren) { $newMail->Headers =& $paren->Headers; } $newMail->_subParts = new MimePartCollection($newMail); $newMail->_sourceCharset = $GLOBALS[MailOutputCharset]; $newBoundary = '--=_NextPart_' . md5(rand(100000, 999999)); $newMail->Headers->SetHeaderByName(MIMEConst_ContentType, MIMETypeConst_MultipartMixed . ';' . CRLF . "\t" . MIMEConst_BoundaryLower . '="' . $newBoundary . '"'); $newMail->Headers->DeleteHeaderByName(MIMEConst_ContentTransferEncoding); if ($paren->IsAlternative) { $alter =& $this->CreateNewAlternativeMail(); $newMail->_subParts->Add($alter); } else { if ($this->HasPlainText() || $this->HasHtmlText()) { $newMail->_subParts->Add($this->CreateNewTextMail()); } } if ($paren->HasAttachments()) { $attachs =& $this->Attachments; foreach ($attachs->Instance() as $att) { $newMail->_subParts->Add($att->MimePart); } } return $newMail; }
function create_message(&$headers, &$message, &$attachments, $for_draft = false, $via_smtp = false) { $to = str_replace(";", ",", $_POST["to"]); $cc = str_replace(";", ",", $_POST["cc"]); $bcc = str_replace(";", ",", $_POST["bcc"]); $subject = $_POST["subject"]; $message = $_POST["message"]; $mailcwp_session = mailcwp_get_session(); if (!isset($mailcwp_session) || empty($mailcwp_session)) { return; } $account = $mailcwp_session["account"]; $from = "{$account['name']} <{$account['email']}>"; $mbox_name = "{$account['host']}:{$account['port']}"; $use_ssl = $account["use_ssl"]; $validate_cert = $account["validate_cert"]; $username = $account["username"]; $password = $account["password"]; $use_tls = $account["use_tls"]; $folder = $mailcwp_session["folder"]; $unique_id = $_POST["unique_id"]; $original = isset($_POST["original"]) ? $_POST["original"] : -1; $use_ssl_flag = $use_ssl === "true" ? "/ssl" : ""; $validate_cert_flag = $validate_cert === "true" ? "" : "/novalidate-cert"; $use_tls_flag = $use_tls === "true" ? "/tls" : ""; if ($original > 0) { $mbox = mailcwp_imap_connect($account, 0, $folder); $mail_message = new MailMessage($mbox, $original); $forward_attachments = $mail_message->getAttachments(); } else { $forward_attachments = array(); } $timezone = null; if (array_key_exists("timezone", $account)) { $tz_name = $account["timezone"]; if (!empty($tz_name)) { $timezone = new DateTimeZone($tz_name); } } $now = new DateTime(); if (isset($timezone)) { $now->setTimeZone($timezone); } $headers = "From: {$from}\r\n" . "Date: " . $now->format("D, d-M-Y H:i:s O") . "\r\n" . "Reply-To: {$from}\r\n" . "X-Mailer: MailCWP " . MAILCWP_VERSION . "\r\n"; if ($for_draft) { $headers .= "To: {$to}\r\n" . "Subject: {$subject}\r\n"; } if (!empty($cc)) { $headers .= "Cc: {$cc}\r\n"; } if (!empty($bcc)) { $headers .= "Bcc: {$bcc}\r\n"; } //This test for the composer is a workaround //This logic must be refactored to correctly handle plain text/html //composing and sending $plugin_base_path = plugin_dir_path(__FILE__) . "../"; $composer_installed = file_exists($plugin_base_path . "mailcwp-composer"); if ($composer_installed) { if (strpos($message, "<p>") === FALSE) { $message = nl2br($message); //, htmlspecialchars($message, ENT_COMPAT, "UTF-8", false)); } } $plain_text_message = preg_replace("/<br[^>]*[\\/]{0,1}>/i", "\n", $message); $plain_text_message = preg_replace("/<\\/li>/i", "\n", $plain_text_message); $plain_text_message = preg_replace("/<p[^>]*[\\/]{0,1}>/i", "\n\n", $plain_text_message); $plain_text_message = preg_replace("/<\\/[ou]l>/i", "\n", $plain_text_message); $plain_text_message = html_entity_decode($plain_text_message); $plain_text_message = strip_tags($plain_text_message); $upload_dir = wp_upload_dir(); $mailcwp_upload_dir = "{$upload_dir['basedir']}/mailcwp/uploads"; $uploaded_files = glob("{$mailcwp_upload_dir}/{$unique_id}-*"); if ($via_smtp) { $attachments = array(); if (is_array($uploaded_files)) { foreach ($uploaded_files as $uploaded_file) { $attachments[] = $uploaded_file; } } } else { if (is_array($uploaded_files) && count($uploaded_files) > 0 || !empty($forward_attachments)) { $part2["type"] = TYPETEXT; $part2["subtype"] = "html"; $part2["contents.data"] = $message; $boundary = "------=" . md5(uniqid(rand())); $headers .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\r\n"; $message = "\r\n\r\n--{$boundary}\r\nContent-Type: text/html; charset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: 8bit \r\n\r\n\r\n" . stripslashes($message); //process attachments //find files //if files found, read each one and generate attachment string if (is_array($uploaded_files)) { foreach ($uploaded_files as $uploaded_file) { $basename = substr(basename($uploaded_file), strlen($unique_id) + 1); $message .= "\r\n\r\n"; $message .= "--{$boundary}\r\n"; $message .= "Content-Transfer-Encoding: base64\r\n"; $message .= "Content-Disposition: attachment; filename=\"{$basename}\"\r\n"; $message .= "\r\n" . chunk_split(base64_encode(file_get_contents($uploaded_file))) . "\r\n"; unlink($uploaded_file); } } if (!empty($forward_attachments)) { foreach ($forward_attachments as $forward_filename => $forward_data) { $message .= "\r\n\r\n"; $message .= "--{$boundary}\r\n"; $message .= "Content-Transfer-Encoding: base64\r\n"; $message .= "Content-Disposition: attachment; filename=\"{$forward_filename}\"\r\n"; $message .= "\r\n" . chunk_split(base64_encode($forward_data)) . "\r\n"; } } $message .= "\r\n\r\n\r\n--{$boundary}--\r\n\r\n"; } else { $boundary = "------=" . md5(uniqid(rand())); $headers .= "Content-Type: multipart/alternative; boundary=\"{$boundary}\"\r\n"; $message = "\r\n\r\n--{$boundary}\r\nContent-Type: text/plain;\r\n\tcharset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: 8bit \r\n\r\n\r\n" . stripslashes($plain_text_message) . "\r\n\r\n--{$boundary}\r\nContent-Type: text/html;\r\n\tcharset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: 8bit \r\n\r\n\r\n" . stripslashes($message); $message .= "\r\n\r\n\r\n--{$boundary}--\r\n\r\n"; } } return true; }
/** * @param bool $isClear optional * @return string */ function GetReplyToAsString($isClear = false) { $value = MailMessage::GetReplyToAsString(); if ($isClear) { $value = WebMailMessage::ClearForSend($value); } return $value; }
/** * 初期データを読み込む * * @param string $dbDataPattern 初期データのパターン * @param string $currentTheme テーマ名 * @return bool */ protected function _load_default_data_pattern($dbDataPattern, $currentTheme = '') { list($theme, $pattern) = explode('.', $dbDataPattern); if (!$this->BcManager->checkDefaultDataPattern($pattern, $theme)) { $this->setMessage('初期データのバージョンが違うか、初期データの構造が壊れています。', true); return false; } $excludes = array('plugins', 'dblogs', 'users'); $User = ClassRegistry::init('User'); /* データを削除する */ $this->BcManager->resetAllTables(null, $excludes); $result = true; /* コアデータ */ if (!$this->BcManager->loadDefaultDataPattern('default', null, $pattern, $theme, 'core', $excludes)) { $result = false; $this->log($dbDataPattern . " の初期データのロードに失敗しました。"); } /* プラグインデータ */ $corePlugins = Configure::read('BcApp.corePlugins'); $plugins = array_merge($corePlugins, BcUtil::getCurrentThemesPlugins()); foreach ($plugins as $plugin) { $this->BcManager->loadDefaultDataPattern('default', null, $pattern, $theme, $plugin, $excludes); } if (!$result) { /* 指定したデータセットでの読み込みに失敗した場合、コアのデータ読み込みを試みる */ if (!$this->BcManager->loadDefaultDataPattern('default', null, 'default', 'core', 'core', $excludes)) { $this->log("コアの初期データのロードに失敗しました。"); $result = false; } foreach ($corePlugins as $corePlugin) { if (!$this->BcManager->loadDefaultDataPattern('default', null, 'default', 'core', $corePlugin, $excludes)) { $this->log("コアのプラグインの初期データのロードに失敗しました。"); $result = false; } } if ($result) { $this->setMessage('初期データの読み込みに失敗しましたので baserCMSコアの初期データを読み込みました。', true); } else { $this->setMessage('初期データの読み込みに失敗しました。データが不完全な状態です。正常に動作しない可能性があります。', true); } } clearAllCache(); // メール受信テーブルの作成 App::uses('MailMessage', 'Mail.Model'); $MailMessage = new MailMessage(); if (!$MailMessage->reconstructionAll()) { $this->log('メールプラグインのメール受信用テーブルの生成に失敗しました。'); $result = false; } clearAllCache(); ClassRegistry::flush(); BcSite::flash(); if ($currentTheme) { $siteConfigs = array('SiteConfig' => array('theme' => $currentTheme)); $this->SiteConfig->saveKeyValue($siteConfigs); } if (!$this->Page->createAllPageTemplate()) { $result = false; $this->log('初期データの読み込み中にページテンプレートの生成に失敗しました。' . '「Pages」フォルダに書き込み権限が付与されていない可能性があります。' . '権限設定後、テーマの適用をやり直すか、表示できないページについて固定ページ管理より更新処理を行ってください。'); } // システムデータの初期化 // TODO $this->BcManager->initSystemData() は、$this->Page->createAllPageTemplate() の // 後に呼出さないと $this->Page の実体が何故か AppModel にすりかわってしまい、 // createAllPageTemplate メソッドが呼び出せないので注意 if (!$this->BcManager->initSystemData(null, array('excludeUsers' => true))) { $result = false; $this->log('システムデータの初期化に失敗しました。'); } // ユーザーデータの初期化 $UserGroup = ClassRegistry::init('UserGroup'); $adminGroupId = $UserGroup->field('id', array('UserGroup.name' => 'admins')); $users = $User->find('all', array('recursive' => -1)); foreach ($users as $user) { $user['User']['user_group_id'] = $adminGroupId; unset($user['User']['password']); if (!$User->save($user)) { $result = false; $this->log('ユーザーデータの初期化に失敗しました。手動で各ユーザーのユーザーグループの設定を行なってください。'); } if (!$User->applyDefaultFavorites($user['User']['id'], $user['User']['user_group_id'])) { $result = false; $this->log('ユーザーのよく使う項目データの初期化に失敗しました。手動で各ユーザーのよく使う項目の設定を行なってください。'); } } $Db = ConnectionManager::getDataSource('default'); if ($Db->config['datasource'] == 'Database/BcPostgres') { $Db->updateSequence(); } // システム基本設定の更新 $siteConfigs = array('SiteConfig' => array('email' => $this->siteConfigs['email'], 'google_analytics_id' => $this->siteConfigs['google_analytics_id'], 'first_access' => null, 'version' => $this->siteConfigs['version'])); $this->SiteConfig->saveKeyValue($siteConfigs); return $result; }
/** * sendAdminNotification * * @param mixed $msgText Text message to send. * * @access public * @return void */ public function sendAdminNotification($msgText) { $message = new MailMessage(); $message->setSubject('Native5 Server : P1 Issue'); $message->setBody($msgText); $mReceipents = array(); $mReceipents[] = '*****@*****.**'; $message->setRecipients($mReceipents); $this->sendNotification(array(Notifier::TYPE_EMAIL), $message); }
$username = $download_data[3]; $password = $download_data[4]; $use_tls = $download_data[5]; $folder = $download_data[6]; $msg_number = (int) $download_data[7]; $attachment_name = $download_data[8]; imap_timeout(15, IMAP_OPENTIMEOUT); imap_timeout(15, IMAP_READTIMEOUT); imap_timeout(15, IMAP_WRITETIMEOUT); imap_timeout(15, IMAP_CLOSETIMEOUT); $use_ssl_flag = $use_ssl == "true" ? "/ssl" : ""; $validate_cert_flag = $validate_cert == "true" ? "" : "/novalidate-cert"; $use_tls_flag = $use_tls == "true" ? "/tls" : ""; $mbox = imap_open("{" . $mbox_name . $use_ssl_flag . $validate_cert_flag . $use_tls_flag . "}{$folder}", $username, $password); //print_r(imap_errors()); $message = new MailMessage($mbox, $msg_number); //print_r($message); $attachments = $message->getAttachments(); //print_r($attachments); $download_data = null; if ($attachment_name == '*') { if (class_exists("ZipArchive")) { $attachment_name = "{$download_dir}/attachments-{$msg_number}.zip"; $zip = new ZipArchive(); $zip->open($attachment_name, ZipArchive::CREATE); foreach ($attachments as $filename => $data) { $zip->addFromString($filename, $data); } $zip->close(); $download_data = file_get_contents($attachment_name); unlink($attachment_name);
/** Replace placeholders in a string or in an array * @param string|string[] $data */ protected function _replace_placeholders($data) { return MailMessage::replacePlaceholders($this->message->placeholders, $data); }
* * @copyright Copyright (c) baserCMS Users Community * @link http://basercms.net baserCMS Project * @package Mail.Config * @since baserCMS v 0.1.0 * @license http://basercms.net/license/index.html */ /** * データベース初期化 */ $this->Plugin->initDb('Mail'); /** * メッセージテーブル構築 */ App::uses('MailMessage', 'Mail.Model'); $MailMessage = new MailMessage(); $MailMessage->reconstructionAll(); /** * 必要フォルダ初期化 */ $filesPath = WWW_ROOT . 'files'; $savePath = $filesPath . DS . 'mail'; $limitedPath = $savePath . DS . 'limited'; if (is_writable($filesPath) && !is_dir($savePath)) { mkdir($savePath); } if (!is_writable($savePath)) { chmod($savePath, 0777); } if (is_writable($savePath) && !is_dir($limitedPath)) { mkdir($limitedPath);
/** * parse header of current mail message * * @since 0.1 * @access protected * @return void * @param MailMessage $mail */ protected function _parseHeader(MailMessage $mail) { $data = imap_header($this->handle, $this->current); $mail->setMessageId($data->message_id); $mail->setSubject($data->subject); $mail->setDate($data->date); $from = $this->_transformAdress($data->from[0]); $seen = $data->Recent == 'N' || $data->Unseen == 'U' ? false : true; $mail->setFrom($from[0], $from[1]); $mail->setRecent($data->Recent == '' ? false : true); $mail->setSeen($seen); if (isset($data->to)) { foreach ($data->to as $adress) { $adress = $this->_transformAdress($adress); $mail->addTo($adress[0], $adress[1]); } } if (isset($data->cc)) { foreach ($data->cc as $adress) { $adress = $this->_transformAdress($adress); $mail->addCc($adress[0], $adress[1]); } } if (isset($data->bcc)) { foreach ($data->bcc as $adress) { $adress = $this->_transformAdress($adress); $mail->addBcc($adress[0], $adress[1]); } } if (isset($data->return_path)) { foreach ($data->return_path as $adress) { $adress = $this->_transformAdress($adress); $mail->addReplyTo($adress[0], $adress[1]); } } }
private function addAttachments(MailMessage $message, $message_number) { $structure = imap_fetchstructure($this->box, $message_number); $message->addAttachment($this->getAttachments($structure)); }