diff --git a/mailnews/base/public/Makefile.in b/mailnews/base/public/Makefile.in index 6ce5d8097967..4ab91cf9523c 100644 --- a/mailnews/base/public/Makefile.in +++ b/mailnews/base/public/Makefile.in @@ -22,24 +22,24 @@ srcdir = @srcdir@ include $(DEPTH)/config/autoconf.mk -IDLSRCS = \ - nsIMsgHost.idl \ - nsIMsgGroupRecord.idl \ - nsIMsgFolder.idl \ - nsIMsg.idl \ +IDLSRCS = \ + nsIMsgHost.idl \ + nsIMsgGroupRecord.idl \ + nsIMsgFolder.idl \ + nsIMsg.idl \ $(NULL) -EXPORTS = \ - msgCore.h \ - nsMsgFolderFlags.h \ - nsMsgHeaderMasks.h \ - nsMsgMessageFlags.h \ - nsIMsgRFC822Parser.h \ - nsIMsgHost.h \ - nsIMsgGroupRecord.h \ - nsIMsgFolder.h \ - nsIMsgRDFFolder.h \ - nsIMsg.h \ +EXPORTS = \ + msgCore.h \ + nsMsgFolderFlags.h \ + nsMsgHeaderMasks.h \ + nsMsgMessageFlags.h \ + nsIMsgRFC822Parser.h \ + nsIMsgHost.h \ + nsIMsgGroupRecord.h \ + nsIMsgFolder.h \ + nsIMsgRDFFolder.h \ + nsIMsg.h \ $(NULL) include $(topsrcdir)/config/config.mk diff --git a/mailnews/base/public/makefile.win b/mailnews/base/public/makefile.win index 2ad84f615728..eac1e3b03acf 100644 --- a/mailnews/base/public/makefile.win +++ b/mailnews/base/public/makefile.win @@ -19,24 +19,24 @@ DEPTH=..\..\.. IGNORE_MANIFEST=1 -IDLSRCS = \ - nsIMsgHost.idl \ - nsIMsgGroupRecord.idl \ - nsIMsgFolder.idl \ - nsIMsg.idl \ +IDLSRCS = \ + nsIMsgHost.idl \ + nsIMsgGroupRecord.idl \ + nsIMsgFolder.idl \ + nsIMsg.idl \ $(NULL) -EXPORTS = \ - nsIMsgRFC822Parser.h \ - msgCore.h \ - nsMsgFolderFlags.h \ - nsMsgHeaderMasks.h \ - nsMsgMessageFlags.h \ - nsIMsgHost.h \ - nsIMsgGroupRecord.h \ - nsIMsgFolder.h \ - nsIMsgRDFFolder.h \ - nsIMsg.h \ +EXPORTS = \ + nsIMsgRFC822Parser.h \ + msgCore.h \ + nsMsgFolderFlags.h \ + nsMsgHeaderMasks.h \ + nsMsgMessageFlags.h \ + nsIMsgHost.h \ + nsIMsgGroupRecord.h \ + nsIMsgFolder.h \ + nsIMsgRDFFolder.h \ + nsIMsg.h \ $(NULL) MODULE=mailnews diff --git a/mailnews/base/public/nsIMsgFolder.h b/mailnews/base/public/nsIMsgFolder.h index e1d29e1c73a0..c63e51efd9cf 100644 --- a/mailnews/base/public/nsIMsgFolder.h +++ b/mailnews/base/public/nsIMsgFolder.h @@ -237,15 +237,15 @@ class nsIMsgFolder : public nsISupports { /* starting interface nsIMsgMailFolder */ /* {27D2DE40-BAF1-11d2-9578-00805F8AC615} */ -#define NS_IMSGMAILFOLDER_IID_STR "27D2DE40-BAF1-11d2-9578-00805F8AC615" -#define NS_IMSGMAILFOLDER_IID \ +#define NS_IMSGLOCALMAILFOLDER_IID_STR "27D2DE40-BAF1-11d2-9578-00805F8AC615" +#define NS_IMSGLOCALMAILFOLDER_IID \ {0x27D2DE40, 0xBAF1, 0x11d2, \ { 0x95, 0x78, 0x00, 0x80, 0x5F, 0x8A, 0xC6, 0x15 }} -class nsIMsgMailFolder : public nsISupports { +class nsIMsgLocalMailFolder : public nsISupports { public: static const nsIID& IID() { - static nsIID iid = NS_IMSGMAILFOLDER_IID; + static nsIID iid = NS_IMSGLOCALMAILFOLDER_IID; return iid; } diff --git a/mailnews/base/src/Makefile.in b/mailnews/base/src/Makefile.in index 3aa41adea800..d2d366788b60 100644 --- a/mailnews/base/src/Makefile.in +++ b/mailnews/base/src/Makefile.in @@ -36,6 +36,7 @@ CPPSRCS = \ nsMsgGroupRecord.cpp \ nsMsgRFC822Parser.cpp \ nsMsgFolder.cpp \ + nsMsgLocalMailFolder.cpp \ nsNewsSet.cpp \ nsMsg.cpp \ $(NULL) diff --git a/mailnews/base/src/makefile.win b/mailnews/base/src/makefile.win index 0b874532492c..f6af1674a6d1 100644 --- a/mailnews/base/src/makefile.win +++ b/mailnews/base/src/makefile.win @@ -26,33 +26,38 @@ REQUIRES=xpcom js nspr DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN -CPPSRCS= nsMsgRFC822Parser.cpp \ - nsUInt32Array.cpp\ - nsMsgKeyArray.cpp\ - nsMsgFolder.cpp \ - nsMsgGroupRecord.cpp \ - nsMsgRDFFolder.cpp \ - nsNewsSet.cpp \ - nsMsg.cpp \ - $(NULL) +CPPSRCS= \ + nsMsgRFC822Parser.cpp \ + nsUInt32Array.cpp \ + nsMsgKeyArray.cpp \ + nsMsgFolder.cpp \ + nsMsgLocalMailFolder.cpp \ + nsMsgGroupRecord.cpp \ + nsMsgRDFFolder.cpp \ + nsNewsSet.cpp \ + nsMsg.cpp \ + $(NULL) -CPP_OBJS= .\$(OBJDIR)\nsMsgRFC822Parser.obj \ - .\$(OBJDIR)\nsUInt32Array.obj\ - .\$(OBJDIR)\nsMsgKeyArray.obj\ - .\$(OBJDIR)\nsMsgFolder.obj \ - .\$(OBJDIR)\nsMsgGroupRecord.obj \ - .\$(OBJDIR)\nsMsgRDFFolder.obj \ - .\$(OBJDIR)\nsNewsSet.obj \ - .\$(OBJDIR)\nsMsg.obj \ - $(NULL) +CPP_OBJS= \ + .\$(OBJDIR)\nsMsgRFC822Parser.obj \ + .\$(OBJDIR)\nsUInt32Array.obj \ + .\$(OBJDIR)\nsMsgKeyArray.obj \ + .\$(OBJDIR)\nsMsgFolder.obj \ + .\$(OBJDIR)\nsMsgLocalMailFolder.obj \ + .\$(OBJDIR)\nsMsgGroupRecord.obj \ + .\$(OBJDIR)\nsMsgRDFFolder.obj \ + .\$(OBJDIR)\nsNewsSet.obj \ + .\$(OBJDIR)\nsMsg.obj \ + $(NULL) -EXPORTS= nsMsgRFC822Parser.h \ - nsUInt32Array.h \ - nsMsgKeyArray.h \ - nsNewsSet.h \ - nsMsgGroupRecord.h \ - $(NULL) +EXPORTS= \ + nsMsgRFC822Parser.h \ + nsUInt32Array.h \ + nsMsgKeyArray.h \ + nsNewsSet.h \ + nsMsgGroupRecord.h \ + $(NULL) LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\mailnews -I$(PUBLIC)\raptor -I$(PUBLIC)\rdf diff --git a/mailnews/base/src/nsMsgFolder.cpp b/mailnews/base/src/nsMsgFolder.cpp index 808ffb6af64d..12298caf009b 100644 --- a/mailnews/base/src/nsMsgFolder.cpp +++ b/mailnews/base/src/nsMsgFolder.cpp @@ -17,9 +17,6 @@ */ #include "nsMsgFolder.h" -#include "nsISupports.h" -#include "nsIRDFNode.h" -#include "nsIRDFResourceFactory.h" #include "nsMsgFolderFlags.h" #include "prprf.h" #include "nsMsgKeyArray.h" @@ -29,11 +26,7 @@ #endif /* use these macros to define a class IID for our component. */ static NS_DEFINE_IID(kIMsgFolderIID, NS_IMSGFOLDER_IID); -static NS_DEFINE_IID(kIMsgMailFolderIID, NS_IMSGMAILFOLDER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID); -static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID); -static NS_DEFINE_IID(kIRDFResourceFactoryIID, NS_IRDFRESOURCEFACTORY_IID); nsMsgFolder::nsMsgFolder(const char* uri) : nsRDFResource(PL_strdup(uri)) @@ -188,7 +181,7 @@ NS_IMETHODIMP nsMsgFolder::StartAsyncCopyMessagesInto (MSG_FolderInfo *dstFolder copyInfo->moveState.haveUploadedMessageSize = FALSE; MsgERR openErr = eSUCCESS; - XP_Bool wasCreated; + PRBool wasCreated; if (dstFolder->GetType() == FOLDER_MAIL) openErr = MailDB::Open (dstFolder->GetMailFolderInfo()->GetPathname(), FALSE, ©Info->moveState.destDB, FALSE); else if (dstFolder->GetType() == FOLDER_IMAPMAIL && !IsNews()) @@ -273,7 +266,7 @@ NS_IMETHODIMP nsMsgFolder::CleanupCopyMessagesInto (MessageCopyInfo **info) MSG_Pane *sourcePane = (*info)->moveState.sourcePane; - XP_Bool searchPane = sourcePane ? sourcePane->GetPaneType() == MSG_SEARCHPANE : FALSE; + PRBool searchPane = sourcePane ? sourcePane->GetPaneType() == MSG_SEARCHPANE : FALSE; if ((*info)->moveState.destDB != NULL) { @@ -320,7 +313,7 @@ NS_IMETHODIMP nsMsgFolder::CleanupCopyMessagesInto (MessageCopyInfo **info) NS_IMETHODIMP nsMsgFolder::SaveMessages(nsMsgKeyArray *, const char *fileName, MSG_Pane *pane, nsMsgDatabase *msgDB, int (*doneCB)(void *, int status) = NULL, void *state = NULL, - XP_Bool addMozillaStatus = TRUE) + PRBool addMozillaStatus = TRUE) { DownloadArticlesToFolder::SaveMessages(array, fileName, pane, this, msgDB, doneCB, state, addMozillaStatus); return NS_OK; @@ -964,7 +957,7 @@ NS_IMETHODIMP nsMsgFolder::GetTotalMessages(PRBool deep, PRUint32 *totalMessages #endif #ifdef HAVE_PANE - virtual void MarkAllRead(MSG_Pane *pane, XP_Bool deep); + virtual void MarkAllRead(MSG_Pane *pane, PRBool deep); #endif #ifdef HAVE_DB @@ -1356,7 +1349,7 @@ NS_IMETHODIMP nsMsgFolder::DownloadToTempFileAndUpload(MessageCopyInfo *copyInfo } -NS_IMETHODIMP nsMsgFolder::UpdateMoveCopyStatus(MWContext *context, XP_Bool isMove, int32 curMsgCount, int32 totMessages) +NS_IMETHODIMP nsMsgFolder::UpdateMoveCopyStatus(MWContext *context, PRBool isMove, int32 curMsgCount, int32 totMessages) { } @@ -1405,722 +1398,6 @@ NS_IMETHODIMP nsMsgFolder::GetHostName(char **hostName) return NS_OK; } - -nsMsgMailFolder::nsMsgMailFolder(const char* uri) -:nsMsgFolder(uri) -{ - mHaveReadNameFromDB = PR_FALSE; - mPathName = nsnull; -} - -nsMsgMailFolder::~nsMsgMailFolder() -{ - -} - -NS_IMPL_ADDREF(nsMsgMailFolder) -NS_IMPL_RELEASE(nsMsgMailFolder) - -NS_IMETHODIMP -nsMsgMailFolder::QueryInterface(REFNSIID iid, void** result) -{ - if (! result) - return NS_ERROR_NULL_POINTER; - - *result = nsnull; - if(iid.Equals(kIMsgMailFolderIID) || - iid.Equals(kISupportsIID)) - { - *result = NS_STATIC_CAST(nsIMsgMailFolder*, this); - AddRef(); - return NS_OK; - } - return nsMsgFolder::QueryInterface(iid, result); -} - -NS_IMETHODIMP nsMsgMailFolder::GetType(FolderType *type) -{ - if(!type) - return NS_ERROR_NULL_POINTER; - - *type = FOLDER_MAIL; - - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::BuildFolderURL(char **url) -{ - const char *urlScheme = "mailbox:"; - - if(!url) - return NS_ERROR_NULL_POINTER; - - *url = PR_smprintf("%s%s", urlScheme, mPathName); - return NS_OK; - -} - -NS_IMETHODIMP nsMsgMailFolder::CreateSubfolder(const char *leafNameFromUser, nsIMsgFolder **outFolder, PRUint32 *outPos) -{ -#ifdef HAVE_PORT - MsgERR status = 0; - *ppOutFolder = NULL; - *pOutPos = 0; - XP_StatStruct stat; - - - // Only create a .sbd pathname if we're not in the root folder. The root folder - // e.g. c:\netscape\mail has to behave differently than subfolders. - if (m_depth > 1) - { - // Look around in our directory to get a subdirectory, creating it - // if necessary - XP_BZERO (&stat, sizeof(stat)); - if (0 == XP_Stat (m_pathName, &stat, xpMailSubdirectory)) - { - if (!S_ISDIR(stat.st_mode)) - status = MK_COULD_NOT_CREATE_DIRECTORY; // a file .sbd already exists - } - else { - status = XP_MakeDirectory (m_pathName, xpMailSubdirectory); - if (status == -1) - status = MK_COULD_NOT_CREATE_DIRECTORY; - } - } - - char *leafNameForDisk = CreatePlatformLeafNameForDisk(leafNameFromUser,m_master, this); - if (!leafNameForDisk) - status = MK_OUT_OF_MEMORY; - - if (0 == status) //ok so far - { - // Now that we have a suitable parent directory created/identified, - // we can create the new mail folder inside the parent dir. Again, - - char *newFolderPath = (char*) XP_ALLOC(XP_STRLEN(m_pathName) + XP_STRLEN(leafNameForDisk) + XP_STRLEN(".sbd/") + 1); - if (newFolderPath) - { - XP_STRCPY (newFolderPath, m_pathName); - if (m_depth == 1) - XP_STRCAT (newFolderPath, "/"); - else - XP_STRCAT (newFolderPath, ".sbd/"); - XP_STRCAT (newFolderPath, leafNameForDisk); - - if (0 != XP_Stat (newFolderPath, &stat, xpMailFolder)) - { - XP_File file = XP_FileOpen(newFolderPath, xpMailFolder, XP_FILE_WRITE_BIN); - if (file) - { - // Create an empty database for this mail folder, set its name from the user - MailDB *unusedDb = NULL; - MailDB::Open(newFolderPath, TRUE, &unusedDb, TRUE); - if (unusedDb) - { - //need to set the folder name - - MSG_FolderInfoMail *newFolder = BuildFolderTree (newFolderPath, m_depth + 1, m_subFolders, m_master); - if (newFolder) - { - // so we don't show ??? in totals - newFolder->SummaryChanged(); - *ppOutFolder = newFolder; - *pOutPos = m_subFolders->FindIndex (0, newFolder); - } - else - status = MK_OUT_OF_MEMORY; - unusedDb->SetFolderInfoValid(newFolderPath,0,0); - unusedDb->Close(); - } - else - { - XP_FileClose(file); - file = NULL; - XP_FileRemove (newFolderPath, xpMailFolder); - status = MK_MSG_CANT_CREATE_FOLDER; - } - if (file) - { - XP_FileClose(file); - file = NULL; - } - } - else - status = MK_MSG_CANT_CREATE_FOLDER; - } - else - status = MK_MSG_FOLDER_ALREADY_EXISTS; - FREEIF(newFolderPath); - } - else - status = MK_OUT_OF_MEMORY; - } - FREEIF(leafNameForDisk); - return status; -#endif //HAVE_PORT - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::RemoveSubFolder (const nsIMsgFolder *which) -{ - // Let the base class do list management - nsMsgFolder::RemoveSubFolder (which); - - // Derived class is responsible for managing the subdirectory -#ifdef HAVE_PORT - if (0 == m_subFolders->GetSize()) - XP_RemoveDirectory (m_pathName, xpMailSubdirectory); -#endif - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::Delete () -{ -#ifdef HAVE_PORT - nsMsgDatabase *db; - // remove the summary file - MsgERR status = CloseDatabase (m_pathName, &db); - if (0 == status) - { - if (db != NULL) - db->Close(); // decrement ref count, so it will leave cache - XP_FileRemove (m_pathName, xpMailFolderSummary); - } - - if ((0 == status) && (GetType() == FOLDER_MAIL)) - { - // remove the mail folder file - status = XP_FileRemove (m_pathName, xpMailFolder); - - // if the delete seems to have failed, but the file doesn't - // exist, that's not really an error condition, is it now? - if (status) - { - XP_StatStruct fileStat; - if (0 == XP_Stat(m_pathName, &fileStat, xpMailFolder)) - status = 0; - } - } - - - if (0 != status) - status = MK_UNABLE_TO_DELETE_FILE; - return status; -#endif - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::Rename (const char *newName) -{ -#ifdef HAVE_PORT - // change the leaf name (stored separately) - MsgERR status = MSG_FolderInfo::Rename (newUserLeafName); - if (status == 0) - { - char *baseDir = XP_STRDUP(m_pathName); - if (baseDir) - { - char *base_slash = XP_STRRCHR (baseDir, '/'); - if (base_slash) - *base_slash = '\0'; - } - - char *leafNameForDisk = CreatePlatformLeafNameForDisk(newUserLeafName,m_master, baseDir); - if (!leafNameForDisk) - status = MK_OUT_OF_MEMORY; - - if (0 == status) - { - // calculate the new path name - char *newPath = (char*) XP_ALLOC(XP_STRLEN(m_pathName) + XP_STRLEN(leafNameForDisk) + 1); - XP_STRCPY (newPath, m_pathName); - char *slash = XP_STRRCHR (newPath, '/'); - if (slash) - XP_STRCPY (slash + 1, leafNameForDisk); - - // rename the mail summary file, if there is one - nsMsgDatabase *db = NULL; - status = CloseDatabase (m_pathName, &db); - - XP_StatStruct fileStat; - if (!XP_Stat(m_pathName, &fileStat, xpMailFolderSummary)) - status = XP_FileRename(m_pathName, xpMailFolderSummary, newPath, xpMailFolderSummary); - if (0 == status) - { - if (db) - { - if (ReopenDatabase (db, newPath) == 0) - { - //need to set mailbox name - } - } - else - { - MailDB *mailDb = NULL; - MailDB::Open(newPath, TRUE, &mailDb, TRUE); - if (mailDb) - { - //need to set mailbox name - mailDb->Close(); - } - } - } - - // rename the mail folder file, if its local - if ((status == 0) && (GetType() == FOLDER_MAIL)) - status = XP_FileRename (m_pathName, xpMailFolder, newPath, xpMailFolder); - - if (status == 0) - { - // rename the subdirectory if there is one - if (m_subFolders->GetSize() > 0) - status = XP_FileRename (m_pathName, xpMailSubdirectory, newPath, xpMailSubdirectory); - - // tell all our children about the new pathname - if (status == 0) - { - int startingAt = XP_STRLEN (newPath) - XP_STRLEN (leafNameForDisk) + 1; // add one for trailing '/' - status = PropagateRename (leafNameForDisk, startingAt); - } - } - } - FREEIF(baseDir); - } - return status; -#endif - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::Adopt(const nsIMsgFolder *srcFolder, PRUint32 *outPos) -{ -#ifdef HAVE_PORT - MsgERR err = eSUCCESS; - XP_ASSERT (srcFolder->GetType() == GetType()); // we can only adopt the same type of folder - MSG_FolderInfoMail *mailFolder = (MSG_FolderInfoMail*) srcFolder; - - if (srcFolder == this) - return MK_MSG_CANT_COPY_TO_SAME_FOLDER; - - if (ContainsChildNamed(mailFolder->GetName())) - return MK_MSG_FOLDER_ALREADY_EXISTS; - - // If we aren't already a directory, create the directory and set the flag bits - if (0 == m_subFolders->GetSize()) - { - XP_Dir dir = XP_OpenDir (m_pathName, xpMailSubdirectory); - if (dir) - XP_CloseDir (dir); - else - { - XP_MakeDirectory (m_pathName, xpMailSubdirectory); - dir = XP_OpenDir (m_pathName, xpMailSubdirectory); - if (dir) - XP_CloseDir (dir); - else - err = MK_COULD_NOT_CREATE_DIRECTORY; - } - if (eSUCCESS == err) - { - m_flags |= MSG_FOLDER_FLAG_DIRECTORY; - m_flags |= MSG_FOLDER_FLAG_ELIDED; - } - } - - // Recurse the tree to adopt srcFolder's children - err = mailFolder->PropagateAdopt (m_pathName, m_depth); - - // Add the folder to our tree in the right sorted position - if (eSUCCESS == err) - { - XP_ASSERT(m_subFolders->FindIndex(0, srcFolder) == -1); - *pOutPos = m_subFolders->Add (srcFolder); - } - - return err; -#endif - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetName(char** name) -{ - if(!name) - return NS_ERROR_NULL_POINTER; - - if (!mHaveReadNameFromDB) - { - if (mDepth == 1) - { - SetName("Local Mail"); - mHaveReadNameFromDB = TRUE; - } - else - { - //Need to read the name from the database - } - } - *name = mName; - - - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetPrettyName(char ** prettyName) -{ - if (mDepth == 1) { - // Depth == 1 means we are on the mail server level - // override the name here to say "Local Mail" - FolderType type; - GetType(&type); - if (type == FOLDER_MAIL) - *prettyName = PL_strdup("Local Mail"); - else - return nsMsgFolder::GetPrettyName(prettyName); - } - else - return nsMsgFolder::GetPrettyName(prettyName); - - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GenerateUniqueSubfolderName(const char *prefix, - const nsIMsgFolder *otherFolder, - char** name) -{ - if(!name) - return NS_ERROR_NULL_POINTER; - - /* only try 256 times */ - for (int count = 0; (count < 256); count++) - { - PRUint32 prefixSize = PL_strlen(prefix); - - //allocate string big enough for prefix, 256, and '\0' - char *uniqueName = (char*)PR_MALLOC(prefixSize + 4); - PR_snprintf(uniqueName, prefixSize + 4, "%s%d",prefix,count); - PRBool containsChild; - PRBool otherContainsChild = PR_FALSE; - - ContainsChildNamed(uniqueName, &containsChild); - if(otherFolder) - { - ((nsIMsgFolder*)otherFolder)->ContainsChildNamed(uniqueName, &otherContainsChild); - } - - if (!containsChild && !otherContainsChild) - { - *name = uniqueName; - return NS_OK; - } - else - PR_FREEIF(uniqueName); - } - *name = nsnull; - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::UpdateSummaryTotals() -{ - //We need to read this info from the database - - // If we asked, but didn't get any, stop asking - if (mNumUnreadMessages == -1) - mNumUnreadMessages = -2; - - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetExpungedBytesCount(PRUint32 *count) -{ - if(!count) - return NS_ERROR_NULL_POINTER; - - *count = mExpungedBytes; - - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetDeletable (PRBool *deletable) -{ - if(!deletable) - return NS_ERROR_NULL_POINTER; - - // These are specified in the "Mail/News Windows" UI spec - - if (mFlags & MSG_FOLDER_FLAG_TRASH) - { - PRBool moveToTrash; - GetDeleteIsMoveToTrash(&moveToTrash); - if(moveToTrash) - *deletable = PR_TRUE; // allow delete of trash if we don't use trash - } - else if (mDepth == 1) - *deletable = PR_FALSE; - else if (mFlags & MSG_FOLDER_FLAG_INBOX || - mFlags & MSG_FOLDER_FLAG_DRAFTS || - mFlags & MSG_FOLDER_FLAG_TRASH || - mFlags & MSG_FOLDER_FLAG_TEMPLATES) - *deletable = PR_FALSE; - else *deletable = PR_TRUE; - - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetCanCreateChildren (PRBool *canCreateChildren) -{ - if(!canCreateChildren) - return NS_ERROR_NULL_POINTER; - - *canCreateChildren = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetCanBeRenamed (PRBool *canBeRenamed) -{ - if(!canBeRenamed) - return NS_ERROR_NULL_POINTER; - - // The root mail folder can't be renamed - if (mDepth < 2) - *canBeRenamed = PR_FALSE; - - // Here's a weird case necessitated because we don't have a separate - // preference for any folder name except the FCC folder (Sent). Others - // are known by name, and as such, can't be renamed. I guess. - else if (mFlags & MSG_FOLDER_FLAG_TRASH || - mFlags & MSG_FOLDER_FLAG_DRAFTS || - mFlags & MSG_FOLDER_FLAG_QUEUE || - mFlags & MSG_FOLDER_FLAG_INBOX || - mFlags & MSG_FOLDER_FLAG_TEMPLATES) - *canBeRenamed = PR_FALSE; - else - *canBeRenamed = PR_TRUE; - - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetRequiresCleanup(PRBool *requiresCleanup) -{ -#ifdef HAVE_PORT - if (m_expungedBytes > 0) - { - int32 purgeThreshhold = m_master->GetPrefs()->GetPurgeThreshhold(); - XP_Bool purgePrompt = m_master->GetPrefs()->GetPurgeThreshholdEnabled();; - return (purgePrompt && m_expungedBytes / 1000L > purgeThreshhold); - } - return FALSE; -#endif - return NS_OK; -} - - - -NS_IMETHODIMP nsMsgMailFolder::GetRelativePathName (char **pathName) -{ - if(!pathName) - return NS_ERROR_NULL_POINTER; - *pathName = mPathName; - return NS_OK; -} - - -NS_IMETHODIMP nsMsgMailFolder::GetSizeOnDisk(PRUint32 size) -{ -#ifdef HAVE_PORT - int32 ret = 0; - XP_StatStruct st; - - if (!XP_Stat(GetPathname(), &st, xpMailFolder)) - ret += st.st_size; - - if (!XP_Stat(GetPathname(), &st, xpMailFolderSummary)) - ret += st.st_size; - - return ret; -#endif - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetUserName(char** userName) -{ -#ifdef HAVE_PORT - return NET_GetPopUsername(); -#endif - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetHostName(char** hostName) -{ -#ifdef HAVE_PORT - XP_Bool serverIsIMAP = m_master->GetPrefs()->GetMailServerIsIMAP4(); - if (serverIsIMAP) - { - MSG_IMAPHost *defaultIMAPHost = m_master->GetIMAPHostTable()->GetDefaultHost(); - return (defaultIMAPHost) ? defaultIMAPHost->GetHostName() : 0; - } - else - return m_master->GetPrefs()->GetPopHost(); -#endif - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate) -{ -#ifdef HAVE_PORT - XP_Bool ret = FALSE; - if (m_master->IsCachePasswordProtected() && !m_master->IsUserAuthenticated() && !m_master->AreLocalFoldersAuthenticated()) - { - char *savedPassword = GetRememberedPassword(); - if (savedPassword && XP_STRLEN(savedPassword)) - ret = TRUE; - FREEIF(savedPassword); - } - return ret; -#endif - - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::RememberPassword(const char *password) -{ -#ifdef HAVE_DB - MailDB *mailDb = NULL; - MailDB::Open(m_pathName, TRUE, &mailDb); - if (mailDb) - { - mailDb->SetCachedPassword(password); - mailDb->Close(); - } -#endif - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetRememberedPassword(char ** password) -{ -#ifdef HAVE_PORT - XP_Bool serverIsIMAP = m_master->GetPrefs()->GetMailServerIsIMAP4(); - char *savedPassword = NULL; - if (serverIsIMAP) - { - MSG_IMAPHost *defaultIMAPHost = m_master->GetIMAPHostTable()->GetDefaultHost(); - if (defaultIMAPHost) - { - MSG_FolderInfo *hostFolderInfo = defaultIMAPHost->GetHostFolderInfo(); - MSG_FolderInfo *defaultHostIMAPInbox = NULL; - if (hostFolderInfo->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, &defaultHostIMAPInbox, 1) == 1 - && defaultHostIMAPInbox != NULL) - { - savedPassword = defaultHostIMAPInbox->GetRememberedPassword(); - } - } - } - else - { - MSG_FolderInfo *offlineInbox = NULL; - if (m_flags & MSG_FOLDER_FLAG_INBOX) - { - char *retPassword = NULL; - MailDB *mailDb = NULL; - MailDB::Open(m_pathName, FALSE, &mailDb, FALSE); - if (mailDb) - { - mailDb->GetCachedPassword(cachedPassword); - retPassword = XP_STRDUP(cachedPassword); - mailDb->Close(); - - } - return retPassword; - } - if (m_master->GetLocalMailFolderTree()->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, &offlineInbox, 1) && offlineInbox) - savedPassword = offlineInbox->GetRememberedPassword(); - } - return savedPassword; -#endif - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::GetPathName(char * *aPathName) -{ - if(!aPathName) - return NS_ERROR_NULL_POINTER; - - if(mPathName) - *aPathName = PL_strdup(mPathName); - else - *aPathName = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP nsMsgMailFolder::SetPathName(char * aPathName) -{ - if(mPathName) - PR_FREEIF(mPathName); - - if(aPathName) - mPathName = PL_strdup(aPathName); - else - mPathName = nsnull; - - return NS_OK; -} - -/** - * This class creates resources for message folder URIs. It should be - * registered for the "mailnewsfolder:" prefix. - */ -class nsMsgFolderResourceFactoryImpl : public nsIRDFResourceFactory -{ -public: - nsMsgFolderResourceFactoryImpl(void); - virtual ~nsMsgFolderResourceFactoryImpl(void); - - NS_DECL_ISUPPORTS - - NS_IMETHOD CreateResource(const char* aURI, nsIRDFResource** aResult); -}; - -nsMsgFolderResourceFactoryImpl::nsMsgFolderResourceFactoryImpl(void) -{ - NS_INIT_REFCNT(); -} - -nsMsgFolderResourceFactoryImpl::~nsMsgFolderResourceFactoryImpl(void) -{ -} - -NS_IMPL_ISUPPORTS(nsMsgFolderResourceFactoryImpl, kIRDFResourceFactoryIID); - -NS_IMETHODIMP -nsMsgFolderResourceFactoryImpl::CreateResource(const char* aURI, nsIRDFResource** aResult) -{ - if (! aResult) - return NS_ERROR_NULL_POINTER; - - nsMsgMailFolder *folder = new nsMsgMailFolder(aURI); - if (! folder) - return NS_ERROR_OUT_OF_MEMORY; - - folder->QueryInterface(kIRDFResourceIID, (void**)aResult); - return NS_OK; -} - -nsresult -NS_NewRDFMsgFolderResourceFactory(nsIRDFResourceFactory** aResult) -{ - if (! aResult) - return NS_ERROR_NULL_POINTER; - - nsMsgFolderResourceFactoryImpl* factory = - new nsMsgFolderResourceFactoryImpl(); - - if (! factory) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(factory); - *aResult = factory; - return NS_OK; -} - //////////////////////////////////////////////////////////////////////////////// // Accessing Messages: @@ -2166,4 +1443,3 @@ nsMsgFolder::RemoveMessage(const nsIMsg *msg) return NS_OK; } -//////////////////////////////////////////////////////////////////////////////// diff --git a/mailnews/base/src/nsMsgFolder.h b/mailnews/base/src/nsMsgFolder.h index 11e970c2f202..34dcbd67a0f2 100644 --- a/mailnews/base/src/nsMsgFolder.h +++ b/mailnews/base/src/nsMsgFolder.h @@ -33,14 +33,14 @@ * MsgFolder */ - class nsMsgFolder: public nsRDFResource, public nsIMsgFolder - { +class nsMsgFolder: public nsRDFResource, public nsIMsgFolder +{ public: - nsMsgFolder(const char* uri); - virtual ~nsMsgFolder(); + nsMsgFolder(const char* uri); + virtual ~nsMsgFolder(); - /* this macro defines QueryInterface, AddRef and Release for this class */ - NS_DECL_ISUPPORTS + /* this macro defines QueryInterface, AddRef and Release for this class */ + NS_DECL_ISUPPORTS NS_IMETHOD GetType(FolderType *type); @@ -93,27 +93,27 @@ public: PRBool addMozillaStatus = TRUE); #endif - NS_IMETHOD GetPrettyName(char * *aPrettyName); - NS_IMETHOD GetName(char **name); - NS_IMETHOD SetName(const char *name); + NS_IMETHOD GetPrettyName(char * *aPrettyName); + NS_IMETHOD GetName(char **name); + NS_IMETHOD SetName(const char *name); NS_IMETHOD GetPrettiestName(char **name); NS_IMETHOD BuildFolderURL(char ** url); NS_IMETHOD GetNameFromPathName(const char *pathName, char ** name); - NS_IMETHOD HasSubFolders(PRBool *hasSubFolders); + NS_IMETHOD HasSubFolders(PRBool *hasSubFolders); NS_IMETHOD GetNumSubFolders(PRUint32 *numSubFolders); NS_IMETHOD GetNumSubFoldersToDisplay(PRUint32 *numSubFolders); NS_IMETHOD GetSubFolder(PRUint32 which, nsIMsgFolder **aFolder); NS_IMETHOD GetSubFolders (nsISupportsArray ** subFolders); - NS_IMETHOD AddSubFolder(const nsIMsgFolder *folder); + NS_IMETHOD AddSubFolder(const nsIMsgFolder *folder); NS_IMETHOD AddSubfolderIfUnique(const nsIMsgFolder *newSubfolder); NS_IMETHOD ReplaceSubfolder(const nsIMsgFolder *oldFolder, const nsIMsgFolder *newFolder); NS_IMETHOD RemoveSubFolder (const nsIMsgFolder *which); #ifdef HAVE_PANE - NS_IMETHOD GetVisibleSubFolders (nsISupportsArray ** visibleSubFolders); + NS_IMETHOD GetVisibleSubFolders (nsISupportsArray ** visibleSubFolders); #endif NS_IMETHOD HasMessages(PRBool *_retval); @@ -125,18 +125,18 @@ public: NS_IMETHOD RemoveMessage(const nsIMsg *msg); #ifdef HAVE_ADMINURL - NS_IMETHOD GetAdminUrl(MWContext *context, MSG_AdminURLType type); - NS_IMETHOD HaveAdminUrl(MSG_AdminURLType type, PRBool *hadAdminUrl); + NS_IMETHOD GetAdminUrl(MWContext *context, MSG_AdminURLType type); + NS_IMETHOD HaveAdminUrl(MSG_AdminURLType type, PRBool *hadAdminUrl); #endif - NS_IMETHOD GetDeleteIsMoveToTrash(PRBool *aIsDeleteIsMoveToTrash); - NS_IMETHOD GetShowDeletedMessages(PRBool *aIsShowDeletedMessages); + NS_IMETHOD GetDeleteIsMoveToTrash(PRBool *aIsDeleteIsMoveToTrash); + NS_IMETHOD GetShowDeletedMessages(PRBool *aIsShowDeletedMessages); - NS_IMETHOD OnCloseFolder (); + NS_IMETHOD OnCloseFolder (); NS_IMETHOD Delete (); NS_IMETHOD PropagateDelete (nsIMsgFolder **folder, PRBool deleteStorage); - NS_IMETHOD RecursiveDelete (PRBool deleteStorage); // called by PropagateDelete + NS_IMETHOD RecursiveDelete (PRBool deleteStorage); // called by PropagateDelete NS_IMETHOD CreateSubfolder (const char *leafNameFromuser, nsIMsgFolder** outFolder, PRUint32* outPos); @@ -148,7 +148,7 @@ public: NS_IMETHOD FindParentOf (const nsIMsgFolder * aFolder, nsIMsgFolder ** aParent); NS_IMETHOD IsParentOf (const nsIMsgFolder *, PRBool deep, PRBool *isParent); - NS_IMETHOD GenerateUniqueSubfolderName(const char *prefix, const nsIMsgFolder *otherFolder, + NS_IMETHOD GenerateUniqueSubfolderName(const char *prefix, const nsIMsgFolder *otherFolder, char **name); NS_IMETHOD GetDepth(PRUint32 *depth); @@ -162,11 +162,11 @@ public: NS_IMETHOD GetTotalMessages(PRBool deep, PRUint32 *totalMessages); // Total number of messages in this folder. #ifdef HAVE_DB - NS_IMETHOD GetTotalMessagesInDB(PRUint32 *totalMessages) const; // How many messages in database. + NS_IMETHOD GetTotalMessagesInDB(PRUint32 *totalMessages) const; // How many messages in database. #endif #ifdef HAVE_PANE - NS_IMETHOD MarkAllRead(MSG_Pane *pane, PRBool deep); + NS_IMETHOD MarkAllRead(MSG_Pane *pane, PRBool deep); #endif #ifdef HAVE_DB @@ -178,18 +178,18 @@ public: int32 GetNumPendingUnread(PRBool deep = FALSE); int32 GetNumPendingTotalMessages(PRBool deep = FALSE); - void ChangeNumPendingUnread(int32 delta); - void ChangeNumPendingTotalMessages(int32 delta); + void ChangeNumPendingUnread(int32 delta); + void ChangeNumPendingTotalMessages(int32 delta); NS_IMETHOD SetFolderPrefFlags(PRUint32 flags); NS_IMETHOD GetFolderPrefFlags(PRUint32 *flags); - NS_IMETHOD SetFolderCSID(PRInt16 csid); - NS_IMETHOD GetFolderCSID(PRInt16 *csid); + NS_IMETHOD SetFolderCSID(PRInt16 csid); + NS_IMETHOD GetFolderCSID(PRInt16 *csid); - NS_IMETHOD SetLastMessageLoaded(MessageKey lastMessageLoaded); - NS_IMETHOD GetLastMessageLoaded(); + NS_IMETHOD SetLastMessageLoaded(MessageKey lastMessageLoaded); + NS_IMETHOD GetLastMessageLoaded(); #endif NS_IMETHOD SetFlag (PRUint32 which); @@ -197,11 +197,11 @@ public: NS_IMETHOD GetFlag(PRUint32 flag, PRBool *_retval); NS_IMETHOD ToggleFlag (PRUint32 which); - NS_IMETHOD OnFlagChange (PRUint32 which); + NS_IMETHOD OnFlagChange (PRUint32 which); NS_IMETHOD GetFlags(PRUint32 *flags); #ifdef HAVE_PANE - NS_IMETHOD SetFlagInAllFolderPanes(PRUint32 which); + NS_IMETHOD SetFlagInAllFolderPanes(PRUint32 which); #endif NS_IMETHOD GetFoldersWithFlag(PRUint32 flags, nsIMsgFolder** result, @@ -213,21 +213,21 @@ public: NS_IMETHOD EscapeMessageId(const char *messageId, const char **escapeMessageID); #endif - NS_IMETHOD GetExpungedBytesCount(PRUint32 *count); + NS_IMETHOD GetExpungedBytesCount(PRUint32 *count); NS_IMETHOD GetDeletable (PRBool *deletable); NS_IMETHOD GetCanCreateChildren (PRBool *canCreateChildren); NS_IMETHOD GetCanBeRenamed (PRBool *canBeRenamed); - NS_IMETHOD GetRequiresCleanup(PRBool *requiredCleanup); - NS_IMETHOD ClearRequiresCleanup() ; + NS_IMETHOD GetRequiresCleanup(PRBool *requiredCleanup); + NS_IMETHOD ClearRequiresCleanup() ; #ifdef HAVE_PANE virtual PRBool CanBeInFolderPane (); #endif - NS_IMETHOD GetKnowsSearchNntpExtension(PRBool *knowsExtension); - NS_IMETHOD GetAllowsPosting(PRBool *allowsPosting); + NS_IMETHOD GetKnowsSearchNntpExtension(PRBool *knowsExtension); + NS_IMETHOD GetAllowsPosting(PRBool *allowsPosting); - NS_IMETHOD DisplayRecipients(PRBool *displayRecipients); + NS_IMETHOD DisplayRecipients(PRBool *displayRecipients); #ifdef HAVE_SEMAPHORE MsgERR AcquireSemaphore (void *semHolder); @@ -251,13 +251,13 @@ public: void SkipCacheTokens (char **ppBuf, int numTokens); #endif - NS_IMETHOD GetRelativePathName (char **pathName); + NS_IMETHOD GetRelativePathName (char **pathName); - NS_IMETHOD GetSizeOnDisk(PRUint32 *size); + NS_IMETHOD GetSizeOnDisk(PRUint32 *size); #ifdef HAVE_NET - NS_IMETHOD ShouldPerformOperationOffline(PRBool *performOffline); + NS_IMETHOD ShouldPerformOperationOffline(PRBool *performOffline); #endif #ifdef DOES_FOLDEROPERATIONS @@ -265,25 +265,25 @@ public: void UpdateMoveCopyStatus(MWContext *context, PRBool isMove, int32 curMsgCount, int32 totMessages); #endif - NS_IMETHOD RememberPassword(const char *password); - NS_IMETHOD GetRememberedPassword(char ** password); - NS_IMETHOD UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *needsAuthenticate); - NS_IMETHOD GetUserName(char **userName); - NS_IMETHOD GetHostName(char **hostName); + NS_IMETHOD RememberPassword(const char *password); + NS_IMETHOD GetRememberedPassword(char ** password); + NS_IMETHOD UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *needsAuthenticate); + NS_IMETHOD GetUserName(char **userName); + NS_IMETHOD GetHostName(char **hostName); protected: - char* mName; + char* mName; PRUint32 mFlags; PRUint32 mNumUnreadMessages; /* count of unread messages (-1 means - unknown; -2 means unknown but we already - tried to find out.) */ + unknown; -2 means unknown but we already + tried to find out.) */ PRUint32 mNumTotalMessages; /* count of existing messages. */ nsISupportsArray *mSubFolders; #ifdef HAVE_MASTER MSG_Master *mMaster; #endif - PRInt16 mCsid; // default csid for folder/newsgroup - maintained by fe. + PRInt16 mCsid; // default csid for folder/newsgroup - maintained by fe. PRUint8 mDepth; PRUint32 mPrefFlags; // prefs like MSG_PREF_OFFLINE, MSG_PREF_ONE_PANE, etc #ifdef HAVE_SEMAPHORE @@ -291,95 +291,18 @@ protected: #endif #ifdef HAVE_DB - MessageKey m_lastMessageLoaded; - // These values are used for tricking the front end into thinking that we have more - // messages than are really in the DB. This is usually after and IMAP message copy where - // we don't want to do an expensive select until the user actually opens that folder - PRUint32 mNumPendingUnreadMessages; - PRUint32 mNumPendingTotalMessages; + MessageKey m_lastMessageLoaded; + // These values are used for tricking the front end into thinking that we have more + // messages than are really in the DB. This is usually after and IMAP message copy where + // we don't want to do an expensive select until the user actually opens that folder + PRUint32 mNumPendingUnreadMessages; + PRUint32 mNumPendingTotalMessages; #endif #ifdef HAVE_CACHE PRBool mIsCachable; #endif - }; - -class nsMsgMailFolder : public nsMsgFolder, public nsIMsgMailFolder -{ -public: - nsMsgMailFolder(const char* uri); - ~nsMsgMailFolder(); - - NS_IMETHOD QueryInterface(REFNSIID aIID, - void** aInstancePtr); - NS_IMETHOD_(nsrefcnt) AddRef(void); - NS_IMETHOD_(nsrefcnt) Release(void); - - NS_IMETHOD GetType(FolderType *type); - -#ifdef HAVE_DB - virtual MsgERR BeginCopyingMessages (MSG_FolderInfo *dstFolder, - nsMsgDatabase *sourceDB, - nsMsgKeyArray *srcArray, - MSG_UrlQueue *urlQueue, - int32 srcCount, - MessageCopyInfo *copyInfo); - - - virtual int FinishCopyingMessages (MWContext *context, - MSG_FolderInfo * srcFolder, - MSG_FolderInfo *dstFolder, - nsMsgDatabase *sourceDB, - nsMsgKeyArray **ppSrcArray, - int32 srcCount, - msg_move_state *state); -#endif - - NS_IMETHOD CreateSubfolder(const char *leafNameFromUser, nsIMsgFolder **outFolder, PRUint32 *outPos); - - NS_IMETHOD RemoveSubFolder (const nsIMsgFolder *which); - NS_IMETHOD Delete (); - NS_IMETHOD Rename (const char *newName); - NS_IMETHOD Adopt(const nsIMsgFolder *srcFolder, PRUint32 *outPos); - - // this override pulls the value from the db - NS_IMETHOD GetName(char** name); // Name of this folder (as presented to user). - NS_IMETHOD GetPrettyName(char ** prettyName); // Override of the base, for top-level mail folder - - NS_IMETHOD BuildFolderURL(char **url); - - NS_IMETHOD GenerateUniqueSubfolderName(const char *prefix, const nsIMsgFolder *otherFolder, char** name); - - NS_IMETHOD UpdateSummaryTotals() ; - - NS_IMETHOD GetExpungedBytesCount(PRUint32 *count); - NS_IMETHOD GetDeletable (PRBool *deletable); - NS_IMETHOD GetCanCreateChildren (PRBool *canCreateChildren) ; - NS_IMETHOD GetCanBeRenamed (PRBool *canBeRenamed); - NS_IMETHOD GetRequiresCleanup(PRBool *requiresCleanup); - - - NS_IMETHOD GetRelativePathName (char **pathName); - - - NS_IMETHOD GetSizeOnDisk(PRUint32 size); - - NS_IMETHOD GetUserName(char** userName); - NS_IMETHOD GetHostName(char** hostName); - NS_IMETHOD UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate); - NS_IMETHOD RememberPassword(const char *password); - NS_IMETHOD GetRememberedPassword(char ** password); - - //nsIMsgMailFolder - NS_IMETHOD GetPathName(char * *aPathName); - NS_IMETHOD SetPathName(char * aPathName); - -protected: - char* mPathName; - PRUint32 mExpungedBytes; - PRBool mHaveReadNameFromDB; - PRBool mGettingMail; }; #endif diff --git a/mailnews/base/src/nsMsgLocalMailFolder.cpp b/mailnews/base/src/nsMsgLocalMailFolder.cpp new file mode 100644 index 000000000000..8cc6147b0893 --- /dev/null +++ b/mailnews/base/src/nsMsgLocalMailFolder.cpp @@ -0,0 +1,682 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsMsgLocalMailFolder.h" +#include "nsMsgFolderFlags.h" +#include "prprf.h" + +static NS_DEFINE_IID(kIMsgLocalMailFolderIID, NS_IMSGLOCALMAILFOLDER_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +nsMsgLocalMailFolder::nsMsgLocalMailFolder(const char* uri) +:nsMsgFolder(uri) +{ + mHaveReadNameFromDB = PR_FALSE; + mPathName = nsnull; +} + +nsMsgLocalMailFolder::~nsMsgLocalMailFolder() +{ +} + +NS_IMPL_ADDREF(nsMsgLocalMailFolder) +NS_IMPL_RELEASE(nsMsgLocalMailFolder) + +NS_IMETHODIMP +nsMsgLocalMailFolder::QueryInterface(REFNSIID iid, void** result) +{ + if (! result) + return NS_ERROR_NULL_POINTER; + + *result = nsnull; + if (iid.Equals(kIMsgLocalMailFolderIID) || + iid.Equals(kISupportsIID)) + { + *result = NS_STATIC_CAST(nsIMsgLocalMailFolder*, this); + AddRef(); + return NS_OK; + } + return nsMsgFolder::QueryInterface(iid, result); +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetType(FolderType *type) +{ + if(!type) + return NS_ERROR_NULL_POINTER; + + *type = FOLDER_MAIL; + + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::BuildFolderURL(char **url) +{ + const char *urlScheme = "mailbox:"; + + if(!url) + return NS_ERROR_NULL_POINTER; + + *url = PR_smprintf("%s%s", urlScheme, mPathName); + return NS_OK; + +} + +NS_IMETHODIMP nsMsgLocalMailFolder::CreateSubfolder(const char *leafNameFromUser, nsIMsgFolder **outFolder, PRUint32 *outPos) +{ +#ifdef HAVE_PORT + MsgERR status = 0; + *ppOutFolder = NULL; + *pOutPos = 0; + XP_StatStruct stat; + + + // Only create a .sbd pathname if we're not in the root folder. The root folder + // e.g. c:\netscape\mail has to behave differently than subfolders. + if (m_depth > 1) + { + // Look around in our directory to get a subdirectory, creating it + // if necessary + XP_BZERO (&stat, sizeof(stat)); + if (0 == XP_Stat (m_pathName, &stat, xpMailSubdirectory)) + { + if (!S_ISDIR(stat.st_mode)) + status = MK_COULD_NOT_CREATE_DIRECTORY; // a file .sbd already exists + } + else { + status = XP_MakeDirectory (m_pathName, xpMailSubdirectory); + if (status == -1) + status = MK_COULD_NOT_CREATE_DIRECTORY; + } + } + + char *leafNameForDisk = CreatePlatformLeafNameForDisk(leafNameFromUser,m_master, this); + if (!leafNameForDisk) + status = MK_OUT_OF_MEMORY; + + if (0 == status) //ok so far + { + // Now that we have a suitable parent directory created/identified, + // we can create the new mail folder inside the parent dir. Again, + + char *newFolderPath = (char*) XP_ALLOC(XP_STRLEN(m_pathName) + XP_STRLEN(leafNameForDisk) + XP_STRLEN(".sbd/") + 1); + if (newFolderPath) + { + XP_STRCPY (newFolderPath, m_pathName); + if (m_depth == 1) + XP_STRCAT (newFolderPath, "/"); + else + XP_STRCAT (newFolderPath, ".sbd/"); + XP_STRCAT (newFolderPath, leafNameForDisk); + + if (0 != XP_Stat (newFolderPath, &stat, xpMailFolder)) + { + XP_File file = XP_FileOpen(newFolderPath, xpMailFolder, XP_FILE_WRITE_BIN); + if (file) + { + // Create an empty database for this mail folder, set its name from the user + MailDB *unusedDb = NULL; + MailDB::Open(newFolderPath, TRUE, &unusedDb, TRUE); + if (unusedDb) + { + //need to set the folder name + + MSG_FolderInfoMail *newFolder = BuildFolderTree (newFolderPath, m_depth + 1, m_subFolders, m_master); + if (newFolder) + { + // so we don't show ??? in totals + newFolder->SummaryChanged(); + *ppOutFolder = newFolder; + *pOutPos = m_subFolders->FindIndex (0, newFolder); + } + else + status = MK_OUT_OF_MEMORY; + unusedDb->SetFolderInfoValid(newFolderPath,0,0); + unusedDb->Close(); + } + else + { + XP_FileClose(file); + file = NULL; + XP_FileRemove (newFolderPath, xpMailFolder); + status = MK_MSG_CANT_CREATE_FOLDER; + } + if (file) + { + XP_FileClose(file); + file = NULL; + } + } + else + status = MK_MSG_CANT_CREATE_FOLDER; + } + else + status = MK_MSG_FOLDER_ALREADY_EXISTS; + FREEIF(newFolderPath); + } + else + status = MK_OUT_OF_MEMORY; + } + FREEIF(leafNameForDisk); + return status; +#endif //HAVE_PORT + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::RemoveSubFolder (const nsIMsgFolder *which) +{ + // Let the base class do list management + nsMsgFolder::RemoveSubFolder (which); + + // Derived class is responsible for managing the subdirectory +#ifdef HAVE_PORT + if (0 == m_subFolders->GetSize()) + XP_RemoveDirectory (m_pathName, xpMailSubdirectory); +#endif + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::Delete () +{ +#ifdef HAVE_PORT + nsMsgDatabase *db; + // remove the summary file + MsgERR status = CloseDatabase (m_pathName, &db); + if (0 == status) + { + if (db != NULL) + db->Close(); // decrement ref count, so it will leave cache + XP_FileRemove (m_pathName, xpMailFolderSummary); + } + + if ((0 == status) && (GetType() == FOLDER_MAIL)) + { + // remove the mail folder file + status = XP_FileRemove (m_pathName, xpMailFolder); + + // if the delete seems to have failed, but the file doesn't + // exist, that's not really an error condition, is it now? + if (status) + { + XP_StatStruct fileStat; + if (0 == XP_Stat(m_pathName, &fileStat, xpMailFolder)) + status = 0; + } + } + + + if (0 != status) + status = MK_UNABLE_TO_DELETE_FILE; + return status; +#endif + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::Rename (const char *newName) +{ +#ifdef HAVE_PORT + // change the leaf name (stored separately) + MsgERR status = MSG_FolderInfo::Rename (newUserLeafName); + if (status == 0) + { + char *baseDir = XP_STRDUP(m_pathName); + if (baseDir) + { + char *base_slash = XP_STRRCHR (baseDir, '/'); + if (base_slash) + *base_slash = '\0'; + } + + char *leafNameForDisk = CreatePlatformLeafNameForDisk(newUserLeafName,m_master, baseDir); + if (!leafNameForDisk) + status = MK_OUT_OF_MEMORY; + + if (0 == status) + { + // calculate the new path name + char *newPath = (char*) XP_ALLOC(XP_STRLEN(m_pathName) + XP_STRLEN(leafNameForDisk) + 1); + XP_STRCPY (newPath, m_pathName); + char *slash = XP_STRRCHR (newPath, '/'); + if (slash) + XP_STRCPY (slash + 1, leafNameForDisk); + + // rename the mail summary file, if there is one + nsMsgDatabase *db = NULL; + status = CloseDatabase (m_pathName, &db); + + XP_StatStruct fileStat; + if (!XP_Stat(m_pathName, &fileStat, xpMailFolderSummary)) + status = XP_FileRename(m_pathName, xpMailFolderSummary, newPath, xpMailFolderSummary); + if (0 == status) + { + if (db) + { + if (ReopenDatabase (db, newPath) == 0) + { + //need to set mailbox name + } + } + else + { + MailDB *mailDb = NULL; + MailDB::Open(newPath, TRUE, &mailDb, TRUE); + if (mailDb) + { + //need to set mailbox name + mailDb->Close(); + } + } + } + + // rename the mail folder file, if its local + if ((status == 0) && (GetType() == FOLDER_MAIL)) + status = XP_FileRename (m_pathName, xpMailFolder, newPath, xpMailFolder); + + if (status == 0) + { + // rename the subdirectory if there is one + if (m_subFolders->GetSize() > 0) + status = XP_FileRename (m_pathName, xpMailSubdirectory, newPath, xpMailSubdirectory); + + // tell all our children about the new pathname + if (status == 0) + { + int startingAt = XP_STRLEN (newPath) - XP_STRLEN (leafNameForDisk) + 1; // add one for trailing '/' + status = PropagateRename (leafNameForDisk, startingAt); + } + } + } + FREEIF(baseDir); + } + return status; +#endif + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::Adopt(const nsIMsgFolder *srcFolder, PRUint32 *outPos) +{ +#ifdef HAVE_PORT + MsgERR err = eSUCCESS; + XP_ASSERT (srcFolder->GetType() == GetType()); // we can only adopt the same type of folder + MSG_FolderInfoMail *mailFolder = (MSG_FolderInfoMail*) srcFolder; + + if (srcFolder == this) + return MK_MSG_CANT_COPY_TO_SAME_FOLDER; + + if (ContainsChildNamed(mailFolder->GetName())) + return MK_MSG_FOLDER_ALREADY_EXISTS; + + // If we aren't already a directory, create the directory and set the flag bits + if (0 == m_subFolders->GetSize()) + { + XP_Dir dir = XP_OpenDir (m_pathName, xpMailSubdirectory); + if (dir) + XP_CloseDir (dir); + else + { + XP_MakeDirectory (m_pathName, xpMailSubdirectory); + dir = XP_OpenDir (m_pathName, xpMailSubdirectory); + if (dir) + XP_CloseDir (dir); + else + err = MK_COULD_NOT_CREATE_DIRECTORY; + } + if (eSUCCESS == err) + { + m_flags |= MSG_FOLDER_FLAG_DIRECTORY; + m_flags |= MSG_FOLDER_FLAG_ELIDED; + } + } + + // Recurse the tree to adopt srcFolder's children + err = mailFolder->PropagateAdopt (m_pathName, m_depth); + + // Add the folder to our tree in the right sorted position + if (eSUCCESS == err) + { + XP_ASSERT(m_subFolders->FindIndex(0, srcFolder) == -1); + *pOutPos = m_subFolders->Add (srcFolder); + } + + return err; +#endif + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetName(char** name) +{ + if(!name) + return NS_ERROR_NULL_POINTER; + + if (!mHaveReadNameFromDB) + { + if (mDepth == 1) + { + SetName("Local Mail"); + mHaveReadNameFromDB = TRUE; + } + else + { + //Need to read the name from the database + } + } + *name = mName; + + + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetPrettyName(char ** prettyName) +{ + if (mDepth == 1) { + // Depth == 1 means we are on the mail server level + // override the name here to say "Local Mail" + FolderType type; + GetType(&type); + if (type == FOLDER_MAIL) + *prettyName = PL_strdup("Local Mail"); + else + return nsMsgFolder::GetPrettyName(prettyName); + } + else + return nsMsgFolder::GetPrettyName(prettyName); + + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GenerateUniqueSubfolderName(const char *prefix, + const nsIMsgFolder *otherFolder, + char** name) +{ + if(!name) + return NS_ERROR_NULL_POINTER; + + /* only try 256 times */ + for (int count = 0; (count < 256); count++) + { + PRUint32 prefixSize = PL_strlen(prefix); + + //allocate string big enough for prefix, 256, and '\0' + char *uniqueName = (char*)PR_MALLOC(prefixSize + 4); + PR_snprintf(uniqueName, prefixSize + 4, "%s%d",prefix,count); + PRBool containsChild; + PRBool otherContainsChild = PR_FALSE; + + ContainsChildNamed(uniqueName, &containsChild); + if(otherFolder) + { + ((nsIMsgFolder*)otherFolder)->ContainsChildNamed(uniqueName, &otherContainsChild); + } + + if (!containsChild && !otherContainsChild) + { + *name = uniqueName; + return NS_OK; + } + else + PR_FREEIF(uniqueName); + } + *name = nsnull; + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::UpdateSummaryTotals() +{ + //We need to read this info from the database + + // If we asked, but didn't get any, stop asking + if (mNumUnreadMessages == -1) + mNumUnreadMessages = -2; + + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetExpungedBytesCount(PRUint32 *count) +{ + if(!count) + return NS_ERROR_NULL_POINTER; + + *count = mExpungedBytes; + + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetDeletable (PRBool *deletable) +{ + if(!deletable) + return NS_ERROR_NULL_POINTER; + + // These are specified in the "Mail/News Windows" UI spec + + if (mFlags & MSG_FOLDER_FLAG_TRASH) + { + PRBool moveToTrash; + GetDeleteIsMoveToTrash(&moveToTrash); + if(moveToTrash) + *deletable = PR_TRUE; // allow delete of trash if we don't use trash + } + else if (mDepth == 1) + *deletable = PR_FALSE; + else if (mFlags & MSG_FOLDER_FLAG_INBOX || + mFlags & MSG_FOLDER_FLAG_DRAFTS || + mFlags & MSG_FOLDER_FLAG_TRASH || + mFlags & MSG_FOLDER_FLAG_TEMPLATES) + *deletable = PR_FALSE; + else *deletable = PR_TRUE; + + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetCanCreateChildren (PRBool *canCreateChildren) +{ + if(!canCreateChildren) + return NS_ERROR_NULL_POINTER; + + *canCreateChildren = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetCanBeRenamed (PRBool *canBeRenamed) +{ + if(!canBeRenamed) + return NS_ERROR_NULL_POINTER; + + // The root mail folder can't be renamed + if (mDepth < 2) + *canBeRenamed = PR_FALSE; + + // Here's a weird case necessitated because we don't have a separate + // preference for any folder name except the FCC folder (Sent). Others + // are known by name, and as such, can't be renamed. I guess. + else if (mFlags & MSG_FOLDER_FLAG_TRASH || + mFlags & MSG_FOLDER_FLAG_DRAFTS || + mFlags & MSG_FOLDER_FLAG_QUEUE || + mFlags & MSG_FOLDER_FLAG_INBOX || + mFlags & MSG_FOLDER_FLAG_TEMPLATES) + *canBeRenamed = PR_FALSE; + else + *canBeRenamed = PR_TRUE; + + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetRequiresCleanup(PRBool *requiresCleanup) +{ +#ifdef HAVE_PORT + if (m_expungedBytes > 0) + { + int32 purgeThreshhold = m_master->GetPrefs()->GetPurgeThreshhold(); + PRBool purgePrompt = m_master->GetPrefs()->GetPurgeThreshholdEnabled();; + return (purgePrompt && m_expungedBytes / 1000L > purgeThreshhold); + } + return FALSE; +#endif + return NS_OK; +} + + + +NS_IMETHODIMP nsMsgLocalMailFolder::GetRelativePathName (char **pathName) +{ + if(!pathName) + return NS_ERROR_NULL_POINTER; + *pathName = mPathName; + return NS_OK; +} + + +NS_IMETHODIMP nsMsgLocalMailFolder::GetSizeOnDisk(PRUint32 size) +{ +#ifdef HAVE_PORT + int32 ret = 0; + XP_StatStruct st; + + if (!XP_Stat(GetPathname(), &st, xpMailFolder)) + ret += st.st_size; + + if (!XP_Stat(GetPathname(), &st, xpMailFolderSummary)) + ret += st.st_size; + + return ret; +#endif + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetUserName(char** userName) +{ +#ifdef HAVE_PORT + return NET_GetPopUsername(); +#endif + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetHostName(char** hostName) +{ +#ifdef HAVE_PORT + PRBool serverIsIMAP = m_master->GetPrefs()->GetMailServerIsIMAP4(); + if (serverIsIMAP) + { + MSG_IMAPHost *defaultIMAPHost = m_master->GetIMAPHostTable()->GetDefaultHost(); + return (defaultIMAPHost) ? defaultIMAPHost->GetHostName() : 0; + } + else + return m_master->GetPrefs()->GetPopHost(); +#endif + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate) +{ +#ifdef HAVE_PORT + PRBool ret = FALSE; + if (m_master->IsCachePasswordProtected() && !m_master->IsUserAuthenticated() && !m_master->AreLocalFoldersAuthenticated()) + { + char *savedPassword = GetRememberedPassword(); + if (savedPassword && XP_STRLEN(savedPassword)) + ret = TRUE; + FREEIF(savedPassword); + } + return ret; +#endif + + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::RememberPassword(const char *password) +{ +#ifdef HAVE_DB + MailDB *mailDb = NULL; + MailDB::Open(m_pathName, TRUE, &mailDb); + if (mailDb) + { + mailDb->SetCachedPassword(password); + mailDb->Close(); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetRememberedPassword(char ** password) +{ +#ifdef HAVE_PORT + PRBool serverIsIMAP = m_master->GetPrefs()->GetMailServerIsIMAP4(); + char *savedPassword = NULL; + if (serverIsIMAP) + { + MSG_IMAPHost *defaultIMAPHost = m_master->GetIMAPHostTable()->GetDefaultHost(); + if (defaultIMAPHost) + { + MSG_FolderInfo *hostFolderInfo = defaultIMAPHost->GetHostFolderInfo(); + MSG_FolderInfo *defaultHostIMAPInbox = NULL; + if (hostFolderInfo->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, &defaultHostIMAPInbox, 1) == 1 + && defaultHostIMAPInbox != NULL) + { + savedPassword = defaultHostIMAPInbox->GetRememberedPassword(); + } + } + } + else + { + MSG_FolderInfo *offlineInbox = NULL; + if (m_flags & MSG_FOLDER_FLAG_INBOX) + { + char *retPassword = NULL; + MailDB *mailDb = NULL; + MailDB::Open(m_pathName, FALSE, &mailDb, FALSE); + if (mailDb) + { + mailDb->GetCachedPassword(cachedPassword); + retPassword = XP_STRDUP(cachedPassword); + mailDb->Close(); + + } + return retPassword; + } + if (m_master->GetLocalMailFolderTree()->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, &offlineInbox, 1) && offlineInbox) + savedPassword = offlineInbox->GetRememberedPassword(); + } + return savedPassword; +#endif + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::GetPathName(char * *aPathName) +{ + if(!aPathName) + return NS_ERROR_NULL_POINTER; + + if(mPathName) + *aPathName = PL_strdup(mPathName); + else + *aPathName = nsnull; + + return NS_OK; +} + +NS_IMETHODIMP nsMsgLocalMailFolder::SetPathName(char * aPathName) +{ + if(mPathName) + PR_FREEIF(mPathName); + + if(aPathName) + mPathName = PL_strdup(aPathName); + else + mPathName = nsnull; + + return NS_OK; +} + diff --git a/mailnews/base/src/nsMsgLocalMailFolder.h b/mailnews/base/src/nsMsgLocalMailFolder.h new file mode 100644 index 000000000000..8198b2f9ad7d --- /dev/null +++ b/mailnews/base/src/nsMsgLocalMailFolder.h @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/******************************************************************************************************** + + Interface for representing Messenger folders. + +*********************************************************************************************************/ + +#ifndef nsMsgLocalMailFolder_h__ +#define nsMsgLocalMailFolder_h__ + +#include "nsMsgFolder.h" /* include the interface we are going to support */ + +class nsMsgLocalMailFolder : public nsMsgFolder, public nsIMsgLocalMailFolder +{ +public: + nsMsgLocalMailFolder(const char* uri); + ~nsMsgLocalMailFolder(); + + NS_IMETHOD QueryInterface(REFNSIID aIID, + void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + NS_IMETHOD GetType(FolderType *type); + +#ifdef HAVE_DB + virtual MsgERR BeginCopyingMessages (MSG_FolderInfo *dstFolder, + MessageDB *sourceDB, + IDArray *srcArray, + MSG_UrlQueue *urlQueue, + int32 srcCount, + MessageCopyInfo *copyInfo); + + + virtual int FinishCopyingMessages (MWContext *context, + MSG_FolderInfo * srcFolder, + MSG_FolderInfo *dstFolder, + MessageDB *sourceDB, + IDArray **ppSrcArray, + int32 srcCount, + msg_move_state *state); +#endif + + NS_IMETHOD CreateSubfolder(const char *leafNameFromUser, nsIMsgFolder **outFolder, PRUint32 *outPos); + + NS_IMETHOD RemoveSubFolder (const nsIMsgFolder *which); + NS_IMETHOD Delete (); + NS_IMETHOD Rename (const char *newName); + NS_IMETHOD Adopt(const nsIMsgFolder *srcFolder, PRUint32 *outPos); + + // this override pulls the value from the db + NS_IMETHOD GetName(char** name); // Name of this folder (as presented to user). + NS_IMETHOD GetPrettyName(char ** prettyName); // Override of the base, for top-level mail folder + + NS_IMETHOD BuildFolderURL(char **url); + + NS_IMETHOD GenerateUniqueSubfolderName(const char *prefix, const nsIMsgFolder *otherFolder, char** name); + + NS_IMETHOD UpdateSummaryTotals() ; + + NS_IMETHOD GetExpungedBytesCount(PRUint32 *count); + NS_IMETHOD GetDeletable (PRBool *deletable); + NS_IMETHOD GetCanCreateChildren (PRBool *canCreateChildren) ; + NS_IMETHOD GetCanBeRenamed (PRBool *canBeRenamed); + NS_IMETHOD GetRequiresCleanup(PRBool *requiresCleanup); + + + NS_IMETHOD GetRelativePathName (char **pathName); + + + NS_IMETHOD GetSizeOnDisk(PRUint32 size); + + NS_IMETHOD GetUserName(char** userName); + NS_IMETHOD GetHostName(char** hostName); + NS_IMETHOD UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate); + NS_IMETHOD RememberPassword(const char *password); + NS_IMETHOD GetRememberedPassword(char ** password); + + //nsIMsgMailFolder + NS_IMETHOD GetPathName(char * *aPathName); + NS_IMETHOD SetPathName(char * aPathName); + +protected: + char* mPathName; + PRUint32 mExpungedBytes; + PRBool mHaveReadNameFromDB; + PRBool mGettingMail; +}; + +#endif // nsMsgLocalMailFolder_h__ diff --git a/mailnews/db/msgdb/public/nsMsgDatabase.h b/mailnews/db/msgdb/public/nsMsgDatabase.h index da80a8b7617f..c77d9ab34d7e 100644 --- a/mailnews/db/msgdb/public/nsMsgDatabase.h +++ b/mailnews/db/msgdb/public/nsMsgDatabase.h @@ -20,7 +20,7 @@ #include "nsMsgHdr.h" -#include "nsMsgPtrArray.h" // for XPPtrArray +#include "nsVoidArray.h" #include "nsString.h" #include "nsFileSpec.h" #include "nsIDBChangeListener.h" @@ -31,7 +31,7 @@ class nsDBFolderInfo; class nsMsgKeyArray; class nsNewsSet; -class nsDBChangeAnnouncer : public XPPtrArray // array of ChangeListeners +class nsDBChangeAnnouncer : public nsVoidArray // array of ChangeListeners { public: nsDBChangeAnnouncer(); @@ -47,14 +47,14 @@ public: // used to cache open db's. -class nsMsgDatabaseArray : public XPPtrArray +class nsMsgDatabaseArray : public nsVoidArray { public: nsMsgDatabaseArray(); // overrides with proper types to avoid casting - nsMsgDatabase* GetAt(int nIndex) const {return((nsMsgDatabase*)XPPtrArray::GetAt(nIndex));} - void* operator[](int nIndex) const {return((nsMsgDatabase*)XPPtrArray::operator[](nIndex));} + nsMsgDatabase* GetAt(int nIndex) const {return((nsMsgDatabase*)nsVoidArray::ElementAt(nIndex));} + void* operator[](int nIndex) const {return((nsMsgDatabase*)nsVoidArray::operator[](nIndex));} }; // This is to be used as an interchange object, to make creating nsMsgHeaders easier. @@ -142,7 +142,7 @@ public: static void CleanupCache(); #ifdef DEBUG - static int GetNumInCache(void) {return(GetDBCache()->GetSize());} + static int GetNumInCache(void) {return(GetDBCache()->Count());} static void DumpCache(); #endif protected: @@ -157,7 +157,7 @@ protected: nsrefcnt mRefCnt; static void AddToCache(nsMsgDatabase* pMessageDB) - {GetDBCache()->Add(pMessageDB);} + {GetDBCache()->AppendElement(pMessageDB);} static void RemoveFromCache(nsMsgDatabase* pMessageDB); static int FindInCache(nsMsgDatabase* pMessageDB); PRBool MatchDbName(nsFilePath &dbName); // returns TRUE if they match diff --git a/mailnews/db/msgdb/src/nsMailDatabase.cpp b/mailnews/db/msgdb/src/nsMailDatabase.cpp index 24c0ea6b3bd2..4c4704956372 100644 --- a/mailnews/db/msgdb/src/nsMailDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMailDatabase.cpp @@ -118,7 +118,7 @@ nsMailDatabase::~nsMailDatabase() if (err == NS_OK || err == NS_MSG_ERROR_FOLDER_SUMMARY_MISSING) { *pMessageDB = mailDB; - GetDBCache()->Add(mailDB); + GetDBCache()->AppendElement(mailDB); // if (err == NS_OK) // mailDB->HandleLatered(); diff --git a/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mailnews/db/msgdb/src/nsMsgDatabase.cpp index 89973d0c0441..8a20c183ca6a 100644 --- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -64,7 +64,7 @@ nsMsgDatabase::CleanupCache() { if (m_dbCache) // clean up memory leak { - for (int i = 0; i < GetDBCache()->GetSize(); i++) + for (int i = 0; i < GetDBCache()->Count(); i++) { nsMsgDatabase* pMessageDB = GetDBCache()->GetAt(i); if (pMessageDB) @@ -89,7 +89,7 @@ nsMsgDatabase::CleanupCache() //---------------------------------------------------------------------- nsMsgDatabase* nsMsgDatabase::FindInCache(nsFilePath &dbName) { - for (int i = 0; i < GetDBCache()->GetSize(); i++) + for (int i = 0; i < GetDBCache()->Count(); i++) { nsMsgDatabase* pMessageDB = GetDBCache()->GetAt(i); if (pMessageDB->MatchDbName(dbName)) @@ -105,7 +105,7 @@ nsMsgDatabase* nsMsgDatabase::FindInCache(nsFilePath &dbName) //---------------------------------------------------------------------- int nsMsgDatabase::FindInCache(nsMsgDatabase* pMessageDB) { - for (int i = 0; i < GetDBCache()->GetSize(); i++) + for (int i = 0; i < GetDBCache()->Count(); i++) { if (GetDBCache()->GetAt(i) == pMessageDB) { @@ -129,7 +129,7 @@ void nsMsgDatabase::RemoveFromCache(nsMsgDatabase* pMessageDB) int i = FindInCache(pMessageDB); if (i != -1) { - GetDBCache()->RemoveAt(i); + GetDBCache()->RemoveElementAt(i); } } @@ -137,7 +137,7 @@ void nsMsgDatabase::RemoveFromCache(nsMsgDatabase* pMessageDB) #ifdef DEBUG void nsMsgDatabase::DumpCache() { - for (int i = 0; i < GetDBCache()->GetSize(); i++) + for (int i = 0; i < GetDBCache()->Count(); i++) { #ifdef DEBUG_bienvenu nsMsgDatabase* pMessageDB = diff --git a/mailnews/local/src/nsMSGFolderDataSource.cpp b/mailnews/local/src/nsMSGFolderDataSource.cpp index c53e1b31de12..1bdf28075ae5 100644 --- a/mailnews/local/src/nsMSGFolderDataSource.cpp +++ b/mailnews/local/src/nsMSGFolderDataSource.cpp @@ -42,7 +42,7 @@ static NS_DEFINE_IID(kIRDFResourceFactoryIID, NS_IRDFRESOURCEFACTORY_IID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID); static NS_DEFINE_IID(kIMsgFolderIID, NS_IMSGFOLDER_IID); -static NS_DEFINE_IID(kIMsgMailFolderIID, NS_IMSGMAILFOLDER_IID); +static NS_DEFINE_IID(kIMsgLocalMailFolderIID, NS_IMSGLOCALMAILFOLDER_IID); static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID); static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID); static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID); @@ -468,8 +468,8 @@ nsMSGFolderDataSource::InitLocalFolders(nsIMsgFolder* aParentFolder, nsNativeFil folder->GetNameFromPathName(pathStr, &folderName); folder->SetName(folderName); - nsIMsgMailFolder *mailFolder; - if(NS_SUCCEEDED(folder->QueryInterface(kIMsgMailFolderIID, (void**)&mailFolder))) + nsIMsgLocalMailFolder *mailFolder; + if(NS_SUCCEEDED(folder->QueryInterface(kIMsgLocalMailFolderIID, (void**)&mailFolder))) { mailFolder->SetPathName(pathStr); NS_IF_RELEASE(mailFolder); @@ -506,8 +506,8 @@ nsMSGFolderDataSource::InitLocalFolders(nsIMsgFolder* aParentFolder, nsNativeFil folder->GetNameFromPathName(pathStr, &folderName); folder->SetName(folderName); - nsIMsgMailFolder *mailFolder; - if(NS_SUCCEEDED(folder->QueryInterface(kIMsgMailFolderIID, (void**)&mailFolder))) + nsIMsgLocalMailFolder *mailFolder; + if(NS_SUCCEEDED(folder->QueryInterface(kIMsgLocalMailFolderIID, (void**)&mailFolder))) { mailFolder->SetPathName(pathStr); NS_IF_RELEASE(mailFolder); diff --git a/mailnews/news/src/nsNNTPHost.cpp b/mailnews/news/src/nsNNTPHost.cpp index f9f3eb912061..efc21f0bdf18 100644 --- a/mailnews/news/src/nsNNTPHost.cpp +++ b/mailnews/news/src/nsNNTPHost.cpp @@ -30,7 +30,6 @@ #include "nsNNTPArticleSet.h" #include "nsMsgGroupRecord.h" -#include "nsMsgPtrArray.h" #include "nsINNTPNewsgroup.h" #include "nsNNTPNewsgroup.h" diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 9ccd39ac2b24..f0d4fdc6ef39 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -24,6 +24,8 @@ #include "nsIInputStream.h" #include "nntpCore.h" +#include "nsCRT.h" +#include "xp.h" // XXX remove! #include "rosetta.h" #include HG40855 @@ -34,7 +36,6 @@ #include "prerror.h" #include "nsEscape.h" -#include "xp_str.h" #include "fe_proto.h" #include "prprf.h" #include "merrors.h" @@ -338,7 +339,7 @@ void nsNNTPProtocol::Initialize(nsIURL * aURL, nsITransport * transportLayer) const char * hostName = NULL; aURL->GetHost(&hostName); if (hostName) - m_hostName = PL_strdup(hostName); + m_hostName = nsCRT::strdup(hostName); else m_hostName = NULL; @@ -382,6 +383,7 @@ PRInt32 nsNNTPProtocol::LoadURL(nsIURL * aURL) PRBool cancel = FALSE; char* colon; nsINNTPNewsgroupPost *message=NULL; + char *message_id = 0; nsresult rv = NS_OK; @@ -511,22 +513,22 @@ PRInt32 nsNNTPProtocol::LoadURL(nsIURL * aURL) if (PL_strstr(commandSpecificData, "?list-pretty")) { m_typeWanted = PRETTY_NAMES_WANTED; - m_commandSpecificData = PL_strdup(commandSpecificData); + m_commandSpecificData = nsCRT::strdup(commandSpecificData); } else if (PL_strstr(commandSpecificData, "?profile")) { m_typeWanted = PROFILE_WANTED; - m_commandSpecificData = PL_strdup(commandSpecificData); + m_commandSpecificData = nsCRT::strdup(commandSpecificData); } else if (PL_strstr(commandSpecificData, "?list-ids")) { m_typeWanted= IDS_WANTED; - m_commandSpecificData = PL_strdup(commandSpecificData); + m_commandSpecificData = nsCRT::strdup(commandSpecificData); } else { m_typeWanted = SEARCH_WANTED; - m_commandSpecificData = PL_strdup(commandSpecificData); + m_commandSpecificData = nsCRT::strdup(commandSpecificData); m_searchData = m_commandSpecificData; } } @@ -569,8 +571,8 @@ PRInt32 nsNNTPProtocol::LoadURL(nsIURL * aURL) if( (colon = PL_strchr(unamePwd, ':')) != NULL ) { *colon = '\0'; - userName = PL_strdup(unamePwd); - password = PL_strdup(colon+1); + userName = nsCRT::strdup(unamePwd); + password = nsCRT::strdup(colon+1); *colon = ':'; PR_Free(unamePwd); } @@ -730,7 +732,7 @@ PRInt32 nsNNTPProtocol::ParseURL(nsIURL * aURL, char ** aHostAndPort, PRBool * b aURL->GetHost(&host); if (host) - hostAndPort = PL_strdup(host); + hostAndPort = nsCRT::strdup(host); // mscott: I took out default code to generate host and port // if the url didn't have any...add this later... @@ -771,7 +773,7 @@ PRInt32 nsNNTPProtocol::ParseURL(nsIURL * aURL, char ** aHostAndPort, PRBool * b if (!path_part) path_part = ""; - group = PL_strdup (path_part); + group = nsCRT::strdup (path_part); if (!group) { status = MK_OUT_OF_MEMORY; @@ -828,7 +830,7 @@ PRInt32 nsNNTPProtocol::ParseURL(nsIURL * aURL, char ** aHostAndPort, PRBool * b if (*s) { - command_specific_data = PL_strdup (s); + command_specific_data = nsCRT::strdup (s); *s = 0; if (!command_specific_data) { @@ -1517,7 +1519,7 @@ PRInt32 nsNNTPProtocol::GetPropertiesResponse(nsIInputStream * inputStream, PRUi if ('.' != line[0]) { - char *propertyName = PL_strdup(line); + char *propertyName = nsCRT::strdup(line); if (propertyName) { char *space = PL_strchr(propertyName, ' '); @@ -1961,7 +1963,7 @@ PRInt32 nsNNTPProtocol::BeginArticle() */ PL_strfree (m_currentGroup); #ifdef UNREADY_CODE - ce->URL_s->content_type = PL_strdup (MESSAGE_RFC822); + ce->URL_s->content_type = nsCRT::strdup (MESSAGE_RFC822); #endif #ifdef NO_ARTICLE_CACHEING @@ -2072,7 +2074,7 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt /* Don't send content-type to mime parser if we're doing a cancel because it confuses mime parser into not parsing. */ - if (m_typeWanted != CANCEL_WANTED || XP_STRNCMP(outputBuffer, "Content-Type:", 13)) + if (m_typeWanted != CANCEL_WANTED || nsCRT::strncmp(outputBuffer, "Content-Type:", 13)) { // for test purposes...we'd want to write this line out to an rfc-822 stream converter... // we don't have one now so print the data out so we can verify that we got it.... @@ -3452,7 +3454,7 @@ PRInt32 nsNNTPProtocol::Cancel() if (!ok) { status = MK_NNTP_CANCEL_DISALLOWED; - m_runningURL->SetErrorMessage(PL_strdup (XP_GetString(status))); + m_runningURL->SetErrorMessage(nsCRT::strdup(XP_GetString(status))); m_nextState = NEWS_ERROR; /* even though it worked */ ClearFlag(NNTP_PAUSE_FOR_READ); goto FAIL; diff --git a/mailnews/news/tests/nsNNTPHostStub.cpp b/mailnews/news/tests/nsNNTPHostStub.cpp index 36d1ebe97f6f..4fcfbb8cd413 100644 --- a/mailnews/news/tests/nsNNTPHostStub.cpp +++ b/mailnews/news/tests/nsNNTPHostStub.cpp @@ -29,7 +29,7 @@ #include "nsINNTPNewsgroup.h" #include "nsMsgGroupRecord.h" -#include "nsMsgPtrArray.h" +#include "nsIMsgFolder.h" #include "nsNNTPNewsgroupList.h" #include "nsNNTPNewsgroup.h"