New changes for mime emitters

This commit is contained in:
rhp%netscape.com 1999-04-01 01:02:42 +00:00
parent 222c204eb3
commit 654b2f866d
5 changed files with 192 additions and 144 deletions

View File

@ -24,14 +24,12 @@ IS_COMPONENT=1
include $(DEPTH)/config/autoconf.mk
MODULE=emitter
LIBRARY_NAME=emitter
MODULE=htmlemitter
LIBRARY_NAME=htmlemitter
CPPSRCS = \
nsMimeEmitter.cpp \
nsEmitterFactory.cpp \
nsEmitterUtils.cpp \
rebuffer.cpp \
$(NULL)
EXTRA_DSO_LDOPTS = \

View File

@ -34,7 +34,7 @@ DEPTH=..\..\..\..
# New build system where zip dll is build indepenant of java stubs.
#//
#//------------------------------------------------------------------------
MODULE = emitter
MODULE = htmlemitter
REQUIRES=
#EXPORTS =\
# .\nsMimeEmitter.h \
@ -52,8 +52,6 @@ DEFINES=
OBJS= \
.\$(OBJDIR)\nsMimeEmitter.obj \
.\$(OBJDIR)\nsEmitterFactory.obj \
.\$(OBJDIR)\nsEmitterUtils.obj \
.\$(OBJDIR)\rebuffer.obj \
$(NULL)
#//------------------------------------------------------------------------
@ -80,7 +78,7 @@ DLL=.\$(OBJDIR)\$(DLLNAME).dll
#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS)
#//
#//------------------------------------------------------------------------
LCFLAGS=-DNETSCAPE
DEFINES= -NS_DEBUG
MSGLIBS= \
$(NULL)
@ -98,6 +96,7 @@ LLIBS= \
$(DIST)\lib\xplib.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\emitterutils.lib \
$(NULL)
LINCS=$(LINCS) -I. \

View File

@ -28,8 +28,7 @@
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kMimeEmitterCID, NS_MIME_EMITTER_CID);
static NS_DEFINE_CID(kMimeEmitterCID, NS_HTML_MIME_EMITTER_CID);
////////////////////////////////////////////////////////////
//
@ -209,7 +208,7 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path)
if (NS_FAILED(rv)) goto done;
#ifdef NS_DEBUG
printf("*** Register MIME Emitter...\n");
printf("*** Register HTML MIME Emitter...\n");
#endif
done:

View File

