Bug 454103 Make nsIMsgCompFields's attachments an nsISimpleEnumerator, r/sr=Neil
authorJoey Minta <jminta@gmail.com>
Wed, 17 Sep 2008 13:44:25 -0400
changeset 362 8240c87b0dab89ffbd604416a49c7c4c0a570250
parent 361 d6628cc24bc509a592d94070b4cc22befac0a02f
child 363 a28e195fb6165ab4725df3daa98f2d1acffe6552
push idunknown
push userunknown
push dateunknown
bugs454103
Bug 454103 Make nsIMsgCompFields's attachments an nsISimpleEnumerator, r/sr=Neil
mail/components/compose/content/MsgComposeCommands.js
mailnews/compose/public/nsIMsgCompFields.idl
mailnews/compose/resources/content/MsgComposeCommands.js
mailnews/compose/src/nsMsgCompFields.cpp
mailnews/compose/src/nsMsgCompFields.h
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsMsgSend.h
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -1333,25 +1333,23 @@ function ComposeStartup(recycled, aParam
         }
         else
           msgCompFields.body = "\n<" + body + ">\n";
       }
 
       var subjectValue = msgCompFields.subject;
       GetMsgSubjectElement().value = subjectValue;
 
-      var attachments = msgCompFields.attachmentsArray;
-      if (attachments)
-        for (i = 0; i < attachments.Count(); i ++)
-          AddAttachment(attachments.QueryElementAt(i, Components.interfaces.nsIMsgAttachment));
-
-        if (attachments.Count())
-        {
-          ChangeAttachmentBucketVisibility(false);
-        }
+      var attachments = msgCompFields.attachments;
+      if (attachments.hasMoreElements())
+        ChangeAttachmentBucketVisibility(false);
+
+      while (attachments.hasMoreElements()) {
+        AddAttachment(attachments.getNext().QueryInterface(Components.interfaces.nsIMsgAttachment));
+      }
     }
 
     var event = document.createEvent('Events');
     event.initEvent('compose-window-init', false, true);
     document.getElementById("msgcomposeWindow").dispatchEvent(event);
 
     gMsgCompose.RegisterStateListener(stateListener);
 
--- a/mailnews/compose/public/nsIMsgCompFields.idl
+++ b/mailnews/compose/public/nsIMsgCompFields.idl
@@ -34,17 +34,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 #include "nsIMsgRecipientArray.idl"
 #include "nsIMsgAttachment.idl"
-#include "nsISupportsArray.idl"
+#include "nsISimpleEnumerator.idl"
 
 [scriptable, uuid(ab598da9-d272-485b-9941-5ce87251a463)]
 interface nsIMsgCompFields : nsISupports {
 
   attribute AString from;
   attribute AString replyTo;
   attribute AString to;
   attribute AString cc;
@@ -85,17 +85,17 @@ interface nsIMsgCompFields : nsISupports
 
   /**
    * temporaryFiles
    *
    * @OBSOLETE, DO NOT USE ANYMORE
    */
   attribute string  temporaryFiles;
   
-  readonly attribute nsISupportsArray attachmentsArray;
+  readonly attribute nsISimpleEnumerator attachments;
   void addAttachment(in nsIMsgAttachment attachment);
   void removeAttachment(in nsIMsgAttachment attachment);
   void removeAttachments();
 
   /* some utility functions */
   nsIMsgRecipientArray SplitRecipients(in AString aRecipients, in boolean aEmailAddressOnly);    
   void ConvertBodyToPlainText();
 
--- a/mailnews/compose/resources/content/MsgComposeCommands.js
+++ b/mailnews/compose/resources/content/MsgComposeCommands.js
@@ -1339,20 +1339,20 @@ function ComposeStartup(recycled, aParam
           }
           else
             msgCompFields.body = "\n<" + body + ">\n";
         }
 
         var subjectValue = msgCompFields.subject;
         document.getElementById("msgSubject").value = subjectValue;
 
-        var attachments = msgCompFields.attachmentsArray;
-        if (attachments)
-          for (i = 0; i < attachments.Count(); i ++)
-            AddAttachment(attachments.QueryElementAt(i, Components.interfaces.nsIMsgAttachment));
+        var attachments = msgCompFields.attachments;
+        while (attachments.hasMoreElements()) {
+          AddAttachment(attachments.getNext().QueryInterface(Components.interfaces.nsIMsgAttachment));
+        }
       }
 
       var event = document.createEvent('Events');
       event.initEvent('compose-window-init', false, true);
       document.getElementById("msgcomposeWindow").dispatchEvent(event);
 
       gMsgCompose.RegisterStateListener(stateListener);
 
