implement pref for strict msg threading, mail_strict_threading, sr=mscott 277190

This commit is contained in:
bienvenu%nventure.com 2005-01-12 15:41:56 +00:00
parent 4e786cabeb
commit c2366c8ad6
7 changed files with 59 additions and 54 deletions

View File

@ -110,8 +110,8 @@ interface nsIMsgDBService : nsISupports
{
// want to remove this method from nsIMsgDatabase...
// if a db is opened on the folder, the listener will automatically be added
nsIMsgDatabase openFolderDB(in nsIMsgFolder aFolder, in boolean aCreate, in boolean aUpgrading);
nsIMsgDatabase openMailDBFromFileSpec(in nsIFileSpec aFolderName, in boolean aCreate, in boolean aUpgrading);
nsIMsgDatabase openFolderDB(in nsIMsgFolder aFolder, in boolean aCreate, in boolean aLeaveInvalidDB);
nsIMsgDatabase openMailDBFromFileSpec(in nsIFileSpec aFolderName, in boolean aCreate, in boolean aLeaveInvalidDB);
void registerPendingListener(in nsIMsgFolder aFolder, in nsIDBChangeListener aListener);
void unregisterPendingListener(in nsIDBChangeListener aListener);
};
@ -119,7 +119,7 @@ interface nsIMsgDBService : nsISupports
[scriptable, uuid(f667dcb8-5aae-4e71-8559-2a48d7e508cd)]
interface nsIMsgDatabase : nsIDBChangeAnnouncer {
void Open(in nsIFileSpec aFolderName, in boolean aCreate, in boolean aUpgrading);
void Open(in nsIFileSpec aFolderName, in boolean aCreate, in boolean aLeaveInvalidDB);
void forceFolderDBClosed(in nsIMsgFolder aFolder);
void Close(in boolean aForceCommit);

View File

@ -93,8 +93,7 @@ protected:
virtual void SetReparse(PRBool reparse);
protected:
void GetGlobalPrefs();
virtual PRBool ThreadBySubjectWithoutRe() ;
virtual void GetGlobalPrefs();
PRBool m_reparse;
nsFileSpec *m_folderSpec;

View File

@ -171,8 +171,9 @@ public:
friend class nsMsgDBThreadEnumerator;
protected:
// prefs stuff - in future, we might want to cache the prefs interface
nsresult GetBoolPref(const char *prefName, PRBool *result);
nsresult GetIntPref(const char *prefName, PRInt32 *result);
nsresult GetBoolPref(const char *prefName, PRBool *result);
nsresult GetIntPref(const char *prefName, PRInt32 *result);
virtual void GetGlobalPrefs();
// retrieval methods
nsIMsgThread * GetThreadForReference(nsCString &msgID, nsIMsgDBHdr **pMsgHdr);
nsIMsgThread * GetThreadForSubject(nsCString &subject);
@ -182,6 +183,7 @@ protected:
// threading interfaces
virtual nsresult CreateNewThread(nsMsgKey key, const char *subject, nsMsgThread **newThread);
virtual PRBool ThreadBySubjectWithoutRe();
virtual PRBool UseStrictThreading();
virtual nsresult ThreadNewHdr(nsMsgHdr* hdr, PRBool &newThread);
virtual nsresult AddNewThread(nsMsgHdr *msgHdr);
virtual nsresult AddToThread(nsMsgHdr *newHdr, nsIMsgThread *thread, nsIMsgDBHdr *pMsgHdr, PRBool threadInThread);

View File

@ -80,8 +80,6 @@ public:
NS_IMETHOD GetDefaultSortType(nsMsgViewSortTypeValue *aDefaultSortType);
protected:
virtual PRBool ThreadBySubjectWithoutRe() ;
// this is owned by the nsNewsFolder, which lives longer than the db.
nsMsgKeySet *m_readSet;
};

View File

@ -77,14 +77,13 @@ NS_IMETHODIMP nsMailDatabase::SetFolderStream(nsIOFileStream *aFileStream)
}
static PRBool gGotGlobalPrefs = PR_FALSE;
static PRBool gThreadWithoutRe = PR_TRUE;
static PRInt32 gTimeStampLeeway;
void nsMailDatabase::GetGlobalPrefs()
{
if (!gGotGlobalPrefs)
{
GetBoolPref("mail.thread_without_re", &gThreadWithoutRe);
nsMsgDatabase::GetGlobalPrefs();
GetIntPref("mail.db_timestamp_leeway", &gTimeStampLeeway);
gGotGlobalPrefs = PR_TRUE;
}
@ -121,7 +120,7 @@ nsresult nsMailDatabase::GetAllOfflineOpsTable()
// cache m_folderStream to make updating mozilla status flags fast
NS_IMETHODIMP nsMailDatabase::StartBatch()
{
if (!m_folderStream) //only if we create a stream, set m_ownFolderStream to true.
if (!m_folderStream && m_folder) //only if we create a stream, set m_ownFolderStream to true.
{
PRBool isLocked;
m_folder->GetLocked(&isLocked);
@ -754,14 +753,6 @@ void nsMailDatabase::SetReparse(PRBool reparse)
}
// should we thread messages with common subjects that don't start with Re: together?
// I imagine we might have separate preferences for mail and news, so this is a virtual method.
PRBool nsMailDatabase::ThreadBySubjectWithoutRe()
{
GetGlobalPrefs();
return gThreadWithoutRe;
}
class nsMsgOfflineOpEnumerator : public nsISimpleEnumerator {
public:
NS_DECL_ISUPPORTS

View File

@ -223,6 +223,20 @@ NS_IMETHODIMP nsMsgDBService::UnregisterPendingListener(nsIDBChangeListener *aLi
return NS_ERROR_FAILURE;
}
static PRBool gGotGlobalPrefs = PR_FALSE;
static PRBool gThreadWithoutRe = PR_TRUE;
static PRBool gStrictThreading = PR_FALSE;
void nsMsgDatabase::GetGlobalPrefs()
{
if (!gGotGlobalPrefs)
{
GetBoolPref("mail.thread_without_re", &gThreadWithoutRe);
GetBoolPref("mail.strict_threading", &gStrictThreading);
gGotGlobalPrefs = PR_TRUE;
}
}
// we never need to call this because we check the use cache first,
// and any hdr in this cache will be in the use cache.
nsresult nsMsgDatabase::GetHdrFromCache(nsMsgKey key, nsIMsgDBHdr* *result)
@ -1692,7 +1706,7 @@ NS_IMETHODIMP nsMsgDatabase::GetMsgHdrForKey(nsMsgKey key, nsIMsgDBHdr **pmsgHdr
mdb_bool hasOid;
mdbOid rowObjectId;
#ifdef DEBUG_bienvenu
#ifdef DEBUG_bienvenu1
NS_ASSERTION(m_folder, "folder should be set");
#endif
@ -3491,6 +3505,21 @@ NS_IMETHODIMP nsMsgDatabase::GetSummaryValid(PRBool *aResult)
// protected routines
// should we thread messages with common subjects that don't start with Re: together?
// I imagine we might have separate preferences for mail and news, so this is a virtual method.
PRBool nsMsgDatabase::ThreadBySubjectWithoutRe()
{
GetGlobalPrefs();
return gThreadWithoutRe;
}
PRBool nsMsgDatabase::UseStrictThreading()
{
GetGlobalPrefs();
return gStrictThreading;
}
nsresult nsMsgDatabase::CreateNewThread(nsMsgKey threadId, const char *subject, nsMsgThread **pnewThread)
{
nsresult err = NS_OK;
@ -3649,7 +3678,7 @@ nsresult nsMsgDatabase::ThreadNewHdr(nsMsgHdr* newHdr, PRBool &newThread)
newHdr->GetRawFlags(&newHdrFlags);
newHdr->GetNumReferences(&numReferences);
#define SUBJ_THREADING 1// try reference threading first
// try reference threading first
for (PRInt32 i = numReferences - 1; i >= 0; i--)
{
nsCAutoString reference;
@ -3671,26 +3700,28 @@ nsresult nsMsgDatabase::ThreadNewHdr(nsMsgHdr* newHdr, PRBool &newThread)
break;
}
}
#ifdef SUBJ_THREADING
// try subject threading if we couldn't find a reference and the subject starts with Re:
nsXPIDLCString subject;
newHdr->GetSubject(getter_Copies(subject));
if ((ThreadBySubjectWithoutRe() || (newHdrFlags & MSG_FLAG_HAS_RE)) && (!thread))
// if user hasn't said "only thread by ref headers", thread by subject
if (!UseStrictThreading())
{
nsCAutoString cSubject(subject);
thread = getter_AddRefs(GetThreadForSubject(cSubject));
if(thread)
// try subject threading if we couldn't find a reference and the subject starts with Re:
nsXPIDLCString subject;
newHdr->GetSubject(getter_Copies(subject));
if ((ThreadBySubjectWithoutRe() || (newHdrFlags & MSG_FLAG_HAS_RE)) && (!thread))
{
thread->GetThreadKey(&threadId);
newHdr->SetThreadId(threadId);
//TRACE("threading based on subject %s\n", (const char *) msgHdr->m_subject);
// if we move this and do subject threading after, ref threading,
// don't thread within children, since we know it won't work. But for now, pass TRUE.
result = AddToThread(newHdr, thread, nsnull, PR_TRUE);
nsCAutoString cSubject(subject);
thread = getter_AddRefs(GetThreadForSubject(cSubject));
if(thread)
{
thread->GetThreadKey(&threadId);
newHdr->SetThreadId(threadId);
//TRACE("threading based on subject %s\n", (const char *) msgHdr->m_subject);
// if we move this and do subject threading after, ref threading,
// don't thread within children, since we know it won't work. But for now, pass TRUE.
result = AddToThread(newHdr, thread, nsnull, PR_TRUE);
}
}
}
#endif // SUBJ_THREADING
if (!thread)
{
@ -3895,14 +3926,6 @@ nsresult nsMsgDatabase::AddNewThread(nsMsgHdr *msgHdr)
return err;
}
// should we thread messages with common subjects that don't start with Re: together?
// I imagine we might have separate preferences for mail and news, so this is a virtual method.
PRBool nsMsgDatabase::ThreadBySubjectWithoutRe()
{
return PR_TRUE;
}
nsresult nsMsgDatabase::GetBoolPref(const char *prefName, PRBool *result)
{
PRBool prefValue = PR_FALSE;

View File

@ -113,7 +113,6 @@ NS_IMETHODIMP nsNewsDatabase::IsRead(nsMsgKey key, PRBool *pRead)
NS_ASSERTION(pRead, "null out param in IsRead");
if (!pRead) return NS_ERROR_NULL_POINTER;
NS_ASSERTION(m_readSet, "set is null!");
if (!m_readSet) return NS_ERROR_FAILURE;
*pRead = m_readSet->IsMember(key);
@ -178,13 +177,6 @@ nsresult nsNewsDatabase::ExpireRange(nsMsgKey startRange, nsMsgKey endRange)
return NS_ERROR_NOT_IMPLEMENTED;
}
// should we thread messages with common subjects that don't start with Re: together?
// I imagine we might have separate preferences for mail and news, so this is a virtual method.
PRBool
nsNewsDatabase::ThreadBySubjectWithoutRe()
{
return PR_TRUE;
}
NS_IMETHODIMP nsNewsDatabase::GetReadSet(nsMsgKeySet **pSet)
{