fix for bug #23457. when we create a new account, set the copies and folders prefs for the associated identity to the right defaults.

added to the nsIMsgProtocolInfo interface defaultCopiesAndFoldersPrefsToServer,
which we use to see for a given server type, do the defaults live on the server
or not (where not would mean "Local Folders").

fix the getFoldersWithFlag method in the nsIMsgFolder interface so it
would be easier to use in JS.

r=alecf
This commit is contained in:
sspitzer%netscape.com 2000-01-11 08:01:37 +00:00
parent b72546b14a
commit 9ca75194ad
16 changed files with 129 additions and 37 deletions

View File

@ -242,7 +242,7 @@ function createAccount(hash) {
/* new nntp identities should use plain text by default
* we wan't that GNKSA (The Good Net-Keeping Seal of Approval) */
if (type == "nntp") {
identity.composeHtml = false;
identity.composeHtml = false;
}
var account = am.createAccount();
@ -259,18 +259,75 @@ function createAccount(hash) {
localMailServer = am.FindServer("","","none");
}
catch (ex) {
dump("exception in findserver: " + ex + "\n");
// dump("exception in findserver: " + ex + "\n");
localMailServer = null;
}
// use server type to get the protocol info
var protocolinfo = Components.classes["component://netscape/messenger/protocol/info;type=" + server.type].getService(Components.interfaces.nsIMsgProtocolInfo);
// for this protocol, do we default the folder prefs to this server, or to the "Local Folders" server
defaultCopiesAndFoldersPrefsToServer = protocolinfo.defaultCopiesAndFoldersPrefsToServer;
if (!localMailServer) {
dump("Creating local mail\n");
// dump("Creating local mail account\n");
// creates a copy of the identity you pass in
am.createLocalMailAccount(identity, false);
}
// we'll need the "local folders" server to exist, if defaultCopiesAndFoldersPrefsToServer is false
// because that is where the copies and folders will live
if (!defaultCopiesAndFoldersPrefsToServer)
localMailServer = am.FindServer("","","none");
}
var copiesAndFoldersServer = null;
if (defaultCopiesAndFoldersPrefsToServer) {
copiesAndFoldersServer = server;
}
else {
if (!localMailServer) {
dump("error! we should have a local mail server at this point");
return;
}
copiesAndFoldersServer = localMailServer;
}
dump("finding folders on server = " + copiesAndFoldersServer.hostName + "\n");
var rootFolder = copiesAndFoldersServer.RootFolder;
// we need to do this or it is possible that the server's draft, stationery fcc folder
// will not be in rdf
//
// this can happen in a couple cases
// 1) the first account we create, creates the local mail. since local mail
// was just created, it obviously hasn't been opened, or in rdf..
// 2) the account we created is of a type where defaultCopiesAndFoldersPrefsToServer is true
// this since we are creating the server, it obviously hasn't been opened, or in rdf.
//
// this makes the assumption that the server's draft, stationery fcc folder
// are at the top level (ie subfolders of the root folder.) this works because
// we happen to be doing things that way, and if the user changes that, it will
// work because to change the folder, it must be in rdf, coming from the folder cache.
// in the worst case.
var folders = rootFolder.GetSubFolders();
var msgFolder = rootFolder.QueryInterface(Components.interfaces.nsIMsgFolder);
var numFolders = new Object();
// these hex values come from nsMsgFolderFlags.h
var draftFolder = msgFolder.getFoldersWithFlag(0x0400, 1, numFolders);
var stationeryFolder = msgFolder.getFoldersWithFlag(0x400000, 1, numFolders);
var fccFolder = msgFolder.getFoldersWithFlag(0x0200, 1, numFolders);
if (draftFolder) identity.draftFolder = draftFolder.URI;
if (stationeryFolder) identity.stationeryFolder = stationeryFolder.URI;
if (fccFolder) identity.fccFolder = fccFolder.URI;
dump("fccFolder = " + identity.fccFolder + "\n");
dump("draftFolder = " + identity.draftFolder + "\n");
dump("stationeryFolder = " + identity.stationeryFolder + "\n");
return true;
} catch (ex) {
// return false (meaning we did not create the account)
// on any error

View File

@ -224,7 +224,7 @@ interface nsIMsgFolder : nsIFolder {
readonly attribute unsigned long flags;
void getFoldersWithFlag(in unsigned long flags, out nsIMsgFolder result,
nsIMsgFolder getFoldersWithFlag(in unsigned long flags,
in unsigned long resultsize, out unsigned long numFolders);
void getExpansionArray(in nsISupportsArray expansionArray);

View File

@ -38,5 +38,6 @@ interface nsIMsgProtocolInfo : nsISupports
readonly attribute boolean preflightPrettyNameWithEmailAddress;
readonly attribute boolean canDelete;
readonly attribute boolean canDuplicate;
readonly attribute boolean defaultCopiesAndFoldersPrefsToServer;
};

View File

@ -668,12 +668,8 @@ function GetSelectTrashUri(folder)
dump("GetSelectTrashUri" + "\n");
var rootFolder = msgFolder.rootFolder;
var numFolder;
var out0 = new Object();
var trashFolder;
var out1 = new Object();
rootFolder.getFoldersWithFlag(0x0100, out0, 1, out1);
trashFolder = out0.value;
var out = new Object();
var trashFolder = rootFolder.getFoldersWithFlag(0x0100, 1, out);
numFolder = out1.value;
dump (numFolder + "\n");
if (trashFolder)

View File

@ -293,14 +293,9 @@ function loadStartFolder()
var rootMsgFolder = rootFolder.QueryInterface(Components.interfaces.nsIMsgFolder);
//now find Inbox
var inboxFolder;
var outInbox = new Object();
var outNumFolders = new Object();
rootMsgFolder.getFoldersWithFlag(0x1000, outInbox, 1, outNumFolders);
inboxFolder = outInbox.value;
if(!inboxFolder)
return;
var inboxFolder = rootMsgFolder.getFoldersWithFlag(0x1000, 1, outNumFolders);
if(!inboxFolder) return;
var resource = inboxFolder.QueryInterface(Components.interfaces.nsIRDFResource);
var inboxURI = resource.Value;

View File

@ -1310,8 +1310,7 @@ NS_IMETHODIMP nsMsgFolder::GetFlags(PRUint32 *_retval)
return NS_OK;
}
NS_IMETHODIMP nsMsgFolder::GetFoldersWithFlag(PRUint32 flags, nsIMsgFolder **result,
PRUint32 resultsize, PRUint32 *numFolders)
NS_IMETHODIMP nsMsgFolder::GetFoldersWithFlag(PRUint32 flags, PRUint32 resultsize, PRUint32 *numFolders, nsIMsgFolder **result)
{
PRUint32 num = 0;
if ((flags & mFlags) == flags) {
@ -1340,12 +1339,12 @@ NS_IMETHODIMP nsMsgFolder::GetFoldersWithFlag(PRUint32 flags, nsIMsgFolder **res
if (!result)
{
folder->GetFoldersWithFlag(flags, NULL, 0, &numSubFolders);
folder->GetFoldersWithFlag(flags, 0, &numSubFolders, NULL);
num += numSubFolders;
}
else if (num < resultsize)
{
folder->GetFoldersWithFlag(flags, result + num, resultsize - num, &numSubFolders);
folder->GetFoldersWithFlag(flags, resultsize - num, &numSubFolders, result+num);
num += numSubFolders;
}
else

View File

@ -122,7 +122,7 @@ public:
NS_IMETHOD ToggleFlag(PRUint32 flag);
NS_IMETHOD OnFlagChange(PRUint32 flag);
NS_IMETHOD GetFlags(PRUint32 *aFlags);
NS_IMETHOD GetFoldersWithFlag(PRUint32 flags, nsIMsgFolder **result, PRUint32 resultsize, PRUint32 *numFolders);
NS_IMETHOD GetFoldersWithFlag(PRUint32 flags, PRUint32 resultsize, PRUint32 *numFolders, nsIMsgFolder **result);
NS_IMETHOD GetExpansionArray(nsISupportsArray *expansionArray);
// NS_IMETHOD DeleteMessages(nsISupportsArray *message, nsITransactionManager *txnMgr, PRBool deleteStorage);
NS_IMETHOD CopyMessages(nsIMsgFolder *srcFolder, nsISupportsArray *messages, PRBool isMove, nsIMsgWindow *window, nsIMsgCopyServiceListener *listener);

View File

@ -381,19 +381,19 @@ LocateMessageFolder(nsIMsgIdentity *userIdentity,
// use the defaults by getting the folder by flags
if (aFolderType == nsMsgQueueForLater) // QueueForLater (Outbox)
{
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_QUEUE, msgFolder, 1, &numFolders);
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_QUEUE, 1, &numFolders, msgFolder);
}
else if (aFolderType == nsMsgSaveAsDraft) // SaveAsDraft (Drafts)
{
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_DRAFTS, msgFolder, 1, &numFolders);
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_DRAFTS, 1, &numFolders, msgFolder);
}
else if (aFolderType == nsMsgSaveAsTemplate) // SaveAsTemplate (Templates)
{
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TEMPLATES, msgFolder, 1, &numFolders);
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TEMPLATES, 1, &numFolders, msgFolder);
}
else // SaveInSentFolder (Sent) - nsMsgDeliverNow
{
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_SENTMAIL, msgFolder, 1, &numFolders);
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_SENTMAIL, 1, &numFolders, msgFolder);
}
if (NS_SUCCEEDED(rv) && *msgFolder) {

View File

@ -1175,8 +1175,8 @@ NS_IMETHODIMP nsImapMailFolder::DeleteMessages(nsISupportsArray *messages,
nsCOMPtr<nsIMsgFolder> trashFolder;
PRUint32 numFolders = 0;
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TRASH,
getter_AddRefs(trashFolder),
1, &numFolders);
1, &numFolders,
getter_AddRefs(trashFolder));
if(NS_SUCCEEDED(rv) && trashFolder)
{
@ -1276,7 +1276,7 @@ NS_IMETHODIMP nsImapMailFolder::GetNewMessages(nsIMsgWindow *aWindow)
if(NS_SUCCEEDED(rv) && rootFolder)
{
PRUint32 numFolders;
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, getter_AddRefs(inbox), 1, &numFolders);
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(inbox));
}
nsCOMPtr <nsIEventQueue> eventQ;
NS_WITH_SERVICE(nsIEventQueueService, pEventQService, kEventQueueServiceCID, &rv);
@ -2570,7 +2570,7 @@ nsresult nsImapMailFolder::GetTrashFolder(nsIMsgFolder **pTrashFolder)
if(NS_SUCCEEDED(rv))
{
PRUint32 numFolders;
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TRASH, pTrashFolder, 1, &numFolders);
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TRASH, 1, &numFolders, pTrashFolder);
if (*pTrashFolder)
NS_ADDREF(*pTrashFolder);
}

