IMP_Compose::forwardMessage PHP Method

forwardMessage() public method

Determine the text and headers for a forwarded message.
public forwardMessage ( integer $type, IMP_Contents $contents, boolean $attach = true, array $opts = [] ) : array
$type integer The forward type (self::FORWARD* constant).
$contents IMP_Contents An IMP_Contents object.
$attach boolean Attach the forwarded message?
$opts array Additional options: - format: (string) Force to this format. DEFAULT: Auto-determine.
return array An array with the following keys: - attach: (boolean) True if original message was attached. - body: (string) The text of the body part. - format: (string) The format of the body message ('html', 'text'). - identity: (mixed) See IMP_Prefs_Identity#getMatchingIdentity(). - subject: (string) Formatted subject. - title: (string) Title to use on page. - type: (integer) - The compose type.
    public function forwardMessage($type, $contents, $attach = true, array $opts = array())
    {
        global $prefs;
        if (!$contents instanceof IMP_Contents) {
            throw new IMP_Exception(_("Could not retrieve message data from the mail server."));
        }
        if ($type == self::FORWARD_AUTO) {
            switch ($prefs->getValue('forward_default')) {
                case 'body':
                    $type = self::FORWARD_BODY;
                    break;
                case 'both':
                    $type = self::FORWARD_BOTH;
                    break;
                case 'editasnew':
                    $ret = $this->editAsNew(new IMP_Indices($contents));
                    $ret['title'] = _("New Message");
                    return $ret;
                case 'attach':
                default:
                    $type = self::FORWARD_ATTACH;
                    break;
            }
        }
        $h = $contents->getHeader();
        $this->_replytype = $type;
        $this->_setMetadata('indices', $contents->getIndicesOb());
        if (strlen($s = $h['Subject'])) {
            $s = strval(new Horde_Imap_Client_Data_BaseSubject($s, array('keepblob' => true)));
            $subject = 'Fwd: ' . $s;
            $title = _("Forward") . ': ' . $s;
        } else {
            $subject = 'Fwd:';
            $title = _("Forward");
        }
        $fwd_attach = false;
        if ($attach && in_array($type, array(self::FORWARD_ATTACH, self::FORWARD_BOTH))) {
            try {
                $this->attachImapMessage(new IMP_Indices($contents));
                $fwd_attach = true;
            } catch (IMP_Exception $e) {
            }
        }
        if (in_array($type, array(self::FORWARD_BODY, self::FORWARD_BOTH))) {
            $ret = $this->forwardMessageText($contents, array('format' => isset($opts['format']) ? $opts['format'] : null));
            unset($ret['charset']);
        } else {
            $ret = array('body' => '', 'format' => $prefs->getValue('compose_html') ? 'html' : 'text');
        }
        return array_merge(array('attach' => $fwd_attach, 'identity' => $this->_getMatchingIdentity($h), 'subject' => $subject, 'title' => $title, 'type' => $type), $ret);
    }