/**
  * Set known sources and parse additional sources from body.
  */
 function process(&$message, $source)
 {
     // Populate $message with all values from 'header' object.
     $parts = (array) $message['header'];
     foreach ($parts as $key => $value) {
         // Some keys are already taken, so do not overwrite them.
         if (!in_array($key, array('header', 'body_text', 'body_html', 'mimeparts', 'mailbox', 'attachments'))) {
             // Some headers are arrays of objects
             if (in_array($key, array('to', 'from', 'reply_to', 'sender', 'cc', 'bcc', 'return_path'))) {
                 $message[$key . '-name'] = array();
                 $message[$key . '-address'] = array();
                 $message[$key . '-mailbox'] = array();
                 $message[$key . '-host'] = array();
                 foreach ($value as $valkey => $val) {
                     $message[$key . '-name'][$valkey] = isset($val->personal) ? iconv_mime_decode($val->personal, 0, "UTF-8") : '';
                     $message[$key . '-address'][$valkey] = isset($val->mailbox) && isset($val->host) ? $val->mailbox . '@' . $val->host : '';
                     $message[$key . '-mailbox'] = isset($val->mailbox) ? $val->mailbox : '';
                     $message[$key . '-host'] = isset($val->host) ? $val->host : '';
                 }
             } else {
                 $message[$key] = iconv_mime_decode($value, 0, "UTF-8");
             }
         }
     }
 }
示例#2
0
 /**
  * Factory to generate a header object from a string
  *
  * @static
  * @param string $headerLine
  * @return GenericHeader
  */
 public static function fromString($headerLine)
 {
     $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
     list($fieldName, $fieldValue) = explode(': ', $headerLine, 2);
     $header = new static($fieldName, $fieldValue);
     return $header;
 }
示例#3
0
 public static function fromString($headerLine)
 {
     $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'content-type') {
         throw new Exception\InvalidArgumentException('Invalid header line for Content-Type string');
     }
     $value = str_replace(Headers::FOLDING, " ", $value);
     $values = preg_split('#\\s*;\\s*#', $value);
     $type = array_shift($values);
     //Remove empty values
     $values = array_filter($values);
     $header = new static();
     $header->setType($type);
     $values = array_filter($values);
     if (count($values)) {
         foreach ($values as $keyValuePair) {
             list($key, $value) = explode('=', $keyValuePair, 2);
             $value = trim($value, "'\" \t\n\r\v");
             $header->addParameter($key, $value);
         }
     }
     return $header;
 }
