Bug 842632, part 3d: Use the C++ API in mime, r=irving.

This commit is contained in:
Joshua Cranmer 2013-12-11 13:20:00 -06:00
Родитель a97dae91ae
Коммит 51fe8faba9
8 изменённых файлов: 103 добавлений и 146 удалений

Просмотреть файл

@ -15,7 +15,6 @@
#include "nsEmitterUtils.h" #include "nsEmitterUtils.h"
#include "nsMimeStringResources.h" #include "nsMimeStringResources.h"
#include "msgCore.h" #include "msgCore.h"
#include "nsIMsgHeaderParser.h"
#include "nsIComponentManager.h" #include "nsIComponentManager.h"
#include "nsEmitterUtils.h" #include "nsEmitterUtils.h"
#include "nsIMimeStreamConverter.h" #include "nsIMimeStreamConverter.h"

Просмотреть файл

@ -15,7 +15,6 @@
#include "nsIURI.h" #include "nsIURI.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsIMimeMiscStatus.h" #include "nsIMimeMiscStatus.h"
#include "nsIMsgHeaderParser.h"
#include "nsIPipe.h" #include "nsIPipe.h"
#include "nsIStringBundle.h" #include "nsIStringBundle.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -126,7 +125,6 @@ protected:
// For header caching... // For header caching...
nsVoidArray *mHeaderArray; nsVoidArray *mHeaderArray;
nsVoidArray *mEmbeddedHeaderArray; nsVoidArray *mEmbeddedHeaderArray;
nsCOMPtr<nsIMsgHeaderParser> mHeaderParser;
// For body caching... // For body caching...
bool mBodyStarted; bool mBodyStarted;

Просмотреть файл

@ -49,7 +49,7 @@ nsMimePlainEmitter::AddHeaderField(const char *field, const char *value)
} }
nsresult nsresult
nsMimePlainEmitter::EndHeader() nsMimePlainEmitter::EndHeader(const nsACString &name)
{ {
UtilityWriteCRLF(""); UtilityWriteCRLF("");
return NS_OK; return NS_OK;

Просмотреть файл

@ -23,7 +23,7 @@ public:
NS_IMETHOD StartHeader(bool rootMailHeader, bool headerOnly, const char *msgID, NS_IMETHOD StartHeader(bool rootMailHeader, bool headerOnly, const char *msgID,
const char *outCharset) MOZ_OVERRIDE; const char *outCharset) MOZ_OVERRIDE;
NS_IMETHOD AddHeaderField(const char *field, const char *value) MOZ_OVERRIDE; NS_IMETHOD AddHeaderField(const char *field, const char *value) MOZ_OVERRIDE;
NS_IMETHOD EndHeader(); NS_IMETHOD EndHeader(const nsACString &buf) MOZ_OVERRIDE;
NS_IMETHOD WriteBody(const nsACString &buf, uint32_t *amountWritten) MOZ_OVERRIDE; NS_IMETHOD WriteBody(const nsACString &buf, uint32_t *amountWritten) MOZ_OVERRIDE;
}; };

Просмотреть файл

