Issue #1258 - Part 1: Import mailnews, ldap, and mork from comm-esr52.9.1

This commit is contained in:
Matt A. Tobin 2019-11-03 00:17:46 -04:00 • committed by Roy Tam
commit e400f4130a
1564 changed files with 510348 additions and 0 deletions

View file

@ -0,0 +1,21 @@
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS += [
'nsMimeEmitterCID.h',
]
SOURCES += [
'nsEmitterUtils.cpp',
'nsMimeBaseEmitter.cpp',
'nsMimeHtmlEmitter.cpp',
'nsMimePlainEmitter.cpp',
'nsMimeRawEmitter.cpp',
'nsMimeRebuffer.cpp',
'nsMimeXmlEmitter.cpp',
]
FINAL_LIBRARY = 'mail'

View file

@ -0,0 +1,67 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCOMPtr.h"
#include "prmem.h"
#include "plstr.h"
#include "nsMailHeaders.h"
#include "nsIMimeEmitter.h"
#include "nsIStringBundle.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsIURI.h"
#include "prprf.h"
extern "C" bool
EmitThisHeaderForPrefSetting(int32_t dispType, const char *header)
{
if (nsMimeHeaderDisplayTypes::AllHeaders == dispType)
return true;
if ((!header) || (!*header))
return false;
if (nsMimeHeaderDisplayTypes::MicroHeaders == dispType)
{
if (
(!strcmp(header, HEADER_SUBJECT)) ||
(!strcmp(header, HEADER_FROM)) ||
(!strcmp(header, HEADER_DATE))
)
return true;
else
return false;
}
if (nsMimeHeaderDisplayTypes::NormalHeaders == dispType)
{
if (
(!strcmp(header, HEADER_DATE)) ||
(!strcmp(header, HEADER_TO)) ||
(!strcmp(header, HEADER_SUBJECT)) ||
(!strcmp(header, HEADER_SENDER)) ||
(!strcmp(header, HEADER_RESENT_TO)) ||
(!strcmp(header, HEADER_RESENT_SENDER)) ||
(!strcmp(header, HEADER_RESENT_FROM)) ||
(!strcmp(header, HEADER_RESENT_CC)) ||
(!strcmp(header, HEADER_REPLY_TO)) ||
(!strcmp(header, HEADER_REFERENCES)) ||
(!strcmp(header, HEADER_NEWSGROUPS)) ||
(!strcmp(header, HEADER_MESSAGE_ID)) ||
(!strcmp(header, HEADER_FROM)) ||
(!strcmp(header, HEADER_FOLLOWUP_TO)) ||
(!strcmp(header, HEADER_CC)) ||
(!strcmp(header, HEADER_ORGANIZATION)) ||
(!strcmp(header, HEADER_REPLY_TO)) ||
(!strcmp(header, HEADER_BCC))
)
return true;
else
return false;
}
return true;
}

View file

@ -0,0 +1,14 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _nsEmitterUtils_h_
#define _nsEmitterUtils_h_
#include "prmem.h"
#include "plstr.h"
extern "C" bool EmitThisHeaderForPrefSetting(int32_t dispType, const char *header);
#endif // _nsEmitterUtils_h_

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,147 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _nsMimeBaseEmitter_h_
#define _nsMimeBaseEmitter_h_
#include "prio.h"
#include "nsIMimeEmitter.h"
#include "nsMimeRebuffer.h"
#include "nsIStreamListener.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
#include "nsIAsyncInputStream.h"
#include "nsIURI.h"
#include "nsIChannel.h"
#include "nsIMimeMiscStatus.h"
#include "nsIPipe.h"
#include "nsIStringBundle.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsIMimeConverter.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIDateTimeFormat.h"
//
// The base emitter will serve as the place to do all of the caching,
// sorting, etc... of mail headers and bodies for this internally developed
// emitter library. The other emitter classes in this file (nsMimeHTMLEmitter, etc.)
// will only be concerned with doing output processing ONLY.
//
//
// Used for keeping track of the attachment information...
//
typedef struct {
char *displayName;
char *urlSpec;
char *contentType;
bool isExternalAttachment;
} attachmentInfoType;
//
// For header info...
//
typedef struct {
char *name;
char *value;
} headerInfoType;
class nsMimeBaseEmitter : public nsIMimeEmitter,
public nsIInterfaceRequestor
{
public:
nsMimeBaseEmitter ();
// nsISupports interface
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIMIMEEMITTER
NS_DECL_NSIINTERFACEREQUESTOR
// Utility output functions...
NS_IMETHOD UtilityWrite(const nsACString &buf);
NS_IMETHOD UtilityWriteCRLF(const char *buf);
// For string bundle usage...
char *MimeGetStringByName(const char *aHeaderName);
char *MimeGetStringByID(int32_t aID);
char *LocalizeHeaderName(const char *aHeaderName, const char *aDefaultName);
// For header processing...
const char *GetHeaderValue(const char *aHeaderName);
// To write out a stored header array as HTML
virtual nsresult WriteHeaderFieldHTMLPrefix(const nsACString &name);
virtual nsresult WriteHeaderFieldHTML(const char *field, const char *value);
virtual nsresult WriteHeaderFieldHTMLPostfix();
protected:
virtual ~nsMimeBaseEmitter();
// Internal methods...
void CleanupHeaderArray(nsTArray<headerInfoType*> *aArray);
// For header output...
nsresult DumpSubjectFromDate();
nsresult DumpToCC();
nsresult DumpRestOfHeaders();
nsresult OutputGenericHeader(const char *aHeaderVal);
nsresult WriteHelper(const nsACString &buf, uint32_t *countWritten);
// For string bundle usage...
nsCOMPtr<nsIStringBundle> m_stringBundle; // for translated strings
nsCOMPtr<nsIStringBundle> m_headerStringBundle; // for non-translated header strings
// For buffer management on output
MimeRebuffer *mBufferMgr;
// mscott
// don't ref count the streams....the emitter is owned by the converter
// which owns these streams...
//
nsIOutputStream *mOutStream;
nsIInputStream *mInputStream;
nsIStreamListener *mOutListener;
nsCOMPtr<nsIChannel> mChannel;
// For gathering statistics on processing...
uint32_t mTotalWritten;
uint32_t mTotalRead;
// Output control and info...
bool mDocHeader; // For header determination...
nsIURI *mURL; // the url for the data being processed...
int32_t mHeaderDisplayType; // The setting for header output...
nsCString mHTMLHeaders; // HTML Header Data...
// For attachment processing...
int32_t mAttachCount;
nsTArray<attachmentInfoType*> *mAttachArray;
attachmentInfoType *mCurrentAttachment;
// For header caching...
nsTArray<headerInfoType*> *mHeaderArray;
nsTArray<headerInfoType*> *mEmbeddedHeaderArray;
// For body caching...
bool mBodyStarted;
nsCString mBody;
bool mFirstHeaders;
// For the format being used...
int32_t mFormat;
// For I18N Conversion...
nsCOMPtr<nsIMimeConverter> mUnicodeConverter;
nsString mCharset;
nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
nsresult GenerateDateString(const char * dateString, nsACString& formattedDate,
bool showDateForToday);
// The caller is expected to free the result of GetLocalizedDateString
char* GetLocalizedDateString(const char * dateString);
};
#endif /* _nsMimeBaseEmitter_h_ */

