BP_Reply_By_Email_IMAP::multipart_plain_text_parser PHP Method

multipart_plain_text_parser() public static method

Used during {@link BP_Reply_By_Email_IMAP::body_parser()} if email is a multipart email. This method parses a multipart email to return the plain-text body as well as the encoding type and other parameters on success.
public static multipart_plain_text_parser ( obj $parts, resource $imap, integer $i, boolean $subpart = false ) : array
$parts obj The multiple parts of an email. See imap_fetchstructure() for more details.
$imap resource The current IMAP connection
$i integer The current email message number
$subpart boolean If we're parsing a subpart or not. Defaults to false.
return array A populated array containing the body, encoding type and other parameters on success. Empty array on failure.
    public static function multipart_plain_text_parser($parts, $imap, $i, $subpart = false)
    {
        $items = $params = array();
        // check each sub-part of a multipart email
        for ($j = 0, $k = count($parts); $j < $k; ++$j) {
            // get subtype
            $subtype = strtolower($parts[$j]->subtype);
            // get the plain-text message only
            if ($subtype == 'plain') {
                // setup the part number
                // if $subpart is true, we must use a decimal number
                $partno = !$subpart ? $j + 1 : $j + 1 . '.' . ($j + 1);
                $items['body'] = imap_fetchbody($imap, $i, $partno);
                $items['encoding'] = $parts[$j]->encoding;
                // add all additional parameters if available
                if (!empty($parts[$j]->parameters)) {
                    foreach ($parts[$j]->parameters as $x) {
                        $params[strtolower($x->attribute)] = $x->value;
                    }
                }
                // add all additional dparameters if available
                if (!empty($parts[$j]->dparameters)) {
                    foreach ($parts[$j]->dparameters as $x) {
                        $params[strtolower($x->attribute)] = $x->value;
                    }
                }
                continue;
            } elseif ($subtype == 'alternative') {
                $items = self::multipart_plain_text_parser($parts[$j]->parts, $imap, $i, true);
                continue;
            }
        }
        if (!empty($params)) {
            $items['params'] = $params;
        }
        return $items;
    }