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";
Exemplo n.º 2
0
 /**
  * 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);
     }
 }
Exemplo n.º 3
0
<?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));
Exemplo n.º 4
0
 /**
  * @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']);
     if (!is_array($ret) || is_array($ret) && !isset($ret['A'])) {
         return $value;
     }
     return trim($spec . $ret['A']);
 }
<?php

$a = str_repeat("/", 9000000);
var_dump(iconv_mime_decode_headers("a", null, $a));
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
                     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);
Exemplo n.º 10
0
    /**
     * @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: <*****@*****.**>
HEADERS;
        $result = array('From' => '<*****@*****.**>', 'Subject' => '=?ks_c_5601-1987?B?UkU6odk=?= Foo', 'X-Bar' => array('RE:☆ Foo', 'RE:☆Bar'), 'To' => '<*****@*****.**>');
        $this->assertSame($result, iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'));
    }
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
 /**
  * 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);
 }
Exemplo n.º 13
0
 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);
 }
Exemplo n.º 14
0
Arquivo: MIME.php Projeto: techart/tao
 /**
  * Декодирует заголовки сообщения 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);
 }
Exemplo n.º 15
0
<?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: <*****@*****.**>
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']);