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.");
}