View File

@ -2403,3 +2403,13 @@ nsImapService::GetCanDuplicate(PRBool *aCanDuplicate)
*aCanDuplicate = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsImapService::GetDefaultCopiesAndFoldersPrefsToServer(PRBool *aDefaultCopiesAndFoldersPrefsToServer)
{
NS_ENSURE_ARG_POINTER(aDefaultCopiesAndFoldersPrefsToServer);
// when an imap server is created, the copies and folder prefs for the associated identity
// don't point to folders on the server. they'll point to the one on "Local Folders"
*aDefaultCopiesAndFoldersPrefsToServer = PR_TRUE;
return NS_OK;
}

View File

@ -1030,8 +1030,8 @@ nsMsgLocalMailFolder::GetTrashFolder(nsIMsgFolder** result)
if(NS_SUCCEEDED(rv))
{
PRUint32 numFolders;
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TRASH, result,
1, &numFolders);
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TRASH,
1, &numFolders, result);
#if 0
// ** jt -- This shouldn't be needed. The OS should prevent
// user from deleting the trash folder while we are running the app.

View File

@ -126,3 +126,14 @@ nsNoneService::GetCanDuplicate(PRBool *aCanDuplicate)
*aCanDuplicate = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsNoneService::GetDefaultCopiesAndFoldersPrefsToServer(PRBool *aDefaultCopiesAndFoldersPrefsToServer)
{
NS_ENSURE_ARG_POINTER(aDefaultCopiesAndFoldersPrefsToServer);
// when a "none" server is created (like "Local Folders")
// the copies and folder prefs for the associated identity
// point to folders on this server.
*aDefaultCopiesAndFoldersPrefsToServer = PR_TRUE;
return NS_OK;
}

