From 2878f72dc2ba96008a4a27546c0056f1ea0ba260 Mon Sep 17 00:00:00 2001 From: "rhp%netscape.com" Date: Tue, 15 Jun 1999 23:22:34 +0000 Subject: [PATCH] New quoting functionality --- mailnews/compose/public/Makefile.in | 1 + mailnews/compose/public/makefile.win | 1 + mailnews/compose/src/Makefile.in | 2 + mailnews/compose/src/makefile.win | 2 + .../compose/src/nsMsgAttachmentHandler.cpp | 10 +- mailnews/compose/src/nsMsgCompUtils.cpp | 3 +- mailnews/compose/src/nsMsgCompose.cpp | 192 ++++++++++-- mailnews/compose/src/nsMsgCompose.h | 46 ++- mailnews/mime/emitters/src/MANIFEST | 2 +- mailnews/mime/emitters/src/nsEmitterUtils.h | 10 +- .../mime/emitters/src/nsMimeHtmlEmitter.h | 3 + mailnews/mime/public/nsIMimeEmitter.h | 6 + mailnews/mime/public/nsIStreamConverter.h | 13 +- mailnews/mime/public/nsMailHeaders.h | 3 +- mailnews/mime/src/MANIFEST | 17 ++ mailnews/mime/src/Makefile.in | 5 +- mailnews/mime/src/makefile.win | 5 +- mailnews/mime/src/mimeebod.cpp | 1 + mailnews/mime/src/mimehdrs.cpp | 17 +- mailnews/mime/src/mimemoz2.cpp | 282 ++++++++++++++++-- mailnews/mime/src/mimemoz2.h | 20 +- mailnews/mime/src/mimemrel.cpp | 2 +- mailnews/mime/src/mimemsg.cpp | 28 +- mailnews/mime/src/nsMimeFactory.cpp | 21 +- mailnews/mime/src/nsMimeTransition.cpp | 130 ++++++++ mailnews/mime/src/plugin_inst.cpp | 9 +- 26 files changed, 708 insertions(+), 123 deletions(-) create mode 100644 mailnews/mime/src/MANIFEST diff --git a/mailnews/compose/public/Makefile.in b/mailnews/compose/public/Makefile.in index f48f24ea750..981aea06677 100644 --- a/mailnews/compose/public/Makefile.in +++ b/mailnews/compose/public/Makefile.in @@ -27,6 +27,7 @@ XPIDLSRCS = \ nsIMsgComposeService.idl \ nsIMsgCompose.idl \ nsIMsgCompFields.idl \ + nsIMsgQuote.idl \ $(NULL) EXPORTS = \ diff --git a/mailnews/compose/public/makefile.win b/mailnews/compose/public/makefile.win index b899402b6e9..fa97af55253 100644 --- a/mailnews/compose/public/makefile.win +++ b/mailnews/compose/public/makefile.win @@ -22,6 +22,7 @@ XPIDLSRCS = \ .\nsIMsgComposeService.idl \ .\nsIMsgCompose.idl \ .\nsIMsgCompFields.idl \ + .\nsIMsgQuote.idl \ $(NULL) ################################################################################ diff --git a/mailnews/compose/src/Makefile.in b/mailnews/compose/src/Makefile.in index 92509921c1c..5a76d30a12e 100644 --- a/mailnews/compose/src/Makefile.in +++ b/mailnews/compose/src/Makefile.in @@ -44,6 +44,7 @@ EXPORTS = \ nsMsgAttachmentHandler.h \ nsMsgPrompts.h \ nsMsgTransition.h \ + nsMsgQuote.h \ $(NULL) CPPSRCS = \ @@ -68,6 +69,7 @@ CPPSRCS = \ nsMsgPrompts.cpp \ nsMsgComposeService.cpp \ nsMsgCompose.cpp \ + nsMsgQuote.cpp \ $(NULL) # we don't want the shared lib, but we want to force the creation of a static lib. diff --git a/mailnews/compose/src/makefile.win b/mailnews/compose/src/makefile.win index 7246e7b966e..12cef3c56c2 100644 --- a/mailnews/compose/src/makefile.win +++ b/mailnews/compose/src/makefile.win @@ -34,6 +34,7 @@ EXPORTS= nsSmtpUrl.h \ nsMsgComposeService.h \ nsMsgCompose.h \ nsMsgCompFields.h \ + nsMsgQuote.h \ $(NULL) ################################################################################ @@ -62,6 +63,7 @@ CPP_OBJS= .\$(OBJDIR)\nsMsgCompFields.obj \ .\$(OBJDIR)\nsMsgI18N.obj \ .\$(OBJDIR)\nsMsgAttachmentHandler.obj \ .\$(OBJDIR)\nsMsgPrompts.obj \ + .\$(OBJDIR)\nsMsgQuote.obj \ $(NULL) diff --git a/mailnews/compose/src/nsMsgAttachmentHandler.cpp b/mailnews/compose/src/nsMsgAttachmentHandler.cpp index c6465381083..37e051ac623 100644 --- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp +++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp @@ -557,22 +557,22 @@ void nsMsgAttachmentHandler::AnalyzeSnarfedFile(void) { char chunk[256]; - PRFileDesc *fileHdl = NULL; PRInt32 numRead = 0; + if (m_file_name && *m_file_name) { - fileHdl = PR_Open(m_file_name, PR_RDONLY, 0); - if (fileHdl) + nsFileSpec aPath(m_file_name); + nsInputFileStream fileHdl(aPath, PR_RDONLY, 0); + if (fileHdl.is_open()) { do { - numRead = PR_Read(fileHdl, chunk, 256); + numRead = fileHdl.read(chunk, 256); if (numRead > 0) AnalyzeDataChunk(chunk, numRead); } while (numRead > 0); - PR_Close(fileHdl); } } } diff --git a/mailnews/compose/src/nsMsgCompUtils.cpp b/mailnews/compose/src/nsMsgCompUtils.cpp index 7796123bbef..7ec8f078054 100644 --- a/mailnews/compose/src/nsMsgCompUtils.cpp +++ b/mailnews/compose/src/nsMsgCompUtils.cpp @@ -546,7 +546,8 @@ mime_generate_headers (nsMsgCompFields *fields, pNetService->GetAppCodeName(aNSStr); sCStr = aNSStr.ToNewCString(); if (sCStr) { - PUSH_STRING ("X-Mailer: "); + // PUSH_STRING ("X-Mailer: "); // To be more standards compliant + PUSH_STRING ("User-Agent: "); PUSH_STRING(sCStr); delete [] sCStr; diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp index c3e4474454a..a0011039a73 100644 --- a/mailnews/compose/src/nsMsgCompose.cpp +++ b/mailnews/compose/src/nsMsgCompose.cpp @@ -27,7 +27,8 @@ #include "nsMsgSend.h" #include "nsIMessenger.h" //temporary! #include "nsIMessage.h" //temporary! - +#include "nsMsgQuote.h" +#include "nsIPref.h" #ifdef XP_UNIX #define TEMP_PATH_DIR "/usr/tmp/" @@ -69,6 +70,7 @@ nsMsgCompose::nsMsgCompose() nsMsgCompose::~nsMsgCompose() { + NS_RELEASE(m_editor); } @@ -406,28 +408,19 @@ nsresult nsMsgCompose::CloseWindow() return NS_OK; } - -nsresult nsMsgCompose::GetEditor(nsIEditorShell * *aEditor) -{ - *aEditor = nsnull; - return NS_OK; -} - - -nsresult nsMsgCompose::SetEditor(nsIEditorShell * aEditor) -{ - nsresult rv; -/* - if (aEditor) - rv = aEditor->QueryInterface(nsIEditorShell::GetIID(), (void **)&m_editor); - else - return NS_ERROR_NULL_POINTER; -*/ - m_editor = aEditor; - - return rv; -} - +nsresult nsMsgCompose::GetEditor(nsIEditorShell * *aEditor) +{ + *aEditor = m_editor; + return NS_OK; +} + +nsresult nsMsgCompose::SetEditor(nsIEditorShell * aEditor) +{ + m_editor = aEditor; + NS_ADDREF(m_editor); + return NS_OK; +} + nsresult nsMsgCompose::GetDomWindow(nsIDOMWindow * *aDomWindow) { @@ -520,11 +513,13 @@ nsresult nsMsgCompose::CreateMessage(const PRUnichar * originalMsgURI, MSG_Compo if (NS_SUCCEEDED(rv = nsMsgI18NDecodeMimePartIIStr(cString, encodedCharset, decodedString))) if (NS_SUCCEEDED(rv = ConvertFromUnicode(msgCompHeaderInternalCharset(), decodedString, &aCString))) { - m_compFields->SetTo(aCString, NULL); + m_compFields->SetCc(aCString, NULL); PR_Free(aCString); } } - HackToGetBody(1); + + QuoteOriginalMessage(originalMsgURI, 1); + break; } case MSGCOMP_TYPE_ForwardAsAttachment: @@ -547,11 +542,11 @@ nsresult nsMsgCompose::CreateMessage(const PRUnichar * originalMsgURI, MSG_Compo } if (type == MSGCOMP_TYPE_ForwardAsAttachment) - HackToGetBody(0); + QuoteOriginalMessage(originalMsgURI, 0); else if (type == MSGCOMP_TYPE_ForwardInline) - HackToGetBody(2); + QuoteOriginalMessage(originalMsgURI, 2); else - HackToGetBody(1); + QuoteOriginalMessage(originalMsgURI, 1); break; } } @@ -560,6 +555,147 @@ nsresult nsMsgCompose::CreateMessage(const PRUnichar * originalMsgURI, MSG_Compo return rv; } +//////////////////////////////////////////////////////////////////////////////////// +// THIS IS THE CLASS THAT IS THE STREAM CONSUMER OF THE HTML OUPUT +// FROM LIBMIME. THIS IS FOR QUOTING +//////////////////////////////////////////////////////////////////////////////////// +QuotingOutputStreamImpl::~QuotingOutputStreamImpl() +{ + if (mComposeObj) + NS_RELEASE(mComposeObj); +} + +QuotingOutputStreamImpl::QuotingOutputStreamImpl(void) +{ + mComposeObj = nsnull; + mMsgBody = "

--- Original Message ---

"; + NS_INIT_REFCNT(); +} + +nsresult +QuotingOutputStreamImpl::Close(void) +{ + if (mComposeObj) + { + mMsgBody += "
"; + nsIMsgCompFields *aCompFields; + mComposeObj->GetCompFields(&aCompFields); + if (aCompFields) + aCompFields->SetBody(nsAutoCString(mMsgBody), NULL); + + nsIEditorShell *aEditor = nsnull; + mComposeObj->GetEditor(&aEditor); + + if (aEditor) + { + if (mMsgBody.Length()) + { + // This is ugly...but hopefully effective... + nsString fileName(TEMP_PATH_DIR); + fileName += TEMP_MESSAGE_OUT; + + nsFileSpec aPath(fileName); + nsOutputFileStream tempFile(aPath); + + if (tempFile.is_open()) + { + tempFile.write(nsAutoCString(mMsgBody), mMsgBody.Length()); + tempFile.close(); + + nsAutoString urlStr = nsFileURL(aPath).GetURLString(); + aEditor->LoadUrl(urlStr.GetUnicode()); + } + } + } + + } + + return NS_OK; +} + +nsresult +QuotingOutputStreamImpl::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) +{ + char *newBuf = (char *)PR_Malloc(aCount + 1); + *aWriteCount = 0; + if (!newBuf) + return NS_ERROR_FAILURE; + + *aWriteCount = aCount; + + nsCRT::memcpy(newBuf, aBuf, aCount); + newBuf[aCount] = '\0'; + mMsgBody += newBuf; + printf("%s", newBuf); + PR_FREEIF(newBuf); + return NS_OK; +} + +nsresult +QuotingOutputStreamImpl::Flush(void) +{ + return NS_OK; +} + +nsresult +QuotingOutputStreamImpl::SetComposeObj(nsMsgCompose *obj) +{ + mComposeObj = obj; + return NS_OK; +} + +NS_IMPL_ISUPPORTS(QuotingOutputStreamImpl, nsIOutputStream::GetIID()); +//////////////////////////////////////////////////////////////////////////////////// +// END OF QUOTING CONSUMER STREAM +//////////////////////////////////////////////////////////////////////////////////// + +// net service definitions.... +static NS_DEFINE_CID(kMsgQuoteCID, NS_MSGQUOTE_CID); +static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); + +nsresult +nsMsgCompose::QuoteOriginalMessage(const PRUnichar *originalMsgURI, PRInt32 what) // New template +{ + nsresult rv; + + // + // For now, you need to set a pref to do the new quoting + // + PRBool newQuoting = PR_FALSE; + NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv); + if (NS_SUCCEEDED(rv) && prefs) + { + rv = prefs->GetBoolPref("mail.new_quoting", &newQuoting); + } + + if (!newQuoting) + { + HackToGetBody(what); + return NS_OK; + } + + // Create a mime parser (nsIStreamConverter)! + rv = nsComponentManager::CreateInstance(kMsgQuoteCID, + NULL, nsIMsgQuote::GetIID(), + (void **) getter_AddRefs(mQuote)); + if (NS_FAILED(rv) || !mQuote) + return NS_ERROR_FAILURE; + + // Create the consumer output stream.. this will receive all the HTML from libmime + mOutStream = do_QueryInterface(new QuotingOutputStreamImpl()); + if (!mOutStream) + { + printf("Failed to create nsIOutputStream\n"); + return NS_ERROR_FAILURE; + } + + NS_ADDREF(this); + mOutStream->SetComposeObj(this); + +// mBaseStream = do_QueryInterface(mOutStream); + return mQuote->QuoteMessage(originalMsgURI, mOutStream); +} + void nsMsgCompose::HackToGetBody(PRInt32 what) { char *buffer = (char *) PR_CALLOC(16384); diff --git a/mailnews/compose/src/nsMsgCompose.h b/mailnews/compose/src/nsMsgCompose.h index 5e15fd62efd..cc1ef598071 100644 --- a/mailnews/compose/src/nsMsgCompose.h +++ b/mailnews/compose/src/nsMsgCompose.h @@ -21,7 +21,10 @@ #include "nsMsgCompFields.h" #include "nsIWebShell.h" #include "nsIWebShellWindow.h" +#include "nsIOutputStream.h" +#include "nsIMsgQuote.h" +class QuotingOutputStreamImpl; class nsMsgCompose : public nsIMsgCompose { @@ -56,9 +59,10 @@ class nsMsgCompose : public nsIMsgCompose NS_IMETHOD CloseWindow(); /* attribute nsIDOMEditorAppCore editor; */ - NS_IMETHOD GetEditor(nsIEditorShell * *aEditor); - NS_IMETHOD SetEditor(nsIEditorShell * aEditor); - + /* attribute nsIEditorShell editor; */ + NS_IMETHOD GetEditor(nsIEditorShell * *aEditor); + NS_IMETHOD SetEditor(nsIEditorShell * aEditor); + /* readonly attribute nsIDOMWindow domWindow; */ NS_IMETHOD GetDomWindow(nsIDOMWindow * *aDomWindow); @@ -71,19 +75,49 @@ class nsMsgCompose : public nsIMsgCompose /* readonly attribute long wrapLength; */ NS_IMETHOD GetWrapLength(PRInt32 *aWrapLength); /******/ - private: nsresult CreateMessage(const PRUnichar * originalMsgURI, MSG_ComposeType type, MSG_ComposeFormat format, nsISupports* object); void HackToGetBody(PRInt32 what); //Temporary - + + nsresult QuoteOriginalMessage(const PRUnichar * originalMsgURI, PRInt32 what); // New template + + nsIEditorShell* m_editor; nsIDOMWindow* m_window; nsIWebShell* m_webShell; nsIWebShellWindow* m_webShellWin; - nsIEditorShell* m_editor; nsCOMPtr m_compFields; PRBool m_composeHTML; + nsCOMPtr mOutStream; + nsCOMPtr mBaseStream; + nsCOMPtr mQuote; }; +//////////////////////////////////////////////////////////////////////////////////// +// THIS IS THE CLASS THAT IS THE STREAM CONSUMER OF THE HTML OUPUT +// FROM LIBMIME. THIS IS FOR QUOTING +//////////////////////////////////////////////////////////////////////////////////// +class QuotingOutputStreamImpl : public nsIOutputStream +{ +public: + QuotingOutputStreamImpl(void); + virtual ~QuotingOutputStreamImpl(void); + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsIBaseStream interface + NS_IMETHOD Close(void); + + // nsIOutputStream interface + NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); + + NS_IMETHOD Flush(void); + + NS_IMETHOD SetComposeObj(nsMsgCompose *obj); + +private: + nsMsgCompose *mComposeObj; + nsString mMsgBody; +}; diff --git a/mailnews/mime/emitters/src/MANIFEST b/mailnews/mime/emitters/src/MANIFEST index 1379e8e9f30..99aa199ea1a 100644 --- a/mailnews/mime/emitters/src/MANIFEST +++ b/mailnews/mime/emitters/src/MANIFEST @@ -20,4 +20,4 @@ nsMimeHtmlEmitter.h nsMimeXmlEmitter.h nsMimeRawEmitter.h nsEmitterUtils.h - +nsMimeRebuffer.h diff --git a/mailnews/mime/emitters/src/nsEmitterUtils.h b/mailnews/mime/emitters/src/nsEmitterUtils.h index 2ade47657ab..06dac755be0 100644 --- a/mailnews/mime/emitters/src/nsEmitterUtils.h +++ b/mailnews/mime/emitters/src/nsEmitterUtils.h @@ -21,15 +21,7 @@ #include "prmem.h" #include "plstr.h" -extern "C" char *nsEscapeHTML(const char *string); - -// mscott - I'm dumping this enum here for lack of a better -// common header file shared by nsMimeRawEmitter & nsMimeXmlEmitter -typedef enum { - MicroHeaders = 0, - NormalHeaders, - AllHeaders -} HeaderDisplayTypes; +extern "C" PRBool EmitThisHeaderForPrefSetting(PRInt32 dispType, const char *header); #endif // _nsEmitterUtils_h_ diff --git a/mailnews/mime/emitters/src/nsMimeHtmlEmitter.h b/mailnews/mime/emitters/src/nsMimeHtmlEmitter.h index f63dd6e3f7a..33d9387e7f4 100644 --- a/mailnews/mime/emitters/src/nsMimeHtmlEmitter.h +++ b/mailnews/mime/emitters/src/nsMimeHtmlEmitter.h @@ -78,6 +78,9 @@ protected: // For content type... char *mAttachContentType; + // For Header display + PRBool mHeaderDisplayType; + #ifdef DEBUG_rhp PRBool mReallyOutput; PRFileDesc *mLogFile; /* Temp file to put generated HTML into. */ diff --git a/mailnews/mime/public/nsIMimeEmitter.h b/mailnews/mime/public/nsIMimeEmitter.h index 86bdc7937f0..2e7b90781a7 100644 --- a/mailnews/mime/public/nsIMimeEmitter.h +++ b/mailnews/mime/public/nsIMimeEmitter.h @@ -23,6 +23,12 @@ #include "prtypes.h" #include "nsINetOStream.h" +typedef enum { + MicroHeaders = 0, + NormalHeaders, + AllHeaders +} HeaderDisplayTypes; + // {D01D7B59-DCCD-11d2-A411-00805F613C79} #define NS_IMIME_EMITTER_IID \ { 0xd01d7b59, 0xdccd, 0x11d2, \ diff --git a/mailnews/mime/public/nsIStreamConverter.h b/mailnews/mime/public/nsIStreamConverter.h index eb3de3ede06..3ba52f1106c 100644 --- a/mailnews/mime/public/nsIStreamConverter.h +++ b/mailnews/mime/public/nsIStreamConverter.h @@ -26,6 +26,11 @@ { 0xc9cdf8e5, 0x95fa, 0x11d2, \ { 0x88, 0x7, 0x0, 0x80, 0x5f, 0x5a, 0x1f, 0xb8 } } +// {588595CB-2012-11d3-8EF0-00A024A7D144} +#define NS_STREAM_CONVERTER_CID \ + { 0x588595cb, 0x2012, 0x11d3, \ + { 0x8e, 0xf0, 0x0, 0xa0, 0x24, 0xa7, 0xd1, 0x44 } }; + class nsIStreamConverter : public nsIStreamListener { public: static const nsIID& GetIID() { static nsIID iid = NS_ISTREAM_CONVERTER_IID; return iid; } @@ -34,7 +39,7 @@ public: // This is the output stream where the stream converter will write processed data after // conversion. // - NS_IMETHOD SetOutputStream(nsIOutputStream *outStream) = 0; + NS_IMETHOD SetOutputStream(nsIOutputStream *outStream, char *url) = 0; // // The output listener can be set to allow for the flexibility of having the stream converter @@ -43,6 +48,12 @@ public: // the responsibility of the client of the stream converter to handle the resulting data. // NS_IMETHOD SetOutputListener(nsIStreamListener *outListner) = 0; + + // + // This is needed by libmime for MHTML link processing...the url is the URL string associated + // with this input stream + // + NS_IMETHOD SetStreamURL(char *url) = 0; }; #endif /* nsIStreamConverter_h_ */ diff --git a/mailnews/mime/public/nsMailHeaders.h b/mailnews/mime/public/nsMailHeaders.h index ff70c3633d2..5701e5568f7 100644 --- a/mailnews/mime/public/nsMailHeaders.h +++ b/mailnews/mime/public/nsMailHeaders.h @@ -62,8 +62,9 @@ #define HEADER_SENDER "Sender" #define HEADER_SUBJECT "Subject" #define HEADER_TO "To" -#define HEADER_APPROVED_BY "Approved-By" +#define HEADER_APPROVED_BY "Approved-By" #define HEADER_X_MAILER "X-Mailer" +#define HEADER_USER_AGENT "User-Agent" #define HEADER_X_NEWSREADER "X-Newsreader" #define HEADER_X_POSTING_SOFTWARE "X-Posting-Software" #define HEADER_X_MOZILLA_STATUS "X-Mozilla-Status" diff --git a/mailnews/mime/src/MANIFEST b/mailnews/mime/src/MANIFEST new file mode 100644 index 00000000000..73ea0aa97a0 --- /dev/null +++ b/mailnews/mime/src/MANIFEST @@ -0,0 +1,17 @@ +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# +# +nsMimeTypes.h diff --git a/mailnews/mime/src/Makefile.in b/mailnews/mime/src/Makefile.in index 3a67729f91a..99bbb787cd5 100644 --- a/mailnews/mime/src/Makefile.in +++ b/mailnews/mime/src/Makefile.in @@ -26,6 +26,7 @@ MODULE=mime LIBRARY_NAME=mime IS_COMPONENT=1 EXPORTS =\ + nsMimeTypes.h \ nsMimeObjectClassAccess.h \ nsMimeConverter.h \ mimetext.h \ @@ -85,13 +86,15 @@ CPPSRCS = \ comi18n.cpp \ nsMimeTransition.cpp \ nsMsgHeaderParser.cpp \ + nsStreamConverter.cpp \ + nsMimeEmitter2.cpp \ $(NULL) CSRCS = \ oldi18n.c \ $(NULL) -EXTRA_DSO_LDOPTS = \ +EXTRA_DSO_LDOPTS = \ -L$(DIST)/bin \ $(NSPR_LIBS) \ -lmozjs \ diff --git a/mailnews/mime/src/makefile.win b/mailnews/mime/src/makefile.win index 035e4010e26..405aa6816ac 100644 --- a/mailnews/mime/src/makefile.win +++ b/mailnews/mime/src/makefile.win @@ -23,6 +23,7 @@ include <$(DEPTH)\config\config.mak> ## exports EXPORTS = \ + nsMimeTypes.h \ nsMimeObjectClassAccess.h \ nsMimeConverter.h \ mimetext.h \ @@ -98,6 +99,8 @@ OBJS= \ .\$(OBJDIR)\mimemoz2.obj \ .\$(OBJDIR)\nsMsgHeaderParser.obj \ .\$(OBJDIR)\nsMimeURLUtils.obj \ + .\$(OBJDIR)\nsStreamConverter.obj \ + .\$(OBJDIR)\nsMimeEmitter2.obj \ # # THIS WILL NEED WORK AFTER WE GET A LIBMSG MORE XP-COM-afied # .\$(OBJDIR)\mimedrft.obj \ @@ -124,4 +127,4 @@ include <$(DEPTH)/config/rules.mak> install:: $(DLL) $(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin\components - $(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib \ No newline at end of file + $(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib diff --git a/mailnews/mime/src/mimeebod.cpp b/mailnews/mime/src/mimeebod.cpp index 880a8bd7744..6ed3053b999 100644 --- a/mailnews/mime/src/mimeebod.cpp +++ b/mailnews/mime/src/mimeebod.cpp @@ -16,6 +16,7 @@ * Reserved. */ #include "nsCOMPtr.h" +#include "nsIURL.h" #include "mimeebod.h" #include "prmem.h" #include "nsCRT.h" diff --git a/mailnews/mime/src/mimehdrs.cpp b/mailnews/mime/src/mimehdrs.cpp index 39f12c671cf..3fd49122afc 100644 --- a/mailnews/mime/src/mimehdrs.cpp +++ b/mailnews/mime/src/mimehdrs.cpp @@ -1887,12 +1887,6 @@ MimeHeaders_write_all_headers (MimeHeaders *hdrs, MimeDisplayOptions *opt, PRBoo int i; PRBool wrote_any_p = PR_FALSE; - nsIMimeEmitter *mimeEmitter = GetMimeEmitter(opt); - - // No emitter, no point. - if (!mimeEmitter) - return -1; - PR_ASSERT(hdrs); if (!hdrs) return -1; @@ -1992,10 +1986,10 @@ MimeHeaders_write_all_headers (MimeHeaders *hdrs, MimeDisplayOptions *opt, PRBoo status = MimeHeaders_write_random_header_1(hdrs, name, c2, opt, PR_FALSE); ****************************************/ if (attachment) - status = mimeEmitter->AddAttachmentField(name, + status = mimeEmitterAddAttachmentField(opt, name, MimeHeaders_convert_header_value(opt, &c2)); else - status = mimeEmitter->AddHeaderField(name, + status = mimeEmitterAddHeaderField(opt, name, MimeHeaders_convert_header_value(opt, &c2)); PR_Free(name); @@ -2500,13 +2494,12 @@ MimeHeaders_write_attachment_box(MimeHeaders *hdrs, { int status = 0; - nsIMimeEmitter *mimeEmitter = GetMimeEmitter(opt); - mimeEmitter->StartAttachment(lname, content_type, lname_url); + mimeEmitterStartAttachment(opt, lname, content_type, lname_url); status = MimeHeaders_write_all_headers (hdrs, opt, TRUE); - mimeEmitter->AddAttachmentField(HEADER_X_MOZILLA_PART_URL, lname_url); + mimeEmitterAddAttachmentField(opt, HEADER_X_MOZILLA_PART_URL, lname_url); - mimeEmitter->EndAttachment(); + mimeEmitterEndAttachment(opt); if (status < 0) return status; diff --git a/mailnews/mime/src/mimemoz2.cpp b/mailnews/mime/src/mimemoz2.cpp index 5e2adea976a..16224c5b3ab 100644 --- a/mailnews/mime/src/mimemoz2.cpp +++ b/mailnews/mime/src/mimemoz2.cpp @@ -50,6 +50,7 @@ #include "nsString.h" #include "nsIEventQueueService.h" #include "nsMimeStringResources.h" +#include "nsStreamConverter.h" #ifdef MOZ_SECURITY #include HG01944 @@ -228,20 +229,35 @@ mime_convert_rfc1522 (const char *input_line, PRInt32 input_length, static int mime_output_fn(char *buf, PRInt32 size, void *stream_closure) { - PRUint32 written; + PRUint32 written = 0; struct mime_stream_data *msd = (struct mime_stream_data *) stream_closure; - PR_ASSERT(msd->pluginObj); - if ( (!msd->pluginObj) || (!msd->output_emitter) ) + if ( ( (!msd->pluginObj) && (!msd->pluginObj2)) && ( (!msd->output_emitter) && (msd->output_emitter2)) ) return -1; // Now, write to the WriteBody method if this is a message body and not // a part retrevial if (!msd->options->part_to_load) { - msd->output_emitter->WriteBody(buf, (PRUint32) size, &written); + if (msd->output_emitter) + { + msd->output_emitter->WriteBody(buf, (PRUint32) size, &written); + } + else if (msd->output_emitter2) + { + msd->output_emitter2->WriteBody(buf, (PRUint32) size, &written); + } } else - msd->output_emitter->Write(buf, (PRUint32) size, &written); + { + if (msd->output_emitter) + { + msd->output_emitter->Write(buf, (PRUint32) size, &written); + } + else if (msd->output_emitter2) + { + msd->output_emitter2->Write(buf, (PRUint32) size, &written); + } + } return written; } @@ -525,10 +541,10 @@ mime_output_init_fn (const char *type, // Now, all of this stream creation is done outside of libmime, so this // is just a check of the pluginObj member and returning accordingly. - if (msd->pluginObj) - return 0; - else + if ( (!msd->pluginObj) && (!msd->pluginObj2)) return -1; + else + return 0; /* If we've converted to HTML, then we've already done charset conversion, so label this data as "internal/parser" to prevent it from being passed @@ -610,7 +626,10 @@ mime_image_begin(const char *image_url, const char *content_type, // RICHIE_URL return 0; // RICHIE_URL } - mid->istream = (nsMIMESession *) msd->pluginObj; + if (msd->pluginObj) + mid->istream = (nsMIMESession *) msd->pluginObj; + else + mid->istream = (nsMIMESession *) msd->pluginObj2; return mid; } @@ -699,7 +718,8 @@ mime_image_write_buffer(char *buf, PRInt32 size, void *image_closure) (struct mime_image_stream_data *) image_closure; struct mime_stream_data *msd = mid->msd; - if ( (!msd->pluginObj) || (!msd->output_emitter) ) + if ( ( (!msd->pluginObj) && (!msd->output_emitter) ) && + ( (!msd->pluginObj2) && (!msd->output_emitter2) ) ) return -1; // @@ -1009,17 +1029,6 @@ extern int MIME_HasAttachments(MWContext *context) ************************************************************** **************************************************************/ -nsIMimeEmitter * -GetMimeEmitter(MimeDisplayOptions *opt) -{ - mime_stream_data *msd = (mime_stream_data *)opt->stream_closure; - if (!msd) - return NULL; - - nsIMimeEmitter *ptr = (nsIMimeEmitter *)(msd->output_emitter); - return ptr; -} - /* Get the connnection to prefs service manager */ nsIPref * GetPrefServiceManager(MimeDisplayOptions *opt) @@ -1049,6 +1058,8 @@ mime_bridge_destroy_stream(void *newStream) void * mime_bridge_create_stream(MimePluginInstance *newPluginObj, nsIMimeEmitter *newEmitter, + nsStreamConverter *newPluginObj2, + nsMimeEmitter2 *newEmitter2, const char *urlString, int format_out) { @@ -1095,21 +1106,25 @@ mime_bridge_create_stream(MimePluginInstance *newPluginObj, // Assign the new mime emitter - will handle output operations msd->output_emitter = newEmitter; + msd->output_emitter2 = newEmitter2; // RICHIE_URL (msd->url)->address = PL_strdup(urlString); - - msd->url_name = PL_strdup(urlString); - if (!(msd->url_name)) + + if (urlString) { - delete msd->output_emitter; - // RICHIE_URL PR_FREEIF(msd->url); - PR_FREEIF(msd); - return NULL; + msd->url_name = PL_strdup(urlString); + if (!(msd->url_name)) + { + // RICHIE_URL PR_FREEIF(msd->url); + PR_FREEIF(msd); + return NULL; + } } msd->context = context; // SHERRY - need to wax this soon msd->format_out = format_out; // output format msd->pluginObj = newPluginObj; // the plugin object pointer + msd->pluginObj2 = newPluginObj2; // the plugin object pointer msd->options = PR_NEW(MimeDisplayOptions); if (!msd->options) @@ -1510,3 +1525,214 @@ MimeGetStringByID(PRInt32 stringID) PR_snprintf(buf, sizeof(buf), "[StringID %d?]", stringID); return PL_strdup(buf); } + + +// To support 2 types of emitters...we need these routines :-( +nsIMimeEmitter * +GetMimeEmitter(MimeDisplayOptions *opt) +{ + mime_stream_data *msd = (mime_stream_data *)opt->stream_closure; + if (!msd) + return NULL; + + nsIMimeEmitter *ptr = (nsIMimeEmitter *)(msd->output_emitter); + return ptr; +} + +mime_stream_data * +GetMSD(MimeDisplayOptions *opt) +{ + if (!opt) + return nsnull; + mime_stream_data *msd = (mime_stream_data *)opt->stream_closure; + return msd; +} + +extern "C" nsresult +mimeEmitterAddAttachmentField(MimeDisplayOptions *opt, const char *field, const char *value) +{ + mime_stream_data *msd = GetMSD(opt); + if (!msd) + return -1; + + if (msd->output_emitter) + { + nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter; + return emitter->AddAttachmentField(field, value); + } + else if (msd->output_emitter2) + { + nsMimeEmitter2 *emitter2 = (nsMimeEmitter2 *)msd->output_emitter2; + return emitter2->AddAttachmentField(field, value); + } + + return -1; +} + +extern "C" nsresult +mimeEmitterAddHeaderField(MimeDisplayOptions *opt, const char *field, const char *value) +{ + mime_stream_data *msd = GetMSD(opt); + if (!msd) + return -1; + + if (msd->output_emitter) + { + nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter; + return emitter->AddHeaderField(field, value); + } + else if (msd->output_emitter2) + { + nsMimeEmitter2 *emitter2 = (nsMimeEmitter2 *)msd->output_emitter2; + return emitter2->AddHeaderField(field, value); + } + + return -1; +} + +extern "C" nsresult +mimeEmitterStartAttachment(MimeDisplayOptions *opt, const char *name, const char *contentType, const char *url) +{ + mime_stream_data *msd = GetMSD(opt); + if (!msd) + return -1; + + if (msd->output_emitter) + { + nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter; + return emitter->StartAttachment(name, contentType, url); + } + else if (msd->output_emitter2) + { + nsMimeEmitter2 *emitter2 = (nsMimeEmitter2 *)msd->output_emitter2; + return emitter2->StartAttachment(name, contentType, url); + } + + return -1; +} + +extern "C" nsresult +mimeEmitterEndAttachment(MimeDisplayOptions *opt) +{ + mime_stream_data *msd = GetMSD(opt); + if (!msd) + return -1; + + if (msd->output_emitter) + { + nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter; + return emitter->EndAttachment(); + } + else if (msd->output_emitter2) + { + nsMimeEmitter2 *emitter2 = (nsMimeEmitter2 *)msd->output_emitter2; + return emitter2->EndAttachment(); + } + + return -1; +} + +extern "C" nsresult +mimeEmitterStartBody(MimeDisplayOptions *opt, PRBool bodyOnly, const char *msgID, const char *outCharset) +{ + mime_stream_data *msd = GetMSD(opt); + if (!msd) + return -1; + + if (msd->output_emitter) + { + nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter; + return emitter->StartBody(bodyOnly, msgID, outCharset); + } + else if (msd->output_emitter2) + { + nsMimeEmitter2 *emitter2 = (nsMimeEmitter2 *)msd->output_emitter2; + return emitter2->StartBody(bodyOnly, msgID, outCharset); + } + + return -1; +} + +extern "C" nsresult +mimeEmitterEndBody(MimeDisplayOptions *opt) +{ + mime_stream_data *msd = GetMSD(opt); + if (!msd) + return -1; + + if (msd->output_emitter) + { + nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter; + return emitter->EndBody(); + } + else if (msd->output_emitter2) + { + nsMimeEmitter2 *emitter2 = (nsMimeEmitter2 *)msd->output_emitter2; + return emitter2->EndBody(); + } + + return -1; +} + +extern "C" nsresult +mimeEmitterEndHeader(MimeDisplayOptions *opt) +{ + mime_stream_data *msd = GetMSD(opt); + if (!msd) + return -1; + + if (msd->output_emitter) + { + nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter; + return emitter->EndHeader(); + } + else if (msd->output_emitter2) + { + nsMimeEmitter2 *emitter2 = (nsMimeEmitter2 *)msd->output_emitter2; + return emitter2->EndHeader(); + } + + return -1; +} + +extern "C" nsresult +mimeEmitterStartHeader(MimeDisplayOptions *opt, PRBool rootMailHeader, PRBool headerOnly, const char *msgID, + const char *outCharset) +{ + mime_stream_data *msd = GetMSD(opt); + if (!msd) + return -1; + + if (msd->output_emitter) + { + nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter; + return emitter->StartHeader(rootMailHeader, headerOnly, msgID, outCharset); + } + else if (msd->output_emitter2) + { + nsMimeEmitter2 *emitter2 = (nsMimeEmitter2 *)msd->output_emitter2; + return emitter2->StartHeader(rootMailHeader, headerOnly, msgID, outCharset); + } + + return -1; +} + + +extern "C" nsresult +mimeSetNewURL(nsMIMESession *stream, char *url) +{ + if ( (!stream) || (!url) || (!*url) ) + return NS_ERROR_FAILURE; + + mime_stream_data *msd = (mime_stream_data *)stream->data_object; + if (!msd) + return NS_ERROR_FAILURE; + + char *tmpPtr = PL_strdup(url); + if (!tmpPtr) + return NS_ERROR_FAILURE; + + PR_FREEIF(msd->url_name); + msd->url_name = PL_strdup(tmpPtr); + return NS_OK; +} \ No newline at end of file diff --git a/mailnews/mime/src/mimemoz2.h b/mailnews/mime/src/mimemoz2.h index b0d73857105..f7c110e942c 100644 --- a/mailnews/mime/src/mimemoz2.h +++ b/mailnews/mime/src/mimemoz2.h @@ -25,7 +25,9 @@ extern "C" { #include "prtypes.h" #include "plugin_inst.h" +#include "nsStreamConverter.h" #include "nsIMimeEmitter.h" +#include "nsMimeEmitter2.h" // SHERRY - Need to get these out of here eventually @@ -97,6 +99,7 @@ struct mime_stream_data { /* This struct is the state we pass around int format_out; MWContext *context; /* Must REMOVE this entry. */ void *pluginObj; /* The new XP-COM stream converter object */ + void *pluginObj2; /* The new XP-COM stream converter object */ nsMIMESession *istream; /* Holdover - new stream we're writing out image data-if any. */ MimeObject *obj; /* The root parser object */ MimeDisplayOptions *options; /* Data for communicating with libmime.a */ @@ -104,7 +107,8 @@ struct mime_stream_data { /* This struct is the state we pass around /* These are used by FO_QUOTE_HTML_MESSAGE stuff only: */ PRInt16 lastcsid; /* csid corresponding to above. */ PRInt16 outcsid; /* csid passed to EDT_PasteQuoteINTL */ - nsIMimeEmitter *output_emitter; /* Output emitter engine for libmime */ + nsIMimeEmitter *output_emitter; /* Output emitter engine for libmime */ + nsMimeEmitter2 *output_emitter2; /* Output emitter 2 engine for libmime */ nsIPref *prefs; /* Connnection to prefs service manager */ }; @@ -115,6 +119,8 @@ struct mime_stream_data { /* This struct is the state we pass around // Create bridge stream for libmime void *mime_bridge_create_stream(MimePluginInstance *newPluginObj, nsIMimeEmitter *newEmitter, + nsStreamConverter *newPluginObj2, + nsMimeEmitter2 *newEmitter2, const char *urlString, int format_out); @@ -129,6 +135,18 @@ extern "C" void mime_display_stream_abort (nsMIMESession *stream, int // To get the mime emitter... extern "C" nsIMimeEmitter *GetMimeEmitter(MimeDisplayOptions *opt); +// To support 2 types of emitters...we need these routines :-( +extern "C" nsresult mimeSetNewURL(nsMIMESession *stream, char *url); +extern "C" nsresult mimeEmitterAddAttachmentField(MimeDisplayOptions *opt, const char *field, const char *value); +extern "C" nsresult mimeEmitterAddHeaderField(MimeDisplayOptions *opt, const char *field, const char *value); +extern "C" nsresult mimeEmitterStartAttachment(MimeDisplayOptions *opt, const char *name, const char *contentType, const char *url); +extern "C" nsresult mimeEmitterEndAttachment(MimeDisplayOptions *opt); +extern "C" nsresult mimeEmitterStartBody(MimeDisplayOptions *opt, PRBool bodyOnly, const char *msgID, const char *outCharset); +extern "C" nsresult mimeEmitterEndBody(MimeDisplayOptions *opt); +extern "C" nsresult mimeEmitterEndHeader(MimeDisplayOptions *opt); +extern "C" nsresult mimeEmitterStartHeader(MimeDisplayOptions *opt, PRBool rootMailHeader, PRBool headerOnly, const char *msgID, + const char *outCharset); + /* To Get the connnection to prefs service manager */ extern "C" nsIPref *GetPrefServiceManager(MimeDisplayOptions *opt); diff --git a/mailnews/mime/src/mimemrel.cpp b/mailnews/mime/src/mimemrel.cpp index 0a5e6b02358..88ad55010cf 100644 --- a/mailnews/mime/src/mimemrel.cpp +++ b/mailnews/mime/src/mimemrel.cpp @@ -346,7 +346,7 @@ MakeAbsoluteURL(char * absolute_url, char * relative_url) nsMimeURLUtils myUtil; char *retString; - if (myUtil.MakeAbsoluteURL(absolute_url, relative_url, &retString) == NS_OK) + if (NS_SUCCEEDED(myUtil.MakeAbsoluteURL(absolute_url, relative_url, &retString))) return retString; else return NULL; diff --git a/mailnews/mime/src/mimemsg.cpp b/mailnews/mime/src/mimemsg.cpp index 272c982d7fb..439eaf6080f 100644 --- a/mailnews/mime/src/mimemsg.cpp +++ b/mailnews/mime/src/mimemsg.cpp @@ -396,11 +396,6 @@ HG09091 // we need to figure out the content type/charset of the part // PRBool outer_p = !obj->headers; /* is this the outermost message? */ - nsIMimeEmitter *mimeEmitter = GetMimeEmitter(obj->options); - - // No emitter, no point. - if (!mimeEmitter) - return -1; if ( (outer_p) && @@ -420,7 +415,7 @@ HG09091 if (!obj->options->force_user_charset) /* Only convert if the user prefs is false */ outCharset = "UTF-8"; - mimeEmitter->StartBody((obj->options->headers == MimeHeadersNone), msgID, outCharset); + mimeEmitterStartBody(obj->options, (obj->options->headers == MimeHeadersNone), msgID, outCharset); PR_FREEIF(msgID); PR_FREEIF(lct); PR_FREEIF(charset); @@ -447,10 +442,6 @@ MimeMessage_parse_eof (MimeObject *obj, PRBool abort_p) // Once we get to the end of parsing the message, we will notify // the emitter that we are done the the body. - nsIMimeEmitter *mimeEmitter = GetMimeEmitter(obj->options); - // No emitter, no point. - if (!mimeEmitter) - return -1; // Mark the end of the mail body if we are actually emitting the // body of the message (i.e. not Header ONLY) @@ -459,7 +450,7 @@ MimeMessage_parse_eof (MimeObject *obj, PRBool abort_p) ( obj->options && (obj->options->part_to_load == NULL) ) && (obj->options->headers != MimeHeadersOnly) ) - mimeEmitter->EndBody(); + mimeEmitterEndBody(obj->options); if (outer_p && obj->options && @@ -541,7 +532,6 @@ static int MimeMessage_write_headers_html (MimeObject *obj) { MimeMessage *msg = (MimeMessage *) obj; - nsIMimeEmitter *mimeEmitter = GetMimeEmitter(obj->options); int status; #ifdef MOZ_SECURITY @@ -553,10 +543,6 @@ MimeMessage_write_headers_html (MimeObject *obj) PR_ASSERT(obj->output_p && obj->options->write_html_p); - // No emitter - no point! - if (!mimeEmitter) - return -1; - // To support the no header option! Make sure we are not // suppressing headers on included email messages... if ( (obj->options->headers == MimeHeadersNone) && @@ -568,7 +554,7 @@ MimeMessage_write_headers_html (MimeObject *obj) status = MimeObject_output_init (obj, TEXT_HTML); if (status < 0) { - mimeEmitter->EndHeader(); + mimeEmitterEndHeader(obj->options); return status; } PR_ASSERT(obj->options->state->first_data_written_p); @@ -577,7 +563,7 @@ MimeMessage_write_headers_html (MimeObject *obj) // Start the header parsing by the emitter char *msgID = MimeHeaders_get (msg->hdrs, HEADER_MESSAGE_ID, PR_FALSE, PR_FALSE); - mimeEmitter->StartHeader( + mimeEmitterStartHeader(obj->options, (obj == obj->options->state->root), (obj->options->headers == MimeHeadersOnly), msgID, @@ -592,7 +578,7 @@ MimeMessage_write_headers_html (MimeObject *obj) status = MimeHeaders_write_all_headers (msg->hdrs, obj->options, FALSE); if (status < 0) { - mimeEmitter->EndHeader(); + mimeEmitterEndHeader(obj->options); return status; } @@ -627,14 +613,14 @@ MimeMessage_write_headers_html (MimeObject *obj) PR_Free(html); if (status < 0) { - mimeEmitter->EndHeader(); + mimeEmitterEndHeader(obj->options); return status; } } } } - mimeEmitter->EndHeader(); + mimeEmitterEndHeader(obj->options); if (obj->options->headers == MimeHeadersOnly) return -1; diff --git a/mailnews/mime/src/nsMimeFactory.cpp b/mailnews/mime/src/nsMimeFactory.cpp index 8fe75a7452c..a5f04b31461 100644 --- a/mailnews/mime/src/nsMimeFactory.cpp +++ b/mailnews/mime/src/nsMimeFactory.cpp @@ -22,6 +22,7 @@ #include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" +#include "nsStreamConverter.h" #include "nsINetPlugin.h" #include "nsIComponentManager.h" @@ -41,9 +42,10 @@ static NS_DEFINE_CID(kCMimeMimeObjectClassAccessCID, NS_MIME_OBJECT_CLASS_ACCE static NS_DEFINE_CID(kCMimeConverterCID, NS_MIME_CONVERTER_CID); // These are necessary for the new stream converter/plugin interface... -static NS_DEFINE_CID(kINetPluginCID, NS_INET_PLUGIN_CID); -static NS_DEFINE_CID(kINetPluginMIMECID, NS_INET_PLUGIN_MIME_CID); -static NS_DEFINE_IID(kINetPluginIID, NS_INET_PLUGIN_IID); +static NS_DEFINE_CID(kINetPluginCID, NS_INET_PLUGIN_CID); +static NS_DEFINE_CID(kINetPluginMIMECID, NS_INET_PLUGIN_MIME_CID); +static NS_DEFINE_IID(kINetPluginIID, NS_INET_PLUGIN_IID); +static NS_DEFINE_CID(kIStreamConverterCID, NS_STREAM_CONVERTER_CID); #include "nsMsgHeaderParser.h" static NS_DEFINE_CID(kCMsgHeaderParserCID, NS_MSGHEADERPARSER_CID); @@ -163,6 +165,12 @@ nsresult nsMimeFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, v if (res != NS_OK) // was there a problem creating the object ? return res; } + else if (mClassID.Equals(kIStreamConverterCID)) + { + res = NS_NewStreamConverter((nsIStreamConverter **) &inst); + if (res != NS_OK) // was there a problem creating the object ? + return res; + } // End of checking the interface ID code.... if (inst) @@ -252,6 +260,11 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char * PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) finalResult = rv; + // Stream converter interface for use in quoting. + rv = compMgr->RegisterComponent(kIStreamConverterCID, NULL, NULL, path, + PR_TRUE, PR_TRUE); + if (NS_FAILED(rv)) finalResult = rv; + return finalResult; } @@ -273,6 +286,8 @@ extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char if (NS_FAILED(rv)) finalResult = rv; rv = compMgr->UnregisterComponent(kCIMimeURLUtilsCID, path); if (NS_FAILED(rv)) finalResult = rv; + rv = compMgr->UnregisterComponent(kIStreamConverterCID, path); + if (NS_FAILED(rv)) finalResult = rv; return finalResult; } diff --git a/mailnews/mime/src/nsMimeTransition.cpp b/mailnews/mime/src/nsMimeTransition.cpp index 97bcb91e2c8..22786f1dd94 100644 --- a/mailnews/mime/src/nsMimeTransition.cpp +++ b/mailnews/mime/src/nsMimeTransition.cpp @@ -45,3 +45,133 @@ NET_cinfo_find_info_by_type (char *uri) { return NULL; } + + +///////////////////////////////////////////////////////////////////// +// THIS IS ONLY HERE UNTIL I CAN GET THE INTERNAL EMITTER OUT OF +// LIBMIME +///////////////////////////////////////////////////////////////////// +#include "nsIMimeEmitter.h" +#include "nsMailHeaders.h" + +extern "C" PRBool +EmitThisHeaderForPrefSetting(PRInt32 dispType, const char *header) +{ + if (AllHeaders == dispType) + return PR_TRUE; + + if ((!header) || (!*header)) + return PR_FALSE; + + if (MicroHeaders == dispType) + { + if ( + (!PL_strcmp(header, HEADER_SUBJECT)) || + (!PL_strcmp(header, HEADER_FROM)) || + (!PL_strcmp(header, HEADER_DATE)) + ) + return PR_TRUE; + else + return PR_FALSE; + } + + if (NormalHeaders == dispType) + { + if ( + (!PL_strcmp(header, HEADER_TO)) || + (!PL_strcmp(header, HEADER_SUBJECT)) || + (!PL_strcmp(header, HEADER_SENDER)) || + (!PL_strcmp(header, HEADER_RESENT_TO)) || + (!PL_strcmp(header, HEADER_RESENT_SENDER)) || + (!PL_strcmp(header, HEADER_RESENT_FROM)) || + (!PL_strcmp(header, HEADER_RESENT_CC)) || + (!PL_strcmp(header, HEADER_REPLY_TO)) || + (!PL_strcmp(header, HEADER_REFERENCES)) || + (!PL_strcmp(header, HEADER_NEWSGROUPS)) || + (!PL_strcmp(header, HEADER_MESSAGE_ID)) || + (!PL_strcmp(header, HEADER_FROM)) || + (!PL_strcmp(header, HEADER_FOLLOWUP_TO)) || + (!PL_strcmp(header, HEADER_CC)) || + (!PL_strcmp(header, HEADER_BCC)) + ) + return PR_TRUE; + else + return PR_FALSE; + } + + return PR_TRUE; +} + + +#include "nsMimeRebuffer.h" +#include "prmem.h" + +MimeRebuffer::MimeRebuffer(void) +{ + mSize = 0; + mBuf = NULL; +} + +MimeRebuffer::~MimeRebuffer(void) +{ + if (mBuf) + { + PR_FREEIF(mBuf); + mBuf = NULL; + } +} + +PRUint32 +MimeRebuffer::GetSize() +{ + return mSize; +} + +PRUint32 +MimeRebuffer::IncreaseBuffer(const char *addBuf, PRUint32 size) +{ + if ( (!addBuf) || (size == 0) ) + return mSize; + + mBuf = (char *)PR_Realloc(mBuf, size + mSize); + if (!mBuf) + { + mSize = 0; + return mSize; + } + + memcpy(mBuf+mSize, addBuf, size); + mSize += size; + return mSize; +} + +PRUint32 +MimeRebuffer::ReduceBuffer(PRUint32 numBytes) +{ + if (numBytes == 0) + return mSize; + + if (!mBuf) + { + mSize = 0; + return mSize; + } + + if (numBytes >= mSize) + { + PR_FREEIF(mBuf); + mBuf = NULL; + mSize = 0; + return mSize; + } + + memcpy(mBuf, mBuf+numBytes, (mSize - numBytes)); + mSize -= numBytes; + return mSize; +} + +char * +MimeRebuffer::GetBuffer() +{ + return mBuf; +} diff --git a/mailnews/mime/src/plugin_inst.cpp b/mailnews/mime/src/plugin_inst.cpp index 55d82389f01..030539a6156 100644 --- a/mailnews/mime/src/plugin_inst.cpp +++ b/mailnews/mime/src/plugin_inst.cpp @@ -15,6 +15,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +#include "nsIURL.h" #include "plugin_inst.h" #include #include @@ -27,7 +28,7 @@ #include "nscore.h" #include "nsString.h" -// Need this for FO_NGLAYOUT +// RICHIE - Need this for FO_NGLAYOUT #include "net.h" // @@ -214,14 +215,14 @@ MimePluginInstance::Initialize(nsINetOStream* stream, const char *stream_name) nsIMimeEmitter::GetIID(), (void **) getter_AddRefs(mEmitter)); - if (NS_FAILED(res) || (!mEmitter)) + if ((NS_FAILED(res)) || (!mEmitter)) { NS_ASSERTION(PR_FALSE, "unable to create the correct converter"); return NS_ERROR_OUT_OF_MEMORY; } mEmitter->Initialize(stream); - mBridgeStream = mime_bridge_create_stream(this, mEmitter, stream_name, format_out); + mBridgeStream = mime_bridge_create_stream(this, mEmitter, nsnull, nsnull, stream_name, format_out); if (!mBridgeStream) { return NS_ERROR_OUT_OF_MEMORY; @@ -293,7 +294,9 @@ nsresult MimePluginInstance::InternalCleanup(void) // // Now complete the emitter and do necessary cleanup! // +#ifdef DEBUG_rhp printf("TOTAL READ = %d\n", mTotalRead); +#endif if (mEmitter) { mEmitter->Complete();