From 6c1039e2d9eed8026389bca6d47945fabc7f69b1 Mon Sep 17 00:00:00 2001 From: "racham%netscape.com" Date: Wed, 13 Feb 2002 00:15:08 +0000 Subject: [PATCH] Fixing bug 80296. This fix allows user to new messages for all authenticated accountswith a single click. This command canbe triggered from GetAllNewMessages item of GetMsg button drop marker, File|GetNewMessagesFor or shortcut Ctrl+Shift+T. r=morse, mscott sr=alecf --- extensions/wallet/src/nsPasswordManager.cpp | 60 +++++++++++++++++++ mailnews/base/public/nsIMsgIncomingServer.idl | 8 +++ .../content/mail3PaneWindowCommands.js | 1 - .../resources/content/mailWindowOverlay.js | 2 +- mailnews/base/util/nsMsgIncomingServer.cpp | 47 +++++++++++++++ 5 files changed, 116 insertions(+), 2 deletions(-) diff --git a/extensions/wallet/src/nsPasswordManager.cpp b/extensions/wallet/src/nsPasswordManager.cpp index 0580f0a947d1..449cd080a61b 100644 --- a/extensions/wallet/src/nsPasswordManager.cpp +++ b/extensions/wallet/src/nsPasswordManager.cpp @@ -39,6 +39,7 @@ #include "nsPasswordManager.h" #include "nsPassword.h" #include "singsign.h" +#include "nsReadableUtils.h" //////////////////////////////////////////////////////////////////////////////// @@ -200,3 +201,62 @@ NS_IMETHODIMP nsPasswordManager::RemoveReject(const char *host) { return ::SINGSIGN_RemoveReject(host); } + +NS_IMETHODIMP +nsPasswordManager::FindPasswordEntry(char **hostURI, PRUnichar **username, PRUnichar **password) +{ + NS_ENSURE_ARG_POINTER(hostURI); + NS_ENSURE_ARG_POINTER(username); + NS_ENSURE_ARG_POINTER(password); + + nsresult rv; + nsCOMPtr passwordElem; + + nsCOMPtr enumerator; + rv = GetEnumerator(getter_AddRefs(enumerator)); + if(NS_SUCCEEDED(rv) && enumerator) { + PRBool hasMoreElements = PR_FALSE; + enumerator->HasMoreElements(&hasMoreElements); + // Emumerate through password elements + while (hasMoreElements) { + rv = enumerator->GetNext(getter_AddRefs(passwordElem)); + if (NS_SUCCEEDED(rv) && passwordElem) { + // Get the server URI stored as host + nsXPIDLCString thisHostURI; + passwordElem->GetHost(getter_Copies(thisHostURI)); + + nsXPIDLString thisUsername; + passwordElem->GetUser(getter_Copies(thisUsername)); + + nsXPIDLString thisPassword; + passwordElem->GetPassword(getter_Copies(thisPassword)); + + // Check if any of the params are null (set by getter_Copies as + // preparation for output parameters) and treat them wild card + // entry matches or if they match with current password element + // attribute values. + PRBool hostURIOK = !*hostURI || thisHostURI.Equals(*hostURI); + PRBool usernameOK = !*username || thisUsername.Equals(*username); + PRBool passwordOK = !*password || thisPassword.Equals(*password); + + // If a password match is found based on given input params, + // fill in those params which are passed in as empty strings. + if (hostURIOK && usernameOK && passwordOK) + { + if (!*hostURI) { + *hostURI = ToNewCString(thisHostURI); + } + if (!*username) { + *username = ToNewUnicode(thisUsername); + } + if (!*password) { + *password = ToNewUnicode(thisPassword); + } + break; + } + } + enumerator->HasMoreElements(&hasMoreElements); + } + } + return NS_OK; +} diff --git a/mailnews/base/public/nsIMsgIncomingServer.idl b/mailnews/base/public/nsIMsgIncomingServer.idl index 37eb4caf2a28..ad289edf95ea 100644 --- a/mailnews/base/public/nsIMsgIncomingServer.idl +++ b/mailnews/base/public/nsIMsgIncomingServer.idl @@ -324,6 +324,14 @@ interface nsIMsgIncomingServer : nsISupports { long getIntAttribute(in string name); void setIntAttribute(in string name, in long value); + + /** + * If the password for the server is available either via authentication + * in the current session or from password manager stored entries, return + * true. Otherwise, return false. If password is obtained from password + * manager, set the password member variable. + */ + readonly attribute boolean isAuthenticated; }; %{C++ diff --git a/mailnews/base/resources/content/mail3PaneWindowCommands.js b/mailnews/base/resources/content/mail3PaneWindowCommands.js index a7789bdd9c2d..73d612e98a7a 100644 --- a/mailnews/base/resources/content/mail3PaneWindowCommands.js +++ b/mailnews/base/resources/content/mail3PaneWindowCommands.js @@ -472,7 +472,6 @@ var DefaultController = MsgGetMessage(); break; case "cmd_getMsgsForAuthAccounts": - MsgGetMessage(); MsgGetMessagesForAllAuthenticatedAccounts(); break; case "cmd_getNextNMessages": diff --git a/mailnews/base/resources/content/mailWindowOverlay.js b/mailnews/base/resources/content/mailWindowOverlay.js index 643e25539e0e..e390d8f37564 100644 --- a/mailnews/base/resources/content/mailWindowOverlay.js +++ b/mailnews/base/resources/content/mailWindowOverlay.js @@ -1431,7 +1431,7 @@ function GetMessagesForAllAuthenticatedAccounts() var currentServer = allServers.GetElementAt(i).QueryInterface(Components.interfaces.nsIMsgIncomingServer); var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + currentServer.type].getService(Components.interfaces.nsIMsgProtocolInfo); - if (protocolinfo.canGetMessages && currentServer.password) { + if (protocolinfo.canGetMessages && currentServer.isAuthenticated) { // Get new messages now GetMessagesForInboxOnServer(currentServer); } diff --git a/mailnews/base/util/nsMsgIncomingServer.cpp b/mailnews/base/util/nsMsgIncomingServer.cpp index 866fb70e1bb8..44d17b065c31 100644 --- a/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mailnews/base/util/nsMsgIncomingServer.cpp @@ -74,6 +74,7 @@ #include "nsIInterfaceRequestorUtils.h" #include "nsIMsgAccountManager.h" +#include "nsIPasswordManager.h" #ifdef DEBUG_sspitzer #define DEBUG_MSGINCOMING_SERVER @@ -1580,3 +1581,49 @@ NS_IMETHODIMP nsMsgIncomingServer::GetIntAttribute(const char *aName, PRInt32 *v { return GetIntValue(aName, val); } + +// Check if the password is available and return a boolean indicating whether +// it is being authenticated or not. +NS_IMETHODIMP +nsMsgIncomingServer::GetIsAuthenticated(PRBool *isAuthenticated) +{ + nsresult rv = NS_OK; + NS_ENSURE_ARG_POINTER(isAuthenticated); + + *isAuthenticated = PR_FALSE; + // If the password is empty, check to see if it is stored and to be retrieved + if (m_password.IsEmpty()) { + nsCOMPtr passwordMgr = do_GetService(NS_PASSWORDMANAGER_CONTRACTID, &rv); + if(NS_SUCCEEDED(rv) && passwordMgr) { + + // Get the current server URI + nsXPIDLCString currServerUri; + rv = GetServerURI(getter_Copies(currServerUri)); + NS_ENSURE_SUCCESS(rv, rv); + + // Obtain the server URI which is in the format ://@. + // Password manager uses the same format when it stores the password on user's request. + char* hostURI; + hostURI = ToNewCString(currServerUri); + + nsXPIDLString userName; + nsXPIDLString password; + + // Get password entry corresponding to the host URI we are passing in. + rv = passwordMgr->FindPasswordEntry(&hostURI, getter_Copies(userName), getter_Copies(password)); + NS_ENSURE_SUCCESS(rv, rv); + + // release hostURI + nsMemory::Free(hostURI); + + // If a match is found, password element is filled in. Convert the + // obtained password and store it for the session. + if (!password.IsEmpty()) { + rv = SetPassword(NS_ConvertUCS2toUTF8(password).get()); + NS_ENSURE_SUCCESS(rv, rv); + } + } + } + *isAuthenticated = !m_password.IsEmpty(); + return rv; +}