fix 384160, attaching non-ascii files to compose window through command line, sr=mscott
authorDavid Bienvenu <bienvenu@nventure.com>
Wed, 17 Sep 2008 08:30:32 -0700
changeset 356 35e89cc8d7963f49df3dd074487a26d194cf047b
parent 355 e8ba2f193d98d4ee8d39c37372c458db99202f97
child 357 930977fe94b057bded6022fa9847ac9535b2acb4
push idunknown
push userunknown
push dateunknown
reviewersmscott
bugs384160
fix 384160, attaching non-ascii files to compose window through command line, sr=mscott
mail/components/compose/content/MsgComposeCommands.js
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -1222,20 +1222,33 @@ function ComposeStartup(recycled, aParam
       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 ioService = Components.classes["@mozilla.org/network/io-service;1"]
+        ioService = ioService.getService(Components.interfaces.nsIIOService);
+        var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
         for (var i = 0; i < attachmentList.length; i ++)
         {
+          var attachmentStr = attachmentList[i];
           attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance(Components.interfaces.nsIMsgAttachment);
-          attachment.url = attachmentList[i];
+          if (/^file:\/\//i.test(attachmentStr))
+          {
+            attachment.url = attachmentStr;
+          }
+          else
+          {
+            localFile.initWithPath(attachmentList[i]);
+            attachment.url = fileHandler.getURLSpecFromFile(localFile);;
+          }
           composeFields.addAttachment(attachment);
         }
       }
       if (args.newshost)
         composeFields.newshost = args.newshost;
       if (args.body)
          composeFields.body = args.body;
     }