IMP_Compose::replyMessageText PHP Method

replyMessageText() public method

Returns the reply text for a message.
public replyMessageText ( IMP_Contents $contents, array $opts = [] ) : array
$contents IMP_Contents An IMP_Contents object.
$opts array Additional options: - format: (string) Force to this format. DEFAULT: Auto-determine.
return array An array with the following keys: - body: (string) The text of the body part. - charset: (string) The guessed charset to use for the reply. - format: (string) The format of the body message ('html', 'text').
    public function replyMessageText($contents, array $opts = array())
    {
        global $prefs;
        if (!$prefs->getValue('reply_quote')) {
            return array('body' => '', 'charset' => '', 'format' => 'text');
        }
        $h = $contents->getHeader();
        $from = ($tmp = $h['from']) ? $tmp->getAddressList(true) : '';
        if ($prefs->getValue('reply_headers') && !empty($h)) {
            $from_text = strval(new IMP_Prefs_AttribText($from, $h, '%f'));
            $msg_pre = '----- ' . ($from_text ? sprintf(_("Message from %s"), $from_text) : _("Message")) . " ---------\n" . $this->_getMsgHeaders($h);
            $msg_post = "\n\n----- " . ($from_text ? sprintf(_("End message from %s"), $from_text) : _("End message")) . " -----\n";
        } else {
            $msg_pre = strval(new IMP_Prefs_AttribText($from, $h));
            $msg_post = '';
        }
        list($compose_html, $force_html) = $this->_msgTextFormat($opts, 'reply_format');
        $msg_text = $this->_getMessageText($contents, array('html' => $compose_html, 'replylimit' => true, 'toflowed' => true));
        if (!empty($msg_text) && ($msg_text['mode'] == 'html' || $force_html)) {
            $msg = '<p>' . $this->text2html(trim($msg_pre)) . '</p>' . self::HTML_BLOCKQUOTE . ($msg_text['mode'] == 'text' ? $this->text2html($msg_text['flowed'] ? $msg_text['flowed'] : $msg_text['text']) : $msg_text['text']) . '</blockquote><br />' . ($msg_post ? $this->text2html($msg_post) : '') . '<br />';
            $msg_text['mode'] = 'html';
        } else {
            $msg = empty($msg_text['text']) ? '[' . _("No message body text") . ']' : $msg_pre . "\n\n" . $msg_text['text'] . $msg_post;
            $msg_text['mode'] = 'text';
        }
        // Bug #10148: Message text might be us-ascii, but reply headers may
        // contain 8-bit characters.
        if ($msg_text['charset'] == 'us-ascii' && (Horde_Mime::is8bit($msg_pre) || Horde_Mime::is8bit($msg_post))) {
            $msg_text['charset'] = 'UTF-8';
        }
        return array('body' => $msg . "\n", 'charset' => $msg_text['charset'], 'format' => $msg_text['mode']);
    }