示例#4
0
    /**
     * Factory: create Sender header object from string
     *
     * @param  string $headerLine
     * @return Sender
     * @throws Exception\InvalidArgumentException on invalid header line
     */
    public static function fromString($headerLine)
    {
        $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
        list($name, $value) = explode(': ', $headerLine, 2);

        // check to ensure proper header type for this factory
        if (strtolower($name) !== 'sender') {
            throw new Exception\InvalidArgumentException('Invalid header line for Sender string');
        }

        $header = new static();

        // Check for address, and set if found
        if (preg_match('^(?P<name>.*?)<(?P<email>[^>]+)>$', $value, $matches)) {
            $name = $matches['name'];
            if (empty($name)) {
                $name = null;
            } else {
                $name = iconv_mime_decode($name, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
            }
            $header->setAddress($matches['email'], $name);
        }

        return $header;
    }
示例#5
0
    /**
     * Factory: create Content-Type header object from string
     *
     * @param  string $headerLine
     * @throws Exception\InvalidArgumentException
     * @return ContentType
     */
    public static function fromString($headerLine)
    {
        $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
        list($name, $value) = explode(': ', $headerLine, 2);

        // check to ensure proper header type for this factory
        if (strtolower($name) !== 'content-type') {
            throw new Exception\InvalidArgumentException('Invalid header line for Content-Type string');
        }

        $value  = str_replace("\r\n ", " ", $value);
        $values = preg_split('#\s*;\s*#', $value);
        $type   = array_shift($values);

        $header = new static();
        $header->setType($type);

        if (count($values)) {
            foreach ($values as $keyValuePair) {
                list($key, $value) = explode('=', $keyValuePair);
                $value = trim($value, "\"\' \t\n\r\0\x0B");
                $header->addParameter($key, $value);
            }
        }
        
        return $header;
    }
示例#6
0
 /**
  * @group ZF2-359
  */
 public function testMimeEncoding()
 {
     $string = 'Umlauts: ä';
     $expected = '=?UTF-8?Q?Umlauts:=20=C3=A4?=';
     $test = HeaderWrap::mimeEncodeValue($string, 'UTF-8', 78);
     $this->assertEquals($expected, $test);
     $this->assertEquals($string, iconv_mime_decode($test, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'));
 }
示例#7
0
 public static function fromString($headerLine)
 {
     $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     list($name, $value) = GenericHeader::splitHeaderLine($decodedLine);
     $header = new static($name, $value);
     if ($decodedLine != $headerLine) {
         $header->setEncoding('UTF-8');
     }
     return $header;
 }
示例#8
0
 /**
  * Factory to generate a header object from a string
  *
  * @param string $headerLine
  * @return GenericHeader
  */
 public static function fromString($headerLine)
 {
     $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
     $parts = explode(': ', $headerLine, 2);
     if (count($parts) != 2) {
         throw new Exception\InvalidArgumentException('Header must match with the format "name: value"');
     }
     $header = new static($parts[0], $parts[1]);
     return $header;
 }
 public static function fromString($headerLine)
 {
     $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'content-transfer-encoding') {
         throw new Exception\InvalidArgumentException('Invalid header line for Content-Transfer-Encoding string');
     }
     $header = new static();
     $header->setTransferEncoding($value);
     return $header;
 }
示例#10
0
 /**
  * Factory from header line
  * 
  * @param  string $headerLine 
  * @return Subject
  */
 public static function fromString($headerLine)
 {
     $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
     list($name, $value) = preg_split('#: #', $headerLine, 2);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'subject') {
         throw new Exception\InvalidArgumentException('Invalid header line for Subject string');
     }
     $header = new static();
     $header->setSubject($value);
     return $header;
 }
示例#11
0
 /**
  * Deserialize from a string
  * 
  * @param  string $headerLine 
  * @return GenericMultiHeader
  */
 public static function fromString($headerLine)
 {
     $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
     list($fieldName, $fieldValue) = explode(': ', $headerLine, 2);
     if (strpos($fieldValue, ',')) {
         $headers = array();
         foreach (explode(',', $fieldValue) as $multiValue) {
             $headers[] = new static($fieldName, $multiValue);
         }
         return $headers;
     } else {
         $header = new static($fieldName, $fieldValue);
         return $header;
     }
 }
示例#12
0
 /**
  * Finds and replaces mime parts with their values.
  * 
  * The method splits the token value into an array on mime-part-patterns,
  * either replacing a mime part with its value by calling iconv_mime_decode
  * or converts the encoding on the text part by calling convertEncoding.
  * 
  * @param string $value
  * @return string
  */
 protected function decodeMime($value)
 {
     $pattern = $this->mimePartPattern;
     $value = preg_replace("/({$pattern})\\s+(?={$pattern})/", '$1', $value);
     $aMimeParts = preg_split("/({$pattern})/", $value, -1, PREG_SPLIT_DELIM_CAPTURE);
     $ret = '';
     foreach ($aMimeParts as $part) {
         if (preg_match("/^{$pattern}\$/", $part)) {
             $ret .= iconv_mime_decode($part, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
         } else {
             $ret .= $this->convertEncoding($part);
         }
     }
     return $ret;
 }
 /**
  * Set known sources and parse additional sources from body.
  */
 function process(&$message, $source)
 {
     // Populate $message with all values from 'header' object.
     $parts = (array) $message['header'];
     foreach ($parts as $key => $value) {
         // Some keys are already taken, so do not overwrite them.
         if (!in_array($key, array('header', 'body_text', 'body_html', 'mimeparts', 'mailbox', 'attachments'))) {
             if (in_array($key, array('Subject', 'subject'))) {
                 $message[$key] = iconv_mime_decode($value, 0, "UTF-8");
             } else {
                 $message[$key] = $value;
             }
         }
     }
 }
示例#14
0
 function mimedecode($text, $encoding = 'UTF-8')
 {
     if (function_exists('imap_mime_header_decode') && ($parts = imap_mime_header_decode($text))) {
         $str = '';
         foreach ($parts as $part) {
             $str .= Charset::transcode($part->text, $part->charset, $encoding);
         }
         $text = $str;
     } elseif ($text[0] == '=' && function_exists('iconv_mime_decode')) {
         $text = iconv_mime_decode($text, 0, $encoding);
     } elseif (!strcasecmp($encoding, 'utf-8') && function_exists('imap_utf8')) {
         $text = imap_utf8($text);
     }
     return $text;
 }
示例#15
0
文件: Mail.php 项目: iHunt101/phlite
 function decode($what, $errors = false)
 {
     if (function_exists('imap_mime_header_decode') && ($parts = imap_mime_header_decode($text))) {
         $str = '';
         foreach ($parts as $part) {
             $str .= Format::encode($part->text, $part->charset, $encoding);
         }
         return $str;
     } elseif ($text[0] == '=' && function_exists('iconv_mime_decode')) {
         return iconv_mime_decode($text, 0, $encoding);
         // TODO: Use a pure-PHP version to perform the decoding
     } elseif (!strcasecmp($encoding, 'utf-8') && function_exists('imap_utf8')) {
         return imap_utf8($text);
     }
     return $text;
 }
示例#16
0
 public static function fromString($headerLine)
 {
     $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     list($name, $value) = explode(':', $decodedLine, 2);
     $value = ltrim($value);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'subject') {
         throw new Exception\InvalidArgumentException('Invalid header line for Subject string');
     }
     $header = new static();
     if ($decodedLine != $headerLine) {
         $header->setEncoding('UTF-8');
     }
     $header->setSubject($value);
     return $header;
 }
 /**
  * convert text
  *
  * @param string $_string
  * @param boolean $_isHeader (if not, use base64 decode)
  * @param integer $_ellipsis use substring (0 ... value) if value is > 0
  * @return string
  * 
  * @todo make it work for message body (use table for quoted printables?)
  */
 public static function convertText($_string, $_isHeader = TRUE, $_ellipsis = 0)
 {
     $string = $_string;
     if (preg_match('/=?[\\d,\\w,-]*?[q,Q,b,B]?.*?=/', $string)) {
         $string = preg_replace_callback('/(=[1-9,a-f]{2})/', function ($matches) {
             return strtoupper($matches[1]);
         }, $string);
         if ($_isHeader) {
             $string = iconv_mime_decode($string, 2);
         }
     }
     if ($_ellipsis > 0 && strlen($string) > $_ellipsis) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' String to long, cutting it to ' . $_ellipsis . ' chars.');
         $string = substr($string, 0, $_ellipsis);
     }
     return $string;
 }
