cooler way of sharing INBOX/Drafts/etc strings between nsPop3IncomingServer and nsNoIncmoingServer

as fix for 14421 r=sspitzer
This commit is contained in:
alecf%netscape.com 2000-05-25 05:53:33 +00:00
Родитель b3f84973cd
Коммит 8219e2a3f9
5 изменённых файлов: 123 добавлений и 146 удалений

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

@ -24,4 +24,12 @@
[scriptable, uuid(27D2DE40-BAF1-11d2-9578-00805F8AC615)]
interface nsIMsgLocalMailFolder : nsISupports {
/**
* set the default flags on the subfolders of this folder, such as
* Drafts, Templates, etc
* you should bitwise OR all the flags all mailboxes you want to flag,
* this function will be smart and find the right names.
* like MSG_FOLDER_FLAG_INBOX | MSG_FOLDER_FLAG_DRAFTS | etc
*/
void setFlagsOnDefaultMailboxes(in unsigned long flags);
};

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

@ -399,28 +399,10 @@ nsMsgLocalMailFolder::~nsMsgLocalMailFolder(void)
NS_IMPL_ADDREF_INHERITED(nsMsgLocalMailFolder, nsMsgFolder)
NS_IMPL_RELEASE_INHERITED(nsMsgLocalMailFolder, nsMsgFolder)
NS_IMETHODIMP nsMsgLocalMailFolder::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (!aInstancePtr) return NS_ERROR_NULL_POINTER;
*aInstancePtr = nsnull;
if (aIID.Equals(NS_GET_IID(nsIMsgLocalMailFolder)))
{
*aInstancePtr = NS_STATIC_CAST(nsIMsgLocalMailFolder*, this);
}
else if(aIID.Equals(NS_GET_IID(nsICopyMessageListener)))
{
*aInstancePtr = NS_STATIC_CAST(nsICopyMessageListener*, this);
}
if(*aInstancePtr)
{
AddRef();
return NS_OK;
}
return nsMsgDBFolder::QueryInterface(aIID, aInstancePtr);
}
NS_IMPL_QUERY_INTERFACE_INHERITED2(nsMsgLocalMailFolder,
nsMsgDBFolder,
nsICopyMessageListener,
nsIMsgLocalMailFolder)
////////////////////////////////////////////////////////////////////////////////
@ -678,21 +660,21 @@ nsMsgLocalMailFolder::GetSubFolders(nsIEnumerator* *result)
if (isServer) {
nsCOMPtr<nsIMsgIncomingServer> server;
rv = GetServer(getter_AddRefs(server));
if (NS_FAILED(rv)) return rv;
if (!server) return NS_ERROR_FAILURE;
localMailServer = do_QueryInterface(server, &rv);
if (NS_FAILED(rv)) return rv;
if (!localMailServer) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
if (!server) return NS_ERROR_FAILURE;
localMailServer = do_QueryInterface(server, &rv);
if (NS_FAILED(rv)) return rv;
if (!localMailServer) return NS_ERROR_FAILURE;
nsCOMPtr<nsIFileSpec> spec;
rv = NS_NewFileSpecWithSpec(path, getter_AddRefs(spec));
if (NS_FAILED(rv)) return rv;
// first create the folders on disk (as empty files)
// first create the folders on disk (as empty files)
rv = localMailServer->CreateDefaultMailboxes(spec);
if (NS_FAILED(rv)) return rv;
createdDefaultMailboxes = PR_TRUE;
createdDefaultMailboxes = PR_TRUE;
}
// now, discover those folders
@ -700,8 +682,9 @@ nsMsgLocalMailFolder::GetSubFolders(nsIEnumerator* *result)
if (NS_FAILED(rv)) return rv;
// must happen after CreateSubFolders, or the folders won't exist.
if (createdDefaultMailboxes && localMailServer) {
rv = localMailServer->SetFlagsOnDefaultMailboxes();
if (createdDefaultMailboxes && isServer) {
nsCOMPtr<nsIFolder> rootFolder;
rv = localMailServer->SetFlagsOnDefaultMailboxes();
if (NS_FAILED(rv)) return rv;
}
@ -2707,3 +2690,56 @@ nsMsgLocalMailFolder::OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode)
return nsMsgDBFolder::OnStopRunningUrl(aUrl, aExitCode);
}
NS_IMETHODIMP
nsMsgLocalMailFolder::SetFlagsOnDefaultMailboxes(PRUint32 flags)
{
nsresult rv = NS_OK;
if (flags & MSG_FOLDER_FLAG_INBOX)
setSubfolderFlag(kInboxName, MSG_FOLDER_FLAG_INBOX);
if (flags & MSG_FOLDER_FLAG_SENTMAIL)
setSubfolderFlag(kSentName, MSG_FOLDER_FLAG_SENTMAIL);
if (flags & MSG_FOLDER_FLAG_DRAFTS)
setSubfolderFlag(kDraftsName, MSG_FOLDER_FLAG_DRAFTS);
if (flags & MSG_FOLDER_FLAG_TEMPLATES)
setSubfolderFlag(kTemplatesName, MSG_FOLDER_FLAG_TEMPLATES);
if (flags & MSG_FOLDER_FLAG_TRASH)
setSubfolderFlag(kTrashName, MSG_FOLDER_FLAG_TRASH);
if (flags & MSG_FOLDER_FLAG_QUEUE)
setSubfolderFlag(kUnsentName, MSG_FOLDER_FLAG_QUEUE);
return NS_OK;
}
nsresult
nsMsgLocalMailFolder::setSubfolderFlag(PRUnichar* aFolderName,
PRUint32 flags)
{
nsresult rv;
// this is safe because nsSubsumeStr will not take ownership
PRUnichar *folderName = NS_CONST_CAST(PRUnichar *, aFolderName);
// no-copy conversion to utf8 string
nsSubsumeCStr utf8Name(nsSubsumeStr(folderName, PR_FALSE).ToNewUTF8String(), PR_TRUE);
nsCOMPtr<nsIFolder> folder;
rv = FindSubFolder(utf8Name, getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
nsCOMPtr<nsIMsgFolder> msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_TRASH);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}

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