@ -16,10 +16,11 @@
* Reserved.
*/
#include "stdio.h"
#include "rebuffer.h"
#include "nsMimeRebuffer.h"
#include "nsMimeEmitter.h"
#include "plstr.h"
#include "nsEmitterUtils.h"
#include "nsMailHeaders.h"
/*
* This function will be used by the factory to generate an
@ -64,6 +65,11 @@ nsMimeEmitter::nsMimeEmitter()
mTotalWritten = 0;
mTotalRead = 0;
mDocHeader = PR_FALSE;
#ifdef NS_DEBUG
mLogFile = NULL; /* Temp file to put generated HTML into. */
mReallyOutput = PR_FALSE;
#endif
}
nsMimeEmitter::~nsMimeEmitter(void)
@ -79,24 +85,85 @@ nsMimeEmitter::SetOutputStream(nsINetOStream *outStream)
return NS_OK;
}
// Note - these is setup only...you should not write
// anything to the stream since these may be image data
// output streams, etc...
nsresult
nsMimeEmitter::Initialize(nsINetOStream *outStream)
{
mOutStream = outStream;
// Create rebuffering object
mBufferMgr = new MimeRebuffer();
// Counters for output stream
mTotalWritten = 0;
mTotalRead = 0;
#ifdef DEBUG
PR_Delete("C:\\email.html");
mLogFile = PR_Open("C:\\email.html", PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE, 493);
#endif /* DEBUG */
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
nsMimeEmitter::Complete()
{
#ifdef DEBUG
mReallyOutput = PR_FALSE;
#endif
// If we are here and still have data to write, we should try
// to flush it...if we try and fail, we should probably return
// an error!
PRUint32 written;
if (mBufferMgr->GetSize() > 0)
Write("", 0, &written);
printf("TOTAL WRITTEN = %d\n", mTotalWritten);
printf("LEFTOVERS = %d\n", mBufferMgr->GetSize());
#ifdef DEBUG
if (mLogFile)
PR_Close(mLogFile);
#endif
return NS_OK;
}
// Header handling routines.
nsresult
nsMimeEmitter::StartHeader(PRBool rootMailHeader)
nsMimeEmitter::StartHeader(PRBool rootMailHeader, PRBool headerOnly, const char *msgID)
{
#ifdef DEBUG
mReallyOutput = PR_TRUE;
#endif
mDocHeader = rootMailHeader;
if (mDocHeader)
UtilityWrite("<table BORDER=0 BGCOLOR=\"#99FF99\" >");
UtilityWrite("<BLOCKQUOTE><table BORDER=0>");
else
UtilityWrite("<table BORDER=0 BGCOLOR=\"#CCCCCC\" >");
UtilityWrite("<BLOCKQUOTE><table BORDER=0 BGCOLOR=\"#CCCCCC\" >");
return NS_OK;
}
nsresult
nsMimeEmitter::AddHeaderField(const char *field, const char *value)
{
char *newValue = nsEscapeHTML(value);
#ifdef DEBUG
mReallyOutput = PR_TRUE;
#endif
if ( (!field) || (!value) )
return NS_OK;
char *newValue = nsEscapeHTML(value);
if (!newValue)
return NS_OK;
@ -124,43 +191,107 @@ nsMimeEmitter::AddHeaderField(const char *field, const char *value)
nsresult
nsMimeEmitter::EndHeader()
{
UtilityWrite("</TABLE>");
#ifdef DEBUG
mReallyOutput = PR_TRUE;
#endif
UtilityWrite("</TABLE></BLOCKQUOTE>");
return NS_OK;
}
// Note - these is setup only...you should not write
// anything to the stream since these may be image data
// output streams, etc...
nsresult
nsMimeEmitter::Initialize(nsINetOStream *outStream)
{
mOutStream = outStream;
// Create rebuffering object
mBufferMgr = new MimeRebuffer();
// Counters for output stream
mTotalWritten = 0;
mTotalRead = 0;
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...
// Attachment handling routines
nsresult
nsMimeEmitter::Complete()
nsMimeEmitter::StartAttachment(const char *name, const char *contentType, const char *url)
{
// If we are here and still have data to write, we should try
// to flush it...if we try and fail, we should probably return
// an error!
PRUint32 written;
if (mBufferMgr->GetSize() > 0)
Write("", 0, &written);
#ifdef DEBUG
mReallyOutput = PR_TRUE;
#endif
printf("TOTAL WRITTEN = %d\n", mTotalWritten);
printf("LEFTOVERS = %d\n", mBufferMgr->GetSize());
UtilityWrite("<table BORDER=2>");
return NS_OK;
}
nsresult
nsMimeEmitter::AddAttachmentField(const char *field, const char *value)
{
#ifdef DEBUG
mReallyOutput = PR_TRUE;
#endif
char *newValue = nsEscapeHTML(value);
PRBool linkIt = (!PL_strcmp(HEADER_X_MOZILLA_PART_URL, field));
UtilityWrite("<TR>");
UtilityWrite("<td>");
UtilityWrite("<div align=right>");
UtilityWrite("<B>");
UtilityWrite(field);
UtilityWrite(":");
UtilityWrite("</B>");
UtilityWrite("</div>");
UtilityWrite("</td>");
UtilityWrite("<td>");
if (linkIt)
{
UtilityWrite("<a href=\"");
UtilityWrite(value);
UtilityWrite("\">");
}
UtilityWrite(newValue);
if (linkIt)
UtilityWrite("</a>");
UtilityWrite("</td>");
UtilityWrite("</TR>");
PR_FREEIF(newValue);
return NS_OK;
}
nsresult
nsMimeEmitter::EndAttachment()
{
#ifdef DEBUG
mReallyOutput = PR_TRUE;
#endif
UtilityWrite("</TABLE>");
UtilityWrite("<BR>");
return NS_OK;
}
// Attachment handling routines
nsresult
nsMimeEmitter::StartBody(PRBool bodyOnly, const char *msgID)
{
#ifdef DEBUG
mReallyOutput = PR_TRUE;
#endif
return NS_OK;
}
nsresult
nsMimeEmitter::WriteBody(const char *buf, PRUint32 size, PRUint32 *amountWritten)
{
#ifdef DEBUG
mReallyOutput = PR_TRUE;
#endif
Write(buf, size, amountWritten);
return NS_OK;
}
nsresult
nsMimeEmitter::EndBody()
{
#ifdef DEBUG
mReallyOutput = PR_FALSE;
#endif
return NS_OK;
}
@ -175,11 +306,17 @@ nsMimeEmitter::Write(const char *buf, PRUint32 size, PRUint32 *amountWritten)
unsigned int written = 0;
PRUint32 rc, aReadyCount = 0;
#ifdef DEBUG
if ((mLogFile) && (mReallyOutput))
PR_Write(mLogFile, buf, size);
#endif
//
// Make sure that the buffer we are "pushing" into has enough room
// for the write operation. If not, we have to buffer, return, and get
// it on the next time through
//
*amountWritten = 0;
rc = mOutStream->WriteReady(&aReadyCount);
// First, handle any old buffer data...
@ -222,46 +359,6 @@ nsMimeEmitter::Write(const char *buf, PRUint32 size, PRUint32 *amountWritten)
}
}
// Attachment handling routines
nsresult
nsMimeEmitter::StartAttachment()
{
UtilityWrite("<table BORDER=2>");
return NS_OK;
}
nsresult
nsMimeEmitter::AddAttachmentField(const char *field, const char *value)
{
char *newValue = nsEscapeHTML(value);
UtilityWrite("<TR>");
UtilityWrite("<td>");
UtilityWrite("<div align=right>");
UtilityWrite("<B>");
UtilityWrite(field);
UtilityWrite(":");
UtilityWrite("</B>");
UtilityWrite("</div>");
UtilityWrite("</td>");
UtilityWrite("<td>");
UtilityWrite(newValue);
UtilityWrite("</td>");
UtilityWrite("</TR>");
PR_FREEIF(newValue);
return NS_OK;
}
nsresult
nsMimeEmitter::EndAttachment()
{
UtilityWrite("</TABLE>");
UtilityWrite("<BR>");
return NS_OK;
}
nsresult
nsMimeEmitter::UtilityWrite(const char *buf)
{
@ -269,60 +366,9 @@ nsMimeEmitter::UtilityWrite(const char *buf)
PRUint32 written;
Write(buf, tmpLen, &written);
return NS_OK;
}
// Attachment handling routines
nsresult
nsMimeEmitter::StartBody()
{
#ifdef rhp_DEBUG
UtilityWrite("<BR>");
UtilityWrite("<B>============== STARTING BODY ==============</B>");
UtilityWrite("<BR>");
#ifdef DEBUG
Write("\r\n", 2, &written);
#endif
return NS_OK;
}
nsresult
nsMimeEmitter::WriteBody(const char *buf, PRUint32 size, PRUint32 *amountWritten)
{
Write(buf, size, amountWritten);
return NS_OK;
}
nsresult
nsMimeEmitter::EndBody()
{
#ifdef rhp_DEBUG
UtilityWrite("<BR>");
UtilityWrite("<B>============== ENDING BODY ==============</B>");
UtilityWrite("<BR>");
#endif
return NS_OK;
}
/*************
#include "prprf.h"
// PR_smprintf(buf,
* First, let's import some style sheet information and
* JavaScript!
#define MHTML_STYLE_IMPORT "<HTML><LINK REL=\"stylesheet\" HREF=\"resource:/res/mail.css\">"
#define MHTML_JS_IMPORT "<SCRIPT LANGUAGE=\"JavaScript1.2\" SRC=\"resource:/res/mail.js\"></SCRIPT>"
status = MimeHeaders_write(opt, MHTML_STYLE_IMPORT, PL_strlen(MHTML_STYLE_IMPORT));
if (status < 0)
{
return status;
}
status = MimeHeaders_write(opt, MHTML_JS_IMPORT, PL_strlen(MHTML_JS_IMPORT));
if (status < 0)
{
return status;
}
******************/

View File

@ -19,7 +19,8 @@
#define _nsMimeEmitter_h_
#include "prtypes.h"
#include "rebuffer.h"
#include "prio.h"
#include "nsMimeRebuffer.h"
#include "nsINetOStream.h"
#include "nsIMimeEmitter.h"
@ -39,17 +40,17 @@ public:
NS_IMETHOD SetOutputStream(nsINetOStream *outStream);
// Header handling routines.
NS_IMETHOD StartHeader(PRBool rootMailHeader);
NS_IMETHOD StartHeader(PRBool rootMailHeader, PRBool headerOnly, const char *msgID);
NS_IMETHOD AddHeaderField(const char *field, const char *value);
NS_IMETHOD EndHeader();
// Attachment handling routines
NS_IMETHOD StartAttachment();
NS_IMETHOD StartAttachment(const char *name, const char *contentType, const char *url);
NS_IMETHOD AddAttachmentField(const char *field, const char *value);
NS_IMETHOD EndAttachment();
// Body handling routines
NS_IMETHOD StartBody();
NS_IMETHOD StartBody(PRBool bodyOnly, const char *msgID);
NS_IMETHOD WriteBody(const char *buf, PRUint32 size, PRUint32 *amountWritten);
NS_IMETHOD EndBody();
@ -70,6 +71,11 @@ protected:
// For header determination...
PRBool mDocHeader;
#ifdef DEBUG
PRBool mReallyOutput;
PRFileDesc *mLogFile; /* Temp file to put generated HTML into. */
#endif
};
/* this function will be used by the factory to generate an class access object....*/