add account name to imap alert messages, r/sr=neil, bug 66860
authorDavid Bienvenu <bienvenu@nventure.com>
Mon, 05 Apr 2010 13:38:58 -0700
changeset 5380 10c828f7de11
parent 5379 6eac7ef88f77
child 5381 eada20ef2a0a
push id4150
push userbienvenu@nventure.com
push dateMon, 05 Apr 2010 20:38:45 +0000
treeherdercomm-central@10c828f7de11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs66860
add account name to imap alert messages, r/sr=neil, bug 66860
mail/locales/en-US/chrome/messenger/imapMsgs.properties
mailnews/imap/src/nsImapIncomingServer.cpp
mailnews/imap/src/nsImapIncomingServer.h
mailnews/imap/src/nsImapStringBundle.h
suite/locales/en-US/chrome/mailnews/imapMsgs.properties
--- a/mail/locales/en-US/chrome/messenger/imapMsgs.properties
+++ b/mail/locales/en-US/chrome/messenger/imapMsgs.properties
@@ -419,8 +419,35 @@ 5113=The IMAP server %S does not support
 ## @loc None
 # LOCALIZATION NOTE (5114): %S is the server hostname
 5114=All login mechanisms for %S failed. Please check the password or change the 'Authentication method' in the 'Account Settings | Server settings'.
 
 ## @name IMAP_AUTH_GSSAPI_FAILED
 ## @loc None
 # LOCALIZATION NOTE (5115): %S is the server hostname
 5115=The Kerberos/GSSAPI ticket was not accepted by the IMAP server %S. Please check that you are logged in to the Kerberos/GSSAPI realm.
+
+## @name IMAP_LOGIN_DISABLED
+## @loc None
+# LOCALIZATION NOTE (5116): %S is the account name
+5116=You cannot log in to %S because the server doesn't allow plaintext authentication without STARTTLS or SSL/TLS. Try enabling connection security or secure authentication in the account settings.
+
+## @name IMAP_SERVER_COMMAND_FAILED
+## @loc None
+# LOCALIZATION NOTE (5117): 
+# Place the word %1$S in your translation where the name of the account name should appear.
+# Place the word %2$S in your translation where the server response should appear.
+5117=The current command did not succeed. The mail server for account %1$S responded: %2$S 
+
+## @name IMAP_FOLDER_COMMAND_FAILED
+## @loc None
+# LOCALIZATION NOTE (5118): Do not translate the word %S below.
+# Place the word %1$S in your translation where the name of the account should appear.
+# Place the word %2$S in your translation where the name of the folder should appear.
+# Place the word %3$S in your translation where the server response should appear.
+5118=The current operation on '%2$S' did not succeed. The mail server for account %1$S responded: %3$S
+
+## @name IMAP_SERVER_ALERT
+## @loc None
+# LOCALIZATION NOTE (5119):
+# Place the word %1$S in your translation where the name of the account should appear.
+# Place the word %2$S in your translation where the alert from the server should appear.
+5119=Alert from account %1$S: %2$S
--- a/mailnews/imap/src/nsImapIncomingServer.cpp
+++ b/mailnews/imap/src/nsImapIncomingServer.cpp
@@ -209,18 +209,17 @@ nsImapIncomingServer::GetConstructedPret
     NS_ENSURE_SUCCESS(rv,rv);
     if (!username.IsEmpty() && !hostName.IsEmpty()) {
       CopyASCIItoUTF16(username, emailAddress);
       emailAddress.Append('@');
       emailAddress.Append(NS_ConvertASCIItoUTF16(hostName));
     }
   }
 
-  rv = GetFormattedStringFromID(emailAddress, IMAP_DEFAULT_ACCOUNT_NAME, retval);
-  return rv;
+  return GetFormattedStringFromID(emailAddress, IMAP_DEFAULT_ACCOUNT_NAME, retval);
 }
 
 
 NS_IMETHODIMP nsImapIncomingServer::GetLocalStoreType(nsACString& type)
 {
   type.AssignLiteral("imap");
   return NS_OK;
 }
@@ -1769,49 +1768,53 @@ PRBool nsImapIncomingServer::AllDescende
     MSG_IMAPFolderInfoMail *currentChild = (MSG_IMAPFolderInfoMail *) parentFolder->GetSubFolder(childIndex);
     allDescendentsAreNoSelect = (currentChild->GetFolderPrefFlags() & MSG_FOLDER_PREF_IMAPNOSELECT) &&
       AllDescendentsAreNoSelect(currentChild);
   }
 #endif // 0
   return allDescendentsAreNoSelect;
 }
 