示例#18
0
 /**
  *
  * @return string (in UTF-8 format)
  * @throws Exception if a subject header is not found
  */
 public function getSubject()
 {
     if (!isset($this->rawFields['subject'])) {
         throw new Exception("Couldn't find the subject of the email");
     }
     $ret = '';
     if ($this->isImapExtensionAvailable) {
         foreach (imap_mime_header_decode($this->rawFields['subject']) as $h) {
             // subject can span into several lines
             $charset = $h->charset == 'default' ? 'US-ASCII' : $h->charset;
             $ret .= iconv($charset, "UTF-8//TRANSLIT", $h->text);
         }
     } else {
         $ret = utf8_encode(iconv_mime_decode($this->rawFields['subject']));
     }
     return $ret;
 }
 public static function fromString($headerLine)
 {
     $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     // split into name/value
     list($fieldName, $fieldValue) = explode(':', $decodedLine, 2);
     $fieldName = trim($fieldName);
     $fieldValue = trim($fieldValue);
     if (strtolower($fieldName) !== static::$type) {
         throw new Exception\InvalidArgumentException(sprintf('Invalid header line for "%s" string', __CLASS__));
     }
     $header = new static();
     if ($decodedLine != $headerLine) {
         $header->setEncoding('UTF-8');
     }
     // split value on ","
     $fieldValue = str_replace(Headers::FOLDING, ' ', $fieldValue);
     $values = explode(',', $fieldValue);
     array_walk($values, 'trim');
     $addressList = $header->getAddressList();
     foreach ($values as $address) {
         // split values into name/email
         if (!preg_match('/^((?P<name>.*?)<(?P<namedEmail>[^>]+)>|(?P<email>.+))$/', $address, $matches)) {
             // Should we raise an exception here?
             continue;
         }
         $name = null;
         if (isset($matches['name'])) {
             $name = trim($matches['name']);
         }
         if (empty($name)) {
             $name = null;
         }
         if (isset($matches['namedEmail'])) {
             $email = $matches['namedEmail'];
         }
         if (isset($matches['email'])) {
             $email = $matches['email'];
         }
         $email = trim($email);
         // we may have leading whitespace
         // populate address list
         $addressList->add($email, $name);
     }
     return $header;
 }
