Draft removal tweaks.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 10 Dec 2009 18:59:13 +0000 (11:59 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 10 Dec 2009 21:10:07 +0000 (14:10 -0700)
Move draft removal code to IMP_Compose_Ui function.
No need to pass draft UID in MIMP/IMP - this information is stored as
metadata within the IMP_Compose object.

imp/compose-dimp.php
imp/compose-mimp.php
imp/compose.php
imp/lib/Ui/Compose.php
imp/templates/compose/compose-mimp.inc

index 5368c3e..949a3a1 100644 (file)
  * @package IMP
  */
 
-function _removeAutoSaveDraft($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));
-    }
-}
-
 require_once dirname(__FILE__) . '/lib/Application.php';
 new IMP_Application(array('init' => true, 'tz' => true));
 
@@ -99,7 +91,7 @@ if (count($_POST)) {
             $result->success = 1;
 
             /* Delete existing draft. */
-            _removeAutoSaveDraft($old_uid);
+            $imp_ui->removeDraft($old_uid);
 
             if ($action == 'auto_save_draft') {
                 $notification->push(_("Draft automatically saved."), 'horde.message');
@@ -171,7 +163,7 @@ if (count($_POST)) {
         /* Remove any auto-saved drafts. */
         if ($prefs->getValue('auto_save_drafts') ||
             $prefs->getValue('auto_delete_drafts')) {
-            _removeAutoSaveDraft($imp_compose->getMetadata('draft_uid'));
+            $imp_ui->removeDraft($imp_compose->getMetadata('draft_uid'));
             $result->draft_delete = 1;
         }
 
index b1fb59c..d9d6df1 100644 (file)
@@ -56,7 +56,6 @@ $save_sent_mail = $prefs->getValue('save_sent_mail');
 $sent_mail_folder = $identity->getValue('sent_mail_folder');
 $thismailbox = Horde_Util::getFormData('thismailbox');
 $uid = Horde_Util::getFormData('uid');
-$resume_draft = false;
 
 /* Determine if mailboxes are readonly. */
 $draft = IMP::folderPref($prefs->getValue('drafts_folder'), true);
@@ -107,7 +106,6 @@ case 'd':
             $identity->setDefault($result['identity']);
             $sent_mail_folder = $identity->getValue('sent_mail_folder');
         }
-        $resume_draft = true;
     } catch (IMP_Compose_Exception $e) {
         $notification->push($e, 'horde.error');
     }
@@ -269,15 +267,13 @@ case _("Send"):
 
         try {
             if ($imp_compose->buildAndSendMessage($message, $header, Horde_Nls::getEmailCharset(), false, $options)) {
-                $imp_compose->destroy();
 
-                if (Horde_Util::getFormData('resume_draft') &&
-                    $prefs->getValue('auto_delete_drafts')) {
-                    $imp_message = IMP_Message::singleton();
-                    $idx_array = array($uid . IMP::IDX_SEP . $thismailbox);
-                    $delete_draft = $imp_message->delete($idx_array, array('nuke' => true));
+                if ($prefs->getValue('auto_delete_drafts')) {
+                    $imp_ui->removeDraft($imp_compose->getMetadata('draft_uid'));
                 }
 
+                $imp_compose->destroy();
+
                 $notification->push(_("Message sent successfully."), 'horde.success');
                 require IMP_BASE . '/mailbox-mimp.php';
                 exit;
index 41cc366..f92a816 100644 (file)
@@ -283,7 +283,6 @@ case 'draft':
             $identity->setDefault($result['identity']);
             $sent_mail_folder = $identity->getValue('sent_mail_folder');
         }
-        $resume_draft = true;
     } catch (IMP_Compose_Exception $e) {
         $notification->push($e, 'horde.error');
     }
@@ -409,6 +408,11 @@ case 'send_message':
 
     try {
         $sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $rtemode, $options);
+
+        if ($prefs->getValue('auto_delete_drafts')) {
+            $imp_ui->removeDraft($imp_compose->getMetadata('draft_uid'));
+        }
+
         $imp_compose->destroy();
     } catch (IMP_Compose_Exception $e) {
         $get_sig = false;
@@ -432,16 +436,6 @@ case 'send_message':
         break;
     }
 
-    if (Horde_Util::getFormData('resume_draft') &&
-        $prefs->getValue('auto_delete_drafts') &&
-        ($thismailbox == IMP::folderPref($prefs->getValue('drafts_folder'), true))) {
-        $imp_message = IMP_Message::singleton();
-        $idx_array = array($uid . IMP::IDX_SEP . $thismailbox);
-        if ($imp_message->delete($idx_array)) {
-            $notification->push(_("The draft message was automatically deleted because it was successfully completed and sent."), 'horde.success');
-        }
-    }
-
     if ($isPopup) {
         if ($prefs->getValue('compose_confirm') || !$sent) {
             if ($sent) {
@@ -855,9 +849,6 @@ if ($redirect) {
     foreach (array('page', 'start', 'popup') as $val) {
         $hidden[$val] = htmlspecialchars(Horde_Util::getFormData($val));
     }
-    if (!empty($resume_draft)) {
-        $hidden['resume_draft'] = 1;
-    }
 
     if ($browser->hasQuirk('broken_multipart_form')) {
         $hidden['msie_formdata_is_broken'] = '';
index e3e0af8..03fa083 100644 (file)
@@ -226,4 +226,17 @@ 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));
+        }
+    }
+
 }
index a4c8314..df9a385 100644 (file)
@@ -10,7 +10,6 @@ $f = $c->add(new Horde_Mobile_form('compose-mimp.php'));
 
 // Hidden Variables.
 $f->add(new Horde_Mobile_hidden('composeCache', $cacheID));
-$f->add(new Horde_Mobile_hidden('resume_draft', Horde_Util::getFormData('resume_draft', $resume_draft)));
 
 if (!$prefs->isLocked('default_identity')) {
     $ib = $f->add(new Horde_Mobile_block(new Horde_Mobile_text(_("Identity: "))));