This commit is contained in:
warren%netscape.com 1999-02-09 03:45:02 +00:00
Родитель 44ec99403e
Коммит c633a424fc
8 изменённых файлов: 617 добавлений и 195 удалений

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

@ -39,6 +39,7 @@ CPPSRCS = \
nsMsgRFC822Parser.cpp \
nsMsgFolder.cpp \
nsMsgLocalMailFolder.cpp \
nsMsgImapMailFolder.cpp \
nsNewsSet.cpp \
nsMsg.cpp \
nsLocalFolderSummarySpec.cpp \

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

@ -32,6 +32,7 @@ CPPSRCS= \
nsMsgKeyArray.cpp \
nsMsgFolder.cpp \
nsMsgLocalMailFolder.cpp \
nsMsgImapMailFolder.cpp \
nsMsgGroupRecord.cpp \
nsMsgRDFFolder.cpp \
nsLocalFolderSummarySpec.cpp \
@ -46,6 +47,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsMsgFolder.obj \
.\$(OBJDIR)\nsLocalFolderSummarySpec.obj \
.\$(OBJDIR)\nsMsgLocalMailFolder.obj \
.\$(OBJDIR)\nsMsgImapMailFolder.obj \
.\$(OBJDIR)\nsMsgGroupRecord.obj \
.\$(OBJDIR)\nsMsgRDFFolder.obj \
.\$(OBJDIR)\nsNewsSet.obj \

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

@ -100,16 +100,6 @@ nsMsgFolder::QueryInterface(REFNSIID iid, void** result)
return nsRDFResource::QueryInterface(iid, result);
}
NS_IMETHODIMP nsMsgFolder::GetType(FolderType *type)
{
if(!type)
return NS_ERROR_NULL_POINTER;
*type = FOLDER_UNKNOWN;
return NS_OK;
}
NS_IMETHODIMP nsMsgFolder::BuildFolderURL(char **url)
{
if(*url)
@ -123,7 +113,7 @@ NS_IMETHODIMP nsMsgFolder::BuildFolderURL(char **url)
#ifdef HAVE_DB
// this class doesn't have a url
NS_IMETHODIMP nsMsgFolder::BuildUrl (nsMsgDatabase *db, MessageKey key, char ** url)
NS_IMETHODIMP nsMsgFolder::BuildUrl(nsMsgDatabase *db, MessageKey key, char ** url)
{
if(*url)
{
@ -144,7 +134,7 @@ NS_IMETHODIMP nsMsgFolder::SetMaster(MSG_Master *master)
#endif
#ifdef DOES_FOLDEROPERATIONS
NS_IMETHODIMP nsMsgFolder::StartAsyncCopyMessagesInto (MSG_FolderInfo *dstFolder,
NS_IMETHODIMP nsMsgFolder::StartAsyncCopyMessagesInto(MSG_FolderInfo *dstFolder,
MSG_Pane* sourcePane,
nsMsgDatabase *sourceDB,
nsMsgKeyArray *srcArray,
@ -708,67 +698,6 @@ NS_IMETHODIMP nsMsgFolder::ContainsChildNamed (const char *name, PRBool* contain
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsMsgFolder::FindChildNamed (const char *name, nsIMsgFolder ** aChild)
{
if(!aChild)
return NS_ERROR_NULL_POINTER;
// will return nsnull if we can't find it
*aChild = nsnull;
nsIMsgFolder *folder = nsnull;
PRUint32 count = mSubFolders->Count();
for (PRUint32 i = 0; i < count; i++)
{
nsISupports *supports;
supports = mSubFolders->ElementAt(i);
if(folder)
NS_RELEASE(folder);
if(NS_SUCCEEDED(supports->QueryInterface(kISupportsIID, (void**)&folder)))
{
FolderType type;
char *folderName;
GetType(&type);
folder->GetName(&folderName);
if (type == FOLDER_IMAPMAIL ||
type == FOLDER_IMAPSERVERCONTAINER)
{
// IMAP INBOX is case insensitive
if (type == FOLDER_IMAPSERVERCONTAINER &&
!PL_strcasecmp(folderName, "INBOX"))
{
NS_RELEASE(supports);
continue;
}
// For IMAP, folder names are case sensitive
if (!PL_strcmp(folderName, name))
{
*aChild = folder;
return NS_OK;
}
}
else
{
// case-insensitive compare is probably LCD across OS filesystems
if (!PL_strcasecmp(folderName, name))
{
*aChild = folder;
return NS_OK;
}
}
}
NS_RELEASE(supports);
}
return NS_OK;
}
NS_IMETHODIMP nsMsgFolder::FindParentOf (const nsIMsgFolder * aFolder, nsIMsgFolder ** aParent)
{
if(!aParent)
@ -844,18 +773,40 @@ NS_IMETHODIMP nsMsgFolder::IsParentOf (const nsIMsgFolder *child, PRBool deep, P
NS_IMETHODIMP nsMsgFolder::GenerateUniqueSubfolderName(const char *prefix, const nsIMsgFolder *otherFolder,
char **name)
char **name)
{
if(!name)
return NS_ERROR_NULL_POINTER;
//we don't support this.
/* 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 nsMsgFolder::GetDepth(PRUint32 *depth)
{
if(!depth)

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

@ -42,14 +42,12 @@ public:
/* this macro defines QueryInterface, AddRef and Release for this class */
NS_DECL_ISUPPORTS
NS_IMETHOD GetType(FolderType *type);
// Gets the URL that represents the given message. Returns a newly
// created string that must be free'd using XP_FREE().
// If the db is NULL, then returns a URL that represents the entire
// folder as a whole.
#ifdef HAVE_DB
NS_IMETHOD BuildUrl (nsMsgDatabase *db, MessageKey key, char ** url);
NS_IMETHOD BuildUrl(nsMsgDatabase *db, MessageKey key, char ** url);
#endif
#ifdef HAVE_MASTER
@ -57,7 +55,7 @@ public:
#endif
#ifdef DOES_FOLDEROPERATIONS
NS_IMETHOD StartAsyncCopyMessagesInto (MSG_FolderInfo *dstFolder,
NS_IMETHOD StartAsyncCopyMessagesInto(MSG_FolderInfo *dstFolder,
MSG_Pane* sourcePane,
nsMsgDatabase *sourceDB,
nsMsgKeyArray *srcArray,
@ -68,7 +66,7 @@ public:
MessageKey nextKey = MSG_MESSAGEKEYNONE);
NS_IMETHOD BeginCopyingMessages (MSG_FolderInfo *dstFolder,
NS_IMETHOD BeginCopyingMessages(MSG_FolderInfo *dstFolder,
nsMsgDatabase *sourceDB,
nsMsgKeyArray *srcArray,
MSG_UrlQueue *urlQueue,
@ -76,7 +74,7 @@ public:
MessageCopyInfo *copyInfo);
NS_IMETHOD FinishCopyingMessages (MWContext *context,
NS_IMETHOD FinishCopyingMessages(MWContext *context,
MSG_FolderInfo * srcFolder,
MSG_FolderInfo *dstFolder,
nsMsgDatabase *sourceDB,
@ -85,11 +83,11 @@ public:
msg_move_state *state);
NS_IMETHOD CleanupCopyMessagesInto (MessageCopyInfo **info);
NS_IMETHOD CleanupCopyMessagesInto(MessageCopyInfo **info);
NS_IMETHOD SaveMessages(nsMsgKeyArray *, const char *fileName,
MSG_Pane *pane, nsMsgDatabase *msgDB,
int (*doneCB)(void *, int status) = NULL, void *state = NULL,
int(*doneCB)(void *, int status) = NULL, void *state = NULL,
PRBool addMozillaStatus = TRUE);
#endif
@ -106,14 +104,14 @@ public:
NS_IMETHOD GetNumSubFolders(PRUint32 *numSubFolders);
NS_IMETHOD GetNumSubFoldersToDisplay(PRUint32 *numSubFolders);
NS_IMETHOD GetSubFolder(PRUint32 which, nsIMsgFolder **aFolder);
NS_IMETHOD GetSubFolders (nsISupportsArray ** subFolders);
NS_IMETHOD GetSubFolders(nsISupportsArray ** subFolders);
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);
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);
@ -132,21 +130,21 @@ public:
NS_IMETHOD GetDeleteIsMoveToTrash(PRBool *aIsDeleteIsMoveToTrash);
NS_IMETHOD GetShowDeletedMessages(PRBool *aIsShowDeletedMessages);
NS_IMETHOD OnCloseFolder ();
NS_IMETHOD Delete ();
NS_IMETHOD OnCloseFolder();
NS_IMETHOD Delete();
NS_IMETHOD PropagateDelete (nsIMsgFolder **folder, PRBool deleteStorage);
NS_IMETHOD RecursiveDelete (PRBool deleteStorage); // called by PropagateDelete
NS_IMETHOD PropagateDelete(nsIMsgFolder **folder, PRBool deleteStorage);
NS_IMETHOD RecursiveDelete(PRBool deleteStorage); // called by PropagateDelete
NS_IMETHOD CreateSubfolder (const char *leafNameFromuser, nsIMsgFolder** outFolder, PRUint32* outPos);
NS_IMETHOD CreateSubfolder(const char *leafNameFromuser, nsIMsgFolder** outFolder, PRUint32* outPos);
NS_IMETHOD Rename (const char *name);
NS_IMETHOD Adopt (const nsIMsgFolder *srcFolder, PRUint32*);
NS_IMETHOD Rename(const char *name);
NS_IMETHOD Adopt(const nsIMsgFolder *srcFolder, PRUint32*);
NS_IMETHOD ContainsChildNamed (const char *name, PRBool *containsChild);
NS_IMETHOD FindChildNamed (const char *name, nsIMsgFolder ** aChild);
NS_IMETHOD FindParentOf (const nsIMsgFolder * aFolder, nsIMsgFolder ** aParent);
NS_IMETHOD IsParentOf (const nsIMsgFolder *, PRBool deep, PRBool *isParent);
NS_IMETHOD ContainsChildNamed(const char *name, PRBool *containsChild);
NS_IMETHOD FindChildNamed(const char *name, nsIMsgFolder ** aChild) = 0;
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,
char **name);
@ -192,12 +190,12 @@ public:
NS_IMETHOD GetLastMessageLoaded();
#endif
NS_IMETHOD SetFlag (PRUint32 which);
NS_IMETHOD ClearFlag (PRUint32 which);
NS_IMETHOD SetFlag(PRUint32 which);
NS_IMETHOD ClearFlag(PRUint32 which);
NS_IMETHOD GetFlag(PRUint32 flag, PRBool *_retval);
NS_IMETHOD ToggleFlag (PRUint32 which);
NS_IMETHOD OnFlagChange (PRUint32 which);
NS_IMETHOD ToggleFlag(PRUint32 which);
NS_IMETHOD OnFlagChange(PRUint32 which);
NS_IMETHOD GetFlags(PRUint32 *flags);
#ifdef HAVE_PANE
@ -215,13 +213,13 @@ public:
NS_IMETHOD GetExpungedBytesCount(PRUint32 *count);
NS_IMETHOD GetDeletable (PRBool *deletable);
NS_IMETHOD GetCanCreateChildren (PRBool *canCreateChildren);
NS_IMETHOD GetCanBeRenamed (PRBool *canBeRenamed);
NS_IMETHOD GetDeletable(PRBool *deletable);
NS_IMETHOD GetCanCreateChildren(PRBool *canCreateChildren);
NS_IMETHOD GetCanBeRenamed(PRBool *canBeRenamed);
NS_IMETHOD GetRequiresCleanup(PRBool *requiredCleanup);
NS_IMETHOD ClearRequiresCleanup() ;
#ifdef HAVE_PANE
virtual PRBool CanBeInFolderPane ();
virtual PRBool CanBeInFolderPane();
#endif
NS_IMETHOD GetKnowsSearchNntpExtension(PRBool *knowsExtension);
@ -230,10 +228,10 @@ public:
NS_IMETHOD DisplayRecipients(PRBool *displayRecipients);
#ifdef HAVE_SEMAPHORE
MsgERR AcquireSemaphore (void *semHolder);
void ReleaseSemaphore (void *semHolder);
PRBool TestSemaphore (void *semHolder);
PRBool IsLocked () { return m_semaphoreHolder != NULL; }
MsgERR AcquireSemaphore(void *semHolder);
void ReleaseSemaphore(void *semHolder);
PRBool TestSemaphore(void *semHolder);
PRBool IsLocked() { return m_semaphoreHolder != NULL; }
#endif
#ifdef HAVE_PANE
@ -245,13 +243,13 @@ public:
#endif
#ifdef HAVE_CACHE
virtual MsgERR WriteToCache (XP_File);
virtual MsgERR ReadFromCache (char *);
virtual PRBool IsCachable ();
void SkipCacheTokens (char **ppBuf, int numTokens);
virtual MsgERR WriteToCache(XP_File);
virtual MsgERR ReadFromCache(char *);
virtual PRBool IsCachable();
void SkipCacheTokens(char **ppBuf, int numTokens);
#endif
NS_IMETHOD GetRelativePathName (char **pathName);
NS_IMETHOD GetRelativePathName(char **pathName);
NS_IMETHOD GetSizeOnDisk(PRUint32 *size);
@ -274,7 +272,7 @@ public:
protected:
char* mName;
PRUint32 mFlags;
PRUint32 mNumUnreadMessages; /* count of unread messages (-1 means
PRUint32 mNumUnreadMessages; /* count of unread messages (-1 means
unknown; -2 means unknown but we already
tried to find out.) */
PRUint32 mNumTotalMessages; /* count of existing messages. */

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

@ -0,0 +1,389 @@
/* -*- 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 "msgCore.h" // precompiled header...
#include "nsMsgImapMailFolder.h"
#include "nsMsgFolderFlags.h"
#include "prprf.h"
static NS_DEFINE_IID(kIMsgImapMailFolderIID, NS_IMSGIMAPMAILFOLDER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsMsgImapMailFolder::nsMsgImapMailFolder(const char* uri)
:nsMsgFolder(uri)
{
mHaveReadNameFromDB = PR_FALSE;
mPathName = nsnull;
}
nsMsgImapMailFolder::~nsMsgImapMailFolder()
{
}
NS_IMPL_ADDREF(nsMsgImapMailFolder)
NS_IMPL_RELEASE(nsMsgImapMailFolder)
NS_IMETHODIMP
nsMsgImapMailFolder::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIMsgImapMailFolderIID) ||
iid.Equals(kISupportsIID))
{
*result = NS_STATIC_CAST(nsIMsgImapMailFolder*, this);
AddRef();
return NS_OK;
}
return nsMsgFolder::QueryInterface(iid, result);
}
NS_IMETHODIMP nsMsgImapMailFolder::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 nsMsgImapMailFolder::CreateSubfolder(const char *leafNameFromUser, nsIMsgFolder **outFolder, PRUint32 *outPos)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgImapMailFolder::RemoveSubFolder(const nsIMsgFolder *which)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgImapMailFolder::Delete()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgImapMailFolder::Rename (const char *newName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgImapMailFolder::Adopt(const nsIMsgFolder *srcFolder, PRUint32 *outPos)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMsgImapMailFolder::FindChildNamed(const char *name, nsIMsgFolder ** aChild)
{
NS_ASSERTION(aChild, "NULL child");
// will return nsnull if we can't find it
*aChild = nsnull;
nsIMsgFolder *folder = nsnull;
PRUint32 count = mSubFolders->Count();
for (PRUint32 i = 0; i < count; i++)
{
nsISupports *supports;
supports = mSubFolders->ElementAt(i);
if (folder)
NS_RELEASE(folder);
if (NS_SUCCEEDED(supports->QueryInterface(kISupportsIID, (void**)&folder)))
{
char *folderName;
folder->GetName(&folderName);
// IMAP INBOX is case insensitive
if (/* XXX type == FOLDER_IMAPSERVERCONTAINER && */
!PL_strcasecmp(folderName, "INBOX"))
{
NS_RELEASE(supports);
continue;
}
// For IMAP, folder names are case sensitive
if (!PL_strcmp(folderName, name))
{
*aChild = folder;
return NS_OK;
}
}
NS_RELEASE(supports);
}
return NS_OK;
}
NS_IMETHODIMP nsMsgImapMailFolder::GetName(char** name)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgImapMailFolder::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 nsMsgImapMailFolder::GetExpungedBytesCount(PRUint32 *count)
{
if(!count)
return NS_ERROR_NULL_POINTER;
*count = mExpungedBytes;
return NS_OK;
}
NS_IMETHODIMP nsMsgImapMailFolder::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 nsMsgImapMailFolder::GetCanCreateChildren (PRBool *canCreateChildren)
{
if(!canCreateChildren)
return NS_ERROR_NULL_POINTER;
*canCreateChildren = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP nsMsgImapMailFolder::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 nsMsgImapMailFolder::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 nsMsgImapMailFolder::GetRelativePathName (char **pathName)
{
if(!pathName)
return NS_ERROR_NULL_POINTER;
*pathName = mPathName;
return NS_OK;
}
NS_IMETHODIMP nsMsgImapMailFolder::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 nsMsgImapMailFolder::GetUserName(char** userName)
{
#ifdef HAVE_PORT
return NET_GetPopUsername();
#endif
return NS_OK;
}
NS_IMETHODIMP nsMsgImapMailFolder::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 nsMsgImapMailFolder::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 nsMsgImapMailFolder::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 nsMsgImapMailFolder::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->GetImapMailFolderTree()->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, &offlineInbox, 1) && offlineInbox)
savedPassword = offlineInbox->GetRememberedPassword();
}
return savedPassword;
#endif
return NS_OK;
}
NS_IMETHODIMP nsMsgImapMailFolder::GetPathName(char * *aPathName)
{
if(!aPathName)
return NS_ERROR_NULL_POINTER;
if(mPathName)
*aPathName = PL_strdup(mPathName);
else
*aPathName = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsMsgImapMailFolder::SetPathName(char * aPathName)
{
if(mPathName)
PR_FREEIF(mPathName);
if(aPathName)
mPathName = PL_strdup(aPathName);
else
mPathName = nsnull;
return NS_OK;
}

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

@ -0,0 +1,101 @@
/* -*- 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 nsMsgImapMailFolder_h__
#define nsMsgImapMailFolder_h__
#include "nsMsgFolder.h" /* include the interface we are going to support */
class nsMsgImapMailFolder : public nsMsgFolder, public nsIMsgImapMailFolder
{
public:
nsMsgImapMailFolder(const char* uri);
~nsMsgImapMailFolder();
NS_DECL_ISUPPORTS
#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);
NS_IMETHOD FindChildNamed(const char *name, nsIMsgFolder ** aChild);
// this override pulls the value from the db
NS_IMETHOD GetName(char** name); // Name of this folder(as presented to user).
NS_IMETHOD BuildFolderURL(char **url);
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 // nsMsgImapMailFolder_h__

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

@ -56,16 +56,6 @@ nsMsgLocalMailFolder::QueryInterface(REFNSIID iid, void** result)
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:";
@ -195,35 +185,33 @@ NS_IMETHODIMP nsMsgLocalMailFolder::RemoveSubFolder (const nsIMsgFolder *which)
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);
}
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 (0 == status) {
// 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)
{
if (status) {
XP_StatStruct fileStat;
if (0 == XP_Stat(m_pathName, &fileStat, xpMailFolder))
if (0 == XP_Stat(m_pathName, &fileStat, xpMailFolder))
status = 0;
}
}
if (0 != status)
status = MK_UNABLE_TO_DELETE_FILE;
return status;
if (0 != status)
status = MK_UNABLE_TO_DELETE_FILE;
return status;
#endif
return NS_OK;
}
@ -359,6 +347,41 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Adopt(const nsIMsgFolder *srcFolder, PRUint3
return NS_OK;
}
NS_IMETHODIMP
nsMsgLocalMailFolder::FindChildNamed(const char *name, nsIMsgFolder ** aChild)
{
NS_ASSERTION(aChild, "NULL child");
// will return nsnull if we can't find it
*aChild = nsnull;
nsIMsgFolder *folder = nsnull;
PRUint32 count = mSubFolders->Count();
for (PRUint32 i = 0; i < count; i++)
{
nsISupports *supports;
supports = mSubFolders->ElementAt(i);
if(folder)
NS_RELEASE(folder);
if(NS_SUCCEEDED(supports->QueryInterface(kISupportsIID, (void**)&folder)))
{
char *folderName;
folder->GetName(&folderName);
// case-insensitive compare is probably LCD across OS filesystems
if (!PL_strcasecmp(folderName, name))
{
*aChild = folder;
return NS_OK;
}
}
NS_RELEASE(supports);
}
return NS_OK;
}
NS_IMETHODIMP nsMsgLocalMailFolder::GetName(char** name)
{
if(!name)
@ -385,14 +408,9 @@ NS_IMETHODIMP nsMsgLocalMailFolder::GetName(char** name)
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);
// Depth == 1 means we are on the mail server level
// override the name here to say "Local Mail"
*prettyName = PL_strdup("Local Mail");
}
else
return nsMsgFolder::GetPrettyName(prettyName);
@ -400,42 +418,6 @@ NS_IMETHODIMP nsMsgLocalMailFolder::GetPrettyName(char ** 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

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

@ -38,8 +38,6 @@ public:
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,
@ -65,14 +63,14 @@ public:
NS_IMETHOD Rename (const char *newName);
NS_IMETHOD Adopt(const nsIMsgFolder *srcFolder, PRUint32 *outPos);
// this override pulls the value from the db
NS_IMETHOD FindChildNamed(const char *name, nsIMsgFolder ** aChild);
// 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);