Back to index

d-push  2.0
Public Member Functions | Public Attributes
Mail_mimeDecode Class Reference

List of all members.

Public Member Functions

 Mail_mimeDecode ($input, $deprecated_linefeed= '')
 Constructor.
 decode ($params=null)
 Begins the decoding process.
 _decode ($headers, $body, $default_ctype= 'text/plain')
 Performs the decoding.
getMimeNumbers (&$structure, $no_refs=false, $mime_number= '', $prepend= '')
 Given the output of the above function, this will return an array of references to the parts, indexed by mime number.
 _splitBodyHeader ($input)
 Given a string containing a header and body section, this function will split them (at the first blank line) and return them.
 _parseHeaders ($input)
 Parse headers given in $input and return as assoc array.
 _parseHeaderValue ($input)
 Function to parse a header value, extract first part, and any secondary parts (after ;) This function is not as robust as it could be.
 _boundarySplit ($input, $boundary)
 This function splits the input based on the given boundary.
 _decodeHeader ($input)
 Given a header, this function will decode it according to RFC2047.
 _decodeBody ($input, $encoding= '7bit', $charset= '')
 Given a body string and an encoding type, this function will decode and return it.
 _quotedPrintableDecode ($input)
 Given a quoted-printable string, this function will decode and return it.
uudecode ($input)
 Checks the input for uuencoded files and returns an array of them.
 getSendArray ()
 getSendArray() returns the arguments required for Mail::send() used to build the arguments for a mail::send() call
 getXML ($input)
 Returns a xml copy of the output of Mail_mimeDecode::decode.
 _getXML ($input, $indent=1)
 Function that does the actual conversion to xml.
 _getXML_helper ($hdr_name, $hdr_value, $indent)
 Helper function to _getXML().
 _fromCharset ($charset, $input)
 Z-Push helper to decode text.
 raiseError ($message)
 Z-Push helper for error logging removing PEAR dependency.

Public Attributes

 $_input
 $_header
 $_body
 $_error
 $_include_bodies
 $_decode_bodies
 $_decode_headers
 $_rfc822_bodies

Detailed Description

Definition at line 102 of file mimeDecode.php.


Member Function Documentation

Mail_mimeDecode::_boundarySplit ( input,
boundary 
)

This function splits the input based on the given boundary.

Parameters:
stringInput to parse
Returns:
array Contains array of resulting mime parts private

Definition at line 542 of file mimeDecode.php.

    {
        $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;
    }

Here is the caller graph for this function:

Mail_mimeDecode::_decode ( headers,
body,
default_ctype = 'text/plain' 
)

Performs the decoding.

Decodes the body string passed to it If it finds certain content-types it will call itself in a recursive fashion

Parameters:
stringHeader section
stringBody section
Returns:
object Results of decoding process private

Definition at line 257 of file mimeDecode.php.

    {
        $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';
                    $charset = isset($return->ctype_parameters['charset']) ? $return->ctype_parameters['charset'] : $this->_charset;
                    $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding, $charset) : $body) : null;
                    break;

                case 'text/html':
                    $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
                    $charset = isset($return->ctype_parameters['charset']) ? $return->ctype_parameters['charset'] : $this->_charset;
                    $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding, $charset) : $body) : null;
                    break;

                case 'multipart/parallel':
                case 'multipart/appledouble': // Appledouble mail
                case 'multipart/report': // RFC1892
                case 'multipart/signed': // PGP
                case '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':
                    if ($this->_rfc822_bodies) {
                        $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
                        $charset = isset($return->ctype_parameters['charset']) ? $return->ctype_parameters['charset'] : $this->_charset;
                        $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding, $charset) : $body);
                    }

                    $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';
                    // if there is no explicit charset, then don't try to convert to default charset, and make sure that only text mimetypes are converted
                    $charset = (isset($return->ctype_parameters['charset']) && ((isset($return->ctype_primary) && $return->ctype_primary == 'text') || !isset($return->ctype_primary)) )? $return->ctype_parameters['charset']: '';
                    $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $content_transfer_encoding['value'], $charset) : $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;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Mail_mimeDecode::_decodeBody ( input,
encoding = '7bit',
charset = '' 
)

Given a body string and an encoding type, this function will decode and return it.

Parameters:
stringInput body to decode
stringEncoding type to use.
Returns:
string Decoded body private

