Bug 617011 composeStartup() Fixups. r=IanN sr=Neil
authorPhilip Chee <philip.chee@gmail.com>
Fri, 17 Dec 2010 21:13:46 +0800
changeset 6855 c6c5290dc2ae37ab11652e1360665151c906dc04
parent 6854 05b2436293603a177c0e761bea9cfdba2df23d86
child 6856 3a67b40d56f8355a4fca52c3b90a3024bf564223
push idunknown
push userunknown
push dateunknown
reviewersIanN, Neil
bugs617011
Bug 617011 composeStartup() Fixups. r=IanN sr=Neil
suite/mailnews/compose/MsgComposeCommands.js
--- a/suite/mailnews/compose/MsgComposeCommands.js
+++ b/suite/mailnews/compose/MsgComposeCommands.js
@@ -70,19 +70,18 @@ var sAccountManagerDataSource = null;
 var sRDF = null;
 var sNameProperty = null;
 var sDictCount = 0;
 
 /* Create message window object. This is use by mail-offline.js and therefore should not be renamed. We need to avoid doing
    this kind of cross file global stuff in the future and instead pass this object as parameter when needed by function
    in the other js file.
 */
-var msgWindow = Components.classes["@mozilla.org/messenger/msgwindow;1"].createInstance();
-msgWindow = msgWindow.QueryInterface(Components.interfaces.nsIMsgWindow);
-
+var msgWindow = Components.classes["@mozilla.org/messenger/msgwindow;1"]
+                          .createInstance(Components.interfaces.nsIMsgWindow);
 
 /**
  * Global variables, need to be re-initialized every time mostly because we need to release them when the window close
  */
 var gHideMenus;
 var gMsgCompose;
 var gAccountManager;
 var gIOService;
@@ -1195,19 +1194,16 @@ function handleMailtoArgs(mailtoUrl)
   return null;
 }
 
 function ComposeStartup(recycled, aParams)
 {
   var params = null; // New way to pass parameters to the compose window as a nsIMsgComposeParameters object
   var args = null;   // old way, parameters are passed as a string
 
-  if (recycled)
-    dump("This is a recycled compose window!\n");
-
   if (aParams)
     params = aParams;
   else if (window.arguments && window.arguments[0]) {
     try {
       if (window.arguments[0] instanceof Components.interfaces.nsIMsgComposeParams)
         params = window.arguments[0];
       else
         params = handleMailtoArgs(window.arguments[0]);
@@ -1253,32 +1249,44 @@ function ComposeStartup(recycled, aParam
         composeFields.bcc = args.bcc;
       if (args.newsgroups)
         composeFields.newsgroups = args.newsgroups;
       if (args.subject)
         composeFields.subject = args.subject;
       if (args.attachment)
       {
         var attachmentList = args.attachment.split(",");
-        var attachment;
+        var localFile = Components.classes["@mozilla.org/file/local;1"]
+                                  .createInstance(Components.interfaces.nsILocalFile);
+        var fileHandler = Services.io.getProtocolHandler("file")
+                                  .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
         for (let i = 0; i < attachmentList.length; i++)
         {
-          attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance(Components.interfaces.nsIMsgAttachment);
-          attachment.url = attachmentList[i];
+          let attachmentStr = attachmentList[i];
+          let attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"]
+                                     .createInstance(Components.interfaces.nsIMsgAttachment);
+
+          try {
+            localFile.initWithPath(attachmentStr);
+            attachment.url = fileHandler.getURLSpecFromFile(localFile);
+          } catch (e) {
+            attachment.url = encodeURI(attachmentStr);
+          }
           composeFields.addAttachment(attachment);
         }
       }
       if (args.newshost)
         composeFields.newshost = args.newshost;
       if (args.body)
          composeFields.body = args.body;
     }
   }
 
-  if (!params.identity) {
+  // " <>" is an empty identity, and most likely not valid
+  if (!params.identity || params.identity.identityName == " <>") {
     // no pre selected identity, so use the default account
     var identities = gAccountManager.defaultAccount.identities;
     if (identities.Count() == 0)
       identities = gAccountManager.allIdentities;
     params.identity = identities.QueryElementAt(0, Components.interfaces.nsIMsgIdentity);
   }
 
   identityList.value = params.identity.key;
@@ -1400,24 +1408,24 @@ function ComposeStartup(recycled, aParam
                                null);
         } catch (e) {
           dump(" Failed to startup editor: "+e+"\n");
         }
       }
     }
   }
 
-  // create URI of the folder from draftId 
+  // create URI of the folder from draftId
   var draftId = msgCompFields.draftId;
   var folderURI = draftId.substring(0, draftId.indexOf("#")).replace("-message", "");
-  
+
   try {
     const nsMsgFolderFlags = Components.interfaces.nsMsgFolderFlags;
     var folder = sRDF.GetResource(folderURI);
-  
+
     gEditingDraft = (folder instanceof Components.interfaces.nsIMsgFolder) &&
                     (folder.flags & nsMsgFolderFlags.Drafts);
   }
   catch (ex) {
     gEditingDraft = false;
   }
 
   gAutoSaveKickedIn = false;