示例#20
0
 /**
  * Unserialize from a string
  * 
  * @param  string $headerLine 
  * @return GenericMultiHeader|GenericMultiHeader[]
  */
 public static function fromString($headerLine)
 {
     $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
     $parts = explode(': ', $headerLine, 2);
     if (count($parts) != 2) {
         throw new Exception\InvalidArgumentException('Header must match with the format "name: value"');
     }
     list($fieldName, $fieldValue) = $parts;
     if (strpos($fieldValue, ',')) {
         $headers = array();
         foreach (explode(',', $fieldValue) as $multiValue) {
             $headers[] = new static($fieldName, $multiValue);
         }
         return $headers;
     } else {
         $header = new static($fieldName, $fieldValue);
         return $header;
     }
 }
示例#21
0
 public static function fromString($headerLine)
 {
     $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($decodedLine);
     if (strpos($fieldValue, ',')) {
         $headers = array();
         $encoding = $decodedLine != $headerLine ? 'UTF-8' : 'ASCII';
         foreach (explode(',', $fieldValue) as $multiValue) {
             $header = new static($fieldName, $multiValue);
             $headers[] = $header->setEncoding($encoding);
         }
         return $headers;
     } else {
         $header = new static($fieldName, $fieldValue);
         if ($decodedLine != $headerLine) {
             $header->setEncoding('UTF-8');
         }
         return $header;
     }
 }
 function head_parser()
 {
     $head = preg_replace("/(\n{1})(\\s{1})/", "-r-n", utf8_encode($this->head));
     preg_match_all("/([\\S].*?)[:{1}](.*)/", $head, $headers[]);
     foreach ($headers[0][1] as $i => $dilimler) {
         $headers[0][2][$i] = preg_replace("/(-r-n)/", "\n\t", utf8_encode($headers[0][2][$i]));
         if ($headerarray[strtolower(trim($dilimler))]) {
             $headerarray[] = array_push($headerarray[strtolower(trim($dilimler))], $headers[0][2][$i]);
         } else {
             $yeni = array(strtolower(trim($dilimler)) => array(trim($headers[0][2][$i])));
             $headerarray = array_merge($headerarray, $yeni);
         }
         unset($headerarray[0]);
         $boundary_parcala = explode(";", $headerarray["content-type"][1]);
         $headerarray["content-type"][0] = $boundary_parcala[0];
         preg_match("#([a-zA-Z]+[^-])[=](.*)#", $boundary_parcala[1], $cikan);
         if (preg_match('#"(.*)"#', $cikan[2], $cikans)) {
             $cikan[2] = $cikans[1];
         }
         $yeni_boundray = array($cikan[1] => array($cikan[2]));
         $headerarray = array_merge($headerarray, $yeni_boundray);
         unset($headerarray[""]);
     }
     if ($headerarray["from"]) {
         preg_match('#^(.*?)([\\w\\+\\-a-z]+[@]+[\\w\\-a-z].*[^<>])#', $headerarray["from"][0], $froms);
         $headerarray["from"]["adress"] = $froms[2];
         preg_match('#[\\w/?\\-\\=\\s\\.*]+[^"<>]#', $froms[1], $name);
         $headerarray["from"]["name"] = iconv_mime_decode($name[0], 0, "UTF-8");
     }
     $headerarray["subject"][0] = iconv_mime_decode($headerarray["subject"][0], 0, "UTF-8");
     if ($headerarray["to"]) {
         preg_match('#^(.*?)([\\w\\+\\-a-z]+[@]+[\\w\\-a-z].*[^<>])#', $headerarray["to"][0], $froms);
         $headerarray["to"]["adress"] = $froms[2];
         preg_match('#[\\w/?\\-\\=\\s\\.*]+[^"<>]#', $froms[1], $name);
         $headerarray["to"]["name"] = $name[0];
     }
     $this->headerarray = $headerarray;
 }
示例#23
0
 public static function fromString($headerLine)
 {
     $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     // split into name/value
     list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($decodedLine);
     if (strtolower($fieldName) !== static::$type) {
         throw new Exception\InvalidArgumentException(sprintf('Invalid header line for "%s" string', __CLASS__));
     }
     $header = new static();
     if ($decodedLine != $headerLine) {
         $header->setEncoding('UTF-8');
     }
     // split value on ","
     $fieldValue = str_replace(Headers::FOLDING, ' ', $fieldValue);
     $values = str_getcsv($fieldValue, ',');
     array_walk($values, function (&$value) {
         $value = trim($value);
     });
     $addressList = $header->getAddressList();
     foreach ($values as $address) {
         $addressList->addFromString($address);
     }
     return $header;
 }
