nsresult nsMimePlainEmitter::AddHeaderField(const char *field, const char *value) { if ( (!field) || (!value) ) return NS_OK; UtilityWrite(field); UtilityWrite(":\t"); UtilityWriteCRLF(value); return NS_OK; }
// 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::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; }
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; }
// 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::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 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; }
// 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; }
// 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(MOZ_UTF16("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 nsMimeXmlEmitter::EndAttachment() { UtilityWrite("</mailattachment>"); return NS_OK; }
nsresult nsMimeXmlEmitter::EndHeader(const nsACString &name) { UtilityWrite("</mailheader>"); return NS_OK; }
nsresult nsMimeXmlEmitter::EndHeader() { UtilityWrite("</mailheader>"); return NS_OK; }