Bug 793865 - mark function arguments as nsMsgKey where appropriate to better show intended use. r=rkent
authoraceman <acelists@atlas.sk>
Tue, 11 Nov 2014 15:40:00 +0100
changeset 21463 34afccc6f8f755638c6fe79ed257a34df37a8050
parent 21462 4da6759d4f47791569467e0a0d8c1151ff0ae0dc
child 21464 37bc8ee327c67b32cb63fdae536d359287e5fcd4
push id1305
push usermbanner@mozilla.com
push dateMon, 23 Feb 2015 19:48:12 +0000
treeherdercomm-beta@3ae4f13858fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrkent
bugs793865
Bug 793865 - mark function arguments as nsMsgKey where appropriate to better show intended use. r=rkent
mailnews/base/public/nsIMsgCopyServiceListener.idl
mailnews/base/search/src/nsMsgFilterService.cpp
mailnews/base/src/nsMessenger.cpp
mailnews/base/src/nsMessengerUnixIntegration.cpp
mailnews/base/src/nsMsgFolderCompactor.cpp
mailnews/base/src/nsMsgFolderCompactor.h
mailnews/base/src/nsMsgSearchDBView.cpp
mailnews/base/src/nsMsgXFViewThread.cpp
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/base/util/nsMsgDBFolder.h
mailnews/base/util/nsMsgUtils.cpp
mailnews/base/util/nsMsgUtils.h
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgCopy.cpp
mailnews/compose/src/nsMsgCopy.h
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsMsgSendLater.cpp
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapMailFolder.h
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsLocalUtils.cpp
mailnews/local/src/nsLocalUtils.h
mailnews/local/src/nsPop3Sink.cpp
mailnews/news/public/nsINNTPArticleList.idl
mailnews/news/public/nsINntpUrl.idl
mailnews/news/src/nsNNTPArticleList.cpp
mailnews/news/src/nsNewsUtils.cpp
mailnews/news/src/nsNewsUtils.h
mailnews/news/src/nsNntpUrl.cpp
mailnews/news/src/nsNntpUrl.h
--- a/mailnews/base/public/nsIMsgCopyServiceListener.idl
+++ b/mailnews/base/public/nsIMsgCopyServiceListener.idl
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsrootidl.idl"
 #include "nsISupports.idl"