View file

@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsMimeEmitterCID_h__
#define nsMimeEmitterCID_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIComponentManager.h"
#define NS_MIME_EMITTER_CONTRACTID_PREFIX \
"@mozilla.org/messenger/mimeemitter;1?type="
#define NS_HTML_MIME_EMITTER_CONTRACTID \
NS_MIME_EMITTER_CONTRACTID_PREFIX "text/html"
// {F0A8AF16-DCCE-11d2-A411-00805F613C79}
#define NS_HTML_MIME_EMITTER_CID \
{ 0xf0a8af16, 0xdcce, 0x11d2, \
{ 0xa4, 0x11, 0x0, 0x80, 0x5f, 0x61, 0x3c, 0x79 } }
#define NS_XML_MIME_EMITTER_CONTRACTID \
NS_MIME_EMITTER_CONTRACTID_PREFIX "text/xml"
// {977E418F-E392-11d2-A2AC-00A024A7D144}
#define NS_XML_MIME_EMITTER_CID \
{ 0x977e418f, 0xe392, 0x11d2, \
{ 0xa2, 0xac, 0x0, 0xa0, 0x24, 0xa7, 0xd1, 0x44 } }
#define NS_RAW_MIME_EMITTER_CONTRACTID \
NS_MIME_EMITTER_CONTRACTID_PREFIX "raw"
// {F0A8AF16-DCFF-11d2-A411-00805F613C79}
#define NS_RAW_MIME_EMITTER_CID \
{ 0xf0a8af16, 0xdcff, 0x11d2, \
{ 0xa4, 0x11, 0x0, 0x80, 0x5f, 0x61, 0x3c, 0x79 } }
#define NS_XUL_MIME_EMITTER_CONTRACTID \
NS_MIME_EMITTER_CONTRACTID_PREFIX "application/vnd.mozilla.xul+xml"
// {FAA8AF16-DCFF-11d2-A411-00805F613C19}
#define NS_XUL_MIME_EMITTER_CID \
{ 0xfaa8af16, 0xdcff, 0x11d2, \
{ 0xa4, 0x11, 0x0, 0x80, 0x5f, 0x61, 0x3c, 0x19 } }
#define NS_PLAIN_MIME_EMITTER_CONTRACTID \
NS_MIME_EMITTER_CONTRACTID_PREFIX "text/plain"
// {E8892265-7653-46c5-A290-307F3404D0F3}
#define NS_PLAIN_MIME_EMITTER_CID \
{ 0xe8892265, 0x7653, 0x46c5, \
{ 0xa2, 0x90, 0x30, 0x7f, 0x34, 0x4, 0xd0, 0xf3 } }
#endif // nsMimeEmitterCID_h__

View file

