IMP_Compose::saveTemplate PHP Method

saveTemplate() public method

Save a template message on the IMAP server.
public saveTemplate ( array $headers, mixed $message, array $opts = [] ) : string
$headers array List of message headers (UTF-8).
$message mixed Either the message text (string) or a Horde_Mime_Part object that contains the text to save.
$opts array An array of options w/the following keys: - html: (boolean) Is this an HTML message? - priority: (string) The message priority ('high', 'normal', 'low'). - readreceipt: (boolean) Add return receipt headers?
return string Notification text on success.
    public function saveTemplate($headers, $message, array $opts = array())
    {
        if (!($mbox = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TEMPLATES))) {
            throw new IMP_Compose_Exception(_("Saving the template failed: no template mailbox exists."));
        }
        /* Check for access to mailbox. */
        if (!$mbox->create()) {
            throw new IMP_Compose_Exception(_("Saving the template failed: could not create the templates mailbox."));
        }
        $append_flags = array(Horde_Imap_Client::FLAG_SEEN);
        $old_uid = $this->getMetadata('template_uid_edit');
        /* Add the message to the mailbox. */
        try {
            $mbox->imp_imap->append($mbox, array(array('data' => $this->_saveDraftMsg($headers, $message, $opts), 'flags' => $append_flags, 'verify_email' => true)));
            if ($old_uid) {
                $old_uid->delete(array('nuke' => true));
            }
        } catch (IMP_Imap_Exception $e) {
            return _("The template was not successfully saved.");
        }
        return _("The template has been saved.");
    }