From: Michael M Slusarz Date: Thu, 10 Dec 2009 20:54:52 +0000 (-0700) Subject: Do draft deletion in IMP_Compose::destroy() X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1970439917f8180292672b4ec6512a9e0d5ca0db;p=horde.git Do draft deletion in IMP_Compose::destroy() --- diff --git a/imp/ajax.php b/imp/ajax.php index 3a797d697..dcbd5cbae 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -658,7 +658,7 @@ case 'GetReplyData': 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(); diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index e22b73a8b..2fce2fd3f 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -95,14 +95,9 @@ if (count($_POST)) { 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') { @@ -160,7 +155,6 @@ if (count($_POST)) { /* 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; } diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 8e5530efc..6f9248aa2 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -267,11 +267,6 @@ case _("Send"): 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'); @@ -286,7 +281,7 @@ case _("Send"): break; case _("Cancel"): - $imp_compose->destroy(); + $imp_compose->destroy(false); require IMP_BASE . '/mailbox-mimp.php'; exit; } diff --git a/imp/compose.php b/imp/compose.php index 2b8822c28..41c0686c3 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -400,13 +400,8 @@ case 'send_message': 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(); @@ -460,12 +455,6 @@ case 'send_message': 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; @@ -518,7 +507,7 @@ case 'fwd_digest': break; case 'cancel_compose': - $imp_compose->destroy(); + $imp_compose->destroy(false); if ($isPopup) { Horde_Util::closeWindowJS(); } else { diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index d8c069289..a5b2a44b1 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -145,9 +145,23 @@ class IMP_Compose /** * 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); @@ -400,6 +414,7 @@ class IMP_Compose } list($this->_metadata['draft_uid'],) = explode(IMP::IDX_SEP, $uid); + $this->_metadata['resume'] = 1; $this->_modified = true; return array( diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php index 03fa083a2..e3e0af87e 100644 --- a/imp/lib/Ui/Compose.php +++ b/imp/lib/Ui/Compose.php @@ -226,17 +226,4 @@ class IMP_Ui_Compose )); } - /** - * 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)); - } - } - }