From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- comm/mailnews/mime/emitters/nsMimeXmlEmitter.cpp | 152 +++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 comm/mailnews/mime/emitters/nsMimeXmlEmitter.cpp (limited to 'comm/mailnews/mime/emitters/nsMimeXmlEmitter.cpp') diff --git a/comm/mailnews/mime/emitters/nsMimeXmlEmitter.cpp b/comm/mailnews/mime/emitters/nsMimeXmlEmitter.cpp new file mode 100644 index 0000000000..30c2b5eac3 --- /dev/null +++ b/comm/mailnews/mime/emitters/nsMimeXmlEmitter.cpp @@ -0,0 +1,152 @@ +/* -*- 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/. */ + +#include +#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(""); + sprintf(buf, "%d", mAttachCount); + UtilityWrite(buf); + UtilityWrite(""); + + UtilityWrite(""); + + return nsMimeBaseEmitter::Complete(); +} + +nsresult nsMimeXmlEmitter::WriteXMLHeader(const char* msgID) { + if ((!msgID) || (!*msgID)) msgID = "none"; + + nsCString newValue; + nsAppendEscapedHTML(nsDependentCString(msgID), newValue); + + UtilityWrite(""); + + UtilityWriteCRLF( + ""); + + UtilityWrite(""); + + mXMLHeaderStarted = true; + return NS_OK; +} + +nsresult nsMimeXmlEmitter::WriteXMLTag(const char* tagName, const char* value) { + if ((!value) || (!*value)) return NS_OK; + + char* upCaseTag = NULL; + nsCString newValue; + nsAppendEscapedHTML(nsDependentCString(value), newValue); + + nsCString newTagName(tagName); + newTagName.StripWhitespace(); + ToUpperCase(newTagName); + upCaseTag = ToNewCString(newTagName); + + 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(""); + char* l10nTagName = LocalizeHeaderName(upCaseTag, tagName); + if ((!l10nTagName) || (!*l10nTagName)) + UtilityWrite(tagName); + else { + UtilityWrite(l10nTagName); + } + PR_FREEIF(l10nTagName); + + UtilityWrite(": "); + UtilityWrite(""); + + // Now write out the actual value itself and move on! + // + UtilityWrite(newValue.get()); + UtilityWrite("
"); + + free(upCaseTag); + + return NS_OK; +} + +// Header handling routines. +nsresult nsMimeXmlEmitter::StartHeader(bool rootMailHeader, bool headerOnly, + const char* msgID, + const char* outCharset) { + mDocHeader = rootMailHeader; + WriteXMLHeader(msgID); + UtilityWrite(""); + + 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(""); + 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, "", 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(""); + return NS_OK; +} -- cgit v1.2.3