diff options
author | Matt A. Tobin <email@mattatobin.com> | 2019-11-11 00:00:30 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2019-11-11 00:00:30 -0500 |
commit | 31fea2bc2b99c1c5008a41c02c78f921d3fa1c62 (patch) | |
tree | 87c6436ad39590985f175cba9f3b7c0d64c3bbad /mailnews/db/msgdb | |
parent | 3d9db9cb381f7e4461708d844cc958cb65a04e56 (diff) | |
download | UXP-31fea2bc2b99c1c5008a41c02c78f921d3fa1c62.tar UXP-31fea2bc2b99c1c5008a41c02c78f921d3fa1c62.tar.gz UXP-31fea2bc2b99c1c5008a41c02c78f921d3fa1c62.tar.lz UXP-31fea2bc2b99c1c5008a41c02c78f921d3fa1c62.tar.xz UXP-31fea2bc2b99c1c5008a41c02c78f921d3fa1c62.zip |
Bug 1508054 - reduce exposed API of nsMsgHdr.
Tag #1273
Diffstat (limited to 'mailnews/db/msgdb')
-rw-r--r-- | mailnews/db/msgdb/public/nsMsgHdr.h | 44 | ||||
-rw-r--r-- | mailnews/db/msgdb/src/nsMsgDatabase.cpp | 48 | ||||
-rw-r--r-- | mailnews/db/msgdb/src/nsMsgHdr.cpp | 2 |
3 files changed, 53 insertions, 41 deletions
diff --git a/mailnews/db/msgdb/public/nsMsgHdr.h b/mailnews/db/msgdb/public/nsMsgHdr.h index 6d23e7b49..23e2d083f 100644 --- a/mailnews/db/msgdb/public/nsMsgHdr.h +++ b/mailnews/db/msgdb/public/nsMsgHdr.h @@ -20,27 +20,18 @@ class nsIMsgThread; class nsMsgHdr : public nsIMsgDBHdr { public: NS_DECL_NSIMSGDBHDR - friend class nsMsgDatabase; - friend class nsMsgPropertyEnumerator; // accesses m_mdb + friend class nsMsgDatabase; + friend class nsImapMailDatabase; + friend class nsMsgPropertyEnumerator; + friend class nsMsgThread; + //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// // nsMsgHdr methods: nsMsgHdr(nsMsgDatabase *db, nsIMdbRow *dbRow); - virtual nsresult GetRawFlags(uint32_t *result); - void Init(); - virtual nsresult InitCachedValues(); - virtual nsresult InitFlags(); - void ClearCachedValues() {m_initedValues = 0;} - NS_DECL_ISUPPORTS - nsIMdbRow *GetMDBRow() {return m_mdbRow;} - bool IsParentOf(nsIMsgDBHdr *possibleChild); - bool IsAncestorOf(nsIMsgDBHdr *possibleChild); - bool IsAncestorKilled(uint32_t ancestorsToCheck); - void ReparentInThread(nsIMsgThread *thread); - size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOfFun) const { return m_references.ShallowSizeOfExcludingThis(aMallocSizeOfFun); @@ -51,7 +42,26 @@ public: } protected: - virtual ~nsMsgHdr(); + nsIMdbRow* GetMDBRow() { return m_mdbRow; } + void ReleaseMDBRow() { NS_IF_RELEASE(m_mdbRow); } + nsMsgDatabase* GetMdb() { return m_mdb; } + void ClearCachedValues() { m_initedValues = 0; } + + virtual nsresult GetRawFlags(uint32_t *result); + + bool IsParentOf(nsIMsgDBHdr *possibleChild); + bool IsAncestorOf(nsIMsgDBHdr *possibleChild); + +private: + virtual ~nsMsgHdr(); + + void Init(); + virtual nsresult InitFlags(); + virtual nsresult InitCachedValues(); + + bool IsAncestorKilled(uint32_t ancestorsToCheck); + void ReparentInThread(nsIMsgThread *thread); + nsresult SetStringColumn(const char *str, mdb_token token); nsresult SetUInt32Column(uint32_t value, mdb_token token); nsresult GetUInt32Column(mdb_token token, uint32_t *pvalue, uint32_t defaultValue = 0); @@ -64,11 +74,11 @@ protected: bool acceptNonDelimitedReferences); nsMsgKey m_threadId; - nsMsgKey m_messageKey; //news: article number, mail mbox offset, imap uid... + nsMsgKey m_messageKey; // news: article number, local mail: key, imap: uid... nsMsgKey m_threadParent; // message this is a reply to, in thread. PRTime m_date; uint32_t m_messageSize; // lines for news articles, bytes for mail messages - uint32_t m_statusOffset; // offset in a local mail message of the mozilla status hdr + uint32_t m_statusOffset; // offset in a local mail message of the x-mozilla-status header uint32_t m_flags; // avoid parsing references every time we want one nsTArray<nsCString> m_references; diff --git a/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mailnews/db/msgdb/src/nsMsgDatabase.cpp index 0b422b31d..31da7bc5e 100644 --- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -2029,14 +2029,14 @@ NS_IMETHODIMP nsMsgDatabase::DeleteHeader(nsIMsgDBHdr *msg, nsIDBChangeListener NS_IMETHODIMP nsMsgDatabase::UndoDelete(nsIMsgDBHdr *aMsgHdr) { - if (aMsgHdr) - { - nsMsgHdr* msgHdr = static_cast<nsMsgHdr*>(aMsgHdr); // closed system, so this is ok - // force deleted flag, so SetHdrFlag won't bail out because deleted flag isn't set - msgHdr->m_flags |= nsMsgMessageFlags::Expunged; - SetHdrFlag(msgHdr, false, nsMsgMessageFlags::Expunged); // clear deleted flag in db - } - return NS_OK; + if (aMsgHdr) + { + // Force deleted flag, so SetHdrFlag won't bail out because deleted flag isn't set. + uint32_t result; + aMsgHdr->OrFlags(nsMsgMessageFlags::Expunged, &result); + SetHdrFlag(aMsgHdr, false, nsMsgMessageFlags::Expunged); // Clear deleted flag in db. + } + return NS_OK; } nsresult nsMsgDatabase::RemoveHeaderFromThread(nsMsgHdr *msgHdr) @@ -2080,7 +2080,7 @@ nsresult nsMsgDatabase::RemoveHeaderFromDB(nsMsgHdr *msgHdr) ret = m_mdbAllMsgHeadersTable->CutRow(GetEnv(), row); row->CutAllColumns(GetEnv()); } - msgHdr->m_initedValues = 0; // invalidate cached values. + msgHdr->ClearCachedValues(); return ret; } @@ -3497,8 +3497,10 @@ NS_IMETHODIMP nsMsgDatabase::AddNewHdrToDB(nsIMsgDBHdr *newHdr, bool notify) NS_ENSURE_ARG_POINTER(newHdr); nsMsgHdr* hdr = static_cast<nsMsgHdr*>(newHdr); // closed system, cast ok bool newThread; - bool hasKey; - ContainsKey(hdr->m_messageKey, &hasKey); + bool hasKey = false; + nsMsgKey msgKey = nsMsgKey_None; + (void)hdr->GetMessageKey(&msgKey); + (void)ContainsKey(msgKey, &hasKey); if (hasKey) { NS_ERROR("adding hdr that already exists"); @@ -3573,7 +3575,7 @@ NS_IMETHODIMP nsMsgDatabase::CopyHdrFromExistingHdr(nsMsgKey key, nsIMsgDBHdr *e { // we may have gotten the header from a cache - calling SetRow // basically invalidates any cached values, so invalidate them. - destMsgHdr->m_initedValues = 0; + destMsgHdr->ClearCachedValues(); if(addHdrToDB) err = AddNewHdrToDB(destMsgHdr, true); if (NS_SUCCEEDED(err) && newHdr) @@ -4831,7 +4833,8 @@ nsresult nsMsgDatabase::AddNewThread(nsMsgHdr *msgHdr) nsMsgThread *threadHdr = nullptr; nsCString subject; - nsMsgKey threadKey = msgHdr->m_messageKey; + nsMsgKey threadKey; + msgHdr->GetMessageKey(&threadKey); // can't have a thread with key 1 since that's the table id of the all msg hdr table, // so give it kTableKeyForThreadOne (0xfffffffe). if (threadKey == kAllMsgHdrsTableKey) @@ -5060,9 +5063,8 @@ nsresult nsMsgDatabase::DumpContents() keys->GetLength(&numKeys); for (i = 0; i < numKeys; i++) { key = keys->m_keys[i]; - nsIMsgDBHdr *msg = NULL; - rv = GetMsgHdrForKey(key, &msg); - nsMsgHdr* msgHdr = static_cast<nsMsgHdr*>(msg); // closed system, cast ok + nsCOMPtr<nsIMsgDBHdr> msgHdr; + rv = GetMsgHdrForKey(key, getter_AddRefs(msgHdr)); if (NS_SUCCEEDED(rv)) { nsCString author; @@ -5072,7 +5074,6 @@ nsresult nsMsgDatabase::DumpContents() msgHdr->GetAuthor(getter_Copies(author)); msgHdr->GetSubject(getter_Copies(subject)); printf("hdr key = %u, author = %s subject = %s\n", key, author.get(), subject.get()); - NS_RELEASE(msgHdr); } } nsTArray<nsMsgKey> threads; @@ -5867,24 +5868,25 @@ nsMsgDatabase::UpdateHdrInCache(const char *aSearchFolderUri, nsIMsgDBHdr *aHdr, nsresult err = GetSearchResultsTable(aSearchFolderUri, true, getter_AddRefs(table)); NS_ENSURE_SUCCESS(err, err); nsMsgKey key; - aHdr->GetMessageKey(&key); + err = aHdr->GetMessageKey(&key); nsMsgHdr* msgHdr = static_cast<nsMsgHdr*>(aHdr); // closed system, so this is ok - if (NS_SUCCEEDED(err) && m_mdbStore && msgHdr->m_mdbRow) + nsIMdbRow* hdrRow = msgHdr->GetMDBRow(); + if (NS_SUCCEEDED(err) && m_mdbStore && hdrRow) { if (!aAdd) { - table->CutRow(m_mdbEnv, msgHdr->m_mdbRow); + table->CutRow(m_mdbEnv, hdrRow); } else { mdbOid rowId; - msgHdr->m_mdbRow->GetOid(m_mdbEnv, &rowId); + hdrRow->GetOid(m_mdbEnv, &rowId); mdb_pos insertPos = FindInsertIndexInSortedTable(table, rowId.mOid_Id); uint32_t rowCount; table->GetCount(m_mdbEnv, &rowCount); - table->AddRow(m_mdbEnv, msgHdr->m_mdbRow); + table->AddRow(m_mdbEnv, hdrRow); mdb_pos newPos; - table->MoveRow(m_mdbEnv, msgHdr->m_mdbRow, rowCount, insertPos, &newPos); + table->MoveRow(m_mdbEnv, hdrRow, rowCount, insertPos, &newPos); } } diff --git a/mailnews/db/msgdb/src/nsMsgHdr.cpp b/mailnews/db/msgdb/src/nsMsgHdr.cpp index fd172024e..7c5cf5709 100644 --- a/mailnews/db/msgdb/src/nsMsgHdr.cpp +++ b/mailnews/db/msgdb/src/nsMsgHdr.cpp @@ -1023,7 +1023,7 @@ nsMsgPropertyEnumerator::nsMsgPropertyEnumerator(nsMsgHdr* aHdr) if (aHdr && (mdbRow = aHdr->GetMDBRow()) && (m_hdr = aHdr) && - (mdb = aHdr->m_mdb) && + (mdb = aHdr->GetMdb()) && (m_mdbEnv = mdb->m_mdbEnv) && (m_mdbStore = mdb->m_mdbStore)) { |