From 9e0e2f3adb59ec5857de16fb77d61d7601bc344d Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Sun, 28 Feb 1999 22:00:50 +0000 Subject: [PATCH] add ability to import msf files --- db/mdb/public/mdb.h | 3 +- mailnews/db/mdb/public/mdb.h | 3 +- mailnews/db/msgdb/public/nsIMessage.h | 2 + mailnews/db/msgdb/public/nsMsgDatabase.h | 2 + mailnews/db/msgdb/public/nsMsgHdr.h | 2 + mailnews/db/msgdb/src/mdbstubs.cpp | 341 +++++++++++++++-------- mailnews/db/msgdb/src/nsDBFolderInfo.cpp | 13 +- mailnews/db/msgdb/src/nsMailDatabase.cpp | 4 +- mailnews/db/msgdb/src/nsMsgDatabase.cpp | 37 ++- mailnews/db/msgdb/src/nsMsgHdr.cpp | 73 ++++- 10 files changed, 357 insertions(+), 123 deletions(-) diff --git a/db/mdb/public/mdb.h b/db/mdb/public/mdb.h index 08301cac0b4..d21c30d9672 100644 --- a/db/mdb/public/mdb.h +++ b/db/mdb/public/mdb.h @@ -1044,6 +1044,7 @@ public: nsIMdbStore() {} mdb_err WriteAll(nsIMdbEnv* ev, nsIMdbThumb** acqThumb); + mdb_err ReadAll(nsIMdbEnv* ev); mdb_err ReadTokenList(); mdb_err WriteTokenList(); mdb_err WriteTableList(); @@ -1857,7 +1858,7 @@ class nsIMdbCell : public nsIMdbBlob { // text attribute in row with column scop class mdbCellImpl : public nsIMdbCell { public: - mdbCellImpl() {} + mdbCellImpl() ; mdbCellImpl(const mdbCellImpl &anotherCell); mdbCellImpl& operator=(const mdbCellImpl& other); virtual mdb_err AliasYarn(nsIMdbEnv* ev, mdbYarn* outYarn) ; diff --git a/mailnews/db/mdb/public/mdb.h b/mailnews/db/mdb/public/mdb.h index 08301cac0b4..d21c30d9672 100644 --- a/mailnews/db/mdb/public/mdb.h +++ b/mailnews/db/mdb/public/mdb.h @@ -1044,6 +1044,7 @@ public: nsIMdbStore() {} mdb_err WriteAll(nsIMdbEnv* ev, nsIMdbThumb** acqThumb); + mdb_err ReadAll(nsIMdbEnv* ev); mdb_err ReadTokenList(); mdb_err WriteTokenList(); mdb_err WriteTableList(); @@ -1857,7 +1858,7 @@ class nsIMdbCell : public nsIMdbBlob { // text attribute in row with column scop class mdbCellImpl : public nsIMdbCell { public: - mdbCellImpl() {} + mdbCellImpl() ; mdbCellImpl(const mdbCellImpl &anotherCell); mdbCellImpl& operator=(const mdbCellImpl& other); virtual mdb_err AliasYarn(nsIMdbEnv* ev, mdbYarn* outYarn) ; diff --git a/mailnews/db/msgdb/public/nsIMessage.h b/mailnews/db/msgdb/public/nsIMessage.h index d70770bd8be..2d393b12186 100644 --- a/mailnews/db/msgdb/public/nsIMessage.h +++ b/mailnews/db/msgdb/public/nsIMessage.h @@ -46,6 +46,8 @@ public: NS_IMETHOD SetReferences(const char *references) = 0; NS_IMETHOD SetCCList(const char *ccList) = 0; NS_IMETHOD SetRecipients(const char *recipients, PRBool recipientsIsNewsgroup) = 0; + NS_IMETHOD SetRecipientsArray(const char *names, const char *addresses, PRUint32 numAddresses) = 0; + NS_IMETHOD SetCCListArray(const char *names, const char *addresses, PRUint32 numAddresses) = 0; NS_IMETHOD SetAuthor(const char *author) = 0; NS_IMETHOD SetSubject(const char *subject) = 0; NS_IMETHOD SetStatusOffset(PRUint32 statusOffset) = 0; diff --git a/mailnews/db/msgdb/public/nsMsgDatabase.h b/mailnews/db/msgdb/public/nsMsgDatabase.h index 203e303ce4d..17ba749a310 100644 --- a/mailnews/db/msgdb/public/nsMsgDatabase.h +++ b/mailnews/db/msgdb/public/nsMsgDatabase.h @@ -227,6 +227,8 @@ public: #ifdef DEBUG static int GetNumInCache(void) {return(GetDBCache()->Count());} static void DumpCache(); + virtual void DumpContents(); + #endif protected: nsDBFolderInfo *m_dbFolderInfo; diff --git a/mailnews/db/msgdb/public/nsMsgHdr.h b/mailnews/db/msgdb/public/nsMsgHdr.h index dd44c19b9ac..3244b71977c 100644 --- a/mailnews/db/msgdb/public/nsMsgHdr.h +++ b/mailnews/db/msgdb/public/nsMsgHdr.h @@ -49,6 +49,8 @@ public: NS_IMETHOD SetReferences(const char *references); NS_IMETHOD SetCCList(const char *ccList); NS_IMETHOD SetRecipients(const char *recipients, PRBool recipientsIsNewsgroup); + NS_IMETHOD SetRecipientsArray(const char *names, const char *addresses, PRUint32 numAddresses); + NS_IMETHOD SetCCListArray(const char *names, const char *addresses, PRUint32 numAddresses); NS_IMETHOD SetAuthor(const char *author); NS_IMETHOD SetSubject(const char *subject); NS_IMETHOD SetStatusOffset(PRUint32 statusOffset); diff --git a/mailnews/db/msgdb/src/mdbstubs.cpp b/mailnews/db/msgdb/src/mdbstubs.cpp index 795a95a334f..12fa6a140f5 100644 --- a/mailnews/db/msgdb/src/mdbstubs.cpp +++ b/mailnews/db/msgdb/src/mdbstubs.cpp @@ -8,27 +8,32 @@ nsIMdbFactory *NS_NewIMdbFactory() return new nsIMdbFactory; } - mdb_err - nsIMdbFactory::ThumbToOpenStore( // redeem completed thumb from OpenFileStore() +mdb_err nsIMdbFactory::ThumbToOpenStore( // redeem completed thumb from OpenFileStore() nsIMdbEnv* ev, // context nsIMdbThumb* ioThumb, // thumb from OpenFileStore() with done status nsIMdbStore** acqStore) // acquire new db store object { + mdb_err ret = 0; nsIMdbStore *resultStore; resultStore = new nsIMdbStore; resultStore->m_fileStream = ioThumb->m_fileStream; resultStore->m_backingFile = ioThumb->m_backingFile; *acqStore = resultStore; - return 0; + // this means its an existing store that we have to load. + if (resultStore->m_fileStream) + { + ret = resultStore->ReadAll(ev); + } + return ret; } - mdb_err nsIMdbFactory::CreateNewFileStore( // create a new db with minimal content - nsIMdbEnv* ev, // context - nsIMdbHeap* ioHeap, // can be nil to cause ev's heap attribute to be used - const char* inFilePath, // name of file which should not yet exist - const mdbOpenPolicy* inOpenPolicy, // runtime policies for using db - nsIMdbStore** acqStore) +mdb_err nsIMdbFactory::CreateNewFileStore( // create a new db with minimal content + nsIMdbEnv* ev, // context + nsIMdbHeap* ioHeap, // can be nil to cause ev's heap attribute to be used + const char* inFilePath, // name of file which should not yet exist + const mdbOpenPolicy* inOpenPolicy, // runtime policies for using db + nsIMdbStore** acqStore) { printf("new file store for %s\n", inFilePath); nsIMdbStore *resultStore; @@ -40,42 +45,41 @@ nsIMdbFactory *NS_NewIMdbFactory() return 0; } - mdb_err nsIMdbStore::SmallCommit( // save minor changes if convenient and uncostly - nsIMdbEnv* ev) - { - return 0; - } - mdb_err nsIMdbStore::LargeCommit( // save important changes if at all possible - nsIMdbEnv* ev, // context - nsIMdbThumb** acqThumb) - { - WriteAll(ev, acqThumb); - return 0; - } +mdb_err nsIMdbStore::SmallCommit( // save minor changes if convenient and uncostly + nsIMdbEnv* ev) +{ + return 0; +} +mdb_err nsIMdbStore::LargeCommit( // save important changes if at all possible +nsIMdbEnv* ev, // context +nsIMdbThumb** acqThumb) +{ + WriteAll(ev, acqThumb); + return 0; +} - mdb_err nsIMdbStore::SessionCommit( // save all changes if large commits delayed - nsIMdbEnv* ev, // context - nsIMdbThumb** acqThumb) - { - WriteAll(ev, acqThumb); - return 0; - } +mdb_err nsIMdbStore::SessionCommit( // save all changes if large commits delayed +nsIMdbEnv* ev, // context +nsIMdbThumb** acqThumb) +{ + WriteAll(ev, acqThumb); + return 0; +} - mdb_err - nsIMdbStore::CompressCommit( // commit and make db physically smaller if possible - nsIMdbEnv* ev, // context - nsIMdbThumb** acqThumb) - { - WriteAll(ev, acqThumb); - return 0; - } +mdb_err +nsIMdbStore::CompressCommit( // commit and make db physically smaller if possible +nsIMdbEnv* ev, // context +nsIMdbThumb** acqThumb) +{ + WriteAll(ev, acqThumb); + return 0; +} mdb_err nsIMdbStore::WriteAll(nsIMdbEnv* ev, // context nsIMdbThumb** acqThumb) { -// nsVoidArray m_tables; -// nsStringArray m_tokenStrings; + *acqThumb = new nsIMdbThumb; m_fileStream = new nsIOFileStream(nsFileSpec(m_backingFile)); WriteTokenList(); @@ -85,85 +89,125 @@ nsIMdbThumb** acqThumb) return 0; } -const char *kStartTokenList = "token list"LINEBREAK; -const char *kEndTokenList = "end token list"LINEBREAK; +mdb_err + nsIMdbStore::ReadAll(nsIMdbEnv* ev) +{ + ReadTokenList(); + ReadTableList(); + return 0; +} - mdb_err nsIMdbStore::WriteTokenList() +const char *kStartTokenList = "token list"; +const char *kEndTokenList = "end token list"; + +mdb_err nsIMdbStore::WriteTokenList() +{ + *m_fileStream << kStartTokenList; + *m_fileStream << LINEBREAK; + PRInt32 i; + + for (i = 0; i < m_tokenStrings.Count(); i++) { - *m_fileStream << kStartTokenList; - PRInt32 i; + nsString outputNSString; + char *outputString; + m_tokenStrings.StringAt(i, outputNSString); + outputString = outputNSString.ToNewCString(); - for (i = 0; i < m_tokenStrings.Count(); i++) - { - nsString outputNSString; - char *outputString; - m_tokenStrings.StringAt(i, outputNSString); - outputString = outputNSString.ToNewCString(); - - *m_fileStream << outputString; - delete [] outputString; - *m_fileStream << LINEBREAK; - } - *m_fileStream << kEndTokenList; - return 0; + *m_fileStream << outputString; + delete [] outputString; + *m_fileStream << LINEBREAK; } + *m_fileStream << kEndTokenList; + *m_fileStream << LINEBREAK; + return 0; +} - mdb_err nsIMdbStore::ReadTokenList() +// read in the token strings. +mdb_err nsIMdbStore::ReadTokenList() +{ + char readlineBuffer[100]; + + m_tokenStrings.Clear(); + + m_fileStream->readline(readlineBuffer, sizeof(readlineBuffer)); + if (strcmp(readlineBuffer, kStartTokenList)) + return -1; + + while (TRUE) { - char readlineBuffer[100]; + if (m_fileStream->eof()) + break; - m_tokenStrings.Clear(); + m_fileStream->readline(readlineBuffer, sizeof(readlineBuffer)); - m_fileStream->readline(readlineBuffer, sizeof(readlineBuffer)); - if (strcmp(readlineBuffer, kStartTokenList)) - return -1; + if (!strcmp(readlineBuffer, kEndTokenList)) + break; - while (TRUE) - { - if (m_fileStream->eof()) - break; - - m_fileStream->readline(readlineBuffer, sizeof(readlineBuffer)); - - if (!strcmp(readlineBuffer, kEndTokenList)) - break; - - nsString unicodeStr(readlineBuffer); - m_tokenStrings.AppendString(unicodeStr); - } - return 0; + nsString unicodeStr(readlineBuffer); + m_tokenStrings.AppendString(unicodeStr); } + return 0; +} -const char *kStartTableList = "table list"LINEBREAK; -const char *kEndTableList = "end table list"LINEBREAK; +const char *kStartTableList = "table list"; +const char *kEndTableList = "end table list"; - mdb_err nsIMdbStore::WriteTableList() - { - *m_fileStream << kStartTableList; - PRInt32 i; +mdb_err nsIMdbStore::WriteTableList() +{ + *m_fileStream << kStartTableList; + *m_fileStream << LINEBREAK; - for (i = 0; i < m_tables.Count(); i++) - { - nsIMdbTable *table = (nsIMdbTable *) m_tables.ElementAt(i); - table->Write(); - } - *m_fileStream << kEndTableList; - return 0; - } + PRInt32 i; + *m_fileStream << (long) m_tables.Count(); + *m_fileStream << LINEBREAK; + for (i = 0; i < m_tables.Count(); i++) + { + nsIMdbTable *table = (nsIMdbTable *) m_tables.ElementAt(i); + table->Write(); + } + *m_fileStream << kEndTableList; + *m_fileStream << LINEBREAK; + return 0; +} - mdb_err nsIMdbStore::NewTable( // make one new table of specific type +mdb_err nsIMdbStore::ReadTableList() +{ + char readlineBuffer[100]; + + m_tables.Clear(); + + m_fileStream->readline(readlineBuffer, sizeof(readlineBuffer)); + if (strcmp(readlineBuffer, kStartTableList)) + return -1; + + m_fileStream->readline(readlineBuffer, sizeof(readlineBuffer)); + PRInt32 numTables = atoi(readlineBuffer); + + for (PRInt32 i = 0; i < numTables; i++) + { + nsIMdbTable *table = new nsIMdbTable(this, /* we don't know the kind yet*/ 0); + if (table) + { + m_tables.AppendElement(table); + table->Read(); + } + } + return 0; +} + +mdb_err nsIMdbStore::NewTable( // make one new table of specific type nsIMdbEnv* ev, // context mdb_scope inRowScope, // row scope for row ids mdb_kind inTableKind, // the type of table to access mdb_bool inMustBeUnique, // whether store can hold only one of these nsIMdbTable** acqTable) // acquire scoped collection of rows - { - *acqTable = new nsIMdbTable(this, inTableKind); - m_tables.AppendElement(*acqTable); - return 0; - } +{ + *acqTable = new nsIMdbTable(this, inTableKind); + m_tables.AppendElement(*acqTable); + return 0; +} nsIMdbPort::nsIMdbPort() : m_backingFile("") { @@ -180,7 +224,8 @@ nsIMdbTable** acqTable) for (PRInt32 i = 0; i < m_tables.Count(); i++) { nsIMdbTable *table = (nsIMdbTable *) m_tables[i]; - if (table->m_Oid.mOid_Id == inOid->mOid_Id) + if (table->m_Oid.mOid_Id == inOid->mOid_Id + && table->m_Oid.mOid_Scope == inOid->mOid_Scope) { retTable = table; table->AddRef(); @@ -221,17 +266,23 @@ mdb_err nsIMdbPort::GetTableKind ( { nsIMdbTable *retTable = NULL; + mdb_count tableCount = 0; for (PRInt32 i = 0; i < m_tables.Count(); i++) { nsIMdbTable *table = (nsIMdbTable *) m_tables[i]; if (table->m_kind == inTableKind) { - retTable = table; - table->AddRef(); - *acqTable = table; - break; + tableCount++; + if (!*acqTable) + { + retTable = table; + table->AddRef(); + *acqTable = table; + } } } + *outTableCount = tableCount; + if (! retTable ) *acqTable = new nsIMdbTable (this, inTableKind); return 0; @@ -280,6 +331,10 @@ mdb_err nsIMdbTable::Write() nsIOFileStream *stream = m_owningPort->m_fileStream; *stream << m_kind; *stream << ","; + *stream << m_Oid.mOid_Id; + *stream << ","; + *stream << m_Oid.mOid_Scope; + *stream << ","; *stream << (long) m_rows.Count(); *stream << LINEBREAK; @@ -287,14 +342,9 @@ mdb_err nsIMdbTable::Write() for (i = 0; i < m_rows.Count(); i++) { - mdb_pos iteratePos; - - for (iteratePos = 0; iteratePos < m_rows.Count(); iteratePos++) - { - nsIMdbRow *row = (nsIMdbRow *) m_rows.ElementAt(iteratePos); - if (row) - row->Write(stream); - } + nsIMdbRow *row = (nsIMdbRow *) m_rows.ElementAt(i); + if (row) + row->Write(stream); } return 0; } @@ -311,17 +361,44 @@ mdb_err nsIMdbTable::Read() char *p; for (p = lineBuf; *p; p++) + { + if (*p == ',') + { + p++; + break; + } + } + PRInt32 oid = atoi(p); + m_Oid.mOid_Id = oid; + + for (p; *p; p++) + { + if (*p == ',') + { + p++; + break; + } + } + + PRInt32 scope = atoi(p); + m_Oid.mOid_Scope = scope; + + for (p; *p; p++) { if (*p == ',') break; } + PRInt32 numRows = atoi(p + 1); for (PRInt32 i = 0; i < numRows; i++) { nsIMdbRow *row = new nsIMdbRow(this, m_owningPort); if (row) + { + m_rows.AppendElement(row); row->Read(stream); + } } return 0; @@ -351,6 +428,10 @@ mdb_err nsIMdbTable::CutRow ( // make sure the row with inOid is not a member nsIMdbEnv* ev, // context nsIMdbRow* ioRow) { + PRBool found = m_rows.RemoveElement(ioRow); + if (found) + ioRow->Release(); // is this right? Who deletes the row? + return 0; } @@ -440,6 +521,10 @@ mdb_err nsIMdbRow::Write(nsIOFileStream *stream) // write out the number of cells. *stream << (long) m_cells.Count(); + *stream << ","; + *stream << (long) m_oid.mOid_Id; + *stream << LINEBREAK; + for (iteratePos = 0; iteratePos < m_cells.Count(); iteratePos++) { mdbCellImpl *cell = (mdbCellImpl *) m_cells.ElementAt(iteratePos); @@ -451,16 +536,40 @@ mdb_err nsIMdbRow::Write(nsIOFileStream *stream) mdb_err nsIMdbRow::Read(nsIOFileStream *stream) { - char numCellsBuf[30]; + char line[50]; - stream->readline(numCellsBuf, sizeof(numCellsBuf)); + stream->readline(line, sizeof(line)); - PRInt32 numCells = atoi(numCellsBuf); + PRInt32 numCells = atoi(line); + + char *p; + for (p = line; *p; p++) + { + if (*p == ',') + break; + } + + m_oid.mOid_Id = atoi(p + 1); +#ifdef DEBUG + printf("reading row id = %d\n", m_oid.mOid_Id); +#endif for (PRInt32 i = 0; i < numCells; i++) { mdbCellImpl *cell = new mdbCellImpl; if (cell) + { cell->Read(stream); + m_cells.AppendCell(*cell); +#ifdef DEBUG + nsString columnStr; + + m_owningPort->m_tokenStrings.StringAt(cell->m_column, columnStr); + char *column = columnStr.ToNewCString(); + printf("column = %s value = %s\n", (column) ? column : "", cell->m_cellValue); + delete [] column; +#endif + + } } return 0; @@ -534,6 +643,11 @@ mdb_err nsIMdbFactory::OpenFileStore(class nsIMdbEnv *, nsIMdbHeap* , char const return 0; } +mdbCellImpl::mdbCellImpl() +{ + m_cellValue = NULL; + m_column = 0; +} mdbCellImpl::mdbCellImpl(const mdbCellImpl &anotherCell) { @@ -560,7 +674,8 @@ mdb_err mdbCellImpl::Write(nsIOFileStream *stream) { *stream << m_column; *stream << "="; - *stream << m_cellValue; + if (m_cellValue) + *stream << m_cellValue; *stream << LINEBREAK; return 0; } diff --git a/mailnews/db/msgdb/src/nsDBFolderInfo.cpp b/mailnews/db/msgdb/src/nsDBFolderInfo.cpp index 967fd74550b..a25de1473e6 100644 --- a/mailnews/db/msgdb/src/nsDBFolderInfo.cpp +++ b/mailnews/db/msgdb/src/nsDBFolderInfo.cpp @@ -133,6 +133,13 @@ nsresult nsDBFolderInfo::AddToNewMDB() mdb_err err = store->NewTable(m_mdb->GetEnv(), m_rowScopeToken, m_tableKindToken, PR_TRUE, &m_mdbTable); + // make sure the oid of the table is 1. + struct mdbOid folderInfoTableOID; + folderInfoTableOID.mOid_Id = 1; + folderInfoTableOID.mOid_Scope = m_rowScopeToken; + + m_mdbTable->BecomeContent(m_mdb->GetEnv(), &folderInfoTableOID); + // create the singleton row for the dbFolderInfo. err = store->NewRowWithOid(m_mdb->GetEnv(), m_rowScopeToken, &gDBFolderInfoOID, &m_mdbRow); @@ -173,7 +180,7 @@ nsresult nsDBFolderInfo::InitFromExistingDB() { ret = rowCursor->NextRow(m_mdb->GetEnv(), &m_mdbRow, &rowPos); rowCursor->Release(); - if (ret == NS_OK) + if (ret == NS_OK && m_mdbRow) { LoadMemberVariables(); } @@ -335,7 +342,7 @@ NS_IMETHODIMP nsDBFolderInfo::ChangeNumMessages(PRInt32 delta) if (m_numMessages < 0) { #ifdef DEBUG_bienvenu - XP_ASSERT(FALSE); + NS_ASSERTION(FALSE, "num messages can't be < 0"); #endif m_numMessages = 0; } @@ -348,7 +355,7 @@ NS_IMETHODIMP nsDBFolderInfo::ChangeNumVisibleMessages(PRInt32 delta) if (m_numVisibleMessages < 0) { #ifdef DEBUG_bienvenu - XP_ASSERT(FALSE); + NS_ASSERTION(FALSE, "num visible messages can't be < 0"); #endif m_numVisibleMessages = 0; } diff --git a/mailnews/db/msgdb/src/nsMailDatabase.cpp b/mailnews/db/msgdb/src/nsMailDatabase.cpp index 31bbdf7dff5..84deffde1ad 100644 --- a/mailnews/db/msgdb/src/nsMailDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMailDatabase.cpp @@ -70,9 +70,9 @@ nsMailDatabase::~nsMailDatabase() // stat file before we open the db, because if we've latered // any messages, handling latered will change time stamp on // folder file. - statResult = stat ((const char *) dbPath, &st); + statResult = stat ((const char *) summarySpec, &st); - nsresult err = mailDB->OpenMDB(dbPath, create); + nsresult err = mailDB->OpenMDB((const char *) summarySpec, create); if (NS_SUCCEEDED(err)) { diff --git a/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mailnews/db/msgdb/src/nsMsgDatabase.cpp index 3d05c77c97e..eeacf39763a 100644 --- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -319,6 +319,9 @@ nsresult nsMsgDatabase::OpenMDB(const char *dbName, PRBool create) if (ret == NS_OK) ret = InitExistingDB(); } +#ifdef DEBUG_bienvenu + DumpContents(); +#endif } else if (create) // ### need error code saying why open file store failed { @@ -1331,7 +1334,7 @@ nsresult nsMsgDatabase::RowCellColumnTonsString(nsIMdbRow *hdrRow, mdb_token col nsIMdbCell *hdrCell; err = hdrRow->GetCell(GetEnv(), columnToken, &hdrCell); - if (err == NS_OK) + if (err == NS_OK && hdrCell) { struct mdbYarn yarn; hdrCell->AliasYarn(GetEnv(), &yarn); @@ -1351,7 +1354,7 @@ nsresult nsMsgDatabase::RowCellColumnToUInt32(nsIMdbRow *hdrRow, mdb_token colum nsIMdbCell *hdrCell; err = hdrRow->GetCell(GetEnv(), columnToken, &hdrCell); - if (err == NS_OK) + if (err == NS_OK && hdrCell) { struct mdbYarn yarn; hdrCell->AliasYarn(GetEnv(), &yarn); @@ -1414,3 +1417,33 @@ nsresult nsMsgDatabase::SetSummaryValid(PRBool valid /* = PR_TRUE */) return NS_OK; } +#ifdef DEBUG +void nsMsgDatabase::DumpContents() +{ + nsMsgKeyArray keys; + nsString author; + nsString subject; + + ListAllKeys(keys); + for (PRInt32 index = 0; index < keys.GetSize(); index++) + { + nsMsgHdr *msgHdr = NULL; + nsresult ret = GetMsgHdrForKey(keys[index], &msgHdr); + if (ret == NS_OK && msgHdr) + { + nsMsgKey key; + + msgHdr->GetMessageKey(&key); + msgHdr->GetAuthor(author); + msgHdr->GetSubject(subject); + char *authorStr = author.ToNewCString(); + char *subjectStr = subject.ToNewCString(); + // leak nsString return values... + printf("hdr key = %ld, author = %s subject = %s\n", key, (authorStr) ? authorStr : "", (subjectStr) ? subjectStr : ""); + delete [] authorStr; + delete [] subjectStr; + msgHdr->Release(); + } + } +} +#endif diff --git a/mailnews/db/msgdb/src/nsMsgHdr.cpp b/mailnews/db/msgdb/src/nsMsgHdr.cpp index b6f7684e132..a72da9de9d6 100644 --- a/mailnews/db/msgdb/src/nsMsgHdr.cpp +++ b/mailnews/db/msgdb/src/nsMsgHdr.cpp @@ -51,15 +51,19 @@ nsMsgHdr::nsMsgHdr(nsMsgDatabase *db, nsIMdbRow *dbRow) m_mdb = db; if(m_mdb) m_mdb->AddRef(); - m_mdbRow = dbRow; Init(); + m_mdbRow = dbRow; } void nsMsgHdr::Init() { m_statusOffset = -1; m_messageKey = nsMsgKey_None; + m_date = 0; + m_messageSize = 0; m_csID = 0; + m_flags = 0; + m_mdbRow = NULL; } nsMsgHdr::~nsMsgHdr() @@ -225,11 +229,78 @@ NS_IMETHODIMP nsMsgHdr::SetRecipients(const char *recipients, PRBool rfc822 /* = return SetStringColumn(recipients, m_mdb->m_recipientsColumnToken); } +NS_IMETHODIMP nsMsgHdr::SetRecipientsArray(const char *names, const char *addresses, PRUint32 numAddresses) +{ + nsresult ret; + const char *curName = names; + const char *curAddress = addresses; + nsString allRecipients; + + for (int i = 0; i < numAddresses; i++) + { + if (strlen(curName)) + { + allRecipients = curName; + allRecipients += ' '; + } + + if (strlen(curAddress)) + { + if (strlen(curName)) + allRecipients += '<'; + else + allRecipients = "<"; + allRecipients += curAddress; + allRecipients += '>'; + } + curName += strlen(curName) + 1; + curAddress += strlen(curAddress) + 1; + } + char *cstringRecipients = allRecipients.ToNewCString(); + ret = SetRecipients(cstringRecipients, PR_TRUE); + delete [] cstringRecipients; + return ret; +} + NS_IMETHODIMP nsMsgHdr::SetCCList(const char *ccList) { return SetStringColumn(ccList, m_mdb->m_ccListColumnToken); } +// ###should make helper routine that takes column token! +NS_IMETHODIMP nsMsgHdr::SetCCListArray(const char *names, const char *addresses, PRUint32 numAddresses) +{ + nsresult ret; + const char *curName = names; + const char *curAddress = addresses; + nsString allRecipients; + + for (int i = 0; i < numAddresses; i++) + { + if (strlen(curName)) + { + allRecipients += curName; + allRecipients += ' '; + } + + if (strlen(curAddress)) + { + if (strlen(curName)) + allRecipients += '<'; + else + allRecipients += "<"; + allRecipients += curAddress; + allRecipients += '>'; + } + curName += strlen(curName) + 1; + curAddress += strlen(curAddress) + 1; + } + char *cstringRecipients = allRecipients.ToNewCString(); + ret = SetCCList(cstringRecipients); + delete [] cstringRecipients; + return ret; +} + NS_IMETHODIMP nsMsgHdr::SetMessageSize(PRUint32 messageSize) {