@ -0,0 +1,543 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCOMPtr.h"
#include <stdio.h>
#include "nsMimeRebuffer.h"
#include "nsMimeHtmlEmitter.h"
#include "plstr.h"
#include "nsMailHeaders.h"
#include "nscore.h"
#include "nsEmitterUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIMimeStreamConverter.h"
#include "nsIMsgWindow.h"
#include "nsIMsgMailNewsUrl.h"
#include "nsMimeTypes.h"
#include "prtime.h"
#include "prprf.h"
#include "nsIStringEnumerator.h"
#include "nsServiceManagerUtils.h"
// hack: include this to fix opening news attachments.
#include "nsINntpUrl.h"
#include "nsComponentManagerUtils.h"
#include "nsIMimeConverter.h"
#include "nsMsgMimeCID.h"
#include "nsMsgUtils.h"
#include "nsAutoPtr.h"
#include "nsINetUtil.h"
#include "nsMemory.h"
#include "mozilla/Services.h"
#define VIEW_ALL_HEADERS 2
/**
* A helper class to implement nsIUTF8StringEnumerator
*/
class nsMimeStringEnumerator final : public nsIUTF8StringEnumerator {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIUTF8STRINGENUMERATOR
nsMimeStringEnumerator() : mCurrentIndex(0) {}
template<class T>
nsCString* Append(T value) { return mValues.AppendElement(value); }
protected:
~nsMimeStringEnumerator() {}
nsTArray<nsCString> mValues;
uint32_t mCurrentIndex; // consumers expect first-in first-out enumeration
};
NS_IMPL_ISUPPORTS(nsMimeStringEnumerator, nsIUTF8StringEnumerator)
NS_IMETHODIMP
nsMimeStringEnumerator::HasMore(bool *result)
{
NS_ENSURE_ARG_POINTER(result);
*result = mCurrentIndex < mValues.Length();
return NS_OK;
}
NS_IMETHODIMP
nsMimeStringEnumerator::GetNext(nsACString& result)
{
if (mCurrentIndex >= mValues.Length())
return NS_ERROR_UNEXPECTED;
result = mValues[mCurrentIndex++];
return NS_OK;
}
/*
* nsMimeHtmlEmitter definitions....
*/
nsMimeHtmlDisplayEmitter::nsMimeHtmlDisplayEmitter() : nsMimeBaseEmitter()
{
mFirst = true;
mSkipAttachment = false;
}
nsMimeHtmlDisplayEmitter::~nsMimeHtmlDisplayEmitter(void)
{
}
nsresult nsMimeHtmlDisplayEmitter::Init()
{
return NS_OK;
}
bool nsMimeHtmlDisplayEmitter::BroadCastHeadersAndAttachments()
{
// try to get a header sink if there is one....
nsCOMPtr<nsIMsgHeaderSink> headerSink;
nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));
if (NS_SUCCEEDED(rv) && headerSink && mDocHeader)
return true;
else
return false;
}
nsresult
nsMimeHtmlDisplayEmitter::WriteHeaderFieldHTMLPrefix(const nsACString &name)
{
if (!BroadCastHeadersAndAttachments() || (mFormat == nsMimeOutput::nsMimeMessagePrintOutput))
return nsMimeBaseEmitter::WriteHeaderFieldHTMLPrefix(name);
else
return NS_OK;
}
nsresult
nsMimeHtmlDisplayEmitter::WriteHeaderFieldHTML(const char *field, const char *value)
{
if (!BroadCastHeadersAndAttachments() || (mFormat == nsMimeOutput::nsMimeMessagePrintOutput))
return nsMimeBaseEmitter::WriteHeaderFieldHTML(field, value);
else
return NS_OK;
}
nsresult
nsMimeHtmlDisplayEmitter::WriteHeaderFieldHTMLPostfix()
{
if (!BroadCastHeadersAndAttachments() || (mFormat == nsMimeOutput::nsMimeMessagePrintOutput))
return nsMimeBaseEmitter::WriteHeaderFieldHTMLPostfix();
else
return NS_OK;
}
nsresult
nsMimeHtmlDisplayEmitter::GetHeaderSink(nsIMsgHeaderSink ** aHeaderSink)
{
nsresult rv = NS_OK;
if ( (mChannel) && (!mHeaderSink) )
{
nsCOMPtr<nsIURI> uri;
mChannel->GetURI(getter_AddRefs(uri));
if (uri)
{
nsCOMPtr<nsIMsgMailNewsUrl> msgurl (do_QueryInterface(uri));
if (msgurl)
{
msgurl->GetMsgHeaderSink(getter_AddRefs(mHeaderSink));
if (!mHeaderSink) // if the url is not overriding the header sink, then just get the one from the msg window
{
nsCOMPtr<nsIMsgWindow> msgWindow;
msgurl->GetMsgWindow(getter_AddRefs(msgWindow));
if (msgWindow)
msgWindow->GetMsgHeaderSink(getter_AddRefs(mHeaderSink));
}
}
}
}
*aHeaderSink = mHeaderSink;
NS_IF_ADDREF(*aHeaderSink);
return rv;
}
nsresult nsMimeHtmlDisplayEmitter::BroadcastHeaders(nsIMsgHeaderSink * aHeaderSink, int32_t aHeaderMode, bool aFromNewsgroup)
{
// two string enumerators to pass out to the header sink
RefPtr<nsMimeStringEnumerator> headerNameEnumerator = new nsMimeStringEnumerator();
NS_ENSURE_TRUE(headerNameEnumerator, NS_ERROR_OUT_OF_MEMORY);
RefPtr<nsMimeStringEnumerator> headerValueEnumerator = new nsMimeStringEnumerator();
NS_ENSURE_TRUE(headerValueEnumerator, NS_ERROR_OUT_OF_MEMORY);
nsCString extraExpandedHeaders;
nsTArray<nsCString> extraExpandedHeadersArray;
nsAutoCString convertedDateString;
nsresult rv;
nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (pPrefBranch)
{
pPrefBranch->GetCharPref("mailnews.headers.extraExpandedHeaders", getter_Copies(extraExpandedHeaders));
// todo - should make this upper case
if (!extraExpandedHeaders.IsEmpty())
{
ToLowerCase(extraExpandedHeaders);
ParseString(extraExpandedHeaders, ' ', extraExpandedHeadersArray);
}
}
for (size_t i = 0; i < mHeaderArray->Length(); i++)
{
headerInfoType * headerInfo = mHeaderArray->ElementAt(i);
if ( (!headerInfo) || (!headerInfo->name) || (!(*headerInfo->name)) || (!headerInfo->value) || (!(*headerInfo->value)))
continue;
const char * headerValue = headerInfo->value;
// optimization: if we aren't in view all header view mode, we only show a small set of the total # of headers.
// don't waste time sending those out to the UI since the UI is going to ignore them anyway.
if (aHeaderMode != VIEW_ALL_HEADERS && (mFormat != nsMimeOutput::nsMimeMessageFilterSniffer))
{
nsDependentCString headerStr(headerInfo->name);
if (PL_strcasecmp("to", headerInfo->name) && PL_strcasecmp("from", headerInfo->name) &&
PL_strcasecmp("cc", headerInfo->name) && PL_strcasecmp("newsgroups", headerInfo->name) &&
PL_strcasecmp("bcc", headerInfo->name) && PL_strcasecmp("followup-to", headerInfo->name) &&
PL_strcasecmp("reply-to", headerInfo->name) && PL_strcasecmp("subject", headerInfo->name) &&
PL_strcasecmp("organization", headerInfo->name) && PL_strcasecmp("user-agent", headerInfo->name) &&
PL_strcasecmp("content-base", headerInfo->name) && PL_strcasecmp("sender", headerInfo->name) &&
PL_strcasecmp("date", headerInfo->name) && PL_strcasecmp("x-mailer", headerInfo->name) &&
PL_strcasecmp("content-type", headerInfo->name) && PL_strcasecmp("message-id", headerInfo->name) &&
PL_strcasecmp("x-newsreader", headerInfo->name) && PL_strcasecmp("x-mimeole", headerInfo->name) &&
PL_strcasecmp("references", headerInfo->name) && PL_strcasecmp("in-reply-to", headerInfo->name) &&
PL_strcasecmp("list-post", headerInfo->name) && PL_strcasecmp("delivered-to", headerInfo->name) &&
// make headerStr lower case because IndexOf is case-sensitive
(!extraExpandedHeadersArray.Length() || (ToLowerCase(headerStr),
!extraExpandedHeadersArray.Contains(headerStr))))
continue;
}
headerNameEnumerator->Append(headerInfo->name);
headerValueEnumerator->Append(headerValue);
// Add a localized version of the date header if we encounter it.
if (!PL_strcasecmp("Date", headerInfo->name))
{
headerNameEnumerator->Append("X-Mozilla-LocalizedDate");
GenerateDateString(headerValue, convertedDateString, false);
headerValueEnumerator->Append(convertedDateString);
}
}
aHeaderSink->ProcessHeaders(headerNameEnumerator, headerValueEnumerator, aFromNewsgroup);
return rv;
}
NS_IMETHODIMP nsMimeHtmlDisplayEmitter::WriteHTMLHeaders(const nsACString &name)
{
// if we aren't broadcasting headers OR printing...just do whatever
// our base class does...
if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput)
{
return nsMimeBaseEmitter::WriteHTMLHeaders(name);
}
else if (!BroadCastHeadersAndAttachments() || !mDocHeader)
{
// This needs to be here to correct the output format if we are
// not going to broadcast headers to the XUL document.
if (mFormat == nsMimeOutput::nsMimeMessageBodyDisplay)
mFormat = nsMimeOutput::nsMimeMessagePrintOutput;
return nsMimeBaseEmitter::WriteHTMLHeaders(name);
}
else
mFirstHeaders = false;
bool bFromNewsgroups = false;
for (size_t j = 0; j < mHeaderArray->Length(); j++)
{
headerInfoType *headerInfo = mHeaderArray->ElementAt(j);
if (!(headerInfo && headerInfo->name && *headerInfo->name))
continue;
if (!PL_strcasecmp("Newsgroups", headerInfo->name))
{
bFromNewsgroups = true;
break;
}
}
// try to get a header sink if there is one....
nsCOMPtr<nsIMsgHeaderSink> headerSink;
nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));
if (headerSink)
{
int32_t viewMode = 0;
nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (pPrefBranch)
rv = pPrefBranch->GetIntPref("mail.show_headers", &viewMode);
rv = BroadcastHeaders(headerSink, viewMode, bFromNewsgroups);
} // if header Sink
return NS_OK;
}
nsresult
nsMimeHtmlDisplayEmitter::EndHeader(const nsACString &name)
{
if (mDocHeader && (mFormat != nsMimeOutput::nsMimeMessageFilterSniffer))
{
UtilityWriteCRLF("<html>");
UtilityWriteCRLF("<head>");
const char * val = GetHeaderValue(HEADER_SUBJECT); // do not free this value
if (val)
{
char * subject = MsgEscapeHTML(val);
if (subject)
{
int32_t bufLen = strlen(subject) + 16;
char *buf = new char[bufLen];
if (!buf)
return NS_ERROR_OUT_OF_MEMORY;
PR_snprintf(buf, bufLen, "<title>%s</title>", subject);
UtilityWriteCRLF(buf);
delete [] buf;
free(subject);
}
}
// Stylesheet info!
UtilityWriteCRLF("<link rel=\"important stylesheet\" href=\"chrome://messagebody/skin/messageBody.css\">");
UtilityWriteCRLF("</head>");
UtilityWriteCRLF("<body>");
}
WriteHTMLHeaders(name);
return NS_OK;
}
nsresult
nsMimeHtmlDisplayEmitter::StartAttachment(const nsACString &name,
const char *contentType,
const char *url,
bool aIsExternalAttachment)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIMsgHeaderSink> headerSink;
rv = GetHeaderSink(getter_AddRefs(headerSink));
if (NS_SUCCEEDED(rv) && headerSink)
{
nsCString uriString;
nsCOMPtr<nsIMsgMessageUrl> msgurl (do_QueryInterface(mURL, &rv));
if (NS_SUCCEEDED(rv))
{
// HACK: news urls require us to use the originalSpec. Everyone
// else uses GetURI to get the RDF resource which describes the message.
nsCOMPtr<nsINntpUrl> nntpUrl (do_QueryInterface(mURL, &rv));
if (NS_SUCCEEDED(rv) && nntpUrl)
rv = msgurl->GetOriginalSpec(getter_Copies(uriString));
else
rv = msgurl->GetUri(getter_Copies(uriString));
}
// we need to convert the attachment name from UTF-8 to unicode before
// we emit it. The attachment name has already been rfc2047 processed
// upstream of us. (Namely, mime_decode_filename has been called, deferring
// to nsIMimeHeaderParam.decodeParameter.)
nsString unicodeHeaderValue;
CopyUTF8toUTF16(name, unicodeHeaderValue);
headerSink->HandleAttachment(contentType, url /* was escapedUrl */,
unicodeHeaderValue.get(), uriString.get(),
aIsExternalAttachment);
mSkipAttachment = false;
}
else if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput)
{
// then we need to deal with the attachments in the body by inserting
// them into a table..
rv = StartAttachmentInBody(name, contentType, url);
}
else
{
// If we don't need or cannot broadcast attachment info, just ignore it
mSkipAttachment = true;
rv = NS_OK;
}
return rv;
}
// Attachment handling routines
// Ok, we are changing the way we handle these now...It used to be that we output
// HTML to make a clickable link, etc... but now, this should just be informational
// and only show up during printing
// XXX should they also show up during quoting?
nsresult
nsMimeHtmlDisplayEmitter::StartAttachmentInBody(const nsACString &name,
const char *contentType,
const char *url)
{
mSkipAttachment = false;
bool p7mExternal = false;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefs)
prefs->GetBoolPref("mailnews.p7m_external", &p7mExternal);
if ( (contentType) &&
((!p7mExternal && !strcmp(contentType, APPLICATION_XPKCS7_MIME)) ||
(!p7mExternal && !strcmp(contentType, APPLICATION_PKCS7_MIME)) ||
(!strcmp(contentType, APPLICATION_XPKCS7_SIGNATURE)) ||
(!strcmp(contentType, APPLICATION_PKCS7_SIGNATURE)) ||
(!strcmp(contentType, TEXT_VCARD)))
)
{
mSkipAttachment = true;
return NS_OK;
}
if (mFirst)
{
UtilityWrite("<br><fieldset class=\"mimeAttachmentHeader\">");
if (!name.IsEmpty())
{
nsresult rv;
nsCOMPtr<nsIStringBundleService> bundleSvc =
mozilla::services::GetStringBundleService();
NS_ENSURE_TRUE(bundleSvc, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleSvc->CreateBundle("chrome://messenger/locale/messenger.properties",
getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
nsString attachmentsHeader;
bundle->GetStringFromName(u"attachmentsPrintHeader",
getter_Copies(attachmentsHeader));
UtilityWrite("<legend class=\"mimeAttachmentHeaderName\">");
nsCString escapedName;
escapedName.Adopt(MsgEscapeHTML(NS_ConvertUTF16toUTF8(attachmentsHeader).get()));
UtilityWrite(escapedName.get());
UtilityWrite("</legend>");
}
UtilityWrite("</fieldset>");
UtilityWrite("<div class=\"mimeAttachmentWrap\">");
UtilityWrite("<table class=\"mimeAttachmentTable\">");
}
UtilityWrite("<tr>");
UtilityWrite("<td class=\"mimeAttachmentFile\">");
UtilityWrite(name);
UtilityWrite("</td>");
mFirst = false;
return NS_OK;
}
nsresult
nsMimeHtmlDisplayEmitter::AddAttachmentField(const char *field, const char *value)
{
if (mSkipAttachment)
return NS_OK;
// Don't let bad things happen
if ( !value || !*value )
return NS_OK;
// Don't output this ugly header...
if (!strcmp(field, HEADER_X_MOZILLA_PART_URL))
return NS_OK;
nsCOMPtr<nsIMsgHeaderSink> headerSink;
nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));
if (NS_SUCCEEDED(rv) && headerSink)
{
headerSink->AddAttachmentField(field, value);
}
else
{
// Currently, we only care about the part size.
if (strcmp(field, HEADER_X_MOZILLA_PART_SIZE))
return NS_OK;
uint64_t size = atoi(value);
nsAutoString sizeString;
rv = FormatFileSize(size, false, sizeString);
UtilityWrite("<td class=\"mimeAttachmentSize\">");
UtilityWrite(NS_ConvertUTF16toUTF8(sizeString).get());
UtilityWrite("</td>");
}
return NS_OK;
}
nsresult
nsMimeHtmlDisplayEmitter::EndAttachment()
{
if (mSkipAttachment)
return NS_OK;
mSkipAttachment = false; // reset it for next attachment round
if (BroadCastHeadersAndAttachments())
return NS_OK;
if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput)
UtilityWrite("</tr>");
return NS_OK;
}
nsresult
nsMimeHtmlDisplayEmitter::EndAllAttachments()
{
nsresult rv = NS_OK;
nsCOMPtr<nsIMsgHeaderSink> headerSink;
rv = GetHeaderSink(getter_AddRefs(headerSink));
if (headerSink)
headerSink->OnEndAllAttachments();
if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput)
{
UtilityWrite("</table>");
UtilityWrite("</div>");
}
return rv;
}
nsresult
nsMimeHtmlDisplayEmitter::WriteBody(const nsACString &buf,
uint32_t *amountWritten)
{
Write(buf, amountWritten);
return NS_OK;
}
nsresult
nsMimeHtmlDisplayEmitter::EndBody()
{
if (mFormat != nsMimeOutput::nsMimeMessageFilterSniffer)
{
UtilityWriteCRLF("</body>");
UtilityWriteCRLF("</html>");
}
nsCOMPtr<nsIMsgHeaderSink> headerSink;
nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsUrl (do_QueryInterface(mURL, &rv));
if (headerSink)
headerSink->OnEndMsgHeaders(mailnewsUrl);
return NS_OK;
}

