/** * Custom email function for creating an email message in ISO-2022-JP */ function CUSTOM_mail($to, $subject, $message, $from = '', $html = false, $priority = 0, $cc = '') { global $_CONF, $LANG_CHARSET; static $mailobj; include_once 'Mail.php'; include_once 'Mail/RFC822.php'; if (defined('CUSTOM_MAIL_DEBUG')) { COM_errorLog('CUSTOM_mail: to=' . $to . ' subject=' . $subject); } // 余分なヘッダを追加されないように改行コードを削除 $to = substr($to, 0, strcspn($to, "\r\n")); $cc = substr($cc, 0, strcspn($cc, "\r\n")); $from = substr($from, 0, strcspn($from, "\r\n")); $subject = substr($subject, 0, strcspn($subject, "\r\n")); // Fromが空の場合は、サイト管理者のアドレスにする if (empty($from)) { $from = COM_formatEmailAddress($_CONF['site_name'], $_CONF['site_mail']); } // ヘッダをエスケープ(1.5.2では、この時点でエスケープ済み) // NOTE: version_compare(VERSION, '1.5.2')とすると、security releaseでは // 判定に失敗する preg_match("/^(\\d+\\.\\d+\\.\\d+).*\$/", VERSION, $match); if (version_compare($match[1], '1.5.2') < 0) { list($temp_to_comment, $temp_to_address) = CUSTOM_splitAddress($to); $to = CUSTOM_formatEmailAddress($temp_to_comment, $temp_to_address); list($temp_cc_comment, $temp_cc_address) = CUSTOM_splitAddress($cc); $cc = CUSTOM_formatEmailAddress($temp_cc_comment, $temp_cc_address); list($temp_from_comment, $temp_from_address) = CUSTOM_splitAddress($from); $from = CUSTOM_formatEmailAddress($temp_from_comment, $temp_from_address); $subject = CUSTOM_emailEscape($subject); } // 本文をエスケープ $message = CUSTOM_convertEncoding($message, CUSTOM_MAIL_ENCODING); $message = str_replace(array("\r\n", "\n", "\r"), CUSTOM_MAIL_BODY_LINEBREAK, $message); // メールオブジェクトを作成 $method = $_CONF['mail_settings']['backend']; if (!isset($mailobj)) { if ($method === 'sendmail' or $method === 'smtp') { $mailobj =& Mail::factory($method, $_CONF['mail_settings']); } else { $mailobj =& Mail::factory($method); } } // ヘッダ組み立て $headers = array(); $headers['From'] = $from; if ($method != 'mail') { $headers['To'] = $to; } if (!empty($cc)) { $headers['Cc'] = $cc; } $headers['Date'] = date('r'); // RFC822 formatted date if ($method === 'smtp') { list($usec, $sec) = explode(' ', microtime()); $m = substr($usec, 2, 5); $headers['Message-Id'] = '<' . date('YmdHis') . '.' . $m . '@' . $_CONF['mail_settings']['host'] . '>'; } if ($html) { $headers['Content-Type'] = 'text/html; charset=' . CUSTOM_MAIL_ENCODING; $headers['Content-Transfer-Encoding'] = '8bit'; } else { $headers['Content-Type'] = 'text/plain; charset=' . CUSTOM_MAIL_ENCODING; } $headers['Subject'] = $subject; if ($priority > 0) { $headers['X-Priority'] = $priority; } $headers['X-Mailer'] = 'Geeklog-' . VERSION . ' (' . CUSTOM_MAIL_ENCODING . ')'; $retval = $mailobj->send($to, $headers, $message); if ($retval !== true) { COM_errorLog($retval->toString(), 1); } return $retval === true; }
/** * Encode a string such that it can be used in an email header * * @param string $string the text to be encoded * @return string encoded text * */ function COM_emailEscape($string) { global $_CONF; if (function_exists('CUSTOM_emailEscape')) { return CUSTOM_emailEscape($string); } $charset = COM_getCharset(); if ($charset == 'utf-8' && $string != utf8_decode($string)) { if (function_exists('iconv_mime_encode')) { $mime_parameters = array('input-charset' => 'utf-8', 'output-charset' => 'utf-8', 'scheme' => 'Q'); $string = substr(iconv_mime_encode('', $string, $mime_parameters), 2); } else { $string = '=?' . $charset . '?B?' . base64_encode($string) . '?='; } } else { if (preg_match('/[^0-9a-z\\-\\.,:;\\?! ]/i', $string)) { $string = '=?' . $charset . '?B?' . base64_encode($string) . '?='; } } return $string; }
/** * Encode a string such that it can be used in an email header * * @param string $string the text to be encoded * @return string encoded text * @deprecated since Geeklog-2.1.2 */ function COM_emailEscape($string) { if (function_exists('CUSTOM_emailEscape')) { return CUSTOM_emailEscape($string); } $charset = COM_getCharset(); if ($charset === 'utf-8' && $string !== utf8_decode($string)) { // Current hack to bypass the use of iconv_mime_encode until proper fix found // In some cases emails being sent fail when using COM_Mail when the email subject contain certain characters in another language (like Japanese) // This bug usually happens when the Geeklog forum sends out a notification email of a reply to a topic. // For more info see https://github.com/Geeklog-Core/geeklog/issues/684 if (false) { //if (function_exists('iconv_mime_encode')) { $mime_parameters = array('input-charset' => 'utf-8', 'output-charset' => 'utf-8', 'scheme' => 'Q'); $string = substr(iconv_mime_encode('', $string, $mime_parameters), 2); } else { $string = '=?' . $charset . '?B?' . base64_encode($string) . '?='; } } elseif (preg_match('/[^0-9a-z\\-\\.,:;\\?! ]/i', $string)) { $string = '=?' . $charset . '?B?' . base64_encode($string) . '?='; } return $string; }