Bug 801383 Fix fallout from bug 779473 - make nsresult an enum class. Fix most of mailnews. Patch started by mconley, completed by irving. r=Standard8
authorIrving Reid <irving@mozilla.com>
Tue, 16 Oct 2012 11:21:18 +0100
changeset 14043 65b8e2fa4eba178e960aa0b2125cac986a90c0c3
parent 14042 eac22e3d7ba343ace7a9c4033392e334a5d443be
child 14044 cc0ff188f5bc5e7e2cd6f37ceb211a460c8e6557
push id804
push userbugzilla@standard8.plus.com
push dateMon, 07 Jan 2013 21:31:35 +0000
treeherdercomm-beta@9fdc5c67cdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs801383, 779473
Bug 801383 Fix fallout from bug 779473 - make nsresult an enum class. Fix most of mailnews. Patch started by mconley, completed by irving. r=Standard8
mailnews/addrbook/src/nsAbLDAPAutoCompFormatter.cpp
mailnews/addrbook/src/nsAbLDIFService.cpp
mailnews/addrbook/src/nsAddrDatabase.cpp
mailnews/base/search/public/nsIMsgSearchAdapter.idl
mailnews/base/search/src/nsMsgSearchAdapter.cpp
mailnews/base/search/src/nsMsgSearchTerm.cpp
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/base/src/nsMsgDBView.cpp
mailnews/base/src/nsMsgFolderCache.cpp
mailnews/base/src/nsMsgFolderDataSource.cpp
mailnews/base/util/nsMsgKeySet.cpp
mailnews/base/util/nsMsgLineBuffer.cpp
mailnews/base/util/nsMsgLineBuffer.h
mailnews/base/util/nsMsgProtocol.cpp
mailnews/db/msgdb/src/nsDBFolderInfo.cpp
mailnews/db/msgdb/src/nsImapMailDatabase.cpp
mailnews/db/msgdb/src/nsMailDatabase.cpp
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapOfflineSync.cpp
mailnews/imap/src/nsImapProtocol.cpp
mailnews/import/eudora/src/nsEudoraFilters.cpp
mailnews/import/eudora/src/nsEudoraMac.cpp
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsMailboxProtocol.cpp
mailnews/local/src/nsMailboxProtocol.h
mailnews/local/src/nsPop3Protocol.cpp
mailnews/local/src/nsPop3Protocol.h
mailnews/mime/src/mimedrft.cpp
mailnews/mime/src/mimehdrs.cpp
mailnews/mime/src/mimemalt.cpp
mailnews/mime/src/mimemrel.cpp
mailnews/mime/src/mimepbuf.cpp
mailnews/mime/src/mimetpfl.cpp
mailnews/mime/src/mimetpla.cpp
mailnews/mime/src/nsMsgHeaderParser.cpp
mailnews/news/src/nsNntpIncomingServer.cpp
mailnews/news/src/nsNntpIncomingServer.h
--- a/mailnews/addrbook/src/nsAbLDAPAutoCompFormatter.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPAutoCompFormatter.cpp
@@ -214,17 +214,17 @@ nsAbLDAPAutoCompFormatter::FormatExcepti
             return rv;
         }
   
     } else {
 
         // put the entire nsresult in string form
         //
         errCodeNum.AppendLiteral("0x");
-        errCodeNum.AppendInt(aErrorCode, 16);    
+        errCodeNum.AppendInt(static_cast<uint32_t>(aErrorCode), 16);
 
         // figure out the key to index into the string bundle
         //
         const int32_t HOST_NOT_FOUND_ERROR=5000;
         const int32_t GENERIC_ERROR=9999;
         errorKey = ( (aErrorCode == NS_ERROR_UNKNOWN_HOST) ? 
                      HOST_NOT_FOUND_ERROR : GENERIC_ERROR );
 
--- a/mailnews/addrbook/src/nsAbLDIFService.cpp
+++ b/mailnews/addrbook/src/nsAbLDIFService.cpp
@@ -365,17 +365,17 @@ void nsAbLDIFService::AddLdifRowToDataba
   char* cursor = ToNewCString(mLdifLine); 
   char* saveCursor = cursor;  /* keep for deleting */ 
   char* line = 0; 
   char* typeSlot = 0; 
   char* valueSlot = 0; 
   int length = 0;  // the length  of an ldif attribute
   while ( (line = str_getline(&cursor)) != nullptr)
   {
-    if ( str_parse_line(line, &typeSlot, &valueSlot, &length) == 0) {
+    if (NS_SUCCEEDED(str_parse_line(line, &typeSlot, &valueSlot, &length))) {
       AddLdifColToDatabase(aDatabase, newRow, typeSlot, valueSlot, bIsList);
     }
     else
       continue; // parse error: continue with next loop iteration
   }
   nsMemory::Free(saveCursor);
   aDatabase->AddCardRowToDB(newRow);    
 
--- a/mailnews/addrbook/src/nsAddrDatabase.cpp
+++ b/mailnews/addrbook/src/nsAddrDatabase.cpp
@@ -545,17 +545,17 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(ns
       ret = mdbFactory->OpenOldFile(m_mdbEnv, dbHeap, filePath.get(),
                                     dbFrozen, &oldFile);
       if ( oldFile )
       {
         if ( ret == NS_OK )
         {
           ret = mdbFactory->CanOpenFilePort(m_mdbEnv, oldFile, // the file to investigate
                                             &canOpen, &outFormatVersion);
-          if (ret == 0 && canOpen)
+          if (NS_SUCCEEDED(ret) && canOpen)
           {
             inOpenPolicy.mOpenPolicy_ScopePlan.mScopeStringSet_Count = 0;
             inOpenPolicy.mOpenPolicy_MinMemory = 0;
             inOpenPolicy.mOpenPolicy_MaxLazy = 0;
 
             ret = mdbFactory->OpenFileStore(m_mdbEnv, dbHeap,
               oldFile, &inOpenPolicy, &thumb);
           }
@@ -572,17 +572,17 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(ns
     {
       mdb_count outTotal;    // total somethings to do in operation
       mdb_count outCurrent;  // subportion of total completed so far
       mdb_bool outDone = false;      // is operation finished?
       mdb_bool outBroken;     // is operation irreparably dead and broken?
       do
       {
         ret = thumb->DoMore(m_mdbEnv, &outTotal, &outCurrent, &outDone, &outBroken);
-        if (ret != 0)
+        if (NS_FAILED(ret))
         {
           outDone = true;
           break;
         }
       }
       while (NS_SUCCEEDED(ret) && !outBroken && !outDone);
       if (NS_SUCCEEDED(ret) && outDone)
       {
@@ -614,19 +614,16 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(ns
           if (ret == NS_OK)
             ret = InitNewDB();
         }
         NS_RELEASE(newFile); // always release our file ref, store has own
       }
     }
     NS_IF_RELEASE(thumb);
   }
-  //Convert the DB error to a valid nsresult error.
-  if (ret == 1)
-    ret = NS_ERROR_FAILURE;
   return ret;
 }
 
 NS_IMETHODIMP nsAddrDatabase::CloseMDB(bool commit)
 {
     if (commit)
         Commit(nsAddrDBCommitType::kSessionCommit);
 //???    RemoveFromCache(this);  // if we've closed it, better not leave it in the cache.
--- a/mailnews/base/search/public/nsIMsgSearchAdapter.idl
+++ b/mailnews/base/search/public/nsIMsgSearchAdapter.idl
@@ -9,22 +9,22 @@
 #include "nsIMsgSearchScopeTerm.idl"
 
 [ptr] native nsMsgResultElement(nsMsgResultElement);
 
 %{C++
 class nsMsgResultElement;
 %}
 
-[scriptable, uuid(B9F49D4C-A494-41f6-9D70-AB6CB5670485)]
+[scriptable, uuid(0b09078b-e0cd-440a-afee-01f45808ee74)]
 interface nsIMsgSearchAdapter : nsISupports {
     void ValidateTerms();
     void Search(out boolean done);
     void SendUrl();
-    void CurrentUrlDone(in long exitCode);
+    void CurrentUrlDone(in nsresult exitCode);
 
     void AddHit(in nsMsgKey key);
     void AddResultElement(in nsIMsgDBHdr aHdr);
 
     [noscript] void OpenResultElement(in nsMsgResultElement element);
     [noscript] void ModifyResultElement(in nsMsgResultElement element,
                                         in nsMsgSearchValue value);
 
--- a/mailnews/base/search/src/nsMsgSearchAdapter.cpp
+++ b/mailnews/base/search/src/nsMsgSearchAdapter.cpp
@@ -116,18 +116,18 @@ NS_IMETHODIMP nsMsgSearchAdapter::Search
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgSearchAdapter::SendUrl ()
 {
   return NS_OK;
 }
 
-/* void CurrentUrlDone (in long exitCode); */
-NS_IMETHODIMP nsMsgSearchAdapter::CurrentUrlDone(int32_t exitCode)
+/* void CurrentUrlDone (in nsresult exitCode); */
+NS_IMETHODIMP nsMsgSearchAdapter::CurrentUrlDone(nsresult exitCode)
 {
   // base implementation doesn't need to do anything.
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgSearchAdapter::GetEncoding (char **encoding)
 {
   return NS_OK;
--- a/mailnews/base/search/src/nsMsgSearchTerm.cpp
+++ b/mailnews/base/search/src/nsMsgSearchTerm.cpp
@@ -1635,17 +1635,17 @@ nsresult nsMsgSearchTerm::MatchKeyword(c
 
 nsresult
 nsMsgSearchTerm::MatchPriority (nsMsgPriorityValue priorityToMatch,
                                 bool *pResult)
 {
   NS_ENSURE_ARG_POINTER(pResult);
 
   nsresult err = NS_OK;
-  bool result=NS_OK;
+  bool result = false;
 
   // Use this ugly little hack to get around the fact that enums don't have
   // integer compare operators
   int p1 = (priorityToMatch == nsMsgPriority::none) ? (int) nsMsgPriority::normal : (int) priorityToMatch;
   int p2 = (int) m_value.u.priority;
 
   switch (m_operator)
   {
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -689,17 +689,17 @@ nsMsgAccountManager::removeListenerFromF
 
 NS_IMETHODIMP
 nsMsgAccountManager::RemoveAccount(nsIMsgAccount *aAccount)
 {
   NS_ENSURE_ARG_POINTER(aAccount);
   nsresult rv = LoadAccounts();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  bool accountRemoved = m_accounts->RemoveElement(aAccount);
+  bool accountRemoved = NS_SUCCEEDED(m_accounts->RemoveElement(aAccount));
 
   rv  = OutputAccountsPref();
   // If we couldn't write out the pref, restore the account.
   if (NS_FAILED(rv) && accountRemoved)
   {
     m_accounts->AppendElement(aAccount);
     return rv;
   }
--- a/mailnews/base/src/nsMsgDBView.cpp
+++ b/mailnews/base/src/nsMsgDBView.cpp
@@ -4627,17 +4627,17 @@ nsMsgViewIndex nsMsgDBView::ThreadIndexO
   nsresult rv = m_db->GetMsgHdrForKey(msgKey, getter_AddRefs(msgHdr));
   NS_ENSURE_SUCCESS(rv, nsMsgViewIndex_None);
   return ThreadIndexOfMsgHdr(msgHdr, msgIndex, pThreadCount, pFlags);
 }
 
 nsMsgViewIndex nsMsgDBView::GetThreadIndex(nsMsgViewIndex msgIndex)
 {
   if (!IsValidIndex(msgIndex))
-    return NS_MSG_INVALID_DBVIEW_INDEX;
+    return nsMsgViewIndex_None;
 
   // scan up looking for level 0 message.
   while (m_levels[msgIndex] && msgIndex)
     --msgIndex;
   return msgIndex;
 }
 
 nsMsgViewIndex
@@ -6840,17 +6840,19 @@ nsresult nsMsgDBView::ToggleMessageKille
 }
 
 nsMsgViewIndex  nsMsgDBView::GetThreadFromMsgIndex(nsMsgViewIndex index,
                                                    nsIMsgThread **threadHdr)
 {
   nsMsgKey        msgKey = GetAt(index);
   nsMsgViewIndex  threadIndex;
 
-  NS_ENSURE_ARG(threadHdr);
+  if (threadHdr == nullptr)
+    return nsMsgViewIndex_None;
+
   nsresult rv = GetThreadContainingIndex(index, threadHdr);
   NS_ENSURE_SUCCESS(rv,nsMsgViewIndex_None);
 
   if (*threadHdr == nullptr)
     return nsMsgViewIndex_None;
 
   nsMsgKey threadKey;
   (*threadHdr)->GetThreadKey(&threadKey);
--- a/mailnews/base/src/nsMsgFolderCache.cpp
+++ b/mailnews/base/src/nsMsgFolderCache.cpp
@@ -177,18 +177,18 @@ nsresult nsMsgFolderCache::OpenMDB(const
       {
         mdb_count outTotal;    // total somethings to do in operation
         mdb_count outCurrent;  // subportion of total completed so far
         mdb_bool outDone = false;      // is operation finished?
         mdb_bool outBroken;     // is operation irreparably dead and broken?
         do
         {
           ret = thumb->DoMore(m_mdbEnv, &outTotal, &outCurrent, &outDone, &outBroken);
-          if (ret != 0)
-          {// mork isn't really doing NS errors yet.
+          if (NS_FAILED(ret))
+          {
             outDone = true;
             break;
           }
         }
         while (NS_SUCCEEDED(ret) && !outBroken && !outDone);
         // m_mdbEnv->ClearErrors(); // ### temporary...
         if (NS_SUCCEEDED(ret) && outDone)
         {
--- a/mailnews/base/src/nsMsgFolderDataSource.cpp
+++ b/mailnews/base/src/nsMsgFolderDataSource.cpp
@@ -2396,17 +2396,17 @@ void nsMsgRecentFoldersDataSource::Ensur
             allFolders->Count(&newLastEntry);
             for (uint32_t newEntryIndex = lastEntry; newEntryIndex < newLastEntry; newEntryIndex++)
             {
               nsCOMPtr <nsIMsgFolder> curFolder = do_QueryElementAt(allFolders, newEntryIndex);
               nsCString dateStr;
               nsresult err;
               curFolder->GetStringProperty(MRU_TIME_PROPERTY, dateStr);
               uint32_t curFolderDate = (uint32_t) dateStr.ToInteger(&err);
-              if (err)
+              if (NS_FAILED(err))
                 curFolderDate = 0;
               if (curFolderDate > m_cutOffDate)
               {
                 // if m_folders is "full", replace oldest folder with this folder,
                 // and adjust m_cutOffDate so that it's the mrutime
                 // of the "new" oldest folder.
                 uint32_t curFaveFoldersCount = m_folders.Count();
                 if (curFaveFoldersCount > m_maxNumFolders)
--- a/mailnews/base/util/nsMsgKeySet.cpp
+++ b/mailnews/base/util/nsMsgKeySet.cpp
@@ -704,17 +704,18 @@ nsMsgKeySet::Add(int32_t number)
      avoiding massive duplication of code, simply insert a literal here and
      then run the optimizer.
      */
   int mid = (tail - head); 
 
   if (m_data_size <= m_length + 1) {
     int endo = end - head;
     if (!Grow()) {
-      return NS_ERROR_OUT_OF_MEMORY;
+      // out of memory
+      return -1;
     }
     head = m_data;
     end = head + endo;
   }
 
   if (tail == end) {
     /* at the end */
     /* Add a literal to the end. */
@@ -821,17 +822,19 @@ nsMsgKeySet::Remove(int32_t number)
         return 1;
       } else {
         /* The number being deleted is in the middle of a range which
            must be split. This increases overall length by 2.
            */
         int32_t i;
         int endo = end - head;
         if (m_data_size - m_length <= 2) {
-          if (!Grow()) return NS_ERROR_OUT_OF_MEMORY;
+          if (!Grow())
+            // out of memory
+            return -1;
         }
         head = m_data;
         end = head + endo;
 
         for (i = m_length + 2; i > mid + 2; i--) {
           m_data[i] = m_data[i-2];
         }
 
@@ -921,17 +924,19 @@ nsMsgKeySet::AddRange(int32_t start, int
 
   if (start == end) {
     return Add(start);
   }
 
   tmplength = m_length + 2;
   tmp = (int32_t*) PR_Malloc(sizeof(int32_t) * tmplength);
 
-  if (!tmp) return NS_ERROR_OUT_OF_MEMORY;
+  if (!tmp)
+    // out of memory
+    return -1;
 
   in = m_data;
   out = tmp;
   tail = in + m_length;
 
 #define EMIT(x, y) out = msg_emit_range(out, x, y)
 
   while (in < tail) {
@@ -1347,17 +1352,17 @@ nsMsgKeySet::test_adder (void)
   printf ("%3lu: %s\n\n", (unsigned long)set->m_length, s); \
   nsMemory::Free(s);                      \
   delete set;
 
 
 void
 nsMsgKeySet::test_ranges(void)
 {
-  char *string;
+  const char *string;
   nsMsgKeySet *set;
   char *s;
   int32_t i;
   int32_t j;
 
   START("20-40,72-99,105,107,110-111,117-200");
 
   FROB(205, 208);
--- a/mailnews/base/util/nsMsgLineBuffer.cpp
+++ b/mailnews/base/util/nsMsgLineBuffer.cpp
@@ -90,17 +90,17 @@ nsresult nsMsgLineBuffer::BufferInput(co
     nsresult status = NS_OK;
     if (m_bufferPos > 0 && m_buffer && m_buffer[m_bufferPos - 1] == '\r' &&
         net_buffer_size > 0 && net_buffer[0] != '\n') {
         /* The last buffer ended with a CR.  The new buffer does not start
            with a LF.  This old buffer should be shipped out and discarded. */
         PR_ASSERT(m_bufferSize > m_bufferPos);
         if (m_bufferSize <= m_bufferPos)
           return NS_ERROR_UNEXPECTED;
-        if (ConvertAndSendBuffer() == -1)
+        if (NS_FAILED(ConvertAndSendBuffer()))
            return NS_ERROR_FAILURE;
         m_bufferPos = 0;
     }
     while (net_buffer_size > 0)
     {
         const char *net_buffer_end = net_buffer + net_buffer_size;
         const char *newline = 0;
         const char *s;
@@ -162,50 +162,50 @@ nsresult nsMsgLineBuffer::BufferInput(co
            a line as we have read so far.
            
            If we have a line, process it, and then remove it from `m_buffer'.
            Then go around the loop again, until we drain the incoming data.
            */
         if (!newline)
             return NS_OK;
 
-        if (ConvertAndSendBuffer() == -1)
+        if (NS_FAILED(ConvertAndSendBuffer()))
           return NS_ERROR_FAILURE;
         
         net_buffer_size -= (newline - net_buffer);
         net_buffer = newline;
         m_bufferPos = 0;
     }
     return NS_OK;
 }
 
 nsresult nsMsgLineBuffer::HandleLine(char *line, uint32_t line_length)
 {
   NS_ASSERTION(false, "must override this method if you don't provide a handler");
   return NS_OK;
 }
 
-int32_t nsMsgLineBuffer::ConvertAndSendBuffer()
+nsresult nsMsgLineBuffer::ConvertAndSendBuffer()
 {
     /* Convert the line terminator to the native form.
      */
 
     char *buf = m_buffer;
     int32_t length = m_bufferPos;
 
     char* newline;
     
     PR_ASSERT(buf && length > 0);
     if (!buf || length <= 0) 
-        return -1;
+        return NS_ERROR_FAILURE;
     newline = buf + length;
     
     PR_ASSERT(newline[-1] == '\r' || newline[-1] == '\n');
     if (newline[-1] != '\r' && newline[-1] != '\n')
-        return -1;
+        return NS_ERROR_FAILURE;
     
     if (m_convertNewlinesP)
     {
 #if (MSG_LINEBREAK_LEN == 1)
       if ((newline - buf) >= 2 &&
            newline[-2] == '\r' &&
            newline[-1] == '\n')
       {
@@ -229,24 +229,24 @@ int32_t nsMsgLineBuffer::ConvertAndSendB
         buf[length - 1] = MSG_LINEBREAK[1];
       }
 #endif
     }    
     return (m_handler) ? m_handler->HandleLine(buf, length) : HandleLine(buf, length);
 }
 
 // If there's still some data (non CRLF terminated) flush it out
-int32_t nsMsgLineBuffer::FlushLastLine()
+nsresult nsMsgLineBuffer::FlushLastLine()
 {
   char *buf = m_buffer + m_bufferPos;
   int32_t length = m_bufferPos - 1;
   if (length > 0)
     return (m_handler) ? m_handler->HandleLine(buf, length) : HandleLine(buf, length);
   else
-    return 0;
+    return NS_OK;
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // This is a utility class used to efficiently extract lines from an input stream by buffering
 // read but unprocessed stream data in a buffer. 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 nsMsgLineStreamBuffer::nsMsgLineStreamBuffer(uint32_t aBufferSize, bool aAllocateNewLines, bool aEatCRLFs, char aLineToken) 
--- a/mailnews/base/util/nsMsgLineBuffer.h
+++ b/mailnews/base/util/nsMsgLineBuffer.h
@@ -43,21 +43,21 @@ public:
   
   virtual    ~nsMsgLineBuffer();
   nsresult    BufferInput(const char *net_buffer, int32_t net_buffer_size);
   // Not sure why anyone cares, by NNTPHost seems to want to know the buf pos.
   uint32_t    GetBufferPos() {return m_bufferPos;}
   
   virtual nsresult HandleLine(char *line, uint32_t line_length);
   // flush last line, though it won't be CRLF terminated.
-  virtual int32_t FlushLastLine();
+  virtual nsresult FlushLastLine();
 protected:
   nsMsgLineBuffer(bool convertNewlinesP);
   
-  int32_t ConvertAndSendBuffer();
+  nsresult ConvertAndSendBuffer();
   void SetLookingForCRLF(bool b);
   
   nsMsgLineBufferHandler *m_handler;
   bool        m_convertNewlinesP;
   bool        m_lookingForCRLF; 
 };
 
 // I'm adding this utility class here for lack of a better place. This utility class is similar to nsMsgLineBuffer
--- a/mailnews/base/util/nsMsgProtocol.cpp
+++ b/mailnews/base/util/nsMsgProtocol.cpp
@@ -742,18 +742,18 @@ nsMsgProtocol::SetNotificationCallbacks(
 NS_IMETHODIMP
 nsMsgProtocol::OnTransportStatus(nsITransport *transport, nsresult status,
                                  uint64_t progress, uint64_t progressMax)
 {
   if ((mLoadFlags & LOAD_BACKGROUND) || !m_url)
     return NS_OK;
 
   // these transport events should not generate any status messages
-  if (status == nsISocketTransport::STATUS_RECEIVING_FROM ||
-      status == nsISocketTransport::STATUS_SENDING_TO)
+  if (status == NS_NET_STATUS_RECEIVING_FROM ||
+      status == NS_NET_STATUS_SENDING_TO)
     return NS_OK;
 
   if (!mProgressEventSink)
   {
     NS_QueryNotificationCallbacks(mCallbacks, m_loadGroup, mProgressEventSink);
     if (!mProgressEventSink)
       return NS_OK;
   }
--- a/mailnews/db/msgdb/src/nsDBFolderInfo.cpp
+++ b/mailnews/db/msgdb/src/nsDBFolderInfo.cpp
@@ -931,20 +931,20 @@ NS_IMETHODIMP nsDBFolderInfo::GetTransfe
   mdbYarn cellName = { columnName, 0, sizeof(columnName), 0, 0, nullptr };
 
   NS_ASSERTION(m_mdbRow, "null row in getTransferInfo");
   m_mdbRow->GetCount(m_mdb->GetEnv(), &numCells);
   // iterate over the cells in the dbfolderinfo remembering attribute names and values.
   for (mdb_count cellIndex = 0; cellIndex < numCells; cellIndex++)
   {
     mdb_err err = m_mdbRow->SeekCellYarn(m_mdb->GetEnv(), cellIndex, &cellColumn, nullptr);
-    if (!err)
+    if (NS_SUCCEEDED(err))
     {
       err = m_mdbRow->AliasCellYarn(m_mdb->GetEnv(), cellColumn, &cellYarn);
-      if (!err)
+      if (NS_SUCCEEDED(err))
       {
         m_mdb->GetStore()->TokenToString(m_mdb->GetEnv(), cellColumn, &cellName);
         newInfo->m_values.AppendElement(Substring((const char *)cellYarn.mYarn_Buf,
                                         (const char *) cellYarn.mYarn_Buf + cellYarn.mYarn_Fill));
         newInfo->m_properties.AppendElement(Substring((const char *) cellName.mYarn_Buf,
                                             (const char *) cellName.mYarn_Buf + cellName.mYarn_Fill));
       }
     }
--- a/mailnews/db/msgdb/src/nsImapMailDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsImapMailDatabase.cpp
@@ -139,20 +139,20 @@ NS_IMETHODIMP nsImapMailDatabase::Update
       aNewHdr->GetFlags(&existingFlags);
       // iterate over the cells in the pending hdr setting properties on the aNewHdr.
       // we skip cell 0, which is the messageId;
       nsMsgHdr* msgHdr = static_cast<nsMsgHdr*>(aNewHdr);      // closed system, cast ok
       nsIMdbRow *row = msgHdr->GetMDBRow();
       for (mdb_count cellIndex = 1; cellIndex < numCells; cellIndex++)
       {
         mdb_err err = pendingRow->SeekCellYarn(GetEnv(), cellIndex, &cellColumn, nullptr);
-        if (err == 0)
+        if (NS_SUCCEEDED(err))
         {
           err = pendingRow->AliasCellYarn(GetEnv(), cellColumn, &cellYarn);
-          if (err == 0)
+          if (NS_SUCCEEDED(err))
           {
             if (row)
               row->AddColumn(GetEnv(), cellColumn, &cellYarn);
           }
         }
       }
       // We might have changed some cached values, so force a refresh.
       msgHdr->ClearCachedValues();
--- a/mailnews/db/msgdb/src/nsMailDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMailDatabase.cpp
@@ -169,17 +169,17 @@ NS_IMETHODIMP nsMailDatabase::GetOffline
       {
         err  = m_mdbStore->NewRowWithOid(GetEnv(), &rowObjectId, getter_AddRefs(offlineOpRow));
         NS_ENSURE_SUCCESS(err, err);
       }
       if (offlineOpRow && !hasOid)
         m_mdbAllOfflineOpsTable->AddRow(GetEnv(), offlineOpRow);
     }
     
-    if (err == NS_OK && offlineOpRow)
+    if (NS_SUCCEEDED(err) && offlineOpRow)
     {
       *offlineOp = new nsMsgOfflineImapOperation(this, offlineOpRow);
       if (*offlineOp)
         (*offlineOp)->SetMessageKey(msgKey);
       NS_IF_ADDREF(*offlineOp);
     }
     if (!hasOid && m_dbFolderInfo)
     {
@@ -192,18 +192,17 @@ NS_IMETHODIMP nsMailDatabase::GetOffline
         msgHdr->GetFlags(&flags);
         (*offlineOp)->SetNewFlags(flags);
       }
       int32_t newFlags;
       m_dbFolderInfo->OrFlags(nsMsgFolderFlags::OfflineEvents, &newFlags);
     }
   }
   
-  return (err == 0) ? NS_OK : NS_ERROR_FAILURE;
-
+  return err;
 }
 
 NS_IMETHODIMP nsMailDatabase::EnumerateOfflineOps(nsISimpleEnumerator **enumerator)
 {
   NS_ASSERTION(false, "not impl yet");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -1257,17 +1257,17 @@ nsresult nsMsgDatabase::OpenMDB(const ch
         ret = mdbFactory->OpenOldFile(m_mdbEnv, dbHeap, dbName,
           dbFrozen, &oldFile);
         if ( oldFile )
         {
           if ( ret == NS_OK )
           {
             ret = mdbFactory->CanOpenFilePort(m_mdbEnv, oldFile, // the file to investigate
               &canOpen, &outFormatVersion);
-            if (ret == 0 && canOpen)
+            if (NS_SUCCEEDED(ret) && canOpen)
             {
               inOpenPolicy.mOpenPolicy_ScopePlan.mScopeStringSet_Count = 0;
               inOpenPolicy.mOpenPolicy_MinMemory = 0;
               inOpenPolicy.mOpenPolicy_MaxLazy = 0;
 
               ret = mdbFactory->OpenFileStore(m_mdbEnv, dbHeap,
                 oldFile, &inOpenPolicy, getter_AddRefs(m_thumb));
             }
@@ -1281,29 +1281,29 @@ nsresult nsMsgDatabase::OpenMDB(const ch
       {
         mdb_count outTotal;    // total somethings to do in operation
         mdb_count outCurrent;  // subportion of total completed so far
         mdb_bool outDone = false;      // is operation finished?
         mdb_bool outBroken;     // is operation irreparably dead and broken?
         do
         {
           ret = m_thumb->DoMore(m_mdbEnv, &outTotal, &outCurrent, &outDone, &outBroken);
-          if (ret != 0)
+          if (NS_FAILED(ret))
           {// mork isn't really doing NS errors yet.
             outDone = true;
             break;
           }
         }
         while (NS_SUCCEEDED(ret) && !outBroken && !outDone);
         //        m_mdbEnv->ClearErrors(); // ### temporary...
         // only 0 is a non-error return.
-        if (ret == 0 && outDone)
+        if (NS_SUCCEEDED(ret) && outDone)
         {
           ret = mdbFactory->ThumbToOpenStore(m_mdbEnv, m_thumb, &m_mdbStore);
-          if (ret == NS_OK)
+          if (NS_SUCCEEDED(ret))
             ret = (m_mdbStore) ? InitExistingDB() : NS_ERROR_FAILURE;
         }
 #ifdef DEBUG_bienvenu1
         DumpContents();
 #endif
         m_thumb = nullptr;
       }
       else if (create)  // ### need error code saying why open file store failed
--- a/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
+++ b/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
@@ -1073,17 +1073,17 @@ make_multipart_signed_header_string(bool
    it's used to write the encoded representation of the signature.  The only
    difference is which MimeEncoderData object is used.
  */
 static void
 mime_crypto_write_base64 (void *closure, const char *buf, unsigned long size)
 {
   MimeEncoderData *data = (MimeEncoderData *) closure;
   nsresult rv = MIME_EncoderWrite (data, buf, size);
-  PR_SetError(NS_FAILED(rv) ? rv : 0, 0);
+  PR_SetError(NS_FAILED(rv) ? static_cast<uint32_t>(rv) : 0, 0);
 }
 
 
 /* Used as the output function of MimeEncoderData -- when we have generated
    the signature for a multipart/signed object, this is used to write the
    base64-encoded representation of the signature to the file.
  */
 int mime_encoder_output_fn(const char *buf, int32_t size, void *closure)
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -5018,17 +5018,17 @@ nsresult nsImapMailFolder::GetTrashFolde
 
 
 // store nsMsgMessageFlags::IMAPDeleted in the specified mailhdr records
 void nsImapMailFolder::SetIMAPDeletedFlag(nsIMsgDatabase *mailDB, const nsTArray<nsMsgKey> &msgids, bool markDeleted)
 {
   nsresult markStatus = NS_OK;
   uint32_t total = msgids.Length();
 
-  for (uint32_t msgIndex=0; !markStatus && (msgIndex < total); msgIndex++)
+  for (uint32_t msgIndex=0; NS_SUCCEEDED(markStatus) && (msgIndex < total); msgIndex++)
     markStatus = mailDB->MarkImapDeleted(msgids[msgIndex], markDeleted, nullptr);
 }
 
 NS_IMETHODIMP
 nsImapMailFolder::GetMessageSizeFromDB(const char * id, uint32_t *size)
 {
   NS_ENSURE_ARG_POINTER(size);
   nsresult rv;
@@ -7140,17 +7140,17 @@ nsresult nsImapMailFolder::CopyMessagesO
       nsOfflineImapOperationType deleteOpType = nsIMsgOfflineImapOperation::kDeletedMsg;
       if (!deleteToTrash)
         deleteOpType = nsIMsgOfflineImapOperation::kMsgMarkedDeleted;
       srcFolder->GetOfflineStoreInputStream(getter_AddRefs(inputStream));
       nsCString messageIds;
       rv = BuildIdsAndKeyArray(messages, messageIds, srcKeyArray);
       // put fake message in destination db, delete source if move
       EnableNotifications(nsIMsgFolder::allMessageCountNotifications, false, false);
-      for (uint32_t sourceKeyIndex = 0; !stopit && (sourceKeyIndex < srcCount); sourceKeyIndex++)
+      for (uint32_t sourceKeyIndex = 0; NS_SUCCEEDED(stopit) && (sourceKeyIndex < srcCount); sourceKeyIndex++)
       {
         bool messageReturningHome = false;
         nsCString originalSrcFolderURI;
         srcFolder->GetURI(originalSrcFolderURI);
         nsCOMPtr<nsIMsgDBHdr> message;
         message = do_QueryElementAt(messages, sourceKeyIndex);
         nsMsgKey originalKey;
         if (message)
@@ -8766,17 +8766,17 @@ NS_IMETHODIMP nsImapMailFolder::RenameSu
   nsCOMPtr<nsISimpleEnumerator> enumerator;
   nsresult rv = oldFolder->GetSubFolders(getter_AddRefs(enumerator));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasMore;
   while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore)
   {
     nsCOMPtr<nsISupports> item;
-    if (enumerator->GetNext(getter_AddRefs(item)))
+    if (NS_FAILED(enumerator->GetNext(getter_AddRefs(item))))
       continue;
 
     nsCOMPtr<nsIMsgFolder> msgFolder(do_QueryInterface(item, &rv));
     if (NS_FAILED(rv))
       return rv;
 
     nsCOMPtr<nsIMsgImapMailFolder> folder(do_QueryInterface(msgFolder, &rv));
     if (NS_FAILED(rv))
--- a/mailnews/imap/src/nsImapOfflineSync.cpp
+++ b/mailnews/imap/src/nsImapOfflineSync.cpp
@@ -771,17 +771,17 @@ nsresult nsImapOfflineSync::ProcessNextO
       if (m_currentDB)
         m_currentDB->AddListener(this);
     }
 
     if (m_currentDB)
     {
       m_CurrentKeys.Clear();
       m_KeyIndex = 0;
-      if ((m_currentDB->ListAllOfflineOpIds(&m_CurrentKeys) != 0) || m_CurrentKeys.IsEmpty())
+      if (NS_FAILED(m_currentDB->ListAllOfflineOpIds(&m_CurrentKeys)) || m_CurrentKeys.IsEmpty())
       {
         ClearDB();
         folderInfo = nullptr; // can't hold onto folderInfo longer than db
         m_currentFolder->ClearFlag(nsMsgFolderFlags::OfflineEvents);
       }
       else
       {
         // trash any ghost msgs
@@ -824,17 +824,17 @@ nsresult nsImapOfflineSync::ProcessNextO
             }
           }
         }
         
         if (deletedGhostMsgs)
           m_currentFolder->SummaryChanged();
         
         m_CurrentKeys.Clear();
-        if ( (m_currentDB->ListAllOfflineOpIds(&m_CurrentKeys) != 0) || m_CurrentKeys.IsEmpty() )
+        if (NS_FAILED(m_currentDB->ListAllOfflineOpIds(&m_CurrentKeys)) || m_CurrentKeys.IsEmpty())
         {
           ClearDB();
           if (deletedGhostMsgs)
             deletedAllOfflineEventsInFolder = m_currentFolder;
         }
         else if (folderFlags & nsMsgFolderFlags::ImapBox)
         {
           // if pseudo offline, falls through to playing ops back.
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -1640,17 +1640,17 @@ bool nsImapProtocol::ProcessCurrentURL()
                     CommitCapability();
                   }
                 }
               }
             }
             if (NS_FAILED(rv))
             {
               nsAutoCString logLine("STARTTLS negotiation failed. Error 0x");
-              logLine.AppendInt(rv, 16);
+              logLine.AppendInt(static_cast<uint32_t>(rv), 16);
               Log("ProcessCurrentURL", nullptr, logLine.get());
               if (m_socketType == nsMsgSocketType::alwaysSTARTTLS)
               {
                 SetConnectionStatus(rv);        // stop netlib
                 m_transport->Close(rv);
               }
               else if (m_socketType == nsMsgSocketType::trySTARTTLS)
                 m_imapServerSink->UpdateTrySTARTTLSPref(false);
@@ -2282,21 +2282,20 @@ NS_IMETHODIMP nsImapProtocol::CanHandleU
               {
                 if (isBusy)
                   *hasToWait = true;
                 else
                   *aCanRunUrl = true;
               }
             }
           }
-#ifdef DEBUG_bienvenu1
-          printf("proposed url = %s folder for connection %s has To Wait = %s can run = %s\n",
-            folderNameForProposedUrl, curUrlFolderName.get(),
-            (*hasToWait) ? "TRUE" : "FALSE", (*aCanRunUrl) ? "TRUE" : "FALSE");
-#endif
+          PR_LOG(IMAP, PR_LOG_DEBUG,
+                 ("proposed url = %s folder for connection %s has To Wait = %s can run = %s",
+                  folderNameForProposedUrl, curSelectedUrlFolderName.get(),
+                  (*hasToWait) ? "TRUE" : "FALSE", (*aCanRunUrl) ? "TRUE" : "FALSE"));
           PR_FREEIF(folderNameForProposedUrl);
         }
       }
       else // *** jt - an authenticated state url can be run in either
         // authenticated or selected state
       {
         nsImapAction actionForRunningUrl;
 
@@ -4515,33 +4514,33 @@ uint32_t nsImapProtocol::CountMessagesIn
   return numberOfMessages;
 }
 
 
 // It would be really nice not to have to use this method nearly as much as we did
 // in 4.5 - we need to think about this some. Some of it may just go away in the new world order
 bool nsImapProtocol::DeathSignalReceived()
 {
-  nsresult returnValue = NS_OK;
   // ignore mock channel status if we've been pseudo interrupted
   // ### need to make sure we clear pseudo interrupted status appropriately.
   if (!GetPseudoInterrupted() && m_mockChannel)
   {
     nsCOMPtr<nsIRequest> request = do_QueryInterface(m_mockChannel);
     if (request)
+    {
+      nsresult returnValue;
       request->GetStatus(&returnValue);
-  }
-  if (NS_SUCCEEDED(returnValue)) // check the other way of cancelling.
-  {
-    ReentrantMonitorAutoEnter threadDeathMon(m_threadDeathMonitor);
-    // XXX Casting bool to nsresult
-    returnValue = static_cast<nsresult>(m_threadShouldDie);
-  }
-  // XXX Casting nsresult to bool
-  return static_cast<bool>(returnValue);
+      if (NS_FAILED(returnValue))
+        return false;
+    }
+  }
+
+  // Check the other way of cancelling.
+  ReentrantMonitorAutoEnter threadDeathMon(m_threadDeathMonitor);
+  return m_threadShouldDie;
 }
 
 NS_IMETHODIMP nsImapProtocol::ResetToAuthenticatedState()
 {
     GetServerStateParser().PreauthSetAuthenticatedState();
     return NS_OK;
 }
 
@@ -4712,17 +4711,17 @@ char* nsImapProtocol::CreateNewLineFromS
             AlertUserEventUsingId(TestFlag(IMAP_RECEIVED_GREETING)
             ? IMAP_SERVER_DISCONNECTED : IMAP_SERVER_DROPPED_CONNECTION);
           break;
         default:
             break;
     }
 
     nsAutoCString logMsg("clearing IMAP_CONNECTION_IS_OPEN - rv = ");
-    logMsg.AppendInt(rv, 16);
+    logMsg.AppendInt(static_cast<uint32_t>(rv), 16);
     Log("CreateNewLineFromSocket", nullptr, logMsg.get());
     ClearFlag(IMAP_CONNECTION_IS_OPEN);
     TellThreadToDie();
   }
   Log("CreateNewLineFromSocket", nullptr, newLine);
   SetConnectionStatus(newLine && numBytesInLine ? NS_OK : rv); // set > 0 if string is not null or empty
   return newLine;
 }
@@ -9483,18 +9482,18 @@ nsImapMockChannel::SetNotificationCallba
 NS_IMETHODIMP
 nsImapMockChannel::OnTransportStatus(nsITransport *transport, nsresult status,
                                      uint64_t progress, uint64_t progressMax)
 {
   if (NS_FAILED(m_cancelStatus) || (mLoadFlags & LOAD_BACKGROUND) || !m_url)
     return NS_OK;
 
   // these transport events should not generate any status messages
-  if (status == nsISocketTransport::STATUS_RECEIVING_FROM ||
-      status == nsISocketTransport::STATUS_SENDING_TO)
+  if (status == NS_NET_STATUS_RECEIVING_FROM ||
+      status == NS_NET_STATUS_SENDING_TO)
     return NS_OK;
 
   if (!mProgressEventSink)
   {
     NS_QueryNotificationCallbacks(mCallbacks, m_loadGroup, mProgressEventSink);
     if (!mProgressEventSink)
       return NS_OK;
   }
--- a/mailnews/import/eudora/src/nsEudoraFilters.cpp
+++ b/mailnews/import/eudora/src/nsEudoraFilters.cpp
@@ -155,17 +155,17 @@ bool nsEudoraFilters::RealImport()
   rv = LoadServers();
   if (NS_FAILED(rv))
   {
     IMPORT_LOG0("*** Error loading servers with filters\n");
     return false;
   }
 
   nsCOMPtr<nsILineInputStream> lineStream(do_QueryInterface(inputStream, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_SUCCESS(rv, false);
 
   nsCString     line;
   bool          more = true;
   nsAutoCString header;
   nsAutoCString verb;
   nsAutoString  name;
 
   // Windows Eudora filters files have a version header as a first line - just skip it
--- a/mailnews/import/eudora/src/nsEudoraMac.cpp
+++ b/mailnews/import/eudora/src/nsEudoraMac.cpp
@@ -127,17 +127,17 @@ bool nsEudoraMac::VerifyEudoraLocation(n
 {
   bool result = false;
   bool foundPref = false;
 
 
   bool hasMore;
   nsCOMPtr<nsISimpleEnumerator> directoryEnumerator;
   nsresult rv = (*pFolder)->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
-  NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_SUCCESS(rv, false);
 
   directoryEnumerator->HasMoreElements(&hasMore);
   nsCOMPtr <nsIFile> prefFile;
 
   int count = 0;
   OSType type, creator;
   while (hasMore && NS_SUCCEEDED(rv) && count < 2)
   {
@@ -780,17 +780,17 @@ bool nsEudoraMac::BuildPOPAccount(nsIMsg
       rv = accMgr->CreateAccount(getter_AddRefs(account));
       if (NS_SUCCEEDED(rv) && account)
       {
         rv = account->SetIncomingServer(in);
 
         IMPORT_LOG0("Created a new account and set the incoming server to the POP3 server.\n");
 
         nsCOMPtr<nsIPop3IncomingServer> pop3Server = do_QueryInterface(in, &rv);
-        NS_ENSURE_SUCCESS(rv,rv);
+        NS_ENSURE_SUCCESS(rv, false);
         pop3Server->SetLeaveMessagesOnServer(pStrs[kLeaveOnServerStr]->First() == 'Y' ? true : false);
 
         // Fiddle with the identities
         SetIdentities(accMgr, account, pStrs[kPopAccountNameStr]->get(), pStrs[kPopServerStr]->get(), pStrs);
         result = true;
         if (ppAccount)
           account->QueryInterface(NS_GET_IID(nsIMsgAccount), (void **)ppAccount);
       }
@@ -915,18 +915,18 @@ void nsEudoraMac::SetSmtpServer(nsIMsgAc
 
 nsresult nsEudoraMac::GetAttachmentInfo(const char *pFileName, nsIFile *pFile, nsCString& mimeType, nsCString& aAttachment)
 {
   mimeType.Truncate();
 
   // Sample attachment line
   // Internet:sandh.jpg (JPEG/JVWR) (0003C2E8)
 
-  OSType    type = '????';
-  OSType    creator = '????';
+  OSType    type = '?\??\?';
+  OSType    creator = '?\??\?';
   uint32_t  fNum = 0;
   int      i;
   PRUnichar  c;
 
   nsCString  str(pFileName);
   if (str.Length() > 22)
   {
     // try and extract the mac file info from the attachment line
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -1405,17 +1405,17 @@ nsMsgLocalMailFolder::SortMessagesBasedO
 bool nsMsgLocalMailFolder::CheckIfSpaceForCopy(nsIMsgWindow *msgWindow,
                                                  nsIMsgFolder *srcFolder,
                                                  nsISupports *srcSupports,
                                                  bool isMove,
                                                  int64_t totalMsgSize)
 {
   nsCOMPtr<nsIMsgPluggableStore> msgStore;
   nsresult rv = GetMsgStore(getter_AddRefs(msgStore));
-  NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_SUCCESS(rv, false);
   bool spaceAvailable;
   rv = msgStore->HasSpaceAvailable(this, totalMsgSize, &spaceAvailable);
   if (!spaceAvailable)
   {
     ThrowAlertMsg("mailboxTooLarge", msgWindow);
     if (isMove && srcFolder)
       srcFolder->NotifyFolderEvent(mDeleteOrMoveMsgFailedAtom);
     OnCopyCompleted(srcSupports, false);
@@ -3412,17 +3412,17 @@ nsMsgLocalMailFolder::OnMessageClassifie
         NS_ENSURE_SUCCESS(rv,rv);
 
         rv = copySvc->CopyMessages(this, messages, folder, true,
           /*nsIMsgCopyServiceListener* listener*/ nullptr, nullptr, false /*allowUndo*/);
         NS_ASSERTION(NS_SUCCEEDED(rv), "CopyMessages failed");
         if (NS_FAILED(rv))
         {
           nsAutoCString logMsg("failed to copy junk messages to junk folder rv = ");
-          logMsg.AppendInt(rv, 16);
+          logMsg.AppendInt(static_cast<uint32_t>(rv), 16);
           spamSettings->LogJunkString(logMsg.get());
         }
       }
     }
     int32_t numNewMessages;
     GetNumNewMessages(false, &numNewMessages);
     uint32_t length;
     messages->GetLength(&length);
--- a/mailnews/local/src/nsMailboxProtocol.cpp
+++ b/mailnews/local/src/nsMailboxProtocol.cpp
@@ -392,17 +392,17 @@ NS_IMETHODIMP nsMailboxProtocol::OnStopR
   nsMsgProtocol::OnStopRequest(request, ctxt, aStatus);
   return CloseSocket(); 
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////
 // End of nsIStreamListenerSupport
 //////////////////////////////////////////////////////////////////////////////////////////////
 
-int32_t nsMailboxProtocol::DoneReadingMessage()
+nsresult nsMailboxProtocol::DoneReadingMessage()
 {
   nsresult rv = NS_OK;
   // and close the article file if it was open....
   
   if (m_mailboxAction == nsIMailboxUrl::ActionSaveMessageToDisk && m_msgFileOutputStream)
     rv = m_msgFileOutputStream->Close();
   
   return rv;
--- a/mailnews/local/src/nsMailboxProtocol.h
+++ b/mailnews/local/src/nsMailboxProtocol.h
@@ -103,17 +103,17 @@ private:
   //            designed to re-act to the current "state". I've attempted to
   //            group them together based on functionality.
   ////////////////////////////////////////////////////////////////////////////////////////
 
   // When parsing a mailbox folder in chunks, this protocol state reads in the current chunk
   // and forwards it to the mailbox parser.
   int32_t ReadFolderResponse(nsIInputStream * inputStream, uint64_t sourceOffset, uint32_t length);
   int32_t ReadMessageResponse(nsIInputStream * inputStream, uint64_t sourceOffset, uint32_t length);
-  int32_t DoneReadingMessage();
+  nsresult DoneReadingMessage();
 
   ////////////////////////////////////////////////////////////////////////////////////////
   // End of Protocol Methods
   ////////////////////////////////////////////////////////////////////////////////////////
 };
 
 #endif  // nsMailboxProtocol_h___
 
--- a/mailnews/local/src/nsPop3Protocol.cpp
+++ b/mailnews/local/src/nsPop3Protocol.cpp
@@ -1304,57 +1304,55 @@ nsPop3Protocol::Error(int32_t err_code)
             }
         }
     }
     m_pop3ConData->next_state = POP3_ERROR_DONE;
     m_pop3ConData->pause_for_read = false;
     return -1;
 }
 
-nsresult nsPop3Protocol::SendData(const char * dataBuffer, bool aSuppressLogging)
+int32_t nsPop3Protocol::Pop3SendData(const char * dataBuffer, bool aSuppressLogging)
 {
   // remove any leftover bytes in the line buffer
   // this can happen if the last message line doesn't end with a (CR)LF
   // or a server sent two reply lines
   m_lineStreamBuffer->ClearBuffer();
 
   nsresult result = nsMsgProtocol::SendData(dataBuffer);
 
   if (!aSuppressLogging)
       PR_LOG(POP3LOGMODULE, PR_LOG_ALWAYS, ("SEND: %s", dataBuffer));
   else
       PR_LOG(POP3LOGMODULE, PR_LOG_ALWAYS, ("Logging suppressed for this command (it probably contained authentication information)"));
 
-  if (NS_SUCCEEDED(result)) // yeah this sucks...i need an error code....
+  if (NS_SUCCEEDED(result))
   {
     m_pop3ConData->pause_for_read = true;
     m_pop3ConData->next_state = POP3_WAIT_FOR_RESPONSE;
+    return 0;
   }
-  else
-  {
-    m_pop3ConData->next_state = POP3_ERROR_DONE;
-    PR_LOG(POP3LOGMODULE, PR_LOG_ALWAYS, ("SendData faild: %lx", result));
-  }
-
-  return result;
+
+  m_pop3ConData->next_state = POP3_ERROR_DONE;
+  PR_LOG(POP3LOGMODULE, PR_LOG_ALWAYS, ("Pop3SendData failed: %lx", result));
+  return -1;
 }
 
 /*
  * POP3 AUTH extension
  */
 
 int32_t nsPop3Protocol::SendAuth()
 {
   if(!m_pop3ConData->command_succeeded)
     return(Error(POP3_SERVER_ERROR));
 
   nsAutoCString command("AUTH" CRLF);
 
   m_pop3ConData->next_state_after_response = POP3_AUTH_RESPONSE;
-  return SendData(command.get());
+  return Pop3SendData(command.get());
 }
 
 int32_t nsPop3Protocol::AuthResponse(nsIInputStream* inputStream,
                              uint32_t length)
 {
     char * line;
     uint32_t ln = 0;
     nsresult rv;
@@ -1438,17 +1436,17 @@ int32_t nsPop3Protocol::SendCapa()
 {
     PR_LOG(POP3LOGMODULE, PR_LOG_MAX, ("SendCapa()"));
     if(!m_pop3ConData->command_succeeded)
         return(Error(POP3_SERVER_ERROR));
 
     nsAutoCString command("CAPA" CRLF);
 
     m_pop3ConData->next_state_after_response = POP3_CAPA_RESPONSE;
-    return SendData(command.get());
+    return Pop3SendData(command.get());
 }
 
 int32_t nsPop3Protocol::CapaResponse(nsIInputStream* inputStream,
                              uint32_t length)
 {
     char * line;
     uint32_t ln = 0;
 
@@ -1558,17 +1556,18 @@ int32_t nsPop3Protocol::SendTLSResponse(
 {
   // only tear down our existing connection and open a new one if we received
   // a +OK response from the pop server after we issued the STLS command
   nsresult rv = NS_OK;
   if (m_pop3ConData->command_succeeded)
   {
       nsCOMPtr<nsISupports> secInfo;
       nsCOMPtr<nsISocketTransport> strans = do_QueryInterface(m_transport, &rv);
-      if (NS_FAILED(rv)) return rv;
+      if (NS_FAILED(rv))
+        return -1;
 
       rv = strans->GetSecurityInfo(getter_AddRefs(secInfo));
 
       if (NS_SUCCEEDED(rv) && secInfo)
       {
           nsCOMPtr<nsISSLSocketControl> sslControl = do_QueryInterface(secInfo, &rv);
 
           if (NS_SUCCEEDED(rv) && sslControl)
@@ -1587,24 +1586,24 @@ int32_t nsPop3Protocol::SendTLSResponse(
         POP3_AUTH_MECH_UNDEFINED |
         POP3_HAS_AUTH_USER |                // should be always there
         POP3_GURL_UNDEFINED |
         POP3_UIDL_UNDEFINED |
         POP3_TOP_UNDEFINED |
         POP3_XTND_XLST_UNDEFINED |
         preservedCapFlags;
       m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags);
-      return rv;
+      return 0;
     }
   }
 
   ClearFlag(POP3_HAS_STLS);
   m_pop3ConData->next_state = POP3_PROCESS_AUTH;
 
-  return rv;
+  return (NS_SUCCEEDED(rv) ? 0 : -1);
 }
 
 void nsPop3Protocol::InitPrefAuthMethods(int32_t authMethodPrefValue)
 {
   // for m_prefAuthMethods, using the same flags as server capablities.
   switch (authMethodPrefValue)
   {
     case nsMsgAuthMethod::none:
@@ -1730,17 +1729,17 @@ int32_t nsPop3Protocol::ProcessAuth()
       if(TestCapFlag(POP3_HAS_STLS))
       {
         if (m_socketType == nsMsgSocketType::trySTARTTLS ||
             m_socketType == nsMsgSocketType::alwaysSTARTTLS)
         {
             nsAutoCString command("STLS" CRLF);
 
             m_pop3ConData->next_state_after_response = POP3_TLS_RESPONSE;
-            return SendData(command.get());
+            return Pop3SendData(command.get());
         }
       }
       else if (m_socketType == nsMsgSocketType::alwaysSTARTTLS)
       {
           m_pop3ConData->next_state = POP3_ERROR_DONE;
           return(Error(NS_ERROR_COULD_NOT_CONNECT_VIA_TLS));
       }
     }
@@ -1938,17 +1937,17 @@ int32_t nsPop3Protocol::NextAuthStep()
 // so we've to start here and continue in SendUsername if the server
 // responds + to "AUTH LOGIN"
 int32_t nsPop3Protocol::AuthLogin()
 {
     nsAutoCString command("AUTH LOGIN" CRLF);
     m_pop3ConData->next_state_after_response = POP3_AUTH_LOGIN_RESPONSE;
     m_pop3ConData->pause_for_read = true;
 
-    return SendData(command.get());
+    return Pop3SendData(command.get());
 }
 
 int32_t nsPop3Protocol::AuthLoginResponse()
 {
     // need the test to be here instead in NextAuthStep() to
     // differentiate between command AUTH LOGIN failed and
     // sending username using LOGIN mechanism failed.
     if (!m_pop3ConData->command_succeeded)
@@ -1970,17 +1969,17 @@ int32_t nsPop3Protocol::AuthLoginRespons
 // responds + to "AUTH NTLM"
 int32_t nsPop3Protocol::AuthNtlm()
 {
     nsAutoCString command (m_currentAuthMethod == POP3_HAS_AUTH_MSN
           ? "AUTH MSN" CRLF : "AUTH NTLM" CRLF);
     m_pop3ConData->next_state_after_response = POP3_AUTH_NTLM_RESPONSE;
     m_pop3ConData->pause_for_read = true;
 
-    return SendData(command.get());
+    return Pop3SendData(command.get());
 }
 
 int32_t nsPop3Protocol::AuthNtlmResponse()
 {
     // need the test to be here instead in NextAuthStep() to
     // differentiate between command AUTH NTLM failed and
     // sending username using NTLM mechanism failed.
     if (!m_pop3ConData->command_succeeded)
@@ -2008,63 +2007,63 @@ int32_t nsPop3Protocol::AuthGSSAPI()
         nsresult rv;
         server->GetRealHostName(hostName);
         service.Append(hostName);
         rv = DoGSSAPIStep1(service.get(), m_username.get(), cmd);
         if (NS_SUCCEEDED(rv)) {
             m_GSSAPICache.Assign(cmd);
             m_pop3ConData->next_state_after_response = POP3_AUTH_GSSAPI_FIRST;
             m_pop3ConData->pause_for_read = true;
-            return SendData("AUTH GSSAPI" CRLF);
+            return Pop3SendData("AUTH GSSAPI" CRLF);
         }
     }
 
     MarkAuthMethodAsFailed(POP3_HAS_AUTH_GSSAPI);
     m_pop3ConData->next_state = POP3_PROCESS_AUTH;
     m_pop3ConData->pause_for_read = false;
-    return NS_OK;
+    return 0;
 }
 
 int32_t nsPop3Protocol::AuthGSSAPIResponse(bool first)
 {
     if (!m_pop3ConData->command_succeeded)
     {
         if (first)
             m_GSSAPICache.Truncate();
         MarkAuthMethodAsFailed(POP3_HAS_AUTH_GSSAPI);
         m_pop3ConData->next_state = POP3_PROCESS_AUTH;
         m_pop3ConData->pause_for_read = false;
-        return NS_OK;
+        return 0;
     }
 
-    nsresult rv;
+    int32_t result;
 
     m_pop3ConData->next_state_after_response = POP3_AUTH_GSSAPI_STEP;
     m_pop3ConData->pause_for_read = true;
 
     if (first) {
         m_GSSAPICache += CRLF;
-        rv = SendData(m_GSSAPICache.get());
+        result = Pop3SendData(m_GSSAPICache.get());
         m_GSSAPICache.Truncate();
     }
     else {
         nsAutoCString cmd;
         PR_LOG(POP3LOGMODULE, PR_LOG_DEBUG, ("GSSAPI step 2"));
-        rv = DoGSSAPIStep2(m_commandResponse, cmd);
+        nsresult rv = DoGSSAPIStep2(m_commandResponse, cmd);
         if (NS_FAILED(rv))
             cmd = "*";
         if (rv == NS_SUCCESS_AUTH_FINISHED) {
             m_pop3ConData->next_state_after_response = POP3_NEXT_AUTH_STEP;
             m_password_already_sent = true;
         }
         cmd += CRLF;
-        rv = SendData(cmd.get());
+        result = Pop3SendData(cmd.get());
     }
 
-    return rv;
+    return result;
 }
 
 int32_t nsPop3Protocol::SendUsername()
 {
     PR_LOG(POP3LOGMODULE, PR_LOG_MAX, ("SendUsername()"));
     if(m_username.IsEmpty())
       return(Error(POP3_USERNAME_UNDEFINED));
 
@@ -2110,17 +2109,17 @@ int32_t nsPop3Protocol::SendUsername()
     }
 
     cmd += CRLF;
 
     m_pop3ConData->next_state_after_response = POP3_NEXT_AUTH_STEP;
 
     m_pop3ConData->pause_for_read = true;
 
-    return SendData(cmd.get());
+    return Pop3SendData(cmd.get());
 }
 
 int32_t nsPop3Protocol::SendPassword()
 {
   PR_LOG(POP3LOGMODULE, PR_LOG_MAX, ("SendPassword()"));
   if (m_username.IsEmpty())
     return(Error(POP3_USERNAME_UNDEFINED));
 
@@ -2266,33 +2265,33 @@ int32_t nsPop3Protocol::SendPassword()
   //m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags);
 
   m_pop3ConData->next_state_after_response = POP3_NEXT_AUTH_STEP;
 
   m_pop3ConData->pause_for_read = true;
 
   m_password_already_sent = true;
   m_lastPasswordSent = m_passwordResult;
-  return SendData(cmd.get(), true);
+  return Pop3SendData(cmd.get(), true);
 }
 
 int32_t nsPop3Protocol::SendStatOrGurl(bool sendStat)
 {
   nsAutoCString cmd;
   if (sendStat)
   {
     cmd  = "STAT" CRLF;
     m_pop3ConData->next_state_after_response = POP3_GET_STAT;
   }
   else
   {
     cmd = "GURL" CRLF;
     m_pop3ConData->next_state_after_response = POP3_GURL_RESPONSE;
   }
-  return SendData(cmd.get());
+  return Pop3SendData(cmd.get());
 }
 
 
 int32_t
 nsPop3Protocol::SendStat()
 {
   return SendStatOrGurl(true);
 }
@@ -2437,17 +2436,17 @@ int32_t nsPop3Protocol::SendList()
 
 
     m_pop3ConData->msg_info = (Pop3MsgInfo *)
       PR_CALLOC(sizeof(Pop3MsgInfo) * m_pop3ConData->number_of_messages);
     if (!m_pop3ConData->msg_info)
         return(MK_OUT_OF_MEMORY);
     m_pop3ConData->next_state_after_response = POP3_GET_LIST;
     m_listpos = 0;
-    return SendData("LIST" CRLF);
+    return Pop3SendData("LIST" CRLF);
 }
 
 
 
 int32_t
 nsPop3Protocol::GetList(nsIInputStream* inputStream,
                         uint32_t length)
 {
@@ -2611,17 +2610,17 @@ int32_t nsPop3Protocol::HandleNoUidListA
 */
 int32_t nsPop3Protocol::SendXtndXlstMsgid()
 {
   if (TestCapFlag(POP3_HAS_XTND_XLST | POP3_XTND_XLST_UNDEFINED))
   {
     m_pop3ConData->next_state_after_response = POP3_GET_XTND_XLST_MSGID;
     m_pop3ConData->pause_for_read = true;
     m_listpos = 0;
-    return SendData("XTND XLST Message-Id" CRLF);
+    return Pop3SendData("XTND XLST Message-Id" CRLF);
   }
   else
     return HandleNoUidListAvailable();
 }
 
 
 /* km
  *
@@ -2694,17 +2693,17 @@ nsPop3Protocol::GetXtndXlstMsgid(nsIInpu
   char *newStr = line;
   char *token = NS_strtok(" ", &newStr);  // msg num
   if (token)
   {
     int32_t msg_num = atol(token);
     if (++m_listpos <= m_pop3ConData->number_of_messages)
     {
       NS_strtok(" ", &newStr);  // eat message ID token
-      char *uid = NS_strtok(" ", &newStr); // not really a UID but a unique token -km
+      const char *uid = NS_strtok(" ", &newStr); // not really a UID but a unique token -km
       if (!uid)
         /* This is bad.  The server didn't give us a UIDL for this message.
         I've seen this happen when somehow the mail spool has a message
         that contains a header that reads "X-UIDL: \n".  But how that got
         there, I have no idea; must be a server bug.  Or something. */
         uid = "";
 
       // seeking right entry, but try the one that should it be first
@@ -2737,17 +2736,17 @@ nsPop3Protocol::GetXtndXlstMsgid(nsIInpu
 
 int32_t nsPop3Protocol::SendUidlList()
 {
     if (TestCapFlag(POP3_HAS_UIDL | POP3_UIDL_UNDEFINED))
     {
       m_pop3ConData->next_state_after_response = POP3_GET_UIDL_LIST;
       m_pop3ConData->pause_for_read = true;
       m_listpos = 0;
-      return SendData("UIDL" CRLF);
+      return Pop3SendData("UIDL" CRLF);
     }
     else
       return SendXtndXlstMsgid();
 }
 
 
 int32_t nsPop3Protocol::GetUidlList(nsIInputStream* inputStream,
                             uint32_t length)
@@ -2809,17 +2808,17 @@ int32_t nsPop3Protocol::GetUidlList(nsII
 
     char *newStr = line;
     char *token = NS_strtok(" ", &newStr);  // msg num
     if (token)
     {
       int32_t msg_num = atol(token);
       if (++m_listpos <= m_pop3ConData->number_of_messages)
       {
-        char *uid = NS_strtok(" ", &newStr); // UID
+        const char *uid = NS_strtok(" ", &newStr); // UID
         if (!uid)
           /* This is bad.  The server didn't give us a UIDL for this message.
              I've seen this happen when somehow the mail spool has a message
              that contains a header that reads "X-UIDL: \n".  But how that got
              there, I have no idea; must be a server bug.  Or something. */
           uid = "";
 
         // seeking right entry, but try the one that should it be first
@@ -2968,21 +2967,23 @@ int32_t nsPop3Protocol::GetMsg()
     {
       nsresult rv;
       int64_t mailboxSpaceLeft = 0;
       nsCOMPtr <nsIMsgFolder> folder;
       nsCOMPtr <nsIFile> path;
 
       // Get the path to the current mailbox
       //
-      NS_ENSURE_TRUE(m_nsIPop3Sink, NS_ERROR_UNEXPECTED);
+      NS_ENSURE_TRUE(m_nsIPop3Sink, -1);
       rv = m_nsIPop3Sink->GetFolder(getter_AddRefs(folder));
-      if (NS_FAILED(rv)) return rv;
+      if (NS_FAILED(rv))
+        return -1;
       rv = folder->GetFilePath(getter_AddRefs(path));
-      if (NS_FAILED(rv)) return rv;
+      if (NS_FAILED(rv))
+        return -1;
 
       // call GetDiskSpaceAvailable on the directory
       nsCOMPtr <nsIFile> parent;
       path->GetParent(getter_AddRefs(parent));
       rv = parent->GetDiskSpaceAvailable(&mailboxSpaceLeft);
       if (NS_FAILED(rv))
       {
         // The call to GetDiskSpaceAvailable FAILED!
@@ -3148,32 +3149,32 @@ int32_t nsPop3Protocol::SendTop()
    {
      m_pop3ConData->next_state_after_response = POP3_TOP_RESPONSE;
      m_pop3ConData->cur_msg_size = -1;
 
      /* zero the bytes received in message in preparation for
      * the next
      */
      m_bytesInMsgReceived = 0;
-     status = SendData(cmd);
+     status = Pop3SendData(cmd);
    }
    PR_Free(cmd);
    return status;
 }
 
 /* send the xsender command
  */
 int32_t nsPop3Protocol::SendXsender()
 {
   char * cmd = PR_smprintf("XSENDER %ld" CRLF, m_pop3ConData->msg_info[m_pop3ConData->last_accessed_msg].msgnum);
   int32_t status = -1;
   if (cmd)
   {
     m_pop3ConData->next_state_after_response = POP3_XSENDER_RESPONSE;
-    status = SendData(cmd);
+    status = Pop3SendData(cmd);
     PR_Free(cmd);
   }
   return status;
 }
 
 int32_t nsPop3Protocol::XsenderResponse()
 {
     m_pop3ConData->seenFromHeader = false;
@@ -3229,17 +3230,17 @@ nsPop3Protocol::SendRetr()
                           m_pop3ConData->really_new_messages,
                           finalString);
 
       NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't format string");
       if (m_statusFeedback)
         m_statusFeedback->ShowStatusString(finalString);
     }
 
-    status = SendData(cmd);
+    status = Pop3SendData(cmd);
   } // if cmd
   PR_Free(cmd);
   return status;
 }
 
 /* digest the message
  */
 int32_t
@@ -3590,17 +3591,17 @@ int32_t nsPop3Protocol::SendDele()
     /* increment the last accessed message since we have now read it
      */
     char * cmd = PR_smprintf("DELE %ld" CRLF, m_pop3ConData->msg_info[m_pop3ConData->last_accessed_msg].msgnum);
     m_pop3ConData->last_accessed_msg++;
     int32_t status = -1;
     if (cmd)
     {
       m_pop3ConData->next_state_after_response = POP3_DELE_RESPONSE;
-      status = SendData(cmd);
+      status = Pop3SendData(cmd);
     }
     PR_Free(cmd);
     return status;
 }
 
 int32_t nsPop3Protocol::DeleResponse()
 {
   Pop3UidlHost *host = NULL;
@@ -4009,17 +4010,17 @@ nsresult nsPop3Protocol::ProcessProtocol
                                               m_pop3ConData->really_new_messages,
                                               statusString);
             if (NS_SUCCEEDED(rv))
               UpdateStatusWithString(statusString.get());
           }
         }
       }
 
-      status = SendData("QUIT" CRLF);
+      status = Pop3SendData("QUIT" CRLF);
       m_pop3ConData->next_state = POP3_WAIT_FOR_RESPONSE;
       m_pop3ConData->next_state_after_response = POP3_QUIT_RESPONSE;
       break;
 
     case POP3_QUIT_RESPONSE:
       if(m_pop3ConData->command_succeeded)
       {
       /*  the QUIT succeeded.  We can now flush the state in popstate.dat which
--- a/mailnews/local/src/nsPop3Protocol.h
+++ b/mailnews/local/src/nsPop3Protocol.h
@@ -306,17 +306,17 @@ private:
   int32_t  m_totalFolderSize;
   int32_t  m_totalDownloadSize; /* Number of bytes we're going to
                                     download.  Might be much less
                                     than the total_folder_size. */
   int32_t m_totalBytesReceived; // total # bytes received for the connection
 
   virtual nsresult ProcessProtocolState(nsIURI * url, nsIInputStream * inputStream,
                                         uint64_t sourceOffset, uint32_t length);
-  virtual nsresult SendData(const char * dataBuffer, bool aSuppressLogging = false);
+  virtual int32_t Pop3SendData(const char * dataBuffer, bool aSuppressLogging = false);
 
   virtual const char* GetType() {return "pop3";}
 
   nsCOMPtr<nsIURI> m_url;
   nsCOMPtr<nsIPop3Sink> m_nsIPop3Sink;
   nsCOMPtr<nsIPop3IncomingServer> m_pop3Server;
 
   nsMsgLineStreamBuffer   * m_lineStreamBuffer; // used to efficiently extract lines from the incoming data stream
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -435,17 +435,17 @@ CreateCompositionFields(const char      
 
   return rv;
 }
 
 static int
 dummy_file_write( char *buf, int32_t size, void *fileHandle )
 {
   if (!fileHandle)
-    return NS_ERROR_FAILURE;
+    return -1;
 
   nsIOutputStream  *tStream = (nsIOutputStream *) fileHandle;
   uint32_t bytesWritten;
   tStream->Write(buf, size, &bytesWritten);
   return (int) bytesWritten;
 }
 
 static int
--- a/mailnews/mime/src/mimehdrs.cpp
+++ b/mailnews/mime/src/mimehdrs.cpp
@@ -608,20 +608,24 @@ MimeHeaders_write_all_headers (MimeHeade
       nsAutoCString convertedStr;
       if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUTF16(hdr_value),
                        convertedStr)))
       {
         hdr_value = convertedStr;
       }
     }
 
-    if (attachment)
-      status = mimeEmitterAddAttachmentField(opt, name.get(), hdr_value.get());
-    else
-      status = mimeEmitterAddHeaderField(opt, name.get(), hdr_value.get());
+    if (attachment) {
+      if (NS_FAILED(mimeEmitterAddAttachmentField(opt, name.get(), hdr_value.get())))
+        status = -1;
+    }
+    else {
+      if (NS_FAILED(mimeEmitterAddHeaderField(opt, name.get(), hdr_value.get())))
+        status = -1;
+    }
 
     if (status < 0) return status;
     if (!wrote_any_p)
       wrote_any_p = (status > 0);
   }
   mimeEmitterAddAllHeaders(opt, hdrs->all_headers, hdrs->all_headers_fp);
   PR_FREEIF(charset);
 
--- a/mailnews/mime/src/mimemalt.cpp
+++ b/mailnews/mime/src/mimemalt.cpp
@@ -188,17 +188,17 @@ MimeMultipartAlternative_flush_children(
     6. Not finished, and the cache contains one non-displayable body:
        create it with output off.
   */
   MimeMultipartAlternative *malt = (MimeMultipartAlternative *) obj;
   bool have_displayable, do_flush, do_display;
 
   /* Case 1 */
   if (! malt->pending_parts)
-    return NS_OK;
+    return 0;
 
   have_displayable =
     MimeMultipartAlternative_display_part_p(obj, malt->buffered_hdrs[0]);
   
   if (finished && have_displayable) {
     /* Case 2 */
     do_flush = true;
     do_display = true;
@@ -220,32 +220,32 @@ MimeMultipartAlternative_flush_children(
   }
   else if (! finished && ! have_displayable) {
     /* Case 6 */
     do_flush = true;
     do_display = false;
   }
   else {
     NS_ERROR("mimemalt.cpp: logic error in flush_children");
-    return NS_ERROR_FAILURE;
+    return -1;
   }
   
   if (do_flush) {
     int32_t i;
     for (i = 0; i < malt->pending_parts; i++) {
       MimeMultipartAlternative_display_cached_part(obj,
                                                    malt->buffered_hdrs[i],
                                                    malt->part_buffers[i],
                                                    do_display && (i == 0));
       MimeHeaders_free(malt->buffered_hdrs[i]);
       MimePartBufferDestroy(malt->part_buffers[i]);
     }
     malt->pending_parts = 0;
   }
-  return NS_OK;
+  return 0;
 }
 
 static int
 MimeMultipartAlternative_parse_eof (MimeObject *obj, bool abort_p)
 {
   int status = 0;
 
   if (obj->closed_p) return 0;
--- a/mailnews/mime/src/mimemrel.cpp
+++ b/mailnews/mime/src/mimemrel.cpp
@@ -387,28 +387,28 @@ MakeAbsoluteURL(char *base_url, char *re
     if (!relative_url)
       return nullptr;
 
     NS_MsgSACopy(&retString, relative_url);
     return retString;
   }
 
   nsresult err = nsMimeNewURI(&base, base_url, nullptr);
-  if (err != NS_OK)
+  if (NS_FAILED(err))
     return nullptr;
 
   nsAutoCString spec;
 
   nsIURI    *url = nullptr;
   err = nsMimeNewURI(&url, relative_url, base);
-  if (err != NS_OK)
+  if (NS_FAILED(err))
     goto done;
 
   err = url->GetSpec(spec);
-  if (err)
+  if (NS_FAILED(err))
   {
     retString = nullptr;
     goto done;
   }
   retString = ToNewCString(spec);
 
 done:
   NS_IF_RELEASE(url);
@@ -652,21 +652,21 @@ MimeMultipartRelated_parse_child_line (M
 
   nsresult rv;
   /* Ok, if at this point we still don't have either kind of buffer, try and
      make a file buffer. */
   if (!relobj->head_buffer && !relobj->file_buffer)
   {
     nsCOMPtr <nsIFile> file;
     rv = nsMsgCreateTempFile("nsma", getter_AddRefs(file));
-    NS_ENSURE_SUCCESS(rv, rv);
+    NS_ENSURE_SUCCESS(rv, -1);
     relobj->file_buffer = do_QueryInterface(file);
 
     rv = MsgNewBufferedFileOutputStream(getter_AddRefs(relobj->output_file_stream), relobj->file_buffer, PR_WRONLY | PR_CREATE_FILE, 00600);
-    NS_ENSURE_SUCCESS(rv, rv);
+    NS_ENSURE_SUCCESS(rv, -1);
   }
 
   PR_ASSERT(relobj->head_buffer || relobj->output_file_stream);
 
 
   /* If this line will fit in the memory buffer, put it there.
    */
   if (relobj->head_buffer &&
@@ -679,30 +679,28 @@ MimeMultipartRelated_parse_child_line (M
     /* If the file isn't open yet, open it, and dump the memory buffer
        to it. */
     if (!relobj->output_file_stream)
     {
       if (!relobj->file_buffer)
       {
         nsCOMPtr <nsIFile> file;
         rv = nsMsgCreateTempFile("nsma", getter_AddRefs(file));
-        NS_ENSURE_SUCCESS(rv, rv);
+        NS_ENSURE_SUCCESS(rv, -1);
         relobj->file_buffer = do_QueryInterface(file);
       }
 
       nsresult rv = MsgNewBufferedFileOutputStream(getter_AddRefs(relobj->output_file_stream), relobj->file_buffer, PR_WRONLY | PR_CREATE_FILE, 00600);
-      NS_ENSURE_SUCCESS(rv, rv);
+      NS_ENSURE_SUCCESS(rv, -1);
 
       if (relobj->head_buffer && relobj->head_buffer_fp)
       {
         uint32_t bytesWritten;
-        status = relobj->output_file_stream->Write(relobj->head_buffer,
-                                                   relobj->head_buffer_fp,
-                                                   &bytesWritten);
-        if (bytesWritten < relobj->head_buffer_fp)
+        rv = relobj->output_file_stream->Write(relobj->head_buffer, relobj->head_buffer_fp, &bytesWritten);
+        if (NS_FAILED(rv) || (bytesWritten < relobj->head_buffer_fp))
           return MIME_UNABLE_TO_OPEN_TMP_FILE;
       }
 
       PR_FREEIF(relobj->head_buffer);
       relobj->head_buffer_fp = 0;
       relobj->head_buffer_size = 0;
     }
 
--- a/mailnews/mime/src/mimepbuf.cpp
+++ b/mailnews/mime/src/mimepbuf.cpp
@@ -166,17 +166,17 @@ MimePartBufferWrite (MimePartBufferData 
   if (!data->part_buffer && !data->file_buffer)
   {
     nsCOMPtr <nsIFile> tmpFile;
     nsresult rv = nsMsgCreateTempFile("nsma", getter_AddRefs(tmpFile));
     NS_ENSURE_SUCCESS(rv, MIME_UNABLE_TO_OPEN_TMP_FILE);
     data->file_buffer = do_QueryInterface(tmpFile);
 
     rv = MsgNewBufferedFileOutputStream(getter_AddRefs(data->output_file_stream), data->file_buffer, PR_WRONLY | PR_CREATE_FILE, 00600);
-    NS_ENSURE_SUCCESS(rv, rv);
+    NS_ENSURE_SUCCESS(rv, MIME_UNABLE_TO_OPEN_TMP_FILE);
   }
 
   NS_ASSERTION(data->part_buffer || data->output_file_stream, "no part_buffer or file_stream");
 
   /* If this buf will fit in the memory buffer, put it there.
     */
   if (data->part_buffer &&
       data->part_buffer_fp + size < data->part_buffer_size)
@@ -206,17 +206,17 @@ MimePartBufferWrite (MimePartBufferData 
       rv = MsgNewBufferedFileOutputStream(getter_AddRefs(data->output_file_stream), data->file_buffer, PR_WRONLY | PR_CREATE_FILE, 00600);
       NS_ENSURE_SUCCESS(rv, MIME_UNABLE_TO_OPEN_TMP_FILE);
 
       if (data->part_buffer && data->part_buffer_fp)
       {
         uint32_t bytesWritten;
         nsresult rv = data->output_file_stream->Write(data->part_buffer,
                                                  data->part_buffer_fp, &bytesWritten);
-        NS_ENSURE_SUCCESS(rv, rv);
+        NS_ENSURE_SUCCESS(rv, MIME_ERROR_WRITING_FILE);
       }
 
       PR_FREEIF(data->part_buffer);
       data->part_buffer_fp = 0;
       data->part_buffer_size = 0;
     }
 
     /* Dump this buf to the file. */
--- a/mailnews/mime/src/mimetpfl.cpp
+++ b/mailnews/mime/src/mimetpfl.cpp
@@ -375,17 +375,17 @@ MimeInlineTextPlainFlowed_parse_line (co
       // escaping (very important), eventually recognizing etc.
       rv = conv->ScanTXT(lineSource.get(), whattodo, getter_Copies(lineResult));
       NS_ENSURE_SUCCESS(rv, -1);
     }
   }
   else
   {
     CopyUTF8toUTF16(nsDependentCString(line, length), lineResult);
-    status = NS_OK;
+    status = 0;
   }
 
   nsAutoCString preface;
 
   /* Correct number of blockquotes */
   int32 quoteleveldiff=linequotelevel - exdata->quotelevel;
   if((quoteleveldiff != 0) && flowed && exdata->inflow) {
     // From RFC 2646 4.5
@@ -462,17 +462,17 @@ MimeInlineTextPlainFlowed_parse_line (co
     { // convert back to mailCharset before writing.
       rv = nsMsgI18NConvertFromUnicode(mailCharset, lineResult2, outString);
       NS_ENSURE_SUCCESS(rv, -1);
     }
     status = MimeObject_write(obj, outString.get(), outString.Length(), true);
     return status;
   }
   else
-    return NS_OK;
+    return 0;
 }
 
 
 /**
  * Maintains a small state machine with three states. "Not in tag",
  * "In tag, but not in quote" and "In quote inside a tag". It also
  * remembers what character started the quote (" or '). The state
  * variables are kept outside this function and are included as
--- a/mailnews/mime/src/mimetpla.cpp
+++ b/mailnews/mime/src/mimetpla.cpp
@@ -431,17 +431,17 @@ MimeInlineTextPlain_parse_line (const ch
                                          lineResultUnichar, outString);
         NS_ENSURE_SUCCESS(rv, -1);
       }
 
       status = MimeObject_write(obj, outString.get(), outString.Length(), true);
     }
     else
     {
-      status = NS_OK;
+      status = 0;
     }
   }
   else
   {
     status = MimeObject_write(obj, line, length, true);
   }
 
   return status;
--- a/mailnews/mime/src/nsMsgHeaderParser.cpp
+++ b/mailnews/mime/src/nsMsgHeaderParser.cpp
@@ -398,23 +398,23 @@ static int msg_parse_Header_addresses (c
   if (!line)
     return -1;
   line_length = strlen(line);
   if (line_length == 0)
     return 0;
 
   name_buf = (char *)PR_Malloc(line_length * 2 + 10);
   if (!name_buf)
-    return NS_ERROR_OUT_OF_MEMORY;
+    return -1;
 
   addr_buf = (char *)PR_Malloc(line_length * 2 + 10);
   if (!addr_buf)
   {
     FREEIF(name_buf);
-    return NS_ERROR_OUT_OF_MEMORY;
+    return -1;
   }
 
   line_end = line;
   addr_out = addr_buf;
   name_out = name_buf;
   name_start = name_buf;
   addr_start = addr_buf;
   this_start = line;
--- a/mailnews/news/src/nsNntpIncomingServer.cpp
+++ b/mailnews/news/src/nsNntpIncomingServer.cpp
@@ -1199,24 +1199,26 @@ nsNntpIncomingServer::Unsubscribe(const 
   // since we've unsubscribed to a newsgroup, the newsrc needs to be written out
   rv = SetNewsrcHasChanged(true);
   if (NS_FAILED(rv))
     return rv;
 
   return NS_OK;
 }
 
-int32_t
+nsresult
 nsNntpIncomingServer::HandleLine(const char* line, uint32_t line_size)
 {
   NS_ASSERTION(line, "line is null");
-  if (!line) return 0;
+  if (!line)
+    return NS_OK;
 
   // skip blank lines and comments
-  if (line[0] == '#' || line[0] == '\0') return 0;
+  if (line[0] == '#' || line[0] == '\0')
+    return NS_OK;
   // ###TODO - make this truly const, maybe pass in an nsCString &
 
   if (mHasSeenBeginGroups) {
     // v1 hostinfo files had additional data fields delimited by commas.
     // with v2 hostinfo files, the additional data fields are removed.
     char *commaPos = (char *) PL_strchr(line,',');
     if (commaPos) *commaPos = 0;
 
@@ -1246,17 +1248,17 @@ nsNntpIncomingServer::HandleLine(const c
       } else if (PL_strcmp(line, "uniqueid") == 0) {
         mUniqueId = strtol(equalPos, nullptr, 16);
       } else if (PL_strcmp(line, "version") == 0) {
         mVersion = strtol(equalPos, nullptr, 16);
       }
     }
   }
 
-  return 0;
+  return NS_OK;
 }
 
 nsresult
 nsNntpIncomingServer::AddGroupOnServer(const nsACString &aName)
 {
   mGroupsOnServer.AppendElement(aName);
   return NS_OK;
 }
--- a/mailnews/news/src/nsNntpIncomingServer.h
+++ b/mailnews/news/src/nsNntpIncomingServer.h
@@ -53,17 +53,17 @@ public:
     NS_IMETHOD CloseCachedConnections();
     NS_IMETHOD PerformBiff(nsIMsgWindow *aMsgWindow);
     NS_IMETHOD PerformExpand(nsIMsgWindow *aMsgWindow);
     NS_IMETHOD OnUserOrHostNameChanged(const nsACString& oldName,
                                        const nsACString& newName,
                                        bool hostnameChanged);
 
     // for nsMsgLineBuffer
-    virtual int32_t HandleLine(const char *line, uint32_t line_size);
+    virtual nsresult HandleLine(const char *line, uint32_t line_size);
 
     // override to clear all passwords associated with server
     NS_IMETHODIMP ForgetPassword();
     NS_IMETHOD GetCanSearchMessages(bool *canSearchMessages);
     NS_IMETHOD GetOfflineSupportLevel(int32_t *aSupportLevel);
     NS_IMETHOD GetDefaultCopiesAndFoldersPrefsToServer(bool *aCopiesAndFoldersOnServer);
     NS_IMETHOD GetCanCreateFoldersOnServer(bool *aCanCreateFoldersOnServer);
     NS_IMETHOD GetCanFileMessagesOnServer(bool *aCanFileMessagesOnServer);