summaryrefslogtreecommitdiffstats
path: root/mailnews
diff options
context:
space:
mode:
Diffstat (limited to 'mailnews')
-rw-r--r--mailnews/compose/src/nsMsgCompFields.cpp5
-rw-r--r--mailnews/compose/src/nsMsgCompose.cpp8
-rw-r--r--mailnews/mime/public/MimeHeaderParser.h5
-rw-r--r--mailnews/mime/public/nsIMsgHeaderParser.idl15
-rw-r--r--mailnews/mime/src/MimeHeaderParser.cpp18
-rw-r--r--mailnews/mime/src/mimeJSComponents.js17
6 files changed, 50 insertions, 18 deletions
diff --git a/mailnews/compose/src/nsMsgCompFields.cpp b/mailnews/compose/src/nsMsgCompFields.cpp
index c65e6ca17..24192f594 100644
--- a/mailnews/compose/src/nsMsgCompFields.cpp
+++ b/mailnews/compose/src/nsMsgCompFields.cpp
@@ -600,7 +600,7 @@ nsMsgCompFields::SplitRecipients(const nsAString &aRecipients,
*aLength = 0;
*aResult = nullptr;
- nsCOMArray<msgIAddressObject> header(EncodedHeader(NS_ConvertUTF16toUTF8(aRecipients)));
+ nsCOMArray<msgIAddressObject> header(EncodedHeaderW(aRecipients));
nsTArray<nsString> results;
if (aEmailAddressOnly)
ExtractEmails(header, results);
@@ -623,8 +623,7 @@ nsresult nsMsgCompFields::SplitRecipientsEx(const nsAString &recipients,
nsTArray<nsMsgRecipient> &aResult)
{
nsTArray<nsString> names, addresses;
- ExtractAllAddresses(EncodedHeader(NS_ConvertUTF16toUTF8(recipients)), names,
- addresses);
+ ExtractAllAddresses(EncodedHeaderW(recipients), names, addresses);
uint32_t numAddresses = names.Length();
for (uint32_t i = 0; i < numAddresses; ++i)
diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp
index 4ce8e8def..a7c2140ad 100644
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -2646,15 +2646,13 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns
}
nsCString fromEmailAddress;
- ExtractEmail(EncodedHeader(NS_ConvertUTF16toUTF8(from)), fromEmailAddress);
+ ExtractEmail(EncodedHeaderW(from), fromEmailAddress);
nsTArray<nsCString> toEmailAddresses;
- ExtractEmails(EncodedHeader(NS_ConvertUTF16toUTF8(to)),
- UTF16ArrayAdapter<>(toEmailAddresses));
+ ExtractEmails(EncodedHeaderW(to), UTF16ArrayAdapter<>(toEmailAddresses));
nsTArray<nsCString> ccEmailAddresses;
- ExtractEmails(EncodedHeader(NS_ConvertUTF16toUTF8(cc)),
- UTF16ArrayAdapter<>(ccEmailAddresses));
+ ExtractEmails(EncodedHeaderW(cc), UTF16ArrayAdapter<>(ccEmailAddresses));
nsCOMPtr<nsIPrefBranch> prefs (do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
diff --git a/mailnews/mime/public/MimeHeaderParser.h b/mailnews/mime/public/MimeHeaderParser.h
index fe9bf59d3..d8cd3705a 100644
--- a/mailnews/mime/public/MimeHeaderParser.h
+++ b/mailnews/mime/public/MimeHeaderParser.h
@@ -31,6 +31,11 @@ nsCOMArray<msgIAddressObject> DecodedHeader(const nsAString &aHeader);
nsCOMArray<msgIAddressObject> EncodedHeader(const nsACString &aHeader,
const char *aCharset = nullptr);
+/**
+ * Same deal, but we're starting with an nsAString.
+ */
+nsCOMArray<msgIAddressObject> EncodedHeaderW(const nsAString &aHeader);
+
namespace detail {
void DoConversion(const nsTArray<nsString> &aUTF16, nsTArray<nsCString> &aUTF8);
};
diff --git a/mailnews/mime/public/nsIMsgHeaderParser.idl b/mailnews/mime/public/nsIMsgHeaderParser.idl
index 2512623d8..fd582b64c 100644
--- a/mailnews/mime/public/nsIMsgHeaderParser.idl
+++ b/mailnews/mime/public/nsIMsgHeaderParser.idl
@@ -97,6 +97,18 @@ interface nsIMsgHeaderParser : nsISupports {
out msgIAddressObject addresses);
/**
+ * Parse an address-based header that has not yet been 2047-decoded and does not
+ * contain raw octets but instead wide (UTF-16) characters.
+ *
+ * @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);
+
+/**
* Parse an address-based header that has been 2047-decoded.
*
* The result of this method is an array of objects described in the above
@@ -178,9 +190,6 @@ interface nsIMsgHeaderParser : nsISupports {
* "Bond, James <agent007@mi5.invalid>" would produce one address object,
* while the string "webmaster@nowhere.invalid, child@nowhere.invalid" would
* produce two address objects.
- *
- * Note that the input string is RFC 2231 and RFC 2047 decoded but no UTF-8
- * decoding takes place.
*/
void makeFromDisplayAddress(in AString aDisplayAddresses,
[optional] out unsigned long count,
diff --git a/mailnews/mime/src/MimeHeaderParser.cpp b/mailnews/mime/src/MimeHeaderParser.cpp
index 4fd7bc982..15341de46 100644
--- a/mailnews/mime/src/MimeHeaderParser.cpp
+++ b/mailnews/mime/src/MimeHeaderParser.cpp
@@ -107,6 +107,24 @@ nsCOMArray<msgIAddressObject> EncodedHeader(const nsACString &aHeader,
return retval;
}
+nsCOMArray<msgIAddressObject> EncodedHeaderW(const nsAString &aHeader)
+{
+ nsCOMArray<msgIAddressObject> retval;
+ if (aHeader.IsEmpty()) {
+ return retval;
+ }
+ nsCOMPtr<nsIMsgHeaderParser> headerParser(services::GetHeaderParser());
+ NS_ENSURE_TRUE(headerParser, retval);
+ msgIAddressObject **addresses = nullptr;
+ uint32_t length;
+ nsresult rv = headerParser->ParseEncodedHeaderW(aHeader, &length, &addresses);
+ MOZ_ASSERT(NS_SUCCEEDED(rv), "This should never fail!");
+ if (NS_SUCCEEDED(rv) && length > 0 && addresses) {
+ retval.Adopt(addresses, length);
+ }
+ return retval;
+}
+
void ExtractAllAddresses(const nsCOMArray<msgIAddressObject> &aHeader,
nsTArray<nsString> &names, nsTArray<nsString> &emails)
{
diff --git a/mailnews/mime/src/mimeJSComponents.js b/mailnews/mime/src/mimeJSComponents.js
index 5ba7ff084..8e9d0684a 100644
--- a/mailnews/mime/src/mimeJSComponents.js
+++ b/mailnews/mime/src/mimeJSComponents.js
@@ -269,6 +269,15 @@ MimeAddressParser.prototype = {
MimeParser.HEADER_ADDRESS | MimeParser.HEADER_OPTION_ALL_I18N, aCharset);
return fixArray(value, aPreserveGroups, count);
},
+ parseEncodedHeaderW: function (aHeader, count) {
+ aHeader = aHeader || "";
+ let value = MimeParser.parseHeaderField(aHeader,
+ MimeParser.HEADER_ADDRESS |
+ MimeParser.HEADER_OPTION_DECODE_2231 |
+ MimeParser.HEADER_OPTION_DECODE_2047,
+ undefined);
+ return fixArray(value, false, count);
+ },
parseDecodedHeader: function (aHeader, aPreserveGroups, count) {
aHeader = aHeader || "";
let value = MimeParser.parseHeaderField(aHeader, MimeParser.HEADER_ADDRESS);
@@ -390,13 +399,7 @@ MimeAddressParser.prototype = {
parseHeadersWithArray: function (aHeader, aAddrs, aNames, aFullNames) {
let addrs = [], names = [], fullNames = [];
- // Parse header, but without HEADER_OPTION_ALLOW_RAW.
- let value = MimeParser.parseHeaderField(aHeader || "",
- MimeParser.HEADER_ADDRESS |
- MimeParser.HEADER_OPTION_DECODE_2231 |
- MimeParser.HEADER_OPTION_DECODE_2047,
- undefined);
- let allAddresses = fixArray(value, false);
+ let allAddresses = this.parseEncodedHeader(aHeader, undefined, false);
// Don't index the dummy empty address.
if (aHeader.trim() == "")