diff --git a/mailnews/base/prefs/resources/content/AccountWizard.js b/mailnews/base/prefs/resources/content/AccountWizard.js index 88e2654167a..bd236280529 100644 --- a/mailnews/base/prefs/resources/content/AccountWizard.js +++ b/mailnews/base/prefs/resources/content/AccountWizard.js @@ -222,7 +222,6 @@ function AccountDataToPageData(accountData, pageData) } } - // take data from each page of pageData and dump it into accountData // use: to put results of wizard into a account-oriented object function PageDataToAccountData(pageData, accountData) @@ -566,6 +565,28 @@ function serverIsNntp(pageData) { return false; } +function getUsernameFromEmail(email) +{ + var emailData = email.split("@"); + return emailData[0]; +} + +function getCurrentUserName(pageData) +{ + var userName = ""; + + if (pageData.login) { + if (pageData.login.username) { + userName = pageData.login.username.value; + } + } + if (userName == "") { + var email = pageData.identity.email.value; + userName = getUsernameFromEmail(email); + } + return userName; +} + function getCurrentServerType(pageData) { var servertype = "pop3"; // hopefully don't resort to default! if (serverIsNntp(pageData)) @@ -642,7 +663,6 @@ function PrefillAccountForIsp(ispName) AccountDataToPageData(ispData, pageData); } - // does any cleanup work for the the account data // - sets the username from the email address if it's not already set // - anything else? @@ -652,8 +672,7 @@ function FixupAccountDataForIsp(accountData) var username; if (email) { - var emailData = email.split("@"); - username = emailData[0]; + username = getUsernameFromEmail(email); } // fix up the username diff --git a/mailnews/base/prefs/resources/content/aw-server.js b/mailnews/base/prefs/resources/content/aw-server.js index c5b44a69ec1..8f7f8f479ef 100644 --- a/mailnews/base/prefs/resources/content/aw-server.js +++ b/mailnews/base/prefs/resources/content/aw-server.js @@ -34,6 +34,30 @@ function validate() { window.alert(alertText); return false; } + + dump("check if this account exists\n"); + var pageData = parent.GetPageData(); + var hostName = servername.value; + var serverType = parent.getCurrentServerType(pageData); + var userName = parent.getCurrentUserName(pageData); + + var accountExists = false; + var accountManager = Components.classes["component://netscape/messenger/account-manager"].getService(Components.interfaces.nsIMsgAccountManager); + try { + var server = accountManager.FindServer(userName,hostName,serverType); + if (server) { + accountExists = true; + } + } + catch (ex) { + accountExists = false; + } + if (accountExists) { + var alertText = Bundle.GetStringFromName("accountExists"); + window.alert(alertText); + return false; + } + return true; } diff --git a/mailnews/base/prefs/resources/locale/en-US/prefs.properties b/mailnews/base/prefs/resources/locale/en-US/prefs.properties index 4d7231a38b2..cb9ba9f8f14 100644 --- a/mailnews/base/prefs/resources/locale/en-US/prefs.properties +++ b/mailnews/base/prefs/resources/locale/en-US/prefs.properties @@ -27,6 +27,7 @@ enterAccountName=Please enter a name for this account. enterUserName=Please enter a username. enterName=Please enter your name. enterValidEmail=Please enter a valid email address. +accountExists=An account of this type with the same username and hostname already exists. Go back and change it or hit cancel. # when the wizard already has a domain (Should we say something different?) enterValidEmailPrefix=Please enter a valid email address.