@ -184,7 +184,9 @@ protected:
//time
nsCOMPtr<nsITransactionManager> mTxnMgr;
const char *mType;
nsCOMPtr<nsIMsgStringService> mMsgStringService;
nsCOMPtr<nsIMsgStringService> mMsgStringService;
nsresult setSubfolderFlag(PRUnichar *aFolderName, PRUint32 flags);
};
#endif // nsMsgLocalMailFolder_h__

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

@ -21,17 +21,20 @@
*/
#include "msgCore.h" // pre-compiled headers
#include "prmem.h"
#include "plstr.h"
#include "prprf.h"
#include "nsIFileSpec.h"
#include "nsIPref.h"
#include "nsXPIDLString.h"
#include "nsNoIncomingServer.h"
#include "nsMsgLocalCID.h"
#include "nsMsgFolderFlags.h"
#include "nsIFileSpec.h"
#include "nsIPref.h"
#include "prmem.h"
#include "plstr.h"
#include "prprf.h"
#include "nsXPIDLString.h"
#include "nsIMsgLocalMailFolder.h"
NS_IMPL_ISUPPORTS_INHERITED2(nsNoIncomingServer,
nsMsgIncomingServer,
@ -60,59 +63,23 @@ nsNoIncomingServer::GetLocalStoreType(char **type)
NS_IMETHODIMP
nsNoIncomingServer::SetFlagsOnDefaultMailboxes()
{
nsresult rv;
nsresult rv;
nsCOMPtr<nsIFolder> rootFolder;
rv = GetRootFolder(getter_AddRefs(rootFolder));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFolder> rootFolder;
rv = GetRootFolder(getter_AddRefs(rootFolder));
if (NS_FAILED(rv)) return rv;
if (!rootFolder) return NS_ERROR_FAILURE;
nsCOMPtr<nsIMsgLocalMailFolder> localFolder =
do_QueryInterface(rootFolder, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr <nsIFolder> folder;
nsCOMPtr <nsIMsgFolder> msgFolder;
// notice, no Inbox
rv = rootFolder->FindSubFolder("Sent", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_SENTMAIL);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Drafts", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_DRAFTS);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Templates", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_TEMPLATES);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Trash", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_TRASH);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Unsent Messages", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_QUEUE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
// pop3 gets all flags
localFolder->SetFlagsOnDefaultMailboxes(MSG_FOLDER_FLAG_SENTMAIL |
MSG_FOLDER_FLAG_DRAFTS |
MSG_FOLDER_FLAG_TEMPLATES |
MSG_FOLDER_FLAG_TRASH |
MSG_FOLDER_FLAG_QUEUE);
return NS_OK;
}
NS_IMETHODIMP nsNoIncomingServer::CreateDefaultMailboxes(nsIFileSpec *path)

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

@ -39,6 +39,7 @@
#include "nsIFileSpec.h"
#include "nsPop3Protocol.h"
#include "nsIMsgMailSession.h"
#include "nsIMsgLocalMailFolder.h"
static NS_DEFINE_CID(kCPop3ServiceCID, NS_POP3SERVICE_CID);
static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID);
@ -209,66 +210,29 @@ NS_IMETHODIMP nsPop3IncomingServer::PerformBiff()
return NS_OK;
}
NS_IMETHODIMP nsPop3IncomingServer::SetFlagsOnDefaultMailboxes()
{
nsresult rv;
nsCOMPtr<nsIFolder> rootFolder;
rv = GetRootFolder(getter_AddRefs(rootFolder));
if (NS_FAILED(rv)) return rv;
if (!rootFolder) return NS_ERROR_FAILURE;
nsCOMPtr <nsIFolder> folder;
nsCOMPtr<nsIMsgFolder> msgFolder;
rv = rootFolder->FindSubFolder(INBOX_NAME, getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_INBOX);
if (NS_FAILED(rv)) return rv;
setSubFolderFlag(rootFolder, kSentName, MSG_FOLDER_FLAG_SENTMAIL);
setSubFolderFlag(rootFolder, kDraftsName, MSG_FOLDER_FLAG_DRAFTS);
setSubFolderFlag(rootFolder, kTemplatesName, MSG_FOLDER_FLAG_TEMPLATES);
setSubFolderFlag(rootFolder, kTrashName, MSG_FOLDER_FLAG_TRASH);
rv = rootFolder->FindSubFolder("Unsent Messages", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_QUEUE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
nsresult
nsPop3IncomingServer::setSubFolderFlag(nsIFolder *aRootFolder,
PRUnichar *aFolderName,
PRUint32 flags)
NS_IMETHODIMP
nsPop3IncomingServer::SetFlagsOnDefaultMailboxes()
{
nsresult rv;
// no-copy conversion to utf8 string
nsSubsumeCStr utf8Name(nsSubsumeStr(aFolderName, PR_FALSE).ToNewUTF8String(), PR_TRUE);
nsCOMPtr<nsIFolder> folder;
rv = aRootFolder->FindSubFolder(utf8Name, getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
nsCOMPtr<nsIMsgFolder> msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_TRASH);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIFolder> rootFolder;
rv = GetRootFolder(getter_AddRefs(rootFolder));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMsgLocalMailFolder> localFolder =
do_QueryInterface(rootFolder, &rv);
NS_ENSURE_SUCCESS(rv, rv);
// pop3 gets all flags
localFolder->SetFlagsOnDefaultMailboxes(MSG_FOLDER_FLAG_INBOX |
MSG_FOLDER_FLAG_SENTMAIL |
MSG_FOLDER_FLAG_DRAFTS |
MSG_FOLDER_FLAG_TEMPLATES |
MSG_FOLDER_FLAG_TRASH |
MSG_FOLDER_FLAG_QUEUE);
return NS_OK;
}
NS_IMETHODIMP nsPop3IncomingServer::CreateDefaultMailboxes(nsIFileSpec *path)
{