cvs: pear /Mail_Mime mime.php

From: Date: Sun, 22 Apr 2007 00:07:08 +0000
Subject: cvs: pear /Mail_Mime mime.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-46083@lists.php.net to get a copy of this message
cipri Sun Apr 22 00:07:08 2007 UTC Modified files: /pear/Mail_Mime mime.php Log: Darn those tabs, again.

http://cvs.php.net/viewvc.cgi/pear/Mail_Mime/mime.php?r1=1.69&r2=1.70&diff_format=u Index: pear/Mail_Mime/mime.php diff -u pear/Mail_Mime/mime.php:1.69 pear/Mail_Mime/mime.php:1.70 --- pear/Mail_Mime/mime.php:1.69 Sun Apr 22 00:06:39 2007 +++ pear/Mail_Mime/mime.php Sun Apr 22 00:07:08 2007 @@ -47,7 +47,7 @@ * @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: mime.php,v 1.69 2007/04/22 00:06:39 cipri Exp $ + * @version CVS: $Id: mime.php,v 1.70 2007/04/22 00:07:08 cipri Exp $ * @link http://pear.php.net/package/Mail_mime * @notes This class is based on HTML Mime Mail class from * Richard Heyes <richard@phpguru.org> which was based also @@ -877,95 +877,95 @@ $hdr_value = iconv_mime_encode($hdr_name, $hdr_value, $imePrefs); $hdr_value = preg_replace("#^{$hdr_name}\:\ #", "", $hdr_value); }elseif ($build_params['head_encoding'] == 'base64'){ - //Base64 encoding has been selected. - //Base64 encode the entire string - $hdr_value = base64_encode($hdr_value); - - //Generate the header using the specified params and dynamicly - //determine the maximum length of such strings. - //75 is the value specified in the RFC. The first -2 is there so - //the later regexp doesn't break any of the translated chars. - //The -2 on the first line-regexp is to compensate for the ": " - //between the header-name and the header value - $prefix = '=?' . $build_params['head_charset'] . '?B?'; - $suffix = '?='; - $maxLength = 75 - strlen($prefix . $suffix) - 2; - $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; - - //We can cut base4 every 4 characters, so the real max we can get must be rounded down. - $maxLength = $maxLength - ($maxLength % 4); - $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4); - - $cutpoint = $maxLength1stLine; - $hdr_value_out = $hdr_value; - $output = ""; - while ($hdr_value_out) { - //Split translated string at every $maxLength - $part = substr($hdr_value_out, 0, $cutpoint); - $hdr_value_out = substr($hdr_value_out, $cutpoint); - $cutpoint = $maxLength; - //RFC 2047 specifies that any split header should be seperated - //by a CRLF SPACE. - if ($output){ - $output .= "\r\n "; - } - $output .= $prefix . $part . $suffix; - } - $hdr_value = $output; - }else{ - //quoted-printable encoding has been selected - - //Fix for Bug #10298, Ota Mares <om@viazenetti.de> - //Check if there is a double quote at beginning or end of the string to - //prevent that an open or closing quote gets ignored because its encapsuled - //by an encoding prefix or suffix. - //Remove the double quote and set the specific prefix or suffix variable - //so later we can concat the encoded string and the double quotes back - //together to get the intended string. - $quotePrefix = $quoteSuffix = ''; - if ($hdr_value{0} == '"') { - $hdr_value = substr($hdr_value, 1); - $quotePrefix = '"'; - } - if ($hdr_value{strlen($hdr_value)-1} == '"') { - $hdr_value = substr($hdr_value, 0, -1); - $quoteSuffix = '"'; - } - - //Generate the header using the specified params and dynamicly - //determine the maximum length of such strings. - //75 is the value specified in the RFC. The -2 is there so - //the later regexp doesn't break any of the translated chars. - //The -2 on the first line-regexp is to compensate for the ": " - //between the header-name and the header value - $prefix = '=?' . $build_params['head_charset'] . '?Q?'; - $suffix = '?='; - $maxLength = 75 - strlen($prefix . $suffix) - 2 - 1; - $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; - $maxLength = $maxLength - 1; - - //Replace all special characters used by the encoder. - $search = array('=', '_', '?', ' '); - $replace = array('=3D', '=5F', '=3F', '_'); - $hdr_value = str_replace($search, $replace, $hdr_value); - - //Replace all extended characters (\x80-xFF) with their - //ASCII values. - $hdr_value = preg_replace( - '#([\x80-\xFF])#e', - '"=" . strtoupper(dechex(ord("\1")))', - $hdr_value - ); - //This regexp will break QP-encoded text at every $maxLength - //but will not break any encoded letters. - $reg1st = "|(.{0,$maxLength1stLine}[^\=][^\=])|"; - $reg2nd = "|(.{0,$maxLength}[^\=][^\=])|"; - //Fix for Bug #10298, Ota Mares <om@viazenetti.de> - //Concat the double quotes if existant and encoded string together - $hdr_value = $quotePrefix . $hdr_value . $quoteSuffix; - + //Base64 encoding has been selected. + //Base64 encode the entire string + $hdr_value = base64_encode($hdr_value); + + //Generate the header using the specified params and dynamicly + //determine the maximum length of such strings. + //75 is the value specified in the RFC. The first -2 is there so + //the later regexp doesn't break any of the translated chars. + //The -2 on the first line-regexp is to compensate for the ": " + //between the header-name and the header value + $prefix = '=?' . $build_params['head_charset'] . '?B?'; + $suffix = '?='; + $maxLength = 75 - strlen($prefix . $suffix) - 2; + $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; + + //We can cut base4 every 4 characters, so the real max we can get must be rounded down. + $maxLength = $maxLength - ($maxLength % 4); + $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4); + + $cutpoint = $maxLength1stLine; + $hdr_value_out = $hdr_value; + $output = ""; + while ($hdr_value_out) { + //Split translated string at every $maxLength + $part = substr($hdr_value_out, 0, $cutpoint); + $hdr_value_out = substr($hdr_value_out, $cutpoint); + $cutpoint = $maxLength; + //RFC 2047 specifies that any split header should be seperated + //by a CRLF SPACE. + if ($output){ + $output .= "\r\n "; + } + $output .= $prefix . $part . $suffix; + } + $hdr_value = $output; + }else{ + //quoted-printable encoding has been selected + + //Fix for Bug #10298, Ota Mares <om@viazenetti.de> + //Check if there is a double quote at beginning or end of the string to + //prevent that an open or closing quote gets ignored because its encapsuled + //by an encoding prefix or suffix. + //Remove the double quote and set the specific prefix or suffix variable + //so later we can concat the encoded string and the double quotes back + //together to get the intended string. + $quotePrefix = $quoteSuffix = ''; + if ($hdr_value{0} == '"') { + $hdr_value = substr($hdr_value, 1); + $quotePrefix = '"'; + } + if ($hdr_value{strlen($hdr_value)-1} == '"') { + $hdr_value = substr($hdr_value, 0, -1); + $quoteSuffix = '"'; + } + + //Generate the header using the specified params and dynamicly + //determine the maximum length of such strings. + //75 is the value specified in the RFC. The -2 is there so + //the later regexp doesn't break any of the translated chars. + //The -2 on the first line-regexp is to compensate for the ": " + //between the header-name and the header value + $prefix = '=?' . $build_params['head_charset'] . '?Q?'; + $suffix = '?='; + $maxLength = 75 - strlen($prefix . $suffix) - 2 - 1; + $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; + $maxLength = $maxLength - 1; + + //Replace all special characters used by the encoder. + $search = array('=', '_', '?', ' '); + $replace = array('=3D', '=5F', '=3F', '_'); + $hdr_value = str_replace($search, $replace, $hdr_value); + + //Replace all extended characters (\x80-xFF) with their + //ASCII values. + $hdr_value = preg_replace( + '#([\x80-\xFF])#e', + '"=" . strtoupper(dechex(ord("\1")))', + $hdr_value + ); + //This regexp will break QP-encoded text at every $maxLength + //but will not break any encoded letters. + $reg1st = "|(.{0,$maxLength1stLine}[^\=][^\=])|"; + $reg2nd = "|(.{0,$maxLength}[^\=][^\=])|"; + //Fix for Bug #10298, Ota Mares <om@viazenetti.de> + //Concat the double quotes if existant and encoded string together + $hdr_value = $quotePrefix . $hdr_value . $quoteSuffix; + - $hdr_value_out = $hdr_value; + $hdr_value_out = $hdr_value; if (strlen($hdr_value_out) >= ($maxLength1stLine + strlen($prefix . $suffix))){ //Begin with the regexp for the first line. $reg = $reg1st; @@ -999,8 +999,8 @@ } $hdr_value_out = $output; }else{ - $hdr_value_out = $prefix . $hdr_value_out . $suffix; - } + $hdr_value_out = $prefix . $hdr_value_out . $suffix; + } $hdr_value = $hdr_value_out; } }
« previous php.pear.cvs (#46083) next »