⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class_mimedecode.php

📁 一个客户联系管理(CRM)系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
                    $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/", "\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, ':'));                $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                // Can't handle if it's in double quotes however. (Of course anyone                // sending that needs a good slap).                $parameters = preg_split('/\s*(?<!\\\\);\s*/i', $input);                for ($i = 0; $i < count($parameters); $i++) {                    $param_name  = substr($parameters[$i], 0, $pos = strpos($parameters[$i], '='));                    $param_value = substr($parameters[$i], $pos + 1);                    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)    {        $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)\?[^?]*\?=)( |' . "\t|\r?\n" . ')+=\?/', '\1=?', $input);        // For each encoded-word...        while (preg_match('/(=\?([^?]+)\?(Q|B)\?([^?]*)\?=)/', $input, $matches)) {            $encoded  = $matches[1];            $charset  = $matches[2];            $encoding = $matches[3];            $text     = $matches[4];            switch ($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 ($encoding) {            case '7bit':			case '8bit':                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        if (preg_match_all('/=[a-f0-9]{2}/i', $input, $matches)) {            $matches = array_unique($matches[0]);            foreach ($matches as $value) {                $input = str_replace($value, chr(hexdec(substr($value,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 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;    }} // End of class?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -