1999-09-09 04:11:38 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
1999-04-06 22:34:19 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-04-06 22:34:19 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-04-06 22:34:19 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-04-06 22:34:19 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-06 03:18:27 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1999-04-06 22:34:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsMsgIncomingServer.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCom.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-07-17 03:26:24 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-03-28 04:58:05 +00:00
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
|
|
|
|
#include "nsMsgBaseCID.h"
|
1999-07-17 03:26:24 +00:00
|
|
|
#include "nsIMsgFolder.h"
|
|
|
|
#include "nsIMsgFolderCache.h"
|
|
|
|
#include "nsIMsgFolderCacheElement.h"
|
2000-01-29 15:53:14 +00:00
|
|
|
#include "nsIMsgWindow.h"
|
2000-03-28 04:58:05 +00:00
|
|
|
#include "nsIMsgFilterService.h"
|
|
|
|
#include "nsIMsgProtocolInfo.h"
|
|
|
|
|
|
|
|
#include "nsIPref.h"
|
2000-01-29 15:53:14 +00:00
|
|
|
#include "nsIWebShell.h"
|
|
|
|
#include "nsIWebShellWindow.h"
|
|
|
|
#include "nsINetPrompt.h"
|
2000-02-03 05:01:42 +00:00
|
|
|
#include "nsIWalletService.h"
|
2000-03-28 04:58:05 +00:00
|
|
|
|
1999-08-30 22:12:20 +00:00
|
|
|
#include "nsIRDFService.h"
|
2000-02-29 21:01:53 +00:00
|
|
|
#include "nsIAppShellService.h"
|
|
|
|
#include "nsAppShellCIDs.h"
|
|
|
|
#include "nsIXULWindow.h"
|
1999-08-30 22:12:20 +00:00
|
|
|
#include "nsRDFCID.h"
|
1999-04-10 20:55:30 +00:00
|
|
|
|
2000-03-15 07:12:59 +00:00
|
|
|
#ifdef DEBUG_sspitzer
|
|
|
|
#define DEBUG_MSGINCOMING_SERVER
|
|
|
|
#endif /* DEBUG_sspitzer */
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
1999-08-30 22:12:20 +00:00
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
2000-02-03 05:01:42 +00:00
|
|
|
static NS_DEFINE_CID(kWalletServiceCID, NS_WALLETSERVICE_CID);
|
2000-02-29 21:01:53 +00:00
|
|
|
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
2000-03-28 04:58:05 +00:00
|
|
|
static NS_DEFINE_CID(kMsgFilterServiceCID, NS_MSGFILTERSERVICE_CID);
|
1999-04-10 20:55:30 +00:00
|
|
|
|
1999-10-06 20:32:25 +00:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsMsgIncomingServer);
|
|
|
|
|
1999-04-06 22:34:19 +00:00
|
|
|
nsMsgIncomingServer::nsMsgIncomingServer():
|
1999-04-10 20:55:30 +00:00
|
|
|
m_prefs(0),
|
1999-06-06 18:46:03 +00:00
|
|
|
m_serverKey(0),
|
|
|
|
m_rootFolder(0)
|
1999-04-06 22:34:19 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
1999-08-31 06:52:27 +00:00
|
|
|
m_serverBusy = PR_FALSE;
|
1999-10-13 04:12:06 +00:00
|
|
|
m_password = "";
|
1999-04-06 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMsgIncomingServer::~nsMsgIncomingServer()
|
|
|
|
{
|
2000-03-28 04:58:05 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (mFilterList) {
|
|
|
|
nsCOMPtr<nsIMsgFilterService> filterService =
|
|
|
|
do_GetService(kMsgFilterServiceCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2000-05-12 09:15:05 +00:00
|
|
|
rv = filterService->SaveFilterList(mFilterList, &mFilterFile);
|
2000-03-28 04:58:05 +00:00
|
|
|
}
|
1999-04-10 20:55:30 +00:00
|
|
|
if (m_prefs) nsServiceManager::ReleaseService(kPrefServiceCID,
|
|
|
|
m_prefs,
|
|
|
|
nsnull);
|
|
|
|
PR_FREEIF(m_serverKey)
|
1999-04-06 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
2000-03-05 21:26:01 +00:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsMsgIncomingServer);
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsMsgIncomingServer);
|
2000-01-26 00:54:15 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMsgIncomingServer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMsgIncomingServer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMsgIncomingServer)
|
2000-03-05 21:26:01 +00:00
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
1999-04-06 22:34:19 +00:00
|
|
|
|
1999-09-09 04:11:38 +00:00
|
|
|
NS_IMPL_GETSET(nsMsgIncomingServer, ServerBusy, PRBool, m_serverBusy)
|
1999-04-10 20:55:30 +00:00
|
|
|
NS_IMPL_GETTER_STR(nsMsgIncomingServer::GetKey, m_serverKey)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-19 23:46:35 +00:00
|
|
|
nsMsgIncomingServer::SetKey(const char * serverKey)
|
1999-04-10 20:55:30 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// in order to actually make use of the key, we need the prefs
|
|
|
|
if (!m_prefs)
|
|
|
|
rv = nsServiceManager::GetService(kPrefServiceCID,
|
2000-02-06 03:18:27 +00:00
|
|
|
NS_GET_IID(nsIPref),
|
1999-04-10 20:55:30 +00:00
|
|
|
(nsISupports**)&m_prefs);
|
|
|
|
|
|
|
|
PR_FREEIF(m_serverKey);
|
|
|
|
m_serverKey = PL_strdup(serverKey);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:56:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::SetRootFolder(nsIFolder * aRootFolder)
|
|
|
|
{
|
|
|
|
m_rootFolder = aRootFolder;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::GetRootFolder(nsIFolder * *aRootFolder)
|
|
|
|
{
|
|
|
|
if (!aRootFolder)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-06-06 18:46:03 +00:00
|
|
|
if (m_rootFolder) {
|
|
|
|
*aRootFolder = m_rootFolder;
|
|
|
|
NS_ADDREF(*aRootFolder);
|
|
|
|
} else {
|
1999-09-09 04:11:38 +00:00
|
|
|
nsresult rv = CreateRootFolder();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*aRootFolder = m_rootFolder;
|
1999-08-30 22:12:20 +00:00
|
|
|
NS_IF_ADDREF(*aRootFolder);
|
1999-06-06 18:46:03 +00:00
|
|
|
}
|
1999-05-26 23:56:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-03 02:06:57 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-21 22:55:18 +00:00
|
|
|
nsMsgIncomingServer::PerformExpand(nsIMsgWindow *aMsgWindow)
|
2000-04-03 02:06:57 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_sspitzer
|
|
|
|
printf("PerformExpand()\n");
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-11 22:10:42 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::PerformBiff()
|
|
|
|
{
|
|
|
|
//This had to be implemented in the derived class, but in case someone doesn't implement it
|
|
|
|
//just return not implemented.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-07-17 03:26:24 +00:00
|
|
|
NS_IMETHODIMP nsMsgIncomingServer::WriteToFolderCache(nsIMsgFolderCache *folderCache)
|
|
|
|
{
|
1999-07-17 20:33:15 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-07-17 03:26:24 +00:00
|
|
|
if (m_rootFolder)
|
|
|
|
{
|
1999-07-17 20:33:15 +00:00
|
|
|
nsCOMPtr <nsIMsgFolder> msgFolder = do_QueryInterface(m_rootFolder, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && msgFolder)
|
|
|
|
rv = msgFolder->WriteToFolderCache(folderCache);
|
1999-07-17 03:26:24 +00:00
|
|
|
}
|
1999-07-17 20:33:15 +00:00
|
|
|
return rv;
|
1999-07-17 03:26:24 +00:00
|
|
|
}
|
|
|
|
|
1999-09-30 01:44:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::CloseCachedConnections()
|
|
|
|
{
|
|
|
|
// derived class should override if they cache connections.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-28 20:22:06 +00:00
|
|
|
// construct <localStoreType>://[<username>@]<hostname
|
1999-09-09 04:11:38 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-03 07:16:59 +00:00
|
|
|
nsMsgIncomingServer::GetServerURI(char **aResult)
|
1999-09-09 04:11:38 +00:00
|
|
|
{
|
1999-11-03 07:16:59 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
1999-10-28 20:22:06 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCAutoString uri;
|
|
|
|
|
|
|
|
nsXPIDLCString localStoreType;
|
|
|
|
rv = GetLocalStoreType(getter_Copies(localStoreType));
|
1999-11-03 07:16:59 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-03-26 12:14:14 +00:00
|
|
|
uri.Append(localStoreType);
|
1999-10-28 20:22:06 +00:00
|
|
|
uri += "://";
|
|
|
|
|
|
|
|
nsXPIDLCString username;
|
|
|
|
rv = GetUsername(getter_Copies(username));
|
|
|
|
|
1999-11-03 07:16:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && ((const char*)username) && username[0]) {
|
|
|
|
nsXPIDLCString escapedUsername;
|
|
|
|
*((char **)getter_Copies(escapedUsername)) =
|
2000-02-05 01:19:38 +00:00
|
|
|
nsEscape(username, url_XAlphas);
|
|
|
|
// nsEscape(username, url_Path);
|
2000-01-12 03:03:30 +00:00
|
|
|
// not all servers have a username
|
2000-03-26 12:14:14 +00:00
|
|
|
uri.Append(escapedUsername);
|
1999-11-03 07:16:59 +00:00
|
|
|
uri += '@';
|
|
|
|
}
|
1999-10-28 20:22:06 +00:00
|
|
|
|
|
|
|
nsXPIDLCString hostname;
|
|
|
|
rv = GetHostName(getter_Copies(hostname));
|
|
|
|
|
1999-11-03 07:16:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && ((const char*)hostname) && hostname[0]) {
|
|
|
|
nsXPIDLCString escapedHostname;
|
|
|
|
*((char **)getter_Copies(escapedHostname)) =
|
|
|
|
nsEscape(hostname, url_Path);
|
2000-01-12 03:03:30 +00:00
|
|
|
// not all servers have a hostname
|
2000-03-26 12:14:14 +00:00
|
|
|
uri.Append(escapedHostname);
|
1999-11-03 07:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = uri.ToNewCString();
|
1999-10-28 20:22:06 +00:00
|
|
|
return NS_OK;
|
1999-09-09 04:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::CreateRootFolder()
|
1999-08-30 22:12:20 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
// get the URI from the incoming server
|
|
|
|
nsXPIDLCString serverUri;
|
|
|
|
rv = GetServerURI(getter_Copies(serverUri));
|
1999-09-09 04:11:38 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-30 22:12:20 +00:00
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIRDFService, rdf,
|
|
|
|
kRDFServiceCID, &rv);
|
|
|
|
|
|
|
|
// get the corresponding RDF resource
|
|
|
|
// RDF will create the server resource if it doesn't already exist
|
|
|
|
nsCOMPtr<nsIRDFResource> serverResource;
|
|
|
|
rv = rdf->GetResource(serverUri, getter_AddRefs(serverResource));
|
1999-09-09 04:11:38 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-30 22:12:20 +00:00
|
|
|
|
|
|
|
// make incoming server know about its root server folder so we
|
|
|
|
// can find sub-folders given an incoming server.
|
1999-09-09 04:11:38 +00:00
|
|
|
m_rootFolder = do_QueryInterface(serverResource, &rv);
|
|
|
|
return rv;
|
1999-08-30 22:12:20 +00:00
|
|
|
}
|
|
|
|
|
2000-01-26 00:54:15 +00:00
|
|
|
void
|
1999-04-06 22:34:19 +00:00
|
|
|
nsMsgIncomingServer::getPrefName(const char *serverKey,
|
2000-01-26 00:54:15 +00:00
|
|
|
const char *prefName,
|
|
|
|
nsCString& fullPrefName)
|
1999-04-06 22:34:19 +00:00
|
|
|
{
|
2000-01-26 00:54:15 +00:00
|
|
|
// mail.server.<key>.<pref>
|
|
|
|
fullPrefName = "mail.server.";
|
|
|
|
fullPrefName.Append(serverKey);
|
|
|
|
fullPrefName.Append('.');
|
|
|
|
fullPrefName.Append(prefName);
|
1999-04-06 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
// this will be slightly faster than the above, and allows
|
|
|
|
// the "default" server preference root to be set in one place
|
2000-01-26 00:54:15 +00:00
|
|
|
void
|
|
|
|
nsMsgIncomingServer::getDefaultPrefName(const char *prefName,
|
|
|
|
nsCString& fullPrefName)
|
1999-04-06 22:34:19 +00:00
|
|
|
{
|
2000-01-26 00:54:15 +00:00
|
|
|
// mail.server.default.<pref>
|
|
|
|
fullPrefName = "mail.server.default.";
|
|
|
|
fullPrefName.Append(prefName);
|
1999-04-06 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
|
|
|
|
nsresult
|
1999-09-09 04:11:38 +00:00
|
|
|
nsMsgIncomingServer::GetBoolValue(const char *prefname,
|
1999-04-10 20:55:30 +00:00
|
|
|
PRBool *val)
|
1999-04-06 22:34:19 +00:00
|
|
|
{
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult rv = m_prefs->GetBoolPref(fullPrefName, val);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = getDefaultBoolPref(prefname, val);
|
|
|
|
|
|
|
|
return rv;
|
1999-04-06 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::getDefaultBoolPref(const char *prefname,
|
|
|
|
PRBool *val) {
|
|
|
|
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getDefaultPrefName(prefname, fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult rv = m_prefs->GetBoolPref(fullPrefName, val);
|
|
|
|
|
1999-06-06 18:46:03 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*val = PR_FALSE;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
1999-04-10 20:55:30 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-09-09 04:11:38 +00:00
|
|
|
nsMsgIncomingServer::SetBoolValue(const char *prefname,
|
1999-04-10 20:55:30 +00:00
|
|
|
PRBool val)
|
1999-04-06 22:34:19 +00:00
|
|
|
{
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult rv;
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
|
|
|
|
PRBool defaultValue;
|
|
|
|
rv = getDefaultBoolPref(prefname, &defaultValue);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
val == defaultValue)
|
1999-09-09 04:11:38 +00:00
|
|
|
m_prefs->ClearUserPref(fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
else
|
|
|
|
rv = m_prefs->SetBoolPref(fullPrefName, val);
|
|
|
|
|
|
|
|
return rv;
|
1999-04-06 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult
|
1999-09-09 04:11:38 +00:00
|
|
|
nsMsgIncomingServer::GetIntValue(const char *prefname,
|
1999-04-10 20:55:30 +00:00
|
|
|
PRInt32 *val)
|
1999-04-06 22:34:19 +00:00
|
|
|
{
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult rv = m_prefs->GetIntPref(fullPrefName, val);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = getDefaultIntPref(prefname, val);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-09 04:11:38 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::GetFileValue(const char* prefname,
|
|
|
|
nsIFileSpec **spec)
|
|
|
|
{
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-09-09 04:11:38 +00:00
|
|
|
nsresult rv = m_prefs->GetFilePref(fullPrefName, spec);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::SetFileValue(const char* prefname,
|
|
|
|
nsIFileSpec *spec)
|
|
|
|
{
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-09-09 04:11:38 +00:00
|
|
|
nsresult rv = m_prefs->SetFilePref(fullPrefName, spec, PR_FALSE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::getDefaultIntPref(const char *prefname,
|
|
|
|
PRInt32 *val) {
|
|
|
|
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getDefaultPrefName(prefname, fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult rv = m_prefs->GetIntPref(fullPrefName, val);
|
|
|
|
|
1999-06-06 18:46:03 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*val = 0;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-09-09 04:11:38 +00:00
|
|
|
nsMsgIncomingServer::SetIntValue(const char *prefname,
|
1999-04-10 20:55:30 +00:00
|
|
|
PRInt32 val)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
|
|
|
|
PRInt32 defaultVal;
|
|
|
|
rv = getDefaultIntPref(prefname, &defaultVal);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && defaultVal == val)
|
1999-09-09 04:11:38 +00:00
|
|
|
m_prefs->ClearUserPref(fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
else
|
|
|
|
rv = m_prefs->SetIntPref(fullPrefName, val);
|
|
|
|
|
|
|
|
return rv;
|
1999-04-06 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult
|
1999-09-09 04:11:38 +00:00
|
|
|
nsMsgIncomingServer::GetCharValue(const char *prefname,
|
1999-04-10 20:55:30 +00:00
|
|
|
char **val)
|
|
|
|
{
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult rv = m_prefs->CopyCharPref(fullPrefName, val);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = getDefaultCharPref(prefname, val);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-12-03 00:10:00 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::GetUnicharValue(const char *prefname,
|
|
|
|
PRUnichar **val)
|
|
|
|
{
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-12-03 00:10:00 +00:00
|
|
|
nsresult rv = m_prefs->CopyUnicharPref(fullPrefName, val);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = getDefaultUnicharPref(prefname, val);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-10 21:58:09 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::getDefaultCharPref(const char *prefname,
|
|
|
|
char **val) {
|
|
|
|
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getDefaultPrefName(prefname, fullPrefName);
|
1999-04-10 21:58:09 +00:00
|
|
|
nsresult rv = m_prefs->CopyCharPref(fullPrefName, val);
|
|
|
|
|
1999-06-06 18:46:03 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-06-14 22:53:09 +00:00
|
|
|
*val = nsnull; // null is ok to return here
|
1999-06-06 18:46:03 +00:00
|
|
|
rv = NS_OK;
|
|
|
|
}
|
1999-04-10 21:58:09 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-12-03 00:10:00 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::getDefaultUnicharPref(const char *prefname,
|
|
|
|
PRUnichar **val) {
|
|
|
|
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getDefaultPrefName(prefname, fullPrefName);
|
1999-12-03 00:10:00 +00:00
|
|
|
nsresult rv = m_prefs->CopyUnicharPref(fullPrefName, val);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*val = nsnull; // null is ok to return here
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult
|
1999-09-09 04:11:38 +00:00
|
|
|
nsMsgIncomingServer::SetCharValue(const char *prefname,
|
1999-08-10 04:39:22 +00:00
|
|
|
const char * val)
|
1999-04-10 20:55:30 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
|
1999-09-09 04:11:38 +00:00
|
|
|
if (!val) {
|
|
|
|
m_prefs->ClearUserPref(fullPrefName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
char *defaultVal=nsnull;
|
|
|
|
rv = getDefaultCharPref(prefname, &defaultVal);
|
1999-09-09 04:11:38 +00:00
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
PL_strcmp(defaultVal, val) == 0)
|
1999-09-09 04:11:38 +00:00
|
|
|
m_prefs->ClearUserPref(fullPrefName);
|
1999-04-10 20:55:30 +00:00
|
|
|
else
|
|
|
|
rv = m_prefs->SetCharPref(fullPrefName, val);
|
|
|
|
|
|
|
|
PR_FREEIF(defaultVal);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-12-03 00:10:00 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::SetUnicharValue(const char *prefname,
|
|
|
|
const PRUnichar * val)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-01-26 00:54:15 +00:00
|
|
|
nsCAutoString fullPrefName;
|
|
|
|
getPrefName(m_serverKey, prefname, fullPrefName);
|
1999-12-03 00:10:00 +00:00
|
|
|
|
|
|
|
if (!val) {
|
|
|
|
m_prefs->ClearUserPref(fullPrefName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUnichar *defaultVal=nsnull;
|
|
|
|
rv = getDefaultUnicharPref(prefname, &defaultVal);
|
1999-12-07 08:48:52 +00:00
|
|
|
if (defaultVal && NS_SUCCEEDED(rv) &&
|
1999-12-03 00:10:00 +00:00
|
|
|
nsCRT::strcmp(defaultVal, val) == 0)
|
|
|
|
m_prefs->ClearUserPref(fullPrefName);
|
|
|
|
else
|
|
|
|
rv = m_prefs->SetUnicharPref(fullPrefName, val);
|
|
|
|
|
|
|
|
PR_FREEIF(defaultVal);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-06-14 22:53:09 +00:00
|
|
|
// pretty name is the display name to show to the user
|
|
|
|
NS_IMETHODIMP
|
1999-08-10 04:39:22 +00:00
|
|
|
nsMsgIncomingServer::GetPrettyName(PRUnichar **retval) {
|
1999-06-14 22:53:09 +00:00
|
|
|
|
1999-12-03 00:10:00 +00:00
|
|
|
nsXPIDLString val;
|
|
|
|
nsresult rv = GetUnicharValue("name", getter_Copies(val));
|
1999-06-14 22:53:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-12-03 00:10:00 +00:00
|
|
|
nsAutoString prettyName(val);
|
1999-08-10 04:39:22 +00:00
|
|
|
|
|
|
|
// if there's no name, then just return the hostname
|
1999-12-03 00:10:00 +00:00
|
|
|
if (prettyName.IsEmpty()) {
|
1999-08-10 04:39:22 +00:00
|
|
|
|
|
|
|
nsXPIDLCString username;
|
|
|
|
rv = GetUsername(getter_Copies(username));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if ((const char*)username &&
|
|
|
|
PL_strcmp((const char*)username, "")!=0) {
|
2000-04-22 08:43:34 +00:00
|
|
|
prettyName.AssignWithConversion(username);
|
|
|
|
prettyName.AppendWithConversion(" on ");
|
1999-08-10 04:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXPIDLCString hostname;
|
|
|
|
rv = GetHostName(getter_Copies(hostname));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
|
2000-04-22 08:43:34 +00:00
|
|
|
prettyName.AppendWithConversion(hostname);
|
1999-08-10 04:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*retval = prettyName.ToNewUnicode();
|
1999-06-14 22:53:09 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-14 09:01:39 +00:00
|
|
|
nsMsgIncomingServer::SetPrettyName(const PRUnichar *value)
|
|
|
|
{
|
|
|
|
SetUnicharValue("name", value);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFolder> rootFolder;
|
|
|
|
GetRootFolder(getter_AddRefs(rootFolder));
|
|
|
|
|
|
|
|
if (rootFolder)
|
|
|
|
rootFolder->SetPrettyName(value);
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-09-09 04:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::ToString(PRUnichar** aResult) {
|
2000-04-22 08:43:34 +00:00
|
|
|
nsString servername; servername.AssignWithConversion("[nsIMsgIncomingServer: ");
|
|
|
|
servername.AppendWithConversion(m_serverKey);
|
|
|
|
servername.AppendWithConversion("]");
|
1999-09-09 04:11:38 +00:00
|
|
|
|
|
|
|
*aResult = servername.ToNewUnicode();
|
|
|
|
NS_ASSERTION(*aResult, "no server name!");
|
|
|
|
return NS_OK;
|
1999-06-14 22:53:09 +00:00
|
|
|
}
|
1999-09-09 04:11:38 +00:00
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
|
1999-08-31 04:39:43 +00:00
|
|
|
NS_IMETHODIMP nsMsgIncomingServer::SetPassword(const char * aPassword)
|
|
|
|
{
|
|
|
|
m_password = aPassword;
|
2000-03-24 08:26:32 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
PRBool rememberPassword = PR_FALSE;
|
|
|
|
|
|
|
|
rv = GetRememberPassword(&rememberPassword);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (rememberPassword) {
|
|
|
|
rv = StorePassword();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-08-31 04:39:43 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-22 02:21:18 +00:00
|
|
|
NS_IMETHODIMP nsMsgIncomingServer::GetPassword(char ** aPassword)
|
1999-08-31 04:39:43 +00:00
|
|
|
{
|
2000-02-01 07:14:54 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aPassword);
|
|
|
|
|
1999-09-22 02:21:18 +00:00
|
|
|
*aPassword = m_password.ToNewCString();
|
2000-02-01 07:14:54 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-09-22 02:21:18 +00:00
|
|
|
}
|
1999-08-31 04:39:43 +00:00
|
|
|
|
2000-04-13 02:59:01 +00:00
|
|
|
NS_IMETHODIMP nsMsgIncomingServer::GetServerRequiresPasswordForBiff(PRBool *_retval)
|
|
|
|
{
|
|
|
|
if (!_retval) return NS_ERROR_NULL_POINTER;
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-22 02:21:18 +00:00
|
|
|
NS_IMETHODIMP
|
2000-01-29 15:53:14 +00:00
|
|
|
nsMsgIncomingServer::GetPasswordWithUI(const PRUnichar * aPromptMessage, const
|
|
|
|
PRUnichar *aPromptTitle,
|
|
|
|
nsIMsgWindow* aMsgWindow,
|
2000-04-26 22:31:59 +00:00
|
|
|
PRBool *okayValue,
|
2000-01-29 15:53:14 +00:00
|
|
|
char **aPassword)
|
1999-09-22 06:02:46 +00:00
|
|
|
{
|
2000-02-01 07:14:54 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-08-31 04:39:43 +00:00
|
|
|
|
2000-02-01 07:14:54 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aPassword);
|
2000-04-26 22:31:59 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(okayValue);
|
1999-09-22 02:21:18 +00:00
|
|
|
|
|
|
|
if (m_password.IsEmpty()) {
|
2000-02-29 21:01:53 +00:00
|
|
|
nsCOMPtr<nsINetPrompt> dialog;
|
2000-02-12 00:52:53 +00:00
|
|
|
// aMsgWindow is required if we need to prompt
|
2000-02-29 21:01:53 +00:00
|
|
|
if (aMsgWindow)
|
|
|
|
{
|
|
|
|
// prompt the user for the password
|
|
|
|
nsCOMPtr<nsIWebShell> webShell;
|
|
|
|
rv = aMsgWindow->GetRootWebShell(getter_AddRefs(webShell));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
// get top level window
|
|
|
|
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
|
|
|
|
rv = webShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
dialog = do_QueryInterface( topLevelWindow, &rv );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID,
|
|
|
|
&rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXULWindow> hiddenWindow;
|
|
|
|
rv = appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
dialog = do_QueryInterface(hiddenWindow, &rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv) && dialog)
|
1999-08-31 04:39:43 +00:00
|
|
|
{
|
2000-02-01 07:14:54 +00:00
|
|
|
nsXPIDLString uniPassword;
|
2000-01-29 15:53:14 +00:00
|
|
|
nsXPIDLCString serverUri;
|
|
|
|
rv = GetServerURI(getter_Copies(serverUri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-04-26 22:31:59 +00:00
|
|
|
rv = dialog->PromptPassword(serverUri, PR_FALSE, aPromptTitle, aPromptMessage, getter_Copies(uniPassword), okayValue);
|
2000-02-03 05:01:42 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-31 04:39:43 +00:00
|
|
|
|
2000-04-26 22:31:59 +00:00
|
|
|
if (!*okayValue) // if the user pressed cancel, just return NULL;
|
1999-08-31 04:39:43 +00:00
|
|
|
{
|
|
|
|
*aPassword = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we got a password back...so remember it
|
2000-04-22 08:43:34 +00:00
|
|
|
nsCString aCStr; aCStr.AssignWithConversion(uniPassword);
|
1999-08-31 04:39:43 +00:00
|
|
|
|
2000-02-01 07:14:54 +00:00
|
|
|
rv = SetPassword((const char *) aCStr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-31 04:39:43 +00:00
|
|
|
} // if we got a prompt dialog
|
|
|
|
} // if the password is empty
|
|
|
|
|
2000-02-01 07:14:54 +00:00
|
|
|
rv = GetPassword(aPassword);
|
1999-08-31 04:39:43 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-03-24 08:26:32 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::StorePassword()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsXPIDLCString pwd;
|
|
|
|
rv = GetPassword(getter_Copies(pwd));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIWalletService, walletservice, kWalletServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsXPIDLCString serverUri;
|
|
|
|
rv = GetServerURI(getter_Copies(serverUri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-04-22 08:43:34 +00:00
|
|
|
nsAutoString password; password.AssignWithConversion((const char *)pwd);
|
2000-03-24 08:26:32 +00:00
|
|
|
rv = walletservice->SI_StorePassword((const char *)serverUri, PR_FALSE, nsnull, password.GetUnicode());
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-02-03 05:01:42 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::ForgetPassword()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIWalletService, walletservice, kWalletServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
|
|
|
|
nsXPIDLCString serverUri;
|
|
|
|
rv = GetServerURI(getter_Copies(serverUri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = SetPassword("");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
|
2000-02-03 06:43:12 +00:00
|
|
|
rv = walletservice->SI_RemoveUser((const char *)serverUri, PR_FALSE, nsnull);
|
2000-02-03 05:01:42 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-14 09:03:40 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::SetDefaultLocalPath(nsIFileSpec *aDefaultLocalPath)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsXPIDLCString type;
|
|
|
|
GetType(getter_Copies(type));
|
|
|
|
|
|
|
|
nsCAutoString progid(NS_MSGPROTOCOLINFO_PROGID_PREFIX);
|
2000-03-26 12:14:14 +00:00
|
|
|
progid.Append(type);
|
1999-09-14 09:03:40 +00:00
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIMsgProtocolInfo, protocolInfo, progid, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = protocolInfo->SetDefaultLocalPath(aDefaultLocalPath);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-09 04:11:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::GetLocalPath(nsIFileSpec **aLocalPath)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-09-15 00:04:47 +00:00
|
|
|
|
|
|
|
// if the local path has already been set, use it
|
1999-09-09 04:11:38 +00:00
|
|
|
rv = GetFileValue("directory", aLocalPath);
|
|
|
|
if (NS_SUCCEEDED(rv) && *aLocalPath) return rv;
|
|
|
|
|
1999-09-15 00:04:47 +00:00
|
|
|
// otherwise, create the path using. note we are using the
|
2000-04-01 09:37:24 +00:00
|
|
|
// hostname, unless that directory exists.
|
|
|
|
// this should prevent all collisions.
|
1999-09-09 04:11:38 +00:00
|
|
|
nsXPIDLCString type;
|
|
|
|
GetType(getter_Copies(type));
|
|
|
|
|
1999-09-14 00:36:37 +00:00
|
|
|
nsCAutoString progid(NS_MSGPROTOCOLINFO_PROGID_PREFIX);
|
2000-03-26 12:14:14 +00:00
|
|
|
progid.Append(type);
|
1999-09-14 00:36:37 +00:00
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIMsgProtocolInfo, protocolInfo, progid, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-09 04:11:38 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFileSpec> path;
|
1999-09-14 00:36:37 +00:00
|
|
|
rv = protocolInfo->GetDefaultLocalPath(getter_AddRefs(path));
|
1999-09-09 04:11:38 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
path->CreateDir();
|
|
|
|
|
2000-04-01 09:37:24 +00:00
|
|
|
// set the leaf name to "dummy", and then call MakeUnique with a suggested leaf name
|
|
|
|
rv = path->AppendRelativeUnixPath("dummy");
|
1999-09-15 00:04:47 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-04-01 09:37:24 +00:00
|
|
|
nsXPIDLCString hostname;
|
|
|
|
rv = GetHostName(getter_Copies(hostname));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = path->MakeUniqueWithSuggestedName((const char *)hostname);
|
1999-09-15 00:04:47 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-04-01 09:37:24 +00:00
|
|
|
|
1999-09-15 00:04:47 +00:00
|
|
|
rv = SetLocalPath(path);
|
1999-09-09 04:11:38 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-09 21:17:32 +00:00
|
|
|
|
1999-09-09 04:11:38 +00:00
|
|
|
*aLocalPath = path;
|
|
|
|
NS_ADDREF(*aLocalPath);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::SetLocalPath(nsIFileSpec *spec)
|
|
|
|
{
|
|
|
|
if (spec) {
|
|
|
|
spec->CreateDir();
|
|
|
|
return SetFileValue("directory", spec);
|
|
|
|
}
|
1999-09-09 21:17:32 +00:00
|
|
|
else {
|
1999-09-14 09:03:40 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-09-09 21:17:32 +00:00
|
|
|
}
|
1999-09-09 04:11:38 +00:00
|
|
|
}
|
|
|
|
|
1999-09-22 02:21:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::SetRememberPassword(PRBool value)
|
|
|
|
{
|
2000-03-24 08:26:32 +00:00
|
|
|
if (!value) {
|
2000-02-12 00:52:53 +00:00
|
|
|
ForgetPassword();
|
2000-03-24 08:26:32 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
StorePassword();
|
|
|
|
}
|
2000-02-16 07:43:18 +00:00
|
|
|
return SetBoolValue("remember_password", value);
|
1999-09-22 02:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::GetRememberPassword(PRBool* value)
|
|
|
|
{
|
2000-02-12 00:52:53 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(value);
|
|
|
|
|
2000-02-16 07:43:18 +00:00
|
|
|
return GetBoolValue("remember_password", value);
|
1999-09-22 02:21:18 +00:00
|
|
|
}
|
|
|
|
|
1999-10-28 20:22:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::GetLocalStoreType(char **aResult)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("nsMsgIncomingServer superclass not implementing GetLocalStoreType!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2000-01-26 04:11:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::Equals(nsIMsgIncomingServer *server, PRBool *_retval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(server);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
nsXPIDLCString key1;
|
|
|
|
nsXPIDLCString key2;
|
|
|
|
|
|
|
|
rv = GetKey(getter_Copies(key1));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = server->GetKey(getter_Copies(key2));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// compare the server keys
|
|
|
|
if (PL_strcmp((const char *)key1,(const char *)key2)) {
|
2000-03-15 07:12:59 +00:00
|
|
|
#ifdef DEBUG_MSGINCOMING_SERVER
|
2000-01-26 06:30:35 +00:00
|
|
|
printf("%s and %s are different, servers are not the same\n",(const char *)key1,(const char *)key2);
|
2000-03-15 07:12:59 +00:00
|
|
|
#endif /* DEBUG_MSGINCOMING_SERVER */
|
2000-01-26 04:11:14 +00:00
|
|
|
*_retval = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
2000-03-15 07:12:59 +00:00
|
|
|
#ifdef DEBUG_MSGINCOMING_SERVER
|
2000-01-26 06:30:35 +00:00
|
|
|
printf("%s and %s are equal, servers are the same\n",(const char *)key1,(const char *)key2);
|
2000-03-15 07:12:59 +00:00
|
|
|
#endif /* DEBUG_MSGINCOMING_SERVER */
|
2000-01-26 04:11:14 +00:00
|
|
|
*_retval = PR_TRUE;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-02-11 00:55:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::ClearAllValues()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCAutoString rootPref("mail.server.");
|
|
|
|
rootPref += m_serverKey;
|
|
|
|
|
|
|
|
rv = m_prefs->EnumerateChildren(rootPref, clearPrefEnum, (void *)m_prefs);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-03-15 07:12:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::RemoveFiles()
|
|
|
|
{
|
|
|
|
// this is not ready for prime time. the problem is that if files are in use, they won't
|
|
|
|
// get deleted properly. for example, when we get here, we may have .msf files in open
|
|
|
|
// and in use. I need to think about this some more.
|
|
|
|
#if 0
|
|
|
|
#ifdef DEBUG_MSGINCOMING_SERVER
|
|
|
|
printf("remove files for %s\n", (const char *)m_serverKey);
|
|
|
|
#endif /* DEBUG_MSGINCOMING_SERVER */
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr <nsIFileSpec> localPath;
|
|
|
|
rv = GetLocalPath(getter_AddRefs(localPath));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!localPath) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRBool exists = PR_FALSE;
|
|
|
|
rv = localPath->Exists(&exists);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// if it doesn't exist, that's ok.
|
|
|
|
if (!exists) return NS_OK;
|
|
|
|
|
|
|
|
rv = localPath->Delete(PR_TRUE /* recursive */);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// now check if it really gone
|
|
|
|
rv = localPath->Exists(&exists);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// if it still exists, something failed.
|
|
|
|
if (exists) return NS_ERROR_FAILURE;
|
|
|
|
#endif /* 0 */
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-11 00:55:54 +00:00
|
|
|
void
|
|
|
|
nsMsgIncomingServer::clearPrefEnum(const char *aPref, void *aClosure)
|
|
|
|
{
|
|
|
|
nsIPref *prefs = (nsIPref *)aClosure;
|
|
|
|
prefs->ClearUserPref(aPref);
|
|
|
|
}
|
|
|
|
|
2000-03-28 04:58:05 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::GetFilterList(nsIMsgFilterList **aResult)
|
|
|
|
{
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!mFilterList) {
|
|
|
|
nsCOMPtr<nsIFolder> folder;
|
|
|
|
rv = GetRootFolder(getter_AddRefs(folder));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMsgFolder> msgFolder(do_QueryInterface(folder, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFileSpec> thisFolder;
|
|
|
|
rv = msgFolder->GetPath(getter_AddRefs(thisFolder));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2000-05-12 09:15:05 +00:00
|
|
|
rv = thisFolder->GetFileSpec(&mFilterFile);
|
2000-03-28 04:58:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2000-05-12 09:15:05 +00:00
|
|
|
mFilterFile += "rules.dat";
|
2000-03-28 04:58:05 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIMsgFilterService> filterService =
|
|
|
|
do_GetService(kMsgFilterServiceCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2000-05-12 09:15:05 +00:00
|
|
|
rv = filterService->OpenFilterList(&mFilterFile, msgFolder, getter_AddRefs(mFilterList));
|
2000-03-28 04:58:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = mFilterList;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
2000-03-30 02:49:10 +00:00
|
|
|
return NS_OK;
|
2000-03-28 04:58:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-05-03 21:42:31 +00:00
|
|
|
// if the user has a : appended, then
|
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::SetHostName(const char *aHostname)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (PL_strchr(aHostname, ':')) {
|
|
|
|
nsCAutoString newHostname(aHostname);
|
|
|
|
PRInt32 colonPos = newHostname.FindChar(':');
|
|
|
|
|
|
|
|
nsCAutoString portString;
|
|
|
|
newHostname.Right(portString, newHostname.Length() - colonPos);
|
|
|
|
|
|
|
|
newHostname.Truncate(colonPos);
|
|
|
|
|
|
|
|
PRInt32 err;
|
|
|
|
PRInt32 port = portString.ToInteger(&err);
|
|
|
|
if (!err) SetPort(port);
|
|
|
|
|
|
|
|
rv = SetCharValue("hostname", (const char*)newHostname);
|
|
|
|
} else {
|
|
|
|
rv = SetCharValue("hostname", aHostname);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::GetHostName(char **aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = GetCharValue("hostname", aResult);
|
|
|
|
if (PL_strchr(*aResult, ':')) {
|
|
|
|
// gack, we need to reformat the hostname - SetHostName will do that
|
|
|
|
SetHostName(*aResult);
|
|
|
|
rv = GetCharValue("hostname", aResult);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2000-02-11 00:55:54 +00:00
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
// use the convenience macros to implement the accessors
|
2000-05-03 21:42:31 +00:00
|
|
|
//NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, HostName, "hostname");
|
1999-10-26 23:34:30 +00:00
|
|
|
NS_IMPL_SERVERPREF_INT(nsMsgIncomingServer, Port, "port");
|
1999-05-27 05:36:10 +00:00
|
|
|
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, Username, "userName");
|
1999-08-31 04:39:43 +00:00
|
|
|
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, PrefPassword, "password");
|
1999-04-10 20:55:30 +00:00
|
|
|
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer, DoBiff, "check_new_mail");
|
2000-01-19 01:16:35 +00:00
|
|
|
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer, IsSecure, "isSecure");
|
1999-04-10 20:55:30 +00:00
|
|
|
NS_IMPL_SERVERPREF_INT(nsMsgIncomingServer, BiffMinutes, "check_time");
|
1999-07-13 19:23:40 +00:00
|
|
|
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, Type, "type");
|
2000-01-11 20:03:51 +00:00
|
|
|
// in 4.x, this was "mail.pop3_gets_new_mail" for pop and
|
|
|
|
// "mail.imap.new_mail_get_headers" for imap (it was global)
|
|
|
|
// in 5.0, this will be per server, and it will be "download_on_biff"
|
1999-04-16 00:36:52 +00:00
|
|
|
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer, DownloadOnBiff, "download_on_biff");
|
2000-01-15 03:06:39 +00:00
|
|
|
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer, Valid, "valid");
|
2000-02-15 06:57:45 +00:00
|
|
|
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, RedirectorType, "redirector_type");
|