case 'CancelCompose':
case 'DeleteDraft':
$imp_compose = IMP_Compose::singleton(Horde_Util::getPost('imp_compose'));
- $imp_compose->destroy();
+ $imp_compose->destroy(false);
$draft_uid = $imp_compose->getMetadata('draft_uid');
if ($draft_uid && ($action == 'DeleteDraft')) {
$imp_message = IMP_Message::singleton();
if (($action == 'auto_save_draft') ||
($action == 'save_draft')) {
try {
- $old_uid = $imp_compose->getMetadata('draft_uid');
-
$res = $imp_compose->saveDraft($header, Horde_Util::getFormData('message', ''), Horde_Nls::getCharset(), Horde_Util::getFormData('html'));
$result->success = 1;
- /* Delete existing draft. */
- $imp_ui->removeDraft($old_uid);
-
$imp_compose->destroy();
if ($action == 'auto_save_draft') {
/* Remove any auto-saved drafts. */
if ($prefs->getValue('auto_save_drafts') ||
$prefs->getValue('auto_delete_drafts')) {
- $imp_ui->removeDraft($imp_compose->getMetadata('draft_uid'));
$result->draft_delete = 1;
}
try {
if ($imp_compose->buildAndSendMessage($message, $header, Horde_Nls::getEmailCharset(), false, $options)) {
-
- if ($prefs->getValue('auto_delete_drafts')) {
- $imp_ui->removeDraft($imp_compose->getMetadata('draft_uid'));
- }
-
$imp_compose->destroy();
$notification->push(_("Message sent successfully."), 'horde.success');
break;
case _("Cancel"):
- $imp_compose->destroy();
+ $imp_compose->destroy(false);
require IMP_BASE . '/mailbox-mimp.php';
exit;
}
if (($actionID == 'auto_save_draft') || ($actionID == 'save_draft')) {
if (!$readonly_drafts) {
try {
- $old_uid = $imp_compose->getMetadata('draft_uid');
-
$result = $imp_compose->saveDraft($header, $message, Horde_Nls::getCharset(), $rtemode);
- /* Delete existing draft. */
- $imp_ui->removeDraft($old_uid);
-
/* Closing draft if requested by preferences. */
if ($actionID == 'save_draft') {
$imp_compose->destroy();
try {
$sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $rtemode, $options);
-
- if ($prefs->getValue('auto_save_drafts') ||
- $prefs->getValue('auto_delete_drafts')) {
- $imp_ui->removeDraft($imp_compose->getMetadata('draft_uid'));
- }
-
$imp_compose->destroy();
} catch (IMP_Compose_Exception $e) {
$get_sig = false;
break;
case 'cancel_compose':
- $imp_compose->destroy();
+ $imp_compose->destroy(false);
if ($isPopup) {
Horde_Util::closeWindowJS();
} else {
/**
* Destroys an IMP_Compose instance.
+ *
+ * @param boolean $success Was the message sent successfully?
*/
- public function destroy()
+ public function destroy($success = true)
{
+ /* Delete draft if we were auto saving and this wasn't a resume
+ * draft request, -or- if this was a resume draft request,
+ * auto_delete_drafts was true, and we successfully sent the
+ * message. */
+ if ((($GLOBALS['prefs']->getValue('auto_save_drafts') &&
+ !$this->_getMetadata('resume')) ||
+ ($success && $GLOBALS['prefs']->getValue('auto_delete_drafts'))) &&
+ ($uid = $this->getMetadata('draft_uid'))) {
+ $imp_message = IMP_Message::singleton();
+ $imp_message->delete(array($uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true)), array('nuke' => true));
+ }
+
$this->deleteAllAttachments();
$obs = Horde_SessionObjects::singleton();
$obs->prune($this->_cacheid);
}
list($this->_metadata['draft_uid'],) = explode(IMP::IDX_SEP, $uid);
+ $this->_metadata['resume'] = 1;
$this->_modified = true;
return array(
));
}
- /**
- * Remove draft message.
- *
- * @param integer $uid The draft message UID.
- */
- public function removeDraft($uid)
- {
- if (!empty($uid)) {
- $imp_message = IMP_Message::singleton();
- $imp_message->delete(array($uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true)), array('nuke' => true));
- }
- }
-
}