Bug 654007 Can't save as template via File > Save As Menu [SeaMonkey Part] f=InvisibleSmiley r=Neil sr/moa=Mnyromyr.
authorPhilip Chee <philip.chee@gmail.com>
Wed, 04 May 2011 17:26:14 +0800
changeset 7686 7f684b5a41a83fa02004454c9b361a3f893a5215
parent 7685 5a5d809c944afb6c8b7d0e0366653ed949a42ba1
child 7687 053cdd2ba13c74e076c41dcbd63a2a666cf0401f
push idunknown
push userunknown
push dateunknown
reviewersNeil
bugs654007
Bug 654007 Can't save as template via File > Save As Menu [SeaMonkey Part] f=InvisibleSmiley r=Neil sr/moa=Mnyromyr.
suite/mailnews/mailCommands.js
suite/mailnews/mailWindowOverlay.js
--- a/suite/mailnews/mailCommands.js
+++ b/suite/mailnews/mailCommands.js
@@ -383,20 +383,47 @@ function SaveAsFile(aUris)
                                          fileNames);
   }
   if (num == 1)
     messenger.saveAs(aUris[0], true, null, fileNames[0]);
   else
     messenger.saveMessages(num, fileNames, aUris);
 }
 
-function SaveAsTemplate(uri, folder)
+function saveAsUrlListener(aUri, aIdentity)
 {
-  if (uri) {
-    var identity = getIdentityForServer(folder.server);
+  this.uri = aUri;
+  this.identity = aIdentity;
+}
+
+saveAsUrlListener.prototype = {
+  OnStartRunningUrl: function(aUrl)
+  {
+  },
+  OnStopRunningUrl: function(aUrl, aExitCode)
+  {
+    messenger.saveAs(this.uri, false, this.identity, null);
+  }
+};
+
+function SaveAsTemplate(uri)
+{
+  if (uri)
+  {
+    var hdr = messenger.msgHdrFromURI(uri);
+    var identity = GetIdentityForHeader(hdr, Components.interfaces.nsIMsgCompType.Template);
+    var templates = MailUtils.getFolderForURI(identity.stationeryFolder, false);
+    if (!templates.parent)
+    {
+      templates.setFlag(Components.interfaces.nsMsgFolderFlags.Templates);
+      let isImap = templates.server.type == "imap";
+      templates.createStorageIfMissing(new saveAsUrlListener(uri, identity));
+      if (isImap)
+        return;
+    }
     messenger.saveAs(uri, false, identity, null);
   }
 }
 
 function MarkSelectedMessagesRead(markRead)
 {
   ClearPendingReadTimer();
   gDBView.doCommand(markRead ? nsMsgViewCommandType.markMessagesRead : nsMsgViewCommandType.markMessagesUnread);
--- a/suite/mailnews/mailWindowOverlay.js
+++ b/suite/mailnews/mailWindowOverlay.js
@@ -1622,20 +1622,18 @@ function MsgUnsubscribe()
 
 function MsgSaveAsFile()
 {
   SaveAsFile(GetSelectedMessages());
 }
 
 function MsgSaveAsTemplate()
 {
-    var folder = GetLoadedMsgFolder();
-    if (GetNumSelectedMessages() == 1) {
-        SaveAsTemplate(GetFirstSelectedMessage(), folder);
-    }
+  if (GetNumSelectedMessages() == 1)
+    SaveAsTemplate(GetFirstSelectedMessage());
 }
 
 const nsIFilePicker = Components.interfaces.nsIFilePicker;
 
 function MsgOpenFromFile()
 {
    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);