Delete older auto save draft.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 2 Feb 2010 06:58:53 +0000 (23:58 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 2 Feb 2010 07:22:19 +0000 (00:22 -0700)
imp/lib/Compose.php

index bfe16a5..8daebbe 100644 (file)
@@ -312,8 +312,19 @@ class IMP_Compose
 
         /* Add the message to the mailbox. */
         try {
+            if ($this->getMetadata('autodraft')) {
+                $old_uid = $this->getMetadata('draft_uid');
+            }
+
             $ids = $GLOBALS['imp_imap']->ob()->append($drafts_mbox, array(array('data' => $data, 'flags' => $append_flags, 'messageid' => $headers->getValue('message-id'))));
+
+            if ($old_uid) {
+                $idx_array = array($old_uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true));
+                $GLOBALS['injector']->getInstance('IMP_Message')->delete($idx_array, array('nuke' => true));
+            }
+
             $this->_metadata['draft_uid'] = reset($ids);
+            $this->_metadata['autodraft'] = true;
             $this->_modified = true;
             return sprintf(_("The draft has been saved to the \"%s\" folder."), IMP::displayFolder($drafts_mbox));
         } catch (Horde_Imap_Client_Exception $e) {