Bug 543227 - Cater for special folders being called 'Draft' and 'Outbox' by certain IMAP providers. r=aceman
authorJorg K <jorgk@jorgk.com>
Thu, 13 Sep 2018 08:29:18 +0200
changeset 33141 5db89a74a3cdc2082f8c3615fe714dd165c662d1
parent 33140 84f675096b814ddb550c4cee0f25336366c16c2b
child 33142 e4373d203bcc042f4343015f3dfb3ff5901c5cf5
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersaceman
bugs543227
Bug 543227 - Cater for special folders being called 'Draft' and 'Outbox' by certain IMAP providers. r=aceman
mailnews/base/util/nsMsgDBFolder.cpp
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -3397,45 +3397,70 @@ nsMsgDBFolder::GetCanCompact(bool *aResu
 }
 
 
 NS_IMETHODIMP nsMsgDBFolder::GetPrettyName(nsAString& name)
 {
   return GetName(name);
 }
 
+// -1: not retrieved yet, 1: English, 0: non-English.
+static int isEnglish = -1;
+
 static bool
 nonEnglishApp()
 {
-  nsAutoCString locale;
-  mozilla::intl::LocaleService::GetInstance()->GetAppLocaleAsLangTag(locale);
-
-  return !(locale.EqualsLiteral("en") ||
-           StringBeginsWith(locale, NS_LITERAL_CSTRING("en-")));
+  if (isEnglish == -1) {
+    nsAutoCString locale;
+    mozilla::intl::LocaleService::GetInstance()->GetAppLocaleAsLangTag(locale);
+    isEnglish = (locale.EqualsLiteral("en") ||
+                 StringBeginsWith(locale, NS_LITERAL_CSTRING("en-"))) ? 1 : 0;
+  }
+  return isEnglish ? false : true;
 }
 
 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());
 }
 
+static bool
+hasDraftsName(const nsAString& name)
+{
+  // Some IMAP providers call the folder "Draft". If the application is non-English,
+  // we want to use the localised name instead.
+  return name.LowerCaseEqualsLiteral("drafts") ||
+         (name.LowerCaseEqualsLiteral("draft") && nonEnglishApp());
+}
+
+static bool
+hasSentName(const nsAString& name)
+{
+  // Some IMAP providers call the folder for sent messages "Outbox". That IMAP
+  // folder is not related to Thunderbird's local folder for queued messages.
+  // If we find such a folder with the 'SentMail' flag, we can safely localize
+  // its name if the application is non-English.
+  return name.LowerCaseEqualsLiteral("sent") ||
+         (name.LowerCaseEqualsLiteral("outbox") && 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"))
+  else if (mFlags & nsMsgFolderFlags::SentMail && hasSentName(name))
     rv = SetName(kLocalizedSentName);
-  else if (mFlags & nsMsgFolderFlags::Drafts && name.LowerCaseEqualsLiteral("drafts"))
+  else if (mFlags & nsMsgFolderFlags::Drafts && hasDraftsName(name))
     rv = SetName(kLocalizedDraftsName);
   else if (mFlags & nsMsgFolderFlags::Templates && name.LowerCaseEqualsLiteral("templates"))
     rv = SetName(kLocalizedTemplatesName);
   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"))