-
-#if 0
-void nsImapIncomingServer::UnsubscribeFromAllDescendents(nsIMsgFolder *parentFolder)
-{
-  int numberOfSubfolders = parentFolder->GetNumSubFolders();
-
-  for (int childIndex=0; childIndex < numberOfSubfolders; childIndex++)
-  {
-    MSG_IMAPFolderInfoMail *currentChild = (MSG_IMAPFolderInfoMail *) parentFolder->GetSubFolder(childIndex);
-    char *unsubscribeUrl = CreateIMAPUnsubscribeMailboxURL(currentChild->GetHostName(), currentChild->GetOnlineName(), currentChild->GetOnlineHierarchySeparator());	// unsubscribe from child
-    if (unsubscribeUrl)
-    {
-      MSG_UrlQueue::AddUrlToPane(unsubscribeUrl, NULL, pane);
-      XP_FREE(unsubscribeUrl);
-    }
-    UnsubscribeFromAllDescendants(currentChild);	// unsubscribe from its children
-  }
-}
-#endif // 0
-
 NS_IMETHODIMP
 nsImapIncomingServer::PromptLoginFailed(nsIMsgWindow *aMsgWindow,
                                         PRInt32 *aResult)
 {
   nsCAutoString hostName;
   GetRealHostName(hostName);
 
   return MsgPromptLoginFailed(aMsgWindow, hostName, aResult);
 }
 
 NS_IMETHODIMP
 nsImapIncomingServer::FEAlert(const nsAString& aString, nsIMsgMailNewsUrl *aUrl)
 {
+  GetStringBundle();
+
+  if (m_stringBundle)
+  {
+    nsAutoString hostName;
+    nsresult rv = GetPrettyName(hostName);
+    if (NS_SUCCEEDED(rv))
+    {
+      nsString message;
+      nsString tempString(aString);
+      const PRUnichar *params[] = { hostName.get(), tempString.get() };
+
+      rv = m_stringBundle->FormatStringFromID(IMAP_SERVER_ALERT, params, 2,
+                                              getter_Copies(message));
+      if (NS_SUCCEEDED(rv))
+        return AlertUser(message, aUrl);
+    }
+  }
+  return AlertUser(aString, aUrl);
+}
+
+nsresult nsImapIncomingServer::AlertUser(const nsAString& aString,
+                                         nsIMsgMailNewsUrl *aUrl)
+{
   nsresult rv;
   nsCOMPtr <nsIMsgMailSession> mailSession =
     do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return mailSession->AlertUser(aString, aUrl);
 }
 
@@ -1823,71 +1826,108 @@ nsImapIncomingServer::FEAlertWithID(PRIn
     return NS_OK;
 
   GetStringBundle();
 
   nsString message;
 
   if (m_stringBundle)
   {
-    nsCAutoString hostName;
-    nsresult rv = GetRealHostName(hostName);
+    nsAutoString hostName;
+    nsresult rv = GetPrettyName(hostName);
     if (NS_SUCCEEDED(rv))
     {
-      NS_ConvertASCIItoUTF16 hostStr(hostName);
-      const PRUnichar *params[] = { hostStr.get() };
+      const PRUnichar *params[] = { hostName.get() };
       rv = m_stringBundle->FormatStringFromID(aMsgId, params, 1,
                                               getter_Copies(message));
       if (NS_SUCCEEDED(rv))
-        return FEAlert(message, aUrl);
+        return AlertUser(message, aUrl);
     }
   }
 
   // Error condition
   message.AssignLiteral("String ID ");
   message.AppendInt(aMsgId);
   FEAlert(message, aUrl);
   return NS_OK;
 }
 
 NS_IMETHODIMP  nsImapIncomingServer::FEAlertFromServer(const nsACString& aString,
                                                        nsIMsgMailNewsUrl *aUrl)
 {
   NS_ENSURE_TRUE(!aString.IsEmpty(), NS_OK);
-  
-  nsresult rv;
-  nsCOMPtr <nsIMsgMailSession> mailSession =
-    do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // Skip over the first two words, I guess.
+
   nsCString message(aString);
-
+  message.Trim(" \t\b\r\n");
+  if (message.Last() != '.')
+    message.Append('.');
+
+  // Skip over the first two words (the command tag and "NO").
   // Find the first word break.
   PRInt32 pos = message.FindChar(' ');
 
   // Find the second word break.
   if (pos != -1)
     pos = message.FindChar(' ', pos + 1);
 
   // Adjust the message.
   if (pos != -1)
+    message = Substring(message, pos + 1);
+
+  nsString hostName;
+  GetPrettyName(hostName);
+
+  const PRUnichar *formatStrings[] =
   {
-    message = Substring(message, pos + 1);
-    message.Append('.');
-  }
-
+    hostName.get(),
+    nsnull,
+    nsnull
+  };
+
+  PRUint32 msgID;
+  PRInt32 numStrings;
   nsString fullMessage;