View file

@ -0,0 +1,64 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _nsMimeHtmlEmitter_h_
#define _nsMimeHtmlEmitter_h_
#include "mozilla/Attributes.h"
#include "prio.h"
#include "nsMimeBaseEmitter.h"
#include "nsMimeRebuffer.h"
#include "nsIStreamListener.h"
#include "nsIOutputStream.h"
#include "nsIInputStream.h"
#include "nsIURI.h"
#include "nsIChannel.h"
#include "nsIMimeMiscStatus.h"
#include "nsIMimeConverter.h"
class nsMimeHtmlDisplayEmitter : public nsMimeBaseEmitter {
public:
nsMimeHtmlDisplayEmitter ();
nsresult Init();
virtual ~nsMimeHtmlDisplayEmitter (void);
// Header handling routines.
NS_IMETHOD EndHeader(const nsACString &name) override;
// Attachment handling routines
NS_IMETHOD StartAttachment(const nsACString &name,
const char *contentType, const char *url,
bool aIsExternalAttachment) override;
NS_IMETHOD AddAttachmentField(const char *field, const char *value) override;
NS_IMETHOD EndAttachment() override;
NS_IMETHOD EndAllAttachments() override;
// Body handling routines
NS_IMETHOD WriteBody(const nsACString &buf, uint32_t *amountWritten) override;
NS_IMETHOD EndBody() override;
NS_IMETHOD WriteHTMLHeaders(const nsACString &name) override;
virtual nsresult WriteHeaderFieldHTMLPrefix(const nsACString &name
) override;
virtual nsresult WriteHeaderFieldHTML(const char *field,
const char *value) override;
virtual nsresult WriteHeaderFieldHTMLPostfix() override;
protected:
bool mFirst; // Attachment flag...
bool mSkipAttachment; // attachments we shouldn't show...
nsCOMPtr<nsIMsgHeaderSink> mHeaderSink;
nsresult GetHeaderSink(nsIMsgHeaderSink ** aHeaderSink);
bool BroadCastHeadersAndAttachments();
nsresult StartAttachmentInBody(const nsACString &name,
const char *contentType, const char *url);
nsresult BroadcastHeaders(nsIMsgHeaderSink * aHeaderSink, int32_t aHeaderMode, bool aFromNewsgroup);
};
#endif /* _nsMimeHtmlEmitter_h_ */

