Bug 499878 - drag & drop an .eml file into a mailbox folder, r=Mnyromyr, sr=bienvenu
authorPhil Lacy <philbaseless-firefox@yahoo.com>
Tue, 01 Sep 2009 23:35:39 +0200
changeset 3486 7cd1d18a9c4671fb2c7b2650d13173f90d1a222a
parent 3485 42bada3ecb39ffb4ccea7142b889fe625e7f5ac6
child 3487 de2502431ec30544ebf5942d068d39a802812938
push idunknown
push userunknown
push dateunknown
reviewersMnyromyr, bienvenu
bugs499878
Bug 499878 - drag & drop an .eml file into a mailbox folder, r=Mnyromyr, sr=bienvenu
mailnews/base/content/messengerdnd.js
--- a/mailnews/base/content/messengerdnd.js
+++ b/mailnews/base/content/messengerdnd.js
@@ -62,16 +62,17 @@ function CanDropOnFolderTree(index, orie
 
     var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
     if (! trans)
         return false;
 
     trans.addDataFlavor("text/x-moz-message");
     trans.addDataFlavor("text/x-moz-folder");
     trans.addDataFlavor("text/x-moz-newsfolder");
+    trans.addDataFlavor("application/x-moz-file");
     trans.addDataFlavor("text/x-moz-url");
  
     var folderTree = GetFolderTree();
     var targetFolder = GetFolderResource(folderTree, index).QueryInterface(Components.interfaces.nsIMsgFolder);
     var targetUri = targetFolder.URI;
     var targetServer = targetFolder.server;
     var sourceServer, sourceFolder;
    
@@ -84,16 +85,27 @@ function CanDropOnFolderTree(index, orie
         try
         {
             trans.getAnyTransferData (dataFlavor, dataObj, len );
         }
         catch (ex)
         {
             continue;   //no data so continue;
         }
+
+        if (dataFlavor.value == "application/x-moz-file" && dataObj)
+        {
+          if (orientation != Components.interfaces.nsITreeView.DROP_ON ||
+              targetFolder.isServer ||
+              !targetFolder.canFileMessages)
+            return false;
+          if (dataObj.value instanceof Components.interfaces.nsIFile)
+            return dataObj.value.isFile();
+          return false;
+        }
         if (dataObj)
             dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
         if (! dataObj)
             continue;
 
         // pull the URL out of the data object
         var sourceUri = dataObj.data.substring(0, len.value);
         if (! sourceUri)
@@ -243,32 +255,51 @@ function DropOnFolderTree(row, orientati
     var dragSession = dragService.getCurrentSession();
     if (! dragSession )
         return false;
 
     var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
     trans.addDataFlavor("text/x-moz-message");
     trans.addDataFlavor("text/x-moz-folder");
     trans.addDataFlavor("text/x-moz-newsfolder");
+    trans.addDataFlavor("application/x-moz-file");
     trans.addDataFlavor("text/x-moz-url");
 
     var list = Components.classes["@mozilla.org/array;1"].createInstance(Components.interfaces.nsIMutableArray);
+    var cs = Components.classes["@mozilla.org/messenger/messagecopyservice;1"]
+                       .getService(Components.interfaces.nsIMsgCopyService);
 
     var dropMessage;
     var sourceUri;
     var sourceFolder;
     var sourceServer;
 	
     for (var i = 0; i < dragSession.numDropItems; i++)
     {
         dragSession.getData (trans, i);
         var dataObj = new Object();
         var flavor = new Object();
         var len = new Object();
         trans.getAnyTransferData(flavor, dataObj, len);
+        
+        // shortcircuit external files and get out
+        if (flavor.value == "application/x-moz-file" && dataObj)
+        {
+          dataObj = dataObj.value.QueryInterface(Components.interfaces.nsIFile);
+          if (!dataObj)
+            return false; // don't know how this would ever happen
+          if (dataObj.isFile())
+          {
+            let len = dataObj.leafName.length;
+            if (len > 4 && dataObj.leafName.substr(len - 4).toLowerCase() == ".eml")
+              cs.CopyFileMessage(dataObj, targetFolder, null, false, 1, "", null, msgWindow);
+          }
+          continue;
+        }
+        
         if (dataObj)
             dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
         if (! dataObj)
             continue;
 
         // pull the URL out of the data object
         sourceUri = dataObj.data.substring(0, len.value);
         if (! sourceUri)
@@ -344,18 +375,16 @@ function DropOnFolderTree(row, orientati
     }
 
     if (list.length < 1)
        return false;
 
     var isSourceNews = false;
     isSourceNews = isNewsURI(sourceUri);
 
-    var cs = Components.classes["@mozilla.org/messenger/messagecopyservice;1"]
-                       .getService(Components.interfaces.nsIMsgCopyService);
     if (dropMessage) {
         var sourceMsgHdr = list.queryElementAt(0, Components.interfaces.nsIMsgDBHdr);
         sourceFolder = sourceMsgHdr.folder;
         sourceServer = sourceFolder.server;
 
 
         try {
             if (isSourceNews) {