Bug 465015 - drag+drop of message not blocked to it's originating folder
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sun, 01 Feb 2009 23:18:08 +0000
changeset 1821 1fb281cf8e06721de19ca622e7e327e7dc5c0dc4
parent 1820 5345570b6c4b2e01a0ac53cc231c72d437b4976c
child 1822 15c15e191d5852a5ae9f64ca1e60f9c48eb81f54
push idunknown
push userunknown
push dateunknown
bugs465015
Bug 465015 - drag+drop of message not blocked to it's originating folder p=me r=mkmelin+mozilla sr=neil
mail/base/content/folderPane.js
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -334,26 +334,67 @@ let gFolderTreeView = {
   get rowCount() {
     return this._rowMap.length;
   },
 
   /**
    * drag drop interfaces
    */
   canDrop: function ftv_canDrop(aRow, aOrientation) {
+    const Cc = Components.classes;
+    const Ci = Components.interfaces;
+    if (aOrientation != Ci.nsITreeView.DROP_ON)
+      return false;
     let targetFolder = gFolderTreeView._rowMap[aRow]._folder;
     if (!targetFolder)
       return false;
     let dt = this._currentTransfer;
     let types = dt.mozTypesAt(0);
-    if (Array.indexOf(types, "text/x-moz-message") != -1 &&
-        !targetFolder.canFileMessages)
-      return false;
-    if (aOrientation != Components.interfaces.nsITreeView.DROP_ON)
-      return false;
+    if (Array.indexOf(types, "text/x-moz-message") != -1) {
+      // Don't allow drop onto server itself.
+      if (targetFolder.isServer)
+        return false;
+      // Don't allow drop into a folder that cannot take messages.
+      if (!targetFolder.canFileMessages)
+        return false;
+      let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
+      for (let i = 0; i < dt.mozItemCount; i++) {
+        let msgHdr = messenger.msgHdrFromURI(dt.mozGetDataAt("text/x-moz-message", i));
+        // Don't allow drop onto original folder.
+        if (msgHdr.folder == targetFolder)
+          return false;
+      }
+    }
+    else if (Array.indexOf(types, "text/x-moz-folder") != -1) {
+      // If cannot create subfolders then don't allow drop here.
+      if (!targetFolder.canCreateSubfolders)
+        return false;
+      for (let i = 0; i < dt.mozItemCount; i++) {
+        let folder = dt.mozGetDataAt("text/x-moz-folder", i)
+                       .QueryInterface(Ci.nsIMsgFolder);
+        // Don't allow to drop on itself.
+        if (targetFolder == folder)
+          return false;
+        // Don't allow immediate child to be dropped onto its parent.
+        if (targetFolder == folder.parent)
+          return false;
+        // Don't allow dragging of virtual folders across accounts.
+        if ((folder.flags & Ci.nsMsgFolderFlags.Virtual) &&
+            folder.server != targetFolder.server)
+          return false;
+        // Don't allow parent to be dropped on its ancestors.
+        if (folder.isAncestorOf(targetFolder))
+          return false;
+        // If there is a folder that can't be renamed, don't allow it to be
+        // dropped if it is not to "Local Folders" or is to the same account.
+        if (!folder.canRename && (targetFolder.server.type != "none" ||
+                                  folder.server == targetFolder.server))
+          return false;
+      }
+    }
     return true;
   },
   drop: function ftv_drop(aRow, aOrientation) {
     const Cc = Components.classes;
     const Ci = Components.interfaces;
     let targetFolder = gFolderTreeView._rowMap[aRow]._folder;
 
     let dt = this._currentTransfer;
@@ -361,26 +402,27 @@ let gFolderTreeView = {
     let cs = Cc["@mozilla.org/messenger/messagecopyservice;1"]
                 .getService(Ci.nsIMsgCopyService);
 
     // we only support drag of a single flavor at a time.
     let types = dt.mozTypesAt(0);
     if (Array.indexOf(types, "text/x-moz-folder") != -1) {
       for (let i = 0; i < count; i++) {
         let folders = new Array;
-        folders.push(dt.mozGetDataAt("text/x-moz-folder", i));
+        folders.push(dt.mozGetDataAt("text/x-moz-folder", i)
+                       .QueryInterface(Ci.nsIMsgFolder));
         let array = toXPCOMArray(folders, Ci.nsIMutableArray);
         cs.CopyFolders(array, targetFolder,
                       (folders[0].server == targetFolder.server), null,
                        msgWindow);
       }
     } 
     else if (Array.indexOf(types, "text/x-moz-message") != -1) {
       let array = Cc["@mozilla.org/array;1"]
-                    .createInstance(Components.interfaces.nsIMutableArray);
+                    .createInstance(Ci.nsIMutableArray);
       let sourceFolder;
       let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
       for (let i = 0; i < count; i++) {
         let msgHdr = messenger.msgHdrFromURI(dt.mozGetDataAt("text/x-moz-message", i));
         if (!i)
           sourceFolder = msgHdr.folder;
         array.appendElement(msgHdr, false);
       }