Source for file mimePart.php
Documentation is available at mimePart.php
* The Mail_mimePart class is used to create MIME E-mail messages
* This class enables you to manipulate and build a mime email
* from the ground up. The Mail_Mime class is a userfriendly api
* to this class for people who aren't interested in the internals
* This class however allows full control over the email.
* 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>
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* - 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.
* @author Richard Heyes <richard@phpguru.org>
* @author Cipriano Groenendal <cipri@php.net>
* @author Sean Coates <sean@php.net>
* @author Aleksander Machniak <alec@php.net>
* @copyright 2003-2006 PEAR <pear-group@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://pear.php.net/package/Mail_mime
* The Mail_mimePart class is used to create MIME E-mail messages
* This class enables you to manipulate and build a mime email
* from the ground up. The Mail_Mime class is a userfriendly api
* to this class for people who aren't interested in the internals
* This class however allows full control over the email.
* @author Richard Heyes <richard@phpguru.org>
* @author Cipriano Groenendal <cipri@php.net>
* @author Sean Coates <sean@php.net>
* @author Aleksander Machniak <alec@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
* The encoding type of this part
* The output of this part after being built
* The body of this part (not encoded)
* The location of file with body of this part (not encoded)
* The end-of-line sequence
* @param string $body The body of the mime part if any.
* @param array $params An associative array of optional parameters:
* content_type - The content type for this part eg multipart/mixed
* encoding - The encoding to use, 7bit, 8bit,
* base64, or quoted-printable
* charset - Content character set
* cid - Content ID to apply
* disposition - Content disposition, inline or attachment
* filename - Filename parameter for content disposition
* description - Content description
* name_encoding - Encoding of the attachment name (Content-Type)
* By default filenames are encoded using RFC2231
* Here you can set RFC2047 encoding (quoted-printable
* filename_encoding - Encoding of the attachment filename (Content-Disposition)
* headers_charset - Charset of the headers e.g. filename, description.
* If not set, 'charset' will be used
* eol - End of line sequence. Default: "\r\n"
* headers - Hash array with additional part headers. Array keys can be
* in form of <header_name>:<parameter_name>
* body_file - Location of file with part's body (instead of $body)
if (!empty ($params['eol'])) {
$this->_eol = $params['eol'];
} else if (defined('MAIL_MIMEPART_CRLF')) { // backward-copat.
$this->_eol = MAIL_MIMEPART_CRLF;
// Additional part headers
if (!empty ($params['headers']) && is_array($params['headers'])) {
$headers = $params['headers'];
foreach ($params as $key => $value) {
$this->_encoding = $value;
$headers['Content-Transfer-Encoding'] = $value;
$headers['Content-ID'] = '<' . $value . '>';
$headers['Content-Location'] = $value;
$this->_body_file = $value;
// for backward compatibility
$params['filename'] = $value;
if (empty ($params['content_type'])) {
$params['content_type'] = 'text/plain';
$headers['Content-Type'] = $params['content_type'];
if (!empty ($params['charset'])) {
$charset = " charset={$params['charset']}";
// place charset parameter in the same line, if possible
if ((strlen($headers['Content-Type']) + strlen($charset) + 16 ) <= 76 ) {
$headers['Content-Type'] .= '; ';
$headers['Content-Type'] .= ';' . $this->_eol . ' ';
$headers['Content-Type'] .= $charset;
// Default headers charset
if (!isset ($params['headers_charset'])) {
$params['headers_charset'] = $params['charset'];
// header values encoding parameters
$h_charset = !empty ($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII';
$h_language = !empty ($params['language']) ? $params['language'] : null;
$h_encoding = !empty ($params['name_encoding']) ? $params['name_encoding'] : null;
if (!empty ($params['filename'])) {
$headers['Content-Type'] .= ';' . $this->_eol;
$headers['Content-Type'] .= $this->_buildHeaderParam (
'name', $params['filename'], $h_charset, $h_language, $h_encoding
if (!empty ($params['disposition'])) {
$headers['Content-Disposition'] = $params['disposition'];
if (!empty ($params['filename'])) {
$headers['Content-Disposition'] .= ';' . $this->_eol;
$headers['Content-Disposition'] .= $this->_buildHeaderParam (
'filename', $params['filename'], $h_charset, $h_language,
!empty ($params['filename_encoding']) ? $params['filename_encoding'] : null
$size = $this->_body_file ? filesize($this->_body_file) : strlen($body);
$headers['Content-Disposition'] .= ';' . $this->_eol . ' size=' . $size;
if (!empty ($params['description'])) {
'Content-Description', $params['description'], $h_charset, $h_encoding,
// Search and add existing headers' parameters
foreach ($headers as $key => $value) {
if (count($items) == 2 ) {
if (isset ($headers[$header])) {
$headers[$header] .= ';' . $this->_eol;
$headers[$header] .= $this->_buildHeaderParam (
$param, $value, $h_charset, $h_language, $h_encoding
if (!isset ($this->_encoding)) {
$this->_encoding = '7bit';
// Assign stuff to member variables
$this->_encoded = array ();
$this->_headers = $headers;
* Encodes and returns the email. Also stores
* it in the encoded member variable
* @param string $boundary Pre-defined boundary string
* @return An associative array containing two elements,
* body and headers. The headers element is itself
* an indexed array. On error returns PEAR error object.
function encode($boundary=null )
$encoded = & $this->_encoded;
if (count($this->_subparts)) {
$this->_headers['Content-Type'] .= " ;$eol boundary=\"$boundary\"";
for ($i = 0; $i < count($this->_subparts); $i++ ) {
$encoded['body'] .= '--' . $boundary . $eol;
$tmp = $this->_subparts[$i]->encode ();
if ($this->_isError ($tmp)) {
foreach ($tmp['headers'] as $key => $value) {
$encoded['body'] .= $key . ': ' . $value . $eol;
$encoded['body'] .= $eol . $tmp['body'] . $eol;
$encoded['body'] .= '--' . $boundary . '--' . $eol;
} else if ($this->_body) {
$encoded['body'] = $this->_getEncodedData ($this->_body, $this->_encoding);
} else if ($this->_body_file) {
// Temporarily reset magic_quotes_runtime for file reads and writes
@ini_set('magic_quotes_runtime', 0 );
$body = $this->_getEncodedDataFromFile ($this->_body_file, $this->_encoding);
if ($magic_quote_setting) {
@ini_set('magic_quotes_runtime', $magic_quote_setting);
if ($this->_isError ($body)) {
$encoded['body'] = $body;
// Add headers to $encoded
$encoded['headers'] = & $this->_headers;
* Encodes and saves the email into file. File must exist.
* Data will be appended to the file.
* @param string $filename Output file location
* @param string $boundary Pre-defined boundary string
* @param boolean $skip_head True if you don't want to save headers
* @return array An associative array containing message headers
function encodeToFile($filename, $boundary=null , $skip_head=false )
$err = PEAR ::raiseError ('File is not writeable: ' . $filename);
if (!($fh = fopen($filename, 'ab'))) {
$err = PEAR ::raiseError ('Unable to open file: ' . $filename);
// Temporarily reset magic_quotes_runtime for file reads and writes
@ini_set('magic_quotes_runtime', 0 );
$res = $this->_encodePartToFile ($fh, $boundary, $skip_head);
if ($magic_quote_setting) {
@ini_set('magic_quotes_runtime', $magic_quote_setting);
return $this->_isError ($res) ? $res : $this->_headers;
* Encodes given email part into file
* @param string $fh Output file handle
* @param string $boundary Pre-defined boundary string
* @param boolean $skip_head True if you don't want to save headers
* @return array True on sucess or PEAR error object
function _encodePartToFile ($fh, $boundary=null , $skip_head=false )
if (count($this->_subparts)) {
$this->_headers['Content-Type'] .= " ;$eol boundary=\"$boundary\"";
foreach ($this->_headers as $key => $value) {
fwrite($fh, $key . ': ' . $value . $eol);
if (count($this->_subparts)) {
for ($i = 0; $i < count($this->_subparts); $i++ ) {
fwrite($fh, $f_eol . '--' . $boundary . $eol);
$res = $this->_subparts[$i]->_encodePartToFile ($fh);
if ($this->_isError ($res)) {
fwrite($fh, $eol . '--' . $boundary . '--' . $eol);
} else if ($this->_body) {
fwrite($fh, $f_eol . $this->_getEncodedData ($this->_body, $this->_encoding));
} else if ($this->_body_file) {
$res = $this->_getEncodedDataFromFile (
$this->_body_file, $this->_encoding, $fh
if ($this->_isError ($res)) {
* Adds a subpart to current mime part and returns
* @param string $body The body of the subpart, if any.
* @param array $params The parameters for the subpart, same
* as the $params argument for constructor.
* @return Mail_mimePart A reference to the part you just added. It is
* crucial if using multipart/* in your subparts that
* you use =& in your script when calling this function,
* otherwise you will not be able to add further subparts.
return $this->_subparts[count($this->_subparts) - 1 ];
* Returns encoded data based upon encoding passed to it
* @param string $data The data to encode.
* @param string $encoding The encoding type to use, 7bit, base64,
function _getEncodedData ($data, $encoding)
return $this->_quotedPrintableEncode ($data);
* Returns encoded data based upon encoding passed to it
* @param string $filename Data file location
* @param string $encoding The encoding type to use, 7bit, base64,
* @param resource $fh Output file handle. If set, data will be
* stored into it instead of returning it
* @return string Encoded data or PEAR error object
function _getEncodedDataFromFile ($filename, $encoding, $fh=null )
$err = PEAR ::raiseError ('Unable to read file: ' . $filename);
if (!($fd = fopen($filename, 'rb'))) {
$err = PEAR ::raiseError ('Could not open file: ' . $filename);
$buffer = $this->_quotedPrintableEncode (fgets($fd));
// Should read in a multiple of 57 bytes so that
// the output is 76 bytes per line. Don't use big chunks
// because base64 encoding is memory expensive
$buffer = fread($fd, 57 * 9198 ); // ca. 0.5 MB
$buffer = rtrim($buffer);
$buffer = fread($fd, 1048576 ); // 1 MB
* Encodes data to quoted-printable standard.
* @param string $input The data to encode
* @param int $line_max Optional max line length. Should
* not be more than 76 chars
* @return string Encoded data
function _quotedPrintableEncode ($input , $line_max = 76 )
// imap_8bit() is extremely fast, but doesn't handle properly some characters
if (function_exists('imap_8bit') && $line_max == 76) {
$input = preg_replace('/\r?\n/', "\r\n", $input);
$input = imap_8bit($input);
$input = str_replace("\r\n", $eol, $input);
while (list ($idx, $line) = each($lines)) {
while (isset ($line[$i])) {
if (($dec == 32 ) && (!isset ($line[$i]))) {
// convert space at eol only
} elseif ($dec == 9 && isset ($line[$i])) {
; // Do nothing if a TAB is not on eol
} elseif (($dec == 61 ) || ($dec < 32 ) || ($dec > 126 )) {
$char = $escape . sprintf('%02X', $dec);
} elseif (($dec == 46 ) && (($newline == '')
// Bug #9722: convert full-stop at bol,
// some Windows servers need this, won't break anything (cipri)
// Bug #11731: full-stop at bol also needs to be encoded
// if this line would push us over the line_max limit.
// Note, when changing this line, also change the ($dec == 46)
// check line, as it mimics this line due to Bug #11731
// soft line break; " =\r\n" is okay
$output .= $newline . $escape . $eol;
$output .= $newline . $eol;
* Encodes the paramater of a header.
* @param string $name The name of the header-parameter
* @param string $value The value of the paramter
* @param string $charset The characterset of $value
* @param string $language The language used in $value
* @param string $encoding Parameter encoding. If not set, parameter value
* is encoded according to RFC2231
* @param int $maxLength The maximum length of a line. Defauls to 75
function _buildHeaderParam ($name, $value, $charset=null , $language=null ,
$encoding=null , $maxLength=75
// value needs encoding if contains non-ASCII chars or is longer than 78 chars
$token_regexp = '#([^\x21\x23-\x27\x2A\x2B\x2D'
. '\x2E\x30-\x39\x41-\x5A\x5E-\x7E])#';
return " {$name}={$value}";
return " {$name}=\"{$quoted}\"";
// RFC2047: use quoted-printable/base64 encoding
if ($encoding == 'quoted-printable' || $encoding == 'base64') {
return $this->_buildRFC2047Param ($name, $value, $charset, $encoding);
'/([^\x21\x23\x24\x26\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E])/',
array ($this, '_encodeReplaceCallback'), $value
$value = " $charset'$language'$encValue";
$header = " {$name}*={$value}";
if (strlen($header) <= $maxLength) {
$preLength = strlen(" {$name}*0*=" );
$maxLength = max(16 , $maxLength - $preLength - 3 );
$maxLengthReg = " |(.{0,$maxLength}[^\%][^\%])|";
$found = preg_match($maxLengthReg, $value, $matches);
$headers[] = " {$name}*{$headCount}*={$matches[0]}";
$headers[] = " {$name}*{$headCount}*={$value}";
$headers = implode(';' . $this->_eol, $headers);
* Encodes header parameter as per RFC2047 if needed
* @param string $name The parameter name
* @param string $value The parameter value
* @param string $charset The parameter charset
* @param string $encoding Encoding type (quoted-printable or base64)
* @param int $maxLength Encoded parameter max length. Default: 76
* @return string Parameter line
function _buildRFC2047Param ($name, $value, $charset,
$encoding= 'quoted-printable', $maxLength=76
// WARNING: RFC 2047 says: "An 'encoded-word' MUST NOT be used in
// parameter of a MIME Content-Type or Content-Disposition field",
// but... it's supported by many clients/servers
if ($encoding == 'base64') {
$prefix = '=?' . $charset . '?B?';
// 2 x SPACE, 2 x '"', '=', ';'
$len = $add_len + strlen($value);
while ($len > $maxLength) {
// We can cut base64-encoded string every 4 characters
$real_len = floor(($maxLength - $add_len) / 4 ) * 4;
$_quote = substr($value, 0 , $real_len);
$value = substr($value, $real_len);
$quoted .= $prefix . $_quote . $suffix . $this->_eol . ' ';
$add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'
$len = strlen($value) + $add_len;
$quoted .= $prefix . $value . $suffix;
$prefix = '=?' . $charset . '?Q?';
// 2 x SPACE, 2 x '"', '=', ';'
$len = $add_len + strlen($value);
while ($len > $maxLength) {
$length = $maxLength - $add_len;
// don't break any encoded letters
if (preg_match(" /^(.{0,$length}[^\=][^\=])/" , $value, $matches)) {
$quoted .= $prefix . $_quote . $suffix . $this->_eol . ' ';
$add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'
$len = strlen($value) + $add_len;
$quoted .= $prefix . $value . $suffix;
return " {$name}=\"{$quoted}\"";
* Encodes a header as per RFC2047
* @param string $name The header name
* @param string $value The header data to encode
* @param string $charset Character set name
* @param string $encoding Encoding name (base64 or quoted-printable)
* @param string $eol End-of-line sequence. Default: "\r\n"
* @return string Encoded header data (without a name)
$encoding= 'quoted-printable', $eol= "\r\n"
'from', 'to', 'cc', 'bcc', 'sender', 'reply-to',
'resent-from', 'resent-to', 'resent-cc', 'resent-bcc',
'resent-sender', 'resent-reply-to',
'mail-reply-to', 'mail-followup-to',
'return-receipt-to', 'disposition-notification-to',
'references', 'in-reply-to', 'message-id', 'resent-message-id',
} else if (in_array($name, $other_headers)) {
// Structured header (make sure addr-spec inside is not encoded)
if (!empty ($separator)) {
// Simple e-mail address regexp
$email_regexp = '([^\s<]+|("[^\r\n"]+"))@\S+';
$parts = Mail_mimePart::_explodeQuotedString ($separator, $value);
foreach ($parts as $part) {
$value .= $separator== ',' ? $separator. ' ' : ' ';
// let's find phrase (name) and/or addr-spec
if (preg_match('/^<' . $email_regexp . '>$/', $part)) {
} else if (preg_match('/^' . $email_regexp . '$/', $part)) {
// address without brackets and without name
} else if (preg_match('/<*' . $email_regexp . '>*$/', $part, $matches)) {
// address with name (handle name)
// check if phrase requires quoting
// non-ASCII: require encoding
if ($word[0 ] == '"' && $word[strlen($word)-1 ] == '"') {
// de-quote quoted-string, encoding changes
$search = array ("\\\"", "\\\\");
$replace = array ("\"", "\\");
// find length of last line
if (($pos = strrpos($value, $eol)) !== false ) {
$last_len = strlen($value) - $pos;
$word, $charset, $encoding, $last_len, $eol
} else if (($word[0 ] != '"' || $word[strlen($word)-1 ] != '"')
// ASCII: quote string if needed
$value .= $word. ' '. $address;
// addr-spec not found, don't encode (?)
// RFC2822 recommends 78 characters limit, use 76 from RFC2047
$value = wordwrap($value, 76 , $eol . ' ');
// remove header name prefix (there could be EOL too)
'/^'. $name. ':('. preg_quote($eol, '/'). ')* /', '', $value
// non-ASCII: require encoding
if ($value[0 ] == '"' && $value[strlen($value)-1 ] == '"') {
// de-quote quoted-string, encoding changes
$search = array ("\\\"", "\\\\");
$replace = array ("\"", "\\");
$value = substr($value, 1 , -1 );
$value, $charset, $encoding, strlen($name) + 2 , $eol
} else if (strlen($name. ': '. $value) > 78 ) {
// ASCII: check if header line isn't too long and use folding
$value = preg_replace('/\r?\n[\s\t]*/', $eol . ' ', $value);
$tmp = wordwrap($name. ': '. $value, 78 , $eol . ' ');
// hard limit 998 (RFC2822)
$value = wordwrap($value, 998 , $eol . ' ', true );
* @param string $delimiter Delimiter expression string for preg_match()
* @param string $string Input string
* @return array String tokens array
function _explodeQuotedString ($delimiter, $string)
for ($q= $p= $i=0; $i < $strlen; $i++ ) {
&& (empty ($string[$i-1 ]) || $string[$i-1 ] != "\\")
} else if (!$q && preg_match(" /$delimiter/" , $string[$i])) {
$result[] = substr($string, $p, $i - $p);
$result[] = substr($string, $p);
* Encodes a header value as per RFC2047
* @param string $value The header data to encode
* @param string $charset Character set name
* @param string $encoding Encoding name (base64 or quoted-printable)
* @param int $prefix_len Prefix length. Default: 0
* @param string $eol End-of-line sequence. Default: "\r\n"
* @return string Encoded header data
// #17311: Use multibyte aware method (requires mbstring extension)
// Generate the header using the specified params and dynamicly
// determine the maximum length of such strings.
// 75 is the value specified in the RFC.
$encoding = $encoding == 'base64' ? 'B' : 'Q';
$prefix = '=?' . $charset . '?' . $encoding . '?';
$maxLength = 75 - strlen($prefix . $suffix);
$maxLength1stLine = $maxLength - $prefix_len;
// Base64 encode the entire string
// We can cut base64 every 4 characters, so the real max
// we can get must be rounded down.
$maxLength = $maxLength - ($maxLength % 4 );
$maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4 );
$cutpoint = $maxLength1stLine;
// Split translated string at every $maxLength
$part = substr($value, 0 , $cutpoint);
$value = substr($value, $cutpoint);
// RFC 2047 specifies that any split header should
// be seperated by a CRLF SPACE.
$output .= $prefix . $part . $suffix;
// quoted-printable encoding has been selected
// This regexp will break QP-encoded text at every $maxLength
// but will not break any encoded letters.
$reg1st = " |(.{0,$maxLength1stLine}[^\=][^\=])|";
$reg2nd = " |(.{0,$maxLength}[^\=][^\=])|";
if (strlen($value) > $maxLength1stLine) {
// Begin with the regexp for the first line.
// Split translated string at every $maxLength
// But make sure not to break any translated chars.
// After this first line, we need to use a different
// regexp for the first line.
// Save the found part and encapsulate it in the
// prefix & suffix. Then remove the part from the
$value = substr($value, $len);
// RFC 2047 specifies that any split header should
// be seperated by a CRLF SPACE
$output .= $prefix . $part . $suffix;
$value = $prefix . $value . $suffix;
* Encodes the given string using quoted-printable
* @param string $str String to encode
* @return string Encoded string
// Bug #17226 RFC 2047 restricts some characters
// if the word is inside a phrase, permitted chars are only:
// ASCII letters, decimal digits, "!", "*", "+", "-", "/", "=", and "_"
// "=", "_", "?" must be encoded
$regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/';
$regexp, array ('Mail_mimePart', '_qpReplaceCallback'), $str
* Encodes the given string using base64 or quoted-printable.
* This method makes sure that encoded-word represents an integral
* number of characters as per RFC2047.
* @param string $str String to encode
* @param string $charset Character set name
* @param string $encoding Encoding name (base64 or quoted-printable)
* @param int $prefix_len Prefix length. Default: 0
* @param string $eol End-of-line sequence. Default: "\r\n"
* @return string Encoded string
function encodeMB($str, $charset, $encoding, $prefix_len=0 , $eol= "\r\n")
$encoding = $encoding == 'base64' ? 'B' : 'Q';
// 75 is the value specified in the RFC
$prefix = '=?' . $charset . '?'. $encoding. '?';
$maxLength = 75 - strlen($prefix . $suffix);
// A multi-octet character may not be split across adjacent encoded-words
// So, we'll loop over each character
// mb_stlen() with wrong charset will generate a warning here and return null
$line_length = $prefix_len;
for ($i=1; $i<= $length; $i++ ) {
$chunk = mb_substr($str, $start, $i- $start, $charset);
if ($line_length + $chunk_len == $maxLength || $i == $length) {
} else if ($line_length + $chunk_len > $maxLength) {
$regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/';
for ($i=0; $i<= $length; $i++ ) {
// RFC recommends underline (instead of =20) in place of the space
// that's one of the reasons why we're not using iconv_mime_encode()
$regexp, array ('Mail_mimePart', '_qpReplaceCallback'), $char
if ($line_length + $char_len > $maxLength) {
$line_length += $char_len;
. str_replace("\n", $suffix. $eol. ' '. $prefix, $result). $suffix;
* Callback function to replace extended characters (\x80-xFF) with their
* ASCII values (RFC2047: quoted-printable)
* @param array $matches Preg_replace's matches array
* @return string Encoded character string
function _qpReplaceCallback ($matches)
* Callback function to replace extended characters (\x80-xFF) with their
* @param array $matches Preg_replace's matches array
* @return string Encoded character string
function _encodeReplaceCallback ($matches)
* @param mixed $data Object
* @return bool True if object is an instance of PEAR_Error
// PEAR::isError() is not PHP 5.4 compatible (see Bug #19473)
Documentation generated on Tue, 25 Dec 2012 17:30:05 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|