Definition at line 613 of file mimeDecode.php.

    {
        switch (strtolower($encoding)) {
            case '7bit':
                return $this->_fromCharset($charset, $input);;
                break;

            case '8bit':
                return $this->_fromCharset($charset, $input);
                break;

            case 'quoted-printable':
                return $this->_fromCharset($charset, $this->_quotedPrintableDecode($input));
                break;

            case 'base64':
                return $this->_fromCharset($charset, base64_decode($input));
                break;

            default:
                return $input;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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).

Parameters:
stringInput header value to decode
Returns:
string Decoded header value private

Definition at line 572 of file mimeDecode.php.

    {
        // 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, $this->_fromCharset($charset, $text), $input);
        }

        return $input;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Mail_mimeDecode::_fromCharset ( charset,
input 
)

Z-Push helper to decode text.

Parameters:
stringcurrent charset of input
stringinput
Returns:
string XML version of input private

Definition at line 900 of file mimeDecode.php.

                                            {
        if($charset == '' || (strtolower($charset) == $this->_charset))
            return $input;

        // all ISO-8859-1 are converted as if they were Windows-1252 - see Mantis #456
        if (strtolower($charset) == 'iso-8859-1')
            $charset = 'Windows-1252';

        return @iconv($charset, $this->_charset. "//TRANSLIT", $input);
    }

Here is the caller graph for this function:

Mail_mimeDecode::_getXML ( input,
indent = 1 
)

Function that does the actual conversion to xml.

Does a single mimepart at a time.

Parameters:
objectInput to convert to xml. This is a mimepart object. It may or may not contain subparts.
integerNumber of tabs to indent
Returns:
string XML version of input private

Definition at line 816 of file mimeDecode.php.

    {
        $htab    =  "\t";
        $crlf    =  "\r\n";
        $output  =  '';
        $headers = @(array)$input->headers;

        foreach ($headers as $hdr_name => $hdr_value) {

            // Multiple headers with this name
            if (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;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Mail_mimeDecode::_getXML_helper ( hdr_name,
hdr_value,
indent 
)

Helper function to _getXML().

Returns xml of a header.

Parameters:
stringName of header
stringValue of header
integerNumber of tabs to indent
Returns:
string XML version of input private

Definition at line 860 of file mimeDecode.php.

    {
        $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 parameters
        if (!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;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Parse headers given in $input and return as assoc array.

Parameters:
stringHeaders to parse
Returns:
array Contains parsed headers private

Definition at line 452 of file mimeDecode.php.

    {

        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;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
stringHeader value to parse
Returns:
array Contains parsed result private

Definition at line 490 of file mimeDecode.php.

    {

        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 = '/([^;\'"]*[\'"]([^\'"]*([^\'"]*)*)[\'"][^;\'"]*|([^;]+))(;|$)/';
                // simplyfied RegEx - Nokia Mail2 sends boundaries containing ' which break the above regex
                $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 (!empty($param_value[0]) && $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;
    }

Here is the caller graph for this function:

Given a quoted-printable string, this function will decode and return it.

Parameters:
stringInput body to decode
Returns:
string Decoded body private

Definition at line 645 of file mimeDecode.php.

    {
        // 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;
    }

Here is the caller graph for this function:

Given a string containing a header and body section, this function will split them (at the first blank line) and return them.

Parameters:
stringInput to split apart
Returns:
array Contains header and body section private

Definition at line 435 of file mimeDecode.php.

    {
        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;
    }

Here is the caller graph for this function:

Mail_mimeDecode::decode ( params = null)

Begins the decoding process.

If called statically it will create an object and call the decode() method of it.

Parameters:
arrayAn 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 charset - convert all data to this charset
Returns:
object Decoded results public

Definition at line 209 of file mimeDecode.php.

    {
        // 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 $this->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;
            $this->_rfc822_bodies  = isset($params['rfc_822bodies']) ?
                                 $params['rfc_822bodies']  : false;
            $this->_charset = isset($params['charset']) ?
                                 strtolower($params['charset']) : 'utf-8';

            $structure = $this->_decode($this->_header, $this->_body);
            if ($structure === false) {
                $structure = $this->raiseError($this->_error);
            }
        }

        return $structure;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

& Mail_mimeDecode::getMimeNumbers ( &$  structure,
no_refs = false,
mime_number = '',
prepend = '' 
)

Given the output of the above function, this will return an array of references to the parts, indexed by mime number.

Parameters:
object$structureThe structure to go through
string$mime_numberInternal use only.
Returns:
array Mime numbers

Definition at line 392 of file mimeDecode.php.

    {
        $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;
    }

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; }

Returns:
mixed array of recipeint, headers,body or Pear_Error public
Author:
Alan Knowles alan@.nosp@m.akbk.nosp@m.home..nosp@m.com

Definition at line 750 of file mimeDecode.php.

    {
        // 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);
    }

Here is the call graph for this function:

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.

Parameters:
objectInput to convert to xml. This should be the output of the Mail_mimeDecode::decode function
Returns:
string XML version of input public

Definition at line 794 of file mimeDecode.php.

    {
        $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;
    }

Here is the call graph for this function:

Mail_mimeDecode::Mail_mimeDecode ( input,
deprecated_linefeed = '' 
)

Constructor.

Sets up the object, initialise the variables, and splits and stores the header and body of the input.

Parameters:
stringThe input to decode public

Definition at line 179 of file mimeDecode.php.

    {
        list($header, $body)   = $this->_splitBodyHeader($input);

        $this->_input          = $input;
        $this->_header         = $header;
        $this->_body           = $body;
        $this->_decode_bodies  = false;
        $this->_include_bodies = true;
        $this->_rfc822_bodies  = false;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Z-Push helper for error logging removing PEAR dependency.

Parameters:
stringdebug message
Returns:
boolean always false as there was an error private

Definition at line 919 of file mimeDecode.php.

                                  {
        ZLog::Write(LOGLEVEL_ERROR, "mimeDecode error: ". $message);
        return false;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

& Mail_mimeDecode::uudecode ( 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.

Parameters:
stringInput body to look for attahcments in
Returns:
array Decoded bodies, filenames and permissions public
Author:
Unknown

Definition at line 671 of file mimeDecode.php.

    {
        // Find all uuencoded sections
        preg_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;
    }

Member Data Documentation

Definition at line 126 of file mimeDecode.php.

Definition at line 151 of file mimeDecode.php.

Definition at line 159 of file mimeDecode.php.

Definition at line 134 of file mimeDecode.php.

Definition at line 118 of file mimeDecode.php.

Definition at line 143 of file mimeDecode.php.

Definition at line 110 of file mimeDecode.php.

Definition at line 168 of file mimeDecode.php.


The documentation for this class was generated from the following file: