/usr/include/thunderbird-11.0.1/nsMsgDatabase.h is in thunderbird-dev 11.0.1+build1-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _nsMsgDatabase_H_
#define _nsMsgDatabase_H_
#include "nsIMsgDatabase.h"
#include "nsMsgHdr.h"
#include "nsStringGlue.h"
#include "nsAutoPtr.h"
#include "nsIDBChangeListener.h"
#include "nsIDBChangeAnnouncer.h"
#include "nsMsgMessageFlags.h"
#include "nsIMsgFolder.h"
#include "nsIMutableArray.h"
#include "nsDBFolderInfo.h"
#include "nsICollation.h"
#include "nsIMsgSearchSession.h"
#include "nsIMimeConverter.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
#include "pldhash.h"
#include "nsTArray.h"
#include "nsTObserverArray.h"
class ListContext;
class nsMsgKeySet;
class nsMsgThread;
class nsIMsgThread;
class nsIDBFolderInfo;
class nsIMsgHeaderParser;
const PRInt32 kMsgDBVersion = 1;
class nsMsgDBService : public nsIMsgDBService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGDBSERVICE
nsMsgDBService();
~nsMsgDBService();
protected:
void HookupPendingListeners(nsIMsgDatabase *db, nsIMsgFolder *folder);
void FinishDBOpen(nsIMsgFolder *aFolder, nsMsgDatabase *aMsgDB);
nsCOMArray <nsIMsgFolder> m_foldersPendingListeners;
nsCOMArray <nsIDBChangeListener> m_pendingListeners;
};
class nsMsgDBEnumerator : public nsISimpleEnumerator {
public:
NS_DECL_ISUPPORTS
// nsISimpleEnumerator methods:
NS_DECL_NSISIMPLEENUMERATOR
// nsMsgDBEnumerator methods:
typedef nsresult (*nsMsgDBEnumeratorFilter)(nsIMsgDBHdr* hdr, void* closure);
nsMsgDBEnumerator(nsMsgDatabase* db, nsIMdbTable *table,
nsMsgDBEnumeratorFilter filter, void* closure,
bool iterateForwards = true);
virtual ~nsMsgDBEnumerator();
void Clear();
nsresult GetRowCursor();
virtual nsresult PrefetchNext();
nsRefPtr<nsMsgDatabase> mDB;
nsCOMPtr<nsIMdbTableRowCursor> mRowCursor;
mdb_pos mRowPos;
nsCOMPtr<nsIMsgDBHdr> mResultHdr;
bool mDone;
bool mNextPrefetched;
bool mIterateForwards;
nsMsgDBEnumeratorFilter mFilter;
nsCOMPtr <nsIMdbTable> mTable;
void* mClosure;
// This is used when the caller wants to limit how many headers the
// enumerator looks at in any given time slice.
mdb_pos mStopPos;
};
class nsMsgFilteredDBEnumerator : public nsMsgDBEnumerator
{
public:
nsMsgFilteredDBEnumerator(nsMsgDatabase* db, nsIMdbTable *table,
bool reverse, nsIArray *searchTerms);
virtual ~nsMsgFilteredDBEnumerator();
nsresult InitSearchSession(nsIArray *searchTerms, nsIMsgFolder *folder);
protected:
virtual nsresult PrefetchNext();
nsCOMPtr <nsIMsgSearchSession> m_searchSession;
};
class nsMsgDatabase : public nsIMsgDatabase
{
public:
friend class nsMsgDBService;
friend class nsMsgPropertyEnumerator; // accesses m_mdbEnv and m_mdbStore
NS_DECL_ISUPPORTS
NS_DECL_NSIDBCHANGEANNOUNCER
NS_DECL_NSIMSGDATABASE
virtual nsresult IsHeaderRead(nsIMsgDBHdr *hdr, bool *pRead);
virtual nsresult MarkHdrReadInDB(nsIMsgDBHdr *msgHdr, bool bRead,
nsIDBChangeListener *instigator);
nsresult OpenInternal(nsILocalFile *aFolderName, bool aCreate,
bool aLeaveInvalidDB, bool sync);
nsresult CheckForErrors(nsresult err, nsILocalFile *summaryFile);
virtual nsresult OpenMDB(const char *dbName, bool create, bool sync);
virtual nsresult CloseMDB(bool commit);
virtual nsresult CreateMsgHdr(nsIMdbRow* hdrRow, nsMsgKey key, nsIMsgDBHdr **result);
virtual nsresult GetThreadForMsgKey(nsMsgKey msgKey, nsIMsgThread **result);
virtual nsresult EnumerateMessagesWithFlag(nsISimpleEnumerator* *result, PRUint32 *pFlag);
nsresult GetSearchResultsTable(const char *searchFolderUri, bool createIfMissing, nsIMdbTable **table);
// this might just be for debugging - we'll see.
nsresult ListAllThreads(nsTArray<nsMsgKey> *threadIds);
//////////////////////////////////////////////////////////////////////////////
// nsMsgDatabase methods:
nsMsgDatabase();
virtual ~nsMsgDatabase();
void GetMDBFactory(nsIMdbFactory ** aMdbFactory);
nsIMdbEnv *GetEnv() {return m_mdbEnv;}
nsIMdbStore *GetStore() {return m_mdbStore;}
virtual PRUint32 GetCurVersion();
nsIMsgHeaderParser *GetHeaderParser();
nsresult GetCollationKeyGenerator();
nsIMimeConverter * GetMimeConverter();
nsresult GetTableCreateIfMissing(const char *scope, const char *kind, nsIMdbTable **table,
mdb_token &scopeToken, mdb_token &kindToken);
static nsMsgDatabase* FindInCache(nsILocalFile *dbName);
static nsIMsgDatabase* FindInCache(nsIMsgFolder *folder);
//helper function to fill in nsStrings from hdr row cell contents.
nsresult RowCellColumnTonsString(nsIMdbRow *row, mdb_token columnToken, nsAString &resultStr);
nsresult RowCellColumnToUInt32(nsIMdbRow *row, mdb_token columnToken, PRUint32 *uint32Result, PRUint32 defaultValue = 0);
nsresult RowCellColumnToUInt32(nsIMdbRow *row, mdb_token columnToken, PRUint32 &uint32Result, PRUint32 defaultValue = 0);
nsresult RowCellColumnToUInt64(nsIMdbRow *row, mdb_token columnToken, PRUint64 *uint64Result, PRUint64 defaultValue = 0);
nsresult RowCellColumnToMime2DecodedString(nsIMdbRow *row, mdb_token columnToken, nsAString &resultStr);
nsresult RowCellColumnToCollationKey(nsIMdbRow *row, mdb_token columnToken, PRUint8 **result, PRUint32 *len);
nsresult RowCellColumnToConstCharPtr(nsIMdbRow *row, mdb_token columnToken, const char **ptr);
nsresult RowCellColumnToAddressCollationKey(nsIMdbRow *row, mdb_token colToken, PRUint8 **result, PRUint32 *len);
// these methods take the property name as a string, not a token.
// they should be used when the properties aren't accessed a lot
nsresult GetProperty(nsIMdbRow *row, const char *propertyName, char **result);
nsresult SetProperty(nsIMdbRow *row, const char *propertyName, const char *propertyVal);
nsresult GetPropertyAsNSString(nsIMdbRow *row, const char *propertyName, nsAString &result);
nsresult SetPropertyFromNSString(nsIMdbRow *row, const char *propertyName, const nsAString &propertyVal);
nsresult GetUint32Property(nsIMdbRow *row, const char *propertyName, PRUint32 *result, PRUint32 defaultValue = 0);
nsresult SetUint32Property(nsIMdbRow *row, const char *propertyName, PRUint32 propertyVal);
nsresult SetUint64Property(nsIMdbRow *row, const char *propertyName, PRUint64 propertyVal);
nsresult GetBooleanProperty(nsIMdbRow *row, const char *propertyName,
bool *result, bool defaultValue = false);
nsresult SetBooleanProperty(nsIMdbRow *row, const char *propertyName,
bool propertyVal);
// helper function for once we have the token.
nsresult SetNSStringPropertyWithToken(nsIMdbRow *row, mdb_token aProperty, const nsAString &propertyStr);
// helper functions to put values in cells for the passed-in row
nsresult UInt32ToRowCellColumn(nsIMdbRow *row, mdb_token columnToken, PRUint32 value);
nsresult CharPtrToRowCellColumn(nsIMdbRow *row, mdb_token columnToken, const char *charPtr);
nsresult RowCellColumnToCharPtr(nsIMdbRow *row, mdb_token columnToken, char **result);
nsresult UInt64ToRowCellColumn(nsIMdbRow *row, mdb_token columnToken, PRUint64 value);
// helper functions to copy an nsString to a yarn, int32 to yarn, and vice versa.
static struct mdbYarn *nsStringToYarn(struct mdbYarn *yarn, const nsAString &str);
static struct mdbYarn *UInt32ToYarn(struct mdbYarn *yarn, PRUint32 i);
static struct mdbYarn *UInt64ToYarn(struct mdbYarn *yarn, PRUint64 i);
static void YarnTonsString(struct mdbYarn *yarn, nsAString &str);
static void YarnTonsCString(struct mdbYarn *yarn, nsACString &str);
static void YarnToUInt32(struct mdbYarn *yarn, PRUint32 *i);
static void YarnToUInt64(struct mdbYarn *yarn, PRUint64 *i);
static void CleanupCache();
static void DumpCache();
#ifdef DEBUG
virtual nsresult DumpContents();
nsresult DumpThread(nsMsgKey threadId);
nsresult DumpMsgChildren(nsIMsgDBHdr *msgHdr);
#endif
friend class nsMsgHdr; // use this to get access to cached tokens for hdr fields
friend class nsMsgThread; // use this to get access to cached tokens for hdr fields
friend class nsMsgDBEnumerator;
friend class nsMsgDBThreadEnumerator;
protected:
// prefs stuff - in future, we might want to cache the prefs interface
nsresult GetBoolPref(const char *prefName, bool *result);
nsresult GetIntPref(const char *prefName, PRInt32 *result);
virtual void GetGlobalPrefs();
// retrieval methods
nsIMsgThread * GetThreadForReference(nsCString &msgID, nsIMsgDBHdr **pMsgHdr);
nsIMsgThread * GetThreadForSubject(nsCString &subject);
nsIMsgThread * GetThreadForMessageId(nsCString &msgId);
nsIMsgThread * GetThreadForThreadId(nsMsgKey threadId);
nsMsgHdr * GetMsgHdrForReference(nsCString &reference);
nsIMsgDBHdr * GetMsgHdrForSubject(nsCString &subject);
// threading interfaces
virtual nsresult CreateNewThread(nsMsgKey key, const char *subject, nsMsgThread **newThread);
virtual bool ThreadBySubjectWithoutRe();
virtual bool UseStrictThreading();
virtual bool UseCorrectThreading();
virtual nsresult ThreadNewHdr(nsMsgHdr* hdr, bool &newThread);
virtual nsresult AddNewThread(nsMsgHdr *msgHdr);
virtual nsresult AddToThread(nsMsgHdr *newHdr, nsIMsgThread *thread, nsIMsgDBHdr *pMsgHdr, bool threadInThread);
static nsTArray<nsMsgDatabase*>* m_dbCache;
static nsTArray<nsMsgDatabase*>* GetDBCache();
static void AddToCache(nsMsgDatabase* pMessageDB)
{
#ifdef DEBUG_David_Bienvenu
// NS_ASSERTION(GetDBCache()->Length() < 50, "50 or more open db's");
#endif
GetDBCache()->AppendElement(pMessageDB);
}
static void RemoveFromCache(nsMsgDatabase* pMessageDB);
bool MatchDbName(nsILocalFile *dbName); // returns TRUE if they match
// Flag handling routines
virtual nsresult SetKeyFlag(nsMsgKey key, bool set, PRUint32 flag,
nsIDBChangeListener *instigator = NULL);
virtual nsresult SetMsgHdrFlag(nsIMsgDBHdr *msgHdr, bool set, PRUint32 flag,
nsIDBChangeListener *instigator);
virtual bool SetHdrFlag(nsIMsgDBHdr *, bool bSet, nsMsgMessageFlagType flag);
virtual bool SetHdrReadFlag(nsIMsgDBHdr *, bool pRead);
virtual PRUint32 GetStatusFlags(nsIMsgDBHdr *msgHdr, PRUint32 origFlags);
// helper function which doesn't involve thread object
virtual nsresult RemoveHeaderFromDB(nsMsgHdr *msgHdr);
virtual nsresult RemoveHeaderFromThread(nsMsgHdr *msgHdr);
virtual nsresult AdjustExpungedBytesOnDelete(nsIMsgDBHdr *msgHdr);
nsCOMPtr <nsICollation> m_collationKeyGenerator;
nsCOMPtr <nsIMimeConverter> m_mimeConverter;
nsCOMPtr <nsIMsgRetentionSettings> m_retentionSettings;
nsCOMPtr <nsIMsgDownloadSettings> m_downloadSettings;
nsresult PurgeMessagesOlderThan(PRUint32 daysToKeepHdrs,
bool keepUnreadMessagesOnly,
bool applyToFlaggedMessages,
nsIMutableArray *hdrsToDelete);
nsresult PurgeExcessMessages(PRUint32 numHeadersToKeep,
bool keepUnreadMessagesOnly,
bool applyToFlaggedMessages,
nsIMutableArray *hdrsToDelete);
// mdb bookkeeping stuff
virtual nsresult InitExistingDB();
virtual nsresult InitNewDB();
virtual nsresult InitMDBInfo();
nsCOMPtr <nsIMsgFolder> m_folder;
nsDBFolderInfo *m_dbFolderInfo;
nsMsgKey m_nextPseudoMsgKey;
nsIMdbEnv *m_mdbEnv; // to be used in all the db calls.
nsIMdbStore *m_mdbStore;
nsIMdbTable *m_mdbAllMsgHeadersTable;
nsIMdbTable *m_mdbAllThreadsTable;
// Used for asynchronous db opens. If non-null, we're still opening
// the underlying mork database. If null, the db has been completely opened.
nsCOMPtr<nsIMdbThumb> m_thumb;
// used to remember the args to Open for async open.
bool m_create;
bool m_leaveInvalidDB;
nsCString m_dbName;
nsTArray<nsMsgKey> m_newSet; // new messages since last open.
bool m_mdbTokensInitialized;
nsTObserverArray<nsCOMPtr<nsIDBChangeListener> > m_ChangeListeners;
mdb_token m_hdrRowScopeToken;
mdb_token m_threadRowScopeToken;
mdb_token m_hdrTableKindToken;
mdb_token m_threadTableKindToken;
mdb_token m_allThreadsTableKindToken;
mdb_token m_subjectColumnToken;
mdb_token m_senderColumnToken;
mdb_token m_messageIdColumnToken;
mdb_token m_referencesColumnToken;
mdb_token m_recipientsColumnToken;
mdb_token m_dateColumnToken;
mdb_token m_messageSizeColumnToken;
mdb_token m_flagsColumnToken;
mdb_token m_priorityColumnToken;
mdb_token m_labelColumnToken;
mdb_token m_statusOffsetColumnToken;
mdb_token m_numLinesColumnToken;
mdb_token m_ccListColumnToken;
mdb_token m_bccListColumnToken;
mdb_token m_threadFlagsColumnToken;
mdb_token m_threadIdColumnToken;
mdb_token m_threadChildrenColumnToken;
mdb_token m_threadUnreadChildrenColumnToken;
mdb_token m_messageThreadIdColumnToken;
mdb_token m_threadSubjectColumnToken;
mdb_token m_messageCharSetColumnToken;
mdb_token m_threadParentColumnToken;
mdb_token m_threadRootKeyColumnToken;
mdb_token m_threadNewestMsgDateColumnToken;
mdb_token m_offlineMsgOffsetColumnToken;
mdb_token m_offlineMessageSizeColumnToken;
nsIMsgHeaderParser *m_HeaderParser;
// header caching stuff - MRU headers, keeps them around in memory
nsresult AddHdrToCache(nsIMsgDBHdr *hdr, nsMsgKey key);
nsresult ClearHdrCache(bool reInit);
nsresult RemoveHdrFromCache(nsIMsgDBHdr *hdr, nsMsgKey key);
// all headers currently instantiated, doesn't hold refs
// these get added when msg hdrs get constructed, and removed when they get destroyed.
nsresult GetHdrFromUseCache(nsMsgKey key, nsIMsgDBHdr* *result);
nsresult AddHdrToUseCache(nsIMsgDBHdr *hdr, nsMsgKey key);
nsresult ClearUseHdrCache();
nsresult RemoveHdrFromUseCache(nsIMsgDBHdr *hdr, nsMsgKey key);
// not-reference holding array of threads we've handed out.
// If a db goes away, it will clean up the outstanding threads.
// We use an nsTArray because we don't expect to ever have very many
// of these, rarely more than 5.
nsTArray<nsMsgThread *> m_threads;
// Clear outstanding thread objects
void ClearThreads();
nsMsgThread *FindExistingThread(nsMsgKey threadId);
mdb_pos FindInsertIndexInSortedTable(nsIMdbTable *table, mdb_id idToInsert);
void ClearCachedObjects(bool dbGoingAway);
void ClearEnumerators();
// all instantiated headers, but doesn't hold refs.
PLDHashTable *m_headersInUse;
static PLDHashNumber HashKey(PLDHashTable* aTable, const void* aKey);
static bool MatchEntry(PLDHashTable* aTable, const PLDHashEntryHdr* aEntry, const void* aKey);
static void MoveEntry(PLDHashTable* aTable, const PLDHashEntryHdr* aFrom, PLDHashEntryHdr* aTo);
static void ClearEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry);
static PLDHashOperator HeaderEnumerator (PLDHashTable *table, PLDHashEntryHdr *hdr,
PRUint32 number, void *arg);
static PLDHashOperator ClearHeaderEnumerator (PLDHashTable *table, PLDHashEntryHdr *hdr,
PRUint32 number, void *arg);
static PLDHashTableOps gMsgDBHashTableOps;
struct MsgHdrHashElement {
PLDHashEntryHdr mHeader;
nsMsgKey mKey;
nsIMsgDBHdr *mHdr;
};
PLDHashTable *m_cachedHeaders;
bool m_bCacheHeaders;
nsMsgKey m_cachedThreadId;
nsCOMPtr <nsIMsgThread> m_cachedThread;
nsCOMPtr<nsIMdbFactory> mMdbFactory;
// Message reference hash table
static PLDHashTableOps gRefHashTableOps;
struct RefHashElement : public PLDHashEntryHdr {
const char *mRef; // Hash entry key, must come first
nsMsgKey mThreadId;
PRUint32 mCount;
};
PLDHashTable *m_msgReferences;
nsresult GetRefFromHash(nsCString &reference, nsMsgKey *threadId);
nsresult AddRefToHash(nsCString &reference, nsMsgKey threadId);
nsresult AddMsgRefsToHash(nsIMsgDBHdr *msgHdr);
nsresult RemoveRefFromHash(nsCString &reference);
nsresult RemoveMsgRefsFromHash(nsIMsgDBHdr *msgHdr);
nsresult InitRefHash();
// not-reference holding array of enumerators we've handed out.
// If a db goes away, it will clean up the outstanding enumerators.
nsTArray<nsMsgDBEnumerator *> m_enumerators;
private:
PRUint32 m_cacheSize;
};
class nsMsgRetentionSettings : public nsIMsgRetentionSettings
{
public:
nsMsgRetentionSettings();
virtual ~nsMsgRetentionSettings();
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGRETENTIONSETTINGS
protected:
nsMsgRetainByPreference m_retainByPreference;
PRUint32 m_daysToKeepHdrs;
PRUint32 m_numHeadersToKeep;
bool m_keepUnreadMessagesOnly;
bool m_useServerDefaults;
bool m_cleanupBodiesByDays;
PRUint32 m_daysToKeepBodies;
bool m_applyToFlaggedMessages;
};
class nsMsgDownloadSettings : public nsIMsgDownloadSettings
{
public:
nsMsgDownloadSettings();
virtual ~nsMsgDownloadSettings();
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGDOWNLOADSETTINGS
protected:
bool m_useServerDefaults;
bool m_downloadUnreadOnly;
bool m_downloadByDate;
PRInt32 m_ageLimitOfMsgsToDownload;
};
#endif
|