BP_Reply_By_Email_IMAP::body_parser PHP Метод

body_parser() публичный статический Метод

Tries to fetch the plain-text version when available first. Otherwise, will fallback to the HTML version.
public static body_parser ( resource $imap, integer $i, boolean $reply = true ) : mixed
$imap resource The current IMAP connection
$i integer The current email message number
$reply boolean If we're parsing a reply or not. Default set to true.
Результат mixed Either the email body on success or false on failure
    public static function body_parser($imap, $i, $reply = true)
    {
        // get the email structure
        $structure = imap_fetchstructure($imap, $i);
        // setup encoding variable
        $encoding = $structure->encoding;
        // this is a multipart email
        if (!empty($structure->parts)) {
            // parse the parts!
            $data = self::multipart_plain_text_parser($structure->parts, $imap, $i);
            // we successfully parsed something from the multipart email
            if (!empty($data)) {
                // $data when extracted includes:
                //	$body
                //	$encoding
                //	$params (if applicable)
                extract($data);
                unset($data);
            }
            // either a plain-text email or a HTML email
        } else {
            $body = imap_body($imap, $i);
        }
        // decode emails with the following encoding
        switch ($encoding) {
            // quoted-printable
            case 4:
                $body = quoted_printable_decode($body);
                break;
                // base64
            // base64
            case 3:
                $body = base64_decode($body);
                break;
        }
        // convert email to UTF-8 if not UTF-8
        if (!empty($params['charset']) && $params['charset'] != 'utf-8') {
            // try to use mb_convert_encoding() first if it exists
            // there are differing opinions as to whether iconv() is better than
            // mb_convert_encoding()
            // mb_convert_encoding() appears to have less problems than iconv()
            // so this is used first
            if (function_exists('mb_convert_encoding')) {
                $body = mb_convert_encoding($body, 'utf-8', $params['charset']);
                // fallback to iconv() if mb_convert_encoding()_doesn't exist
            } elseif (function_exists('iconv')) {
                $body = iconv($params['charset'], 'utf-8//TRANSLIT', $body);
            }
        }
        // do something special for emails that only contain HTML
        if (strtolower($structure->subtype) == 'html') {
            self::$html = true;
        }
        return $body;
    }