Bug 1320191 - Cater for Outlook's/Hotmail's 'Deleted' folder. r=aceman a=jorgk
authorJorg K <jorgk@jorgk.com>
Sat, 02 Dec 2017 23:32:04 +0100
changeset 29404 760c2d834c8225c22223ac6d09226f80707560a8
parent 29403 a5c2e04140a90a7aeba9947594e8103b28c17174
child 29405 18f5dfef9cbdda9bddebc9a2cc108322bfe61de1
push id2086
push usermozilla@jorgk.com
push dateMon, 04 Dec 2017 16:29:58 +0000
treeherdercomm-beta@18f5dfef9cbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman, jorgk
bugs1320191
Bug 1320191 - Cater for Outlook's/Hotmail's 'Deleted' folder. r=aceman a=jorgk
mailnews/base/util/nsMsgDBFolder.cpp
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -66,16 +66,17 @@
 #include "nsMsgUtils.h"
 #include "nsIMsgFilterService.h"
 #include "nsDirectoryServiceUtils.h"
 #include "mozilla/Services.h"
 #include "nsMimeTypes.h"
 #include "nsIMsgFilter.h"
 #include "nsIConsoleService.h"
 #include "nsIScriptError.h"
+#include "mozilla/intl/LocaleService.h"
 
 static PRTime gtimeOfLastPurgeCheck;    //variable to know when to check for purge_threshhold
 
 #define PREF_MAIL_PROMPT_PURGE_THRESHOLD "mail.prompt_purge_threshhold"
 #define PREF_MAIL_PURGE_THRESHOLD "mail.purge_threshhold"
 #define PREF_MAIL_PURGE_THRESHOLD_MB "mail.purge_threshhold_mb"
 #define PREF_MAIL_PURGE_MIGRATED "mail.purge_threshold_migrated"
 #define PREF_MAIL_PURGE_ASK "mail.purge.ask"
@@ -3400,30 +3401,49 @@ nsMsgDBFolder::GetCanCompact(bool *aResu
 }
 
 
 NS_IMETHODIMP nsMsgDBFolder::GetPrettyName(nsAString& name)
 {
   return GetName(name);
 }
 
+static bool
+nonEnglishApp()
+{
+  nsAutoCString locale;
+  mozilla::intl::LocaleService::GetInstance()->GetAppLocaleAsLangTag(locale);
+
+  return !(locale.EqualsLiteral("en") ||
+           StringBeginsWith(locale, NS_LITERAL_CSTRING("en-")));
+}
+
+static bool
+hasTrashName(const nsAString& name)
+{
+  // Microsoft calls the folder "Deleted". If the application is non-English,
+  // we want to use the localised name instead.
+  return name.LowerCaseEqualsLiteral("trash") ||
+         (name.LowerCaseEqualsLiteral("deleted") && nonEnglishApp());
+}
+
 NS_IMETHODIMP nsMsgDBFolder::SetPrettyName(const nsAString& name)
 {
   nsresult rv;
 
   //Set pretty name only if special flag is set and if it the default folder name
   if (mFlags & nsMsgFolderFlags::Inbox && name.LowerCaseEqualsLiteral("inbox"))
     rv = SetName(kLocalizedInboxName);
   else if (mFlags & nsMsgFolderFlags::SentMail && name.LowerCaseEqualsLiteral("sent"))
     rv = SetName(kLocalizedSentName);
   else if (mFlags & nsMsgFolderFlags::Drafts && name.LowerCaseEqualsLiteral("drafts"))
     rv = SetName(kLocalizedDraftsName);
   else if (mFlags & nsMsgFolderFlags::Templates && name.LowerCaseEqualsLiteral("templates"))
     rv = SetName(kLocalizedTemplatesName);
-  else if (mFlags & nsMsgFolderFlags::Trash && name.LowerCaseEqualsLiteral("trash"))
+  else if (mFlags & nsMsgFolderFlags::Trash && hasTrashName(name))
     rv = SetName(kLocalizedTrashName);
   else if (mFlags & nsMsgFolderFlags::Queue && name.LowerCaseEqualsLiteral("unsent messages"))
     rv = SetName(kLocalizedUnsentName);
   else if (mFlags & nsMsgFolderFlags::Junk && name.LowerCaseEqualsLiteral("junk"))
     rv = SetName(kLocalizedJunkName);
   else if (mFlags & nsMsgFolderFlags::Archive && name.LowerCaseEqualsLiteral("archives"))
     rv = SetName(kLocalizedArchivesName);
   else