Bug 41929 Allow multiple accounts with the same server and username if they have different port numbers p=kteuscher@myrealbox.com r=bienvenu sr=me

This commit is contained in:
neil%parkwaycc.co.uk 2004-08-18 23:11:28 +00:00
Родитель 4b4f94e6b6
Коммит fbcddd3920
13 изменённых файлов: 670 добавлений и 640 удалений

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

@ -370,7 +370,7 @@ function checkUserServerChanges(showAlert) {
// If something is changed then check if the new user/host already exists.
if ( (oldUser != newUser) || (oldHost != newHost) ) {
var newServer = accountManager.findRealServer(newUser, newHost, newType);
var newServer = accountManager.findRealServer(newUser, newHost, newType, 0);
if (newServer) {
if (showAlert) {
var alertText = gPrefsBundle.getString("modifiedAccountExists");

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

@ -720,7 +720,7 @@ function AccountExists(userName,hostName,serverType)
var accountExists = false;
var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
try {
var server = accountManager.findRealServer(userName,hostName,serverType);
var server = accountManager.findRealServer(userName,hostName,serverType,0);
if (server) {
accountExists = true;
}

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

@ -47,7 +47,7 @@
interface nsIMsgFolderCache;
interface nsIFolderListener;
[scriptable, uuid(6ed2cc00-e623-11d2-b7fc-00805f05ffa5)]
[scriptable, uuid(0dc74b96-c2fc-4ce0-baed-c6f03c69026e)]
interface nsIMsgAccountManager : nsISupports {
nsIMsgAccount createAccount();
@ -124,12 +124,21 @@ interface nsIMsgAccountManager : nsISupports {
nsIMsgIncomingServer
FindServer(in string userName, in string hostname, in string type);
/*
* search for the server with the given uri
* an analog to FindServer()
* The boolean flag selects whether we compare input against the
* 'realhostname' and 'realuserName' pref settings.
*/
nsIMsgIncomingServer
findServerByURI(in nsIURI aURI, in boolean aRealFlag);
/*
* Same as FindServer() except it compares the input values against
* 'realhostname' and 'realuserName' pref settings.
*/
nsIMsgIncomingServer
findRealServer(in string userName, in string hostname, in string type);
findRealServer(in string userName, in string hostname, in string type, in long port );
/**
* find the index of this server in the (ordered) list of accounts
@ -210,7 +219,7 @@ interface nsIMsgAccountManager : nsISupports {
interface nsIMsgAccountManagerExtension : nsISupports
{
readonly attribute string name; // examples: mdn
boolean showPanel(in nsIMsgIncomingServer server);
readonly attribute string chromePackageName; // example: messenger, chrome://messenger/content/am-mdn.xul and chrome://messenger/locale/am-mdn.properties
boolean showPanel(in nsIMsgIncomingServer server);
readonly attribute string chromePackageName; // example: messenger, chrome://messenger/content/am-mdn.xul and chrome://messenger/locale/am-mdn.properties
};

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

@ -58,6 +58,7 @@
#include "nsXPIDLString.h"
#include "nsUnicharUtils.h"
#include "nscore.h"
#include "nsEscape.h"
#include "nsCRT.h" // for nsCRT::strtok
#include "prprf.h"
#include "nsIMsgFolderCache.h"
@ -116,6 +117,7 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
typedef struct _findServerEntry {
const char *hostname;
const char *username;
PRInt32 port;
const char *type;
PRBool useRealSetting;
nsIMsgIncomingServer *server;
@ -171,7 +173,7 @@ nsMsgAccountManager::~nsMsgAccountManager()
//Don't remove from Observer service in Shutdown because Shutdown also gets called
//from xpcom shutdown observer. And we don't want to remove from the service in that case.
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1", &rv);
do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_SUCCEEDED(rv))
{
observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
@ -211,7 +213,7 @@ nsresult nsMsgAccountManager::Shutdown()
nsresult rv;
SaveVirtualFolders();
nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
if (msgDBService)
{
@ -303,7 +305,7 @@ NS_IMETHODIMP nsMsgAccountManager::Observe(nsISupports *aSubject, const char *aT
Shutdown();
return NS_OK;
}
return NS_OK;
}
@ -398,8 +400,7 @@ nsMsgAccountManager::GetIdentity(const char* key,
nsCOMPtr<nsIMsgIdentity> identity = do_QueryInterface(idsupports, &rv);
if (NS_SUCCEEDED(rv)) {
*_retval = identity;
NS_ADDREF(*_retval);
NS_ADDREF(*_retval = identity);
return NS_OK;
}
@ -434,8 +435,7 @@ nsMsgAccountManager::createKeyedIdentity(const char* key,
NS_ADDREF(idsupports);
m_identities.Put(&hashKey, (void *)idsupports);
*aIdentity = identity;
NS_ADDREF(*aIdentity);
NS_ADDREF(*aIdentity = identity);
return NS_OK;
}
@ -646,7 +646,7 @@ nsMsgAccountManager::RemoveAccount(nsIMsgAccount *aAccount)
NS_ENSURE_SUCCESS(rv,rv);
if (!nsCRT::strcmp((const char *)serverKey,(const char *)cachedServerKey)) {
rv = SetLastServerFound(nsnull,"","","");
rv = SetLastServerFound(nsnull,"","",0,"");
NS_ENSURE_SUCCESS(rv,rv);
}
}
@ -925,19 +925,19 @@ nsMsgAccountManager::hashUnloadServer(nsHashKey *aKey, void *aData,
do_QueryInterface((nsISupports*)aData, &rv);
if (NS_FAILED(rv)) return PR_TRUE;
nsMsgAccountManager *accountManager = (nsMsgAccountManager*)closure;
accountManager->NotifyServerUnloaded(server);
nsMsgAccountManager *accountManager = (nsMsgAccountManager*)closure;
accountManager->NotifyServerUnloaded(server);
nsCOMPtr<nsIMsgFolder> rootFolder;
rv = server->GetRootFolder(getter_AddRefs(rootFolder));
nsCOMPtr<nsIMsgFolder> rootFolder;
rv = server->GetRootFolder(getter_AddRefs(rootFolder));
accountManager->mFolderListeners->EnumerateForwards(removeListenerFromFolder,
(void *)(nsIMsgFolder*)rootFolder);
if(NS_SUCCEEDED(rv))
rootFolder->Shutdown(PR_TRUE);
if(NS_SUCCEEDED(rv))
rootFolder->Shutdown(PR_TRUE);
return PR_TRUE;
return PR_TRUE;
}
@ -975,7 +975,7 @@ NS_IMETHODIMP nsMsgAccountManager::GetFolderCache(nsIMsgFolderCache* *aFolderCac
NS_GET_IID(nsIMsgFolderCache),
getter_AddRefs(m_msgFolderCache));
if (NS_FAILED(rv))
return rv;
return rv;
nsCOMPtr<nsIFile> cacheFile;
nsCOMPtr <nsIFileSpec> cacheFileSpec;
@ -1002,10 +1002,10 @@ PRBool nsMsgAccountManager::writeFolderCache(nsHashKey *aKey, void *aData,
void *closure)
{
nsIMsgIncomingServer *server = (nsIMsgIncomingServer*)aData;
nsIMsgFolderCache *folderCache = (nsIMsgFolderCache *)closure;
nsIMsgFolderCache *folderCache = (nsIMsgFolderCache *)closure;
server->WriteToFolderCache(folderCache);
return PR_TRUE;
server->WriteToFolderCache(folderCache);
return PR_TRUE;
}
// enumeration for empty trash on exit
@ -1162,8 +1162,7 @@ nsMsgAccountManager::GetAccounts(nsISupportsArray **_retval)
accounts->AppendElements(m_accounts);
*_retval = accounts;
NS_ADDREF(*_retval);
NS_ADDREF(*_retval = accounts);
return NS_OK;
}
@ -1207,8 +1206,7 @@ nsMsgAccountManager::GetAllIdentities(nsISupportsArray **_retval)
(void *)(nsISupportsArray*)identities);
// convert nsISupportsArray->nsISupportsArray
// when do we free the nsISupportsArray?
*_retval = identities;
NS_ADDREF(*_retval);
NS_ADDREF(*_retval = identities);
return rv;
}
@ -1290,8 +1288,7 @@ nsMsgAccountManager::GetAllServers(nsISupportsArray **_retval)
// get the order correct
m_incomingServers.Enumerate(getServersToArray,
(void *)(nsISupportsArray*)servers);
*_retval = servers;
NS_ADDREF(*_retval);
NS_ADDREF(*_retval = servers);
return rv;
}
@ -1502,7 +1499,7 @@ NS_IMETHODIMP
nsMsgAccountManager::SetSpecialFolders()
{
nsresult rv;
nsCOMPtr<nsIRDFService> rdf = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
nsCOMPtr<nsIRDFService> rdf = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsISupportsArray> identities;
@ -1582,7 +1579,7 @@ nsMsgAccountManager::UnloadAccounts()
m_incomingServers.Reset(hashElementRelease, nsnull);
m_accountsLoaded = PR_FALSE;
mAccountKeyList.Truncate(0);
SetLastServerFound(nsnull,"","","");
SetLastServerFound(nsnull,"","",0,"");
return NS_OK;
}
@ -1610,8 +1607,8 @@ nsMsgAccountManager::CleanupOnExit()
NS_IMETHODIMP
nsMsgAccountManager::WriteToFolderCache(nsIMsgFolderCache *folderCache)
{
m_incomingServers.Enumerate(writeFolderCache, folderCache);
return folderCache->Close();
m_incomingServers.Enumerate(writeFolderCache, folderCache);
return folderCache->Close();
}
nsresult
@ -1645,8 +1642,7 @@ nsMsgAccountManager::createKeyedAccount(const char* key,
m_prefs->SetCharPref(PREF_MAIL_ACCOUNTMANAGER_ACCOUNTS,
mAccountKeyList.get());
*aAccount = account;
NS_ADDREF(*aAccount);
NS_ADDREF(*aAccount = account);
return NS_OK;
}
@ -1675,8 +1671,7 @@ nsMsgAccountManager::GetAccount(const char* key,
m_accounts->EnumerateForwards(findAccountByKey, (void *)&findEntry);
if (findEntry.account) {
*_retval = findEntry.account;
NS_ADDREF(*_retval);
NS_ADDREF(*_retval = findEntry.account);
return NS_OK;
}
@ -1770,42 +1765,130 @@ NS_IMETHODIMP nsMsgAccountManager::RemoveIncomingServerListener(nsIIncomingServe
NS_IMETHODIMP nsMsgAccountManager::NotifyServerLoaded(nsIMsgIncomingServer *server)
{
PRInt32 count = m_incomingServerListeners.Count();
for(PRInt32 i = 0; i < count; i++)
{
nsIIncomingServerListener* listener = m_incomingServerListeners[i];
listener->OnServerLoaded(server);
}
PRInt32 count = m_incomingServerListeners.Count();
for(PRInt32 i = 0; i < count; i++)
{
nsIIncomingServerListener* listener = m_incomingServerListeners[i];
listener->OnServerLoaded(server);
}
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP nsMsgAccountManager::NotifyServerUnloaded(nsIMsgIncomingServer *server)
{
PRInt32 count = m_incomingServerListeners.Count();
server->SetFilterList(nsnull); // clear this to cut shutdown leaks. we are always passing valid non-null server here.
for(PRInt32 i = 0; i < count; i++)
{
nsIIncomingServerListener* listener = m_incomingServerListeners[i];
listener->OnServerUnloaded(server);
}
PRInt32 count = m_incomingServerListeners.Count();
server->SetFilterList(nsnull); // clear this to cut shutdown leaks. we are always passing valid non-null server here.
for(PRInt32 i = 0; i < count; i++)
{
nsIIncomingServerListener* listener = m_incomingServerListeners[i];
listener->OnServerUnloaded(server);
}
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP nsMsgAccountManager::NotifyServerChanged(nsIMsgIncomingServer *server)
{
PRInt32 count = m_incomingServerListeners.Count();
for(PRInt32 i = 0; i < count; i++)
{
nsIIncomingServerListener* listener = m_incomingServerListeners[i];
listener->OnServerChanged(server);
}
PRInt32 count = m_incomingServerListeners.Count();
for(PRInt32 i = 0; i < count; i++)
{
nsIIncomingServerListener* listener = m_incomingServerListeners[i];
listener->OnServerChanged(server);
}
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
nsMsgAccountManager::FindServerByURI(nsIURI *aURI, PRBool aRealFlag,
nsIMsgIncomingServer** aResult)
{
nsresult rv;
nsCOMPtr<nsISupportsArray> servers;
// Get username and hostname and port so we can get the server
nsCAutoString username;
rv = aURI->GetUserPass(username);
if (NS_SUCCEEDED(rv) && !username.IsEmpty())
NS_UnescapeURL(username);
nsCAutoString hostname;
rv = aURI->GetHost(hostname);
if (NS_SUCCEEDED(rv) && !hostname.IsEmpty())
NS_UnescapeURL(hostname);
nsCAutoString type;
rv = aURI->GetScheme(type);
if (NS_SUCCEEDED(rv) && !type.IsEmpty())
{
// now modify type if pop or news
if (type.EqualsLiteral("pop"))
type.AssignLiteral("pop3");
// we use "nntp" in the server list so translate it here.
else if (type.EqualsLiteral("news"))
type.AssignLiteral("nntp");
}
PRInt32 port = 0;
// check the port of the scheme is not 'none'
if (!type.EqualsLiteral("none"))
{
rv = aURI->GetPort(&port);
// Set the port to zero if we got a -1 (use default)
if (NS_SUCCEEDED(rv) && (port == -1))
port = 0;
}
// If 'aRealFlag' is set then we want to scan all existing accounts
// to make sure there's no duplicate including those whose host and/or
// user names have been changed.
if (!aRealFlag &&
(m_lastFindServerHostName.Equals(hostname)) &&
(m_lastFindServerUserName.Equals(username)) &&
(port == m_lastFindServerPort) &&
(m_lastFindServerType.Equals(type)) &&
m_lastFindServerResult)
{
NS_ADDREF(*aResult = m_lastFindServerResult);
return NS_OK;
}
rv = GetAllServers(getter_AddRefs(servers));
if (NS_FAILED(rv)) return rv;
findServerEntry serverInfo;
// "" or 0 (for the port only) act as the wild card.
// hostname might be blank, pass "" instead
serverInfo.hostname = (!hostname.IsEmpty()) ? hostname.get() : "";
// username might be blank, pass "" instead
serverInfo.username = (!username.IsEmpty()) ? username.get() : "";
// port is initialized to zero if not specified in the url,
// so use it no matter what
serverInfo.port = port;
// type might be blank, pass "" instead
serverInfo.type = (!type.IsEmpty()) ? type.get() : "";
serverInfo.useRealSetting = aRealFlag;
serverInfo.server = *aResult = nsnull;
servers->EnumerateForwards(findServerUrl, (void *)&serverInfo);
if (!serverInfo.server)
return NS_ERROR_UNEXPECTED;
// cache for next time
rv = SetLastServerFound(serverInfo.server, hostname.get(), username.get(), port, type.get());
NS_ENSURE_SUCCESS(rv,rv);
NS_ADDREF(*aResult = serverInfo.server);
return NS_OK;
}
nsresult
@ -1822,9 +1905,9 @@ nsMsgAccountManager::InternalFindServer(const char* username,
// to make sure there's no duplicate including those whose host and/or
// user names have been changed.
if (!useRealSetting &&
(!nsCRT::strcmp((hostname?hostname:""),m_lastFindServerHostName.get())) &&
(!nsCRT::strcmp((username?username:""),m_lastFindServerUserName.get())) &&
(!nsCRT::strcmp((type?type:""),m_lastFindServerType.get())) &&
(m_lastFindServerHostName.Equals(hostname)) &&
(m_lastFindServerUserName.Equals(username)) &&
(m_lastFindServerType.Equals(type)) &&
m_lastFindServerResult)
{
NS_ADDREF(*aResult = m_lastFindServerResult);
@ -1853,11 +1936,10 @@ nsMsgAccountManager::InternalFindServer(const char* username,
if (!serverInfo.server) return NS_ERROR_UNEXPECTED;
// cache for next time
rv = SetLastServerFound(serverInfo.server, hostname, username, type);
rv = SetLastServerFound(serverInfo.server, hostname, username, 0, type);
NS_ENSURE_SUCCESS(rv,rv);
*aResult = serverInfo.server;
NS_ADDREF(*aResult);
NS_ADDREF(*aResult = serverInfo.server);
return NS_OK;
@ -1877,9 +1959,29 @@ NS_IMETHODIMP
nsMsgAccountManager::FindRealServer(const char* username,
const char* hostname,
const char* type,
PRInt32 port,
nsIMsgIncomingServer** aResult)
{
InternalFindServer(username, hostname, type, PR_TRUE, aResult);
// Dummy string to initialize the URL
// Needed so that we can use the Set....() items below (except SetSpec())
nsCAutoString spec("http://user@hostname:1111");
nsresult rv;
nsCOMPtr<nsIURL> aUrl = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_FAILED(rv)) return NS_OK;
aUrl->SetSpec(spec);
aUrl->SetScheme(nsDependentCString(type));
aUrl->SetHost(nsDependentCString(hostname));
aUrl->SetUserPass(nsDependentCString(username));
aUrl->SetPort(port);
#ifdef DEBUG_kteuscher
aUrl->GetSpec(spec);
printf("aUrl == %s\n", spec.get());
#endif
FindServerByURI(aUrl, PR_TRUE, aResult);
return NS_OK;
}
@ -1934,12 +2036,61 @@ nsMsgAccountManager::FindAccountForServer(nsIMsgIncomingServer *server,
m_accounts->EnumerateForwards(findAccountByServerKey, (void *)&entry);
if (entry.account) {
*aResult = entry.account;
NS_ADDREF(*aResult);
NS_ADDREF(*aResult = entry.account);
}
return NS_OK;
}
// if the aElement matches the given hostname, add it to the given array
PRBool
nsMsgAccountManager::findServerUrl(nsISupports *aElement, void *data)
{
nsresult rv;
nsCOMPtr<nsIMsgIncomingServer> server = do_QueryInterface(aElement);
if (!server) return PR_TRUE;
findServerEntry *entry = (findServerEntry*) data;
nsXPIDLCString thisHostname;
if (entry->useRealSetting)
rv = server->GetRealHostName(getter_Copies(thisHostname));
else
rv = server->GetHostName(getter_Copies(thisHostname));
if (NS_FAILED(rv)) return PR_TRUE;
nsXPIDLCString thisUsername;
if (entry->useRealSetting)
rv = server->GetRealUsername(getter_Copies(thisUsername));
else
rv = server->GetUsername(getter_Copies(thisUsername));
if (NS_FAILED(rv)) return PR_TRUE;
nsXPIDLCString thisType;
rv = server->GetType(getter_Copies(thisType));
if (NS_FAILED(rv)) return PR_TRUE;
PRInt32 thisPort = -1; // use the default port identifier
// Don't try and get a port for the 'none' scheme
if (!thisType.EqualsLiteral("none")) {
rv = server->GetPort(&thisPort);
NS_ENSURE_TRUE(NS_SUCCEEDED(rv), PR_TRUE);
}
// treat "" as a wild card, so if the caller passed in "" for the desired attribute
// treat it as a match
if ((!*entry->type || (strcmp(entry->type, thisType)==0)) &&
(!*entry->hostname || (nsCRT::strcasecmp(entry->hostname, thisHostname)==0)) &&
(!(entry->port != 0) || (entry->port == thisPort)) &&
(!*entry->username || (strcmp(entry->username, thisUsername)==0)))
{
entry->server = server;
return PR_FALSE; // stop on first find
}
return PR_TRUE;
}
// if the aElement matches the given hostname, add it to the given array
PRBool
nsMsgAccountManager::findServer(nsISupports *aElement, void *data)
@ -2035,8 +2186,7 @@ nsMsgAccountManager::GetIdentitiesForServer(nsIMsgIncomingServer *server,
(void *)&identityInfo);
// do an addref for the caller.
*_retval = identities;
NS_ADDREF(*_retval);
NS_ADDREF(*_retval = identities);
return NS_OK;
}
@ -2054,7 +2204,7 @@ nsMsgAccountManager::findIdentitiesForServer(nsISupports* element, void *aData)
rv = account->GetIncomingServer(getter_AddRefs(thisServer));
if (NS_FAILED(rv)) return PR_TRUE;
nsXPIDLCString serverKey;
NS_ASSERTION(thisServer, "thisServer is null");
NS_ASSERTION(entry, "entry is null");
NS_ASSERTION(entry->server, "entry->server is null");
@ -2095,8 +2245,7 @@ nsMsgAccountManager::GetServersForIdentity(nsIMsgIdentity *identity,
(void *)&serverInfo);
// do an addref for the caller.
*_retval = servers;
NS_ADDREF(*_retval);
NS_ADDREF(*_retval = servers);
return NS_OK;
}
@ -2219,53 +2368,53 @@ nsMsgAccountManager::removeListener(nsHashKey *aKey, void *element, void *aData)
NS_IMETHODIMP nsMsgAccountManager::SetLocalFoldersServer(nsIMsgIncomingServer *aServer)
{
nsresult rv;
if (!aServer) return NS_ERROR_NULL_POINTER;
nsresult rv;
if (!aServer) return NS_ERROR_NULL_POINTER;
nsXPIDLCString key;
rv = aServer->GetKey(getter_Copies(key));
if (NS_FAILED(rv)) return rv;
rv = m_prefs->SetCharPref(PREF_MAIL_ACCOUNTMANAGER_LOCALFOLDERSSERVER, (const char *)key);
return rv;
nsXPIDLCString key;
rv = aServer->GetKey(getter_Copies(key));
if (NS_FAILED(rv)) return rv;
rv = m_prefs->SetCharPref(PREF_MAIL_ACCOUNTMANAGER_LOCALFOLDERSSERVER, (const char *)key);
return rv;
}
NS_IMETHODIMP nsMsgAccountManager::GetLocalFoldersServer(nsIMsgIncomingServer **aServer)
{
nsXPIDLCString serverKey;
nsresult rv;
nsXPIDLCString serverKey;
nsresult rv;
if (!aServer) return NS_ERROR_NULL_POINTER;
if (!aServer) return NS_ERROR_NULL_POINTER;
if (!m_prefs) {
rv = getPrefService();
NS_ENSURE_SUCCESS(rv,rv);
}
rv = m_prefs->GetCharPref(PREF_MAIL_ACCOUNTMANAGER_LOCALFOLDERSSERVER, getter_Copies(serverKey));
rv = m_prefs->GetCharPref(PREF_MAIL_ACCOUNTMANAGER_LOCALFOLDERSSERVER, getter_Copies(serverKey));
if (NS_SUCCEEDED(rv) && ((const char *)serverKey)) {
rv = GetIncomingServer(serverKey, aServer);
if (!*aServer) return NS_ERROR_FAILURE;
return rv;
}
if (NS_SUCCEEDED(rv) && ((const char *)serverKey)) {
rv = GetIncomingServer(serverKey, aServer);
if (!*aServer) return NS_ERROR_FAILURE;
return rv;
}
// try ("nobody","Local Folders","none"), and work down to any "none" server.
rv = FindServer("nobody","Local Folders","none",aServer);
if (NS_FAILED(rv) || !*aServer) {
rv = FindServer("nobody",nsnull,"none",aServer);
if (NS_FAILED(rv) || !*aServer) {
rv = FindServer(nsnull,"Local Folders","none",aServer);
if (NS_FAILED(rv) || !*aServer) {
rv = FindServer(nsnull,nsnull,"none",aServer);
}
}
}
// try ("nobody","Local Folders","none"), and work down to any "none" server.
rv = FindServer("nobody","Local Folders","none",aServer);
if (NS_FAILED(rv) || !*aServer) {
rv = FindServer("nobody",nsnull,"none",aServer);
if (NS_FAILED(rv) || !*aServer) {
rv = FindServer(nsnull,"Local Folders","none",aServer);
if (NS_FAILED(rv) || !*aServer) {
rv = FindServer(nsnull,nsnull,"none",aServer);
}
}
}
if (NS_FAILED(rv)) return rv;
if (!*aServer) return NS_ERROR_FAILURE;
rv = SetLocalFoldersServer(*aServer);
return rv;
if (NS_FAILED(rv)) return rv;
if (!*aServer) return NS_ERROR_FAILURE;
rv = SetLocalFoldersServer(*aServer);
return rv;
}
// nsIUrlListener methods
@ -2347,11 +2496,12 @@ nsMsgAccountManager::GetCleanupInboxInProgress(PRBool *bVal)
return NS_OK;
}
nsresult
nsMsgAccountManager::SetLastServerFound(nsIMsgIncomingServer *server, const char *hostname, const char *username, const char *type)
nsMsgAccountManager::SetLastServerFound(nsIMsgIncomingServer *server, const char *hostname, const char *username, PRInt32 port, const char *type)
{
m_lastFindServerResult = server;
m_lastFindServerHostName = hostname;
m_lastFindServerUserName = username;
m_lastFindServerPort = port;
m_lastFindServerType = type;
return NS_OK;

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

@ -106,9 +106,10 @@ private:
nsCOMPtr <nsIMsgIncomingServer> m_lastFindServerResult;
nsCString m_lastFindServerHostName;
nsCString m_lastFindServerUserName;
PRInt32 m_lastFindServerPort;
nsCString m_lastFindServerType;
nsresult SetLastServerFound(nsIMsgIncomingServer *server, const char *hostname, const char *username, const char *type);
nsresult SetLastServerFound(nsIMsgIncomingServer *server, const char *hostname, const char *username, const PRInt32 port, const const char *type);
/* internal creation routines - updates m_identities and m_incomingServers */
nsresult createKeyedAccount(const char* key,
@ -192,6 +193,9 @@ private:
// find the server given by {username, hostname, type}
static PRBool findServer(nsISupports *aElement, void *data);
// find the server given by {username, hostname, port, type}
static PRBool findServerUrl(nsISupports *aElement, void *data);
// write out the server's cache through the given folder cache
static PRBool PR_CALLBACK writeFolderCache(nsHashKey *aKey, void *aData, void *closure);
static PRBool PR_CALLBACK shutdown(nsHashKey *aKey, void *aData, void *closure);

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

@ -200,7 +200,7 @@ nsMsgDBFolder::~nsMsgDBFolder(void)
mParsingURL = nsnull;
#endif
}
//shutdown but don't shutdown children.
//shutdown but don't shutdown children.
Shutdown(PR_FALSE);
}
@ -269,30 +269,30 @@ NS_IMETHODIMP nsMsgDBFolder::ForceDBClosed()
NS_IMETHODIMP nsMsgDBFolder::StartFolderLoading(void)
{
if(mDatabase)
mDatabase->RemoveListener(this);
mAddListener = PR_FALSE;
return NS_OK;
if(mDatabase)
mDatabase->RemoveListener(this);
mAddListener = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsMsgDBFolder::EndFolderLoading(void)
{
if(mDatabase)
mDatabase->AddListener(this);
mAddListener = PR_TRUE;
UpdateSummaryTotals(PR_TRUE);
if(mDatabase)
mDatabase->AddListener(this);
mAddListener = PR_TRUE;
UpdateSummaryTotals(PR_TRUE);
//GGGG check for new mail here and call SetNewMessages...?? -- ONE OF THE 2 PLACES
if(mDatabase)
{
nsresult rv;
PRBool hasNewMessages;
//GGGG check for new mail here and call SetNewMessages...?? -- ONE OF THE 2 PLACES
if(mDatabase)
{
nsresult rv;
PRBool hasNewMessages;
rv = mDatabase->HasNew(&hasNewMessages);
SetHasNewMessages(hasNewMessages);
}
rv = mDatabase->HasNew(&hasNewMessages);
SetHasNewMessages(hasNewMessages);
}
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
@ -316,7 +316,7 @@ nsMsgDBFolder::GetExpungedBytes(PRUint32 *count)
ReadDBFolderInfo(PR_FALSE);
*count = mExpungedBytes;
}
return NS_OK;
return NS_OK;
}
@ -335,18 +335,18 @@ NS_IMETHODIMP nsMsgDBFolder::GetCharset(char * *aCharset)
NS_IMETHODIMP nsMsgDBFolder::SetCharset(const char * aCharset)
{
nsresult rv;
nsresult rv;
nsCOMPtr<nsIDBFolderInfo> folderInfo;
nsCOMPtr<nsIMsgDatabase> db;
rv = GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(db));
if(NS_SUCCEEDED(rv))
{
rv = folderInfo->SetCharacterSet(NS_ConvertASCIItoUTF16(aCharset).get());
db->Commit(nsMsgDBCommitType::kLargeCommit);
mCharset.AssignWithConversion(aCharset); // synchronize member variable
}
return rv;
nsCOMPtr<nsIDBFolderInfo> folderInfo;
nsCOMPtr<nsIMsgDatabase> db;
rv = GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(db));
if(NS_SUCCEEDED(rv))
{
rv = folderInfo->SetCharacterSet(NS_ConvertASCIItoUTF16(aCharset).get());
db->Commit(nsMsgDBCommitType::kLargeCommit);
mCharset.AssignWithConversion(aCharset); // synchronize member variable
}
return rv;
}
NS_IMETHODIMP nsMsgDBFolder::GetCharsetOverride(PRBool *aCharsetOverride)
@ -388,8 +388,8 @@ NS_IMETHODIMP nsMsgDBFolder::SetHasNewMessages(PRBool curNewMessages)
if (curNewMessages != mNewMessages)
{
/** @params
* nsIAtom* property, PRBool oldValue, PRBool newValue
*/
* nsIAtom* property, PRBool oldValue, PRBool newValue
*/
PRBool oldNewMessages = mNewMessages;
mNewMessages = curNewMessages;
NotifyBoolPropertyChanged(kNewMessagesAtom, oldNewMessages, curNewMessages);
@ -498,8 +498,8 @@ nsresult nsMsgDBFolder::ReadDBFolderInfo(PRBool force)
}
}
}
// if (m_master->InitFolderFromCache (this))
// return err;
// if (m_master->InitFolderFromCache (this))
// return err;
if (force || !mInitializedFromCache)
{
@ -878,7 +878,7 @@ nsresult nsMsgDBFolder::OnKeyAddedOrDeleted(nsMsgKey aKeyChanged, PRBool added)
NS_IMETHODIMP nsMsgDBFolder::OnParentChanged(nsMsgKey aKeyChanged, nsMsgKey oldParent, nsMsgKey newParent,
nsIDBChangeListener * aInstigator)
nsIDBChangeListener * aInstigator)
{
//In reality we probably want to just change the parent because otherwise we will lose things like
//selection.
@ -995,14 +995,14 @@ NS_IMETHODIMP nsMsgDBFolder::HasMsgOffline(nsMsgKey msgKey, PRBool *result)
{
NS_ENSURE_ARG(result);
*result = PR_FALSE;
if(!mDatabase)
return NS_ERROR_FAILURE;
if(!mDatabase)
return NS_ERROR_FAILURE;
nsresult rv;
nsCOMPtr<nsIMsgDBHdr> hdr;
rv = mDatabase->GetMsgHdrForKey(msgKey, getter_AddRefs(hdr));
if(NS_FAILED(rv))
return rv;
nsresult rv;
nsCOMPtr<nsIMsgDBHdr> hdr;
rv = mDatabase->GetMsgHdrForKey(msgKey, getter_AddRefs(hdr));
if(NS_FAILED(rv))
return rv;
if (hdr)
{
@ -1020,8 +1020,8 @@ NS_IMETHODIMP nsMsgDBFolder::HasMsgOffline(nsMsgKey msgKey, PRBool *result)
NS_IMETHODIMP nsMsgDBFolder::GetFlags(PRUint32 *_retval)
{
ReadDBFolderInfo(PR_FALSE);
*_retval = mFlags;
return NS_OK;
*_retval = mFlags;
return NS_OK;
}
@ -1117,73 +1117,73 @@ nsresult nsMsgDBFolder::FlushToFolderCache()
NS_IMETHODIMP nsMsgDBFolder::WriteToFolderCache(nsIMsgFolderCache *folderCache, PRBool deep)
{
nsCOMPtr <nsIEnumerator> aEnumerator;
nsCOMPtr <nsIEnumerator> aEnumerator;
nsresult rv;
if (folderCache)
{
nsCOMPtr <nsIMsgFolderCacheElement> cacheElement;
nsCOMPtr <nsIFileSpec> dbPath;
if (folderCache)
{
nsCOMPtr <nsIMsgFolderCacheElement> cacheElement;
nsCOMPtr <nsIFileSpec> dbPath;
rv = GetFolderCacheKey(getter_AddRefs(dbPath));
rv = GetFolderCacheKey(getter_AddRefs(dbPath));
#ifdef DEBUG_bienvenu1
PRBool exists;
NS_ASSERTION(NS_SUCCEEDED(dbPath->Exists(&exists)) && exists, "file spec we're adding to cache should exist");
PRBool exists;
NS_ASSERTION(NS_SUCCEEDED(dbPath->Exists(&exists)) && exists, "file spec we're adding to cache should exist");
#endif
if (NS_SUCCEEDED(rv) && dbPath)
{
nsXPIDLCString persistentPath;
dbPath->GetPersistentDescriptorString(getter_Copies(persistentPath));
rv = folderCache->GetCacheElement(persistentPath, PR_TRUE, getter_AddRefs(cacheElement));
if (NS_SUCCEEDED(rv) && cacheElement)
rv = WriteToFolderCacheElem(cacheElement);
}
}
if (NS_SUCCEEDED(rv) && dbPath)
{
nsXPIDLCString persistentPath;
dbPath->GetPersistentDescriptorString(getter_Copies(persistentPath));
rv = folderCache->GetCacheElement(persistentPath, PR_TRUE, getter_AddRefs(cacheElement));
if (NS_SUCCEEDED(rv) && cacheElement)
rv = WriteToFolderCacheElem(cacheElement);
}
}
if (!deep)
return rv;
rv = GetSubFolders(getter_AddRefs(aEnumerator));
if(NS_FAILED(rv))
return rv;
rv = GetSubFolders(getter_AddRefs(aEnumerator));
if(NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aItem;
nsCOMPtr<nsISupports> aItem;
rv = aEnumerator->First();
if (NS_FAILED(rv))
return NS_OK; // it's OK, there are no sub-folders.
rv = aEnumerator->First();
if (NS_FAILED(rv))
return NS_OK; // it's OK, there are no sub-folders.
while(NS_SUCCEEDED(rv))
{
rv = aEnumerator->CurrentItem(getter_AddRefs(aItem));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIMsgFolder> aMsgFolder(do_QueryInterface(aItem, &rv));
if (NS_SUCCEEDED(rv))
{
if (folderCache)
{
rv = aMsgFolder->WriteToFolderCache(folderCache, PR_TRUE);
if (NS_FAILED(rv))
break;
}
}
rv = aEnumerator->Next();
if (NS_FAILED(rv))
{
rv = NS_OK;
break;
}
}
return rv;
while(NS_SUCCEEDED(rv))
{
rv = aEnumerator->CurrentItem(getter_AddRefs(aItem));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIMsgFolder> aMsgFolder(do_QueryInterface(aItem, &rv));
if (NS_SUCCEEDED(rv))
{
if (folderCache)
{
rv = aMsgFolder->WriteToFolderCache(folderCache, PR_TRUE);
if (NS_FAILED(rv))
break;
}
}
rv = aEnumerator->Next();
if (NS_FAILED(rv))
{
rv = NS_OK;
break;
}
}
return rv;
}
NS_IMETHODIMP nsMsgDBFolder::WriteToFolderCacheElem(nsIMsgFolderCacheElement *element)
{
nsresult rv = NS_OK;
nsresult rv = NS_OK;
element->SetInt32Property("flags", (PRInt32) mFlags);
element->SetInt32Property("totalMsgs", mNumTotalMessages);
element->SetInt32Property("totalUnreadMsgs", mNumUnreadMessages);
element->SetInt32Property("flags", (PRInt32) mFlags);
element->SetInt32Property("totalMsgs", mNumTotalMessages);
element->SetInt32Property("totalUnreadMsgs", mNumUnreadMessages);
element->SetInt32Property("pendingUnreadMsgs", mNumPendingUnreadMessages);
element->SetInt32Property("pendingMsgs", mNumPendingTotalMessages);
element->SetInt32Property("expungedBytes", mExpungedBytes);
@ -1191,16 +1191,16 @@ NS_IMETHODIMP nsMsgDBFolder::WriteToFolderCacheElem(nsIMsgFolderCacheElement *el
nsCAutoString mcharsetC;
mcharsetC.AssignWithConversion(mCharset);
element->SetStringProperty("charset", mcharsetC.get());
element->SetStringProperty("charset", mcharsetC.get());
#ifdef DEBUG_bienvenu1
char *uri;
char *uri;
GetURI(&uri);
printf("writing total %ld for %s\n", mNumTotalMessages, uri);
PR_Free(uri);
GetURI(&uri);
printf("writing total %ld for %s\n", mNumTotalMessages, uri);
PR_Free(uri);
#endif
return rv;
return rv;
}
NS_IMETHODIMP
@ -2456,26 +2456,12 @@ nsMsgDBFolder::parseURI(PRBool needServer)
// no parent. do the extra work of asking
if (!server && needServer)
{
// Get username and hostname so we can get the server
nsCAutoString userPass;
rv = url->GetUserPass(userPass);
if (NS_SUCCEEDED(rv) && !userPass.IsEmpty())
nsUnescape(userPass.BeginWriting());
nsCAutoString hostName;
rv = url->GetHost(hostName);
if (NS_SUCCEEDED(rv) && !hostName.IsEmpty())
nsUnescape(hostName.BeginWriting());
// turn it back into a server:
nsCOMPtr<nsIMsgAccountManager> accountManager =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
rv = accountManager->FindServer(userPass.get(),
hostName.get(),
GetIncomingServerType(),
url->SetScheme(nsDependentCString(GetIncomingServerType()));
rv = accountManager->FindServerByURI(url, PR_FALSE,
getter_AddRefs(server));
if (NS_FAILED(rv)) return rv;

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

@ -77,7 +77,7 @@ nsMsgMailNewsUrl::nsMsgMailNewsUrl()
nsMsgMailNewsUrl::~nsMsgMailNewsUrl()
{
PR_FREEIF(m_errorMessage);
PR_FREEIF(m_errorMessage);
}
NS_IMPL_THREADSAFE_ADDREF(nsMsgMailNewsUrl)
@ -96,10 +96,10 @@ NS_INTERFACE_MAP_END_THREADSAFE
nsresult nsMsgMailNewsUrl::GetUrlState(PRBool * aRunningUrl)
{
if (aRunningUrl)
*aRunningUrl = m_runningUrl;
if (aRunningUrl)
*aRunningUrl = m_runningUrl;
return NS_OK;
return NS_OK;
}
nsresult nsMsgMailNewsUrl::SetUrlState(PRBool aRunningUrl, nsresult aExitCode)
@ -141,74 +141,71 @@ nsresult nsMsgMailNewsUrl::SetUrlState(PRBool aRunningUrl, nsresult aExitCode)
nsresult nsMsgMailNewsUrl::RegisterListener (nsIUrlListener * aUrlListener)
{
if (m_urlListeners)
m_urlListeners->RegisterListener(aUrlListener);
return NS_OK;
if (m_urlListeners)
m_urlListeners->RegisterListener(aUrlListener);
return NS_OK;
}
nsresult nsMsgMailNewsUrl::UnRegisterListener (nsIUrlListener * aUrlListener)
{
if (m_urlListeners)
m_urlListeners->UnRegisterListener(aUrlListener);
return NS_OK;
if (m_urlListeners)
m_urlListeners->UnRegisterListener(aUrlListener);
return NS_OK;
}
nsresult nsMsgMailNewsUrl::SetErrorMessage (const char * errorMessage)
{
// functionality has been moved to nsIMsgStatusFeedback
return NS_ERROR_NOT_IMPLEMENTED;
// functionality has been moved to nsIMsgStatusFeedback
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsMsgMailNewsUrl::GetErrorMessage (char ** errorMessage)
{
// functionality has been moved to nsIMsgStatusFeedback
return NS_ERROR_NOT_IMPLEMENTED;
// functionality has been moved to nsIMsgStatusFeedback
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetServer(nsIMsgIncomingServer ** aIncomingServer)
{
// mscott --> we could cache a copy of the server here....but if we did, we run
// the risk of leaking the server if any single url gets leaked....of course that
// shouldn't happen...but it could. so i'm going to look it up every time and
// we can look at caching it later.
// mscott --> we could cache a copy of the server here....but if we did, we run
// the risk of leaking the server if any single url gets leaked....of course that
// shouldn't happen...but it could. so i'm going to look it up every time and
// we can look at caching it later.
nsCAutoString host;
nsCAutoString scheme;
nsCAutoString userName;
nsresult rv;
nsCAutoString urlstr;
nsCAutoString scheme;
nsresult rv = GetAsciiHost(host);
nsCOMPtr<nsIURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
/* GetUsername() returns an escaped string, so we need to manually unescape it.
*/
GetUsername(userName);
NS_UnescapeURL(userName); // XXX may result in non-ASCII octets!
rv = GetScheme(scheme);
m_baseURL->GetSpec(urlstr);
rv = url->SetSpec(urlstr);
if (NS_FAILED(rv)) return rv;
rv = GetScheme(scheme);
if (NS_SUCCEEDED(rv))
{
if (scheme.Equals("pop"))
if (scheme.EqualsLiteral("pop"))
scheme.Assign("pop3");
// we use "nntp" in the server list so translate it here.
if (scheme.Equals("news"))
if (scheme.EqualsLiteral("news"))
scheme.Assign("nntp");
url->SetScheme(scheme);
nsCOMPtr<nsIMsgAccountManager> accountManager =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIMsgIncomingServer> server;
rv = accountManager->FindServer(userName.get(),
host.get(),
scheme.get(),
rv = accountManager->FindServerByURI(url, PR_FALSE,
aIncomingServer);
if (!*aIncomingServer && scheme.Equals("imap"))
if (!*aIncomingServer && scheme.EqualsLiteral("imap"))
{
// look for any imap server with this host name so clicking on
// other users folder urls will work. We could override this method
// for imap urls, or we could make caching of servers work and
// just set the server in the imap code for this case.
rv = accountManager->FindServer("",
host.get(),
scheme.get(),
url->SetUserPass(NS_LITERAL_CSTRING(""));
rv = accountManager->FindServerByURI(url, PR_FALSE,
aIncomingServer);
}
}
@ -218,63 +215,63 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetServer(nsIMsgIncomingServer ** aIncomingServe
NS_IMETHODIMP nsMsgMailNewsUrl::SetStatusFeedback(nsIMsgStatusFeedback *aMsgFeedback)
{
if (aMsgFeedback)
m_statusFeedback = do_QueryInterface(aMsgFeedback);
return NS_OK;
if (aMsgFeedback)
m_statusFeedback = do_QueryInterface(aMsgFeedback);
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetMsgWindow(nsIMsgWindow **aMsgWindow)
{
NS_ENSURE_ARG_POINTER(aMsgWindow);
// note: it is okay to return a null msg window and not return an error
// it's possible the url really doesn't have msg window
// note: it is okay to return a null msg window and not return an error
// it's possible the url really doesn't have msg window
*aMsgWindow = m_msgWindow;
NS_IF_ADDREF(*aMsgWindow);
*aMsgWindow = m_msgWindow;
NS_IF_ADDREF(*aMsgWindow);
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetMsgWindow(nsIMsgWindow *aMsgWindow)
{
if (aMsgWindow)
m_msgWindow = do_QueryInterface(aMsgWindow);
return NS_OK;
if (aMsgWindow)
m_msgWindow = do_QueryInterface(aMsgWindow);
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetStatusFeedback(nsIMsgStatusFeedback **aMsgFeedback)
{
nsresult rv = NS_OK;
// note: it is okay to return a null status feedback and not return an error
// it's possible the url really doesn't have status feedback
if (!m_statusFeedback)
{
nsresult rv = NS_OK;
// note: it is okay to return a null status feedback and not return an error
// it's possible the url really doesn't have status feedback
if (!m_statusFeedback)
{
if(m_msgWindow)
{
m_msgWindow->GetStatusFeedback(getter_AddRefs(m_statusFeedback));
}
}
if (aMsgFeedback)
{
*aMsgFeedback = m_statusFeedback;
NS_IF_ADDREF(*aMsgFeedback);
}
else
rv = NS_ERROR_NULL_POINTER;
return rv;
if(m_msgWindow)
{
m_msgWindow->GetStatusFeedback(getter_AddRefs(m_statusFeedback));
}
}
if (aMsgFeedback)
{
*aMsgFeedback = m_statusFeedback;
NS_IF_ADDREF(*aMsgFeedback);
}
else
rv = NS_ERROR_NULL_POINTER;
return rv;
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetLoadGroup(nsILoadGroup **aLoadGroup)
{
nsresult rv = NS_OK;
// note: it is okay to return a null load group and not return an error
// it's possible the url really doesn't have load group
if (!m_loadGroup)
{
if (m_msgWindow)
{
nsresult rv = NS_OK;
// note: it is okay to return a null load group and not return an error
// it's possible the url really doesn't have load group
if (!m_loadGroup)
{
if (m_msgWindow)
{
nsCOMPtr<nsIDocShell> docShell;
m_msgWindow->GetRootDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
@ -302,101 +299,101 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetLoadGroup(nsILoadGroup **aLoadGroup)
}
}
#endif
if (webShell)
{
nsCOMPtr <nsIDocumentLoader> docLoader;
webShell->GetDocumentLoader(*getter_AddRefs(docLoader));
if (docLoader)
docLoader->GetLoadGroup(getter_AddRefs(m_loadGroup));
}
}
}
if (webShell)
{
nsCOMPtr <nsIDocumentLoader> docLoader;
webShell->GetDocumentLoader(*getter_AddRefs(docLoader));
if (docLoader)
docLoader->GetLoadGroup(getter_AddRefs(m_loadGroup));
}
}
}
if (aLoadGroup)
{
*aLoadGroup = m_loadGroup;
NS_IF_ADDREF(*aLoadGroup);
}
else
rv = NS_ERROR_NULL_POINTER;
return rv;
if (aLoadGroup)
{
*aLoadGroup = m_loadGroup;
NS_IF_ADDREF(*aLoadGroup);
}
else
rv = NS_ERROR_NULL_POINTER;
return rv;
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetUpdatingFolder(PRBool *aResult)
{
NS_ENSURE_ARG(aResult);
*aResult = m_updatingFolder;
return NS_OK;
*aResult = m_updatingFolder;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetUpdatingFolder(PRBool updatingFolder)
{
m_updatingFolder = updatingFolder;
return NS_OK;
m_updatingFolder = updatingFolder;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetAddToMemoryCache(PRBool *aAddToCache)
{
NS_ENSURE_ARG(aAddToCache);
*aAddToCache = m_addContentToCache;
return NS_OK;
*aAddToCache = m_addContentToCache;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetAddToMemoryCache(PRBool aAddToCache)
{
m_addContentToCache = aAddToCache;
return NS_OK;
m_addContentToCache = aAddToCache;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetMsgIsInLocalCache(PRBool *aMsgIsInLocalCache)
{
NS_ENSURE_ARG(aMsgIsInLocalCache);
*aMsgIsInLocalCache = m_msgIsInLocalCache;
return NS_OK;
*aMsgIsInLocalCache = m_msgIsInLocalCache;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetMsgIsInLocalCache(PRBool aMsgIsInLocalCache)
{
m_msgIsInLocalCache = aMsgIsInLocalCache;
return NS_OK;
m_msgIsInLocalCache = aMsgIsInLocalCache;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetSuppressErrorMsgs(PRBool *aSuppressErrorMsgs)
{
NS_ENSURE_ARG(aSuppressErrorMsgs);
*aSuppressErrorMsgs = m_suppressErrorMsgs;
return NS_OK;
*aSuppressErrorMsgs = m_suppressErrorMsgs;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetSuppressErrorMsgs(PRBool aSuppressErrorMsgs)
{
m_suppressErrorMsgs = aSuppressErrorMsgs;
return NS_OK;
m_suppressErrorMsgs = aSuppressErrorMsgs;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::IsUrlType(PRUint32 type, PRBool *isType)
{
//base class doesn't know about any specific types
NS_ENSURE_ARG(isType);
*isType = PR_FALSE;
return NS_OK;
//base class doesn't know about any specific types
NS_ENSURE_ARG(isType);
*isType = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetSearchSession(nsIMsgSearchSession *aSearchSession)
{
if (aSearchSession)
m_searchSession = do_QueryInterface(aSearchSession);
return NS_OK;
if (aSearchSession)
m_searchSession = do_QueryInterface(aSearchSession);
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetSearchSession(nsIMsgSearchSession **aSearchSession)
{
NS_ENSURE_ARG(aSearchSession);
*aSearchSession = m_searchSession;
NS_IF_ADDREF(*aSearchSession);
return NS_OK;
*aSearchSession = m_searchSession;
NS_IF_ADDREF(*aSearchSession);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////////
@ -410,7 +407,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetSearchSession(nsIMsgSearchSession **aSearchSe
NS_IMETHODIMP nsMsgMailNewsUrl::GetSpec(nsACString &aSpec)
{
return m_baseURL->GetSpec(aSpec);
return m_baseURL->GetSpec(aSpec);
}
#define FILENAME_PART "&filename="
@ -423,7 +420,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::SetSpec(const nsACString &aSpec)
char *start, *end;
start = PL_strcasestr(spec.BeginWriting(),FILENAME_PART);
if (start)
{ // Make sure we only get our own value.
{ // Make sure we only get our own value.
end = PL_strcasestr((char*)(start+FILENAME_PART_LEN),"&");
if (end)
{
@ -440,89 +437,89 @@ NS_IMETHODIMP nsMsgMailNewsUrl::SetSpec(const nsACString &aSpec)
NS_IMETHODIMP nsMsgMailNewsUrl::GetPrePath(nsACString &aPrePath)
{
return m_baseURL->GetPrePath(aPrePath);
return m_baseURL->GetPrePath(aPrePath);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetScheme(nsACString &aScheme)
{
return m_baseURL->GetScheme(aScheme);
return m_baseURL->GetScheme(aScheme);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetScheme(const nsACString &aScheme)
{
return m_baseURL->SetScheme(aScheme);
return m_baseURL->SetScheme(aScheme);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetUserPass(nsACString &aUserPass)
{
return m_baseURL->GetUserPass(aUserPass);
return m_baseURL->GetUserPass(aUserPass);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetUserPass(const nsACString &aUserPass)
{
return m_baseURL->SetUserPass(aUserPass);
return m_baseURL->SetUserPass(aUserPass);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetUsername(nsACString &aUsername)
{
/* note: this will return an escaped string */
return m_baseURL->GetUsername(aUsername);
/* note: this will return an escaped string */
return m_baseURL->GetUsername(aUsername);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetUsername(const nsACString &aUsername)
{
return m_baseURL->SetUsername(aUsername);
return m_baseURL->SetUsername(aUsername);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetPassword(nsACString &aPassword)
{
return m_baseURL->GetPassword(aPassword);
return m_baseURL->GetPassword(aPassword);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetPassword(const nsACString &aPassword)
{
return m_baseURL->SetPassword(aPassword);
return m_baseURL->SetPassword(aPassword);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetHostPort(nsACString &aHostPort)
{
return m_baseURL->GetHostPort(aHostPort);
return m_baseURL->GetHostPort(aHostPort);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetHostPort(const nsACString &aHostPort)
{
return m_baseURL->SetHostPort(aHostPort);
return m_baseURL->SetHostPort(aHostPort);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetHost(nsACString &aHost)
{
return m_baseURL->GetHost(aHost);
return m_baseURL->GetHost(aHost);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetHost(const nsACString &aHost)
{
return m_baseURL->SetHost(aHost);
return m_baseURL->SetHost(aHost);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetPort(PRInt32 *aPort)
{
return m_baseURL->GetPort(aPort);
return m_baseURL->GetPort(aPort);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetPort(PRInt32 aPort)
{
return m_baseURL->SetPort(aPort);
return m_baseURL->SetPort(aPort);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetPath(nsACString &aPath)
{
return m_baseURL->GetPath(aPath);
return m_baseURL->GetPath(aPath);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetPath(const nsACString &aPath)
{
return m_baseURL->SetPath(aPath);
return m_baseURL->SetPath(aPath);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetAsciiHost(nsACString &aHostA)
@ -590,7 +587,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::Clone(nsIURI **_retval)
rv = GetSpec(urlSpec);
if (NS_FAILED(rv)) return rv;
return ioService->NewURI(urlSpec, nsnull, nsnull, _retval);
}
}
NS_IMETHODIMP nsMsgMailNewsUrl::Resolve(const nsACString &relativePath, nsACString &result)
{
@ -626,13 +623,13 @@ NS_IMETHODIMP nsMsgMailNewsUrl::Resolve(const nsACString &relativePath, nsACStri
NS_IMETHODIMP nsMsgMailNewsUrl::GetDirectory(nsACString &aDirectory)
{
return m_baseURL->GetDirectory(aDirectory);
return m_baseURL->GetDirectory(aDirectory);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetDirectory(const nsACString &aDirectory)
{
return m_baseURL->SetDirectory(aDirectory);
return m_baseURL->SetDirectory(aDirectory);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetFileName(nsACString &aFileName)
@ -647,12 +644,12 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetFileName(nsACString &aFileName)
NS_IMETHODIMP nsMsgMailNewsUrl::GetFileBaseName(nsACString &aFileBaseName)
{
return m_baseURL->GetFileBaseName(aFileBaseName);
return m_baseURL->GetFileBaseName(aFileBaseName);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetFileBaseName(const nsACString &aFileBaseName)
{
return m_baseURL->SetFileBaseName(aFileBaseName);
return m_baseURL->SetFileBaseName(aFileBaseName);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetFileExtension(nsACString &aFileExtension)
@ -673,7 +670,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetFileExtension(nsACString &aFileExtension)
NS_IMETHODIMP nsMsgMailNewsUrl::SetFileExtension(const nsACString &aFileExtension)
{
return m_baseURL->SetFileExtension(aFileExtension);
return m_baseURL->SetFileExtension(aFileExtension);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetFileName(const nsACString &aFileName)
@ -684,42 +681,42 @@ NS_IMETHODIMP nsMsgMailNewsUrl::SetFileName(const nsACString &aFileName)
NS_IMETHODIMP nsMsgMailNewsUrl::GetParam(nsACString &aParam)
{
return m_baseURL->GetParam(aParam);
return m_baseURL->GetParam(aParam);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetParam(const nsACString &aParam)
{
return m_baseURL->SetParam(aParam);
return m_baseURL->SetParam(aParam);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetQuery(nsACString &aQuery)
{
return m_baseURL->GetQuery(aQuery);
return m_baseURL->GetQuery(aQuery);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetQuery(const nsACString &aQuery)
{
return m_baseURL->SetQuery(aQuery);
return m_baseURL->SetQuery(aQuery);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetRef(nsACString &aRef)
{
return m_baseURL->GetRef(aRef);
return m_baseURL->GetRef(aRef);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetRef(const nsACString &aRef)
{
return m_baseURL->SetRef(aRef);
return m_baseURL->SetRef(aRef);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetFilePath(nsACString &o_DirFile)
{
return m_baseURL->GetFilePath(o_DirFile);
return m_baseURL->GetFilePath(o_DirFile);
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetFilePath(const nsACString &i_DirFile)
{
return m_baseURL->SetFilePath(i_DirFile);
return m_baseURL->SetFilePath(i_DirFile);
}
NS_IMETHODIMP nsMsgMailNewsUrl::GetCommonBaseSpec(nsIURI *uri2, nsACString &result)
@ -1009,13 +1006,13 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetFolder(nsIMsgFolder ** /* aFolder */)
NS_IMETHODIMP nsMsgMailNewsUrl::GetMsgHeaderSink(nsIMsgHeaderSink * *aMsgHdrSink)
{
NS_ENSURE_ARG_POINTER(aMsgHdrSink);
NS_IF_ADDREF(*aMsgHdrSink = mMsgHeaderSink);
return NS_OK;
NS_ENSURE_ARG_POINTER(aMsgHdrSink);
NS_IF_ADDREF(*aMsgHdrSink = mMsgHeaderSink);
return NS_OK;
}
NS_IMETHODIMP nsMsgMailNewsUrl::SetMsgHeaderSink(nsIMsgHeaderSink * aMsgHdrSink)
{
mMsgHeaderSink = aMsgHdrSink;
return NS_OK;
mMsgHeaderSink = aMsgHdrSink;
return NS_OK;
}

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

@ -364,8 +364,8 @@ nsSmtpServer::GetPassword(char * *aPassword)
GetHostname(getter_Copies(hostName));
GetUsername(getter_Copies(userName));
if (useMatchingHostNameServer)
// pass in empty type, to match imap and pop3.
accountManager->FindRealServer(userName, hostName, "", getter_AddRefs(incomingServerToUse));
// pass in empty type and port=0, to match imap and pop3.
accountManager->FindRealServer(userName, hostName, "", 0, getter_AddRefs(incomingServerToUse));
PRInt32 dotPos = -1;
if (!incomingServerToUse && useMatchingDomainServer
&& (dotPos = hostName.FindChar('.')) != kNotFound)

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

@ -2635,22 +2635,14 @@ nsresult nsImapService::CreateSubscribeURI(nsIMsgIncomingServer *server, char *f
}
// this method first tries to find an exact username and hostname match with the given url
// then, tries to find any accoutn on the passed in imap host in case this is a url to
// then, tries to find any account on the passed in imap host in case this is a url to
// a shared imap folder.
nsresult nsImapService::GetServerFromUrl(nsIImapUrl *aImapUrl, nsIMsgIncomingServer **aServer)
{
nsCAutoString userPass;
nsCAutoString hostName;
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(aImapUrl);
// extract the user name and host name information...
nsresult rv = mailnewsUrl->GetAsciiHost(hostName);
if (NS_FAILED(rv)) return rv;
rv = mailnewsUrl->GetUserPass(userPass);
if (NS_FAILED(rv)) return rv;
if (!userPass.IsEmpty())
NS_UnescapeURL(userPass); // hopefully we're not unescaping ':' or nasty control chars
nsresult rv;
nsXPIDLCString folderName;
@ -2666,7 +2658,7 @@ nsresult nsImapService::GetServerFromUrl(nsIImapUrl *aImapUrl, nsIMsgIncomingSer
if (NS_FAILED(rv))
return rv;
rv = accountManager->FindServer(userPass.get(), hostName.get(), "imap", aServer);
rv = accountManager->FindServerByURI(mailnewsUrl, PR_FALSE, aServer);
// look for server with any user name, in case we're trying to subscribe
// to a folder with some one else's user name like the following
@ -2674,7 +2666,16 @@ nsresult nsImapService::GetServerFromUrl(nsIImapUrl *aImapUrl, nsIMsgIncomingSer
if (NS_FAILED(rv) || !aServer)
{
rv = accountManager->FindServer("", hostName.get(), "imap", aServer);
nsCAutoString turl;
nsCOMPtr<nsIURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
mailnewsUrl->GetSpec(turl);
rv = url->SetSpec(turl);
if (NS_FAILED(rv)) return rv;
url->SetUserPass(NS_LITERAL_CSTRING(""));
rv = accountManager->FindServerByURI(url, PR_FALSE, aServer);
if (*aServer)
aImapUrl->SetExternalLinkUrl(PR_TRUE);
}

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

@ -44,6 +44,7 @@
#include "prsystem.h"
#include "nsEscape.h"
#include "nsIFileSpec.h"
#include "nsNetCID.h"
// stuff for temporary root folder hack
#include "nsIMsgAccountManager.h"
@ -61,11 +62,15 @@ nsImapURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult)
nsresult rv;
nsAutoString sbdSep;
nsCOMPtr<nsIURL> url;
rv = nsGetMailFolderSeparator(sbdSep);
if (NS_FAILED(rv))
return rv;
url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsCAutoString uri(uriStr);
if (uri.Find(rootURI) != 0) // if doesn't start with rootURI
return NS_ERROR_FAILURE;
@ -77,56 +82,23 @@ nsImapURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult)
rv = NS_ERROR_FAILURE;
}
// the server name is the first component of the path, so extract it out
PRInt32 hostStart;
hostStart = uri.FindChar('/');
if (hostStart <= 0) return NS_ERROR_FAILURE;
// skip past all //
while (uri.CharAt(hostStart) =='/') hostStart++;
// cut imap://[userid@]hostname/folder -> [userid@]hostname/folder
nsCAutoString hostname;
uri.Right(hostname, uri.Length() - hostStart);
nsCAutoString username;
PRInt32 atPos = hostname.FindChar('@');
if (atPos != -1) {
hostname.Left(username, atPos);
hostname.Cut(0, atPos+1);
}
// Set our url to the string given
rv = url->SetSpec(nsDependentCString(uriStr));
if (NS_FAILED(rv)) return rv;
// Set the folder to the url path
nsCAutoString folder;
// folder comes after the hostname, after the '/'
// cut off first '/' and everything following it
// hostname/folder -> hostname
PRInt32 hostEnd = hostname.FindChar('/');
if (hostEnd > 0)
{
hostname.Right(folder, hostname.Length() - hostEnd - 1);
hostname.Truncate(hostEnd);
}
rv = url->GetPath(folder);
// Now find the server from the URL
nsCOMPtr<nsIMsgIncomingServer> server;
nsCOMPtr<nsIMsgAccountManager> accountManager =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
if(NS_FAILED(rv)) return rv;
char *unescapedUserName = ToNewCString(username);
if (unescapedUserName)
{
nsUnescape(unescapedUserName);
rv = accountManager->FindServer(unescapedUserName,
hostname.get(),
"imap",
getter_AddRefs(server));
PR_Free(unescapedUserName);
}
else
rv = NS_ERROR_OUT_OF_MEMORY;
rv = accountManager->FindServerByURI(url, PR_FALSE,
getter_AddRefs(server));
if (NS_FAILED(rv)) return rv;
if (server)

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

@ -49,7 +49,7 @@
#include "msgCore.h" // precompiled header...
#include "nsLocalMailFolder.h"
#include "nsLocalMailFolder.h"
#include "nsMsgLocalFolderHdrs.h"
#include "nsMsgFolderFlags.h"
#include "nsMsgMessageFlags.h"
@ -110,7 +110,7 @@
#include "nsIRssIncomingServer.h"
static NS_DEFINE_CID(kMailboxServiceCID, NS_MAILBOXSERVICE_CID);
static NS_DEFINE_CID(kMailboxServiceCID, NS_MAILBOXSERVICE_CID);
static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID);
//////////////////////////////////////////////////////////////////////////////
@ -850,14 +850,14 @@ nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow
safeFolderName.Assign(nativeFolderName.get());
NS_MsgHashIfNecessary(safeFolderName);
path += safeFolderName.get();
path += safeFolderName.get();
if (path.Exists()) //check this because localized names are different from disk names
{
ThrowAlertMsg("folderExists", msgWindow);
return NS_MSG_FOLDER_EXISTS;
}
nsOutputFileStream outputStream(path, PR_WRONLY | PR_CREATE_FILE, 00600);
nsOutputFileStream outputStream(path, PR_WRONLY | PR_CREATE_FILE, 00600);
if (outputStream.is_open())
{
outputStream.flush();
@ -873,7 +873,7 @@ nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow
path.Delete(PR_FALSE);
return rv;
}
// Create an empty database for this mail folder, set its name from the user
nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
if (msgDBService)
@ -1349,7 +1349,7 @@ nsMsgLocalMailFolder::GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo, nsIMsgD
{
nsresult openErr=NS_ERROR_UNEXPECTED;
if(!db || !folderInfo || !mPath || mIsServer)
return NS_ERROR_NULL_POINTER; //ducarroz: should we use NS_ERROR_INVALID_ARG?
return NS_ERROR_NULL_POINTER; //ducarroz: should we use NS_ERROR_INVALID_ARG?
nsresult rv;
if (mDatabase)
@ -1543,7 +1543,7 @@ nsMsgLocalMailFolder::DeleteMessages(nsISupportsArray *messages,
return rv;
}
else
{
{
rv = GetDatabase(msgWindow);
if(NS_SUCCEEDED(rv))
{
@ -1846,13 +1846,13 @@ nsMsgLocalMailFolder::CopyMessages(nsIMsgFolder* srcFolder, nsISupportsArray*
// for srcFolder that are on different server than the dstFolder.
nsresult
nsMsgLocalMailFolder::CopyFolderAcrossServer(nsIMsgFolder* srcFolder, nsIMsgWindow *msgWindow,
nsIMsgCopyServiceListener *listener )
nsIMsgCopyServiceListener *listener )
{
mInitialized = PR_TRUE;
nsXPIDLString folderName;
srcFolder->GetName(getter_Copies(folderName));
nsresult rv = CreateSubfolder(folderName, msgWindow);
if (NS_FAILED(rv)) return rv;
@ -1902,7 +1902,7 @@ nsMsgLocalMailFolder::CopyFolderAcrossServer(nsIMsgFolder* srcFolder, nsIMsgWind
localFolder->CopyAllSubFolders(srcFolder, msgWindow, listener);
return localFolder->OnCopyCompleted(srcSupports, PR_TRUE);
}
}
}
return NS_OK; // otherwise the front-end will say Exception::CopyFolder
}
@ -1941,7 +1941,7 @@ nsMsgLocalMailFolder::CopyFolder( nsIMsgFolder* srcFolder, PRBool isMoveFolder,
rv = CopyFolderLocal(srcFolder, isMoveFolder, msgWindow, listener );
else
rv = CopyFolderAcrossServer(srcFolder, msgWindow, listener );
return rv;
}
@ -1981,7 +1981,7 @@ nsMsgLocalMailFolder::CopyFolderLocal(nsIMsgFolder *srcFolder, PRBool isMoveFold
nsXPIDLString folderName;
srcFolder->GetName(getter_Copies(folderName));
srcFolder->ForceDBClosed();
srcFolder->ForceDBClosed();
nsCOMPtr<nsIFileSpec> oldPathSpec;
rv = srcFolder->GetPath(getter_AddRefs(oldPathSpec));
@ -1991,7 +1991,7 @@ nsMsgLocalMailFolder::CopyFolderLocal(nsIMsgFolder *srcFolder, PRBool isMoveFold
rv = oldPathSpec->GetFileSpec(&oldPath);
NS_ENSURE_SUCCESS(rv,rv);
nsLocalFolderSummarySpec summarySpec(oldPath);
nsLocalFolderSummarySpec summarySpec(oldPath);
nsCOMPtr<nsIFileSpec> newPathSpec;
rv = GetPath(getter_AddRefs(newPathSpec));
@ -2244,14 +2244,14 @@ nsresult nsMsgLocalMailFolder::WriteStartOfNewMessage()
curSourceMessage = do_QueryElementAt(mCopyState->m_messages,
mCopyState->m_curCopyIndex, &rv);
char statusStrBuf[50];
char statusStrBuf[50];
if (curSourceMessage)
{
PRUint32 dbFlags = 0;
PRUint32 dbFlags = 0;
curSourceMessage->GetFlags(&dbFlags);
// write out x-mozilla-status, but make sure we don't write out MSG_FLAG_OFFLINE
PR_snprintf(statusStrBuf, sizeof(statusStrBuf), X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK,
PR_snprintf(statusStrBuf, sizeof(statusStrBuf), X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK,
dbFlags & ~(MSG_FLAG_RUNTIME_ONLY | MSG_FLAG_OFFLINE) & 0x0000FFFF);
// need to carry the new flag over to the new header.
if (dbFlags & MSG_FLAG_NEW)
@ -2305,7 +2305,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::BeginCopy(nsIMsgDBHdr *message)
DisplayMoveCopyStatusMsg();
// if we're copying more than one message, StartMessage will handle this.
if (!mCopyState->m_copyingMultipleMessages)
rv = WriteStartOfNewMessage();
rv = WriteStartOfNewMessage();
return rv;
}
@ -2346,7 +2346,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::CopyData(nsIInputStream *aIStream, PRInt32 a
start = mCopyState->m_dataBuffer;
end = (char *) memchr(start, '\r', mCopyState->m_leftOver);
if (!end)
end = (char *) memchr(start, '\n', mCopyState->m_leftOver);
end = (char *) memchr(start, '\n', mCopyState->m_leftOver);
else if (*(end+1) == nsCRT::LF && linebreak_len == 0)
linebreak_len = 2;
@ -2573,8 +2573,8 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndCopy(PRBool copySucceeded)
localUndoTxn->AddDstMsgSize(msgSize);
}
}
// msgDb->SetSummaryValid(PR_TRUE);
// msgDb->Commit(nsMsgDBCommitType::kLargeCommit);
// msgDb->SetSummaryValid(PR_TRUE);
// msgDb->Commit(nsMsgDBCommitType::kLargeCommit);
}
else
mCopyState->m_undoMsgTxn = nsnull; //null out the transaction because we can't undo w/o the msg db
@ -2613,7 +2613,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndCopy(PRBool copySucceeded)
txnMgr->DoTransaction(mCopyState->m_undoMsgTxn);
}
if (srcFolder && !mCopyState->m_isFolder)
srcFolder->NotifyFolderEvent(mDeleteOrMoveMsgCompletedAtom);
srcFolder->NotifyFolderEvent(mDeleteOrMoveMsgCompletedAtom);
(void) OnCopyCompleted(mCopyState->m_srcSupport, PR_TRUE);
// enable the dest folder
@ -3114,27 +3114,12 @@ nsMsgLocalMailFolder::GetIncomingServerType()
if (mType) return mType;
// this is totally hacky - we have to re-parse the URI, then
// guess at "none" or "pop3"
// if anyone has any better ideas mail me! -alecf@netscape.com
nsCOMPtr<nsIURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_FAILED(rv)) return "";
rv = url->SetSpec(nsDependentCString(mURI));
if (NS_FAILED(rv)) return "";
nsCAutoString userPass;
rv = url->GetUserPass(userPass);
if (NS_FAILED(rv)) return "";
if (!userPass.IsEmpty())
nsUnescape(userPass.BeginWriting());
nsCAutoString hostName;
rv = url->GetAsciiHost(hostName);
if (NS_FAILED(rv)) return "";
if (!hostName.IsEmpty())
nsUnescape(hostName.BeginWriting());
nsCOMPtr<nsIMsgAccountManager> accountManager =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return "";
@ -3142,9 +3127,8 @@ nsMsgLocalMailFolder::GetIncomingServerType()
nsCOMPtr<nsIMsgIncomingServer> server;
// try "none" first
rv = accountManager->FindServer(userPass.get(),
hostName.get(),
"none",
url->SetScheme(NS_LITERAL_CSTRING("none"));
rv = accountManager->FindServerByURI(url, PR_FALSE,
getter_AddRefs(server));
if (NS_SUCCEEDED(rv) && server)
{
@ -3153,9 +3137,8 @@ nsMsgLocalMailFolder::GetIncomingServerType()
}
// next try "pop3"
rv = accountManager->FindServer(userPass.get(),
hostName.get(),
"pop3",
url->SetScheme(NS_LITERAL_CSTRING("pop3"));
rv = accountManager->FindServerByURI(url, PR_FALSE,
getter_AddRefs(server));
if (NS_SUCCEEDED(rv) && server)
{
@ -3164,9 +3147,8 @@ nsMsgLocalMailFolder::GetIncomingServerType()
}
// next try "rss"
rv = accountManager->FindServer(userPass.get(),
hostName.get(),
"rss",
url->SetScheme(NS_LITERAL_CSTRING("rss"));
rv = accountManager->FindServerByURI(url, PR_FALSE,
getter_AddRefs(server));
if (NS_SUCCEEDED(rv) && server)
{
@ -3176,9 +3158,8 @@ nsMsgLocalMailFolder::GetIncomingServerType()
#ifdef HAVE_MOVEMAIL
// next try "movemail"
rv = accountManager->FindServer(userPass.get(),
hostName.get(),
"movemail",
url->SetScheme(NS_LITERAL_CSTRING("movemail");
rv = accountManager->FindServerByURI(url, PR_FALSE,
getter_AddRefs(server));
if (NS_SUCCEEDED(rv) && server)
{
@ -3230,7 +3211,7 @@ nsMsgLocalMailFolder::OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode)
{
nsresult rv;
nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIMsgWindow> msgWindow;
rv = mailSession->GetTopmostMsgWindow(getter_AddRefs(msgWindow));
nsCAutoString aSpec;
@ -3311,12 +3292,12 @@ nsresult nsMsgLocalMailFolder::DisplayMoveCopyStatusMsg()
{
// get msgWindow from undo txn
nsCOMPtr<nsIMsgWindow> msgWindow;
nsresult rv;
nsresult rv;
if (mCopyState->m_undoMsgTxn)
{
nsCOMPtr<nsLocalMoveCopyMsgTxn> localUndoTxn;
localUndoTxn = do_QueryInterface(mCopyState->m_undoMsgTxn, &rv);
nsCOMPtr<nsLocalMoveCopyMsgTxn> localUndoTxn;
localUndoTxn = do_QueryInterface(mCopyState->m_undoMsgTxn, &rv);
if (NS_SUCCEEDED(rv))
localUndoTxn->GetMsgWindow(getter_AddRefs(msgWindow));
NS_ASSERTION(msgWindow, "no msg window");
@ -3390,7 +3371,7 @@ nsMsgLocalMailFolder::SetFlagsOnDefaultMailboxes(PRUint32 flags)
if (flags & MSG_FOLDER_FLAG_QUEUE)
setSubfolderFlag(NS_LITERAL_STRING("Unsent Messages").get(), MSG_FOLDER_FLAG_QUEUE);
if (flags & MSG_FOLDER_FLAG_JUNK)
setSubfolderFlag(NS_LITERAL_STRING("Junk").get(), MSG_FOLDER_FLAG_JUNK);

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

@ -52,19 +52,23 @@
#include "nsMsgBaseCID.h"
#include "nsMsgUtils.h"
#include "nsNetCID.h"
// it would be really cool to:
// - cache the last hostname->path match
// - if no such server exists, behave like an old-style mailbox URL
// (i.e. return the mail.directory preference or something)
static nsresult
nsGetMailboxServer(char *username, char *hostname, nsIMsgIncomingServer** aResult)
nsGetMailboxServer(const char *uriStr, nsIMsgIncomingServer** aResult)
{
nsresult rv = NS_OK;
nsUnescape(username);
nsUnescape(hostname);
nsCOMPtr<nsIURL> aUrl = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
rv = aUrl->SetSpec(nsDependentCString(uriStr));
if (NS_FAILED(rv)) return rv;
// retrieve the AccountManager
nsCOMPtr<nsIMsgAccountManager> accountManager =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
@ -72,39 +76,35 @@ nsGetMailboxServer(char *username, char *hostname, nsIMsgIncomingServer** aResul
// find all local mail "no servers" matching the given hostname
nsCOMPtr<nsIMsgIncomingServer> none_server;
rv = accountManager->FindServer(username,
hostname,
"none",
getter_AddRefs(none_server));
aUrl->SetScheme(NS_LITERAL_CSTRING("none"));
// No unescaping of username or hostname done here.
// The unescaping is done inside of FindServerByURI
rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
getter_AddRefs(none_server));
if (NS_SUCCEEDED(rv)) {
*aResult = none_server;
NS_ADDREF(*aResult);
NS_ADDREF(*aResult = none_server);
return rv;
}
// if that fails, look for the rss hosts matching the given hostname
nsCOMPtr<nsIMsgIncomingServer> rss_server;
rv = accountManager->FindServer(username,
hostname,
"rss",
getter_AddRefs(rss_server));
aUrl->SetScheme(NS_LITERAL_CSTRING("rss"));
rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
getter_AddRefs(rss_server));
if (NS_SUCCEEDED(rv))
{
*aResult = rss_server;
NS_ADDREF(*aResult);
NS_ADDREF(*aResult = rss_server);
return rv;
}
#ifdef HAVE_MOVEMAIL
// find all movemail "servers" matching the given hostname
nsCOMPtr<nsIMsgIncomingServer> movemail_server;
rv = accountManager->FindServer(username,
hostname,
"movemail",
aUrl->SetScheme(NS_LITERAL_CSTRING("movemail"));
rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
getter_AddRefs(movemail_server));
if (NS_SUCCEEDED(rv)) {
*aResult = movemail_server;
NS_ADDREF(*aResult);
return rv;
NS_ADDREF(*aResult = movemail_server);
return rv;
}
#endif /* HAVE_MOVEMAIL */
@ -112,27 +112,24 @@ nsGetMailboxServer(char *username, char *hostname, nsIMsgIncomingServer** aResul
nsCOMPtr<nsIMsgIncomingServer> server;
if (NS_FAILED(rv))
{
rv = accountManager->FindServer(username,
hostname,
"pop3",
getter_AddRefs(server));
aUrl->SetScheme(NS_LITERAL_CSTRING("pop3"));
rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
getter_AddRefs(server));
// if we can't find a pop server, maybe it's a local message
// in an imap hiearchy. look for an imap server.
// in an imap hierarchy. look for an imap server.
if (NS_FAILED(rv))
{
rv = accountManager->FindServer(username,
hostname,
"imap",
getter_AddRefs(server));
aUrl->SetScheme(NS_LITERAL_CSTRING("imap"));
rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
getter_AddRefs(server));
}
}
if (NS_SUCCEEDED(rv))
{
*aResult = server;
NS_ADDREF(*aResult);
return rv;
}
NS_ADDREF(*aResult = server);
return rv;
}
// if you fail after looking at all "pop3", "movemail" and "none" servers, you fail.
return rv;
@ -144,60 +141,11 @@ nsLocalURI2Server(const char* uriStr,
{
nsresult rv;
// start parsing the uriStr
const char* curPos = uriStr;
// skip past schema xxx://
while (*curPos != ':') curPos++;
curPos++;
while (*curPos == '/') curPos++;
// extract userid from userid@hostname...
// this is so amazingly ugly, please forgive me....
// I'll fix this post-M7 -alecf@netscape.com
char *atPos = PL_strchr(curPos, '@');
NS_ASSERTION(atPos!=nsnull, "URI with no userid!");
int length;
if (atPos)
length = (atPos - curPos) + 1;
else {
length = 1;
}
char *username = new char[length];
if (!username) return NS_ERROR_OUT_OF_MEMORY;
if (atPos) {
PL_strncpyz(username, curPos, length);
curPos = atPos;
curPos++;
}
else
username[0] = '\0';
// extract hostname
char *slashPos = PL_strchr(curPos, '/');
// if there are no more /'s then we just copy the rest of the string
if (slashPos)
length = (slashPos - curPos) + 1;
else
length = PL_strlen(curPos) + 1;
char* hostname = new char[length];
if(!hostname)
return NS_ERROR_OUT_OF_MEMORY;
PL_strncpyz(hostname, curPos, length);
nsCOMPtr<nsIMsgIncomingServer> server;
rv = nsGetMailboxServer(username, hostname, getter_AddRefs(server));
delete[] username;
delete[] hostname;
rv = nsGetMailboxServer(uriStr, getter_AddRefs(server));
*aResult = server;
NS_IF_ADDREF(*aResult);
NS_IF_ADDREF(*aResult = server);
return rv;
}
@ -226,7 +174,7 @@ nsLocalURI2Path(const char* rootURI, const char* uriStr,
rv = nsLocalURI2Server(uriStr, getter_AddRefs(server));
if (NS_FAILED(rv))
return rv;
return rv;
// now ask the server what it's root is
// and begin pathResult with the mailbox root
@ -275,62 +223,62 @@ nsresult nsParseLocalMessageURI(const char* uri,
nsCString& folderURI,
PRUint32 *key)
{
if(!key)
return NS_ERROR_NULL_POINTER;
if(!key)
return NS_ERROR_NULL_POINTER;
nsCAutoString uriStr(uri);
PRInt32 keySeparator = uriStr.FindChar('#');
if(keySeparator != -1)
{
nsCAutoString uriStr(uri);
PRInt32 keySeparator = uriStr.FindChar('#');
if(keySeparator != -1)
{
PRInt32 keyEndSeparator = uriStr.FindCharInSet("?&",
keySeparator);
nsAutoString folderPath;
uriStr.Left(folderURI, keySeparator);
nsAutoString folderPath;
uriStr.Left(folderURI, keySeparator);
folderURI.Cut(7, 8); // cut out the -message part of mailbox-message:
nsCAutoString keyStr;
nsCAutoString keyStr;
if (keyEndSeparator != -1)
uriStr.Mid(keyStr, keySeparator+1,
keyEndSeparator-(keySeparator+1));
else
uriStr.Right(keyStr, uriStr.Length() - (keySeparator + 1));
PRInt32 errorCode;
*key = keyStr.ToInteger(&errorCode);
PRInt32 errorCode;
*key = keyStr.ToInteger(&errorCode);
return errorCode;
}
return NS_ERROR_FAILURE;
return errorCode;
}
return NS_ERROR_FAILURE;
}
nsresult nsBuildLocalMessageURI(const char *baseURI, PRUint32 key, nsCString& uri)
{
// need to convert mailbox://hostname/.. to mailbox-message://hostname/..
// need to convert mailbox://hostname/.. to mailbox-message://hostname/..
uri.Append(baseURI);
uri.Append('#');
uri.AppendInt(key);
return NS_OK;
uri.Append(baseURI);
uri.Append('#');
uri.AppendInt(key);
return NS_OK;
}
nsresult nsCreateLocalBaseMessageURI(const char *baseURI, char **baseMessageURI)
{
if(!baseMessageURI)
return NS_ERROR_NULL_POINTER;
if(!baseMessageURI)
return NS_ERROR_NULL_POINTER;
nsCAutoString tailURI(baseURI);
nsCAutoString tailURI(baseURI);
// chop off mailbox:/
if (tailURI.Find(kMailboxRootURI) == 0)
tailURI.Cut(0, PL_strlen(kMailboxRootURI));
nsCAutoString baseURIStr(kMailboxMessageRootURI);
baseURIStr += tailURI;
// chop off mailbox:/
if (tailURI.Find(kMailboxRootURI) == 0)
tailURI.Cut(0, PL_strlen(kMailboxRootURI));
nsCAutoString baseURIStr(kMailboxMessageRootURI);
baseURIStr += tailURI;
*baseMessageURI = ToNewCString(baseURIStr);
if(!*baseMessageURI)
return NS_ERROR_OUT_OF_MEMORY;
*baseMessageURI = ToNewCString(baseURIStr);
if(!*baseMessageURI)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
return NS_OK;
}

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

@ -619,29 +619,15 @@ nsNntpService::GetFolderFromUri(const char *aUri, nsIMsgFolder **aFolder)
nsresult rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(aUri));
NS_ENSURE_SUCCESS(rv,rv);
nsCAutoString hostName;
rv = uri->GetAsciiHost(hostName);
NS_ENSURE_SUCCESS(rv,rv);
nsCAutoString path;
rv = uri->GetPath(path);
NS_ENSURE_SUCCESS(rv,rv);
nsCAutoString userPass;
rv = uri->GetUserPass(userPass);
NS_ENSURE_SUCCESS(rv,rv);
char *unescapedUserPass = ToNewCString(userPass);
if (!unescapedUserPass)
return NS_ERROR_OUT_OF_MEMORY;
nsUnescape(unescapedUserPass);
nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr <nsIMsgIncomingServer> server;
rv = accountManager->FindServer(unescapedUserPass, hostName.get(), "nntp", getter_AddRefs(server));
PR_Free(unescapedUserPass);
rv = accountManager->FindServerByURI(uri, PR_FALSE, getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr <nsIMsgFolder> rootFolder;
@ -1136,17 +1122,13 @@ nsNntpService::GetProtocolForUri(nsIURI *aUri, nsIMsgWindow *aMsgWindow, nsINNTP
//
// xxx todo what if we have two servers on the same host, but different ports?
// or no port, but isSecure (snews:// vs news://) is different?
rv = accountManager->FindServer("",
hostName.get(),
"nntp",
rv = accountManager->FindServerByURI(aUri, PR_FALSE,
getter_AddRefs(server));
if (!server)
{
// try the "real" settings ("realservername" and "realusername")
rv = accountManager->FindRealServer("",
hostName.get(),
"nntp",
rv = accountManager->FindServerByURI(aUri, PR_TRUE,
getter_AddRefs(server));
}
@ -1159,7 +1141,7 @@ nsNntpService::GetProtocolForUri(nsIURI *aUri, nsIMsgWindow *aMsgWindow, nsINNTP
NS_ENSURE_SUCCESS(rv,rv);
// until we support default news servers, use the first nntp server we find
rv = accountManager->FindServer("","","nntp", getter_AddRefs(server));
rv = accountManager->FindServerByURI(aUri, PR_FALSE, getter_AddRefs(server));
if (NS_FAILED(rv) || !server)
{
// step 2, set the uri's hostName and the local variable hostName