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
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "nsIPref.h"
|
1999-07-17 03:26:24 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIMsgFolder.h"
|
|
|
|
#include "nsIMsgFolderCache.h"
|
|
|
|
#include "nsIMsgFolderCacheElement.h"
|
1999-08-31 04:39:43 +00:00
|
|
|
#include "nsINetSupportDialogService.h"
|
|
|
|
#include "nsIPrompt.h"
|
1999-08-10 04:39:22 +00:00
|
|
|
#include "nsXPIDLString.h"
|
1999-08-30 22:12:20 +00:00
|
|
|
#include "nsIRDFService.h"
|
|
|
|
#include "nsRDFCID.h"
|
1999-04-10 20:55:30 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
1999-08-31 04:39:43 +00:00
|
|
|
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
1999-08-30 22:12:20 +00:00
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
1999-04-10 20:55:30 +00:00
|
|
|
|
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-04-06 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMsgIncomingServer::~nsMsgIncomingServer()
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
1999-09-09 04:11:38 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsMsgIncomingServer, nsIMsgIncomingServer)
|
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
|
|
|
|
nsMsgIncomingServer::SetKey(char * serverKey)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// in order to actually make use of the key, we need the prefs
|
|
|
|
if (!m_prefs)
|
|
|
|
rv = nsServiceManager::GetService(kPrefServiceCID,
|
1999-07-01 00:16:39 +00:00
|
|
|
nsCOMTypeInfo<nsIPref>::GetIID(),
|
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;
|
|
|
|
}
|
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-09 04:11:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::GetServerURI(char **)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-04-06 22:34:19 +00:00
|
|
|
char *
|
|
|
|
nsMsgIncomingServer::getPrefName(const char *serverKey,
|
1999-04-10 20:55:30 +00:00
|
|
|
const char *fullPrefName)
|
1999-04-06 22:34:19 +00:00
|
|
|
{
|
1999-04-10 20:55:30 +00:00
|
|
|
return PR_smprintf("mail.server.%s.%s", serverKey, fullPrefName);
|
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
|
|
|
|
char *
|
|
|
|
nsMsgIncomingServer::getDefaultPrefName(const char *fullPrefName)
|
1999-04-06 22:34:19 +00:00
|
|
|
{
|
1999-04-10 20:55:30 +00:00
|
|
|
return PR_smprintf("mail.server.default.%s", fullPrefName);
|
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
|
|
|
{
|
1999-04-10 20:55:30 +00:00
|
|
|
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
|
|
|
nsresult rv = m_prefs->GetBoolPref(fullPrefName, val);
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
1999-07-01 21:56:54 +00:00
|
|
|
char *fullPrefName = getDefaultPrefName(prefname);
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult rv = m_prefs->GetBoolPref(fullPrefName, val);
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
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;
|
|
|
|
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
1999-04-10 20:55:30 +00:00
|
|
|
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
|
|
|
nsresult rv = m_prefs->GetIntPref(fullPrefName, val);
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
|
|
|
nsresult rv = m_prefs->GetFilePref(fullPrefName, spec);
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::SetFileValue(const char* prefname,
|
|
|
|
nsIFileSpec *spec)
|
|
|
|
{
|
|
|
|
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
|
|
|
nsresult rv = m_prefs->SetFilePref(fullPrefName, spec, PR_FALSE);
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::getDefaultIntPref(const char *prefname,
|
|
|
|
PRInt32 *val) {
|
|
|
|
|
1999-07-01 21:56:54 +00:00
|
|
|
char *fullPrefName = getDefaultPrefName(prefname);
|
1999-04-10 20:55:30 +00:00
|
|
|
nsresult rv = m_prefs->GetIntPref(fullPrefName, val);
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
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;
|
|
|
|
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
|
|
|
nsresult rv = m_prefs->CopyCharPref(fullPrefName, val);
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = getDefaultCharPref(prefname, val);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-10 21:58:09 +00:00
|
|
|
nsresult
|
|
|
|
nsMsgIncomingServer::getDefaultCharPref(const char *prefname,
|
|
|
|
char **val) {
|
|
|
|
|
1999-07-01 21:56:54 +00:00
|
|
|
char *fullPrefName = getDefaultPrefName(prefname);
|
1999-04-10 21:58:09 +00:00
|
|
|
nsresult rv = m_prefs->CopyCharPref(fullPrefName, val);
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
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-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;
|
|
|
|
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
|
|
|
|
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);
|
|
|
|
PR_Free(fullPrefName);
|
|
|
|
|
|
|
|
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-08-10 04:39:22 +00:00
|
|
|
char *val=nsnull;
|
1999-09-09 04:11:38 +00:00
|
|
|
nsresult rv = GetCharValue("name", &val);
|
1999-06-14 22:53:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-08-10 04:39:22 +00:00
|
|
|
nsString prettyName;
|
|
|
|
|
|
|
|
// if there's no name, then just return the hostname
|
|
|
|
if (val) {
|
|
|
|
prettyName = val;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
nsXPIDLCString username;
|
|
|
|
rv = GetUsername(getter_Copies(username));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if ((const char*)username &&
|
|
|
|
PL_strcmp((const char*)username, "")!=0) {
|
|
|
|
prettyName = username;
|
|
|
|
prettyName += " on ";
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXPIDLCString hostname;
|
|
|
|
rv = GetHostName(getter_Copies(hostname));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
|
|
|
|
prettyName += hostname;
|
|
|
|
}
|
|
|
|
|
|
|
|
*retval = prettyName.ToNewUnicode();
|
1999-06-14 22:53:09 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-10 04:39:22 +00:00
|
|
|
nsMsgIncomingServer::SetPrettyName(PRUnichar *value) {
|
|
|
|
// this is lossy. Not sure what to do.
|
|
|
|
nsCString str(value);
|
1999-09-09 04:11:38 +00:00
|
|
|
return SetCharValue("name", str.GetBuffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::ToString(PRUnichar** aResult) {
|
|
|
|
nsString servername("[nsIMsgIncomingServer: ");
|
|
|
|
servername += m_serverKey;
|
|
|
|
servername += "]";
|
|
|
|
|
|
|
|
*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)
|
|
|
|
{
|
|
|
|
// if remember password is turned on, write the password to preferences
|
|
|
|
// otherwise, just set the password so we remember it for the rest of the current
|
|
|
|
// session.
|
|
|
|
|
|
|
|
PRBool rememberPassword = PR_FALSE;
|
|
|
|
GetRememberPassword(&rememberPassword);
|
|
|
|
|
|
|
|
if (rememberPassword)
|
|
|
|
{
|
|
|
|
SetPrefPassword((char *) aPassword);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_password = aPassword;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgIncomingServer::GetPassword(PRBool aWithUI, char ** aPassword)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool rememberPassword = PR_FALSE;
|
|
|
|
// okay, here's the scoop for this messs...
|
|
|
|
// (1) if we have a password already, go ahead and use it!
|
|
|
|
// (2) if remember password is turned on, try reading in from the prefs and if we have one, go ahead
|
|
|
|
// and use it
|
|
|
|
// (3) otherwise prompt the user for a password and then remember that password in the server
|
|
|
|
|
|
|
|
if (m_password.IsEmpty())
|
|
|
|
{
|
|
|
|
|
|
|
|
// case (2)
|
|
|
|
GetRememberPassword(&rememberPassword);
|
|
|
|
if (rememberPassword)
|
|
|
|
{
|
|
|
|
nsXPIDLCString password;
|
|
|
|
GetPrefPassword(getter_Copies(password));
|
|
|
|
m_password = password;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we still don't have a password fall to case (3)
|
|
|
|
if (m_password.IsEmpty() && aWithUI)
|
|
|
|
{
|
|
|
|
|
|
|
|
// case (3) prompt the user for the password
|
|
|
|
NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
PRUnichar * uniPassword;
|
|
|
|
PRBool okayValue = PR_TRUE;
|
|
|
|
char * promptText = nsnull;
|
|
|
|
nsXPIDLCString hostName;
|
|
|
|
nsXPIDLCString userName;
|
|
|
|
|
|
|
|
GetHostName(getter_Copies(hostName));
|
|
|
|
GetUsername(getter_Copies(userName));
|
|
|
|
// mscott - this is just a temporary hack using the raw string..this needs to be pushed into
|
|
|
|
// a string bundle!!!!!
|
|
|
|
if (hostName)
|
|
|
|
promptText = PR_smprintf("Enter your password for %s@%s.", (const char *) userName, (const char *) hostName);
|
|
|
|
else
|
|
|
|
promptText = PL_strdup("Enter your password here: ");
|
|
|
|
|
|
|
|
dialog->PromptPassword(nsAutoString(promptText).GetUnicode(), &uniPassword, &okayValue);
|
|
|
|
PR_FREEIF(promptText);
|
|
|
|
|
|
|
|
if (!okayValue) // if the user pressed cancel, just return NULL;
|
|
|
|
{
|
|
|
|
*aPassword = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we got a password back...so remember it
|
|
|
|
nsCString aCStr(uniPassword);
|
|
|
|
|
|
|
|
SetPassword((const char *) aCStr);
|
|
|
|
} // if we got a prompt dialog
|
|
|
|
} // if the password is empty
|
|
|
|
|
|
|
|
*aPassword = m_password.ToNewCString();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-09 04:11:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::GetLocalPath(nsIFileSpec **aLocalPath)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = GetFileValue("directory", aLocalPath);
|
|
|
|
if (NS_SUCCEEDED(rv) && *aLocalPath) return rv;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsXPIDLCString type;
|
|
|
|
GetType(getter_Copies(type));
|
|
|
|
|
|
|
|
nsCString pathPref("mail.root.");
|
|
|
|
pathPref += type;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFileSpec> path;
|
|
|
|
rv = m_prefs->GetFilePref(pathPref, getter_AddRefs(path));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
path->CreateDir();
|
|
|
|
|
|
|
|
nsXPIDLCString hostname;
|
|
|
|
rv = GetHostName(getter_Copies(hostname));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
path->AppendRelativeUnixPath(hostname);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
SetLocalPath(path);
|
|
|
|
|
|
|
|
*aLocalPath = path;
|
|
|
|
NS_ADDREF(*aLocalPath);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMsgIncomingServer::SetLocalPath(nsIFileSpec *spec)
|
|
|
|
{
|
|
|
|
if (spec) {
|
|
|
|
spec->CreateDir();
|
|
|
|
return SetFileValue("directory", spec);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-10 20:55:30 +00:00
|
|
|
// use the convenience macros to implement the accessors
|
|
|
|
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, HostName, "hostname");
|
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");
|
|
|
|
NS_IMPL_SERVERPREF_INT(nsMsgIncomingServer, BiffMinutes, "check_time");
|
1999-04-16 00:36:52 +00:00
|
|
|
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer, RememberPassword, "remember_password");
|
1999-07-13 19:23:40 +00:00
|
|
|
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, Type, "type");
|
1999-04-16 00:36:52 +00:00
|
|
|
|
|
|
|
/* what was this called in 4.x? */
|
1999-06-28 21:56:33 +00:00
|
|
|
// pref("mail.pop3_gets_new_mail", true);
|
|
|
|
|
1999-04-16 00:36:52 +00:00
|
|
|
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer, DownloadOnBiff, "download_on_biff");
|