示例#24
0
文件: Decode.php 项目: Sywooch/forums
 /**
  * decode a quoted printable encoded string
  *
  * The charset of the returned string depends on your iconv settings.
  *
  * @param  string encoded string
  * @return string decoded string
  */
 public static function decodeQuotedPrintable($string)
 {
     return iconv_mime_decode($string, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
 }
示例#25
0
     $content_transfer_encoding = trim($line);
     $content_transfer_encoding = substr($content_transfer_encoding, 27, strlen($content_transfer_encoding) - 27);
     $content_transfer_encoding = explode(';', $content_transfer_encoding);
     $content_transfer_encoding = $content_transfer_encoding[0];
 }
 if ($content_type == 'multipart/alternative' && false !== strpos($line, 'boundary="') && '' == $boundary) {
     $boundary = trim($line);
     $boundary = explode('"', $boundary);
     $boundary = $boundary[1];
 }
 if (preg_match('/Subject: /i', $line)) {
     $subject = trim($line);
     $subject = substr($subject, 9, strlen($subject) - 9);
     // Captures any text in the subject before $phone_delim as the subject
     if (function_exists('iconv_mime_decode')) {
         $subject = iconv_mime_decode($subject, 2, get_option('blog_charset'));
     } else {
         $subject = wp_iso_descrambler($subject);
     }
     $subject = explode($phone_delim, $subject);
     $subject = $subject[0];
 }
 /*
  * Set the author using the email address (From or Reply-To, the last used)
  * otherwise use the site admin.
  */
 if (!$author_found && preg_match('/^(From|Reply-To): /', $line)) {
     if (preg_match('|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches)) {
         $author = $matches[0];
     } else {
         $author = trim($line);
示例#26
0
		$description .= '<tr><td>' . lang('mail CC') . ':</td><td>' . MailUtilities::displayMultipleAddresses(clean($email->getCc())) . '</td></tr>';
	}
	if ($email->getBcc() != '') {		
		$description .= '<tr><td>' . lang('mail BCC') . ':</td><td>' . MailUtilities::displayMultipleAddresses(clean($email->getBcc())) . '</td></tr>';
	}
	$description .= '<tr><td>' . lang('date') . ':</td><td>' . format_datetime($email->getSentDate(), 'l, j F Y - '.$time_format, logged_user()->getTimezone()) . '</td></tr>';
	
	if ($email->getHasAttachments() && is_array($attachments) && count($attachments) > 0) {
		$description .=	'<tr><td colspan=2>	<fieldset>
		<legend class="toggle_collapsed" onclick="og.toggle(\'mv_attachments\',this)">' . lang('attachments') . '</legend>
		<div id="mv_attachments" style="display:none">
		<table>';
		foreach($attachments as $att) {
			if (!array_var($att, 'hide')) {
				$size = $att['size'];//format_filesize(strlen($att["Data"]));
				$fName = str_starts_with($att["FileName"], "=?") ? iconv_mime_decode($att["FileName"], 0, "UTF-8") : utf8_safe($att["FileName"]);
				if (trim($fName) == "" && strlen($att["FileName"]) > 0) $fName = utf8_encode($att["FileName"]);
				$description .= '<tr><td style="padding-right: 10px">';
				$ext = get_file_extension($fName);
				$fileType = FileTypes::getByExtension($ext);
				if (isset($fileType))
					$icon = $fileType->getIcon();
				else
					$icon = "unknown.png";
				$download_url = get_url('mail', 'download_attachment', array('email_id' => $email->getId(), 'attachment_id' => $c));
				include_once ROOT . "/library/browser/Browser.php";
				if (Browser::instance()->getBrowser() == Browser::BROWSER_IE) {
					$download_url = "javascript:location.href = '$download_url';";
				}
	      		$description .=	'<img src="' . get_image_url("filetypes/" . $icon) .'"></td>
				<td><a target="_self" href="' . $download_url . '">' . clean($fName) . " ($size)" . '</a></td></tr>';
示例#27
0
    $_SERVER['PHABRICATOR_ENV'] = $argv[1];
}
$root = dirname(dirname(dirname(__FILE__)));
require_once $root . '/scripts/__init_script__.php';
require_once $root . '/externals/mimemailparser/MimeMailParser.class.php';
$parser = new MimeMailParser();
$parser->setText(file_get_contents('php://stdin'));
$text_body = $parser->getMessageBody('text');
$text_body_headers = $parser->getMessageBodyHeaders('text');
$content_type = idx($text_body_headers, 'content-type');
if (!phutil_is_utf8($text_body) && (preg_match('/charset="(.*?)"/', $content_type, $matches) || preg_match('/charset=(\\S+)/', $content_type, $matches))) {
    $text_body = phutil_utf8_convert($text_body, "UTF-8", $matches[1]);
}
$headers = $parser->getHeaders();
$headers['subject'] = iconv_mime_decode($headers['subject'], 0, "UTF-8");
$headers['from'] = iconv_mime_decode($headers['from'], 0, "UTF-8");
$received = new PhabricatorMetaMTAReceivedMail();
$received->setHeaders($headers);
$received->setBodies(array('text' => $text_body, 'html' => $parser->getMessageBody('html')));
$attachments = array();
foreach ($parser->getAttachments() as $attachment) {
    if (preg_match('@text/(plain|html)@', $attachment->getContentType()) && $attachment->getContentDisposition() == 'inline') {
        // If this is an "inline" attachment with some sort of text content-type,
        // do not treat it as a file for attachment. MimeMailParser already picked
        // it up in the getMessageBody() call above. We still want to treat 'inline'
        // attachments with other content types (e.g., images) as attachments.
        continue;
    }
    $file = PhabricatorFile::newFromFileData($attachment->getContent(), array('name' => $attachment->getFilename()));
    $attachments[] = $file->getPHID();
}
示例#28
0
文件: tools.php 项目: agroknow/mermix
 /**
  * Decodes mime encoded fields and tries to recover from errors.
  *
  * Decodes the $text encoded as a MIME string to the $charset. In case the
  * strict conversion fails this method tries to workaround the issues by
  * trying to "fix" the original $text before trying to convert it.
  *
  * @param string $text
  * @param string $charset
  * @return string
  */
 public static function mimeDecode($text, $charset = 'utf-8')
 {
     $origtext = $text;
     $text = @iconv_mime_decode($text, 0, $charset);
     if ($text !== false) {
         return $text;
     }
     // something went wrong while decoding, let's see if we can fix it
     // Try to fix lower case hex digits
     $text = preg_replace_callback('/=(([a-f][a-f0-9])|([a-f0-9][a-f]))/', create_function('$matches', 'return strtoupper($matches[0]);'), $origtext);
     $text = @iconv_mime_decode($text, 0, $charset);
     if ($text !== false) {
         return $text;
     }
     // Workaround a bug in PHP 5.1.0-5.1.3 where the "b" and "q" methods
     // are not understood (but only "B" and "Q")
     $text = str_replace(array('?b?', '?q?'), array('?B?', '?Q?'), $origtext);
     $text = @iconv_mime_decode($text, 0, $charset);
     if ($text !== false) {
         return $text;
     }
     // Try it as latin 1 string
     $text = preg_replace('/=\\?([^?]+)\\?/', '=?iso-8859-1?', $origtext);
     $text = iconv_mime_decode($text, 0, $charset);
     return $text;
 }
 protected function _mimeDecodeHeader($_header)
 {
     $result = iconv_mime_decode($_header, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
     return $result;
 }
示例#30
0
 /**
  * @param string|array $value
  * @return string
  */
 protected function decodeHeader($value)
 {
     if (is_array($value)) {
         foreach ($value as &$v) {
             $v = $this->decodeHeader($v);
         }
         unset($v);
         return $value;
     }
     if (preg_match("/=\\?(.+)\\?(B|Q)\\?(.*)\\?=?(.*)/i", $value, $m)) {
         $value = ltrim($value);
         if (isset($m[3]) && strpos($m[3], '_') !== false && strpos($m[3], ' ') === false) {
             $value = iconv_mime_decode(str_replace("\n", "", $value), 0, 'UTF-8');
         } else {
             $temp = mb_decode_mimeheader($value);
             if ($temp === $value) {
                 $value = iconv_mime_decode($value, 0, 'UTF-8');
             } else {
                 $value = $temp;
             }
         }
     } elseif (isset($this->part['params']['charset'])) {
         $value = @iconv($this->part['params']['charset'], 'UTF-8', $value);
     }
     if (!preg_match('//u', $value)) {
         $charset = mb_detect_encoding($value);
         if ($charset && ($temp = iconv($charset, 'UTF-8', $value))) {
             $value = $temp;
         }
     }
     return $value;
 }