From d6bb465ae8f2c6fac34274cb2fc8b2a0435dd1e2 Mon Sep 17 00:00:00 2001 From: Ben Campbell Date: Thu, 17 Dec 2020 11:03:34 +1300 Subject: [PATCH] Bug 1682943 - Remove nsISimpleEnumerator use in nsIMsgCompFields.idl. r=mkmelin --- .../compose/content/MsgComposeCommands.js | 18 +- .../composition/browser_attachmentReminder.js | 4 +- mailnews/compose/public/nsIMsgCompFields.idl | 3 +- mailnews/compose/src/nsMsgCompFields.cpp | 33 +- mailnews/compose/src/nsMsgCompFields.h | 2 +- mailnews/compose/src/nsMsgSend.cpp | 464 ++++++++---------- 6 files changed, 229 insertions(+), 295 deletions(-) diff --git a/mail/components/compose/content/MsgComposeCommands.js b/mail/components/compose/content/MsgComposeCommands.js index 42bf8e32e2..b8b7adf7d4 100644 --- a/mail/components/compose/content/MsgComposeCommands.js +++ b/mail/components/compose/content/MsgComposeCommands.js @@ -5844,17 +5844,15 @@ function FileToAttachment(file) { } /** - * Add a list of attachment objects as attachments. The attachment URLs must be - * set. + * Add a list of attachment objects as attachments. The attachment URLs must + * be set. * - * @param aAttachments an iterable list of nsIMsgAttachment objects to add as - * attachments. Anything iterable with fixIterator is - * accepted. - * @param aCallback an optional callback function called immediately after - * adding each attachment. Takes one argument: - * the newly-added node. - * @param aContentChanged {Boolean} optional value to assign to gContentChanged - * after adding attachments; defaults to true. + * @param {nsIMsgAttachment[]} aAttachments - Objects to add as attachments. + * @param {function} [aCallback] - An optional callback function called after + * adding each attachment. Takes one argument: the newly-added + * node. + * @param {Boolean} [aContentChanged=true] - Optional value to assign gContentChanged + * after adding attachments. */ function AddAttachments(aAttachments, aCallback, aContentChanged = true) { let bucket = document.getElementById("attachmentBucket"); diff --git a/mail/test/browser/composition/browser_attachmentReminder.js b/mail/test/browser/composition/browser_attachmentReminder.js index c9376992a4..54544fc201 100644 --- a/mail/test/browser/composition/browser_attachmentReminder.js +++ b/mail/test/browser/composition/browser_attachmentReminder.js @@ -261,8 +261,8 @@ add_task(function test_attachment_reminder_with_attachment() { file.exists(), "The required file panacea.dat was not found in the profile." ); - let attachment = [cwc.window.FileToAttachment(file)]; - cwc.window.AddAttachments(attachment); + let attachments = [cwc.window.FileToAttachment(file)]; + cwc.window.AddAttachments(attachments); // The notification should hide. wait_for_reminder_state(cwc, false); diff --git a/mailnews/compose/public/nsIMsgCompFields.idl b/mailnews/compose/public/nsIMsgCompFields.idl index d03bc6c2e0..a7986c9c4c 100644 --- a/mailnews/compose/public/nsIMsgCompFields.idl +++ b/mailnews/compose/public/nsIMsgCompFields.idl @@ -6,7 +6,6 @@ #include "msgIStructuredHeaders.idl" interface nsIMsgAttachment; -interface nsISimpleEnumerator; interface nsIMsgComposeSecure; /** @@ -64,7 +63,7 @@ interface nsIMsgCompFields : msgIWritableStructuredHeaders { */ attribute AString body; - readonly attribute nsISimpleEnumerator attachments; + readonly attribute Array attachments; void addAttachment(in nsIMsgAttachment attachment); void removeAttachment(in nsIMsgAttachment attachment); void removeAttachments(); diff --git a/mailnews/compose/src/nsMsgCompFields.cpp b/mailnews/compose/src/nsMsgCompFields.cpp index 7f39e545b5..3d6e65909f 100644 --- a/mailnews/compose/src/nsMsgCompFields.cpp +++ b/mailnews/compose/src/nsMsgCompFields.cpp @@ -449,41 +449,30 @@ nsresult nsMsgCompFields::SetBody(const char* value) { const char* nsMsgCompFields::GetBody() { return m_body.get(); } -/* readonly attribute nsISimpleEnumerator attachmentsArray; */ NS_IMETHODIMP nsMsgCompFields::GetAttachments( - nsISimpleEnumerator** aAttachmentsEnum) { - return aAttachmentsEnum - ? NS_NewArrayEnumerator(aAttachmentsEnum, m_attachments, - NS_GET_IID(nsIMsgAttachment)) - : NS_ERROR_NULL_POINTER; + nsTArray>& attachments) { + attachments = m_attachments.Clone(); + return NS_OK; } -/* void addAttachment (in nsIMsgAttachment attachment); */ NS_IMETHODIMP nsMsgCompFields::AddAttachment(nsIMsgAttachment* attachment) { - int32_t attachmentCount = m_attachments.Count(); - - // Don't add twice the same attachment. - nsCOMPtr element; - bool sameUrl; - for (int32_t i = 0; i < attachmentCount; i++) { - m_attachments[i]->EqualsUrl(attachment, &sameUrl); + // Don't add the same attachment twice. + for (nsIMsgAttachment* a : m_attachments) { + bool sameUrl; + a->EqualsUrl(attachment, &sameUrl); if (sameUrl) return NS_OK; } - m_attachments.AppendObject(attachment); - + m_attachments.AppendElement(attachment); return NS_OK; } /* void removeAttachment (in nsIMsgAttachment attachment); */ NS_IMETHODIMP nsMsgCompFields::RemoveAttachment(nsIMsgAttachment* attachment) { - int32_t attachmentCount = m_attachments.Count(); - - nsCOMPtr element; - bool sameUrl; - for (int32_t i = 0; i < attachmentCount; i++) { + for (uint32_t i = 0; i < m_attachments.Length(); i++) { + bool sameUrl; m_attachments[i]->EqualsUrl(attachment, &sameUrl); if (sameUrl) { - m_attachments.RemoveObjectAt(i); + m_attachments.RemoveElementAt(i); break; } } diff --git a/mailnews/compose/src/nsMsgCompFields.h b/mailnews/compose/src/nsMsgCompFields.h index 7b178822ad..37c242652b 100644 --- a/mailnews/compose/src/nsMsgCompFields.h +++ b/mailnews/compose/src/nsMsgCompFields.h @@ -193,7 +193,7 @@ class nsMsgCompFields : public nsIMsgCompFields { virtual ~nsMsgCompFields(); nsCString m_headers[MSG_MAX_HEADERS]; nsCString m_body; - nsCOMArray m_attachments; + nsTArray> m_attachments; bool m_attachVCard; bool m_attachmentReminder; int32_t m_deliveryFormat; diff --git a/mailnews/compose/src/nsMsgSend.cpp b/mailnews/compose/src/nsMsgSend.cpp index 7edbb4a291..1f1d76c28d 100644 --- a/mailnews/compose/src/nsMsgSend.cpp +++ b/mailnews/compose/src/nsMsgSend.cpp @@ -1625,36 +1625,21 @@ nsresult nsMsgComposeAndSend::CountCompFieldAttachments() { mCompFieldLocalAttachments = 0; mCompFieldRemoteAttachments = 0; - // Get the attachments array - nsCOMPtr attachments; - mCompFields->GetAttachments(getter_AddRefs(attachments)); - if (!attachments) return NS_OK; - - nsresult rv; - // Parse the attachments array - bool moreAttachments; - nsCString url; - nsCOMPtr element; - while (NS_SUCCEEDED(attachments->HasMoreElements(&moreAttachments)) && - moreAttachments) { - rv = attachments->GetNext(getter_AddRefs(element)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr attachment = do_QueryInterface(element, &rv); - if (NS_SUCCEEDED(rv) && attachment) { - attachment->GetUrl(url); - if (!url.IsEmpty()) { - // Check to see if this is a file URL, if so, don't retrieve - // like a remote URL... - if (PL_strncasecmp(url.get(), "file://", 7) == 0) - mCompFieldLocalAttachments++; - else // This is a remote URL... - mCompFieldRemoteAttachments++; - } + nsTArray> attachments; + mCompFields->GetAttachments(attachments); + for (nsIMsgAttachment* attachment : attachments) { + nsCString url; + attachment->GetUrl(url); + if (!url.IsEmpty()) { + // Check to see if this is a file URL, if so, don't retrieve + // like a remote URL... + if (PL_strncasecmp(url.get(), "file://", 7) == 0) + mCompFieldLocalAttachments++; + else // This is a remote URL... + mCompFieldRemoteAttachments++; } } - return NS_OK; } @@ -1665,183 +1650,169 @@ nsresult nsMsgComposeAndSend::AddCompFieldLocalAttachments() { // If none, just return... if (mCompFieldLocalAttachments <= 0) return NS_OK; - // Get the attachments array - nsCOMPtr attachments; - mCompFields->GetAttachments(getter_AddRefs(attachments)); - if (!attachments) return NS_OK; - - uint32_t newLoc = 0; - nsresult rv; - nsCString url; - // Parse the attachments array - bool moreAttachments; - nsCOMPtr element; - while (NS_SUCCEEDED(attachments->HasMoreElements(&moreAttachments)) && - moreAttachments) { - rv = attachments->GetNext(getter_AddRefs(element)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr attachment = do_QueryInterface(element, &rv); - if (NS_SUCCEEDED(rv) && attachment) { - bool sendViaCloud = false; + nsTArray> attachments; + mCompFields->GetAttachments(attachments); + uint32_t newLoc = 0; + for (nsIMsgAttachment* attachment : attachments) { + bool sendViaCloud = false; + attachment->GetSendViaCloud(&sendViaCloud); + m_attachments[newLoc]->mSendViaCloud = sendViaCloud; + nsCString url; + attachment->GetUrl(url); + if (!url.IsEmpty()) { + bool sendViaCloud; attachment->GetSendViaCloud(&sendViaCloud); - m_attachments[newLoc]->mSendViaCloud = sendViaCloud; - attachment->GetUrl(url); - if (!url.IsEmpty()) { - bool sendViaCloud; - attachment->GetSendViaCloud(&sendViaCloud); - if (sendViaCloud) { - nsCString cloudFileAccountKey; - // We'd like to output a part for the attachment, just an html part - // with information about how to download the attachment. - // m_attachments[newLoc]->m_done = true; - attachment->GetHtmlAnnotation(m_attachments[newLoc]->mHtmlAnnotation); - m_attachments[newLoc]->m_type.AssignLiteral("text/html"); - attachment->GetCloudFileAccountKey( - m_attachments[newLoc]->mCloudFileAccountKey); - attachment->GetContentLocation(m_attachments[newLoc]->mCloudUrl); + if (sendViaCloud) { + nsCString cloudFileAccountKey; + // We'd like to output a part for the attachment, just an html part + // with information about how to download the attachment. + // m_attachments[newLoc]->m_done = true; + attachment->GetHtmlAnnotation(m_attachments[newLoc]->mHtmlAnnotation); + m_attachments[newLoc]->m_type.AssignLiteral("text/html"); + attachment->GetCloudFileAccountKey( + m_attachments[newLoc]->mCloudFileAccountKey); + attachment->GetContentLocation(m_attachments[newLoc]->mCloudUrl); + } + // Just look for local file:// attachments and do the right thing. + if (PL_strncasecmp(url.get(), "file://", 7) == 0) { + // + // Now we have to setup the m_attachments entry for the file:// + // URL that is passed in... + // + m_attachments[newLoc]->mDeleteFile = false; + + nsMsgNewURL(getter_AddRefs(m_attachments[newLoc]->mURL), url); + + if (m_attachments[newLoc]->mTmpFile) { + if (m_attachments[newLoc]->mDeleteFile) + m_attachments[newLoc]->mTmpFile->Remove(false); + m_attachments[newLoc]->mTmpFile = nullptr; + } + nsresult rv; + nsCOMPtr ioService = mozilla::services::GetIOService(); + NS_ENSURE_TRUE(ioService, NS_ERROR_UNEXPECTED); + nsCOMPtr uri; + rv = ioService->NewURI(url, nullptr, nullptr, getter_AddRefs(uri)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr fileURL = do_QueryInterface(uri); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr fileURLFile; + fileURL->GetFile(getter_AddRefs(fileURLFile)); + m_attachments[newLoc]->mTmpFile = fileURLFile; + m_attachments[newLoc]->mDeleteFile = false; + if (m_attachments[newLoc]->mURL) { + nsAutoString proposedName; + attachment->GetName(proposedName); + msg_pick_real_name(m_attachments[newLoc], proposedName.get()); } - // Just look for local file:// attachments and do the right thing. - if (PL_strncasecmp(url.get(), "file://", 7) == 0) { - // - // Now we have to setup the m_attachments entry for the file:// - // URL that is passed in... - // - m_attachments[newLoc]->mDeleteFile = false; - nsMsgNewURL(getter_AddRefs(m_attachments[newLoc]->mURL), url); - - if (m_attachments[newLoc]->mTmpFile) { - if (m_attachments[newLoc]->mDeleteFile) - m_attachments[newLoc]->mTmpFile->Remove(false); - m_attachments[newLoc]->mTmpFile = nullptr; - } - nsresult rv; - nsCOMPtr ioService = mozilla::services::GetIOService(); - NS_ENSURE_TRUE(ioService, NS_ERROR_UNEXPECTED); - nsCOMPtr uri; - rv = ioService->NewURI(url, nullptr, nullptr, getter_AddRefs(uri)); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr fileURL = do_QueryInterface(uri); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr fileURLFile; - fileURL->GetFile(getter_AddRefs(fileURLFile)); - m_attachments[newLoc]->mTmpFile = fileURLFile; - m_attachments[newLoc]->mDeleteFile = false; - if (m_attachments[newLoc]->mURL) { - nsAutoString proposedName; - attachment->GetName(proposedName); - msg_pick_real_name(m_attachments[newLoc], proposedName.get()); - } - - // 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. + // 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. - bool mustSnarfAttachment = true; + // 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. + bool mustSnarfAttachment = true; #else - bool mustSnarfAttachment = false; + bool mustSnarfAttachment = false; #endif - if (sendViaCloud) mustSnarfAttachment = false; + if (sendViaCloud) mustSnarfAttachment = false; - attachment->GetContentType( - getter_Copies(m_attachments[newLoc]->m_type)); - if (m_attachments[newLoc]->m_type.IsEmpty()) { - nsresult rv = NS_OK; - nsCOMPtr mimeFinder( - do_GetService(NS_MIMESERVICE_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && mimeFinder) { - nsCOMPtr fileUrl; - rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID) - .Apply(NS_MutatorMethod( - &nsIURLMutator::SetFileName, - m_attachments[newLoc]->m_realName, nullptr)) - .Finalize(fileUrl); - if (NS_SUCCEEDED(rv)) { - nsAutoCString fileExt; - // First try using the real file name. - rv = fileUrl->GetFileExtension(fileExt); - if (NS_SUCCEEDED(rv) && !fileExt.IsEmpty()) { - nsAutoCString type; - mimeFinder->GetTypeFromExtension(fileExt, type); + attachment->GetContentType( + getter_Copies(m_attachments[newLoc]->m_type)); + if (m_attachments[newLoc]->m_type.IsEmpty()) { + nsresult rv = NS_OK; + nsCOMPtr mimeFinder( + do_GetService(NS_MIMESERVICE_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv) && mimeFinder) { + nsCOMPtr fileUrl; + rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID) + .Apply(NS_MutatorMethod(&nsIURLMutator::SetFileName, + m_attachments[newLoc]->m_realName, + nullptr)) + .Finalize(fileUrl); + if (NS_SUCCEEDED(rv)) { + nsAutoCString fileExt; + // First try using the real file name. + rv = fileUrl->GetFileExtension(fileExt); + if (NS_SUCCEEDED(rv) && !fileExt.IsEmpty()) { + nsAutoCString type; + mimeFinder->GetTypeFromExtension(fileExt, type); #ifndef XP_MACOSX - if (!type.EqualsLiteral( - "multipart/appledouble")) // can't do apple double on - // non-macs + if (!type.EqualsLiteral( + "multipart/appledouble")) // can't do apple double on + // non-macs #endif - m_attachments[newLoc]->m_type = type; - } + m_attachments[newLoc]->m_type = type; + } - // Then try using the url if we still haven't figured out the - // content type - if (m_attachments[newLoc]->m_type.IsEmpty()) { - rv = NS_MutateURI(fileUrl).SetSpec(url).Finalize(fileUrl); - if (NS_SUCCEEDED(rv)) { - rv = fileUrl->GetFileExtension(fileExt); - if (NS_SUCCEEDED(rv) && !fileExt.IsEmpty()) { - nsAutoCString type; - mimeFinder->GetTypeFromExtension(fileExt, type); + // Then try using the url if we still haven't figured out the + // content type + if (m_attachments[newLoc]->m_type.IsEmpty()) { + rv = NS_MutateURI(fileUrl).SetSpec(url).Finalize(fileUrl); + if (NS_SUCCEEDED(rv)) { + rv = fileUrl->GetFileExtension(fileExt); + if (NS_SUCCEEDED(rv) && !fileExt.IsEmpty()) { + nsAutoCString type; + mimeFinder->GetTypeFromExtension(fileExt, type); #ifndef XP_MACOSX - if (!type.EqualsLiteral( - "multipart/appledouble")) // can't do apple - // double on non-macs + if (!type.EqualsLiteral( + "multipart/appledouble")) // can't do apple + // double on non-macs #endif - m_attachments[newLoc]->m_type = type; - // rtf and vcs files may look like text to sniffers, - // but they're not human readable. - if (type.IsEmpty() && !fileExt.IsEmpty() && - (fileExt.LowerCaseEqualsLiteral("rtf") || - fileExt.LowerCaseEqualsLiteral("vcs"))) - m_attachments[newLoc]->m_type = - APPLICATION_OCTET_STREAM; - } + m_attachments[newLoc]->m_type = type; + // rtf and vcs files may look like text to sniffers, + // but they're not human readable. + if (type.IsEmpty() && !fileExt.IsEmpty() && + (fileExt.LowerCaseEqualsLiteral("rtf") || + fileExt.LowerCaseEqualsLiteral("vcs"))) + m_attachments[newLoc]->m_type = APPLICATION_OCTET_STREAM; } } } } - } else { - attachment->GetContentTypeParam( - getter_Copies(m_attachments[newLoc]->m_typeParam)); - mustSnarfAttachment = false; - if (m_attachments[newLoc]->m_type.EqualsLiteral("application/pgp-keys")) { - m_attachments[newLoc]->m_description = nsLiteralCString("OpenPGP public key"); - } } - - // 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.IsEmpty()) { - m_attachments[newLoc]->m_done = false; - m_attachments[newLoc]->SetMimeDeliveryState(this); - } else { - m_attachments[newLoc]->m_done = true; - m_attachments[newLoc]->SetMimeDeliveryState(nullptr); + } else { + attachment->GetContentTypeParam( + getter_Copies(m_attachments[newLoc]->m_typeParam)); + mustSnarfAttachment = false; + if (m_attachments[newLoc]->m_type.EqualsLiteral( + "application/pgp-keys")) { + m_attachments[newLoc]->m_description = + nsLiteralCString("OpenPGP public key"); } - // For local files, if they are HTML docs and we don't have a charset, - // we should sniff the file and see if we can figure it out. - if (!m_attachments[newLoc]->m_type.IsEmpty()) { - if (m_attachments[newLoc]->m_type.LowerCaseEqualsLiteral( - TEXT_HTML)) { - char* tmpCharset = (char*)nsMsgI18NParseMetaCharset( - m_attachments[newLoc]->mTmpFile); - if (tmpCharset[0] != '\0') - m_attachments[newLoc]->m_charset = tmpCharset; - } - } - - attachment->GetMacType( - getter_Copies(m_attachments[newLoc]->m_xMacType)); - attachment->GetMacCreator( - getter_Copies(m_attachments[newLoc]->m_xMacCreator)); - - ++newLoc; } + + // 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.IsEmpty()) { + m_attachments[newLoc]->m_done = false; + m_attachments[newLoc]->SetMimeDeliveryState(this); + } else { + m_attachments[newLoc]->m_done = true; + m_attachments[newLoc]->SetMimeDeliveryState(nullptr); + } + // For local files, if they are HTML docs and we don't have a charset, + // we should sniff the file and see if we can figure it out. + if (!m_attachments[newLoc]->m_type.IsEmpty()) { + if (m_attachments[newLoc]->m_type.LowerCaseEqualsLiteral(TEXT_HTML)) { + char* tmpCharset = (char*)nsMsgI18NParseMetaCharset( + m_attachments[newLoc]->mTmpFile); + if (tmpCharset[0] != '\0') + m_attachments[newLoc]->m_charset = tmpCharset; + } + } + + attachment->GetMacType( + getter_Copies(m_attachments[newLoc]->m_xMacType)); + attachment->GetMacCreator( + getter_Copies(m_attachments[newLoc]->m_xMacCreator)); + + ++newLoc; } } } @@ -1854,75 +1825,62 @@ nsresult nsMsgComposeAndSend::AddCompFieldRemoteAttachments( if (mCompFieldRemoteAttachments <= 0) return NS_OK; // Get the attachments array - nsCOMPtr attachments; - mCompFields->GetAttachments(getter_AddRefs(attachments)); - if (!attachments) return NS_OK; - + nsTArray> attachments; + mCompFields->GetAttachments(attachments); uint32_t newLoc = aStartLocation; + for (nsIMsgAttachment* attachment : attachments) { + nsCString url; + attachment->GetUrl(url); + if (!url.IsEmpty()) { + // Just look for files that are NOT local file attachments and do + // the right thing. + if (PL_strncasecmp(url.get(), "file://", 7) != 0) { + // Check for message attachment, see + // nsMsgMailNewsUrl::GetIsMessageUri. + nsCOMPtr nsiuri; + nsresult rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID) + .SetSpec(url) + .Finalize(nsiuri); + NS_ENSURE_SUCCESS(rv, rv); - nsresult rv; - bool moreAttachments; - nsCString url; - nsCOMPtr element; - while (NS_SUCCEEDED(attachments->HasMoreElements(&moreAttachments)) && - moreAttachments) { - rv = attachments->GetNext(getter_AddRefs(element)); - NS_ENSURE_SUCCESS(rv, rv); + nsAutoCString scheme; + nsiuri->GetScheme(scheme); + bool isAMessageAttachment = StringEndsWith(scheme, "-message"_ns); - nsCOMPtr attachment = do_QueryInterface(element, &rv); - if (NS_SUCCEEDED(rv) && attachment) { - attachment->GetUrl(url); - if (!url.IsEmpty()) { - // Just look for files that are NOT local file attachments and do - // the right thing. - if (PL_strncasecmp(url.get(), "file://", 7) != 0) { - // Check for message attachment, see - // nsMsgMailNewsUrl::GetIsMessageUri. - nsCOMPtr nsiuri; - rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID) - .SetSpec(url) - .Finalize(nsiuri); - NS_ENSURE_SUCCESS(rv, rv); + m_attachments[newLoc]->mDeleteFile = true; + m_attachments[newLoc]->m_done = false; + m_attachments[newLoc]->SetMimeDeliveryState(this); - nsAutoCString scheme; - nsiuri->GetScheme(scheme); - bool isAMessageAttachment = StringEndsWith(scheme, "-message"_ns); + if (!isAMessageAttachment) + nsMsgNewURL(getter_AddRefs(m_attachments[newLoc]->mURL), url); - m_attachments[newLoc]->mDeleteFile = true; - m_attachments[newLoc]->m_done = false; - m_attachments[newLoc]->SetMimeDeliveryState(this); + m_attachments[newLoc]->m_encoding = ENCODING_7BIT; - if (!isAMessageAttachment) - nsMsgNewURL(getter_AddRefs(m_attachments[newLoc]->mURL), url); + attachment->GetMacType( + getter_Copies(m_attachments[newLoc]->m_xMacType)); + attachment->GetMacCreator( + getter_Copies(m_attachments[newLoc]->m_xMacCreator)); - m_attachments[newLoc]->m_encoding = ENCODING_7BIT; + /* Count up attachments which are going to come from mail folders + and from NNTP servers. */ + bool do_add_attachment = false; + if (isAMessageAttachment) { + do_add_attachment = true; + if (!PL_strncasecmp(url.get(), "news-message://", 15)) + (*aNewsCount)++; + else + (*aMailboxCount)++; - attachment->GetMacType( - getter_Copies(m_attachments[newLoc]->m_xMacType)); - attachment->GetMacCreator( - getter_Copies(m_attachments[newLoc]->m_xMacCreator)); - - /* Count up attachments which are going to come from mail folders - and from NNTP servers. */ - bool do_add_attachment = false; - if (isAMessageAttachment) { - do_add_attachment = true; - if (!PL_strncasecmp(url.get(), "news-message://", 15)) - (*aNewsCount)++; - else - (*aMailboxCount)++; - - m_attachments[newLoc]->m_uri = url; - m_attachments[newLoc]->mURL = nullptr; - } else - do_add_attachment = (nullptr != m_attachments[newLoc]->mURL); - m_attachments[newLoc]->mSendViaCloud = false; - if (do_add_attachment) { - nsAutoString proposedName; - attachment->GetName(proposedName); - msg_pick_real_name(m_attachments[newLoc], proposedName.get()); - ++newLoc; - } + m_attachments[newLoc]->m_uri = url; + m_attachments[newLoc]->mURL = nullptr; + } else + do_add_attachment = (nullptr != m_attachments[newLoc]->mURL); + m_attachments[newLoc]->mSendViaCloud = false; + if (do_add_attachment) { + nsAutoString proposedName; + attachment->GetName(proposedName); + msg_pick_real_name(m_attachments[newLoc], proposedName.get()); + ++newLoc; } } } @@ -2270,20 +2228,10 @@ nsresult nsMsgComposeAndSend::InitCompositionFields( rv = mCompFields->AddAllHeaders(fields); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr srcAttachments; - fields->GetAttachments(getter_AddRefs(srcAttachments)); - if (srcAttachments) { - bool moreAttachments; - nsCOMPtr element; - while (NS_SUCCEEDED(srcAttachments->HasMoreElements(&moreAttachments)) && - moreAttachments) { - rv = srcAttachments->GetNext(getter_AddRefs(element)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr attachment = do_QueryInterface(element, &rv); - NS_ENSURE_SUCCESS(rv, rv); - mCompFields->AddAttachment(attachment); - } + nsTArray> srcAttachments; + fields->GetAttachments(srcAttachments); + for (nsIMsgAttachment* attachment : srcAttachments) { + mCompFields->AddAttachment(attachment); } AddDefaultCustomHeaders();