cvs: pear /Mail_Mime mimeDecode.php
| From: | Shane Caraveo | Date: | Tue, 14 May 2002 00:52:31 +0000 |
| Subject: | cvs: pear /Mail_Mime mimeDecode.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3811@lists.php.net to get a copy of this message | ||
shane Mon May 13 20:52:31 2002 EDT
Modified files:
/pear/Mail_Mime mimeDecode.php
Log:
Fix the crlf issue altogether. There is no need to pass in that argument.
The class now handles either ending, or mixed endings apropriately.
Index: pear/Mail_Mime/mimeDecode.php
diff -u pear/Mail_Mime/mimeDecode.php:1.28 pear/Mail_Mime/mimeDecode.php:1.29
--- pear/Mail_Mime/mimeDecode.php:1.28 Mon Apr 8 13:32:17 2002
+++ pear/Mail_Mime/mimeDecode.php Mon May 13 20:52:31 2002
@@ -48,7 +48,7 @@
* perhaps even message/partial.
*
* @author Richard Heyes <richard@phpguru.org>
-* @version $Revision: 1.28 $
+* @version $Revision: 1.29 $
* @package Mail
*/
@@ -99,12 +99,6 @@
var $_decode_headers;
/**
- * Variable to hold the line end type.
- * @var string
- */
- var $_crlf;
-
- /**
* If invoked from a class, $this will be set. This has problematic
* connotations for calling decode() statically. Hence this variable
* is used to determine if we are indeed being called statically or
@@ -119,13 +113,10 @@
* stores the header and body of the input.
*
* @param string The input to decode
- * @param string CRLF type to use (CRLF/LF/CR)
* @access public
*/
- function Mail_mimeDecode($input, $crlf = "\r\n")
+ function Mail_mimeDecode($input)
{
-
- $this->_crlf = $crlf;
list($header, $body) = $this->_splitBodyHeader($input);
$this->_input = $input;
@@ -134,7 +125,7 @@
$this->_decode_bodies = false;
$this->_include_bodies = true;
- $this->mailmimeDecode = true;
+ $this->mailMimeDecode = true;
}
/**
@@ -151,8 +142,6 @@
* decode_headers - Whether to decode headers
* input - If called statically, this will be treated
* as the input
- * crlf - If called statically, this will be used as
- * the crlf value.
* @return object Decoded results
* @access public
*/
@@ -162,11 +151,7 @@
// Have we been called statically? If so, create an object and pass details to that.
if (!isset($this->mailMimeDecode) AND isset($params['input'])) {
- if (isset($params['crlf'])) {
- $obj = new Mail_mimeDecode($params['input'], $params['crlf']);
- } else {
- $obj = new Mail_mimeDecode($params['input']);
- }
+ $obj = new Mail_mimeDecode($params['input']);
$structure = $obj->decode($params);
// Called statically but no input
@@ -289,7 +274,7 @@
break;
case 'message/rfc822':
- $obj = &new Mail_mimeDecode($body, $this->_crlf);
+ $obj = &new Mail_mimeDecode($body);
$return->parts[] = $obj->decode(array('include_bodies' =>
$this->_include_bodies));
unset($obj);
break;
@@ -364,17 +349,11 @@
*/
function _splitBodyHeader($input)
{
-
- $pos = strpos($input, $this->_crlf . $this->_crlf);
- if ($pos === false) {
- $this->_error = 'Could not split header and body';
- return false;
+ if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $match)) {
+ return array($match[1], $match[2]);
}
-
- $header = substr($input, 0, $pos);
- $body = substr($input, $pos+(2*strlen($this->_crlf)));
-
- return array($header, $body);
+ $this->_error = 'Could not split header and body';
+ return false;
}
/**
@@ -390,8 +369,9 @@
if ($input !== '') {
// Unfold the input
- $input = preg_replace('/' . $this->_crlf . "(\t| )/", '
', $input);
- $headers = explode($this->_crlf, trim($input));
+ $input = preg_replace("/\r\n/", "\n", $input);
+ $input = preg_replace("/\n(\t| )/", ' ', $input);
+ $headers = explode("\n", trim($input));
foreach ($headers as $value) {
$hdr_name = substr($value, 0, $pos = strpos($value, ':'));
@@ -486,7 +466,7 @@
function _decodeHeader($input)
{
// Remove white space between encoded-words
- $input = preg_replace('/(=\?[^?]+\?(Q|B)\?[^?]*\?=)( |' . "\t|" .
$this->_crlf . ')+=\?/', '\1=?', $input);
+ $input = preg_replace('/(=\?[^?]+\?(Q|B)\?[^?]*\?=)( |' . "\t|\r?\n" .
')+=\?/', '\1=?', $input);
// For each encoded-word...
while (preg_match('/(=\?([^?]+)\?(Q|B)\?([^?]*)\?=)/', $input, $matches)) {