View file

@ -0,0 +1,64 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h>
#include "nsMimeRebuffer.h"
#include "nsMimePlainEmitter.h"
#include "plstr.h"
#include "nsMailHeaders.h"
#include "nscore.h"
#include "prmem.h"
#include "nsEmitterUtils.h"
#include "nsCOMPtr.h"
#include "nsUnicharUtils.h"
/*
* nsMimePlainEmitter definitions....
*/
nsMimePlainEmitter::nsMimePlainEmitter()
{
}
nsMimePlainEmitter::~nsMimePlainEmitter(void)
{
}
// Header handling routines.
nsresult
nsMimePlainEmitter::StartHeader(bool rootMailHeader, bool headerOnly, const char *msgID,
const char *outCharset)
{
mDocHeader = rootMailHeader;
return NS_OK;
}
nsresult
nsMimePlainEmitter::AddHeaderField(const char *field, const char *value)
{
if ( (!field) || (!value) )
return NS_OK;
UtilityWrite(field);
UtilityWrite(":\t");
UtilityWriteCRLF(value);
return NS_OK;
}
nsresult
nsMimePlainEmitter::EndHeader(const nsACString &name)
{
UtilityWriteCRLF("");
return NS_OK;
}
NS_IMETHODIMP
nsMimePlainEmitter::WriteBody(const nsACString &buf, uint32_t *amountWritten)
{
Write(buf, amountWritten);
return NS_OK;
}