-  GetImapStringByID(IMAP_SERVER_SAID, fullMessage);
-  NS_ENSURE_TRUE(!fullMessage.IsEmpty(), NS_OK);
-
-  // The alert string from the server IS UTF-8!!! We must convert it to unicode
-  // correctly before appending it to our error message string...
-  AppendUTF8toUTF16(message, fullMessage);
-  return mailSession->AlertUser(fullMessage, aUrl);
+  nsCOMPtr<nsIImapUrl> imapUrl = do_QueryInterface(aUrl);
+  NS_ENSURE_TRUE(imapUrl, NS_ERROR_INVALID_ARG);
+
+  nsImapState imapState;
+  imapUrl->GetRequiredImapState(&imapState);
+  nsString folderName;
+
+  NS_ConvertUTF8toUTF16 unicodeMsg(message);
+
+  nsCOMPtr<nsIMsgFolder> folder;
+  if (imapState == nsIImapUrl::nsImapSelectedState)
+  {
+    aUrl->GetFolder(getter_AddRefs(folder));
+    if (folder)
+      folder->GetPrettyName(folderName);
+    numStrings = 3;
+    msgID = IMAP_FOLDER_COMMAND_FAILED;
+    formatStrings[1] = folderName.get();
+  }
+  else
+  {
+    msgID = IMAP_SERVER_COMMAND_FAILED;
+    numStrings = 2;
+  }
+
+  formatStrings[numStrings -1] = unicodeMsg.get();
+
+  nsresult rv = GetStringBundle();
+  NS_ENSURE_SUCCESS(rv, rv);
+  if (m_stringBundle)
+  {
+    rv = m_stringBundle->FormatStringFromID(msgID,
+                                formatStrings, numStrings,
+                                getter_Copies(fullMessage));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+
+  return AlertUser(fullMessage, aUrl);
 }
 
 #define IMAP_MSGS_URL       "chrome://messenger/locale/imapMsgs.properties"
 
 nsresult nsImapIncomingServer::GetStringBundle()
 {
   nsresult res;
   if (!m_stringBundle)
@@ -2728,27 +2768,25 @@ nsImapIncomingServer::GetOfflineSupportL
 }
 
 // Called only during the migration process. This routine enables the generation of
 // unique account name based on the username, hostname and the port. If the port
 // is valid and not a default one, it will be appended to the account name.
 NS_IMETHODIMP
 nsImapIncomingServer::GeneratePrettyNameForMigration(nsAString& aPrettyName)
 {
-  nsresult rv = NS_OK;
-
   nsCString userName;
   nsCString hostName;
 
 /**
   * Pretty name for migrated account is of format username@hostname:<port>,
   * provided the port is valid and not the default
 */
   // Get user name to construct pretty name
-  rv = GetUsername(userName);
+  nsresult rv = GetUsername(userName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Get host name to construct pretty name
   rv = GetHostName(hostName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRInt32 defaultServerPort;
   PRInt32 defaultSecureServerPort;
@@ -2788,25 +2826,24 @@ nsImapIncomingServer::GeneratePrettyName
   AppendASCIItoUTF16(hostName, constructedPrettyName);
   
   // If the port is valid and not default, add port value to the pretty name
   if ((serverPort > 0) && (!isItDefaultPort)) {
     constructedPrettyName.Append(':');
     constructedPrettyName.AppendInt(serverPort);
   }
 
-    // Format the pretty name
-    return GetFormattedStringFromID(constructedPrettyName, IMAP_DEFAULT_ACCOUNT_NAME, aPrettyName);
+  // Format the pretty name
+  return GetFormattedStringFromID(constructedPrettyName, IMAP_DEFAULT_ACCOUNT_NAME, aPrettyName);
 }
 
 nsresult
 nsImapIncomingServer::GetFormattedStringFromID(const nsAString& aValue, PRInt32 aID, nsAString& aResult)
 {
-  nsresult rv;
-  rv = GetStringBundle();
+  nsresult rv = GetStringBundle();
   if (m_stringBundle)
   {
     nsString tmpVal (aValue);
     const PRUnichar *formatStrings[] =
     {
       tmpVal.get(),
     };
 
@@ -2826,17 +2863,17 @@ nsImapIncomingServer::GetPrefForServerAt
 
   if (!mPrefBranch)
     return NS_ERROR_NOT_INITIALIZED;
 
   NS_ENSURE_ARG_POINTER(prefValue);
 
   if (NS_FAILED(mPrefBranch->GetBoolPref(prefSuffix, prefValue)))
     mDefPrefBranch->GetBoolPref(prefSuffix, prefValue);
-  
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsImapIncomingServer::GetCanFileMessagesOnServer(PRBool *aCanFileMessagesOnServer)
 {
   NS_ENSURE_ARG_POINTER(aCanFileMessagesOnServer);
   // Initialize aCanFileMessagesOnServer true, a default value for IMAP
--- a/mailnews/imap/src/nsImapIncomingServer.h
+++ b/mailnews/imap/src/nsImapIncomingServer.h
@@ -110,16 +110,17 @@ protected:
                                nsCOMArray<nsIMsgImapMailFolder> &aFoldersArray);
   void GetUnverifiedFolders(nsCOMArray<nsIMsgImapMailFolder> &aFolderArray);
   nsresult DeleteNonVerifiedFolders(nsIMsgFolder *parentFolder);
   PRBool NoDescendentsAreVerified(nsIMsgFolder *parentFolder);
   PRBool AllDescendentsAreNoSelect(nsIMsgFolder *parentFolder);
 
   nsresult GetStringBundle();
   nsString GetImapStringByName(const nsString &aName);
+  static nsresult AlertUser(const nsAString& aString, nsIMsgMailNewsUrl *aUrl);
 
 private:
   nsresult SubscribeToFolder(const PRUnichar *aName, PRBool subscribe);
   nsresult GetImapConnection (nsIEventTarget* aEventTarget,
                                    nsIImapUrl* aImapUrl,
                                    nsIImapProtocol** aImapConnection);
   nsresult CreateProtocolInstance(nsIEventTarget *aEventTarget,
                                            nsIImapProtocol ** aImapConnection);
--- a/mailnews/imap/src/nsImapStringBundle.h
+++ b/mailnews/imap/src/nsImapStringBundle.h
@@ -70,24 +70,24 @@ PR_END_EXTERN_C
 #define	IMAP_RECEIVING_MESSAGE_HEADERS_OF                                  5036
 #define	IMAP_RECEIVING_MESSAGE_FLAGS_OF                                  5037
 #define	IMAP_DELETING_MESSAGES                                  5038
 #define	IMAP_DELETING_MESSAGE                   5039
 #define	IMAP_MOVING_MESSAGES_TO                 5040
 #define	IMAP_MOVING_MESSAGE_TO                  5041
 #define	IMAP_COPYING_MESSAGES_TO                5042
 #define	IMAP_COPYING_MESSAGE_TO                 5043
-#define IMAP_FOLDER_RECEIVING_MESSAGE_OF	5045
-#define IMAP_DISCOVERING_MAILBOX		5046
-#define IMAP_ENTER_PASSWORD_PROMPT		5047
-#define IMAP_SERVER_NOT_IMAP4			5048
-#define IMAP_SERVER_SAID			5049
-#define IMAP_DONE				5050
-#define IMAP_ENTER_PASSWORD_PROMPT_TITLE	5051
-#define IMAP_UNKNOWN_HOST_ERROR			5052
+#define IMAP_FOLDER_RECEIVING_MESSAGE_OF        5045
+#define IMAP_DISCOVERING_MAILBOX                5046
+#define IMAP_ENTER_PASSWORD_PROMPT              5047
+#define IMAP_SERVER_NOT_IMAP4                   5048
+#define IMAP_SERVER_SAID                        5049
+#define IMAP_DONE                               5050
+#define IMAP_ENTER_PASSWORD_PROMPT_TITLE        5051
+#define IMAP_UNKNOWN_HOST_ERROR                 5052
 #define IMAP_CONNECTION_REFUSED_ERROR               5053
 #define IMAP_NET_TIMEOUT_ERROR                      5054
 #define IMAP_NO_NEW_MESSAGES                        5056
 #define IMAP_DEFAULT_ACCOUNT_NAME                   5057
 #define IMAP_EMPTY_TRASH_CONFIRM                    5061
 #define IMAP_SPECIAL_CHAR                           5065
 #define IMAP_PERSONAL_SHARED_FOLDER_TYPE_NAME       5066
 #define IMAP_PUBLIC_FOLDER_TYPE_NAME                5067
@@ -121,9 +121,13 @@ PR_END_EXTERN_C
 #define IMAP_DELETE_FOLDER_DIALOG_TITLE             5107
 #define IMAP_DELETE_FOLDER_BUTTON_LABEL             5108
 #define IMAP_AUTH_CHANGE_ENCRYPT_TO_PLAIN_SSL       5110
 #define IMAP_AUTH_CHANGE_PLAIN_TO_ENCRYPT           5111
 #define IMAP_AUTH_CHANGE_ENCRYPT_TO_PLAIN_NO_SSL    5112
 #define IMAP_AUTH_MECH_NOT_SUPPORTED                5113
 #define IMAP_AUTH_MECH_FAILED                       5114
 #define IMAP_AUTH_GSSAPI_FAILED                     5115
+#define IMAP_LOGIN_DISABLED                         5116
+#define IMAP_SERVER_COMMAND_FAILED                  5117
+#define IMAP_FOLDER_COMMAND_FAILED                  5118
+#define IMAP_SERVER_ALERT                           5119
 #endif /* _nsImapStringBundle_H__ */
--- a/suite/locales/en-US/chrome/mailnews/imapMsgs.properties
+++ b/suite/locales/en-US/chrome/mailnews/imapMsgs.properties
@@ -213,20 +213,16 @@ 5046=Found folder: %S
 # or the username should appear
 5047=Enter your password for %S:
 
 ## @name IMAP_SERVER_NOT_IMAP4
 ## @loc None
 # LOCALIZATION NOTE (Error 5048): Do not translate the word "IMAP4" below.
 5048=Mail server %S is not an IMAP4 mail server.
 
-## @name IMAP_SERVER_SAID
-## @loc None
-5049=The current command did not succeed.  The mail server responded: 
-
 ## @name IMAP_DONE
 ## @loc None
 5050=
 
 ## @name IMAP_ENTER_PASSWORD_PROMPT_TITLE
 ## @loc None
 5051=Mail Server Password Required
 
@@ -417,8 +413,35 @@ 5113=The IMAP server %S does not support
 ## @loc None
 # LOCALIZATION NOTE (5114): %S is the server hostname
 5114=All login mechanisms for %S failed. Please check the password or change the 'Authentication method' in the 'Account Settings | Server settings'.
 
 ## @name IMAP_AUTH_GSSAPI_FAILED
 ## @loc None
 # LOCALIZATION NOTE (5115): %S is the server hostname
 5115=The Kerberos/GSSAPI ticket was not accepted by the IMAP server %S. Please check that you are logged in to the Kerberos/GSSAPI realm.
+
+## @name IMAP_LOGIN_DISABLED
+## @loc None
+# LOCALIZATION NOTE (5116): %S is the account name
+5116=You cannot log in to %S because the server doesn't allow plaintext authentication without STARTTLS or SSL/TLS. Try enabling connection security or secure authentication in the account settings.
+
+## @name IMAP_SERVER_COMMAND_FAILED
+## @loc None
+# LOCALIZATION NOTE (5117): 
+# Place the word %1$S in your translation where the name of the account name should appear.
+# Place the word %2$S in your translation where the server response should appear.
+5117=The current command did not succeed. The mail server for account %1$S responded: %2$S 
+
+## @name IMAP_FOLDER_COMMAND_FAILED
+## @loc None
+# LOCALIZATION NOTE (5118): Do not translate the word %S below.
+# Place the word %1$S in your translation where the name of the account should appear.
+# Place the word %2$S in your translation where the name of the folder should appear.
+# Place the word %3$S in your translation where the server response should appear.
+5118=The current operation on '%2$S' did not succeed. The mail server for account %1$S responded: %3$S
+
+## @name IMAP_SERVER_ALERT
+## @loc None
+# LOCALIZATION NOTE (5119):
+# Place the word %1$S in your translation where the name of the account should appear.
+# Place the word %2$S in your translation where the alert from the server should appear.
+5119=Alert from account %1$S: %2$S