From f0f98fb108885aca3c29f759128040ef9e015e68 Mon Sep 17 00:00:00 2001
From: svncommit <devs@roundcube.net>
Date: Mon, 24 Jul 2006 14:41:27 -0400
Subject: [PATCH] Improvements to Draft handling

---
 program/steps/mail/compose.inc |   39 +++++++++++++++++----------------------
 1 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 7e6d306..877948c 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -22,16 +22,6 @@
 
 require_once('Mail/mimeDecode.php');
 
-
-$MESSAGE_FORM = NULL;
-$REPLY_MESSAGE = NULL;
-$FORWARD_MESSAGE = NULL;
-$DRAFT_MESSAGE = NULL;
-
-
-if (!is_array($_SESSION['compose']))
-  $_SESSION['compose'] = array('id' => uniqid(rand()));
-
 // remove an attachment
 if ($_action=='remove-attachment' && !empty($_GET['_filename']))
   {
@@ -46,6 +36,18 @@
         exit;
         }
   }
+
+$MESSAGE_FORM = NULL;
+$REPLY_MESSAGE = NULL;
+$FORWARD_MESSAGE = NULL;
+$DRAFT_MESSAGE = NULL;
+
+// nothing below is called during message composition, only at "new/forward/reply/draft" initialization
+// since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old
+// compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear
+
+rcmail_compose_cleanup();
+$_SESSION['compose'] = array('id' => uniqid(rand()));
 
 // add some labels to client
 rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'savingmessage', 'messagesaved');
@@ -376,18 +378,9 @@
   
   $out = $form_start ? "$form_start\n" : '';
 
-  // Check if a previous save was done so we can delete it upon the next save
-  if (!empty($_POST['_draft_newsaveid']))
-    $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => $_POST['_draft_newsaveid']));
-  else if (strlen($DRAFT_MESSAGE['headers']->messageID) > 6)
-    $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => str_replace(array('<','>'),"",$DRAFT_MESSAGE['headers']->messageID) ));
+  $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => str_replace(array('<','>'),"",$DRAFT_MESSAGE['headers']->messageID) ));
+  $out .= $saveid->show();
 
-  if ($saveid) 
-    $out .= $saveid->show();
-
-  $newsaveid = new hiddenfield(array('name' => '_draft_newsaveid', 'value' => sprintf('%s@%s', md5(uniqid('rcmail'.rand(),true)), $_SESSION['imap_host']) ));
-  $out .= $newsaveid->show();
- 
   $drafttoggle = new hiddenfield(array('name' => '_draft', 'value' => 'yes'));
   $out .= $drafttoggle->show();
 
@@ -417,7 +410,9 @@
 
     rcube_add_label('checking');
     }
-  
+ 
+  $out .= '<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
+ 
   return $out;
   }
 

--
Gitblit v1.9.1