Back to index

lightning-sunbird  0.9+nobinonly
nsSmtpServer.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Seth Spitzer <sspitzer@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsIServiceManager.h"
00040 #include "nsIPrefService.h"
00041 #include "nsIPrefBranch.h"
00042 #include "nsEscape.h"
00043 #include "nsSmtpServer.h"
00044 #include "nsIObserverService.h"
00045 #include "nsNetUtil.h"
00046 #include "nsIAuthPrompt.h"
00047 #include "nsXPIDLString.h"
00048 #include "nsReadableUtils.h"
00049 #include "nsISmtpUrl.h"
00050 #include "nsCRT.h"
00051 #include "nsMsgUtils.h"
00052 #include "nsIMsgAccountManager.h"
00053 #include "nsMsgBaseCID.h"
00054 
00055 NS_IMPL_ADDREF(nsSmtpServer)
00056 NS_IMPL_RELEASE(nsSmtpServer)
00057 NS_INTERFACE_MAP_BEGIN(nsSmtpServer)
00058     NS_INTERFACE_MAP_ENTRY(nsISmtpServer)
00059     NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
00060     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISmtpServer)
00061 NS_INTERFACE_MAP_END
00062 
00063 nsSmtpServer::nsSmtpServer():
00064     mKey("")
00065 {
00066     m_logonFailed = PR_FALSE;
00067     getPrefs();
00068 }
00069 
00070 nsSmtpServer::~nsSmtpServer()
00071 {
00072 }
00073 
00074 NS_IMETHODIMP
00075 nsSmtpServer::GetKey(char * *aKey)
00076 {
00077     if (!aKey) return NS_ERROR_NULL_POINTER;
00078     if (mKey.IsEmpty())
00079         *aKey = nsnull;
00080     else
00081         *aKey = ToNewCString(mKey);
00082     return NS_OK;
00083 }
00084 
00085 NS_IMETHODIMP
00086 nsSmtpServer::SetKey(const char * aKey)
00087 {
00088     NS_ASSERTION(aKey, "Bad key pointer");
00089     mKey = aKey;
00090     return getPrefs();
00091 }
00092 
00093 nsresult nsSmtpServer::getPrefs()
00094 {
00095     nsresult rv;
00096     nsCOMPtr<nsIPrefService> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
00097     if (NS_FAILED(rv))
00098         return rv;
00099 
00100     nsCAutoString branchName;
00101     branchName.AssignLiteral("mail.smtpserver.");
00102     branchName += mKey;
00103     branchName.Append('.');
00104     rv = prefs->GetBranch(branchName.get(), getter_AddRefs(mPrefBranch));
00105     if (NS_FAILED(rv))
00106         return rv;
00107 
00108     if(!mDefPrefBranch) {
00109         branchName.AssignLiteral("mail.smtpserver.default.");
00110         rv = prefs->GetBranch(branchName.get(), getter_AddRefs(mDefPrefBranch));
00111         if (NS_FAILED(rv))
00112             return rv;
00113     }
00114 
00115     return NS_OK;
00116 }
00117 
00118 NS_IMETHODIMP
00119 nsSmtpServer::GetHostname(char * *aHostname)
00120 {
00121     nsresult rv;
00122     NS_ENSURE_ARG_POINTER(aHostname);
00123     rv = mPrefBranch->GetCharPref("hostname", aHostname);
00124     if (NS_FAILED(rv))
00125         *aHostname=nsnull;
00126     return NS_OK;
00127 }
00128 
00129 NS_IMETHODIMP
00130 nsSmtpServer::SetHostname(const char * aHostname)
00131 {
00132     if (aHostname)
00133         return mPrefBranch->SetCharPref("hostname", aHostname);
00134     else
00135         mPrefBranch->ClearUserPref("hostname");
00136     return NS_OK;
00137 }
00138 
00139 NS_IMETHODIMP
00140 nsSmtpServer::GetDescription(nsACString &aDescription)
00141 {
00142     nsXPIDLCString temp;
00143     mPrefBranch->GetCharPref("description", getter_Copies(temp));
00144     aDescription.Assign(temp);
00145     return NS_OK;
00146 }
00147 
00148 NS_IMETHODIMP
00149 nsSmtpServer::SetDescription(const nsACString &aDescription)
00150 {
00151     if (!aDescription.IsEmpty())
00152         return mPrefBranch->SetCharPref("description", PromiseFlatCString(aDescription).get());
00153     else
00154         mPrefBranch->ClearUserPref("description");
00155     return NS_OK;
00156 }
00157 
00158 // if GetPort returns 0, it means default port
00159 NS_IMETHODIMP
00160 nsSmtpServer::GetPort(PRInt32 *aPort)
00161 {
00162     nsresult rv;
00163     NS_ENSURE_ARG_POINTER(aPort);
00164     rv = mPrefBranch->GetIntPref("port", aPort);
00165     if (NS_FAILED(rv))
00166         *aPort = 0;
00167     return NS_OK;
00168 }
00169 
00170 NS_IMETHODIMP
00171 nsSmtpServer::SetPort(PRInt32 aPort)
00172 {
00173     if (aPort)
00174         return mPrefBranch->SetIntPref("port", aPort);
00175     else
00176         mPrefBranch->ClearUserPref("port");
00177     return NS_OK;
00178 }
00179 
00180 NS_IMETHODIMP
00181 nsSmtpServer::GetDisplayname(char * *aDisplayname)
00182 {
00183     nsresult rv;
00184     NS_ENSURE_ARG_POINTER(aDisplayname);
00185 
00186     nsXPIDLCString hostname;
00187     rv = mPrefBranch->GetCharPref("hostname", getter_Copies(hostname));
00188     if (NS_FAILED(rv)) {
00189         *aDisplayname=nsnull;
00190         return NS_OK;
00191     }
00192     PRInt32 port;
00193     rv = mPrefBranch->GetIntPref("port", &port);
00194     if (NS_FAILED(rv))
00195         port = 0;
00196     
00197     if (port) {
00198         hostname.Append(':');
00199         hostname.AppendInt(port);
00200     }
00201 
00202     *aDisplayname = ToNewCString(hostname);
00203     return NS_OK;
00204 }
00205 
00206 NS_IMETHODIMP
00207 nsSmtpServer::GetTrySSL(PRInt32 *trySSL)
00208 {
00209     NS_ENSURE_ARG_POINTER(trySSL);
00210     return getIntPrefWithDefault("try_ssl", trySSL, 0);
00211 }
00212 
00213 NS_IMETHODIMP
00214 nsSmtpServer::SetTrySSL(PRInt32 trySSL)
00215 {
00216     return mPrefBranch->SetIntPref("try_ssl", trySSL);
00217 }
00218 
00219 NS_IMETHODIMP
00220 nsSmtpServer::GetTrySecAuth(PRBool *trySecAuth)
00221 {
00222     nsresult rv;
00223     NS_ENSURE_ARG_POINTER(trySecAuth);
00224     *trySecAuth = PR_TRUE;
00225     rv = mPrefBranch->GetBoolPref("trySecAuth", trySecAuth);
00226     if (NS_FAILED(rv))
00227         mDefPrefBranch->GetBoolPref("trySecAuth", trySecAuth);
00228     return NS_OK;
00229 }
00230 
00231 NS_IMETHODIMP
00232 nsSmtpServer::GetHelloArgument(char * *aHelloArgument)
00233 {
00234     nsresult rv;
00235     NS_ENSURE_ARG_POINTER(aHelloArgument);
00236     rv = mPrefBranch->GetCharPref("hello_argument", aHelloArgument);
00237     if (NS_FAILED(rv))
00238     {
00239         rv = mDefPrefBranch->GetCharPref("hello_argument", aHelloArgument);
00240         if (NS_FAILED(rv))
00241             *aHelloArgument = nsnull;
00242     }
00243     return NS_OK;
00244 }
00245 
00246 NS_IMETHODIMP
00247 nsSmtpServer::GetAuthMethod(PRInt32 *authMethod)
00248 {
00249     NS_ENSURE_ARG_POINTER(authMethod);
00250     return getIntPrefWithDefault("auth_method", authMethod, 1);
00251 }
00252 
00253 nsresult
00254 nsSmtpServer::getIntPrefWithDefault(const char *prefName,
00255                                     PRInt32 *val,
00256                                     PRInt32 defVal)
00257 {
00258     nsresult rv = mPrefBranch->GetIntPref(prefName, val);
00259     if (NS_SUCCEEDED(rv))
00260         return NS_OK;
00261 
00262     rv = mDefPrefBranch->GetIntPref(prefName, val);
00263 
00264     if (NS_FAILED(rv))
00265     { // last resort
00266         *val = defVal;
00267     }
00268 
00269     return NS_OK;
00270 }
00271 
00272 NS_IMETHODIMP
00273 nsSmtpServer::SetAuthMethod(PRInt32 authMethod)
00274 {
00275     return mPrefBranch->SetIntPref("auth_method", authMethod);
00276 }
00277 
00278 NS_IMETHODIMP
00279 nsSmtpServer::GetUsername(char * *aUsername)
00280 {
00281     nsresult rv;
00282     NS_ENSURE_ARG_POINTER(aUsername);
00283     rv = mPrefBranch->GetCharPref("username", aUsername);
00284     if (NS_FAILED(rv))
00285         *aUsername = nsnull;
00286     return NS_OK;
00287 }
00288 
00289 NS_IMETHODIMP
00290 nsSmtpServer::SetUsername(const char * aUsername)
00291 {
00292     if (aUsername)
00293         return mPrefBranch->SetCharPref("username", aUsername);
00294     else
00295         mPrefBranch->ClearUserPref("username");
00296     return NS_OK;
00297 }
00298 
00299 NS_IMETHODIMP
00300 nsSmtpServer::GetPassword(char * *aPassword)
00301 {
00302     NS_ENSURE_ARG_POINTER(aPassword);
00303     if (m_password.IsEmpty() && !m_logonFailed)
00304     {
00305       // try to avoid prompting the user for another password. If the user has set
00306       // the appropriate pref, we'll use the password from an incoming server, if 
00307       // the user has already logged onto that server.
00308 
00309       // if this is set, we'll only use this, and not the other prefs
00310       // user_pref("mail.smtpserver.smtp1.incomingAccount", "server1");
00311 
00312       // if this is set, we'll accept an exact match of user name and server
00313       // user_pref("mail.smtp.useMatchingHostNameServer", true);
00314 
00315       // if this is set, and we don't find an exact match of user and host name, 
00316       // we'll accept a match of username and domain, where domain
00317       // is everything after the first '.'
00318       // user_pref("mail.smtp.useMatchingDomainServer", true);
00319 
00320       nsXPIDLCString accountKey;
00321       PRBool useMatchingHostNameServer = PR_FALSE;
00322       PRBool useMatchingDomainServer = PR_FALSE;
00323       mPrefBranch->GetCharPref("incomingAccount", getter_Copies(accountKey));
00324 
00325       nsCOMPtr<nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID);
00326       nsCOMPtr<nsIMsgIncomingServer> incomingServerToUse;
00327       if (accountManager) 
00328       {
00329         if (!accountKey.IsEmpty()) 
00330         {
00331           accountManager->GetIncomingServer(accountKey.get(), getter_AddRefs(incomingServerToUse));
00332         }
00333         else
00334         {
00335           nsresult rv;
00336           nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
00337           NS_ENSURE_SUCCESS(rv,rv);
00338           prefBranch->GetBoolPref("mail.smtp.useMatchingHostNameServer", &useMatchingHostNameServer);
00339           prefBranch->GetBoolPref("mail.smtp.useMatchingDomainServer", &useMatchingDomainServer);
00340           if (useMatchingHostNameServer || useMatchingDomainServer)
00341           {
00342             nsXPIDLCString userName;
00343             nsXPIDLCString hostName;
00344             GetHostname(getter_Copies(hostName));
00345             GetUsername(getter_Copies(userName));
00346             if (useMatchingHostNameServer)
00347               // pass in empty type and port=0, to match imap and pop3.
00348               accountManager->FindRealServer(userName, hostName, "", 0, getter_AddRefs(incomingServerToUse));
00349             PRInt32 dotPos = -1;
00350             if (!incomingServerToUse && useMatchingDomainServer 
00351               && (dotPos = hostName.FindChar('.')) != kNotFound)
00352             {
00353               hostName.Cut(0, dotPos);
00354               nsCOMPtr<nsISupportsArray> allServers;
00355               accountManager->GetAllServers(getter_AddRefs(allServers));
00356               if (allServers)
00357               {
00358                 PRUint32 count = 0;
00359                 allServers->Count(&count);
00360                 PRUint32 i;
00361                 for (i = 0; i < count; i++) 
00362                 {
00363                   nsCOMPtr<nsIMsgIncomingServer> server = do_QueryElementAt(allServers, i);
00364                   if (server)
00365                   {
00366                     nsXPIDLCString serverUserName;
00367                     nsXPIDLCString serverHostName;
00368                     server->GetRealUsername(getter_Copies(serverUserName));
00369                     server->GetRealHostName(getter_Copies(serverHostName));
00370                     if (serverUserName.Equals(userName))
00371                     {
00372                       PRInt32 serverDotPos = serverHostName.FindChar('.');
00373                       if (serverDotPos != kNotFound)
00374                       {
00375                         serverHostName.Cut(0, serverDotPos);
00376                         if (serverHostName.Equals(hostName))
00377                         {
00378                           incomingServerToUse = server;
00379                           break;
00380                         }
00381                       }
00382                     }
00383                   }
00384                 }
00385               }
00386             }
00387           }
00388         }
00389       }
00390       if (incomingServerToUse)
00391         return incomingServerToUse->GetPassword(aPassword);
00392 
00393     }
00394     *aPassword = ToNewCString(m_password);
00395     return NS_OK;
00396 }
00397 
00398 NS_IMETHODIMP
00399 nsSmtpServer::SetPassword(const char * aPassword)
00400 {
00401     m_password = aPassword;
00402     return NS_OK;
00403 }
00404 
00405 NS_IMETHODIMP
00406 nsSmtpServer::GetPasswordWithUI(const PRUnichar * aPromptMessage, const
00407                                 PRUnichar *aPromptTitle, 
00408                                 nsIAuthPrompt* aDialog,
00409                                 char **aPassword) 
00410 {
00411     nsresult rv = NS_OK;
00412 
00413     NS_ENSURE_ARG_POINTER(aPassword);
00414 
00415     if (m_password.IsEmpty())
00416     {
00417         NS_ENSURE_ARG_POINTER(aDialog);
00418 
00419         // prompt the user for the password
00420         if (NS_SUCCEEDED(rv))
00421         {
00422             nsXPIDLString uniPassword;
00423             PRBool okayValue = PR_TRUE;
00424             nsXPIDLCString serverUri;
00425             rv = GetServerURI(getter_Copies(serverUri));
00426             if (NS_FAILED(rv))
00427                 return rv;
00428             nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
00429             PRBool passwordProtectLocalCache = PR_FALSE;
00430 
00431             (void) prefBranch->GetBoolPref( "mail.password_protect_local_cache", &passwordProtectLocalCache);
00432 
00433             PRUint32 savePasswordType = (passwordProtectLocalCache) ? nsIAuthPrompt::SAVE_PASSWORD_FOR_SESSION : nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY;
00434             rv = aDialog->PromptPassword(aPromptTitle, aPromptMessage, 
00435                     NS_ConvertASCIItoUCS2(serverUri).get(), savePasswordType,
00436                     getter_Copies(uniPassword), &okayValue);
00437             if (NS_FAILED(rv))
00438                 return rv;
00439 
00440             if (!okayValue) // if the user pressed cancel, just return NULL;
00441             {
00442                 *aPassword = nsnull;
00443                 return rv;
00444             }
00445 
00446             // we got a password back...so remember it
00447             nsCString aCStr; aCStr.AssignWithConversion(uniPassword); 
00448 
00449             rv = SetPassword(aCStr.get());
00450             if (NS_FAILED(rv))
00451                 return rv;
00452         } // if we got a prompt dialog
00453     } // if the password is empty
00454 
00455     rv = GetPassword(aPassword);
00456     return rv;
00457 }
00458 
00459 NS_IMETHODIMP
00460 nsSmtpServer::GetUsernamePasswordWithUI(const PRUnichar * aPromptMessage, const
00461                                 PRUnichar *aPromptTitle, 
00462                                 nsIAuthPrompt* aDialog,
00463                                 char **aUsername,
00464                                 char **aPassword) 
00465 {
00466     nsresult rv = NS_OK;
00467 
00468     NS_ENSURE_ARG_POINTER(aUsername);
00469     NS_ENSURE_ARG_POINTER(aPassword);
00470 
00471     if (m_password.IsEmpty()) {
00472         NS_ENSURE_ARG_POINTER(aDialog);
00473         // prompt the user for the password
00474         if (NS_SUCCEEDED(rv))
00475         {
00476             nsXPIDLString uniUsername;
00477             nsXPIDLString uniPassword;
00478             PRBool okayValue = PR_TRUE;
00479             nsXPIDLCString serverUri;
00480             rv = GetServerURI(getter_Copies(serverUri));
00481             if (NS_FAILED(rv))
00482                 return rv;
00483             rv = aDialog->PromptUsernameAndPassword(aPromptTitle, aPromptMessage, 
00484                                          NS_ConvertASCIItoUCS2(serverUri).get(), nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY,
00485                                          getter_Copies(uniUsername), getter_Copies(uniPassword), &okayValue);
00486             if (NS_FAILED(rv))
00487                 return rv;
00488                             
00489             if (!okayValue) // if the user pressed cancel, just return NULL;
00490             {
00491                 *aUsername = nsnull;
00492                 *aPassword = nsnull;
00493                 return rv;
00494             }
00495 
00496             // we got a userid and password back...so remember it
00497             nsCString aCStr; 
00498 
00499             aCStr.AssignWithConversion(uniUsername); 
00500             rv = SetUsername(aCStr.get());
00501             if (NS_FAILED(rv))
00502                 return rv;
00503 
00504             aCStr.AssignWithConversion(uniPassword); 
00505             rv = SetPassword(aCStr.get());
00506             if (NS_FAILED(rv))
00507                 return rv;
00508         } // if we got a prompt dialog
00509     } // if the password is empty
00510 
00511     rv = GetUsername(aUsername);
00512     if (NS_FAILED(rv))
00513         return rv;
00514     rv = GetPassword(aPassword);
00515     return rv;
00516 }
00517 
00518 NS_IMETHODIMP
00519 nsSmtpServer::ForgetPassword()
00520 {
00521     nsresult rv;
00522     nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
00523     NS_ENSURE_SUCCESS(rv,rv);
00524 
00525     nsXPIDLCString serverUri;
00526     rv = GetServerURI(getter_Copies(serverUri));
00527     if (NS_FAILED(rv))
00528         return rv;
00529 
00530     nsCOMPtr<nsIURI> uri;
00531     NS_NewURI(getter_AddRefs(uri), serverUri);
00532 
00533     //this is need to make sure wallet service has been created
00534     rv = CreateServicesForPasswordManager();
00535     NS_ENSURE_SUCCESS(rv, rv);
00536 
00537     rv = observerService->NotifyObservers(uri, "login-failed", nsnull);
00538     NS_ENSURE_SUCCESS(rv,rv);
00539 
00540     rv = SetPassword("");
00541     m_logonFailed = PR_TRUE;
00542     return rv;
00543 }
00544 
00545 NS_IMETHODIMP
00546 nsSmtpServer::GetServerURI(char **aResult)
00547 {
00548     NS_ENSURE_ARG_POINTER(aResult);
00549     nsresult rv;
00550     nsCAutoString uri;
00551 
00552     uri += "smtp";
00553     uri += "://";
00554 
00555     nsXPIDLCString username;
00556     rv = GetUsername(getter_Copies(username));
00557 
00558     if (NS_SUCCEEDED(rv) && ((const char*)username) && username[0]) {
00559         nsXPIDLCString escapedUsername;
00560         *((char **)getter_Copies(escapedUsername)) =
00561             nsEscape(username, url_XAlphas);
00562 //            nsEscape(username, url_Path);
00563         // not all servers have a username 
00564         uri.Append(escapedUsername);
00565         uri += '@';
00566     }
00567 
00568     nsXPIDLCString hostname;
00569     rv = GetHostname(getter_Copies(hostname));
00570 
00571     if (NS_SUCCEEDED(rv) && ((const char*)hostname) && hostname[0]) {
00572         nsXPIDLCString escapedHostname;
00573         *((char **)getter_Copies(escapedHostname)) =
00574             nsEscape(hostname, url_Path);
00575         // not all servers have a hostname
00576         uri.Append(escapedHostname);
00577     }
00578 
00579     *aResult = ToNewCString(uri);
00580     return NS_OK;
00581 }
00582     
00583 NS_IMETHODIMP
00584 nsSmtpServer::SetRedirectorType(const char *aRedirectorType)
00585 {
00586     if (aRedirectorType)
00587         return mPrefBranch->SetCharPref("redirector_type", aRedirectorType);
00588 
00589     mPrefBranch->ClearUserPref("redirector_type");
00590     return NS_OK;
00591 }
00592 
00593 NS_IMETHODIMP
00594 nsSmtpServer::GetRedirectorType(char **aResult)
00595 {
00596     nsresult rv;
00597 
00598     rv = mPrefBranch->GetCharPref("redirector_type", aResult);
00599     if (NS_FAILED(rv)) 
00600       *aResult = nsnull;
00601 
00602     // Check if we need to change 'aol' to 'netscape' per #4696
00603     if (*aResult)
00604     { 
00605       if (!nsCRT::strcasecmp(*aResult, "aol"))
00606       {
00607         nsXPIDLCString hostName;
00608         rv = GetHostname(getter_Copies(hostName));
00609         if (NS_SUCCEEDED(rv) && (hostName.get()) && !nsCRT::strcmp(hostName, "smtp.netscape.net"))
00610         {
00611           PL_strfree(*aResult);
00612           rv = SetRedirectorType("netscape");
00613           NS_ENSURE_SUCCESS(rv,rv);
00614           *aResult = nsCRT::strdup("netscape");
00615         }
00616       }
00617     }
00618     else {
00619       // for people who have migrated from 4.x or outlook, or mistakenly
00620       // created redirected accounts as regular imap accounts, 
00621       // they won't have redirector type set properly
00622       // this fixes the redirector type for them automatically
00623       nsXPIDLCString hostName;
00624       rv = GetHostname(getter_Copies(hostName));
00625       NS_ENSURE_SUCCESS(rv,rv);
00626 
00627       nsCAutoString prefName;
00628       prefName.AssignLiteral("default_redirector_type.smtp.");
00629       prefName.Append(hostName);
00630 
00631       nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
00632       NS_ENSURE_SUCCESS(rv,rv);
00633       nsXPIDLCString defaultRedirectorType;
00634       rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(defaultRedirectorType));
00635       if (NS_SUCCEEDED(rv) && !defaultRedirectorType.IsEmpty()) 
00636       {
00637         // only set redirectory type in memory
00638         // if we call SetRedirectorType() that sets it in prefs
00639         // which makes this automatic redirector type repair permanent
00640         *aResult = ToNewCString(defaultRedirectorType);
00641       }
00642     }
00643     return NS_OK;
00644 }
00645 
00646 NS_IMETHODIMP
00647 nsSmtpServer::ClearAllValues()
00648 {
00649   return mPrefBranch->DeleteBranch("");
00650 }