Bug 966705 - Replace ParsedHeader with nsCOMArray<msgIAddressObject>, r=Neil
This commit is contained in:
Родитель
1d27f78094
Коммит
db5c9c1a11
|
@ -515,7 +515,7 @@ nsMsgCompFields::SplitRecipients(const nsAString &aRecipients,
|
|||
*aLength = 0;
|
||||
*aResult = nullptr;
|
||||
|
||||
ParsedHeader header(EncodedHeader(NS_ConvertUTF16toUTF8(aRecipients)));
|
||||
nsCOMArray<msgIAddressObject> header(EncodedHeader(NS_ConvertUTF16toUTF8(aRecipients)));
|
||||
nsTArray<nsString> results;
|
||||
if (aEmailAddressOnly)
|
||||
ExtractEmails(header, results);
|
||||
|
|
|
@ -323,7 +323,7 @@ protected:
|
|||
|
||||
char *ConvertDateToMapiFormat (time_t);
|
||||
char *ConvertBodyToMapiFormat (nsIMsgDBHdr *hdr);
|
||||
void ConvertRecipientsToMapiFormat(const ParsedHeader &ourRecips,
|
||||
void ConvertRecipientsToMapiFormat(const nsCOMArray<msgIAddressObject> &ourRecips,
|
||||
lpnsMapiRecipDesc mapiRecips,
|
||||
int mapiRecipClass);
|
||||
|
||||
|
@ -611,10 +611,10 @@ lpnsMapiMessage MsgMapiListContext::GetMessage (nsMsgKey key, unsigned long flFl
|
|||
msgHdr->GetRecipients(getter_Copies(recipients));
|
||||
msgHdr->GetCcList(getter_Copies(ccList));
|
||||
|
||||
ParsedHeader parsedToRecips = EncodedHeader(recipients);
|
||||
ParsedHeader parsedCCRecips = EncodedHeader(ccList);
|
||||
uint32_t numToRecips = parsedToRecips.mCount;
|
||||
uint32_t numCCRecips = parsedCCRecips.mCount;
|
||||
nsCOMArray<msgIAddressObject> parsedToRecips = EncodedHeader(recipients);
|
||||
nsCOMArray<msgIAddressObject> parsedCCRecips = EncodedHeader(ccList);
|
||||
uint32_t numToRecips = parsedToRecips.Length();
|
||||
uint32_t numCCRecips = parsedCCRecips.Length();
|
||||
|
||||
message->lpRecips = (lpnsMapiRecipDesc) CoTaskMemAlloc ((numToRecips + numCCRecips) * sizeof(MapiRecipDesc));
|
||||
memset(message->lpRecips, 0, (numToRecips + numCCRecips) * sizeof(MapiRecipDesc));
|
||||
|
@ -658,8 +658,8 @@ char *MsgMapiListContext::ConvertDateToMapiFormat (time_t ourTime)
|
|||
|
||||
|
||||
void MsgMapiListContext::ConvertRecipientsToMapiFormat(
|
||||
const ParsedHeader &recipients, lpnsMapiRecipDesc mapiRecips,
|
||||
int mapiRecipClass)
|
||||
const nsCOMArray<msgIAddressObject> &recipients,
|
||||
lpnsMapiRecipDesc mapiRecips, int mapiRecipClass)
|
||||
{
|
||||
nsTArray<nsCString> names, addresses;
|
||||
ExtractAllAddresses(recipients, UTF16ArrayAdapter<>(names),
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#ifndef MimeHeaderParser_h__
|
||||
#define MimeHeaderParser_h__
|
||||
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsStringGlue.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
|
@ -15,40 +16,11 @@ class msgIAddressObject;
|
|||
namespace mozilla {
|
||||
namespace mailnews {
|
||||
|
||||
/**
|
||||
* This struct represents the list of addresses found in an addressing header.
|
||||
* It is primarily meant to be used only as a temporary object in between the
|
||||
* results of Parse*Header and the various Extract* methods. As such, it can
|
||||
* only be moved and not copied.
|
||||
*/
|
||||
struct ParsedHeader
|
||||
{
|
||||
ParsedHeader() : mCount(0), mAddresses(nullptr) {}
|
||||
|
||||
ParsedHeader(ParsedHeader &&other)
|
||||
: mCount(other.mCount),
|
||||
mAddresses(other.mAddresses)
|
||||
{
|
||||
other.mAddresses = nullptr;
|
||||
}
|
||||
|
||||
~ParsedHeader();
|
||||
|
||||
/// The number of addresses in the list
|
||||
uint32_t mCount;
|
||||
/// The list of addresses in an email header
|
||||
msgIAddressObject **mAddresses;
|
||||
|
||||
private:
|
||||
ParsedHeader(const ParsedHeader &) MOZ_DELETE;
|
||||
ParsedHeader &operator=(const ParsedHeader &) MOZ_DELETE;
|
||||
};
|
||||
|
||||
/**
|
||||
* This is used to signal that the input header value has already been decoded
|
||||
* according to RFC 2047 and is in UTF-16 form.
|
||||
*/
|
||||
ParsedHeader DecodedHeader(const nsAString &aHeader);
|
||||
nsCOMArray<msgIAddressObject> DecodedHeader(const nsAString &aHeader);
|
||||
|
||||
/**
|
||||
* This is used to signal that the input header value needs to be decoded
|
||||
|
@ -56,8 +28,8 @@ ParsedHeader DecodedHeader(const nsAString &aHeader);
|
|||
* that non-ASCII data is in; if the value is null (the default), then the
|
||||
* charset is assumed to be UTF-8.
|
||||
*/
|
||||
ParsedHeader EncodedHeader(const nsACString &aHeader,
|
||||
const char *aCharset = nullptr);
|
||||
nsCOMArray<msgIAddressObject> EncodedHeader(const nsACString &aHeader,
|
||||
const char *aCharset = nullptr);
|
||||
|
||||
namespace detail {
|
||||
void DoConversion(const nsTArray<nsString> &aUTF16, nsTArray<nsCString> &aUTF8);
|
||||
|
@ -138,14 +110,14 @@ void RemoveDuplicateAddresses(const nsACString &aHeader,
|
|||
* Given a message header, extract all names and email addresses found in that
|
||||
* header into the two arrays.
|
||||
*/
|
||||
void ExtractAllAddresses(const ParsedHeader &aHeader, nsTArray<nsString> &names,
|
||||
nsTArray<nsString> &emails);
|
||||
void ExtractAllAddresses(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsTArray<nsString> &names, nsTArray<nsString> &emails);
|
||||
|
||||
/**
|
||||
* Given a raw message header value, extract display names for every address
|
||||
* found in the header.
|
||||
*/
|
||||
void ExtractDisplayAddresses(const ParsedHeader &aHeader,
|
||||
void ExtractDisplayAddresses(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsTArray<nsString> &addresses);
|
||||
|
||||
/**
|
||||
|
@ -154,43 +126,47 @@ void ExtractDisplayAddresses(const ParsedHeader &aHeader,
|
|||
*
|
||||
* Duplicate email addresses are not removed from the output list.
|
||||
*/
|
||||
void ExtractEmails(const ParsedHeader &aHeader, nsTArray<nsString> &emails);
|
||||
void ExtractEmails(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsTArray<nsString> &emails);
|
||||
|
||||
/**
|
||||
* Given a raw message header value, extract the first name/email address found
|
||||
* in the header. This is essentially equivalent to grabbing the first entry of
|
||||
* ExtractAllAddresses.
|
||||
*/
|
||||
void ExtractFirstAddress(const ParsedHeader &aHeader, nsACString &name,
|
||||
nsACString &email);
|
||||
void ExtractFirstAddress(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsACString &name, nsACString &email);
|
||||
|
||||
/**
|
||||
* Given an RFC 2047-decoded message header value, extract the first name/email
|
||||
* address found in the header. This is essentially equivalent to grabbing the
|
||||
* first entry of ExtractAllAddresses.
|
||||
*/
|
||||
void ExtractFirstAddress(const ParsedHeader &aHeader, nsAString &name,
|
||||
nsACString &email);
|
||||
void ExtractFirstAddress(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsAString &name, nsACString &email);
|
||||
|
||||
/**
|
||||
* Given a raw message header value, extract the first email address found in
|
||||
* the header.
|
||||
*/
|
||||
void ExtractEmail(const ParsedHeader &aHeader, nsACString &email);
|
||||
void ExtractEmail(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsACString &email);
|
||||
|
||||
/**
|
||||
* Given a raw message header value, extract and clean up the first display
|
||||
* name found in the header. If there is no display name, the email address is
|
||||
* used instead.
|
||||
*/
|
||||
void ExtractName(const ParsedHeader &aHeader, nsACString &name);
|
||||
void ExtractName(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsACString &name);
|
||||
|
||||
/**
|
||||
* Given an RFC 2047-decoded message header value, extract the first display
|
||||
* name found in the header. If there is no display name, the email address is
|
||||
* returned instead.
|
||||
*/
|
||||
void ExtractName(const ParsedHeader &aDecodedHeader, nsAString &name);
|
||||
void ExtractName(const nsCOMArray<msgIAddressObject> &aDecodedHeader,
|
||||
nsAString &name);
|
||||
|
||||
} // namespace mailnews
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -69,37 +69,37 @@ void RemoveDuplicateAddresses(const nsACString &aHeader,
|
|||
// These are the core shim methods we need //
|
||||
/////////////////////////////////////////////
|
||||
|
||||
ParsedHeader DecodedHeader(const nsAString &aHeader)
|
||||
nsCOMArray<msgIAddressObject> DecodedHeader(const nsAString &aHeader)
|
||||
{
|
||||
ParsedHeader retval;
|
||||
nsCOMPtr<nsIMsgHeaderParser> headerParser(services::GetHeaderParser());
|
||||
msgIAddressObject **addresses;
|
||||
uint32_t length;
|
||||
DebugOnly<nsresult> rv = headerParser->ParseDecodedHeader(aHeader, false,
|
||||
&retval.mCount, &retval.mAddresses);
|
||||
&length, &addresses);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv), "This should never fail!");
|
||||
nsCOMArray<msgIAddressObject> retval;
|
||||
retval.Adopt(addresses, length);
|
||||
return retval;
|
||||
}
|
||||
|
||||
ParsedHeader EncodedHeader(const nsACString &aHeader, const char *aCharset)
|
||||
nsCOMArray<msgIAddressObject> EncodedHeader(const nsACString &aHeader,
|
||||
const char *aCharset)
|
||||
{
|
||||
ParsedHeader retval;
|
||||
nsCOMPtr<nsIMsgHeaderParser> headerParser(services::GetHeaderParser());
|
||||
msgIAddressObject **addresses;
|
||||
uint32_t length;
|
||||
DebugOnly<nsresult> rv = headerParser->ParseEncodedHeader(aHeader, aCharset,
|
||||
false, &retval.mCount, &retval.mAddresses);
|
||||
false, &length, &addresses);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv), "This should never fail!");
|
||||
nsCOMArray<msgIAddressObject> retval;
|
||||
retval.Adopt(addresses, length);
|
||||
return retval;
|
||||
}
|
||||
|
||||
ParsedHeader::~ParsedHeader()
|
||||
void ExtractAllAddresses(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsTArray<nsString> &names, nsTArray<nsString> &emails)
|
||||
{
|
||||
if (mAddresses)
|
||||
NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(mCount, mAddresses);
|
||||
}
|
||||
|
||||
void ExtractAllAddresses(const ParsedHeader &aHeader, nsTArray<nsString> &names,
|
||||
nsTArray<nsString> &emails)
|
||||
{
|
||||
uint32_t count = aHeader.mCount;
|
||||
msgIAddressObject **addresses = aHeader.mAddresses;
|
||||
uint32_t count = aHeader.Length();
|
||||
|
||||
// Prefill arrays before we start
|
||||
names.SetLength(count);
|
||||
|
@ -107,8 +107,8 @@ void ExtractAllAddresses(const ParsedHeader &aHeader, nsTArray<nsString> &names,
|
|||
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
{
|
||||
addresses[i]->GetName(names[i]);
|
||||
addresses[i]->GetEmail(emails[i]);
|
||||
aHeader[i]->GetName(names[i]);
|
||||
aHeader[i]->GetEmail(emails[i]);
|
||||
}
|
||||
|
||||
if (count == 1 && names[0].IsEmpty() && emails[0].IsEmpty())
|
||||
|
@ -118,15 +118,14 @@ void ExtractAllAddresses(const ParsedHeader &aHeader, nsTArray<nsString> &names,
|
|||
}
|
||||
}
|
||||
|
||||
void ExtractDisplayAddresses(const ParsedHeader &aHeader,
|
||||
void ExtractDisplayAddresses(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsTArray<nsString> &displayAddrs)
|
||||
{
|
||||
uint32_t count = aHeader.mCount;
|
||||
msgIAddressObject **addresses = aHeader.mAddresses;
|
||||
uint32_t count = aHeader.Length();
|
||||
|
||||
displayAddrs.SetLength(count);
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
addresses[i]->ToString(displayAddrs[i]);
|
||||
aHeader[i]->ToString(displayAddrs[i]);
|
||||
|
||||
if (count == 1 && displayAddrs[0].IsEmpty())
|
||||
displayAddrs.Clear();
|
||||
|
@ -136,13 +135,15 @@ void ExtractDisplayAddresses(const ParsedHeader &aHeader,
|
|||
// All of these are based on the above methods //
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
void ExtractEmails(const ParsedHeader &aHeader, nsTArray<nsString> &emails)
|
||||
void ExtractEmails(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsTArray<nsString> &emails)
|
||||
{
|
||||
nsTArray<nsString> names;
|
||||
ExtractAllAddresses(aHeader, names, emails);
|
||||
}
|
||||
|
||||
void ExtractEmail(const ParsedHeader &aHeader, nsACString &email)
|
||||
void ExtractEmail(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsACString &email)
|
||||
{
|
||||
nsAutoTArray<nsString, 1> names;
|
||||
nsAutoTArray<nsString, 1> emails;
|
||||
|
@ -154,8 +155,8 @@ void ExtractEmail(const ParsedHeader &aHeader, nsACString &email)
|
|||
email.Truncate();
|
||||
}
|
||||
|
||||
void ExtractFirstAddress(const ParsedHeader &aHeader, nsACString &name,
|
||||
nsACString &email)
|
||||
void ExtractFirstAddress(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsACString &name, nsACString &email)
|
||||
{
|
||||
nsAutoTArray<nsString, 1> names, emails;
|
||||
ExtractAllAddresses(aHeader, names, emails);
|
||||
|
@ -171,8 +172,8 @@ void ExtractFirstAddress(const ParsedHeader &aHeader, nsACString &name,
|
|||
}
|
||||
}
|
||||
|
||||
void ExtractFirstAddress(const ParsedHeader &aHeader, nsAString &name,
|
||||
nsACString &email)
|
||||
void ExtractFirstAddress(const nsCOMArray<msgIAddressObject> &aHeader,
|
||||
nsAString &name, nsACString &email)
|
||||
{
|
||||
nsAutoTArray<nsString, 1> names, emails;
|
||||
ExtractAllAddresses(aHeader, names, emails);
|
||||
|
@ -188,7 +189,7 @@ void ExtractFirstAddress(const ParsedHeader &aHeader, nsAString &name,
|
|||
}
|
||||
}
|
||||
|
||||
void ExtractName(const ParsedHeader &aHeader, nsACString &name)
|
||||
void ExtractName(const nsCOMArray<msgIAddressObject> &aHeader, nsACString &name)
|
||||
{
|
||||
nsCString email;
|
||||
ExtractFirstAddress(aHeader, name, email);
|
||||
|
@ -196,7 +197,7 @@ void ExtractName(const ParsedHeader &aHeader, nsACString &name)
|
|||
name = email;
|
||||
}
|
||||
|
||||
void ExtractName(const ParsedHeader &aHeader, nsAString &name)
|
||||
void ExtractName(const nsCOMArray<msgIAddressObject> &aHeader, nsAString &name)
|
||||
{
|
||||
nsAutoTArray<nsString, 1> names;
|
||||
nsAutoTArray<nsString, 1> emails;
|
||||
|
|
Загрузка…
Ссылка в новой задаче