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

This commit is contained in:
racham%netscape.com 2002-02-13 00:15:08 +00:00
Родитель a592bef976
Коммит 61af2a0aac
5 изменённых файлов: 116 добавлений и 2 удалений

Просмотреть файл

@ -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<nsIPassword> passwordElem;
nsCOMPtr<nsISimpleEnumerator> 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;
}

Просмотреть файл

@ -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++

Просмотреть файл

@ -472,7 +472,6 @@ var DefaultController =
MsgGetMessage();
break;
case "cmd_getMsgsForAuthAccounts":
MsgGetMessage();
MsgGetMessagesForAllAuthenticatedAccounts();
break;
case "cmd_getNextNMessages":

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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 <nsIPasswordManager> 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 <protocol>://<userid>@<hostname>.
// 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;
}