private function process_message_part_body($messagedata, $partdata, $part) {
        // This is a content section for the main body.

        // Get the string version of it.
        $content = $messagedata->getBodyPart($part);
        if (!$messagedata->getBodyPartDecode($part)) {
            // Decode the content.
            $partdata->setContents($content);
            $content = $partdata->getContents();
        }

        // Convert the text from the current encoding to UTF8.
        $content = \core_text::convert($content, $partdata->getCharset());

        // Fix any invalid UTF8 characters.
        // Note: XSS cleaning is not the responsibility of this code. It occurs immediately before display when
        // format_text is called.
        $content = clean_param($content, PARAM_RAW);

        return $content;
    }