--- a/mailnews/compose/src/nsMsgCompFields.cpp
+++ b/mailnews/compose/src/nsMsgCompFields.cpp
@@ -42,30 +42,29 @@
 #include "nsMsgRecipientArray.h"
 #include "nsIMsgHeaderParser.h"
 #include "nsMsgCompUtils.h"
 #include "nsMsgUtils.h"
 #include "prmem.h"
 #include "nsIFileChannel.h"
 #include "nsIMsgMdnGenerator.h"
 #include "nsServiceManagerUtils.h"
+#include "nsArrayEnumerator.h"
 
 /* the following macro actually implement addref, release and query interface for our component. */
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsMsgCompFields, nsIMsgCompFields)
 
 nsMsgCompFields::nsMsgCompFields()
 {
   PRInt16 i;
   for (i = 0; i < MSG_MAX_HEADERS; i ++)
     m_headers[i] = nsnull;
 
   m_body.Truncate();
 
-  NS_NewISupportsArray(getter_AddRefs(m_attachments));
-
   m_attachVCard = PR_FALSE;
   m_forcePlainText = PR_FALSE;
   m_useMultipartAlternative = PR_FALSE;
   m_returnReceipt = PR_FALSE;
   m_receiptHeaderType = nsIMsgMdnGenerator::eDntType;
   m_DSN = PR_FALSE;
   m_bodyIsAsciiOnly = PR_FALSE;
   m_forceMsgEncoding = PR_FALSE;
@@ -475,84 +474,65 @@ nsresult nsMsgCompFields::SetBody(const 
   return NS_OK;
 }
 
 const char* nsMsgCompFields::GetBody()
 {
     return m_body.get();
 }
 
-/* readonly attribute nsISupportsArray attachmentsArray; */
-NS_IMETHODIMP nsMsgCompFields::GetAttachmentsArray(nsISupportsArray * *aAttachmentsArray)
+/* readonly attribute nsISimpleEnumerator attachmentsArray; */
+NS_IMETHODIMP nsMsgCompFields::GetAttachments(nsISimpleEnumerator * *aAttachmentsEnum)
 {
-  NS_ENSURE_ARG_POINTER(aAttachmentsArray);
-  *aAttachmentsArray = m_attachments;
-  NS_IF_ADDREF(*aAttachmentsArray);
-  return NS_OK;
+  return aAttachmentsEnum ? NS_NewArrayEnumerator(aAttachmentsEnum, m_attachments) : NS_ERROR_NULL_POINTER;
 }
 
 /* void addAttachment (in nsIMsgAttachment attachment); */
 NS_IMETHODIMP nsMsgCompFields::AddAttachment(nsIMsgAttachment *attachment)
 {
-  PRUint32 i;
-  PRUint32 attachmentCount = 0;
-  m_attachments->Count(&attachmentCount);
+  PRInt32 attachmentCount = m_attachments.Count();
 
   //Don't add twice the same attachment.
   nsCOMPtr<nsIMsgAttachment> element;
   PRBool sameUrl;
-  for (i = 0; i < attachmentCount; i ++)
+  for (PRInt32 i = 0; i < attachmentCount; i ++)
   {
-    m_attachments->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
-    if (element)
-    {
-      element->EqualsUrl(attachment, &sameUrl);
-      if (sameUrl)
-        return NS_OK;
-    }
+    m_attachments[i]->EqualsUrl(attachment, &sameUrl);
+    if (sameUrl)
+      return NS_OK;
   }
+  m_attachments.AppendObject(attachment);
 
-  return m_attachments->InsertElementAt(attachment, attachmentCount);
+  return NS_OK;
 }
 
 /* void removeAttachment (in nsIMsgAttachment attachment); */
 NS_IMETHODIMP nsMsgCompFields::RemoveAttachment(nsIMsgAttachment *attachment)
 {
-  PRUint32 i;
-  PRUint32 attachmentCount = 0;
-  m_attachments->Count(&attachmentCount);
+  PRInt32 attachmentCount = m_attachments.Count();
 
   nsCOMPtr<nsIMsgAttachment> element;
   PRBool sameUrl;
-  for (i = 0; i < attachmentCount; i ++)
+  for (PRInt32 i = 0; i < attachmentCount; i ++)
   {
-    m_attachments->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
-    if (element)
+    m_attachments[i]->EqualsUrl(attachment, &sameUrl);
+    if (sameUrl)
     {
-      element->EqualsUrl(attachment, &sameUrl);
-      if (sameUrl)
-      {
-        m_attachments->DeleteElementAt(i);
-        break;
-      }
+      m_attachments.RemoveObjectAt(i);
+      break;
     }
   }
 
   return NS_OK;
 }
 
 /* void removeAttachments (); */
 NS_IMETHODIMP nsMsgCompFields::RemoveAttachments()
 {
-  PRUint32 i;
-  PRUint32 attachmentCount = 0;
-  m_attachments->Count(&attachmentCount);
-
-  for (i = 0; i < attachmentCount; i ++)
-    m_attachments->DeleteElementAt(0);
+  m_attachments.Clear();
 
   return NS_OK;
 }
 
 
 // This method is called during the creation of a new window.
 NS_IMETHODIMP nsMsgCompFields::SplitRecipients(const nsAString &aRecipients, PRBool aEmailAddressOnly, nsIMsgRecipientArray **_retval)
 {
--- a/mailnews/compose/src/nsMsgCompFields.h
+++ b/mailnews/compose/src/nsMsgCompFields.h
@@ -38,16 +38,17 @@
 
 #ifndef _MsgCompFields_H_
 #define _MsgCompFields_H_
 
 #include "nsIMsgCompFields.h"
 #include "msgCore.h"
 #include "nsIAbCard.h"
 #include "nsTArray.h"
+#include "nsCOMArray.h"
 
 struct nsMsgRecipient
 {
   nsMsgRecipient() : mPreferFormat(nsIAbPreferMailFormat::unknown),
                      mProcessed(PR_FALSE) {}
 
   nsMsgRecipient(const nsMsgRecipient &other)
   {
@@ -192,17 +193,17 @@ public:
   const char* GetBody();
 
   nsresult SplitRecipientsEx(const nsAString &recipients,
                              nsTArray<nsMsgRecipient> &aResult); 
 
 protected:
   char*       m_headers[MSG_MAX_HEADERS];
   nsCString   m_body;
-  nsCOMPtr<nsISupportsArray>  m_attachments;
+  nsCOMArray<nsIMsgAttachment> m_attachments;
   PRBool      m_attachVCard;
   PRBool      m_forcePlainText;
   PRBool      m_useMultipartAlternative;
   PRBool      m_returnReceipt;
   PRBool      m_DSN;
   PRBool      m_bodyIsAsciiOnly;
   PRBool      m_forceMsgEncoding;
   PRInt32     m_receiptHeaderType;        /* receipt header type */
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -2181,34 +2181,35 @@ nsMsgComposeAndSend::ProcessMultipartRel
 nsresult
 nsMsgComposeAndSend::CountCompFieldAttachments()
 {
   //Reset the counters
   mCompFieldLocalAttachments = 0;
   mCompFieldRemoteAttachments = 0;
 
   //Get the attachments array
-  nsCOMPtr<nsISupportsArray> attachmentsArray;
-  mCompFields->GetAttachmentsArray(getter_AddRefs(attachmentsArray));
-  if (!attachmentsArray)
+  nsCOMPtr<nsISimpleEnumerator> attachments;
+  mCompFields->GetAttachments(getter_AddRefs(attachments));
+  if (!attachments)
     return NS_OK;
 
-  PRUint32 i;
-  PRUint32 attachmentCount = 0;
-  attachmentsArray->Count(&attachmentCount);
-
-  //Parse the attachments array
-  nsCOMPtr<nsIMsgAttachment> element;
+  nsresult rv;
+
+  // Parse the attachments array
+  PRBool moreAttachments;
   nsCString url;
-  for (i = 0; i < attachmentCount; i ++)
-  {
-    attachmentsArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
-    if (element)
+  nsCOMPtr<nsISupports> element;
+  while (NS_SUCCEEDED(attachments->HasMoreElements(&moreAttachments)) && moreAttachments) {
+    rv = attachments->GetNext(getter_AddRefs(element));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIMsgAttachment> attachment = do_QueryInterface(element, &rv);
+    if (NS_SUCCEEDED(rv) && attachment)
     {
-      element->GetUrl(getter_Copies(url));
+      attachment->GetUrl(getter_Copies(url));
       if (!url.IsEmpty())
     {
       // Check to see if this is a file URL, if so, don't retrieve
       // like a remote URL...
         if (nsMsgIsLocalFile(url.get()))
       {
         mCompFieldLocalAttachments++;
 #if defined(DEBUG_ducarroz)
@@ -2235,35 +2236,36 @@ nsMsgComposeAndSend::CountCompFieldAttac
 nsresult
 nsMsgComposeAndSend::AddCompFieldLocalAttachments()
 {
   // If none, just return...
   if (mCompFieldLocalAttachments <= 0)
     return NS_OK;
 
   //Get the attachments array
-  nsCOMPtr<nsISupportsArray> attachmentsArray;
-  mCompFields->GetAttachmentsArray(getter_AddRefs(attachmentsArray));
-  if (!attachmentsArray)
+  nsCOMPtr<nsISimpleEnumerator> attachments;
+  mCompFields->GetAttachments(getter_AddRefs(attachments));
+  if (!attachments)
     return NS_OK;
 
-  PRUint32 i;
   PRUint32  newLoc = 0;
-  PRUint32 attachmentCount = 0;
-  attachmentsArray->Count(&attachmentCount);
+  nsresult rv;
+  nsCString url;
 
   //Parse the attachments array
-  nsCOMPtr<nsIMsgAttachment> element;
-  nsCString url;
-  for (i = 0; i < attachmentCount; i ++)
-  {
-    attachmentsArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
-    if (element)
+  PRBool moreAttachments;
+  nsCOMPtr<nsISupports> element;
+  while (NS_SUCCEEDED(attachments->HasMoreElements(&moreAttachments)) && moreAttachments) {
+    rv = attachments->GetNext(getter_AddRefs(element));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIMsgAttachment> attachment = do_QueryInterface(element, &rv);
+    if (NS_SUCCEEDED(rv) && attachment)
     {
-      element->GetUrl(getter_Copies(url));
+      attachment->GetUrl(getter_Copies(url));
       if (!url.IsEmpty())
       {
         // Just look for local file:// attachments and do the right thing.
         if (nsMsgIsLocalFile(url.get()))
         {
   #if defined(DEBUG_ducarroz)
           printf("Adding LOCAL attachment %d: %s\n", newLoc, url.get());
   #endif
@@ -2291,32 +2293,32 @@ nsMsgComposeAndSend::AddCompFieldLocalAt
           NS_ENSURE_SUCCESS(rv, rv);
           nsCOMPtr <nsIFile> fileURLFile;
           fileURL->GetFile(getter_AddRefs(fileURLFile));
           m_attachments[newLoc].mTmpFile = do_QueryInterface(fileURLFile);
           m_attachments[newLoc].mDeleteFile = PR_FALSE;
           if (m_attachments[newLoc].mURL)
           {
             nsAutoString proposedName;
-            element->GetName(proposedName);
+            attachment->GetName(proposedName);
             msg_pick_real_name(&m_attachments[newLoc], proposedName.get(), mCompFields->GetCharacterSet());
           }
 
           // Now, most importantly, we need to figure out what the content type is for
           // this attachment...If we can't, then just make it application/octet-stream
 
   #ifdef MAC_OSX
           //Mac always need to snarf the file to figure out how to send it, maybe we need to use apple double...
           //  unless caller has already set the content type, in which case, trust them.
           PRBool mustSnarfAttachment = PR_TRUE;
   #else
           PRBool mustSnarfAttachment = PR_FALSE;
   #endif
           PR_FREEIF(m_attachments[newLoc].m_type);
-          element->GetContentType(&m_attachments[newLoc].m_type);
+          attachment->GetContentType(&m_attachments[newLoc].m_type);
           if (!m_attachments[newLoc].m_type || !(*m_attachments[newLoc].m_type))
           {
             nsresult  rv = NS_OK;
             nsCOMPtr<nsIMIMEService> mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
             if (NS_SUCCEEDED(rv) && mimeFinder)
             {
               nsCOMPtr<nsIURL> fileUrl(do_CreateInstance(NS_STANDARDURL_CONTRACTID));
               if (fileUrl)
@@ -2359,17 +2361,17 @@ nsMsgComposeAndSend::AddCompFieldLocalAt
                     }
                   }
                 }
               }
             }
           }
           else
           {
-            element->GetContentTypeParam(&m_attachments[newLoc].m_type_param);
+            attachment->GetContentTypeParam(&m_attachments[newLoc].m_type_param);
             mustSnarfAttachment = PR_FALSE;
           }
 
           //We need to snarf the file to figure out how to send it only if we don't have a content type...
           if (mustSnarfAttachment || (!m_attachments[newLoc].m_type) || (!*m_attachments[newLoc].m_type))
           {
             m_attachments[newLoc].m_done = PR_FALSE;
             m_attachments[newLoc].SetMimeDeliveryState(this);
@@ -2390,19 +2392,19 @@ nsMsgComposeAndSend::AddCompFieldLocalAt
               {
                 PR_FREEIF(m_attachments[newLoc].m_charset);
                 m_attachments[newLoc].m_charset = PL_strdup(tmpCharset);
               }
             }
           }
 
           PR_FREEIF(m_attachments[newLoc].m_x_mac_type);
-          element->GetMacType(&m_attachments[newLoc].m_x_mac_type);
+          attachment->GetMacType(&m_attachments[newLoc].m_x_mac_type);
           PR_FREEIF(m_attachments[newLoc].m_x_mac_creator);
-          element->GetMacCreator(&m_attachments[newLoc].m_x_mac_creator);
+          attachment->GetMacCreator(&m_attachments[newLoc].m_x_mac_creator);
 
           ++newLoc;
         }
       }
     }
   }
   return NS_OK;
 }
@@ -2412,35 +2414,35 @@ nsMsgComposeAndSend::AddCompFieldRemoteA
                                                    PRInt32    *aMailboxCount,
                                                    PRInt32    *aNewsCount)
 {
   // If none, just return...
   if (mCompFieldRemoteAttachments <= 0)
     return NS_OK;
 
   //Get the attachments array
-  nsCOMPtr<nsISupportsArray> attachmentsArray;
-  mCompFields->GetAttachmentsArray(getter_AddRefs(attachmentsArray));
-  if (!attachmentsArray)
+  nsCOMPtr<nsISimpleEnumerator> attachments;
+  mCompFields->GetAttachments(getter_AddRefs(attachments));
+  if (!attachments)
     return NS_OK;
 
-  PRUint32 i;
   PRUint32  newLoc = aStartLocation;
-  PRUint32 attachmentCount = 0;
-  attachmentsArray->Count(&attachmentCount);
-
-  //Parse the attachments array
-  nsCOMPtr<nsIMsgAttachment> element;
+
+  nsresult rv;
+  PRBool moreAttachments;
   nsCString url;
-  for (i = 0; i < attachmentCount; i ++)
-  {
-    attachmentsArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
-    if (element)
+  nsCOMPtr<nsISupports> element;
+  while (NS_SUCCEEDED(attachments->HasMoreElements(&moreAttachments)) && moreAttachments) {
+    rv = attachments->GetNext(getter_AddRefs(element));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIMsgAttachment> attachment = do_QueryInterface(element, &rv);
+    if (NS_SUCCEEDED(rv) && attachment)
     {
-      element->GetUrl(getter_Copies(url));
+      attachment->GetUrl(getter_Copies(url));
       if (!url.IsEmpty())
       {
         // Just look for files that are NOT local file attachments and do
         // the right thing.
         if (! nsMsgIsLocalFile(url.get()))
         {
 #if defined(DEBUG_ducarroz)
           printf("Adding REMOTE attachment %d: %s\n", newLoc, url.get());
@@ -2455,19 +2457,19 @@ nsMsgComposeAndSend::AddCompFieldRemoteA
 
           if (!isAMessageAttachment)
             nsMsgNewURL(getter_AddRefs(m_attachments[newLoc].mURL), url.get());
 
           PR_FREEIF(m_attachments[newLoc].m_encoding);
           m_attachments[newLoc].m_encoding = PL_strdup ("7bit");
 
           PR_FREEIF(m_attachments[newLoc].m_x_mac_type);
-          element->GetMacType(&m_attachments[newLoc].m_x_mac_type);
+          attachment->GetMacType(&m_attachments[newLoc].m_x_mac_type);
           PR_FREEIF(m_attachments[newLoc].m_x_mac_creator);
-          element->GetMacCreator(&m_attachments[newLoc].m_x_mac_creator);
+          attachment->GetMacCreator(&m_attachments[newLoc].m_x_mac_creator);
 
           /* Count up attachments which are going to come from mail folders
              and from NNTP servers. */
           PRBool do_add_attachment = PR_FALSE;
           if (isAMessageAttachment)
           {
             do_add_attachment = PR_TRUE;
             if (!PL_strncasecmp(url.get(), "news-message://", 15))
@@ -2479,17 +2481,17 @@ nsMsgComposeAndSend::AddCompFieldRemoteA
             m_attachments[newLoc].mURL = nsnull;
           }
           else
             do_add_attachment = (nsnull != m_attachments[newLoc].mURL);
 
           if (do_add_attachment)
           {
             nsAutoString proposedName;
-            element->GetName(proposedName);
+            attachment->GetName(proposedName);
             msg_pick_real_name(&m_attachments[newLoc], proposedName.get(), mCompFields->GetCharacterSet());
             ++newLoc;
           }
         }
       }
     }
   }
   return NS_OK;
@@ -3026,32 +3028,29 @@ nsMsgComposeAndSend::InitCompositionFiel
   SetMimeHeader(nsMsgCompFields::MSG_BCC_HEADER_ID, fields->GetBcc());
   SetMimeHeader(nsMsgCompFields::MSG_NEWSGROUPS_HEADER_ID, fields->GetNewsgroups());
   SetMimeHeader(nsMsgCompFields::MSG_FOLLOWUP_TO_HEADER_ID, fields->GetFollowupTo());
   SetMimeHeader(nsMsgCompFields::MSG_ORGANIZATION_HEADER_ID, fields->GetOrganization());
   SetMimeHeader(nsMsgCompFields::MSG_SUBJECT_HEADER_ID, fields->GetSubject());
   SetMimeHeader(nsMsgCompFields::MSG_REFERENCES_HEADER_ID, fields->GetReferences());
   SetMimeHeader(nsMsgCompFields::MSG_X_TEMPLATE_HEADER_ID, fields->GetTemplateName());
 
-  nsCOMPtr<nsISupportsArray> srcAttachmentArray;
-  fields->GetAttachmentsArray(getter_AddRefs(srcAttachmentArray));
-  if (srcAttachmentArray)
+  nsCOMPtr<nsISimpleEnumerator> srcAttachments;
+  fields->GetAttachments(getter_AddRefs(srcAttachments));
+  if (srcAttachments)
   {
-    PRUint32 i;
-    PRUint32 attachmentCount = 0;
-    srcAttachmentArray->Count(&attachmentCount);
-    if (attachmentCount > 0)
-    {
-      nsCOMPtr<nsIMsgAttachment> element;
-      for (i = 0; i < attachmentCount; i ++)
-      {
-        srcAttachmentArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
-        if (element)
-          mCompFields->AddAttachment(element);
-      }
+    PRBool moreAttachments;
+    nsCOMPtr<nsISupports> element;
+    while (NS_SUCCEEDED(srcAttachments->HasMoreElements(&moreAttachments)) && moreAttachments) {
+      rv = srcAttachments->GetNext(getter_AddRefs(element));
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      nsCOMPtr<nsIMsgAttachment> attachment = do_QueryInterface(element, &rv);
+      NS_ENSURE_SUCCESS(rv, rv);
+      mCompFields->AddAttachment(attachment);
     }
   }
 
   pStr = fields->GetOtherRandomHeaders();
   if (pStr)
     mCompFields->SetOtherRandomHeaders((char *) pStr);
 
   AddDefaultCustomHeaders();
--- a/mailnews/compose/src/nsMsgSend.h
+++ b/mailnews/compose/src/nsMsgSend.h
@@ -154,16 +154,17 @@
 #include "nsIMsgStatusFeedback.h"
 #include "nsIMsgIdentity.h"
 #include "nsIMsgHdr.h"
 #include "nsIMsgIdentity.h"
 #include "nsWeakReference.h"
 #include "nsIDOMWindowInternal.h"
 #include "nsIMsgComposeSecure.h"
 #include "nsAutoPtr.h"
+#include "nsISupportsArray.h"
 
 //
 // Some necessary defines...
 //
 #define TEN_K                 10240
 #define MIME_BUFFER_SIZE      4096 // must be greater than 1000
                                    // SMTP (RFC821) limit