View file

@ -0,0 +1,31 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _nsMimePlainEmitter_h_
#define _nsMimePlainEmitter_h_
#include "mozilla/Attributes.h"
#include "prio.h"
#include "nsMimeBaseEmitter.h"
#include "nsMimeRebuffer.h"
#include "nsIStreamListener.h"
#include "nsIOutputStream.h"
#include "nsIURI.h"
#include "nsIChannel.h"
class nsMimePlainEmitter : public nsMimeBaseEmitter {
public:
nsMimePlainEmitter ();
virtual ~nsMimePlainEmitter (void);
// Header handling routines.
NS_IMETHOD StartHeader(bool rootMailHeader, bool headerOnly, const char *msgID,
const char *outCharset) override;
NS_IMETHOD AddHeaderField(const char *field, const char *value) override;
NS_IMETHOD EndHeader(const nsACString &buf) override;
NS_IMETHOD WriteBody(const nsACString &buf, uint32_t *amountWritten) override;
};
#endif /* _nsMimePlainEmitter_h_ */

View file

@ -0,0 +1,34 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCOMPtr.h"
#include <stdio.h>
#include "nsMimeRebuffer.h"
#include "nsMimeRawEmitter.h"
#include "plstr.h"
#include "nsIMimeEmitter.h"
#include "nsMailHeaders.h"
#include "nscore.h"
#include "prmem.h"
#include "nsEmitterUtils.h"
/*
* nsMimeRawEmitter definitions....
*/
nsMimeRawEmitter::nsMimeRawEmitter()
{
}
nsMimeRawEmitter::~nsMimeRawEmitter(void)
{
}
NS_IMETHODIMP
nsMimeRawEmitter::WriteBody(const nsACString &buf, uint32_t *amountWritten)
{
Write(buf, amountWritten);
return NS_OK;
}