@ -142,7 +142,7 @@ nsMimeXmlEmitter::AddHeaderField(const char *field, const char *value)
} }
nsresult nsresult
nsMimeXmlEmitter::EndHeader() nsMimeXmlEmitter::EndHeader(const nsACString &name)
{ {
UtilityWrite("</mailheader>"); UtilityWrite("</mailheader>");
return NS_OK; return NS_OK;

Просмотреть файл

@ -25,7 +25,7 @@ public:
NS_IMETHOD StartHeader(bool rootMailHeader, bool headerOnly, const char *msgID, NS_IMETHOD StartHeader(bool rootMailHeader, bool headerOnly, const char *msgID,
const char *outCharset) MOZ_OVERRIDE; const char *outCharset) MOZ_OVERRIDE;
NS_IMETHOD AddHeaderField(const char *field, const char *value) MOZ_OVERRIDE; NS_IMETHOD AddHeaderField(const char *field, const char *value) MOZ_OVERRIDE;
NS_IMETHOD EndHeader(); NS_IMETHOD EndHeader(const nsACString &buf) MOZ_OVERRIDE;
// Attachment handling routines // Attachment handling routines
NS_IMETHOD StartAttachment(const nsACString &name, NS_IMETHOD StartAttachment(const nsACString &name,

Просмотреть файл

@ -20,11 +20,14 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsIX509Cert.h" #include "nsIX509Cert.h"
#include "nsIMsgHeaderParser.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
#include "mozilla/mailnews/MimeHeaderParser.h"
using namespace mozilla::mailnews;
#define MIME_SUPERCLASS mimeEncryptedClass #define MIME_SUPERCLASS mimeEncryptedClass
MimeDefClass(MimeEncryptedCMS, MimeEncryptedCMSClass, MimeDefClass(MimeEncryptedCMS, MimeEncryptedCMSClass,
@ -136,20 +139,6 @@ bool MimeEncryptedCMS_encrypted_p (MimeObject *obj)
return false; return false;
} }
// extern MimeMessageClass mimeMessageClass; /* gag */
static void ParseRFC822Addresses (const char *line, nsCString &names, nsCString &addresses)
{
uint32_t numAddresses;
nsresult res;
nsCOMPtr<nsIMsgHeaderParser> pHeader = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, &res);
if (NS_SUCCEEDED(res))
{
pHeader->ParseHeaderAddresses(line, getter_Copies(names),
getter_Copies(addresses), &numAddresses);
}
}
bool MimeCMSHeadersAndCertsMatch(nsICMSMessage *content_info, bool MimeCMSHeadersAndCertsMatch(nsICMSMessage *content_info,
nsIX509Cert *signerCert, nsIX509Cert *signerCert,
@ -564,23 +553,17 @@ void MimeCMSGetFromSender(MimeObject *obj,
/* Find the names and addresses in the From and/or Sender fields. /* Find the names and addresses in the From and/or Sender fields.
*/ */
char *s; nsCString s;
/* Extract the name and address of the "From:" field. */ /* Extract the name and address of the "From:" field. */
s = MimeHeaders_get(msg_headers, HEADER_FROM, false, false); s.Adopt(MimeHeaders_get(msg_headers, HEADER_FROM, false, false));
if (s) if (!s.IsEmpty())
{ ExtractFirstAddress(EncodedHeader(s), from_name, from_addr);
ParseRFC822Addresses(s, from_name, from_addr);
PR_FREEIF(s);
}
/* Extract the name and address of the "Sender:" field. */ /* Extract the name and address of the "Sender:" field. */
s = MimeHeaders_get(msg_headers, HEADER_SENDER, false, false); s.Adopt(MimeHeaders_get(msg_headers, HEADER_SENDER, false, false));
if (s) if (!s.IsEmpty())
{ ExtractFirstAddress(EncodedHeader(s), sender_name, sender_addr);
ParseRFC822Addresses(s, sender_name, sender_addr);
PR_FREEIF(s);
}
} }
void MimeCMSRequestAsyncSignatureVerification(nsICMSMessage *aCMSMsg, void MimeCMSRequestAsyncSignatureVerification(nsICMSMessage *aCMSMsg,

Просмотреть файл

@ -44,10 +44,12 @@
#include "nsMsgUtils.h" #include "nsMsgUtils.h"
#include "nsCExternalHandlerService.h" #include "nsCExternalHandlerService.h"
#include "nsIMIMEService.h" #include "nsIMIMEService.h"
#include "nsIMsgHeaderParser.h"
#include "nsIMsgAccountManager.h" #include "nsIMsgAccountManager.h"
#include "nsMsgBaseCID.h" #include "nsMsgBaseCID.h"
#include "nsIMimeConverter.h" // for MimeConverterOutputCallback #include "nsIMimeConverter.h" // for MimeConverterOutputCallback
#include "mozilla/mailnews/MimeHeaderParser.h"
using namespace mozilla::mailnews;
// //
// Header strings... // Header strings...
@ -457,7 +459,7 @@ mime_free_attachments(nsTArray<nsMsgAttachedFile *> &attachments)
if (attachments.Length() <= 0) if (attachments.Length() <= 0)
return; return;
for (int i = 0; i < attachments.Length(); i++) for (uint32_t i = 0; i < attachments.Length(); i++)
{ {
if (attachments[i]->m_tmpFile) if (attachments[i]->m_tmpFile)
{ {
@ -551,7 +553,7 @@ FAIL:
static void static void
mime_intl_insert_message_header_1(char **body, mime_intl_insert_message_header_1(char **body,
char **hdr_value, const char *hdr_value,
const char *hdr_str, const char *hdr_str,
const char *html_hdr_str, const char *html_hdr_str,
const char *mailcharset, const char *mailcharset,
@ -580,7 +582,7 @@ mime_intl_insert_message_header_1(char **body,
// MIME decode header // MIME decode header
nsAutoCString utf8Value; nsAutoCString utf8Value;
MIME_DecodeMimeHeader(*hdr_value, mailcharset, false, true, utf8Value); MIME_DecodeMimeHeader(hdr_value, mailcharset, false, true, utf8Value);
if (!utf8Value.IsEmpty()) { if (!utf8Value.IsEmpty()) {
char *escaped = nullptr; char *escaped = nullptr;
if (htmlEdit) if (htmlEdit)
@ -588,7 +590,7 @@ mime_intl_insert_message_header_1(char **body,
NS_MsgSACat(body, escaped ? escaped : utf8Value.get()); NS_MsgSACat(body, escaped ? escaped : utf8Value.get());
NS_Free(escaped); NS_Free(escaped);
} else { } else {
NS_MsgSACat(body, *hdr_value); // raw MIME encoded string NS_MsgSACat(body, hdr_value); // raw MIME encoded string
} }
if (htmlEdit) if (htmlEdit)
@ -628,24 +630,23 @@ MimeGetReplyHeaderOriginalMessage(nsACString &retString)
/* given an address string passed though parameter "address", this one will be converted /* given an address string passed though parameter "address", this one will be converted
and returned through the same parameter. The original string will be destroyed and returned through the same parameter. The original string will be destroyed
*/ */
static void UnquoteMimeAddress(nsIMsgHeaderParser* parser, char** address) static void UnquoteMimeAddress(nsACString &mimeHeader, const char *charset)
{ {
if (parser && address && *address && **address) if (!mimeHeader.IsEmpty())
{ {
char *result; nsTArray<nsCString> addresses;
if (NS_SUCCEEDED(parser->UnquotePhraseOrAddr(*address, false, &result))) ExtractDisplayAddresses(EncodedHeader(mimeHeader, charset),
UTF16ArrayAdapter<>(addresses));
mimeHeader.Truncate();
uint32_t count = addresses.Length();
for (uint32_t i = 0; i < count; i++)
{ {
if (result && *result) if (i != 0)
{ mimeHeader.AppendASCII(", ");
PR_Free(*address); mimeHeader += addresses[i];
*address = result;
return;
}
PR_FREEIF(result);
} }
} }
return;
} }
static void static void
@ -654,8 +655,6 @@ mime_insert_all_headers(char **body,
MSG_ComposeFormat composeFormat, MSG_ComposeFormat composeFormat,
char *mailcharset) char *mailcharset)
{ {
nsCOMPtr<nsIMsgHeaderParser> parser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID);
bool htmlEdit = (composeFormat == nsIMsgCompFormat::HTML); bool htmlEdit = (composeFormat == nsIMsgCompFormat::HTML);
char *newBody = NULL; char *newBody = NULL;
char *html_tag = nullptr; char *html_tag = nullptr;
@ -692,7 +691,6 @@ mime_insert_all_headers(char **body,
char *colon, *ocolon; char *colon, *ocolon;
char *contents; char *contents;
char *name = 0; char *name = 0;
char *c2 = 0;
// Hack for BSD Mailbox delimiter. // Hack for BSD Mailbox delimiter.
if (i == 0 && head[0] == 'F' && !strncmp(head, "From ", 5)) if (i == 0 && head[0] == 'F' && !strncmp(head, "From ", 5))
@ -730,14 +728,8 @@ mime_insert_all_headers(char **body,
memcpy(name, head, colon - head); memcpy(name, head, colon - head);
name[colon - head] = 0; name[colon - head] = 0;
c2 = (char *)PR_MALLOC(end - contents + 1); nsAutoCString headerValue;
if (!c2) headerValue.Assign(contents, end - contents);
{
PR_Free(name);
return /* MIME_OUT_OF_MEMORY */;
}
memcpy(c2, contents, end - contents);
c2[end - contents] = 0;
/* Do not reveal bcc recipients when forwarding a message! /* Do not reveal bcc recipients when forwarding a message!
See http://bugzilla.mozilla.org/show_bug.cgi?id=41150 See http://bugzilla.mozilla.org/show_bug.cgi?id=41150
@ -748,12 +740,12 @@ mime_insert_all_headers(char **body,
!PL_strcasecmp(name, "resent-to") || !PL_strcasecmp(name, "to") || !PL_strcasecmp(name, "resent-to") || !PL_strcasecmp(name, "to") ||
!PL_strcasecmp(name, "resent-cc") || !PL_strcasecmp(name, "cc") || !PL_strcasecmp(name, "resent-cc") || !PL_strcasecmp(name, "cc") ||
!PL_strcasecmp(name, "reply-to")) !PL_strcasecmp(name, "reply-to"))
UnquoteMimeAddress(parser, &c2); UnquoteMimeAddress(headerValue, mailcharset);
mime_intl_insert_message_header_1(&newBody, &c2, name, name, mailcharset, htmlEdit); mime_intl_insert_message_header_1(&newBody, headerValue.get(), name, name,
mailcharset, htmlEdit);
} }
PR_Free(name); PR_Free(name);
PR_Free(c2);
} }
if (htmlEdit) if (htmlEdit)
@ -789,15 +781,15 @@ mime_insert_normal_headers(char **body,
char *subject = MimeHeaders_get(headers, HEADER_SUBJECT, false, false); char *subject = MimeHeaders_get(headers, HEADER_SUBJECT, false, false);
char *resent_comments = MimeHeaders_get(headers, HEADER_RESENT_COMMENTS, false, false); char *resent_comments = MimeHeaders_get(headers, HEADER_RESENT_COMMENTS, false, false);
char *resent_date = MimeHeaders_get(headers, HEADER_RESENT_DATE, false, true); char *resent_date = MimeHeaders_get(headers, HEADER_RESENT_DATE, false, true);
char *resent_from = MimeHeaders_get(headers, HEADER_RESENT_FROM, false, true); nsCString resent_from(MimeHeaders_get(headers, HEADER_RESENT_FROM, false, true));
char *resent_to = MimeHeaders_get(headers, HEADER_RESENT_TO, false, true); nsCString resent_to(MimeHeaders_get(headers, HEADER_RESENT_TO, false, true));
char *resent_cc = MimeHeaders_get(headers, HEADER_RESENT_CC, false, true); nsCString resent_cc(MimeHeaders_get(headers, HEADER_RESENT_CC, false, true));
char *date = MimeHeaders_get(headers, HEADER_DATE, false, true); char *date = MimeHeaders_get(headers, HEADER_DATE, false, true);
char *from = MimeHeaders_get(headers, HEADER_FROM, false, true); nsCString from(MimeHeaders_get(headers, HEADER_FROM, false, true));
char *reply_to = MimeHeaders_get(headers, HEADER_REPLY_TO, false, true); nsCString reply_to(MimeHeaders_get(headers, HEADER_REPLY_TO, false, true));
char *organization = MimeHeaders_get(headers, HEADER_ORGANIZATION, false, false); char *organization = MimeHeaders_get(headers, HEADER_ORGANIZATION, false, false);
char *to = MimeHeaders_get(headers, HEADER_TO, false, true); nsCString to(MimeHeaders_get(headers, HEADER_TO, false, true));
char *cc = MimeHeaders_get(headers, HEADER_CC, false, true); nsCString cc(MimeHeaders_get(headers, HEADER_CC, false, true));
char *newsgroups = MimeHeaders_get(headers, HEADER_NEWSGROUPS, false, true); char *newsgroups = MimeHeaders_get(headers, HEADER_NEWSGROUPS, false, true);
char *followup_to = MimeHeaders_get(headers, HEADER_FOLLOWUP_TO, false, true); char *followup_to = MimeHeaders_get(headers, HEADER_FOLLOWUP_TO, false, true);
char *references = MimeHeaders_get(headers, HEADER_REFERENCES, false, true); char *references = MimeHeaders_get(headers, HEADER_REFERENCES, false, true);
@ -806,20 +798,19 @@ mime_insert_normal_headers(char **body,
html_tag = PL_strcasestr(*body, "<HTML>"); html_tag = PL_strcasestr(*body, "<HTML>");
bool htmlEdit = composeFormat == nsIMsgCompFormat::HTML; bool htmlEdit = composeFormat == nsIMsgCompFormat::HTML;
if (!from) if (from.IsEmpty())
from = MimeHeaders_get(headers, HEADER_SENDER, false, true); from.Adopt(MimeHeaders_get(headers, HEADER_SENDER, false, true));
if (!resent_from) if (resent_from.IsEmpty())
resent_from = MimeHeaders_get(headers, HEADER_RESENT_SENDER, false, resent_from.Adopt(MimeHeaders_get(headers, HEADER_RESENT_SENDER, false,
true); true));
nsCOMPtr<nsIMsgHeaderParser> parser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID); UnquoteMimeAddress(resent_from, mailcharset);
UnquoteMimeAddress(parser, &resent_from); UnquoteMimeAddress(resent_to, mailcharset);
UnquoteMimeAddress(parser, &resent_to); UnquoteMimeAddress(resent_cc, mailcharset);
UnquoteMimeAddress(parser, &resent_cc); UnquoteMimeAddress(reply_to, mailcharset);
UnquoteMimeAddress(parser, &reply_to); UnquoteMimeAddress(from, mailcharset);
UnquoteMimeAddress(parser, &from); UnquoteMimeAddress(to, mailcharset);
UnquoteMimeAddress(parser, &to); UnquoteMimeAddress(cc, mailcharset);
UnquoteMimeAddress(parser, &cc);
nsCString replyHeader; nsCString replyHeader;
MimeGetReplyHeaderOriginalMessage(replyHeader); MimeGetReplyHeaderOriginalMessage(replyHeader);
@ -835,70 +826,70 @@ mime_insert_normal_headers(char **body,
NS_MsgSACat(&newBody, replyHeader.get()); NS_MsgSACat(&newBody, replyHeader.get());
} }
if (subject) if (subject)
mime_intl_insert_message_header_1(&newBody, &subject, HEADER_SUBJECT, mime_intl_insert_message_header_1(&newBody, subject, HEADER_SUBJECT,
MimeGetNamedString(MIME_MHTML_SUBJECT), MimeGetNamedString(MIME_MHTML_SUBJECT),
mailcharset, htmlEdit); mailcharset, htmlEdit);
if (resent_comments) if (resent_comments)
mime_intl_insert_message_header_1(&newBody, &resent_comments, mime_intl_insert_message_header_1(&newBody, resent_comments,
HEADER_RESENT_COMMENTS, HEADER_RESENT_COMMENTS,
MimeGetNamedString(MIME_MHTML_RESENT_COMMENTS), MimeGetNamedString(MIME_MHTML_RESENT_COMMENTS),
mailcharset, htmlEdit); mailcharset, htmlEdit);
if (resent_date) if (resent_date)
mime_intl_insert_message_header_1(&newBody, &resent_date, mime_intl_insert_message_header_1(&newBody, resent_date,
HEADER_RESENT_DATE, HEADER_RESENT_DATE,
MimeGetNamedString(MIME_MHTML_RESENT_DATE), MimeGetNamedString(MIME_MHTML_RESENT_DATE),
mailcharset, htmlEdit); mailcharset, htmlEdit);
if (resent_from) if (!resent_from.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &resent_from, mime_intl_insert_message_header_1(&newBody, resent_from.get(),
HEADER_RESENT_FROM, HEADER_RESENT_FROM,
MimeGetNamedString(MIME_MHTML_RESENT_FROM), MimeGetNamedString(MIME_MHTML_RESENT_FROM),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
if (resent_to) if (!resent_to.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &resent_to, mime_intl_insert_message_header_1(&newBody, resent_to.get(),
HEADER_RESENT_TO, HEADER_RESENT_TO,
MimeGetNamedString(MIME_MHTML_RESENT_TO), MimeGetNamedString(MIME_MHTML_RESENT_TO),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
if (resent_cc) if (!resent_cc.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &resent_cc, mime_intl_insert_message_header_1(&newBody, resent_cc.get(),
HEADER_RESENT_CC, HEADER_RESENT_CC,
MimeGetNamedString(MIME_MHTML_RESENT_CC), MimeGetNamedString(MIME_MHTML_RESENT_CC),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
if (date) if (date)
mime_intl_insert_message_header_1(&newBody, &date, HEADER_DATE, mime_intl_insert_message_header_1(&newBody, date, HEADER_DATE,
MimeGetNamedString(MIME_MHTML_DATE), MimeGetNamedString(MIME_MHTML_DATE),
mailcharset, htmlEdit); mailcharset, htmlEdit);
if (from) if (!from.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &from, HEADER_FROM, mime_intl_insert_message_header_1(&newBody, from.get(), HEADER_FROM,
MimeGetNamedString(MIME_MHTML_FROM), MimeGetNamedString(MIME_MHTML_FROM),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
if (reply_to) if (!reply_to.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &reply_to, HEADER_REPLY_TO, mime_intl_insert_message_header_1(&newBody, reply_to.get(), HEADER_REPLY_TO,
MimeGetNamedString(MIME_MHTML_REPLY_TO), MimeGetNamedString(MIME_MHTML_REPLY_TO),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
if (organization) if (organization)
mime_intl_insert_message_header_1(&newBody, &organization, mime_intl_insert_message_header_1(&newBody, organization,
HEADER_ORGANIZATION, HEADER_ORGANIZATION,
MimeGetNamedString(MIME_MHTML_ORGANIZATION), MimeGetNamedString(MIME_MHTML_ORGANIZATION),
mailcharset, htmlEdit); mailcharset, htmlEdit);
if (to) if (!to.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &to, HEADER_TO, mime_intl_insert_message_header_1(&newBody, to.get(), HEADER_TO,
MimeGetNamedString(MIME_MHTML_TO), MimeGetNamedString(MIME_MHTML_TO),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
if (cc) if (cc.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &cc, HEADER_CC, mime_intl_insert_message_header_1(&newBody, cc.get(), HEADER_CC,
MimeGetNamedString(MIME_MHTML_CC), MimeGetNamedString(MIME_MHTML_CC),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
@ -907,12 +898,12 @@ mime_insert_normal_headers(char **body,
See http://bugzilla.mozilla.org/show_bug.cgi?id=41150 See http://bugzilla.mozilla.org/show_bug.cgi?id=41150
*/ */
if (newsgroups) if (newsgroups)
mime_intl_insert_message_header_1(&newBody, &newsgroups, HEADER_NEWSGROUPS, mime_intl_insert_message_header_1(&newBody, newsgroups, HEADER_NEWSGROUPS,
MimeGetNamedString(MIME_MHTML_NEWSGROUPS), MimeGetNamedString(MIME_MHTML_NEWSGROUPS),
mailcharset, htmlEdit); mailcharset, htmlEdit);
if (followup_to) if (followup_to)
{ {
mime_intl_insert_message_header_1(&newBody, &followup_to, mime_intl_insert_message_header_1(&newBody, followup_to,
HEADER_FOLLOWUP_TO, HEADER_FOLLOWUP_TO,
MimeGetNamedString(MIME_MHTML_FOLLOWUP_TO), MimeGetNamedString(MIME_MHTML_FOLLOWUP_TO),
mailcharset, htmlEdit); mailcharset, htmlEdit);
@ -920,7 +911,7 @@ mime_insert_normal_headers(char **body,
// only show references for newsgroups // only show references for newsgroups
if (newsgroups && references) if (newsgroups && references)
{ {
mime_intl_insert_message_header_1(&newBody, &references, mime_intl_insert_message_header_1(&newBody, references,
HEADER_REFERENCES, HEADER_REFERENCES,
MimeGetNamedString(MIME_MHTML_REFERENCES), MimeGetNamedString(MIME_MHTML_REFERENCES),
mailcharset, htmlEdit); mailcharset, htmlEdit);
@ -948,15 +939,8 @@ mime_insert_normal_headers(char **body,
PR_FREEIF(subject); PR_FREEIF(subject);
PR_FREEIF(resent_comments); PR_FREEIF(resent_comments);
PR_FREEIF(resent_date); PR_FREEIF(resent_date);
PR_FREEIF(resent_from);
PR_FREEIF(resent_to);
PR_FREEIF(resent_cc);
PR_FREEIF(date); PR_FREEIF(date);
PR_FREEIF(from);
PR_FREEIF(reply_to);
PR_FREEIF(organization); PR_FREEIF(organization);
PR_FREEIF(to);
PR_FREEIF(cc);
PR_FREEIF(newsgroups); PR_FREEIF(newsgroups);
PR_FREEIF(followup_to); PR_FREEIF(followup_to);
PR_FREEIF(references); PR_FREEIF(references);
@ -970,12 +954,11 @@ mime_insert_micro_headers(char **body,
{ {
char *newBody = NULL; char *newBody = NULL;
char *subject = MimeHeaders_get(headers, HEADER_SUBJECT, false, false); char *subject = MimeHeaders_get(headers, HEADER_SUBJECT, false, false);
char *from = MimeHeaders_get(headers, HEADER_FROM, false, true); nsCString from(MimeHeaders_get(headers, HEADER_FROM, false, true));
char *resent_from = MimeHeaders_get(headers, HEADER_RESENT_FROM, false, nsCString resent_from(MimeHeaders_get(headers, HEADER_RESENT_FROM, false, true));
true);
char *date = MimeHeaders_get(headers, HEADER_DATE, false, true); char *date = MimeHeaders_get(headers, HEADER_DATE, false, true);
char *to = MimeHeaders_get(headers, HEADER_TO, false, true); nsCString to(MimeHeaders_get(headers, HEADER_TO, false, true));
char *cc = MimeHeaders_get(headers, HEADER_CC, false, true); nsCString cc(MimeHeaders_get(headers, HEADER_CC, false, true));
char *newsgroups = MimeHeaders_get(headers, HEADER_NEWSGROUPS, false, char *newsgroups = MimeHeaders_get(headers, HEADER_NEWSGROUPS, false,
true); true);
const char *html_tag = nullptr; const char *html_tag = nullptr;
@ -983,19 +966,17 @@ mime_insert_micro_headers(char **body,
html_tag = PL_strcasestr(*body, "<HTML>"); html_tag = PL_strcasestr(*body, "<HTML>");
bool htmlEdit = composeFormat == nsIMsgCompFormat::HTML; bool htmlEdit = composeFormat == nsIMsgCompFormat::HTML;
if (!from) if (from.IsEmpty())
from = MimeHeaders_get(headers, HEADER_SENDER, false, true); from.Adopt(MimeHeaders_get(headers, HEADER_SENDER, false, true));
if (!resent_from) if (resent_from.IsEmpty())
resent_from = MimeHeaders_get(headers, HEADER_RESENT_SENDER, false, resent_from.Adopt(MimeHeaders_get(headers, HEADER_RESENT_SENDER, false, true));
true);
if (!date) if (!date)
date = MimeHeaders_get(headers, HEADER_RESENT_DATE, false, true); date = MimeHeaders_get(headers, HEADER_RESENT_DATE, false, true);
nsCOMPtr<nsIMsgHeaderParser> parser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID); UnquoteMimeAddress(resent_from, mailcharset);
UnquoteMimeAddress(parser, &resent_from); UnquoteMimeAddress(from, mailcharset);
UnquoteMimeAddress(parser, &from); UnquoteMimeAddress(to, mailcharset);
UnquoteMimeAddress(parser, &to); UnquoteMimeAddress(cc, mailcharset);
UnquoteMimeAddress(parser, &cc);
nsCString replyHeader; nsCString replyHeader;
MimeGetReplyHeaderOriginalMessage(replyHeader); MimeGetReplyHeaderOriginalMessage(replyHeader);
@ -1012,38 +993,38 @@ mime_insert_micro_headers(char **body,
NS_MsgSACat(&newBody, replyHeader.get()); NS_MsgSACat(&newBody, replyHeader.get());
} }
if (from) if (!from.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &from, HEADER_FROM, mime_intl_insert_message_header_1(&newBody, from.get(), HEADER_FROM,
MimeGetNamedString(MIME_MHTML_FROM), MimeGetNamedString(MIME_MHTML_FROM),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
if (subject) if (subject)
mime_intl_insert_message_header_1(&newBody, &subject, HEADER_SUBJECT, mime_intl_insert_message_header_1(&newBody, subject, HEADER_SUBJECT,
MimeGetNamedString(MIME_MHTML_SUBJECT), MimeGetNamedString(MIME_MHTML_SUBJECT),
mailcharset, htmlEdit); mailcharset, htmlEdit);
/* /*
if (date) if (date)
mime_intl_insert_message_header_1(&newBody, &date, HEADER_DATE, mime_intl_insert_message_header_1(&newBody, date, HEADER_DATE,
MimeGetNamedString(MIME_MHTML_DATE), MimeGetNamedString(MIME_MHTML_DATE),
mailcharset, htmlEdit); mailcharset, htmlEdit);
*/ */
if (resent_from) if (resent_from.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &resent_from, mime_intl_insert_message_header_1(&newBody, resent_from.get(),
HEADER_RESENT_FROM, HEADER_RESENT_FROM,
MimeGetNamedString(MIME_MHTML_RESENT_FROM), MimeGetNamedString(MIME_MHTML_RESENT_FROM),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
if (to) if (to.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &to, HEADER_TO, mime_intl_insert_message_header_1(&newBody, to.get(), HEADER_TO,
MimeGetNamedString(MIME_MHTML_TO), MimeGetNamedString(MIME_MHTML_TO),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
if (cc) if (cc.IsEmpty())
{ {
mime_intl_insert_message_header_1(&newBody, &cc, HEADER_CC, mime_intl_insert_message_header_1(&newBody, cc.get(), HEADER_CC,
MimeGetNamedString(MIME_MHTML_CC), MimeGetNamedString(MIME_MHTML_CC),
mailcharset, htmlEdit); mailcharset, htmlEdit);
} }
@ -1052,7 +1033,7 @@ mime_insert_micro_headers(char **body,
See http://bugzilla.mozilla.org/show_bug.cgi?id=41150 See http://bugzilla.mozilla.org/show_bug.cgi?id=41150
*/ */
if (newsgroups) if (newsgroups)
mime_intl_insert_message_header_1(&newBody, &newsgroups, HEADER_NEWSGROUPS, mime_intl_insert_message_header_1(&newBody, newsgroups, HEADER_NEWSGROUPS,
MimeGetNamedString(MIME_MHTML_NEWSGROUPS), MimeGetNamedString(MIME_MHTML_NEWSGROUPS),
mailcharset, htmlEdit); mailcharset, htmlEdit);
if (htmlEdit) if (htmlEdit)
@ -1076,11 +1057,7 @@ mime_insert_micro_headers(char **body,
*body = newBody; *body = newBody;
} }
PR_FREEIF(subject); PR_FREEIF(subject);
PR_FREEIF(from);
PR_FREEIF(resent_from);
PR_FREEIF(date); PR_FREEIF(date);
PR_FREEIF(to);
PR_FREEIF(cc);
PR_FREEIF(newsgroups); PR_FREEIF(newsgroups);
} }