diff --git a/mail/base/content/msgHdrView.js b/mail/base/content/msgHdrView.js index ccf162327b..cd14ee6e4a 100644 --- a/mail/base/content/msgHdrView.js +++ b/mail/base/content/msgHdrView.js @@ -1723,11 +1723,10 @@ function SendMailToNode(addressNode, aEvent) { fields.newsgroups = addressNode.getAttribute("newsgroup"); if (addressNode.hasAttribute("fullAddress")) { let addresses = MailServices.headerParser.makeFromDisplayAddress( - addressNode.getAttribute("fullAddress"), - {} + addressNode.getAttribute("fullAddress") ); if (addresses.length > 0) { - fields.to = MailServices.headerParser.makeMimeHeader(addresses, 1); + fields.to = MailServices.headerParser.makeMimeHeader([addresses[0]]); } } diff --git a/mail/components/compose/content/MsgComposeCommands.js b/mail/components/compose/content/MsgComposeCommands.js index 8fead39773..a0d45bf38d 100644 --- a/mail/components/compose/content/MsgComposeCommands.js +++ b/mail/components/compose/content/MsgComposeCommands.js @@ -3534,10 +3534,7 @@ function GenericSendMessage(msgType) { let addresses = MailServices.headerParser.makeFromDisplayAddress( GetMsgIdentityElement().value ); - msgCompFields.from = MailServices.headerParser.makeMimeHeader( - addresses, - addresses.length - ); + msgCompFields.from = MailServices.headerParser.makeMimeHeader(addresses); var subject = GetMsgSubjectElement().value; msgCompFields.subject = subject; Attachments2CompFields(msgCompFields); diff --git a/mail/components/compose/content/addressingWidgetOverlay.js b/mail/components/compose/content/addressingWidgetOverlay.js index 3d656637cd..f4fb1e46f7 100644 --- a/mail/components/compose/content/addressingWidgetOverlay.js +++ b/mail/components/compose/content/addressingWidgetOverlay.js @@ -133,7 +133,7 @@ function Recipients2CompFields(msgCompFields) { try { let headerParser = MailServices.headerParser; recipient = headerParser - .makeFromDisplayAddress(fieldValue, {}) + .makeFromDisplayAddress(fieldValue) .map(fullValue => headerParser.makeMimeAddress(fullValue.name, fullValue.email) ) diff --git a/mailnews/compose/src/nsMsgCompUtils.cpp b/mailnews/compose/src/nsMsgCompUtils.cpp index 244a3145d9..82318b8c30 100644 --- a/mailnews/compose/src/nsMsgCompUtils.cpp +++ b/mailnews/compose/src/nsMsgCompUtils.cpp @@ -371,7 +371,8 @@ nsresult mime_generate_headers(nsIMsgCompFields *fields, nsCOMPtr headerParser( mozilla::services::GetHeaderParser()); nsCOMPtr group; - headerParser->MakeGroupObject(undisclosedRecipients, nullptr, 0, + nsTArray> noRecipients; + headerParser->MakeGroupObject(undisclosedRecipients, noRecipients, getter_AddRefs(group)); recipients.AppendElement(group); finalHeaders->SetAddressingHeader("To", recipients); diff --git a/mailnews/mime/public/nsIMsgHeaderParser.idl b/mailnews/mime/public/nsIMsgHeaderParser.idl index 890ad201ce..c1a79bbfcc 100644 --- a/mailnews/mime/public/nsIMsgHeaderParser.idl +++ b/mailnews/mime/public/nsIMsgHeaderParser.idl @@ -89,12 +89,9 @@ interface nsIMsgHeaderParser : nsISupports { * of mailbox objects, containing no group objects. * @return An array corresponding to the header description. */ - void parseEncodedHeader(in ACString aEncodedHeader, + Array parseEncodedHeader(in ACString aEncodedHeader, [optional] in string aHeaderCharset, - [optional] in bool aPreserveGroups, - [optional] out unsigned long length, - [retval, array, size_is(length)] - out msgIAddressObject addresses); + [optional] in bool aPreserveGroups); /** * Parse an address-based header that has not yet been 2047-decoded and does not @@ -103,10 +100,7 @@ interface nsIMsgHeaderParser : nsISupports { * @param aEncodedHeader The RFC 2047-encoded header to parse. * @return An array corresponding to the header description. */ - void parseEncodedHeaderW(in AString aEncodedHeader, - [optional] out unsigned long length, - [retval, array, size_is(length)] - out msgIAddressObject addresses); + Array parseEncodedHeaderW(in AString aEncodedHeader); /** * Parse an address-based header that has been 2047-decoded. @@ -120,11 +114,8 @@ interface nsIMsgHeaderParser : nsISupports { * of mailbox objects, containing no group objects. * @return An array corresponding to the header description. */ - void parseDecodedHeader(in AString aDecodedHeader, - [optional] in bool aPreserveGroups, - [optional] out unsigned long length, - [retval, array, size_is(length)] - out msgIAddressObject addresses); + Array parseDecodedHeader(in AString aDecodedHeader, + [optional] in bool aPreserveGroups); /** * Given an array of addresses, make a MIME header suitable for emission. @@ -135,12 +126,9 @@ interface nsIMsgHeaderParser : nsISupports { * to maximum line length formats. * * @param aAddresses An array corresponding to the header description. - * @param aLength The length of said array of addresses. * @return A string that is suitable for writing in a MIME message. */ - AString makeMimeHeader([array, size_is(aLength)] - in msgIAddressObject aAddresses, - in unsigned long aLength); + AString makeMimeHeader(in Array aAddresses); /** * Return the first address in the list in a format suitable for display. @@ -178,8 +166,7 @@ interface nsIMsgHeaderParser : nsISupports { /// Return a structured group object having the given name and members. msgIAddressObject makeGroupObject(in AString aName, - [array, size_is(aLength)] in msgIAddressObject aMembers, - in unsigned long aLength); + in Array aMembers); /** * Return an array of structured mailbox objects for the given display name @@ -191,9 +178,7 @@ interface nsIMsgHeaderParser : nsISupports { * while the string "webmaster@nowhere.invalid, child@nowhere.invalid" would * produce two address objects. */ - void makeFromDisplayAddress(in AString aDisplayAddresses, - [optional] out unsigned long count, - [retval, array, size_is(count)] out msgIAddressObject addresses); + Array makeFromDisplayAddress(in AString aDisplayAddresses); /** * Given a string which contains a list of Header addresses, returns a diff --git a/mailnews/mime/src/MimeHeaderParser.cpp b/mailnews/mime/src/MimeHeaderParser.cpp index a8a48964bd..3b15d1d359 100644 --- a/mailnews/mime/src/MimeHeaderParser.cpp +++ b/mailnews/mime/src/MimeHeaderParser.cpp @@ -38,8 +38,9 @@ void MakeMimeAddress(const nsAString &aName, const nsAString &aEmail, nsCOMPtr address; headerParser->MakeMailboxObject(aName, aEmail, getter_AddRefs(address)); - msgIAddressObject *obj = address; - headerParser->MakeMimeHeader(&obj, 1, full); + nsTArray> addresses; + addresses.AppendElement(address); + headerParser->MakeMimeHeader(addresses, full); } void MakeDisplayAddress(const nsAString &aName, const nsAString &aEmail, @@ -70,16 +71,14 @@ nsCOMArray DecodedHeader(const nsAString &aHeader) { } nsCOMPtr headerParser(services::GetHeaderParser()); NS_ENSURE_TRUE(headerParser, retval); - msgIAddressObject **addresses = nullptr; - uint32_t length; - nsresult rv = - headerParser->ParseDecodedHeader(aHeader, false, &length, &addresses); + nsTArray> addresses; + nsresult rv = headerParser->ParseDecodedHeader(aHeader, false, addresses); MOZ_ASSERT(NS_SUCCEEDED(rv), "Javascript jsmime returned an error!"); - if (NS_SUCCEEDED(rv) && length > 0 && addresses) { - // retval.Adopt(addresses, length); - retval.Clear(); - retval.AppendElements(addresses, length); - free(addresses); + if (NS_SUCCEEDED(rv) && addresses.Length() > 0) { + retval.SetCapacity(addresses.Length()); + for (auto &addr : addresses) { + retval.AppendElement(addr); + } } return retval; } @@ -92,16 +91,15 @@ nsCOMArray EncodedHeader(const nsACString &aHeader, } nsCOMPtr headerParser(services::GetHeaderParser()); NS_ENSURE_TRUE(headerParser, retval); - msgIAddressObject **addresses = nullptr; - uint32_t length; - nsresult rv = headerParser->ParseEncodedHeader(aHeader, aCharset, false, - &length, &addresses); + nsTArray> addresses; + nsresult rv = + headerParser->ParseEncodedHeader(aHeader, aCharset, false, addresses); MOZ_ASSERT(NS_SUCCEEDED(rv), "This should never fail!"); - if (NS_SUCCEEDED(rv) && length > 0 && addresses) { - // retval.Adopt(addresses, length); - retval.Clear(); - retval.AppendElements(addresses, length); - free(addresses); + if (NS_SUCCEEDED(rv) && addresses.Length() > 0) { + retval.SetCapacity(addresses.Length()); + for (auto &addr : addresses) { + retval.AppendElement(addr); + } } return retval; } @@ -113,15 +111,14 @@ nsCOMArray EncodedHeaderW(const nsAString &aHeader) { } nsCOMPtr headerParser(services::GetHeaderParser()); NS_ENSURE_TRUE(headerParser, retval); - msgIAddressObject **addresses = nullptr; - uint32_t length; - nsresult rv = headerParser->ParseEncodedHeaderW(aHeader, &length, &addresses); + nsTArray> addresses; + nsresult rv = headerParser->ParseEncodedHeaderW(aHeader, addresses); MOZ_ASSERT(NS_SUCCEEDED(rv), "This should never fail!"); - if (NS_SUCCEEDED(rv) && length > 0 && addresses) { - // retval.Adopt(addresses, length); - retval.Clear(); - retval.AppendElements(addresses, length); - free(addresses); + if (NS_SUCCEEDED(rv) && addresses.Length() > 0) { + retval.SetCapacity(addresses.Length()); + for (auto &addr : addresses) { + retval.AppendElement(addr); + } } return retval; } diff --git a/mailnews/mime/src/mimeJSComponents.js b/mailnews/mime/src/mimeJSComponents.js index 79a99e84ff..2dd655eb0e 100644 --- a/mailnews/mime/src/mimeJSComponents.js +++ b/mailnews/mime/src/mimeJSComponents.js @@ -282,16 +282,16 @@ MimeAddressParser.prototype = { classID: Components.ID("96bd8769-2d0e-4440-963d-22b97fb3ba77"), QueryInterface: ChromeUtils.generateQI([Ci.nsIMsgHeaderParser]), - parseEncodedHeader(aHeader, aCharset, aPreserveGroups, count) { + parseEncodedHeader(aHeader, aCharset, aPreserveGroups) { aHeader = aHeader || ""; let value = MimeParser.parseHeaderField( aHeader, MimeParser.HEADER_ADDRESS | MimeParser.HEADER_OPTION_ALL_I18N, aCharset ); - return fixArray(value, aPreserveGroups, count); + return fixArray(value, aPreserveGroups); }, - parseEncodedHeaderW(aHeader, count) { + parseEncodedHeaderW(aHeader) { aHeader = aHeader || ""; let value = MimeParser.parseHeaderField( aHeader, @@ -300,15 +300,15 @@ MimeAddressParser.prototype = { MimeParser.HEADER_OPTION_DECODE_2047, undefined ); - return fixArray(value, false, count); + return fixArray(value, false); }, - parseDecodedHeader(aHeader, aPreserveGroups, count) { + parseDecodedHeader(aHeader, aPreserveGroups) { aHeader = aHeader || ""; let value = MimeParser.parseHeaderField(aHeader, MimeParser.HEADER_ADDRESS); - return fixArray(value, aPreserveGroups, count); + return fixArray(value, aPreserveGroups); }, - makeMimeHeader(addresses, length) { + makeMimeHeader(addresses) { addresses = fixXpconnectAddresses(addresses); // Don't output any necessary continuations, so make line length as large as // possible first. @@ -387,7 +387,7 @@ MimeAddressParser.prototype = { return object; }, - makeFromDisplayAddress(aDisplay, count) { + makeFromDisplayAddress(aDisplay) { if (aDisplay.includes(";") && !/:.*;/.test(aDisplay)) { // Using semicolons as mailbox separators in against the standard, but // used in the wild by some clients. @@ -424,9 +424,6 @@ MimeAddressParser.prototype = { output.push(this._makeSingleAddress(addr)); } } - if (count) { - count.value = output.length; - } return output; }, diff --git a/mailnews/mime/test/unit/test_nsIMsgHeaderParser4.js b/mailnews/mime/test/unit/test_nsIMsgHeaderParser4.js index d465d03916..99994f8a4b 100644 --- a/mailnews/mime/test/unit/test_nsIMsgHeaderParser4.js +++ b/mailnews/mime/test/unit/test_nsIMsgHeaderParser4.js @@ -113,10 +113,8 @@ function run_test() { // Test - strings for (let i = 0; i < checks.length; ++i) { - dump("Test " + i + "\n"); let addrs = MailServices.headerParser.makeFromDisplayAddress( - checks[i].displayString, - {} + checks[i].displayString ); let checkaddrs = checks[i].addresses; Assert.equal(addrs.length, checkaddrs.length); diff --git a/suite/mailnews/components/compose/content/MsgComposeCommands.js b/suite/mailnews/components/compose/content/MsgComposeCommands.js index 6f5869bb95..63db26f087 100644 --- a/suite/mailnews/components/compose/content/MsgComposeCommands.js +++ b/suite/mailnews/components/compose/content/MsgComposeCommands.js @@ -1603,7 +1603,7 @@ function GenericSendMessage( msgType ) Recipients2CompFields(msgCompFields); var address = GetMsgIdentityElement().value; address = MailServices.headerParser.makeFromDisplayAddress(address); - msgCompFields.from = MailServices.headerParser.makeMimeHeader(address, 1); + msgCompFields.from = MailServices.headerParser.makeMimeHeader([address[0]]); var subject = GetMsgSubjectElement().value; msgCompFields.subject = subject; Attachments2CompFields(msgCompFields); diff --git a/suite/mailnews/components/compose/content/addressingWidgetOverlay.js b/suite/mailnews/components/compose/content/addressingWidgetOverlay.js index b4f62a8631..571ad5eac8 100644 --- a/suite/mailnews/components/compose/content/addressingWidgetOverlay.js +++ b/suite/mailnews/components/compose/content/addressingWidgetOverlay.js @@ -118,7 +118,7 @@ function Recipients2CompFields(msgCompFields) try { let headerParser = MailServices.headerParser; recipient = - headerParser.makeFromDisplayAddress(fieldValue, {}).map(fullValue => + headerParser.makeFromDisplayAddress(fieldValue).map(fullValue => headerParser.makeMimeAddress(fullValue.name, fullValue.email)) .join(", "); } catch (ex) {recipient = fieldValue;} diff --git a/suite/mailnews/content/mailContextMenus.js b/suite/mailnews/content/mailContextMenus.js index 279de610de..4d07f27897 100644 --- a/suite/mailnews/content/mailContextMenus.js +++ b/suite/mailnews/content/mailContextMenus.js @@ -465,7 +465,7 @@ function SendMailTo(fullAddress, aEvent) var headerParser = MailServices.headerParser; var addresses = headerParser.makeFromDisplayAddress(fullAddress); - fields.to = headerParser.makeMimeHeader(addresses, 1); + fields.to = headerParser.makeMimeHeader([addresses[0]]); params.type = Ci.nsIMsgCompType.New; // If aEvent is passed, check if Shift key was pressed for composition in