PHP 利用Mail_MimeDecode類提取郵件正文

參考鏈接:http://blog.csdn.net/dmtnewtons_blog/article/details/18765289

rfc mail content-type:

參考鏈接:http://blog.csdn.net/dmtnewtons_blog/article/details/19327105


根據主流的郵件解析類Mail_MimeDecode,提取郵件正文。如有問題請指教。

#獲取郵件正文
#[path] 郵件路徑
function getMailBody($path){if(!is_file($path)) return false;$contents_c = file_get_contents($path);if(empty($contents_c)) return false;$mmd_c = new Mail_mimeDecode($contents_c);  //創建Mail_mimeDecode類的實例$sr = $mmd_c->decode(array ('include_bodies' => true,  //是否包含郵件正文'decode_bodies' => false,  'decode_headers' => true));unset($mail_part);$mail_part = getMailPart($sr);$mail_code = $mail_part->headers;$mail_code = empty($mail_code['content-transfer-encoding'])?'':$mail_code['content-transfer-encoding']; //編碼格式$mail_type = $mail_part->ctype_parameters;$mail_type = empty($mail_type['charset'])?'GBK':$mail_type['charset'];$mail_body = $mail_part->body; //正文內容if ($mail_code == "base64") { //判斷編碼格式,受'decode_bodies'影響$text = base64_decode("$mail_body");$text = iconv("$mail_type", "UTF-8", $text);} else {$text = quoted_printable_decode("$mail_body");$text = iconv("$mail_type", "UTF-8", $text);}$body = $text;return $body;
}#Edit 20140331| Edit 20140414 | Edit 20140507
function get_mail_part($sr){if(empty($sr)) return false;$mail_part = null;$accept_primary = array("multipart", "text", "message");if (property_exists($sr, 'parts')) {$mail_part = $sr->parts;foreach($mail_part as $k => $m_part){if(property_exists($m_part, 'disposition')) continue;if(property_exists($m_part, 'ctype_primary') && in_array($m_part->ctype_primary, $accept_primary)){$mail_part = &get_mail_part($m_part);}//end if (else attach)}//end for} else {if(property_exists($sr, 'ctype_primary') && in_array($sr->ctype_primary, $accept_primary)){if (property_exists($sr, 'parts')) {$mail_part = &get_mail_part($sr);}else{if(property_exists($sr, 'ctype_secondary') && !strcmp($sr->ctype_secondary,'html')){$mail_part = $sr;}elseif(property_exists($sr, 'ctype_primary') && !strcmp($sr->ctype_primary,'text')){$mail_part = $sr;}//end if}//end if}//end if}//end ifreturn $mail_part;}//end get_mail_part

MimeDecodeClass:

[摘自] http://www.oschina.net/code/explore/magento-1.4.2.0/lib/PEAR/Mail/mimeDecode.php

<?php
/**** The Mail_mimeDecode class is used to decode mail/mime messages** This class will parse a raw mime email and return* the structure. Returned structure is similar to* that returned by imap_fetchstructure().**  +----------------------------- IMPORTANT ------------------------------+*  | Usage of this class compared to native php extensions such as        |*  | mailparse or imap, is slow and may be feature deficient. If available|*  | you are STRONGLY recommended to use the php extensions.              |*  +----------------------------------------------------------------------+** Compatible with PHP versions 4 and 5** LICENSE: This LICENSE is in the BSD license style.* Copyright (c) 2002-2003, Richard Heyes <richard@phpguru.org>* Copyright (c) 2003-2006, PEAR <pear-group@php.net>* All rights reserved.** Redistribution and use in source and binary forms, with or* without modification, are permitted provided that the following* conditions are met:** - Redistributions of source code must retain the above copyright*   notice, this list of conditions and the following disclaimer.* - Redistributions in binary form must reproduce the above copyright*   notice, this list of conditions and the following disclaimer in the*   documentation and/or other materials provided with the distribution.* - Neither the name of the authors, nor the names of its contributors *   may be used to endorse or promote products derived from this *   software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF* THE POSSIBILITY OF SUCH DAMAGE.** @category   Mail* @package    Mail_Mime* @author     Richard Heyes  <richard@phpguru.org>* @author     George Schlossnagle <george@omniti.com>* @author     Cipriano Groenendal <cipri@php.net>* @author     Sean Coates <sean@php.net>* @copyright  2003-2006 PEAR <pear-group@php.net>* @license    http://www.opensource.org/licenses/bsd-license.php BSD License* @version    CVS: $Id: mimeDecode.php,v 1.48 2006/12/03 13:43:33 cipri Exp $* @link       http://pear.php.net/package/Mail_mime*//**** require PEAR** This package depends on PEAR to raise errors.*/
require_once 'PEAR.php';/**** The Mail_mimeDecode class is used to decode mail/mime messages** This class will parse a raw mime email and return the structure.* Returned structure is similar to that returned by imap_fetchstructure().**  +----------------------------- IMPORTANT ------------------------------+*  | Usage of this class compared to native php extensions such as        |*  | mailparse or imap, is slow and may be feature deficient. If available|*  | you are STRONGLY recommended to use the php extensions.              |*  +----------------------------------------------------------------------+** @category   Mail* @package    Mail_Mime* @author     Richard Heyes  <richard@phpguru.org>* @author     George Schlossnagle <george@omniti.com>* @author     Cipriano Groenendal <cipri@php.net>* @author     Sean Coates <sean@php.net>* @copyright  2003-2006 PEAR <pear-group@php.net>* @license    http://www.opensource.org/licenses/bsd-license.php BSD License* @version    Release: @package_version@* @link       http://pear.php.net/package/Mail_mime*/
class Mail_mimeDecode extends PEAR
{/**** The raw email to decode** @var    string* @access private*/var $_input;/**** The header part of the input** @var    string* @access private*/var $_header;/**** The body part of the input** @var    string* @access private*/var $_body;/**** If an error occurs, this is used to store the message** @var    string* @access private*/var $_error;/**** Flag to determine whether to include bodies in the* returned object.** @var    boolean* @access private*/var $_include_bodies;/**** Flag to determine whether to decode bodies** @var    boolean* @access private*/var $_decode_bodies;/**** Flag to determine whether to decode headers** @var    boolean* @access private*/var $_decode_headers;/**** Constructor.** Sets up the object, initialise the variables, and splits and* stores the header and body of the input.** @param string The input to decode* @access public*/function Mail_mimeDecode($input){list($header, $body)   = $this->_splitBodyHeader($input);$this->_input          = $input;$this->_header         = $header;$this->_body           = $body;$this->_decode_bodies  = false;$this->_include_bodies = true;}/**** Begins the decoding process. If called statically* it will create an object and call the decode() method* of it.** @param array An array of various parameters that determine*              various things:*              include_bodies - Whether to include the body in the returned*                               object.*              decode_bodies  - Whether to decode the bodies*                               of the parts. (Transfer encoding)*              decode_headers - Whether to decode headers*              input          - If called statically, this will be treated*                               as the input* @return object Decoded results* @access public*/function decode($params = null){// determine if this method has been called statically$isStatic = !(isset($this) && get_class($this) == __CLASS__);// Have we been called statically?// If so, create an object and pass details to that.if ($isStatic AND isset($params['input'])) {$obj = new Mail_mimeDecode($params['input']);$structure = $obj->decode($params);// Called statically but no input} elseif ($isStatic) {return PEAR::raiseError('Called statically and no input given');// Called via an object} else {$this->_include_bodies = isset($params['include_bodies']) ?$params['include_bodies'] : false;$this->_decode_bodies  = isset($params['decode_bodies']) ?$params['decode_bodies']  : false;$this->_decode_headers = isset($params['decode_headers']) ?$params['decode_headers'] : false;$structure = $this->_decode($this->_header, $this->_body);if ($structure === false) {$structure = $this->raiseError($this->_error);}}return $structure;}/**** Performs the decoding. Decodes the body string passed to it* If it finds certain content-types it will call itself in a* recursive fashion** @param string Header section* @param string Body section* @return object Results of decoding process* @access private*/function _decode($headers, $body, $default_ctype = 'text/plain'){$return = new stdClass;$return->headers = array();$headers = $this->_parseHeaders($headers);foreach ($headers as $value) {if (isset($return->headers[strtolower($value['name'])]) AND !is_array($return->headers[strtolower($value['name'])])) {$return->headers[strtolower($value['name'])]   = array($return->headers[strtolower($value['name'])]);$return->headers[strtolower($value['name'])][] = $value['value'];} elseif (isset($return->headers[strtolower($value['name'])])) {$return->headers[strtolower($value['name'])][] = $value['value'];} else {$return->headers[strtolower($value['name'])] = $value['value'];}}reset($headers);while (list($key, $value) = each($headers)) {$headers[$key]['name'] = strtolower($headers[$key]['name']);switch ($headers[$key]['name']) {case 'content-type':$content_type = $this->_parseHeaderValue($headers[$key]['value']);if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) {$return->ctype_primary   = $regs[1];$return->ctype_secondary = $regs[2];}if (isset($content_type['other'])) {while (list($p_name, $p_value) = each($content_type['other'])) {$return->ctype_parameters[$p_name] = $p_value;}}break;case 'content-disposition':$content_disposition = $this->_parseHeaderValue($headers[$key]['value']);$return->disposition   = $content_disposition['value'];if (isset($content_disposition['other'])) {while (list($p_name, $p_value) = each($content_disposition['other'])) {$return->d_parameters[$p_name] = $p_value;}}break;case 'content-transfer-encoding':$content_transfer_encoding = $this->_parseHeaderValue($headers[$key]['value']);break;}}if (isset($content_type)) {switch (strtolower($content_type['value'])) {case 'text/plain':$encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';$this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;break;case 'text/html':$encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';$this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;break;case 'multipart/parallel':case 'multipart/appledouble': // Appledouble mailcase 'multipart/report': // RFC1892case 'multipart/signed': // PGPcase 'multipart/digest':case 'multipart/alternative':case 'multipart/related':case 'multipart/mixed':if(!isset($content_type['other']['boundary'])){$this->_error = 'No boundary found for ' . $content_type['value'] . ' part';return false;}$default_ctype = (strtolower($content_type['value']) === 'multipart/digest') ? 'message/rfc822' : 'text/plain';$parts = $this->_boundarySplit($body, $content_type['other']['boundary']);for ($i = 0; $i < count($parts); $i++) {list($part_header, $part_body) = $this->_splitBodyHeader($parts[$i]);$part = $this->_decode($part_header, $part_body, $default_ctype);if($part === false)$part = $this->raiseError($this->_error);$return->parts[] = $part;}break;case 'message/rfc822':$obj = new Mail_mimeDecode($body);$return->parts[] = $obj->decode(array('include_bodies' => $this->_include_bodies,'decode_bodies'  => $this->_decode_bodies,'decode_headers' => $this->_decode_headers));unset($obj);break;default:if(!isset($content_transfer_encoding['value']))$content_transfer_encoding['value'] = '7bit';$this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $content_transfer_encoding['value']) : $body) : null;break;}} else {$ctype = explode('/', $default_ctype);$return->ctype_primary   = $ctype[0];$return->ctype_secondary = $ctype[1];$this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body) : $body) : null;}return $return;}/**** Given the output of the above function, this will return an* array of references to the parts, indexed by mime number.** @param  object $structure   The structure to go through* @param  string $mime_number Internal use only.* @return array               Mime numbers*/function &getMimeNumbers(&$structure, $no_refs = false, $mime_number = '', $prepend = ''){$return = array();if (!empty($structure->parts)) {if ($mime_number != '') {$structure->mime_id = $prepend . $mime_number;$return[$prepend . $mime_number] = &$structure;}for ($i = 0; $i < count($structure->parts); $i++) {if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') {$prepend      = $prepend . $mime_number . '.';$_mime_number = '';} else {$_mime_number = ($mime_number == '' ? $i + 1 : sprintf('%s.%s', $mime_number, $i + 1));}$arr = &Mail_mimeDecode::getMimeNumbers($structure->parts[$i], $no_refs, $_mime_number, $prepend);foreach ($arr as $key => $val) {$no_refs ? $return[$key] = '' : $return[$key] = &$arr[$key];}}} else {if ($mime_number == '') {$mime_number = '1';}$structure->mime_id = $prepend . $mime_number;$no_refs ? $return[$prepend . $mime_number] = '' : $return[$prepend . $mime_number] = &$structure;}return $return;}/**** Given a string containing a header and body* section, this function will split them (at the first* blank line) and return them.** @param string Input to split apart* @return array Contains header and body section* @access private*/function _splitBodyHeader($input){if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $match)) {return array($match[1], $match[2]);}$this->_error = 'Could not split header and body';return false;}/**** Parse headers given in $input and return* as assoc array.** @param string Headers to parse* @return array Contains parsed headers* @access private*/function _parseHeaders($input){if ($input !== '') {// Unfold the input$input   = preg_replace("/\r?\n/", "\r\n", $input);$input   = preg_replace("/\r\n(\t| )+/", ' ', $input);$headers = explode("\r\n", trim($input));foreach ($headers as $value) {$hdr_name = substr($value, 0, $pos = strpos($value, ':'));$hdr_value = substr($value, $pos+1);if($hdr_value[0] == ' ')$hdr_value = substr($hdr_value, 1);$return[] = array('name'  => $hdr_name,'value' => $this->_decode_headers ? $this->_decodeHeader($hdr_value) : $hdr_value);}} else {$return = array();}return $return;}/**** Function to parse a header value,* extract first part, and any secondary* parts (after ;) This function is not as* robust as it could be. Eg. header comments* in the wrong place will probably break it.** @param string Header value to parse* @return array Contains parsed result* @access private*/function _parseHeaderValue($input){if (($pos = strpos($input, ';')) !== false) {$return['value'] = trim(substr($input, 0, $pos));$input = trim(substr($input, $pos+1));if (strlen($input) > 0) {// This splits on a semi-colon, if there's no preceeding backslash// Now works with quoted values; had to glue the \; breaks in PHP// the regex is already bordering on incomprehensible$splitRegex = '/([^;\'"]*[\'"]([^\'"]*([^\'"]*)*)[\'"][^;\'"]*|([^;]+))(;|$)/';preg_match_all($splitRegex, $input, $matches);$parameters = array();for ($i=0; $i<count($matches[0]); $i++) {$param = $matches[0][$i];while (substr($param, -2) == '\;') {$param .= $matches[0][++$i];}$parameters[] = $param;}for ($i = 0; $i < count($parameters); $i++) {$param_name  = trim(substr($parameters[$i], 0, $pos = strpos($parameters[$i], '=')), "'\";\t\\ ");$param_value = trim(str_replace('\;', ';', substr($parameters[$i], $pos + 1)), "'\";\t\\ ");if ($param_value[0] == '"') {$param_value = substr($param_value, 1, -1);}$return['other'][$param_name] = $param_value;$return['other'][strtolower($param_name)] = $param_value;}}} else {$return['value'] = trim($input);}return $return;}/**** This function splits the input based* on the given boundary** @param string Input to parse* @return array Contains array of resulting mime parts* @access private*/function _boundarySplit($input, $boundary){$parts = array();$bs_possible = substr($boundary, 2, -2);$bs_check = '\"' . $bs_possible . '\"';if ($boundary == $bs_check) {$boundary = $bs_possible;}$tmp = explode('--' . $boundary, $input);for ($i = 1; $i < count($tmp) - 1; $i++) {$parts[] = $tmp[$i];}return $parts;}/**** Given a header, this function will decode it* according to RFC2047. Probably not *exactly** conformant, but it does pass all the given* examples (in RFC2047).** @param string Input header value to decode* @return string Decoded header value* @access private*/function _decodeHeader($input){// Remove white space between encoded-words$input = preg_replace('/(=\?[^?]+\?(q|b)\?[^?]*\?=)(\s)+=\?/i', '\1=?', $input);// For each encoded-word...while (preg_match('/(=\?([^?]+)\?(q|b)\?([^?]*)\?=)/i', $input, $matches)) {$encoded  = $matches[1];$charset  = $matches[2];$encoding = $matches[3];$text     = $matches[4];switch (strtolower($encoding)) {case 'b':$text = base64_decode($text);break;case 'q':$text = str_replace('_', ' ', $text);preg_match_all('/=([a-f0-9]{2})/i', $text, $matches);foreach($matches[1] as $value)$text = str_replace('='.$value, chr(hexdec($value)), $text);break;}$input = str_replace($encoded, $text, $input);}return $input;}/**** Given a body string and an encoding type,* this function will decode and return it.** @param  string Input body to decode* @param  string Encoding type to use.* @return string Decoded body* @access private*/function _decodeBody($input, $encoding = '7bit'){switch (strtolower($encoding)) {case '7bit':return $input;break;case 'quoted-printable':return $this->_quotedPrintableDecode($input);break;case 'base64':return base64_decode($input);break;default:return $input;}}/**** Given a quoted-printable string, this* function will decode and return it.** @param  string Input body to decode* @return string Decoded body* @access private*/function _quotedPrintableDecode($input){// Remove soft line breaks$input = preg_replace("/=\r?\n/", '', $input);// Replace encoded characters$input = preg_replace('/=([a-f0-9]{2})/ie', "chr(hexdec('\\1'))", $input);return $input;}/**** Checks the input for uuencoded files and returns* an array of them. Can be called statically, eg:** $files =& Mail_mimeDecode::uudecode($some_text);** It will check for the begin 666 ... end syntax* however and won't just blindly decode whatever you* pass it.** @param  string Input body to look for attahcments in* @return array  Decoded bodies, filenames and permissions* @access public* @author Unknown*/function &uudecode($input){// Find all uuencoded sectionspreg_match_all("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $input, $matches);for ($j = 0; $j < count($matches[3]); $j++) {$str      = $matches[3][$j];$filename = $matches[2][$j];$fileperm = $matches[1][$j];$file = '';$str = preg_split("/\r?\n/", trim($str));$strlen = count($str);for ($i = 0; $i < $strlen; $i++) {$pos = 1;$d = 0;$len=(int)(((ord(substr($str[$i],0,1)) -32) - ' ') & 077);while (($d + 3 <= $len) AND ($pos + 4 <= strlen($str[$i]))) {$c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);$c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);$c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);$c3 = (ord(substr($str[$i],$pos+3,1)) ^ 0x20);$file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));$file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));$file .= chr(((($c2 - ' ') & 077) << 6) |  (($c3 - ' ') & 077));$pos += 4;$d += 3;}if (($d + 2 <= $len) && ($pos + 3 <= strlen($str[$i]))) {$c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);$c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);$c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);$file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));$file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));$pos += 3;$d += 2;}if (($d + 1 <= $len) && ($pos + 2 <= strlen($str[$i]))) {$c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);$c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);$file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));}}$files[] = array('filename' => $filename, 'fileperm' => $fileperm, 'filedata' => $file);}return $files;}/**** getSendArray() returns the arguments required for Mail::send()* used to build the arguments for a mail::send() call ** Usage:* $mailtext = Full email (for example generated by a template)* $decoder = new Mail_mimeDecode($mailtext);* $parts =  $decoder->getSendArray();* if (!PEAR::isError($parts) {*     list($recipents,$headers,$body) = $parts;*     $mail = Mail::factory('smtp');*     $mail->send($recipents,$headers,$body);* } else {*     echo $parts->message;* }* @return mixed   array of recipeint, headers,body or Pear_Error* @access public* @author Alan Knowles <alan@akbkhome.com>*/function getSendArray(){// prevent warning if this is not set$this->_decode_headers = FALSE;$headerlist =$this->_parseHeaders($this->_header);$to = "";if (!$headerlist) {return $this->raiseError("Message did not contain headers");}foreach($headerlist as $item) {$header[$item['name']] = $item['value'];switch (strtolower($item['name'])) {case "to":case "cc":case "bcc":$to = ",".$item['value'];default:break;}}if ($to == "") {return $this->raiseError("Message did not contain any recipents");}$to = substr($to,1);return array($to,$header,$this->_body);} /**** Returns a xml copy of the output of* Mail_mimeDecode::decode. Pass the output in as the* argument. This function can be called statically. Eg:** $output = $obj->decode();* $xml    = Mail_mimeDecode::getXML($output);** The DTD used for this should have been in the package. Or* alternatively you can get it from cvs, or here:* http://www.phpguru.org/xmail/xmail.dtd.** @param  object Input to convert to xml. This should be the*                output of the Mail_mimeDecode::decode function* @return string XML version of input* @access public*/function getXML($input){$crlf    =  "\r\n";$output  = '<?xml version=\'1.0\'?>' . $crlf .'<!DOCTYPE email SYSTEM "http://www.phpguru.org/xmail/xmail.dtd">' . $crlf .'<email>' . $crlf .Mail_mimeDecode::_getXML($input) .'</email>';return $output;}/**** Function that does the actual conversion to xml. Does a single* mimepart at a time.** @param  object  Input to convert to xml. This is a mimepart object.*                 It may or may not contain subparts.* @param  integer Number of tabs to indent* @return string  XML version of input* @access private*/function _getXML($input, $indent = 1){$htab    =  "\t";$crlf    =  "\r\n";$output  =  '';$headers = @(array)$input->headers;foreach ($headers as $hdr_name => $hdr_value) {// Multiple headers with this nameif (is_array($headers[$hdr_name])) {for ($i = 0; $i < count($hdr_value); $i++) {$output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value[$i], $indent);}// Only one header of this sort} else {$output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value, $indent);}}if (!empty($input->parts)) {for ($i = 0; $i < count($input->parts); $i++) {$output .= $crlf . str_repeat($htab, $indent) . '<mimepart>' . $crlf .Mail_mimeDecode::_getXML($input->parts[$i], $indent+1) .str_repeat($htab, $indent) . '</mimepart>' . $crlf;}} elseif (isset($input->body)) {$output .= $crlf . str_repeat($htab, $indent) . '<body><![CDATA[' .$input->body . ']]></body>' . $crlf;}return $output;}/**** Helper function to _getXML(). Returns xml of a header.** @param  string  Name of header* @param  string  Value of header* @param  integer Number of tabs to indent* @return string  XML version of input* @access private*/function _getXML_helper($hdr_name, $hdr_value, $indent){$htab   = "\t";$crlf   = "\r\n";$return = '';$new_hdr_value = ($hdr_name != 'received') ? Mail_mimeDecode::_parseHeaderValue($hdr_value) : array('value' => $hdr_value);$new_hdr_name  = str_replace(' ', '-', ucwords(str_replace('-', ' ', $hdr_name)));// Sort out any parametersif (!empty($new_hdr_value['other'])) {foreach ($new_hdr_value['other'] as $paramname => $paramvalue) {$params[] = str_repeat($htab, $indent) . $htab . '<parameter>' . $crlf .str_repeat($htab, $indent) . $htab . $htab . '<paramname>' . htmlspecialchars($paramname) . '</paramname>' . $crlf .str_repeat($htab, $indent) . $htab . $htab . '<paramvalue>' . htmlspecialchars($paramvalue) . '</paramvalue>' . $crlf .str_repeat($htab, $indent) . $htab . '</parameter>' . $crlf;}$params = implode('', $params);} else {$params = '';}$return = str_repeat($htab, $indent) . '<header>' . $crlf .str_repeat($htab, $indent) . $htab . '<headername>' . htmlspecialchars($new_hdr_name) . '</headername>' . $crlf .str_repeat($htab, $indent) . $htab . '<headervalue>' . htmlspecialchars($new_hdr_value['value']) . '</headervalue>' . $crlf .$params .str_repeat($htab, $indent) . '</header>' . $crlf;return $return;}} // End of class

相關文件:

??? http://www.oschina.net/code/explore/magento-1.4.2.0/lib/PEAR

所需文件用 [*] 標注

目 錄

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:
http://www.pswp.cn/news/276335.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/276335.shtml
英文地址,請注明出處:http://en.pswp.cn/news/276335.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

android 單元測試

首先AndroidManifest.xml View Code <?xml version"1.0" encoding"utf-8"?> <manifest xmlns:android"http://schemas.android.com/apk/res/android"package"com.travelsky.test" android:versionCode"1"androi…

申萬一級行業日指數_基金收評 | 指數震蕩走弱,軍工股成兩市主線!后期行情如何?...

收評君復盤日記(2020年9月21日)三大指數集體收跌&#xff0c;北向資金全天大幅凈流出近65億元&#xff0c;軍工板塊表現強勢。盤面回顧9月21日&#xff0c;兩市全天高開低走&#xff0c;早盤指數弱勢震蕩&#xff0c;三大指數盤中一度翻紅&#xff0c;但隨后震蕩走弱&#xff0…

若川的2016年度總結,畢業工作

可以點擊上方的標簽若川的故事、年度總結&#xff0c;查看往期文章有讀者反饋說看我年度總結系列比我源碼系列更有啟發。所以打算把2016-2018的年度總結發布到公眾號聲明原創&#xff0c;希望對大家有所啟發。&#xff08;雖然我的每一年都過得非常普通...&#xff09;以下是正…

jQuery之Ajax

轉載鏈接&#xff1a;http://cargoj.iteye.com/blog/1008047 1 . jQuery幫助之Ajax請求&#xff08;一&#xff09;jQuery.ajax(options) 2 . jQuery幫助之Ajax請求&#xff08;二&#xff09;jQuery.get(url,[data],[callback] 3 . jQuery幫助之Ajax請求&#xff08;三&am…

深入淺出之正則表達式(二)

深入淺出之正則表達式&#xff08;二&#xff09; http://dragon.cnblogs.com/archive/2006/05/09/394923.html 前言&#xff1a; 本文是前一片文章《深入淺出之正則表達式&#xff08;一&#xff09;》的續篇&#xff0c;在本文中講述了正則表達式中的組與向后引用&…

MVC(溫習深入)

MVC&#xff08;Model-View-Controller&#xff0c;模型—視圖—控制器模式&#xff09;是軟件工程中的一種軟件架構模式。它把軟件系統分為三個基本部分&#xff1a;模型&#xff08;Model&#xff09;&#xff0c;視圖&#xff08;View&#xff09;和控制器&#xff08;Contr…

面試官問:能否模擬實現JS的new操作符(高頻考點)

可以點擊上方的話題JS基礎系列&#xff0c;查看往期文章這篇文章寫于2018年11月05日&#xff0c;new模擬實現&#xff0c;Object.create是面試高頻考點&#xff0c;之前發布在掘金有近2萬人閱讀&#xff0c;現在發布到公眾號聲明原創。1. 前言這是面試官問系列的第一篇&#xf…

Linux環境下設置IPDNSGateway

轉載鏈接&#xff1a;http://www.myhack58.com/Article/sort099/sort0102/2011/29291.htm 在Linux中不管你是做服務器還是只是平常使用&#xff0c;上網肯定都是最重要和不可缺少的一個因素之一&#xff0c;所以就涉及到它的ip gateway dns等network配置和使用。但是設置Linux…

跟我一起學WCF(2)——利用.NET Remoting技術開發分布式應用

一、引言 上一篇博文分享了消息隊列&#xff08;MSMQ&#xff09;技術來實現分布式應用&#xff0c;在這篇博文繼續分享下.NET平臺下另一種分布式技術——.NET Remoting。 二、.NET Remoting 介紹 2.1 .NET Remoting簡介 .NET REmoting與MSMQ不同&#xff0c;它不支持離線可得&…

二叉樹的建立與遍歷_51、二叉樹遍歷-重建二叉樹JZ4

題目描述輸入某二叉樹的前序遍歷和中序遍歷的結果&#xff0c;請重建出該二叉樹。假設輸入的前序遍歷和中序遍歷的結果中都不含重復的數字。例如輸入前序遍歷序列{1,2,4,7,3,5,6,8}和中序遍歷序列{4,7,2,1,5,3,8,6}&#xff0c;則重建二叉樹并返回。思路回顧三種經典的遍歷&…

越來越覺得現在的工作很枯燥

很不想這么說&#xff0c;但又不想欺騙自己&#xff0c;真的是很枯燥&#xff0c;不過這種感覺早在一年在在上一間公司時就很強烈的有過這種感覺了&#xff0c;只不過現在是又一次有感觸罷了。話說說我這種性質的工作枯燥很多人都講過&#xff0c;如果哪個人說不枯燥估計腦袋進…

推薦關注這7個高質量的前端公眾號

拓寬眼界&#xff0c;增加深度&#xff0c;在閱讀的世界里&#xff0c;我們往往能找到不一樣的態度&#xff0c;提升朋友圈質量&#xff0c;從關注這幾個公眾號開始。輕掃一下二維碼就行了&#xff0c;你可以試試&#xff0c;肯定會有意外收獲。大遷世界 簡介&#xff1a;前端小…

MySQL 實用語句集合

MySQL 實用語句集合 參考鏈接[用戶]&#xff1a;http://blog.csdn.net/dmtnewtons_blog/article/details/9136339 參考鏈接[屬性]&#xff1a;http://stackoverflow.com/questions/15821532/get-current-auto-increment-value-for-any-table 參考鏈接[索引]&#xff1a;htt…

python對象序列化或持久化的方法

http://blog.csdn.net/chen_lovelotus/article/details/7233293 一、Python對象持久化方法 目前為止&#xff0c;據我所知&#xff0c;在python中對象持久化有以下幾種方法&#xff1a; 1. 使用(dbhash/bsddb, dbm, gdbm, dumbdbm 等&#xff09;以及它們的"管理器"(…

Windows Live Writer 在win2003 的安裝方法

下載Windows Live Writer整體安裝包&#xff0c;最好是離線安裝包 2.在xp系統上安裝 3.查找C:\Program Files\Common Files\Windows Live\.cache目錄 .cache目錄是隱藏的&#xff0c;目錄下面就是各個安裝文件的msi安裝包 4.拷貝相應的msi文件&#xff0c;到Windows 2003安裝就…

decode 大于比較 小于_6 燃氣輸配系統6.3 壓力不大于1.6Mpa的室外燃氣管道城鎮燃氣設計規范 GB500282006(2020修訂版)...

6.3 壓力不大于1.6Mpa的室外燃氣管道6.3.1中壓和低壓燃氣管道宜采用聚乙烯管、機械接口球墨鑄鐵管、鋼管或鋼骨架聚乙烯塑料復合管&#xff0c;并應符合下列要求&#xff1a; 1 聚乙烯燃氣管應符合現行的國家標準《燃氣用埋地聚乙烯管材》GB15558.1 和《燃氣用埋地聚乙烯管件…

若川的2017年度總結,一如既往

可以點擊上方的標簽若川的故事、年度總結&#xff0c;查看往期文章有讀者反饋說看我年度總結系列比我源碼系列更有啟發。所以打算把2016-2018的年度總結發布到公眾號聲明原創&#xff0c;希望對大家有所啟發。&#xff08;雖然我的每一年都過得非常普通...&#xff09;若川的20…

MIME協議及源郵件格式分析

轉載鏈接&#xff1a;http://wenku.baidu.com/view/7246de671ed9ad51f01df277.html 電子郵件也許是一個Internet上的流行最廣泛的應用。也是我們現在的大多數網絡辦公流程的基礎。各種郵件服務器很多,但都大都遵循以1982年出版的RFC822--《ARPA網絡文本信息格式標準(STANDARD F…

溝通:用故事產生共鳴

《溝通:用故事產生共鳴》(全彩) 基本信息作者&#xff1a; Nancy Duarte(南希.杜瓦特)譯者&#xff1a; 馮海洋出版社&#xff1a;電子工業出版社ISBN&#xff1a;9787121195914上架時間&#xff1a;2013-4-1出版日期&#xff1a;2013 年3月開本&#xff1a;12開頁碼&#xff1…

合工大五套卷_2020合工大超越數一五套卷第一套感想

合工大的卷子確實不錯&#xff0c;題目給我的感覺是題干包裝的看起來就很難&#xff0c;但是寫起來還是一樣的套路。計算上要難一些&#xff0c;需要細心點選擇題:1.可去間斷點的定義和泰勒公式2.這個題我用排除法寫的&#xff0c;可微的話連續和偏導存在都成立了&#xff0c;然…