mime.php

来自「This is the script which used on 10minut」· PHP 代码 · 共 1,096 行 · 第 1/3 页

PHP
1,096
字号
                               );        return true;    }    /**     * Get the contents of the given file name as string     *     * @param string $file_name path of file to process     *     * @return string  contents of $file_name     * @access private     */    function &_file2str($file_name)    {        if (!is_readable($file_name)) {            $err = PEAR::raiseError('File is not readable ' . $file_name);            return $err;        }        if (!$fd = fopen($file_name, 'rb')) {            $err = PEAR::raiseError('Could not open ' . $file_name);            return $err;        }        $filesize = filesize($file_name);        if ($filesize == 0) {            $cont =  "";        } else {            if ($magic_quote_setting = get_magic_quotes_runtime()) {                set_magic_quotes_runtime(0);            }            $cont = fread($fd, $filesize);            if ($magic_quote_setting) {                set_magic_quotes_runtime($magic_quote_setting);            }        }        fclose($fd);        return $cont;    }    /**     * Adds a text subpart to the mimePart object and     * returns it during the build process.     *     * @param mixed  &$obj The object to add the part to, or     *                      null if a new object is to be created.     * @param string $text The text to add.     *     * @return object  The text mimePart object     * @access private     */    function &_addTextPart(&$obj, $text)    {        $params['content_type'] = 'text/plain';        $params['encoding']     = $this->_build_params['text_encoding'];        $params['charset']      = $this->_build_params['text_charset'];        if (is_object($obj)) {            $ret = $obj->addSubpart($text, $params);            return $ret;        } else {            $ret = new Mail_mimePart($text, $params);            return $ret;        }    }    /**     * Adds a html subpart to the mimePart object and     * returns it during the build process.     *     * @param mixed &$obj The object to add the part to, or     *                     null if a new object is to be created.     *     * @return object The html mimePart object     * @access private     */    function &_addHtmlPart(&$obj)    {        $params['content_type'] = 'text/html';        $params['encoding']     = $this->_build_params['html_encoding'];        $params['charset']      = $this->_build_params['html_charset'];        if (is_object($obj)) {            $ret = $obj->addSubpart($this->_htmlbody, $params);            return $ret;        } else {            $ret = new Mail_mimePart($this->_htmlbody, $params);            return $ret;        }    }    /**     * Creates a new mimePart object, using multipart/mixed as     * the initial content-type and returns it during the     * build process.     *     * @return object The multipart/mixed mimePart object     * @access private     */    function &_addMixedPart()    {        $params                 = array();        $params['content_type'] = 'multipart/mixed';                //Create empty multipart/mixed Mail_mimePart object to return        $ret = new Mail_mimePart('', $params);        return $ret;    }    /**     * Adds a multipart/alternative part to a mimePart     * object (or creates one), and returns it during     * the build process.     *     * @param mixed &$obj The object to add the part to, or     *                     null if a new object is to be created.     *     * @return object  The multipart/mixed mimePart object     * @access private     */    function &_addAlternativePart(&$obj)    {        $params['content_type'] = 'multipart/alternative';        if (is_object($obj)) {            return $obj->addSubpart('', $params);        } else {            $ret = new Mail_mimePart('', $params);            return $ret;        }    }    /**     * Adds a multipart/related part to a mimePart     * object (or creates one), and returns it during     * the build process.     *     * @param mixed &$obj The object to add the part to, or     *                     null if a new object is to be created     *     * @return object  The multipart/mixed mimePart object     * @access private     */    function &_addRelatedPart(&$obj)    {        $params['content_type'] = 'multipart/related';        if (is_object($obj)) {            return $obj->addSubpart('', $params);        } else {            $ret = new Mail_mimePart('', $params);            return $ret;        }    }    /**     * Adds an html image subpart to a mimePart object     * and returns it during the build process.     *     * @param object &$obj  The mimePart to add the image to     * @param array  $value The image information     *     * @return object  The image mimePart object     * @access private     */    function &_addHtmlImagePart(&$obj, $value)    {        $params['content_type'] = $value['c_type'];        $params['encoding']     = 'base64';        $params['disposition']  = 'inline';        $params['dfilename']    = $value['name'];        $params['cid']          = $value['cid'];                $ret = $obj->addSubpart($value['body'], $params);        return $ret;        }    /**     * Adds an attachment subpart to a mimePart object     * and returns it during the build process.     *     * @param object &$obj  The mimePart to add the image to     * @param array  $value The attachment information     *     * @return object  The image mimePart object     * @access private     */    function &_addAttachmentPart(&$obj, $value)    {        $params['dfilename'] = $value['name'];        $params['encoding']  = $value['encoding'];        if ($value['charset']) {            $params['charset'] = $value['charset'];        }        if ($value['language']) {            $params['language'] = $value['language'];        }        if ($value['location']) {            $params['location'] = $value['location'];        }        $params['content_type'] = $value['c_type'];        $params['disposition']  = isset($value['disposition']) ?                                   $value['disposition'] : 'attachment';        $ret = $obj->addSubpart($value['body'], $params);        return $ret;    }    /**     * Returns the complete e-mail, ready to send using an alternative     * mail delivery method. Note that only the mailpart that is made     * with Mail_Mime is created. This means that,     * YOU WILL HAVE NO TO: HEADERS UNLESS YOU SET IT YOURSELF      * using the $xtra_headers parameter!     *      * @param string $separation   The separation etween these two parts.     * @param array  $build_params The Build parameters passed to the     *                             &get() function. See &get for more info.     * @param array  $xtra_headers The extra headers that should be passed     *                             to the &headers() function.     *                             See that function for more info.     * @param bool   $overwrite    Overwrite the existing headers with new.     *     * @return string The complete e-mail.     * @access public     */    function getMessage(                        $separation   = null,                         $build_params = null,                         $xtra_headers = null,                         $overwrite    = false                       )    {        if ($separation === null) {            $separation = MAIL_MIME_CRLF;        }        $body = $this->get($build_params);        $head = $this->txtHeaders($xtra_headers, $overwrite);        $mail = $head . $separation . $body;        return $mail;    }    /**     * Builds the multipart message from the list ($this->_parts) and     * returns the mime content.     *     * @param array $build_params Build parameters that change the way the email     *                             is built. Should be associative. Can contain:     *                head_encoding  -  What encoding to use for the headers.      *                                  Options: quoted-printable or base64     *                                  Default is quoted-printable     *                text_encoding  -  What encoding to use for plain text     *                                  Options: 7bit, 8bit,     *                                  base64, or quoted-printable     *                                  Default is 7bit     *                html_encoding  -  What encoding to use for html     *                                  Options: 7bit, 8bit,     *                                  base64, or quoted-printable     *                                  Default is quoted-printable     *                7bit_wrap      -  Number of characters before text is     *                                  wrapped in 7bit encoding     *                                  Default is 998     *                html_charset   -  The character set to use for html.     *                                  Default is iso-8859-1     *                text_charset   -  The character set to use for text.     *                                  Default is iso-8859-1     *                head_charset   -  The character set to use for headers.     *                                  Default is iso-8859-1     *     * @return string The mime content     * @access public     */    function &get($build_params = null)    {        if (isset($build_params)) {            while (list($key, $value) = each($build_params)) {                $this->_build_params[$key] = $value;            }        }                if (isset($this->_headers['From'])){            $domain = @strstr($this->_headers['From'],'@');            //Bug #11381: Illegal characters in domain ID            $domain = str_replace(array("<", ">", "&", "(", ")", " ", "\"", "'"), "", $domain);            $domain = urlencode($domain);            foreach($this->_html_images as $i => $img){                $this->_html_images[$i]['cid'] = $this->_html_images[$i]['cid'] . $domain;            }        }                if (count($this->_html_images) AND isset($this->_htmlbody)) {            foreach ($this->_html_images as $key => $value) {                $regex   = array();                $regex[] = '#(\s)((?i)src|background|href(?-i))\s*=\s*(["\']?)' .                            preg_quote($value['name'], '#') . '\3#';                $regex[] = '#(?i)url(?-i)\(\s*(["\']?)' .                            preg_quote($value['name'], '#') . '\1\s*\)#';                $rep   = array();                $rep[] = '\1\2=\3cid:' . $value['cid'] .'\3';                $rep[] = 'url(\1cid:' . $value['cid'] . '\2)';                $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody);                $this->_html_images[$key]['name'] =                     basename($this->_html_images[$key]['name']);            }        }        $null        = null;        $attachments = count($this->_parts)                 ? true : false;        $html_images = count($this->_html_images)           ? true : false;        $html        = strlen($this->_htmlbody)             ? true : false;        $text        = (!$html AND strlen($this->_txtbody)) ? true : false;        switch (true) {        case $text AND !$attachments:            $message =& $this->_addTextPart($null, $this->_txtbody);            break;        case !$text AND !$html AND $attachments:            $message =& $this->_addMixedPart();            for ($i = 0; $i < count($this->_parts); $i++) {                $this->_addAttachmentPart($message, $this->_parts[$i]);            }            break;        case $text AND $attachments:            $message =& $this->_addMixedPart();            $this->_addTextPart($message, $this->_txtbody);            for ($i = 0; $i < count($this->_parts); $i++) {                $this->_addAttachmentPart($message, $this->_parts[$i]);            }            break;        case $html AND !$attachments AND !$html_images:            if (isset($this->_txtbody)) {                $message =& $this->_addAlternativePart($null);                $this->_addTextPart($message, $this->_txtbody);                $this->_addHtmlPart($message);            } else {                $message =& $this->_addHtmlPart($null);            }            break;        case $html AND !$attachments AND $html_images:            $message =& $this->_addRelatedPart($null);            if (isset($this->_txtbody)) {                $alt =& $this->_addAlternativePart($message);                $this->_addTextPart($alt, $this->_txtbody);                $this->_addHtmlPart($alt);            } else {                $this->_addHtmlPart($message);            }            for ($i = 0; $i < count($this->_html_images); $i++) {                $this->_addHtmlImagePart($message, $this->_html_images[$i]);            }            break;        case $html AND $attachments AND !$html_images:            $message =& $this->_addMixedPart();            if (isset($this->_txtbody)) {                $alt =& $this->_addAlternativePart($message);                $this->_addTextPart($alt, $this->_txtbody);                $this->_addHtmlPart($alt);            } else {                $this->_addHtmlPart($message);            }            for ($i = 0; $i < count($this->_parts); $i++) {                $this->_addAttachmentPart($message, $this->_parts[$i]);            }            break;

⌨️ 快捷键说明

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