View file

@ -0,0 +1,29 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _nsMimeRawEmitter_h_
#define _nsMimeRawEmitter_h_
#include "mozilla/Attributes.h"
#include "prio.h"
#include "nsMimeBaseEmitter.h"
#include "nsMimeRebuffer.h"
#include "nsIStreamListener.h"
#include "nsIOutputStream.h"
#include "nsIURI.h"
#include "nsIChannel.h"
class nsMimeRawEmitter : public nsMimeBaseEmitter {
public:
nsMimeRawEmitter ();
virtual ~nsMimeRawEmitter (void);
NS_IMETHOD WriteBody(const nsACString &buf,
uint32_t *amountWritten) override;
protected:
};
#endif /* _nsMimeRawEmitter_h_ */

View file

@ -0,0 +1,50 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <string.h>
#include "nsMimeRebuffer.h"
#include "prmem.h"
MimeRebuffer::MimeRebuffer(void)
{
}
MimeRebuffer::~MimeRebuffer(void)
{
}
uint32_t
MimeRebuffer::GetSize()
{
return mBuf.Length();
}
uint32_t
MimeRebuffer::IncreaseBuffer(const nsACString &addBuf)
{
mBuf.Append(addBuf);
return mBuf.Length();
}
uint32_t
MimeRebuffer::ReduceBuffer(uint32_t numBytes)
{
if (numBytes == 0)
return mBuf.Length();
if (numBytes >= mBuf.Length())
{
mBuf.Truncate();
return 0;
}
mBuf.Cut(0, numBytes);
return mBuf.Length();
}
nsACString &
MimeRebuffer::GetBuffer()
{
return mBuf;
}

View file

@ -0,0 +1,29 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _rebuffer_h_
#define _rebuffer_h_
#include <stdint.h>
#include "nsStringGlue.h"
//////////////////////////////////////////////////////////////
// A rebuffering class necessary for stream output buffering
//////////////////////////////////////////////////////////////
class MimeRebuffer {
public:
MimeRebuffer (void);
virtual ~MimeRebuffer (void);
uint32_t GetSize();
uint32_t IncreaseBuffer(const nsACString &addBuf);
uint32_t ReduceBuffer(uint32_t numBytes);
nsACString & GetBuffer();
protected:
nsCString mBuf;
};
#endif /* _rebuffer_h_ */

View file

