Update of /cvsroot/mahogany/M/src/gui
In directory usw-pr-cvs1:/tmp/cvs-serv7436/src/gui

Modified Files:
        wxComposeView.cpp 
Log Message:
delete the draft message after the message is sent or postponed again


Index: wxComposeView.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxComposeView.cpp,v
retrieving revision 1.256
retrieving revision 1.257
diff -b -u -2 -r1.256 -r1.257
--- wxComposeView.cpp   16 Mar 2002 23:38:48 -0000      1.256
+++ wxComposeView.cpp   17 Mar 2002 17:25:29 -0000      1.257
@@ -145,4 +145,7 @@
 };
 
+// the header used to indicate that a message is our draft
+#define DRAFT_HEADER "X-M-Draft"
+
 // the composer frame title
 #define COMPOSER_TITLE _("Message Composition")
@@ -1017,5 +1020,5 @@
    MailFolder::Params params("");
 
-   Composer *cv = CreateNewMessage(params, profile);
+   wxComposeView *cv = (wxComposeView *)CreateNewMessage(params, profile);
 
    // next, import the message body in it
@@ -1024,8 +1027,6 @@
    cv->ResetDirty();
 
-   // finally, also import all headers
-
-   // except the ones in ignoredHeaders:
-
+   // finally, also import all headers except the ones in ignoredHeaders:
+   //
    // first ignore those which are generated by the transport layer as it
    // doesn't make sense to generate them at all a MUA
@@ -1060,10 +1061,21 @@
          cv->AddBcc(values[n]);
       else if ( ignoredHeaders.Index(name) == wxNOT_FOUND )
+      {
+         // compare case sensitively here as we always write DRAFT_HEADER in
+         // the same case
+         if ( names[n] == DRAFT_HEADER )
+         {
+            cv->SetDraft(msg);
+         }
+         else // just another header
+         {
          cv->AddHeaderEntry(names[n], values[n]);
+         }
+      }
       //else: we ignore this one
    }
 
    // use the same language as we had used before
-   ((wxComposeView *)cv)->SetEncodingToSameAs(msg);
+   cv->SetEncodingToSameAs(msg);
 
    msg->DecRef();
@@ -1089,4 +1101,5 @@
    m_sending = false;
    m_OriginalMessage = NULL;
+   m_DraftMessage = NULL;
 
    m_indexLast = -1;
@@ -1110,4 +1123,17 @@
 }
 
+void wxComposeView::SetDraft(Message *msg)
+{
+   if ( m_DraftMessage )
+   {
+      FAIL_MSG( "Duplicate X-M-Draft?" );
+
+      m_DraftMessage->DecRef();
+   }
+
+   m_DraftMessage = msg;
+   m_DraftMessage->IncRef();
+}
+
 wxComposeView::~wxComposeView()
 {
@@ -1119,4 +1145,5 @@
 
    SafeDecRef(m_OriginalMessage);
+   SafeDecRef(m_DraftMessage);
 }
 
@@ -3124,5 +3151,13 @@
    m_sending = false;
 
-   return success;
+   if ( !success )
+   {
+      return false;
+   }
+
+   // we can now safely remove the draft message, if any
+   DeleteDraft();
+
+   return true;
 }
 
@@ -3244,4 +3279,30 @@
 }
 
+// ----------------------------------------------------------------------------
+// wxComposeView support for drafts folder
+// ----------------------------------------------------------------------------
+
+bool wxComposeView::DeleteDraft()
+{
+   if ( !m_DraftMessage )
+      return false;
+
+   // NB: GetFolder() doesn't IncRef() the result, so don't DecRef() it
+   MailFolder *mf = m_DraftMessage->GetFolder();
+   CHECK( mf, false, "draft message without folder?" );
+
+   if ( !mf->DeleteMessage(m_DraftMessage->GetUId()) )
+   {
+      wxLogError(_("Failed to delete the original draft message from "
+                   "the folder '%s'."), mf->GetName().c_str());
+      return false;
+   }
+
+   m_DraftMessage->DecRef();
+   m_DraftMessage = NULL;
+
+   return true;
+}
+
 // from upgrade.cpp, this forward decl will disappear once we move it somewhere
 // else (most likely MFolder?)
@@ -3264,4 +3325,7 @@
    }
 
+   // mark this message as our draft
+   msg->AddHeaderEntry(DRAFT_HEADER, "Yes");
+
    // ensure that the "Drafts" folder we're going to save the message to exists
    String nameDrafts = READ_CONFIG(m_Profile, MP_DRAFTS_FOLDER);
@@ -3292,5 +3356,5 @@
 
       // VerifyStdFolder() writes the name to profile
-      nameDrafts = READ_APPCONFIG(MP_DRAFTS_FOLDER);
+      nameDrafts = READ_APPCONFIG_TEXT(MP_DRAFTS_FOLDER);
 
       if ( rc == -1 )
@@ -3314,4 +3378,7 @@
    wxComposeView *self = (wxComposeView *)this;
    self->ResetDirty(); // const_cast
+
+   // we can now safely remove the old draft message, if any
+   self->DeleteDraft();
 
    MDialog_Message


_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to