Do draft deletion in IMP_Compose::destroy()
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 10 Dec 2009 20:54:52 +0000 (13:54 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 10 Dec 2009 21:10:07 +0000 (14:10 -0700)
imp/ajax.php
imp/compose-dimp.php
imp/compose-mimp.php
imp/compose.php
imp/lib/Compose.php
imp/lib/Ui/Compose.php

index 3a797d6..dcbd5cb 100644 (file)
@@ -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();
index e22b73a..2fce2fd 100644 (file)
@@ -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;
         }
 
index 8e5530e..6f9248a 100644 (file)
@@ -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;
 }
index 2b8822c..41c0686 100644 (file)
@@ -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 {
index d8c0692..a5b2a44 100644 (file)
@@ -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(
index 03fa083..e3e0af8 100644 (file)
@@ -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));
-        }
-    }
-
 }