@ -0,0 +1,184 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h>
#include "nsMimeRebuffer.h"
#include "nsMimeXmlEmitter.h"
#include "plstr.h"
#include "nsMailHeaders.h"
#include "nscore.h"
#include "prmem.h"
#include "nsEmitterUtils.h"
#include "nsCOMPtr.h"
#include "nsUnicharUtils.h"
#include "nsMsgUtils.h"
/*
* nsMimeXmlEmitter definitions....
*/
nsMimeXmlEmitter::nsMimeXmlEmitter()
{
}
nsMimeXmlEmitter::~nsMimeXmlEmitter(void)
{
}
// Note - this is teardown only...you should not write
// anything to the stream since these may be image data
// output streams, etc...
nsresult
nsMimeXmlEmitter::Complete()
{
char buf[16];
// Now write out the total count of attachments for this message
UtilityWrite("<mailattachcount>");
sprintf(buf, "%d", mAttachCount);
UtilityWrite(buf);
UtilityWrite("</mailattachcount>");
UtilityWrite("</message>");
return nsMimeBaseEmitter::Complete();
}
nsresult
nsMimeXmlEmitter::WriteXMLHeader(const char *msgID)
{
if ( (!msgID) || (!*msgID) )
msgID = "none";
char *newValue = MsgEscapeHTML(msgID);
if (!newValue)
return NS_ERROR_OUT_OF_MEMORY;
UtilityWrite("<?xml version=\"1.0\"?>");
UtilityWriteCRLF("<?xml-stylesheet href=\"chrome://messagebody/skin/messageBody.css\" type=\"text/css\"?>");
UtilityWrite("<message id=\"");
UtilityWrite(newValue);
UtilityWrite("\">");
mXMLHeaderStarted = true;
PR_FREEIF(newValue);
return NS_OK;
}
nsresult
nsMimeXmlEmitter::WriteXMLTag(const char *tagName, const char *value)
{
if ( (!value) || (!*value) )
return NS_OK;
char *upCaseTag = NULL;
char *newValue = MsgEscapeHTML(value);
if (!newValue)
return NS_OK;
nsCString newTagName(tagName);
newTagName.StripWhitespace();
ToUpperCase(newTagName);
upCaseTag = ToNewCString(newTagName);
UtilityWrite("<header field=\"");
UtilityWrite(upCaseTag);
UtilityWrite("\">");
// Here is where we are going to try to L10N the tagName so we will always
// get a field name next to an emitted header value. Note: Default will always
// be the name of the header itself.
//
UtilityWrite("<headerdisplayname>");
char *l10nTagName = LocalizeHeaderName(upCaseTag, tagName);
if ( (!l10nTagName) || (!*l10nTagName) )
UtilityWrite(tagName);
else
{
UtilityWrite(l10nTagName);
}
PR_FREEIF(l10nTagName);
UtilityWrite(": ");
UtilityWrite("</headerdisplayname>");
// Now write out the actual value itself and move on!
//
UtilityWrite(newValue);
UtilityWrite("</header>");
NS_Free(upCaseTag);
PR_FREEIF(newValue);
return NS_OK;
}
// Header handling routines.
nsresult
nsMimeXmlEmitter::StartHeader(bool rootMailHeader, bool headerOnly, const char *msgID,
const char *outCharset)
{
mDocHeader = rootMailHeader;
WriteXMLHeader(msgID);
UtilityWrite("<mailheader>");
return NS_OK;
}
nsresult
nsMimeXmlEmitter::AddHeaderField(const char *field, const char *value)
{
if ( (!field) || (!value) )
return NS_OK;
WriteXMLTag(field, value);
return NS_OK;
}
nsresult
nsMimeXmlEmitter::EndHeader(const nsACString &name)
{
UtilityWrite("</mailheader>");
return NS_OK;
}
// Attachment handling routines
nsresult
nsMimeXmlEmitter::StartAttachment(const nsACString &name,
const char *contentType,
const char *url,
bool aIsExternalAttachment)
{
char buf[128];
++mAttachCount;
sprintf(buf, "<mailattachment id=\"%d\">", mAttachCount);
UtilityWrite(buf);
AddAttachmentField(HEADER_PARM_FILENAME, PromiseFlatCString(name).get());
return NS_OK;
}
nsresult
nsMimeXmlEmitter::AddAttachmentField(const char *field, const char *value)
{
WriteXMLTag(field, value);
return NS_OK;
}
nsresult
nsMimeXmlEmitter::EndAttachment()
{
UtilityWrite("</mailattachment>");
return NS_OK;
}

View file

@ -0,0 +1,47 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _nsMimeXmlEmitter_h_
#define _nsMimeXmlEmitter_h_
#include "mozilla/Attributes.h"
#include "prio.h"
#include "nsMimeBaseEmitter.h"
#include "nsMimeRebuffer.h"
#include "nsIStreamListener.h"
#include "nsIOutputStream.h"
#include "nsIURI.h"
#include "nsIChannel.h"
class nsMimeXmlEmitter : public nsMimeBaseEmitter {
public:
nsMimeXmlEmitter ();
virtual ~nsMimeXmlEmitter (void);
NS_IMETHOD Complete() override;
// Header handling routines.
NS_IMETHOD StartHeader(bool rootMailHeader, bool headerOnly, const char *msgID,
const char *outCharset) override;
NS_IMETHOD AddHeaderField(const char *field, const char *value) override;
NS_IMETHOD EndHeader(const nsACString &buf) override;
// Attachment handling routines
NS_IMETHOD StartAttachment(const nsACString &name,
const char *contentType, const char *url,
bool aIsExternalAttachment) override;
NS_IMETHOD AddAttachmentField(const char *field, const char *value) override;
NS_IMETHOD EndAttachment() override;
NS_IMETHOD WriteXMLHeader(const char *msgID);
NS_IMETHOD WriteXMLTag(const char *tagName, const char *value);
protected:
// For header determination...
bool mXMLHeaderStarted;
int32_t mAttachCount;
};
#endif /* _nsMimeXmlEmitter_h_ */