本文整理汇总了PHP中iconv_mime_decode_headers函数的典型用法代码示例。如果您正苦于以下问题:PHP iconv_mime_decode_headers函数的具体用法?PHP iconv_mime_decode_headers怎么用?PHP iconv_mime_decode_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iconv_mime_decode_headers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unset
EOF;
$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR;
$charset = 'UTF-8';
//get an unset variable
$unset_var = 10;
unset($unset_var);
// get a class
class classA
{
public function __toString()
{
return "Class A object";
}
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// unexpected values to be passed to $str argument
$inputs = array(0, 1, 12345, -2345, 10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5, NULL, null, true, false, TRUE, FALSE, "", '', "string", 'string', $heredoc, new classA(), @$undefined_var, @$unset_var, $fp);
// loop through each element of $inputs to check the behavior of iconv_mime_decode_headers()
$iterator = 1;
foreach ($inputs as $input) {
echo "\n-- Iteration {$iterator} --\n";
var_dump(iconv_mime_decode_headers($headers, $input, $charset));
$iterator++;
}
fclose($fp);
echo "Done";
示例2: splitMessage
/**
* split a message in header and body part, if no header or an
* invalid header is found $headers is empty
*
* The charset of the returned headers depend on your iconv settings.
*
* @param string $message raw message with header and optional content
* @param array $headers output param, array with headers as array(name => value)
* @param string $body output param, content of message
* @param string $EOL EOL string; defaults to {@link Zend_Mime::LINEEND}
* @return null
*/
public static function splitMessage($message, &$headers, &$body, $EOL = Zend_Mime::LINEEND)
{
// check for valid header at first line
$firstline = strtok($message, "\n");
if (!preg_match('%^[^\\s]+[^:]*:%', $firstline)) {
$headers = array();
// TODO: we're ignoring \r for now - is this function fast enough and is it safe to asume noone needs \r?
$body = str_replace(array("\r", "\n"), array('', $EOL), $message);
return;
}
// find an empty line between headers and body
// default is set new line
if (strpos($message, $EOL . $EOL)) {
list($headers, $body) = explode($EOL . $EOL, $message, 2);
// next is the standard new line
} else {
if ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
list($headers, $body) = explode("\r\n\r\n", $message, 2);
// next is the other "standard" new line
} else {
if ($EOL != "\n" && strpos($message, "\n\n")) {
list($headers, $body) = explode("\n\n", $message, 2);
// at last resort find anything that looks like a new line
} else {
@(list($headers, $body) = @preg_split("%([\r\n]+)\\1%U", $message, 2));
}
}
}
$headers = iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
if ($headers === false) {
// an error occurs during the decoding
return;
}
// normalize header names
foreach ($headers as $name => $header) {
$lower = strtolower($name);
if ($lower == $name) {
continue;
}
unset($headers[$name]);
if (!isset($headers[$lower])) {
$headers[$lower] = $header;
continue;
}
if (is_array($headers[$lower])) {
$headers[$lower][] = $header;
continue;
}
$headers[$lower] = array($headers[$lower], $header);
}
}
示例3: var_dump
<?php
$headers = <<<HERE
Return-Path: <internals-return-5651-***=***.example.com@lists.php.net>
Received: from pb1.pair.com (pb1.pair.com [16.92.131.4]) by ***.example.com
(8.12.10/8.12.10/1970-09-30) with SMTP id hALLmpea023899 for
<***@***.example.com>; Sat, 22 Jan 1970 06:48:51 +0900 (JST)
(envelope-from
internals-return-5651-***=***.example.com@lists.php.net)
Received: (qmail 63472 invoked by uid 1010); 1 Jan 1970 0:00:00 -0000
Mailing-List: contact internals-help@lists.php.net; run by ezmlm
Precedence: bulk
List-Help: <mailto:internals-help@lists.php.net>
List-Unsubscribe: <mailto:internals-unsubscribe@lists.php.net>
List-Post: <mailto:internals@lists.php.net>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 63459 invoked by uid 1010); 1 Jan 1970 0:00:00 -0000
Delivered-To: ezmlm-scan-internals@lists.php.net
Delivered-To: ezmlm-internals@lists.php.net
Date: Thu, 1 Jan 1970 00:00:00 -0000 (GMT)
From: *** *** *** <***@***.example.com>
X-X-Sender: ***@***.example.com
To: internals@lists.php.net
Message-Id: <Pine.LNX.4.58.************@***.example.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Subject: [PHP-DEV] [ICONV] test for =?US-ASCII?Q?iconv_mime_decode_headers=28=29?=
X-UIDL: @eH!!h2:!!EOS!!A_c"!
HERE;
var_dump(iconv_mime_decode_headers($headers));
示例4: transform
/**
* @inherit Conjoon_Text_Transformer::transform
*/
public function transform($input)
{
$data = array('input' => $input);
/**
* @see Conjoon_Argument_Check
*/
require_once 'Conjoon/Argument/Check.php';
Conjoon_Argument_Check::check(array('input' => array('allowEmpty' => true, 'type' => 'string')), $data);
$value = $data['input'];
if ($value === "") {
return "";
}
$bid = '?q?';
$q = stripos($value, '?q?');
if ($q === false) {
$q = stripos($value, '?b?');
if ($q === false) {
return $value;
}
$bid = '?b?';
}
$ms = array(trim($value));
$usedSpace = false;
if (strpos($value, "\r\n") !== false) {
$ms = explode("\r\n", $value);
} else {
if (strpos($value, "\r") !== false) {
$ms = explode("\r", $value);
} else {
if (strpos($value, "\n") !== false) {
$ms = explode("\n", $value);
} else {
if (strpos(trim($value), " ") !== false) {
$usedSpace = true;
$ms = explode(" ", trim($value));
}
}
}
}
$len = count($ms);
$spec = "";
if ($len > 1) {
$index = -1;
for ($i = 0; $i < $len; $i++) {
$ms[$i] = $ms[$i];
if (stripos($ms[$i], $bid) !== false) {
if (strpos($ms[$i], '=') === 0) {
$spec = ' ';
} else {
$fo = strpos($ms[$i], '=');
$old = $ms[$i];
$ms[$i] = substr($ms[$i], 0, $fo);
array_push($ms, substr($old, $fo));
}
break;
}
$index = $i;
}
if ($index != -1) {
$spec = implode(" ", array_slice($ms, 0, $index + 2)) . $spec;
$ms = array_slice($ms, $index + 2);
}
$ms[0] = substr($ms[0], 0, -2);
$chId = substr($ms[0], 0, $q + 3);
for ($i = 1, $len_i = count($ms); $i < $len_i; $i++) {
$f = strrpos($ms[$i], '?=');
if ($f != false) {
$ms[$i] = trim($ms[$i]);
}
if ($ms[$i] == "") {
continue;
}
$ms[$i] = str_replace($chId, "", $ms[$i]);
if ($f !== false) {
$ms[$i] = substr($ms[$i], 0, -2);
}
}
$tmp = array_shift($ms);
$ms = $tmp . ($usedSpace ? "" : "") . implode($usedSpace ? " " : "", $ms) . '?=';
} else {
$ms = implode("", $ms);
}
$s = preg_replace_callback("/=(\\d[a-f]|[a-f]{0,2}|[[:xdigit:]])/", array($this, "strtoupperCallback"), $ms);
$oldEncodings = array('input_encoding' => iconv_get_encoding('input_encoding'), 'output_encoding' => iconv_get_encoding('output_encoding'), 'internal_encoding' => iconv_get_encoding('internal_encoding'));
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');
$ret = @iconv_mime_decode_headers('A: ' . $s);
if (!is_array($ret) || is_array($ret) && !isset($ret['A'])) {
$delimPos = stripos($s, $bid);
$mimeChar = strtolower(substr($s, 2, $delimPos - 2));
@iconv_set_encoding('internal_encoding', $mimeChar);
$ret = @iconv_mime_decode_headers('A: ' . $s);
}
iconv_set_encoding('input_encoding', $oldEncodings['input_encoding']);
iconv_set_encoding('output_encoding', $oldEncodings['output_encoding']);
iconv_set_encoding('internal_encoding', $oldEncodings['internal_encoding']);
//.........这里部分代码省略.........
示例5: str_repeat
<?php
$a = str_repeat("/", 9000000);
var_dump(iconv_mime_decode_headers("a", null, $a));
示例6: decodeHash
/**
* Decode a report message
* e.g.
* foo: bar
* bar: foo
* foo1
* foor
* var2: foobar
*
* to:
* array(...);
*
* @param unknown $report
* @return NULL|multitype:
*/
public static function decodeHash($string, $tolower = true)
{
$string = trim($string);
if (empty($string)) {
return null;
}
$string = preg_replace("/[\r\n]+/", "\n", $string);
$hash = iconv_mime_decode_headers($string, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
if (!$hash) {
return null;
}
if ($tolower) {
$hash = array_change_key_case($hash);
//$hash = array_combine(array_map("strtolower", array_keys($hash)), array_values($hash));
}
return $hash;
}
示例7: getHeaders
/**
* This function returns an object containing the headers of the message. This is done by taking the raw headers
* and running them through the imap_rfc822_parse_headers function. The results are only retrieved from the server
* once unless passed true as a parameter.
*
* @param bool $force_reload Load headers anyway
*
* @return array
*/
public function getHeaders($force_reload = false)
{
if ($force_reload || empty($this->headers)) {
$raw_headers = $this->imap->fetchHeader($this->imap_stream, $this->uid, FT_UID);
$decoded_headers = iconv_mime_decode_headers($raw_headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
$this->headers = array_change_key_case($decoded_headers, CASE_LOWER);
}
return $this->headers;
}
示例8: mimesDecode
public function mimesDecode(string $encodedHeaders, int $mode = 0, string $charset = NULL) : array
{
if ($charset === NULL) {
$charset = ini_get("iconv.internal_encoding");
}
return iconv_mime_decode_headers($encodedHeaders, $mode, $charset);
}
示例9: quoted_printable_decode
if (strstr($headers['content-transfer-encoding'], 'quoted-printable')) {
//echo 'quoted-printable';
$text = quoted_printable_decode($text);
}
}
}
if (preg_match("/^.*charset=([\"\\w\\d\\-]+).*\$/ix", $headers['content-type'], $check)) {
$charset = strtoupper(@$check[1]);
if ($charset && $charset != $default_charset) {
$text = iconv($charset, $default_charset, $text);
}
}
//echo $text;
$obTicket = MC('Ticket')->postMessage(array('user_id_from' => $obUser->id(), 'user_id_to' => 0, 'body' => M('TextFilter')->process('sh', $text), 'parent_id' => 0, 'level' => 0, 'from_mail' => 1), $obUser, FALSE);
if ($obTicket) {
M('Trace')->trace('ticket_mail_added', "From: " . $email . " Ticket: " . $obTicket->id() . " Headers: " . print_r(iconv_mime_decode_headers($headers['all'], 0, $default_charset), 1) . "\nText: " . $text);
/*
раньше удалялись только письма, из которых создавался тикет
остальные приходилось удалять вручную через почтовый клиент
теперь удаляются все письма, которые не перекочевали в систему сообщений (см. $popObject->Del($i) ниже)
как правило, такие письма - спам
if ( C('project.target') == 'production' )
$popObject->Del($i);*/
$added++;
}
$popObject->Del($i);
}
}
$popObject->Quit();
}
M('Trace')->trace('ticket_mail', "Processed: " . $count . " Added: " . $added);
示例10: testIconvMimeDecodeHeaders
/**
* @covers Symfony\Polyfill\Iconv\Iconv::iconv_mime_decode_headers
* @covers Symfony\Polyfill\Iconv\Iconv::iconv_mime_decode
*/
public function testIconvMimeDecodeHeaders()
{
$headers = <<<HEADERS
From: =?UTF-8?B?PGZvb0BleGFtcGxlLmNvbT4=?=
Subject: =?ks_c_5601-1987?B?UkU6odk=?= Foo
X-Bar: =?cp949?B?UkU6odk=?= Foo
X-Bar: =?cp949?B?UkU6odk=?= =?UTF-8?Q?Bar?=
To: <test@example.com>
HEADERS;
$result = array('From' => '<foo@example.com>', 'Subject' => '=?ks_c_5601-1987?B?UkU6odk=?= Foo', 'X-Bar' => array('RE:☆ Foo', 'RE:☆Bar'), 'To' => '<test@example.com>');
$this->assertSame($result, iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'));
}
示例11: get_email_headers
function get_email_headers($email, $header_names = array())
{
$ret = array();
$pos = strpos($email, "\r\n\r\n");
if (!$pos) {
// incorrectly formatted email with missing \r?
$pos = strpos($email, "\n\n");
}
$headers_str = substr($email, 0, $pos);
$headers = iconv_mime_decode_headers($headers_str, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'utf-8');
$headers = array_combine(array_map("ucfirst", array_keys($headers)), array_values($headers));
foreach ($header_names as $i => $name) {
if (is_array($headers[$name])) {
$headers[$name] = implode(', ', $headers[$name]);
}
if (strpos($headers[$name], '=?') === 0) {
// workaround if iconv_mime_decode_headers() - sometimes more than one to decode
if (preg_match_all('#=\\?(.+?)\\?([QB])\\?(.+?)\\?=#i', $headers[$name], $matches)) {
$decoded_str = '';
foreach ($matches[1] as $index => $encoding) {
if (strtolower($matches[2][$index]) === 'b') {
$decoded_str = mail_body_decode($matches[3][$index], 'base64', $encoding);
} elseif (strtolower($matches[2][$index]) === 'q') {
$decoded_str = mail_body_decode($matches[3][$index], 'quoted-printable', $encoding);
}
if (!empty($decoded_str)) {
$headers[$name] = str_replace($matches[0][$index], $decoded_str, $headers[$name]);
}
}
}
}
$ret[$i] = $headers[$name];
}
return $ret;
}
示例12: parseHeader
/**
* Parses a string of email headers into an array
*/
function parseHeader($raw_head)
{
$headers = iconv_mime_decode_headers($raw_head);
// lowercase array keys
return array_change_key_case($headers, CASE_LOWER);
}
示例13: mimesDecode
public function mimesDecode($encodedHeaders = '', $mode = 0, $charset = NULL)
{
if (!is_string($encodedHeaders)) {
return Error::set(lang('Error', 'stringParameter', '1.(encodedHeaders)'));
}
if (!is_numeric($mode)) {
return Error::set(lang('Error', 'numericParameter', '2.(mode)'));
}
if ($charset === NULL) {
$charset = ini_get("iconv.internal_encoding");
}
return iconv_mime_decode_headers($encodedHeaders, $mode, $charset);
}
示例14: decode_headers
/**
* Декодирует заголовки сообщения MIME
*
* @param string $string
*
* @return array
*/
public static function decode_headers($string)
{
return iconv_mime_decode_headers($string, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, self::$default_charset);
}
示例15: iconv_mime_decode_headers
<?php
$headers = <<<HEADERS
From: =?UTF-8?B?PGZvb0BleGFtcGxlLmNvbT4=?=
Subject: =?ks_c_5601-1987?B?UkU6odk=?=
X-Foo: =?ks_c_5601-1987?B?UkU6odk=?= Foo
X-Bar: =?ks_c_5601-1987?B?UkU6odk=?= =?UTF-8?Q?Foo?=
To: <test@example.com>
HEADERS;
$decoded = iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
var_dump($decoded['From']);
var_dump($decoded['Subject']);
var_dump($decoded['X-Foo']);
var_dump($decoded['X-Bar']);
var_dump($decoded['To']);
$decoded = iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR | ICONV_MIME_DECODE_STRICT, 'UTF-8');
var_dump($decoded['From']);
var_dump($decoded['Subject']);
var_dump($decoded['X-Foo']);
var_dump($decoded['X-Bar']);
var_dump($decoded['To']);