View File

@ -1597,7 +1597,7 @@ nsresult nsParseNewMailState::GetTrashFolder(nsIMsgFolder **pTrashFolder)
if (rootMsgFolder)
{
PRUint32 numFolders;
rv = rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TRASH, pTrashFolder, 1, &numFolders);
rv = rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TRASH, 1, &numFolders, pTrashFolder);
if (*pTrashFolder)
NS_ADDREF(*pTrashFolder);
}
@ -1615,7 +1615,7 @@ void nsParseNewMailState::ApplyFilters(PRBool *pMoved)
if (rootMsgFolder)
{
PRUint32 numFolders;
rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, getter_AddRefs(inbox), 1, &numFolders);
rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(inbox));
char * headers = m_headers.GetBuffer();
PRUint32 headersSize = m_headers.GetBufferPos();
nsresult matchTermStatus;

View File

@ -124,7 +124,7 @@ NS_IMETHODIMP nsPop3IncomingServer::PerformBiff()
if(rootMsgFolder)
{
PRUint32 numFolders;
rv = rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, getter_AddRefs(inbox), 1, &numFolders);
rv = rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(inbox));
}
}

View File

@ -352,3 +352,14 @@ nsPop3Service::GetCanDuplicate(PRBool *aCanDuplicate)
*aCanDuplicate = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsPop3Service::GetDefaultCopiesAndFoldersPrefsToServer(PRBool *aDefaultCopiesAndFoldersPrefsToServer)
{
NS_ENSURE_ARG_POINTER(aDefaultCopiesAndFoldersPrefsToServer);
// when a pop3 server is created, the copies and folder prefs for the associated identity
// point to folders on this server.
// when we create a pop server, we give it its own Drafts, Sent, Templates, etc folders.
*aDefaultCopiesAndFoldersPrefsToServer = PR_TRUE;
return NS_OK;
}

View File

@ -1112,3 +1112,15 @@ nsNntpService::GetCanDuplicate(PRBool *aCanDuplicate)
*aCanDuplicate = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsNntpService::GetDefaultCopiesAndFoldersPrefsToServer(PRBool *aDefaultCopiesAndFoldersPrefsToServer)
{
NS_ENSURE_ARG_POINTER(aDefaultCopiesAndFoldersPrefsToServer);
// when a news account is created, the copies and folder prefs for the associated identity
// don't point to folders on the server.
// this makes sense, since there is no "Drafts" folder on a news server.
// they'll point to the ones on "Local Folders"
*aDefaultCopiesAndFoldersPrefsToServer = PR_FALSE;
return NS_OK;
}