From 7f7c240f087457b255f2fb6d68ae5866d2645f57 Mon Sep 17 00:00:00 2001 From: Ben Campbell Date: Tue, 3 Dec 2019 20:11:24 +0200 Subject: [PATCH] Bug 1594890 - Remove xpidl [array] use in nsIMsgCompFields. r=mkmelin --- calendar/base/modules/utils/calEmailUtils.jsm | 2 +- calendar/base/modules/utils/calItipUtils.jsm | 4 ++-- .../compose/content/MsgComposeCommands.js | 11 +++++----- .../content/addressingWidgetOverlay.js | 12 +++++------ mail/components/extensions/parent/ext-mail.js | 7 +++---- mailnews/compose/public/nsIMsgCompFields.idl | 9 ++++---- mailnews/compose/src/nsMsgCompFields.cpp | 21 ++++--------------- .../compose/test/unit/test_splitRecipients.js | 7 ++----- .../compose/content/MsgComposeCommands.js | 8 +++---- .../content/addressingWidgetOverlay.js | 12 +++++------ 10 files changed, 37 insertions(+), 56 deletions(-) diff --git a/calendar/base/modules/utils/calEmailUtils.jsm b/calendar/base/modules/utils/calEmailUtils.jsm index 50dfbcfc78..5b47d6b79c 100644 --- a/calendar/base/modules/utils/calEmailUtils.jsm +++ b/calendar/base/modules/utils/calEmailUtils.jsm @@ -146,7 +146,7 @@ var calemail = { Ci.nsIMsgCompFields ); // Resolve the list considering also configured common names - let members = compFields.splitRecipients(aRecipients, false, {}); + let members = compFields.splitRecipients(aRecipients, false); let list = []; let prefix = ""; for (let member of members) { diff --git a/calendar/base/modules/utils/calItipUtils.jsm b/calendar/base/modules/utils/calItipUtils.jsm index 1e86301f77..6782c33569 100644 --- a/calendar/base/modules/utils/calItipUtils.jsm +++ b/calendar/base/modules/utils/calItipUtils.jsm @@ -482,7 +482,7 @@ var calitip = { let compFields = Cc["@mozilla.org/messengercompose/composefields;1"].createInstance( Ci.nsIMsgCompFields ); - let addresses = compFields.splitRecipients(author, true, {}); + let addresses = compFields.splitRecipients(author, true); if (addresses.length != 1) { cal.LOG("No unique email address for lookup in message.\r\n" + cal.STACK(20)); } @@ -1264,7 +1264,7 @@ var calitip = { let compFields = Cc["@mozilla.org/messengercompose/composefields;1"].createInstance( Ci.nsIMsgCompFields ); - let addresses = compFields.splitRecipients(aEmailAddress, true, {}); + let addresses = compFields.splitRecipients(aEmailAddress, true); if (addresses.length == 1) { let searchFor = cal.email.prependMailTo(addresses[0]); aAttendees.forEach(aAttendee => { diff --git a/mail/components/compose/content/MsgComposeCommands.js b/mail/components/compose/content/MsgComposeCommands.js index f96e137a6e..906c34d89e 100644 --- a/mail/components/compose/content/MsgComposeCommands.js +++ b/mail/components/compose/content/MsgComposeCommands.js @@ -3905,8 +3905,7 @@ function CheckValidEmailAddress(aMsgCompFields) { for (let type of ["to", "cc", "bcc"]) { let recipients = aMsgCompFields.splitRecipients( aMsgCompFields[type], - false, - {} + false ); // MsgCompFields contains only non-empty recipients. recipientCount += recipients.length; @@ -6301,10 +6300,10 @@ function LoadIdentity(startup) { } let toAddrs = new Set( - msgCompFields.splitRecipients(msgCompFields.to, true, {}) + msgCompFields.splitRecipients(msgCompFields.to, true) ); let ccAddrs = new Set( - msgCompFields.splitRecipients(msgCompFields.cc, true, {}) + msgCompFields.splitRecipients(msgCompFields.cc, true) ); if (newCc != prevCc) { @@ -6314,7 +6313,7 @@ function LoadIdentity(startup) { } if (newCc) { // Ensure none of the Ccs are already in To. - let cc2 = msgCompFields.splitRecipients(newCc, true, {}); + let cc2 = msgCompFields.splitRecipients(newCc, true); newCc = cc2.filter(x => !toAddrs.has(x)).join(", "); awAddRecipients(msgCompFields, "addr_cc", newCc); } @@ -6327,7 +6326,7 @@ function LoadIdentity(startup) { } if (newBcc) { // Ensure none of the Bccs are already in To or Cc. - let bcc2 = msgCompFields.splitRecipients(newBcc, true, {}); + let bcc2 = msgCompFields.splitRecipients(newBcc, true); let toCcAddrs = new Set([...toAddrs, ...ccAddrs]); newBcc = bcc2.filter(x => !toCcAddrs.has(x)).join(", "); awAddRecipients(msgCompFields, "addr_bcc", newBcc); diff --git a/mail/components/compose/content/addressingWidgetOverlay.js b/mail/components/compose/content/addressingWidgetOverlay.js index aaa92b3885..14bf806a64 100644 --- a/mail/components/compose/content/addressingWidgetOverlay.js +++ b/mail/components/compose/content/addressingWidgetOverlay.js @@ -203,14 +203,14 @@ function CompFields2Recipients(msgCompFields) { let havePrimaryRecipient = false; if (msgReplyTo) { awSetInputAndPopupFromArray( - msgCompFields.splitRecipients(msgReplyTo, false, {}), + msgCompFields.splitRecipients(msgReplyTo, false), "addr_reply", listbox, templateNode ); } if (msgTo) { - let rcp = msgCompFields.splitRecipients(msgTo, false, {}); + let rcp = msgCompFields.splitRecipients(msgTo, false); if (rcp.length) { awSetInputAndPopupFromArray(rcp, "addr_to", listbox, templateNode); havePrimaryRecipient = true; @@ -218,7 +218,7 @@ function CompFields2Recipients(msgCompFields) { } if (msgCC) { awSetInputAndPopupFromArray( - msgCompFields.splitRecipients(msgCC, false, {}), + msgCompFields.splitRecipients(msgCC, false), "addr_cc", listbox, templateNode @@ -226,7 +226,7 @@ function CompFields2Recipients(msgCompFields) { } if (msgBCC) { awSetInputAndPopupFromArray( - msgCompFields.splitRecipients(msgBCC, false, {}), + msgCompFields.splitRecipients(msgBCC, false), "addr_bcc", listbox, templateNode @@ -359,7 +359,7 @@ function awRemoveRecipients(msgCompFields, recipientType, recipientsList) { return; } - var recipientArray = msgCompFields.splitRecipients(recipientsList, false, {}); + var recipientArray = msgCompFields.splitRecipients(recipientsList, false); for (var index = 0; index < recipientArray.length; index++) { for (var row = 1; row <= top.MAX_RECIPIENTS; row++) { @@ -388,7 +388,7 @@ function awAddRecipients(msgCompFields, recipientType, recipientsList) { return; } - var recipientArray = msgCompFields.splitRecipients(recipientsList, false, {}); + var recipientArray = msgCompFields.splitRecipients(recipientsList, false); awAddRecipientsArray(recipientType, recipientArray); } diff --git a/mail/components/extensions/parent/ext-mail.js b/mail/components/extensions/parent/ext-mail.js index 44ef62d19b..f7417a8f7a 100644 --- a/mail/components/extensions/parent/ext-mail.js +++ b/mail/components/extensions/parent/ext-mail.js @@ -1350,11 +1350,10 @@ function convertMessage(msgHdr, extension) { author: msgHdr.mime2DecodedAuthor, recipients: composeFields.splitRecipients( msgHdr.mime2DecodedRecipients, - false, - {} + false ), - ccList: composeFields.splitRecipients(msgHdr.ccList, false, {}), - bccList: composeFields.splitRecipients(msgHdr.bccList, false, {}), + ccList: composeFields.splitRecipients(msgHdr.ccList, false), + bccList: composeFields.splitRecipients(msgHdr.bccList, false), subject: msgHdr.mime2DecodedSubject, read: msgHdr.isRead, flagged: msgHdr.isFlagged, diff --git a/mailnews/compose/public/nsIMsgCompFields.idl b/mailnews/compose/public/nsIMsgCompFields.idl index 72c729109d..114f507fe9 100644 --- a/mailnews/compose/public/nsIMsgCompFields.idl +++ b/mailnews/compose/public/nsIMsgCompFields.idl @@ -77,12 +77,11 @@ interface nsIMsgCompFields : msgIWritableStructuredHeaders { * @param aRecipients The recipients list to split. * @param aEmailAddressOnly Set to true to drop display names from the results * array. - * @param aLength The length of the aResult array. - * @param aResult An array of the recipients. + * + * @return An array of the recipients. */ - void splitRecipients(in AString aRecipients, in boolean aEmailAddressOnly, - out unsigned long aLength, - [array, size_is(aLength), retval] out wstring aResult); + Array splitRecipients(in AString aRecipients, + in boolean aEmailAddressOnly); void ConvertBodyToPlainText(); diff --git a/mailnews/compose/src/nsMsgCompFields.cpp b/mailnews/compose/src/nsMsgCompFields.cpp index 2bc21dc2e1..b102b96d35 100644 --- a/mailnews/compose/src/nsMsgCompFields.cpp +++ b/mailnews/compose/src/nsMsgCompFields.cpp @@ -519,27 +519,14 @@ NS_IMETHODIMP nsMsgCompFields::RemoveAttachments() { // This method is called during the creation of a new window. NS_IMETHODIMP nsMsgCompFields::SplitRecipients(const nsAString &aRecipients, - bool aEmailAddressOnly, uint32_t *aLength, - char16_t ***aResult) { - NS_ENSURE_ARG_POINTER(aLength); - NS_ENSURE_ARG_POINTER(aResult); - - *aLength = 0; - *aResult = nullptr; - + bool aEmailAddressOnly, + nsTArray &aResult) { nsCOMArray header(EncodedHeaderW(aRecipients)); - nsTArray results; if (aEmailAddressOnly) - ExtractEmails(header, results); + ExtractEmails(header, aResult); else - ExtractDisplayAddresses(header, results); + ExtractDisplayAddresses(header, aResult); - uint32_t count = results.Length(); - char16_t **result = (char16_t **)moz_xmalloc(sizeof(char16_t *) * count); - for (uint32_t i = 0; i < count; ++i) result[i] = ToNewUnicode(results[i]); - - *aResult = result; - *aLength = count; return NS_OK; } diff --git a/mailnews/compose/test/unit/test_splitRecipients.js b/mailnews/compose/test/unit/test_splitRecipients.js index d18cc3ea1c..b51da1c7a2 100644 --- a/mailnews/compose/test/unit/test_splitRecipients.js +++ b/mailnews/compose/test/unit/test_splitRecipients.js @@ -148,18 +148,15 @@ function run_test() { // the basic argument/return combinations. for (var part = 0; part < splitRecipientsTests.length; ++part) { - var count = {}; print("Test: " + splitRecipientsTests[part].recipients); var result = fields.splitRecipients( splitRecipientsTests[part].recipients, - splitRecipientsTests[part].emailAddressOnly, - count + splitRecipientsTests[part].emailAddressOnly ); - Assert.equal(splitRecipientsTests[part].count, count.value); Assert.equal(splitRecipientsTests[part].count, result.length); - for (var item = 0; item < count.value; ++item) { + for (var item = 0; item < result.length; ++item) { Assert.equal(splitRecipientsTests[part].result[item], result[item]); } } diff --git a/suite/mailnews/components/compose/content/MsgComposeCommands.js b/suite/mailnews/components/compose/content/MsgComposeCommands.js index a65db02d65..40b69d3d29 100644 --- a/suite/mailnews/components/compose/content/MsgComposeCommands.js +++ b/suite/mailnews/components/compose/content/MsgComposeCommands.js @@ -2863,8 +2863,8 @@ function LoadIdentity(startup) awAddRecipients(msgCompFields, "addr_reply", newReplyTo); } - let toAddrs = new Set(msgCompFields.splitRecipients(msgCompFields.to, true, {})); - let ccAddrs = new Set(msgCompFields.splitRecipients(msgCompFields.cc, true, {})); + let toAddrs = new Set(msgCompFields.splitRecipients(msgCompFields.to, true)); + let ccAddrs = new Set(msgCompFields.splitRecipients(msgCompFields.cc, true)); if (newCc != prevCc) { @@ -2873,7 +2873,7 @@ function LoadIdentity(startup) awRemoveRecipients(msgCompFields, "addr_cc", prevCc); if (newCc) { // Ensure none of the Ccs are already in To. - let cc2 = msgCompFields.splitRecipients(newCc, true, {}); + let cc2 = msgCompFields.splitRecipients(newCc, true); newCc = cc2.filter(x => !toAddrs.has(x)).join(", "); awAddRecipients(msgCompFields, "addr_cc", newCc); } @@ -2886,7 +2886,7 @@ function LoadIdentity(startup) awRemoveRecipients(msgCompFields, "addr_bcc", prevBcc); if (newBcc) { // Ensure none of the Bccs are already in To or Cc. - let bcc2 = msgCompFields.splitRecipients(newBcc, true, {}); + let bcc2 = msgCompFields.splitRecipients(newBcc, true); let toCcAddrs = new Set([...toAddrs, ...ccAddrs]); newBcc = bcc2.filter(x => !toCcAddrs.has(x)).join(", "); awAddRecipients(msgCompFields, "addr_bcc", newBcc); diff --git a/suite/mailnews/components/compose/content/addressingWidgetOverlay.js b/suite/mailnews/components/compose/content/addressingWidgetOverlay.js index 571ad5eac8..6083f5f8bf 100644 --- a/suite/mailnews/components/compose/content/addressingWidgetOverlay.js +++ b/suite/mailnews/components/compose/content/addressingWidgetOverlay.js @@ -176,11 +176,11 @@ function CompFields2Recipients(msgCompFields) var msgFollowupTo = msgCompFields.followupTo; var havePrimaryRecipient = false; if(msgReplyTo) - awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgReplyTo, false, {}), + awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgReplyTo, false), "addr_reply", newListBoxNode, templateNode); if(msgTo) { - var rcp = msgCompFields.splitRecipients(msgTo, false, {}); + var rcp = msgCompFields.splitRecipients(msgTo, false); if (rcp.length) { awSetInputAndPopupFromArray(rcp, "addr_to", newListBoxNode, templateNode); @@ -188,10 +188,10 @@ function CompFields2Recipients(msgCompFields) } } if(msgCC) - awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgCC, false, {}), + awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgCC, false), "addr_cc", newListBoxNode, templateNode); if(msgBCC) - awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgBCC, false, {}), + awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgBCC, false), "addr_bcc", newListBoxNode, templateNode); if(msgNewsgroups) { @@ -276,7 +276,7 @@ function awRemoveRecipients(msgCompFields, recipientType, recipientsList) if (!msgCompFields) return; - var recipientArray = msgCompFields.splitRecipients(recipientsList, false, {}); + var recipientArray = msgCompFields.splitRecipients(recipientsList, false); for (var index = 0; index < recipientArray.length; index++) for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) @@ -299,7 +299,7 @@ function awAddRecipients(msgCompFields, recipientType, recipientsList) if (!msgCompFields) return; - var recipientArray = msgCompFields.splitRecipients(recipientsList, false, {}); + var recipientArray = msgCompFields.splitRecipients(recipientsList, false); for (var index = 0; index < recipientArray.length; index++) awAddRecipient(recipientType, recipientArray[index]);