Bug 1315662 - delete SMTP server login credentials when deleting the account or if hostname/username changes. r=mkmelin

This commit is contained in:
aceman 2019-06-15 09:03:00 +02:00
Родитель 5edf37d6df
Коммит d531de8a1d
3 изменённых файлов: 44 добавлений и 17 удалений

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

@ -53,6 +53,11 @@ var gSmtpServerListWindow = {
Services.prompt.STD_YES_NO_BUTTONS, null, null, null, null, { });
if (!cancel) {
// Remove password information first.
try {
server.forgetPassword();
} catch (e) { /* It is OK if this fails. */ }
// Remove the server.
MailServices.smtp.deleteServer(server);
parent.replaceWithDefaultSmtpServer(server.key);
this.refreshServerList("", true);

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

@ -106,6 +106,18 @@ nsresult nsSmtpServer::getPrefs() {
return NS_OK;
}
// This function is intentionally called the same as in nsIMsgIncomingServer.
nsresult
nsSmtpServer::OnUserOrHostNameChanged(const nsACString& oldName,
const nsACString& newName,
bool hostnameChanged)
{
// Reset password so that users are prompted for new password for the new user/host.
(void)ForgetPassword();
return NS_OK;
}
NS_IMETHODIMP
nsSmtpServer::GetHostname(nsACString &aHostname) {
nsCString result;
@ -120,12 +132,22 @@ nsSmtpServer::GetHostname(nsACString &aHostname) {
NS_IMETHODIMP
nsSmtpServer::SetHostname(const nsACString &aHostname) {
nsCString oldName;
nsresult rv = GetHostname(oldName);
NS_ENSURE_SUCCESS(rv, rv);
// A few things to take care of if we're changing the hostname.
if (!oldName.Equals(aHostname, nsCaseInsensitiveCStringComparator())) {
rv = OnUserOrHostNameChanged(oldName, aHostname, true);
NS_ENSURE_SUCCESS(rv, rv);
}
if (!aHostname.IsEmpty())
return mPrefBranch->SetCharPref("hostname", aHostname);
// If the pref value is already empty, ClearUserPref will return
// NS_ERROR_UNEXPECTED, so don't check the rv here.
mPrefBranch->ClearUserPref("hostname");
(void)mPrefBranch->ClearUserPref("hostname");
return NS_OK;
}
@ -245,12 +267,22 @@ nsSmtpServer::GetUsername(nsACString &aUsername) {
NS_IMETHODIMP
nsSmtpServer::SetUsername(const nsACString &aUsername) {
// Need to take care of few things if we're changing the username.
nsCString oldName;
nsresult rv = GetUsername(oldName);
NS_ENSURE_SUCCESS(rv, rv);
if (!oldName.Equals(aUsername)) {
rv = OnUserOrHostNameChanged(oldName, aUsername, false);
NS_ENSURE_SUCCESS(rv, rv);
}
if (!aUsername.IsEmpty())
return mPrefBranch->SetCharPref("username", aUsername);
// If the pref value is already empty, ClearUserPref will return
// NS_ERROR_UNEXPECTED, so don't check the rv here.
mPrefBranch->ClearUserPref("username");
(void)mPrefBranch->ClearUserPref("username");
return NS_OK;
}
@ -522,19 +554,7 @@ nsSmtpServer::ForgetPassword() {
NS_ENSURE_SUCCESS(rv, rv);
// Get the current server URI without the username
nsAutoCString serverUri(NS_LITERAL_CSTRING("smtp://"));
nsCString hostname;
rv = GetHostname(hostname);
if (NS_SUCCEEDED(rv) && !hostname.IsEmpty()) {
nsCString escapedHostname;
MsgEscapeString(hostname, nsINetUtil::ESCAPE_URL_PATH, escapedHostname);
// not all servers have a hostname
serverUri.Append(escapedHostname);
}
NS_ConvertUTF8toUTF16 currServer(serverUri);
NS_ConvertASCIItoUTF16 serverUri(GetServerURIInternal(false));
nsCString serverCUsername;
rv = GetUsername(serverCUsername);
@ -543,7 +563,7 @@ nsSmtpServer::ForgetPassword() {
NS_ConvertUTF8toUTF16 serverUsername(serverCUsername);
nsTArray<RefPtr<nsILoginInfo>> logins;
rv = loginMgr->FindLogins(currServer, EmptyString(), currServer, logins);
rv = loginMgr->FindLogins(serverUri, EmptyString(), serverUri, logins);
NS_ENSURE_SUCCESS(rv, rv);
// There should only be one-login stored for this url, however just in case

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

@ -34,7 +34,9 @@ class nsSmtpServer : public nsISmtpServer,
int32_t defval);
nsresult GetPasswordWithoutUI();
nsCString GetServerURIInternal(const bool aIncludeUsername);
nsresult OnUserOrHostNameChanged(const nsACString& oldName,
const nsACString& newName,
bool hostnameChanged);
nsString m_password;
bool m_logonFailed;
};