+#include "MailNewsTypes2.idl"
 
 [scriptable, uuid(CA620E0E-927F-4fbe-A108-9ECF31A7ECC7)]
 interface nsIMsgCopyServiceListener : nsISupports {
 
     /**
      * Notify the observer that the message has started to be copied. This
      * method is called only once, at the beginning of a message
      * copyoperation. 
@@ -26,17 +27,17 @@ interface nsIMsgCopyServiceListener : ns
 
     /**
      * Setting newly created message key. This method is taylored specifically
      * for nsIMsgCopyService::CopyFileMessage() when saveing Drafts/Templates.
      * We need to have a way to inform the client what's the key of the newly
      * created message.
      * aKey -
      */
-    void SetMessageKey(in uint32_t aKey);
+    void SetMessageKey(in nsMsgKey aKey);
 
     /**
      * Getting the file message message ID. This method is taylored
      * specifically for nsIMsgCopyService::CopyFileMessage() when saving
      * Drafts/Templates. In order to work with imap server which doesn't
      * support uidplus we have to use search comman to retrieve the key of
      * newly created message. Message ID generated by the compose gurantee its
      * uniqueness.
--- a/mailnews/base/search/src/nsMsgFilterService.cpp
+++ b/mailnews/base/search/src/nsMsgFilterService.cpp
@@ -1020,17 +1020,17 @@ NS_IMETHODIMP nsMsgFilterAfterTheFact::O
 
 /* void OnProgress (in uint32_t aProgress, in uint32_t aProgressMax); */
 NS_IMETHODIMP nsMsgFilterAfterTheFact::OnProgress(uint32_t aProgress, uint32_t aProgressMax)
 {
   return NS_OK;
 }
 
 /* void SetMessageKey (in uint32_t aKey); */
-NS_IMETHODIMP nsMsgFilterAfterTheFact::SetMessageKey(uint32_t /* aKey */)
+NS_IMETHODIMP nsMsgFilterAfterTheFact::SetMessageKey(nsMsgKey /* aKey */)
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgFilterAfterTheFact::GetMessageId(nsACString& messageId)
 {
   return NS_OK;
 }
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -1668,17 +1668,17 @@ nsSaveMsgListener::OnStartCopy(void)
 
 NS_IMETHODIMP
 nsSaveMsgListener::OnProgress(uint32_t aProgress, uint32_t aProgressMax)
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsSaveMsgListener::SetMessageKey(uint32_t aKey)
+nsSaveMsgListener::SetMessageKey(nsMsgKey aKey)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsSaveMsgListener::GetMessageId(nsACString& aMessageId)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
@@ -2492,17 +2492,17 @@ public:
   bool mSaveFirst;                                // detach (true) or delete (false)
   nsCOMPtr<nsIFile> mMsgFile;                       // temporary file (processed mail)
   nsCOMPtr<nsIOutputStream> mMsgFileStream;         // temporary file (processed mail)
   nsCOMPtr<nsIMsgMessageService> mMessageService;   // original message service
   nsCOMPtr<nsIMsgDBHdr> mOriginalMessage;           // original message header
   nsCOMPtr<nsIMsgFolder> mMessageFolder;            // original message folder
   nsCOMPtr<nsIMessenger> mMessenger;                // our messenger instance
   nsCOMPtr<nsIMsgWindow> mMsgWindow;                // our UI window
-  uint32_t mNewMessageKey;                          // new message key
+  nsMsgKey mNewMessageKey;                          // new message key
   uint32_t mOrigMsgFlags;
 
 
    enum {
       eStarting,
       eCopyingNewMsg,
       eUpdatingFolder, // for IMAP
       eDeletingOldMessage,
@@ -2557,17 +2557,17 @@ nsDelAttachListener::OnStopRequest(nsIRe
   // copy the file back into the folder. Note: setting msgToReplace only copies
   // metadata, so we do the delete ourselves
   nsCOMPtr<nsIMsgCopyServiceListener> listenerCopyService;
   rv = this->QueryInterface( NS_GET_IID(nsIMsgCopyServiceListener), getter_AddRefs(listenerCopyService) );
   NS_ENSURE_SUCCESS(rv,rv);
 
   mMsgFileStream->Close();
   mMsgFileStream = nullptr;
-  mNewMessageKey = PR_UINT32_MAX;
+  mNewMessageKey = nsMsgKey_None;
   nsCOMPtr<nsIMsgCopyService> copyService = do_GetService(NS_MSGCOPYSERVICE_CONTRACTID);
   m_state = eCopyingNewMsg;
   // clone file because nsIFile on Windows caches the wrong file size.
   nsCOMPtr <nsIFile> clone;
   mMsgFile->Clone(getter_AddRefs(clone));
   if (copyService)
   {
     nsCString originalKeys;
@@ -2639,17 +2639,17 @@ void nsDelAttachListener::SelectNewMessa
     if (!displayUri.IsEmpty() && mMsgWindow)
     {
       nsCOMPtr<nsIMsgWindowCommands> windowCommands;
       mMsgWindow->GetWindowCommands(getter_AddRefs(windowCommands));
       if (windowCommands)
         windowCommands->SelectMessage(displayUri);
     }
   }
-  mNewMessageKey = PR_UINT32_MAX;
+  mNewMessageKey = nsMsgKey_None;
 }
 
 NS_IMETHODIMP
 nsDelAttachListener::OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode)
 {
   nsresult rv = NS_OK;
   const char * messageUri = mAttach->mAttachmentArray[0].mMessageUri;
   if (mOriginalMessage && !strncmp(messageUri, "imap-message:", 13))
@@ -2678,17 +2678,17 @@ nsDelAttachListener::OnStartCopy(void)
 NS_IMETHODIMP
 nsDelAttachListener::OnProgress(uint32_t aProgress, uint32_t aProgressMax)
 {
   // never called?
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDelAttachListener::SetMessageKey(uint32_t aKey)
+nsDelAttachListener::SetMessageKey(nsMsgKey aKey)
 {
   // called during the copy of the modified message back into the message
   // store to notify us of the message key of the newly created message.
   mNewMessageKey = aKey;
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -2731,17 +2731,17 @@ nsDelAttachListener::OnStopCopy(nsresult
 // local methods
 //
 
 nsDelAttachListener::nsDelAttachListener()
 {
   mAttach = nullptr;
   mSaveFirst = false;
   mWrittenExtra = false;
-  mNewMessageKey = PR_UINT32_MAX;
+  mNewMessageKey = nsMsgKey_None;
   m_state = eStarting;
 }
 
 nsDelAttachListener::~nsDelAttachListener()
 {
   if (mAttach)
   {
     delete mAttach;
--- a/mailnews/base/src/nsMessengerUnixIntegration.cpp
+++ b/mailnews/base/src/nsMessengerUnixIntegration.cpp
@@ -236,17 +236,17 @@ nsMessengerUnixIntegration::BuildNotific
   if (msgURIIndex == mFetchingURIs.NoIndex)
   {
     localOnly = false;
     mFetchingURIs.AppendElement(msgURI);
   }
   else
     localOnly = true;
 
-  uint32_t messageKey;
+  nsMsgKey messageKey;
   if (NS_FAILED(aHdr->GetMessageKey(&messageKey)))
     return false;
 
   bool asyncResult = false;
   nsresult rv = folder->FetchMsgPreviewText(&messageKey, 1,
                                             localOnly, this,
                                             &asyncResult);
   // If we're still waiting on getting the message previews,
--- a/mailnews/base/src/nsMsgFolderCompactor.cpp
+++ b/mailnews/base/src/nsMsgFolderCompactor.cpp
@@ -82,21 +82,22 @@ void nsFolderCompactState::CleanupTempFi
   if (m_db)
     m_db->ForceClosed();
   nsCOMPtr <nsIFile> summaryFile;
   GetSummaryFileLocation(m_file, getter_AddRefs(summaryFile)); 
   m_file->Remove(false);
   summaryFile->Remove(false);
 }
 
-nsresult nsFolderCompactState::BuildMessageURI(const char *baseURI, uint32_t key, nsCString& uri)
+nsresult nsFolderCompactState::BuildMessageURI(const char *baseURI, nsMsgKey key, nsCString& uri)
 {
   uri.Append(baseURI);
   uri.Append('#');
   uri.AppendInt(key);
+
   return NS_OK;
 }
 
 
 nsresult
 nsFolderCompactState::InitDB(nsIMsgDatabase *db)
 {
   nsCOMPtr<nsIMsgDatabase> mailDBFactory;
--- a/mailnews/base/src/nsMsgFolderCompactor.h
+++ b/mailnews/base/src/nsMsgFolderCompactor.h
@@ -40,17 +40,17 @@ protected:
   virtual nsresult StartCompacting();
   virtual nsresult FinishCompact();
   void CloseOutputStream();
   void  CleanupTempFilesAfterError();
 
   nsresult Init(nsIMsgFolder *aFolder, const char* aBaseMsgUri, nsIMsgDatabase *aDb,
                             nsIFile *aPath, nsIMsgWindow *aMsgWindow);
   nsresult GetMessage(nsIMsgDBHdr **message);
-  nsresult BuildMessageURI(const char *baseURI, uint32_t key, nsCString& uri);
+  nsresult BuildMessageURI(const char *baseURI, nsMsgKey key, nsCString& uri);
   nsresult ShowStatusMsg(const nsString& aMsg);
   nsresult ReleaseFolderLock();
   void     ShowCompactingStatusMsg();
   void     CompactCompleted(nsresult exitCode);
   void     ShowDoneStatus();
   nsresult CompactNextFolder();
 
   nsCString m_baseMessageUri; // base message uri
--- a/mailnews/base/src/nsMsgSearchDBView.cpp
+++ b/mailnews/base/src/nsMsgSearchDBView.cpp
@@ -1011,17 +1011,17 @@ nsMsgSearchDBView::OnStartCopy()
 NS_IMETHODIMP
 nsMsgSearchDBView::OnProgress(uint32_t aProgress, uint32_t aProgressMax)
 {
   return NS_OK;
 }
 
 // believe it or not, these next two are msgcopyservice listener methods!
 NS_IMETHODIMP
-nsMsgSearchDBView::SetMessageKey(uint32_t aMessageKey)
+nsMsgSearchDBView::SetMessageKey(nsMsgKey aMessageKey)
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgSearchDBView::GetMessageId(nsACString& messageId)
 {
   return NS_OK;
--- a/mailnews/base/src/nsMsgXFViewThread.cpp
+++ b/mailnews/base/src/nsMsgXFViewThread.cpp
@@ -468,14 +468,14 @@ NS_IMETHODIMP nsMsgXFViewThread::GetFirs
       {
         NS_ADDREF(*aResult = child);
         break;
       }
     }
   }
   return rv;
 }
-NS_IMETHODIMP nsMsgXFViewThread::EnumerateMessages(uint32_t aParentKey,
+NS_IMETHODIMP nsMsgXFViewThread::EnumerateMessages(nsMsgKey aParentKey,
                                                    nsISimpleEnumerator **aResult)
 {
   NS_ERROR("shouldn't call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -552,17 +552,17 @@ NS_IMETHODIMP nsMsgDBFolder::ClearNewMes
   nsresult rv = NS_OK;
   bool dbWasCached = mDatabase != nullptr;
   if (!dbWasCached)
     GetDatabase();
 
   if (mDatabase)
   {
     uint32_t numNewKeys;
-    uint32_t *newMessageKeys;
+    nsMsgKey *newMessageKeys;
     rv = mDatabase->GetNewList(&numNewKeys, &newMessageKeys);
     if (NS_SUCCEEDED(rv) && newMessageKeys)
     {
       m_saveNewMsgs.Clear();
       m_saveNewMsgs.AppendElements(newMessageKeys, numNewKeys);
       NS_Free(newMessageKeys);
     }
     mDatabase->ClearNewList(true);
@@ -963,17 +963,17 @@ nsMsgDBFolder::SetMsgDatabase(nsIMsgData
   {
     // commit here - db might go away when all these refs are released.
     mDatabase->Commit(nsMsgDBCommitType::kLargeCommit);
     mDatabase->RemoveListener(this);
     mDatabase->ClearCachedHdrs();
     if (!aMsgDatabase)
     {
       uint32_t numNewKeys;
-      uint32_t *newMessageKeys;
+      nsMsgKey *newMessageKeys;
       nsresult rv = mDatabase->GetNewList(&numNewKeys, &newMessageKeys);
       if (NS_SUCCEEDED(rv) && newMessageKeys)
       {
         m_newMsgs.Clear();
         m_newMsgs.AppendElements(newMessageKeys, numNewKeys);
       }
       NS_Free(newMessageKeys);
     }
@@ -2662,17 +2662,17 @@ nsMsgDBFolder::CallFilterPlugins(nsIMsgW
   {
     NotifyHdrsNotBeingClassified();
     return NS_OK;
   }
 
   // get the list of new messages
   //
   uint32_t numNewKeys;
-  uint32_t *newKeys;
+  nsMsgKey *newKeys;
   rv = database->GetNewList(&numNewKeys, &newKeys);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsTArray<nsMsgKey> newMessageKeys;
   // Start from m_saveNewMsgs (and clear its current state).  m_saveNewMsgs is
   // where we stash the list of new messages when we are told to clear the list
   // of new messages by the UI (which purges the list from the nsMsgDatabase).
   newMessageKeys.SwapElements(m_saveNewMsgs);
@@ -5969,33 +5969,33 @@ nsMsgKeySetU::nsMsgKeySetU()
 nsMsgKeySetU::~nsMsgKeySetU()
 {
   delete loKeySet;
   delete hiKeySet;
 }
 
 const uint32_t kLowerBits = 0x7fffffff;
 
-int nsMsgKeySetU::Add(uint32_t aKey)
+int nsMsgKeySetU::Add(nsMsgKey aKey)
 {
   int32_t intKey = static_cast<int32_t>(aKey);
   if (intKey >= 0)
     return loKeySet->Add(intKey);
   return hiKeySet->Add(intKey & kLowerBits);
 }
 
-int nsMsgKeySetU::Remove(uint32_t aKey)
+int nsMsgKeySetU::Remove(nsMsgKey aKey)
 {
   int32_t intKey = static_cast<int32_t>(aKey);
   if (intKey >= 0)
     return loKeySet->Remove(intKey);
   return hiKeySet->Remove(intKey & kLowerBits);
 }
 
-bool nsMsgKeySetU::IsMember(uint32_t aKey)
+bool nsMsgKeySetU::IsMember(nsMsgKey aKey)
 {
   int32_t intKey = static_cast<int32_t>(aKey);
   if (intKey >= 0)
     return loKeySet->IsMember(intKey);
   return hiKeySet->IsMember(intKey & kLowerBits);
 }
 
 nsresult nsMsgKeySetU::ToMsgKeyArray(nsTArray<nsMsgKey> &aArray)
--- a/mailnews/base/util/nsMsgDBFolder.h
+++ b/mailnews/base/util/nsMsgDBFolder.h
@@ -286,22 +286,22 @@ protected:
 // This class is a kludge to allow nsMsgKeySet to be used with uint32_t keys
 class nsMsgKeySetU
 {
 public:
     // Creates an empty set.
   static nsMsgKeySetU* Create();
   ~nsMsgKeySetU();
   // IsMember() returns whether the given key is a member of this set.
-  bool IsMember(uint32_t key);
+  bool IsMember(nsMsgKey key);
   // Add() adds the given key to the set.  (Returns 1 if a change was
   // made, 0 if it was already there, and negative on error.)
-  int Add(uint32_t key);
-  // Remove() removes the given article from the set. 
-  int Remove(uint32_t key);
+  int Add(nsMsgKey key);
+  // Remove() removes the given article from the set.
+  int Remove(nsMsgKey key);
   // Add the keys in the set to aArray.
   nsresult ToMsgKeyArray(nsTArray<nsMsgKey> &aArray);
 
 protected:
   nsMsgKeySetU();
   nsMsgKeySet* loKeySet;
   nsMsgKeySet* hiKeySet;
 };
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -2434,8 +2434,19 @@ ConvertBufToPlainText(nsString &aConBuf,
 
   nsCOMPtr<nsIParserUtils> utils =
     do_GetService(NS_PARSERUTILS_CONTRACTID);
   return utils->ConvertToPlainText(aConBuf,
                                    converterFlags,
                                    wrapWidth,
                                    aConBuf);
 }
+
+NS_MSG_BASE nsMsgKey msgKeyFromInt(uint32_t aValue)
+{
+  return aValue;
+}
+
+NS_MSG_BASE nsMsgKey msgKeyFromInt(uint64_t aValue)
+{
+  NS_ASSERTION(aValue <= PR_UINT32_MAX, "Msg key value too big!");
+  return aValue;
+}
--- a/mailnews/base/util/nsMsgUtils.h
+++ b/mailnews/base/util/nsMsgUtils.h
@@ -540,9 +540,20 @@ uint32_t MsgCountChar(nsAString &aString
  */
 NS_MSG_BASE uint64_t MsgUnhex(const char *aHexString, size_t aNumChars);
 
 /**
  * Checks if a string is a valid hex literal containing at least aNumChars digits.
  */
 NS_MSG_BASE bool MsgIsHex(const char *aHexString, size_t aNumChars);
 
+/**
+ * Convert an uint32_t to a nsMsgKey.
+ * Currently they are mostly the same but we need to preserve the notion that
+ * nsMsgKey is an opaque value that can't be treated as a generic integer
+ * (except when storing it into the database). It enables type safety checks and
+ * may prevent coding errors.
+ */
+NS_MSG_BASE nsMsgKey msgKeyFromInt(uint32_t aValue);
+
+NS_MSG_BASE nsMsgKey msgKeyFromInt(uint64_t aValue);
+
 #endif
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -3853,17 +3853,17 @@ nsMsgComposeSendListener::RemoveCurrentD
         compFields->SetDraftId(newDraftIdURL.get());
       }
     }
   }
   return rv;
 }
 
 nsresult
-nsMsgComposeSendListener::SetMessageKey(uint32_t aMessageKey)
+nsMsgComposeSendListener::SetMessageKey(nsMsgKey aMessageKey)
 {
   return NS_OK;
 }
 
 nsresult
 nsMsgComposeSendListener::GetMessageId(nsACString& messageId)
 {
   return NS_OK;
--- a/mailnews/compose/src/nsMsgCopy.cpp
+++ b/mailnews/compose/src/nsMsgCopy.cpp
@@ -69,17 +69,17 @@ CopyListener::OnProgress(uint32_t aProgr
 
   if (mComposeAndSend)
     mComposeAndSend->NotifyListenerOnProgressCopy(aProgress, aProgressMax);
 
   return NS_OK;
 }
 
 nsresult
-CopyListener::SetMessageKey(uint32_t aMessageKey)
+CopyListener::SetMessageKey(nsMsgKey aMessageKey)
 {
   if (mComposeAndSend)
       mComposeAndSend->SetMessageKey(aMessageKey);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 CopyListener::GetMessageId(nsACString& aMessageId)
--- a/mailnews/compose/src/nsMsgCopy.h
+++ b/mailnews/compose/src/nsMsgCopy.h
@@ -34,18 +34,18 @@ public:
 
   // nsISupports interface
   NS_DECL_THREADSAFE_ISUPPORTS
 
   NS_IMETHOD OnStartCopy() MOZ_OVERRIDE;
   
   NS_IMETHOD OnProgress(uint32_t aProgress, uint32_t aProgressMax) MOZ_OVERRIDE;
 
-  NS_IMETHOD SetMessageKey(uint32_t aMessageKey) MOZ_OVERRIDE;
-  
+  NS_IMETHOD SetMessageKey(nsMsgKey aMessageKey) MOZ_OVERRIDE;
+
   NS_IMETHOD GetMessageId(nsACString& aMessageId) MOZ_OVERRIDE;
   
   NS_IMETHOD OnStopCopy(nsresult aStatus) MOZ_OVERRIDE;
 
   NS_IMETHOD SetMsgComposeAndSendObject(nsIMsgSend *obj);
   
   bool                            mCopyInProgress;
 
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -247,17 +247,17 @@ NS_IMETHODIMP MsgDeliveryListener::OnSto
   return NS_OK;
 }
 
 
 /* the following macro actually implement addref, release and query interface for our component. */
 NS_IMPL_ISUPPORTS(nsMsgComposeAndSend, nsIMsgSend)
 
 nsMsgComposeAndSend::nsMsgComposeAndSend() :
-    m_messageKey(0xffffffff)
+    m_messageKey(nsMsgKey_None)
 {
   mGUINotificationEnabled = true;
   mAbortInProcess = false;
   mMultipartRelatedAttachmentCount = -1;
   mSendMailAlso = false;
 
   m_dont_deliver_p = false;
   m_deliver_mode = nsMsgDeliverNow;
@@ -3907,24 +3907,24 @@ nsMsgComposeAndSend::NotifyListenerOnPro
     if (copyListener)
       copyListener->OnProgress(aProgress, aProgressMax);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgComposeAndSend::SetMessageKey(uint32_t aMessageKey)
+nsMsgComposeAndSend::SetMessageKey(nsMsgKey aMessageKey)
 {
     m_messageKey = aMessageKey;
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgComposeAndSend::GetMessageKey(uint32_t *aMessageKey)
+nsMsgComposeAndSend::GetMessageKey(nsMsgKey *aMessageKey)
 {
     *aMessageKey = m_messageKey;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgComposeAndSend::GetFolderUri(nsACString &aFolderUri)
 {
--- a/mailnews/compose/src/nsMsgSendLater.cpp
+++ b/mailnews/compose/src/nsMsgSendLater.cpp
@@ -470,17 +470,17 @@ SendOperationListener::OnStartCopy(void)
 
 NS_IMETHODIMP
 SendOperationListener::OnProgress(uint32_t aProgress, uint32_t aProgressMax)
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP
-SendOperationListener::SetMessageKey(uint32_t aKey)
+SendOperationListener::SetMessageKey(nsMsgKey aKey)
 {
   NS_NOTREACHED("SendOperationListener::SetMessageKey()");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 SendOperationListener::GetMessageId(nsACString& messageId)
 {
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -5653,28 +5653,28 @@ NS_IMETHODIMP nsMsgDatabase::ResetHdrCac
   }
   return NS_OK;
 }
 
 /**
   void getNewList(out unsigned long count, [array, size_is(count)] out long newKeys);
  */
 NS_IMETHODIMP
-nsMsgDatabase::GetNewList(uint32_t *aCount, uint32_t **aNewKeys)
+nsMsgDatabase::GetNewList(uint32_t *aCount, nsMsgKey **aNewKeys)
 {
     NS_ENSURE_ARG_POINTER(aCount);
     NS_ENSURE_ARG_POINTER(aNewKeys);
 
     *aCount = m_newSet.Length();
     if (*aCount > 0)
     {
-      *aNewKeys = static_cast<uint32_t *>(nsMemory::Alloc(*aCount * sizeof(uint32_t)));
+      *aNewKeys = static_cast<nsMsgKey *>(nsMemory::Alloc(*aCount * sizeof(nsMsgKey)));
       if (!*aNewKeys)
         return NS_ERROR_OUT_OF_MEMORY;
-      memcpy(*aNewKeys, m_newSet.Elements(), *aCount * sizeof(uint32_t));
+      memcpy(*aNewKeys, m_newSet.Elements(), *aCount * sizeof(nsMsgKey));
       return NS_OK;
     }
     // if there were no new messages, signal this by returning a null pointer
     //
     *aNewKeys = nullptr;
     return NS_OK;
 }
 
@@ -5770,20 +5770,20 @@ NS_IMETHODIMP nsMsgDatabase::RefreshCach
       table->CutOid(GetEnv(), &oid);
       rowCount--;
       continue; // don't increment tableRowIndex since we removed that row.
     }
    }
    *aNumBadHits = staleHits.Length();
    if (*aNumBadHits)
    {
-     *aStaleHits = static_cast<uint32_t *>(nsMemory::Alloc(*aNumBadHits * sizeof(uint32_t)));
+     *aStaleHits = static_cast<nsMsgKey *>(nsMemory::Alloc(*aNumBadHits * sizeof(nsMsgKey)));
      if (!*aStaleHits)
        return NS_ERROR_OUT_OF_MEMORY;
-     memcpy(*aStaleHits, staleHits.Elements(), *aNumBadHits * sizeof(uint32_t));
+     memcpy(*aStaleHits, staleHits.Elements(), *aNumBadHits * sizeof(nsMsgKey));
    }
    else
      *aStaleHits = nullptr;
 
 #ifdef DEBUG_David_Bienvenu
   printf("after refreshing cache\n");
   // iterate over table and assert that it's in id order
   table->GetCount(GetEnv(), &rowCount);
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -2977,17 +2977,17 @@ nsresult nsImapMailFolder::SetupHeaderPa
     m_msgParser->Clear();
 
   m_msgParser->SetMailDB(mDatabase);
   if (mBackupDatabase)
     m_msgParser->SetBackupMailDB(mBackupDatabase);
   return m_msgParser->SetState(nsIMsgParseMailMsgState::ParseHeadersState);
 }
 
-nsresult nsImapMailFolder::ParseAdoptedHeaderLine(const char *aMessageLine, uint32_t aMsgKey)
+nsresult nsImapMailFolder::ParseAdoptedHeaderLine(const char *aMessageLine, nsMsgKey aMsgKey)
 {
   // we can get blocks that contain more than one line,
   // but they never contain partial lines
   const char *str = aMessageLine;
   m_curMsgUid = aMsgKey;
   m_msgParser->SetEnvelopePos(m_curMsgUid);
   // m_envelope_pos, for local folders,
   // is the msg key. Setting this will set the msg key for the new header.
@@ -5021,17 +5021,17 @@ nsImapMailFolder::GetMessageSizeFromDB(c
 {
   NS_ENSURE_ARG_POINTER(size);
 
   *size = 0;
   nsresult rv = GetDatabase();
   NS_ENSURE_SUCCESS(rv, rv);
   if (id)
   {
-    uint32_t key = strtoul(id, nullptr, 10);
+    nsMsgKey key = msgKeyFromInt(ParseUint64Str(id));
     nsCOMPtr<nsIMsgDBHdr> mailHdr;
     rv = mDatabase->GetMsgHdrForKey(key, getter_AddRefs(mailHdr));
     if (NS_SUCCEEDED(rv) && mailHdr)
       rv = mailHdr->GetMessageSize(size);
   }
   return rv;
 }
 
@@ -7843,18 +7843,18 @@ NS_IMETHODIMP nsImapFolderCopyState::OnS
 }
 
 /* void OnProgress (in uint32_t aProgress, in uint32_t aProgressMax); */
 NS_IMETHODIMP nsImapFolderCopyState::OnProgress(uint32_t aProgress, uint32_t aProgressMax)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-/* void SetMessageKey (in uint32_t aKey); */
-NS_IMETHODIMP nsImapFolderCopyState::SetMessageKey(uint32_t aKey)
+/* void SetMessageKey (in nsMsgKey aKey); */
+NS_IMETHODIMP nsImapFolderCopyState::SetMessageKey(nsMsgKey aKey)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* [noscript] void GetMessageId (in nsCString aMessageId); */
 NS_IMETHODIMP nsImapFolderCopyState::GetMessageId(nsACString& messageId)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
@@ -8011,17 +8011,17 @@ nsImapMailFolder::CopyFileMessage(nsIFil
                                   nsIMsgDBHdr* msgToReplace,
                                   bool isDraftOrTemplate,
                                   uint32_t aNewMsgFlags,
                                   const nsACString &aNewMsgKeywords,
                                   nsIMsgWindow *msgWindow,
                                   nsIMsgCopyServiceListener* listener)
 {
     nsresult rv = NS_ERROR_NULL_POINTER;
-    nsMsgKey key = 0xffffffff;
+    nsMsgKey key = nsMsgKey_None;
     nsAutoCString messageId;
     nsCOMPtr<nsIUrlListener> urlListener;
     nsCOMPtr<nsIMutableArray> messages(do_CreateInstance(NS_ARRAY_CONTRACTID));
     nsCOMPtr<nsISupports> srcSupport = do_QueryInterface(file, &rv);
 
     if (!messages)
       return OnCopyCompleted(srcSupport, rv);
 
--- a/mailnews/imap/src/nsImapMailFolder.h
+++ b/mailnews/imap/src/nsImapMailFolder.h
@@ -356,17 +356,17 @@ protected:
 
   nsresult SyncFlags(nsIImapFlagAndUidState *flagState);
   nsresult HandleCustomFlags(nsMsgKey uidOfMessage, nsIMsgDBHdr *dbHdr,
                              uint16_t userFlags, nsCString& keywords);
   nsresult NotifyMessageFlagsFromHdr(nsIMsgDBHdr *dbHdr, nsMsgKey msgKey,
                                      uint32_t flags);
 
   nsresult SetupHeaderParseStream(uint32_t size, const nsACString& content_type, nsIMailboxSpec *boxSpec);
-  nsresult  ParseAdoptedHeaderLine(const char *messageLine, uint32_t msgKey);
+  nsresult  ParseAdoptedHeaderLine(const char *messageLine, nsMsgKey msgKey);
   nsresult  NormalEndHeaderParseStream(nsIImapProtocol *aProtocol, nsIImapUrl *imapUrl);
 
   void EndOfflineDownload();
   nsresult CopyFileToOfflineStore(nsIFile *srcFile, nsMsgKey msgKey);
 
   nsresult MarkMessagesImapDeleted(nsTArray<nsMsgKey> *keyArray, bool deleted, nsIMsgDatabase *db);
 
   // Notifies imap autosync that it should update this folder when it
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -69,17 +69,17 @@
 
 //////////////////////////////////////////////////////////////////////////////
 // nsLocal
 /////////////////////////////////////////////////////////////////////////////
 
 nsLocalMailCopyState::nsLocalMailCopyState() :
   m_flags(0),
   m_lastProgressTime(PR_IntervalToMilliseconds(PR_IntervalNow())),
-  m_curDstKey(0xffffffff),
+  m_curDstKey(nsMsgKey_None),
   m_curCopyIndex(0),
   m_totalMsgCount(0),
   m_dataBufferSize(0),
   m_leftOver(0),
   m_isMove(false),
   m_dummyEnvelopeNeeded(false),
   m_fromLineSeen(false),
   m_writeFailed(false),
@@ -2393,17 +2393,17 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndC
       // msgDb->SetSummaryValid(true);
       // msgDb->Commit(nsMsgDBCommitType::kLargeCommit);
     }
     else
       mCopyState->m_undoMsgTxn = nullptr; //null out the transaction because we can't undo w/o the msg db
 
     mCopyState->m_parseMsgState->Clear();
     if (mCopyState->m_listener) // CopyFileMessage() only
-      mCopyState->m_listener->SetMessageKey((uint32_t) mCopyState->m_curDstKey);
+      mCopyState->m_listener->SetMessageKey(mCopyState->m_curDstKey);
   }
 
   if (!multipleCopiesFinished && !mCopyState->m_copyingMultipleMessages)
   {
     // CopyMessages() goes here; CopyFileMessage() never gets in here because
     // curCopyIndex will always be less than the mCopyState->m_totalMsgCount
     nsCOMPtr<nsISupports> aSupport = do_QueryElementAt(mCopyState->m_messages, mCopyState->m_curCopyIndex);
     rv = CopyMessageTo(aSupport, this, mCopyState->m_msgWindow, mCopyState->m_isMove);
@@ -2637,17 +2637,17 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndM
         }
       }
       else
         mCopyState->m_undoMsgTxn = nullptr; //null out the transaction because we can't undo w/o the msg db
     }
     mCopyState->m_parseMsgState->Clear();
 
     if (mCopyState->m_listener) // CopyFileMessage() only
-      mCopyState->m_listener->SetMessageKey((uint32_t) mCopyState->m_curDstKey);
+      mCopyState->m_listener->SetMessageKey(mCopyState->m_curDstKey);
   }
 
   if (mCopyState->m_fileStream)
     mCopyState->m_fileStream->Flush();
   return NS_OK;
 }
 
 
--- a/mailnews/local/src/nsLocalUtils.cpp
+++ b/mailnews/local/src/nsLocalUtils.cpp
@@ -180,17 +180,17 @@ nsLocalURI2Path(const char* rootURI, con
  * mailbox-message://folder1/folder2#123?header=none or
  * mailbox-message://folder1/folder2#1234&part=1.2
  *
  * puts folder URI in folderURI (mailbox://folder1/folder2)
  * message key number in key
  */
 nsresult nsParseLocalMessageURI(const char* uri,
                                 nsCString& folderURI,
-                                uint32_t *key)
+                                nsMsgKey *key)
 {
   if(!key)
     return NS_ERROR_NULL_POINTER;
 
   nsAutoCString uriStr(uri);
   int32_t keySeparator = uriStr.FindChar('#');
   if(keySeparator != -1)
   {
@@ -200,28 +200,26 @@ nsresult nsParseLocalMessageURI(const ch
 
     nsAutoCString keyStr;
     if (keyEndSeparator != -1)
       keyStr = Substring(uriStr, keySeparator + 1,
                          keyEndSeparator - (keySeparator + 1));
     else
       keyStr = StringTail(uriStr, uriStr.Length() - (keySeparator + 1));
 
-    *key = (uint32_t) ParseUint64Str(keyStr.get());
+    *key = msgKeyFromInt(ParseUint64Str(keyStr.get()));
     return NS_OK;
   }
   return NS_ERROR_FAILURE;
 
 }
 
-nsresult nsBuildLocalMessageURI(const char *baseURI, uint32_t key, nsCString& uri)
+nsresult nsBuildLocalMessageURI(const char *baseURI, nsMsgKey key, nsCString& uri)
 {
-  
   // need to convert mailbox://hostname/.. to mailbox-message://hostname/..
-
   uri.Append(baseURI);
   uri.Append('#');
   uri.AppendInt(key);
   return NS_OK;
 }
 
 nsresult nsCreateLocalBaseMessageURI(const nsACString& baseURI, nsCString &baseMessageURI)
 {
--- a/mailnews/local/src/nsLocalUtils.h
+++ b/mailnews/local/src/nsLocalUtils.h
@@ -11,20 +11,20 @@
 
 static const char kMailboxRootURI[] = "mailbox:/";
 static const char kMailboxMessageRootURI[] = "mailbox-message:/";
 
 nsresult
 nsLocalURI2Path(const char* rootURI, const char* uriStr, nsCString& pathResult);
 
 nsresult
-nsParseLocalMessageURI(const char* uri, nsCString& folderURI, uint32_t *key);
+nsParseLocalMessageURI(const char* uri, nsCString& folderURI, nsMsgKey *key);
 
 nsresult 
-nsBuildLocalMessageURI(const char* baseURI, uint32_t key, nsCString& uri);
+nsBuildLocalMessageURI(const char* baseURI, nsMsgKey key, nsCString& uri);
 
 nsresult
 nsCreateLocalBaseMessageURI(const nsACString& baseURI, nsCString &baseMessageURI);
 
 void
 nsEscapeNativePath(nsCString& nativePath);
 
 #endif //NS_LOCALUTILS_H
--- a/mailnews/local/src/nsPop3Sink.cpp
+++ b/mailnews/local/src/nsPop3Sink.cpp
@@ -734,17 +734,17 @@ nsresult nsPop3Sink::HandleTempDownloadF
 
 
 NS_IMETHODIMP
 nsPop3Sink::IncorporateComplete(nsIMsgWindow *aMsgWindow, int32_t aSize)
 {
   if (m_buildMessageUri && !m_baseMessageUri.IsEmpty() && m_newMailParser &&
       m_newMailParser->m_newMsgHdr)
   {
-    uint32_t msgKey;
+    nsMsgKey msgKey;
     m_newMailParser->m_newMsgHdr->GetMessageKey(&msgKey);
     m_messageUri.Truncate();
     nsBuildLocalMessageURI(m_baseMessageUri.get(), msgKey, m_messageUri);
   }
 
   nsresult rv = WriteLineToMailbox(NS_LITERAL_CSTRING(MSG_LINEBREAK));
   NS_ENSURE_SUCCESS(rv, rv);
   bool leaveOnServer = false;
--- a/mailnews/news/public/nsINNTPArticleList.idl
+++ b/mailnews/news/public/nsINNTPArticleList.idl
@@ -1,16 +1,17 @@
 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
+#include "MailNewsTypes2.idl"
 
 interface nsIMsgNewsFolder;
 
 [scriptable, uuid(921AC214-96B5-11d2-B7EB-00805F05FFA5)]
 interface nsINNTPArticleList : nsISupports {
-    void initialize(in nsIMsgNewsFolder newsFolder); 
-    void addArticleKey(in long key);
+    void initialize(in nsIMsgNewsFolder newsFolder);
+    void addArticleKey(in nsMsgKey key);
     void finishAddingArticleKeys();
 };
 
--- a/mailnews/news/public/nsINntpUrl.idl
+++ b/mailnews/news/public/nsINntpUrl.idl
@@ -61,17 +61,17 @@ interface nsINntpUrl : nsISupports {
    * this value, be sure to escape it first.
    */
   readonly attribute ACString group;
 
   /// The message ID portion of the URI, if one is present
   readonly attribute ACString messageID;
 
   /// The message key portion of the URI or nsMsgKey_None if not present
-  readonly attribute unsigned long key;
+  readonly attribute nsMsgKey key;
 
   /// The action of this news URI could not be determined
   const nsNewsAction ActionUnknown = 0;
   /// Fetch the contents of an article
   const nsNewsAction ActionFetchArticle = 1;
   /// Fetch the part of an article (requires ?part=)
   const nsNewsAction ActionFetchPart = 2;
   /// Save the contents of an article to disk
--- a/mailnews/news/src/nsNNTPArticleList.cpp
+++ b/mailnews/news/src/nsNNTPArticleList.cpp
@@ -49,25 +49,25 @@ nsNNTPArticleList::Initialize(nsIMsgNews
     rv = m_newsDB->ListAllKeys(keys);
     NS_ENSURE_SUCCESS(rv,rv);
     m_idsInDB.AppendElements(keys->m_keys);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsNNTPArticleList::AddArticleKey(int32_t key)
+nsNNTPArticleList::AddArticleKey(nsMsgKey key)
 {
 #ifdef DEBUG
   m_idsOnServer.AppendElement(key);
 #endif
 
   if (m_dbIndex < m_idsInDB.Length())
   {
-    int32_t idInDBToCheck = m_idsInDB[m_dbIndex];
+    nsMsgKey idInDBToCheck = m_idsInDB[m_dbIndex];
     // if there are keys in the database that aren't in the newsgroup
     // on the server, remove them. We probably shouldn't do this if
     // we have a copy of the article offline.
     // We'll add to m_idsDeleted for now and remove the id later
     while (idInDBToCheck < key)
     {
       m_idsDeleted.AppendElement(idInDBToCheck);
       if (m_dbIndex >= m_idsInDB.Length())
--- a/mailnews/news/src/nsNewsUtils.cpp
+++ b/mailnews/news/src/nsNewsUtils.cpp
@@ -6,17 +6,17 @@
 #include "msgCore.h"
 #include "nntpCore.h"
 #include "nsNewsUtils.h"
 #include "nsMsgUtils.h"
 
 
 /* parses NewsMessageURI */
 nsresult
-nsParseNewsMessageURI(const char* uri, nsCString& group, uint32_t *key)
+nsParseNewsMessageURI(const char* uri, nsCString& group, nsMsgKey *key)
 {
   NS_ENSURE_ARG_POINTER(uri);
   NS_ENSURE_ARG_POINTER(key);
 
   nsAutoCString uriStr(uri);
   int32_t keySeparator = uriStr.FindChar('#');
   if(keySeparator != -1)
   {
--- a/mailnews/news/src/nsNewsUtils.h
+++ b/mailnews/news/src/nsNewsUtils.h
@@ -2,31 +2,32 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef NS_NEWSUTILS_H
 #define NS_NEWSUTILS_H
 
 #include "nsStringGlue.h"
+#include "MailNewsTypes2.h"
 
 class nsIMsgNewsFolder;
 
 static const char kNntpRootURI[] = "nntp:/";
 static const char kNewsRootURI[] = "news:/";
 static const char kNewsMessageRootURI[] = "news-message:/";
 static const char kNewsURIGroupQuery[] = "?group=";
 static const char kNewsURIKeyQuery[] = "&key=";
 
 #define kNewsRootURILen 6
 #define kNntpRootURILen 6
 #define kNewsMessageRootURILen 14
 #define kNewsURIGroupQueryLen 7
 #define kNewsURIKeyQueryLen 5
 
 extern nsresult
-nsParseNewsMessageURI(const char* uri, nsCString& group, uint32_t *key);
+nsParseNewsMessageURI(const char* uri, nsCString& group, nsMsgKey *key);
 
 extern nsresult
 nsCreateNewsBaseMessageURI(const char *baseURI, nsCString &baseMessageURI);
 
 #endif //NS_NEWSUTILS_H
 
--- a/mailnews/news/src/nsNntpUrl.cpp
+++ b/mailnews/news/src/nsNntpUrl.cpp
@@ -289,17 +289,17 @@ NS_IMETHODIMP nsNntpUrl::GetGroup(nsACSt
 }
 
 NS_IMETHODIMP nsNntpUrl::GetMessageID(nsACString &messageID)
 {
   messageID = m_messageID;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsNntpUrl::GetKey(uint32_t *key)
+NS_IMETHODIMP nsNntpUrl::GetKey(nsMsgKey *key)
 {
   NS_ENSURE_ARG_POINTER(key);
   *key = m_key;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsNntpUrl::SetUri(const char * aURI)
 {
--- a/mailnews/news/src/nsNntpUrl.h
+++ b/mailnews/news/src/nsNntpUrl.h
@@ -52,12 +52,12 @@ private:
   nsCOMPtr<nsIFile> m_messageFile;
 
   bool          m_addDummyEnvelope;
   bool          m_canonicalLineEnding;
   bool          m_getOldMessages;
 
   nsCString m_group;
   nsCString m_messageID;
-  uint32_t m_key;
+  nsMsgKey m_key;
 };
 
 #endif // nsNntpUrl_h__