Bug 39121 - Unspecialize Trash folder for IMAP "Mark as Deleted" & "Remove Immediately" modes; r=bienvenu, sr=neil
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Thu, 17 Nov 2011 22:00:59 +0200
changeset 9908 16b5f81c65f54e2a85f316407994cb0d47cfc9c6
parent 9907 fbbb89f6e1ee5e96db2f3558c0ebf5fc057fed19
child 9909 1330950c8ae4aca1c5290d792ff60364edb1971e
push id336
push userbugzilla@standard8.plus.com
push dateTue, 31 Jan 2012 22:15:45 +0000
treeherdercomm-beta@54945f5d278d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu, neil
bugs39121
Bug 39121 - Unspecialize Trash folder for IMAP "Mark as Deleted" & "Remove Immediately" modes; r=bienvenu, sr=neil
mail/base/content/folderPane.js
mail/base/content/mailContextMenus.js
mail/locales/en-US/chrome/messenger/messenger.properties
mailnews/base/public/nsIMsgFolder.idl
mailnews/base/public/nsIMsgProtocolInfo.idl
mailnews/base/test/unit/test_nsIMsgFolder.js
mailnews/imap/src/nsImapIncomingServer.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapService.cpp
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsMovemailService.cpp
mailnews/local/src/nsNoneService.cpp
mailnews/local/src/nsPop3Service.cpp
mailnews/local/src/nsRssService.cpp
mailnews/news/src/nsNewsFolder.cpp
mailnews/news/src/nsNntpService.cpp
suite/locales/en-US/chrome/mailnews/messenger.properties
suite/mailnews/mail3PaneWindowCommands.js
suite/mailnews/mailContextMenus.js
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -2188,38 +2188,21 @@ let gFolderTreeController = {
     let folder = folders[0];
 
     // For newsgroups, "delete" means "unsubscribe".
     if (folder.server.type == "nntp") {
       MsgUnsubscribe(folders);
       return;
     }
 
-    if (folder.flags & nsMsgFolderFlags.Inbox || folder.flags & nsMsgFolderFlags.Trash)
-      return;
-
-    let prefix = "@mozilla.org/messenger/protocol/info;1?type=";
-    let info = Components.classes[prefix + folder.server.type]
-                          .getService(Ci.nsIMsgProtocolInfo);
+    var canDelete = (folder.isSpecialFolder(nsMsgFolderFlags.Junk, false)) ?
+      CanRenameDeleteJunkMail(folder.URI) : folder.deletable;
 
-    // do not allow deletion of special folders on imap accounts
-    let bundle = document.getElementById("bundle_messenger");
-    if ((folder.flags & nsMsgFolderFlags.SentMail || folder.flags & nsMsgFolderFlags.Drafts ||
-         folder.flags & nsMsgFolderFlags.Templates ||
-         ((folder.flags & nsMsgFolderFlags.Junk) && CanRenameDeleteJunkMail(folder))) &&
-        !info.specialFoldersDeletionAllowed) {
-      let specialFolderString = getSpecialFolderString(folder);
-      let errorMessage = bundle.getFormattedString("specialFolderDeletionErr",
-                                                    [specialFolderString]);
-      let errorTitle = bundle.getString("specialFolderDeletionErrTitle");
-      Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
-                         .getService(Ci.nsIPromptService)
-                         .alert(window, errorTitle, errorMessage);
-      return;
-    }
+    if (!canDelete)
+      throw new Error("Can't delete folder: " + folder.name);
 
     if (folder.flags & nsMsgFolderFlags.Virtual) {
       let confirmation = bundle.getString("confirmSavedSearchDeleteMessage");
       let title = bundle.getString("confirmSavedSearchTitle");
       let IPS = Components.interfaces.nsIPromptService;
       if (Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
             .getService(IPS)
             .confirmEx(window, title, confirmation, IPS.STD_YES_NO_BUTTONS + IPS.BUTTON_POS_1_DEFAULT,
--- a/mail/base/content/mailContextMenus.js
+++ b/mail/base/content/mailContextMenus.js
@@ -437,20 +437,19 @@ function fillFolderPaneContextMenu()
                    !folders[0].isServer && folders[0].isCommandEnabled("cmd_renameFolder"));
   }
   else {
     ShowMenuItem("folderPaneContext-rename", false);
   }
 
   // --- Set up the delete folder menu item.
   function checkCanDeleteFolder(folder) {
-    let specialFolder = getSpecialFolderString(folder);
-    return folder.server.type != "nntp" && !folder.isServer &&
-           (specialFolder == "none" || specialFolder == "Virtual" ||
-            (specialFolder == "Junk" && CanRenameDeleteJunkMail(folder.URI)));
+    if (folder.isSpecialFolder(nsMsgFolderFlags.Junk, false))
+      return CanRenameDeleteJunkMail(folder.URI);
+    return folder.deletable;
   }
   var haveOnlyDeletableFolders = folders.every(checkCanDeleteFolder);
   ShowMenuItem("folderPaneContext-remove", haveOnlyDeletableFolders && numSelected == 1);
 
   function checkIsDeleteEnabled(folder) {
     return folder.isCommandEnabled("cmd_delete");
   }
   var haveOnlyDeleteEnabledFolders = folders.every(checkIsDeleteEnabled);
--- a/mail/locales/en-US/chrome/messenger/messenger.properties
+++ b/mail/locales/en-US/chrome/messenger/messenger.properties
@@ -182,21 +182,16 @@ inboxFolderName=Inbox
 trashFolderName=Trash
 sentFolderName=Sent
 draftsFolderName=Drafts
 templatesFolderName=Templates
 outboxFolderName=Outbox
 junkFolderName=Junk
 archivesFolderName=Archives
 
-# Error message for special folder deletion on imap accounts
-# LOCALIZATION NOTE (specialFolderDeletionErr): Do not translate "IMAP" in the line below
-specialFolderDeletionErr=Deletion of special folder %S is not allowed for IMAP accounts.
-specialFolderDeletionErrTitle=Special Folder Deletion
-
 # "Normal" priority is often blank,
 # depending on the consumers of these strings
 priorityLowest=Lowest
 priorityLow=Low
 priorityNormal=Normal
 priorityHigh=High
 priorityHighest=Highest
 
--- a/mailnews/base/public/nsIMsgFolder.idl
+++ b/mailnews/base/public/nsIMsgFolder.idl
@@ -278,25 +278,24 @@ interface nsIMsgFolder : nsISupports {
   /**
    * return the first new message in the folder
    *
    */
   readonly attribute nsIMsgDBHdr firstNewMessage;
 
   /**
    * clear new status flag of all of the new messages
-   *
    */
   void clearNewMessages();
 
   readonly attribute unsigned long expungedBytes;
 
   /**
-   * can this folder be deleted?
-   * for example, special folders cannot be deleted
+   * Can this folder be deleted?
+   * For example, special folders and isServer folders cannot be deleted.
    */
   readonly attribute boolean deletable;
 
   /**
    * should we be displaying recipients instead of the sender?
    * for example, in the Sent folder, recipients are more relevant
    * than the sender
    */
--- a/mailnews/base/public/nsIMsgProtocolInfo.idl
+++ b/mailnews/base/public/nsIMsgProtocolInfo.idl
@@ -40,17 +40,17 @@
 interface nsILocalFile;
 
 %{C++
 #define NS_MSGPROTOCOLINFO_CONTRACTID_PREFIX \
   "@mozilla.org/messenger/protocol/info;1?type="
 %}
 
 
-[scriptable, uuid(035fd631-e751-46af-9bbd-a660b930c288)]
+[scriptable, uuid(9428b5f5-8b12-493c-aae2-18296c2877b0)]
 interface nsIMsgProtocolInfo : nsISupports
 {
     /**
      * the default path to store local data for this type of
      * server. Each server is usually in a subdirectory below this
      */
     attribute nsILocalFile defaultLocalPath;
 
@@ -117,15 +117,10 @@ interface nsIMsgProtocolInfo : nsISuppor
      * do biff by default?
      */
     readonly attribute boolean defaultDoBiff;
 
     /**
      * do we need to show compose message link in the AccountCentral page ? 
      */
     readonly attribute boolean showComposeMsgLink;
-
-    /**
-     * do we allow special folder deletion ?
-     */
-    readonly attribute boolean specialFoldersDeletionAllowed;
 };
 
--- a/mailnews/base/test/unit/test_nsIMsgFolder.js
+++ b/mailnews/base/test/unit/test_nsIMsgFolder.js
@@ -43,9 +43,55 @@ function run_test() {
   var folder1 = root.getChildNamed("folder1");
 
   do_check_neq(folder1, folder2);
   do_check_eq(folder1.prettiestName, "folder1");
 
   var folder2 = root.getChildNamed("FOLDER1");
 
   do_check_eq(folder1, folder2);
+
+  // Check special folders aren't deletable, and that normal folders are.
+  if (!root.containsChildNamed("Inbox"))
+    root.createSubfolder("Inbox", null);
+  var inbox = root.getChildNamed("Inbox");
+  inbox.setFlag(Ci.nsMsgFolderFlags.Inbox);
+  do_check_false(inbox.deletable);
+
+  if (!root.containsChildNamed("Drafts"))
+    root.createSubfolder("Drafts", null);
+  var drafts = root.getChildNamed("Drafts");
+  drafts.setFlag(Ci.nsMsgFolderFlags.Drafts);
+  do_check_false(drafts.deletable);
+
+  if (!root.containsChildNamed("Templates"))
+    root.createSubfolder("Templates", null);
+  var templates = root.getChildNamed("Templates");
+  templates.setFlag(Ci.nsMsgFolderFlags.Templates);
+  do_check_false(templates.deletable);
+
+  if (!root.containsChildNamed("Sent"))
+     root.createSubfolder("Sent", null);
+  var sent = root.getChildNamed("Sent");
+  sent.setFlag(Ci.nsMsgFolderFlags.SentMail);
+  do_check_false(sent.deletable);
+
+  if (!root.containsChildNamed("Archives"))
+    root.createSubfolder("Archives", null);
+  var archives = root.getChildNamed("Archives");
+  archives.setFlag(Ci.nsMsgFolderFlags.Archive);
+  do_check_false(archives.deletable);
+
+  if (!root.containsChildNamed("Trash"))
+    root.createSubfolder("Trash", null);
+  var trash = root.getChildNamed("Trash");
+  trash.setFlag(Ci.nsMsgFolderFlags.Trash);
+  do_check_false(trash.deletable);
+
+  if (!root.containsChildNamed("Outbox"))
+    root.createSubfolder("Outbox", null);
+  var outbox = root.getChildNamed("Outbox");
+  outbox.setFlag(Ci.nsMsgFolderFlags.Queue);
+  do_check_false(outbox.deletable);
+
+  // test a normal folder is deletable
+  do_check_true(folder1.deletable);
 }
--- a/mailnews/imap/src/nsImapIncomingServer.cpp
+++ b/mailnews/imap/src/nsImapIncomingServer.cpp
@@ -361,16 +361,41 @@ nsImapIncomingServer::SetDeleteModel(PRI
   nsresult rv = SetIntValue("delete_model", ivalue);
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsIImapHostSessionList> hostSession =
         do_GetService(kCImapHostSessionListCID, &rv);
     NS_ENSURE_SUCCESS(rv,rv);
     hostSession->SetDeleteIsMoveToTrashForHost(m_serverKey.get(), ivalue == nsMsgImapDeleteModels::MoveToTrash);
     hostSession->SetShowDeletedMessagesForHost(m_serverKey.get(), ivalue == nsMsgImapDeleteModels::IMAPDelete);
+
+    nsAutoString trashFolderName;
+    nsresult rv = GetTrashFolderName(trashFolderName);
+    if (NS_SUCCEEDED(rv))
+    {
+      nsCAutoString trashFolderNameUtf7;
+      rv = CopyUTF16toMUTF7(trashFolderName, trashFolderNameUtf7);
+      if (NS_SUCCEEDED(rv))
+      {
+        nsCOMPtr<nsIMsgFolder> trashFolder;
+        rv = GetFolder(trashFolderNameUtf7, getter_AddRefs(trashFolder));
+        NS_ENSURE_SUCCESS(rv, rv);
+        nsCString trashURI;
+        trashFolder->GetURI(trashURI);
+        GetMsgFolderFromURI(trashFolder, trashURI, getter_AddRefs(trashFolder));
+        if (NS_SUCCEEDED(rv) && trashFolder)
+        {
+           // If the trash folder is used, set the flag, otherwise clear it.
+          if (ivalue == nsMsgImapDeleteModels::MoveToTrash)
+            trashFolder->SetFlag(nsMsgFolderFlags::Trash);
+          else
+            trashFolder->ClearFlag(nsMsgFolderFlags::Trash);
+        }
+      }
+    }
   }
   return rv;
 }
 
 NS_IMPL_SERVERPREF_INT(nsImapIncomingServer, TimeOutLimits,
                        "timeout")
 
 NS_IMPL_SERVERPREF_INT(nsImapIncomingServer, CapabilityPref,
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -1223,18 +1223,25 @@ NS_IMETHODIMP nsImapMailFolder::SetBoxFl
 
   if (m_boxFlags & kImapSent)
     newFlags |= nsMsgFolderFlags::SentMail;
 
   if (m_boxFlags & kImapInbox)
     newFlags |= nsMsgFolderFlags::Inbox;
 
   if (m_boxFlags & kImapXListTrash)
-    newFlags |= nsMsgFolderFlags::Trash;
-
+  {
+    nsCOMPtr<nsIImapIncomingServer> imapServer;
+    nsMsgImapDeleteModel deleteModel = nsMsgImapDeleteModels::MoveToTrash;
+    (void) GetImapIncomingServer(getter_AddRefs(imapServer));
+    if (imapServer)
+      imapServer->GetDeleteModel(&deleteModel);
+    if (deleteModel == nsMsgImapDeleteModels::MoveToTrash)
+      newFlags |= nsMsgFolderFlags::Trash;
+  }
   // Treat the GMail all mail folder as the archive folder.
   if (m_boxFlags & kImapAllMail)
     newFlags |= nsMsgFolderFlags::Archive;
 
   SetFlags(newFlags);
   return NS_OK;
 }
 
@@ -1805,18 +1812,26 @@ NS_IMETHODIMP nsImapMailFolder::GetPrett
 NS_IMETHODIMP nsImapMailFolder::UpdateSummaryTotals(bool force)
 {
   // bug 72871 inserted the mIsServer check for IMAP
   return mIsServer? NS_OK : nsMsgDBFolder::UpdateSummaryTotals(force);
 }
 
 NS_IMETHODIMP nsImapMailFolder::GetDeletable (bool *deletable)
 {
-  nsresult rv = NS_ERROR_FAILURE;
-  return rv;
+  NS_ENSURE_ARG_POINTER(deletable);
+
+  bool isServer;
+  GetIsServer(&isServer);
+
+  *deletable = !(isServer || (mFlags & (nsMsgFolderFlags::Inbox |
+    nsMsgFolderFlags::Drafts | nsMsgFolderFlags::Templates |
+    nsMsgFolderFlags::SentMail | nsMsgFolderFlags::Archive |
+    nsMsgFolderFlags::Junk | nsMsgFolderFlags::Trash)));
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsImapMailFolder::GetRequiresCleanup(bool *requiresCleanup)
 {
   nsresult rv = NS_ERROR_FAILURE;
   return rv;
 }
 
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -3003,23 +3003,16 @@ NS_IMETHODIMP nsImapService::GetCanGetIn
   return NS_OK;
 }    
 
 NS_IMETHODIMP nsImapService::GetShowComposeMsgLink(bool *showComposeMsgLink)
 {
   NS_ENSURE_ARG_POINTER(showComposeMsgLink);
   *showComposeMsgLink = PR_TRUE;
   return NS_OK;
-}        
-
-NS_IMETHODIMP nsImapService::GetSpecialFoldersDeletionAllowed(bool *specialFoldersDeletionAllowed)
-{
-  NS_ENSURE_ARG_POINTER(specialFoldersDeletionAllowed);
-  *specialFoldersDeletionAllowed = PR_FALSE;
-  return NS_OK;
 }
 
 NS_IMETHODIMP nsImapService::GetListOfFoldersWithPath(nsIImapIncomingServer *aServer, 
                                                       nsIMsgWindow *aMsgWindow, 
                                                       const nsACString &folderPath)
 {
   nsresult rv;
 
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -1383,21 +1383,21 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Writ
 }
 
 NS_IMETHODIMP nsMsgLocalMailFolder::GetDeletable(bool *deletable)
 {
   NS_ENSURE_ARG_POINTER(deletable);
 
   bool isServer;
   GetIsServer(&isServer);
-  *deletable = !(isServer || mFlags & nsMsgFolderFlags::Inbox ||
-    mFlags & nsMsgFolderFlags::Drafts ||
-    mFlags & nsMsgFolderFlags::Trash ||
-    mFlags & nsMsgFolderFlags::Templates ||
-    mFlags & nsMsgFolderFlags::Junk);
+  *deletable = !(isServer || (mFlags & (nsMsgFolderFlags::Inbox |
+    nsMsgFolderFlags::Drafts | nsMsgFolderFlags::Templates |
+    nsMsgFolderFlags::SentMail | nsMsgFolderFlags::Archive |
+    nsMsgFolderFlags::Junk | nsMsgFolderFlags::Trash |
+    nsMsgFolderFlags::Queue)));
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgLocalMailFolder::GetRequiresCleanup(bool *requiresCleanup)
 {
 #ifdef HAVE_PORT
   if (m_expungedBytes > 0)
   {
--- a/mailnews/local/src/nsMovemailService.cpp
+++ b/mailnews/local/src/nsMovemailService.cpp
@@ -647,16 +647,8 @@ nsMovemailService::GetDefaultServerPort(
 
 NS_IMETHODIMP
 nsMovemailService::GetShowComposeMsgLink(bool *showComposeMsgLink)
 {
   NS_ENSURE_ARG_POINTER(showComposeMsgLink);
   *showComposeMsgLink = PR_TRUE;
   return NS_OK;
 }
-
-NS_IMETHODIMP
-nsMovemailService::GetSpecialFoldersDeletionAllowed(bool *specialFoldersDeletionAllowed)
-{
-  NS_ENSURE_ARG_POINTER(specialFoldersDeletionAllowed);
-  *specialFoldersDeletionAllowed = PR_TRUE;
-  return NS_OK;
-}
--- a/mailnews/local/src/nsNoneService.cpp
+++ b/mailnews/local/src/nsNoneService.cpp
@@ -187,17 +187,8 @@ nsNoneService::GetDefaultServerPort(bool
 
 NS_IMETHODIMP 
 nsNoneService::GetShowComposeMsgLink(bool *showComposeMsgLink)
 {
     NS_ENSURE_ARG_POINTER(showComposeMsgLink);
     *showComposeMsgLink = PR_FALSE;    
     return NS_OK;
 }
-
-NS_IMETHODIMP
-nsNoneService::GetSpecialFoldersDeletionAllowed(bool *specialFoldersDeletionAllowed)
-{
-    NS_ENSURE_ARG_POINTER(specialFoldersDeletionAllowed);
-    *specialFoldersDeletionAllowed = PR_TRUE;
-    return NS_OK;
-}
-
--- a/mailnews/local/src/nsPop3Service.cpp
+++ b/mailnews/local/src/nsPop3Service.cpp
@@ -650,24 +650,16 @@ nsPop3Service::GetDefaultServerPort(bool
       *aPort = nsIPop3URL::DEFAULT_POP3S_PORT;
     else
       rv = GetDefaultPort(aPort);
 
     return rv;
 }
 
 NS_IMETHODIMP
-nsPop3Service::GetSpecialFoldersDeletionAllowed(bool *specialFoldersDeletionAllowed)
-{
-    NS_ENSURE_ARG_POINTER(specialFoldersDeletionAllowed);
-    *specialFoldersDeletionAllowed = PR_TRUE;
-    return NS_OK;
-}
-
-NS_IMETHODIMP
 nsPop3Service::NotifyDownloadStarted(nsIMsgFolder *aFolder)
 {
   nsTObserverArray<nsCOMPtr<nsIPop3ServiceListener> >::ForwardIterator
     iter(mListeners);
   nsCOMPtr<nsIPop3ServiceListener> listener;
   while (iter.HasMore()) {
     listener = iter.GetNext();
     listener->OnDownloadStarted(aFolder);
--- a/mailnews/local/src/nsRssService.cpp
+++ b/mailnews/local/src/nsRssService.cpp
@@ -146,13 +146,8 @@ NS_IMETHODIMP nsRssService::GetDefaultDo
 }
 
 NS_IMETHODIMP nsRssService::GetShowComposeMsgLink(bool *aShowComposeMsgLink)
 {
     NS_ENSURE_ARG_POINTER(aShowComposeMsgLink);
     *aShowComposeMsgLink = PR_FALSE;    
     return NS_OK;
 }
-
-NS_IMETHODIMP nsRssService::GetSpecialFoldersDeletionAllowed(bool *aSpecialFoldersDeletionAllowed)
-{
-    return NS_ERROR_NOT_IMPLEMENTED;
-}
--- a/mailnews/news/src/nsNewsFolder.cpp
+++ b/mailnews/news/src/nsNewsFolder.cpp
@@ -781,17 +781,18 @@ NS_IMETHODIMP nsMsgNewsFolder::GetExpung
 {
   NS_ENSURE_ARG_POINTER(count);
   *count = mExpungedBytes;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgNewsFolder::GetDeletable(bool *deletable)
 {
-  return NS_ERROR_NOT_IMPLEMENTED;
+  *deletable = false;
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgNewsFolder::GetRequiresCleanup(bool *requiresCleanup)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP nsMsgNewsFolder::GetSizeOnDisk(PRUint32 *size)
--- a/mailnews/news/src/nsNntpService.cpp
+++ b/mailnews/news/src/nsNntpService.cpp
@@ -1424,24 +1424,16 @@ nsNntpService::GetCanGetIncomingMessages
 NS_IMETHODIMP
 nsNntpService::GetShowComposeMsgLink(bool *showComposeMsgLink)
 {
     NS_ENSURE_ARG_POINTER(showComposeMsgLink);
     *showComposeMsgLink = PR_FALSE;
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsNntpService::GetSpecialFoldersDeletionAllowed(bool *specialFoldersDeletionAllowed)
-{
-    NS_ENSURE_ARG_POINTER(specialFoldersDeletionAllowed);
-    *specialFoldersDeletionAllowed = PR_FALSE;
-    return NS_OK;
-}
-
 //
 // rhp: Right now, this is the same as simple DisplayMessage, but it will change
 // to support print rendering.
 //
 NS_IMETHODIMP nsNntpService::DisplayMessageForPrinting(const char* aMessageURI, nsISupports * aDisplayConsumer,
                                                   nsIMsgWindow *aMsgWindow, nsIUrlListener * aUrlListener, nsIURI ** aURL)
 {
   mPrintingOperation = PR_TRUE;
--- a/suite/locales/en-US/chrome/mailnews/messenger.properties
+++ b/suite/locales/en-US/chrome/mailnews/messenger.properties
@@ -181,21 +181,16 @@ inboxFolderName=Inbox
 trashFolderName=Trash
 sentFolderName=Sent
 draftsFolderName=Drafts
 templatesFolderName=Templates
 outboxFolderName=Outbox
 junkFolderName=Junk
 archivesFolderName=Archives
 
-# Error message for special folder deletion on imap accounts
-# LOCALIZATION NOTE (specialFolderDeletionErr): Do not translate "IMAP" in the line below
-specialFolderDeletionErr=Deletion of special folder %S is not allowed for IMAP accounts.
-specialFolderDeletionErrTitle=Special Folder Deletion
-
 # "Normal" priority is often blank,
 # depending on the consumers of these strings
 priorityLowest=Lowest
 priorityLow=Low
 priorityNormal=Normal
 priorityHigh=High
 priorityHighest=Highest
 
--- a/suite/mailnews/mail3PaneWindowCommands.js
+++ b/suite/mailnews/mail3PaneWindowCommands.js
@@ -959,39 +959,28 @@ function MsgDeleteFolder()
                 if (gCurrentVirtualFolderUri == selectedFolder.URI)
                   gCurrentVirtualFolderUri = null;
                 var array = Components.classes["@mozilla.org/array;1"]
                                       .createInstance(Components.interfaces.nsIMutableArray);
                 array.appendElement(folder, false);
                 folder.parent.deleteSubFolders(array, msgWindow);
                 continue;
             }
-            var protocolInfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + selectedFolder.server.type].getService(Components.interfaces.nsIMsgProtocolInfo);
 
-            // do not allow deletion of special folders on imap accounts
-            if ((specialFolder == "Sent" || 
-                specialFolder == "Drafts" || 
-                specialFolder == "Templates" ||
-                (specialFolder == "Junk" && !CanRenameDeleteJunkMail(GetSelectedFolderURI()))) &&
-                !protocolInfo.specialFoldersDeletionAllowed)
-            {
-                var errorMessage = gMessengerBundle.getFormattedString("specialFolderDeletionErr",
-                                                    [specialFolder]);
-                var specialFolderDeletionErrTitle = gMessengerBundle.getString("specialFolderDeletionErrTitle");
-                prompt.alert(window, specialFolderDeletionErrTitle, errorMessage);
-                continue;
-            }   
-            else if (isNewsURI(selectedFolder.URI))
+            if (isNewsURI(selectedFolder.URI))
             {
                 var unsubscribe = ConfirmUnsubscribe(selectedFolder);
                 if (unsubscribe)
                     UnSubscribe(selectedFolder);
             }
-            else
+            else if (specialFolder == "Junk" ?
+                     CanRenameDeleteJunkMail(folder.URI) : folder.deletable)
             {
+                // We can delete this folder.
+
                 var array = Components.classes["@mozilla.org/array;1"]
                                       .createInstance(Components.interfaces.nsIMutableArray);
                 array.appendElement(selectedFolder, false);
                 try
                 {
                     selectedFolder.parent.deleteSubFolders(array, msgWindow);
                 }
                 // Ignore known errors from canceled warning dialogs.
--- a/suite/mailnews/mailContextMenus.js
+++ b/suite/mailnews/mailContextMenus.js
@@ -311,38 +311,37 @@ function FillFolderPaneContextMenu()
   ShowMenuItem("folderPaneContext-searchMessages", (numSelected <= 1) && !isVirtualFolder);
   goUpdateCommand('cmd_search');
 
   return(true);
 }
 
 function SetupRenameMenuItem(msgFolder, numSelected, isServer, serverType, specialFolder)
 {
-  var isSpecialFolder = !(specialFolder == "none" || (specialFolder == "Junk" && CanRenameDeleteJunkMail(msgFolder.URI))
-                                                  || (specialFolder == "Virtual"));
-  let canRename = msgFolder.canRename;
-  ShowMenuItem("folderPaneContext-rename", (numSelected <= 1) && !isServer && !isSpecialFolder && canRename);
+  var canRename = (specialFolder == "Junk") ?
+                  CanRenameDeleteJunkMail(msgFolder.URI) : msgFolder.canRename;
+  ShowMenuItem("folderPaneContext-rename", (numSelected <= 1) && canRename);
   EnableMenuItem("folderPaneContext-rename", !isServer && msgFolder.isCommandEnabled("cmd_renameFolder"));
 
   if (canRename)
     SetMenuItemLabel("folderPaneContext-rename", gMessengerBundle.getString("renameFolder"));
 }
 
 function SetupRemoveMenuItem(msgFolder, numSelected, isServer, serverType, specialFolder)
 {
   var isMail = serverType != 'nntp';
-  var isSpecialFolder = !(specialFolder == "none" || (specialFolder == "Junk" && CanRenameDeleteJunkMail(msgFolder.URI))
-                                                  || (specialFolder == "Virtual"));
-  //Can't currently delete Accounts or special folders.
-  var showRemove = (numSelected <=1) && (isMail && !isSpecialFolder) && !isServer;
+  var canDelete = (specialFolder == "Junk") ?
+                  CanRenameDeleteJunkMail(msgFolder.URI) : msgFolder.deletable;
+
+  var showRemove = (numSelected <=1) && isMail && canDelete;
 
   ShowMenuItem("folderPaneContext-remove", showRemove);
   if (showRemove)
     EnableMenuItem("folderPaneContext-remove", msgFolder.isCommandEnabled("cmd_delete"));
-  if (isMail && !isSpecialFolder)
+  if (canDelete)
     SetMenuItemLabel("folderPaneContext-remove", gMessengerBundle.getString("removeFolder"));
 }
 
 function SetupCompactMenuItem(folder, numSelected)
 {
   let canCompact = folder.canCompact;
   ShowMenuItem("folderPaneContext-compact", numSelected <= 1 && canCompact);
   EnableMenuItem("folderPaneContext-compact", folder.isCommandEnabled("cmd_compactFolder"));