Bug 496046 Message headers should be processed in first-in first-out order r+sr=Standard8
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Tue, 09 Jun 2009 13:24:40 +0100
changeset 2810 7075e80889c6ef4626e6f537f196e1ccd2a5cf9d
parent 2809 af67b109386e987f723d6c1660ea803f34115dc7
child 2811 3c7a12447bdc958fd2620f7275fa43f39fd173c6
push idunknown
push userunknown
push dateunknown
bugs496046
Bug 496046 Message headers should be processed in first-in first-out order r+sr=Standard8
mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp
--- a/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp
+++ b/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp
@@ -72,42 +72,43 @@
  * A helper class to implement nsIUTF8StringEnumerator
  */
 
 class nsMimeStringEnumerator : public nsIUTF8StringEnumerator {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIUTF8STRINGENUMERATOR
 
+  nsMimeStringEnumerator() : mCurrentIndex(0) {}
+
   template<class T>
-  nsCString* Append(T value) { return values.AppendElement(value); }
+  nsCString* Append(T value) { return mValues.AppendElement(value); }
 
 protected:
-  nsTArray<nsCString> values;
+  nsTArray<nsCString> mValues;
+  PRUint32 mCurrentIndex; // consumers expect first-in first-out enumeration
 };
 
 NS_IMPL_ISUPPORTS1(nsMimeStringEnumerator, nsIUTF8StringEnumerator)
 
 NS_IMETHODIMP
 nsMimeStringEnumerator::HasMore(PRBool *result)
 {
   NS_ENSURE_ARG_POINTER(result);
-  *result = values.Length() != 0;
+  *result = mCurrentIndex < mValues.Length();
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMimeStringEnumerator::GetNext(nsACString& result)
+NS_IMETHODIMP
+nsMimeStringEnumerator::GetNext(nsACString& result)
 {
-  PRUint32 length = values.Length();
-  if (!length)
+  if (mCurrentIndex >= mValues.Length())
     return NS_ERROR_UNEXPECTED;
 
-  length--;
-  result = values[length];
-  values.RemoveElementAt(length);
+  result = mValues[mCurrentIndex++];
   return NS_OK;
 }
 
 /*
  * nsMimeHtmlEmitter definitions....
  */
 nsMimeHtmlDisplayEmitter::nsMimeHtmlDisplayEmitter() : nsMimeBaseEmitter()
 {