зеркало из https://github.com/mozilla/pjs.git
Changes for cleaner attachment output
This commit is contained in:
Родитель
42c39ebb55
Коммит
e7eb2facb3
|
@ -22,7 +22,7 @@ srcdir = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = src html xml
|
||||
DIRS = src html xml raw
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ nsMimeEmitter::nsMimeEmitter()
|
|||
mTotalWritten = 0;
|
||||
mTotalRead = 0;
|
||||
mDocHeader = PR_FALSE;
|
||||
mAttachContentType = NULL;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
mLogFile = NULL; /* Temp file to put generated HTML into. */
|
||||
|
@ -199,6 +200,40 @@ nsMimeEmitter::EndHeader()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMimeEmitter::ProcessContentType(const char *ct)
|
||||
{
|
||||
if (mAttachContentType)
|
||||
{
|
||||
PR_FREEIF(mAttachContentType);
|
||||
mAttachContentType = NULL;
|
||||
}
|
||||
|
||||
if ( (!ct) || (!*ct) )
|
||||
return NS_OK;
|
||||
|
||||
char *slash = PL_strchr(ct, '/');
|
||||
if (!slash)
|
||||
mAttachContentType = PL_strdup(ct);
|
||||
else
|
||||
{
|
||||
PRInt32 size = (PL_strlen(ct) + 4 + 1);
|
||||
mAttachContentType = (char *)PR_MALLOC( size );
|
||||
if (!mAttachContentType)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
memset(mAttachContentType, 0, size);
|
||||
PL_strcpy(mAttachContentType, ct);
|
||||
|
||||
char *newSlash = PL_strchr(mAttachContentType, '/');
|
||||
*newSlash = '\0';
|
||||
PL_strcat(mAttachContentType, "%2F");
|
||||
PL_strcat(mAttachContentType, (slash + 1));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Attachment handling routines
|
||||
nsresult
|
||||
nsMimeEmitter::StartAttachment(const char *name, const char *contentType, const char *url)
|
||||
|
@ -207,7 +242,32 @@ nsMimeEmitter::StartAttachment(const char *name, const char *contentType, const
|
|||
mReallyOutput = PR_TRUE;
|
||||
#endif
|
||||
|
||||
UtilityWrite("<table BORDER=2>");
|
||||
PR_FREEIF(mAttachContentType);
|
||||
mAttachContentType = NULL;
|
||||
ProcessContentType(contentType);
|
||||
UtilityWrite("<CENTER>");
|
||||
UtilityWrite("<table BORDER CELLSPACING=0>");
|
||||
UtilityWrite("<tr>");
|
||||
UtilityWrite("<td>");
|
||||
|
||||
if (mAttachContentType)
|
||||
{
|
||||
UtilityWrite("<a href=\"");
|
||||
UtilityWrite(url);
|
||||
UtilityWrite("&outformat=");
|
||||
UtilityWrite(mAttachContentType);
|
||||
UtilityWrite("\" target=new>");
|
||||
}
|
||||
|
||||
UtilityWrite("<img SRC=\"resource:/res/network/gopher-unknown.gif\" BORDER=0 ALIGN=ABSCENTER>");
|
||||
UtilityWrite(name);
|
||||
|
||||
if (mAttachContentType)
|
||||
UtilityWrite("</a>");
|
||||
|
||||
UtilityWrite("</td>");
|
||||
UtilityWrite("<td>");
|
||||
UtilityWrite("<table BORDER=0 BGCOLOR=\"#FFFFCC\">");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -221,6 +281,13 @@ nsMimeEmitter::AddAttachmentField(const char *field, const char *value)
|
|||
char *newValue = nsEscapeHTML(value);
|
||||
PRBool linkIt = (!PL_strcmp(HEADER_X_MOZILLA_PART_URL, field));
|
||||
|
||||
//
|
||||
// For now, let's not output the long URL field, but when prefs are
|
||||
// working this will change.
|
||||
//
|
||||
if (linkIt)
|
||||
return NS_OK;
|
||||
|
||||
UtilityWrite("<TR>");
|
||||
|
||||
UtilityWrite("<td>");
|
||||
|
@ -237,7 +304,12 @@ nsMimeEmitter::AddAttachmentField(const char *field, const char *value)
|
|||
{
|
||||
UtilityWrite("<a href=\"");
|
||||
UtilityWrite(value);
|
||||
UtilityWrite("\">");
|
||||
if (mAttachContentType)
|
||||
{
|
||||
UtilityWrite("&outformat=");
|
||||
UtilityWrite(mAttachContentType);
|
||||
}
|
||||
UtilityWrite("\" target=new>");
|
||||
}
|
||||
|
||||
UtilityWrite(newValue);
|
||||
|
@ -259,7 +331,13 @@ nsMimeEmitter::EndAttachment()
|
|||
mReallyOutput = PR_TRUE;
|
||||
#endif
|
||||
|
||||
PR_FREEIF(mAttachContentType);
|
||||
UtilityWrite("</TABLE>");
|
||||
UtilityWrite("</td>");
|
||||
UtilityWrite("</tr>");
|
||||
|
||||
UtilityWrite("</TABLE>");
|
||||
UtilityWrite("</CENTER>");
|
||||
UtilityWrite("<BR>");
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -367,7 +445,7 @@ nsMimeEmitter::UtilityWrite(const char *buf)
|
|||
|
||||
Write(buf, tmpLen, &written);
|
||||
#ifdef DEBUG
|
||||
Write("\r\n", 2, &written);
|
||||
// Write("\r\n", 2, &written);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -60,6 +60,8 @@ public:
|
|||
NS_IMETHOD Write(const char *buf, PRUint32 size, PRUint32 *amountWritten);
|
||||
NS_IMETHOD UtilityWrite(const char *buf);
|
||||
|
||||
NS_IMETHOD ProcessContentType(const char *ct);
|
||||
|
||||
protected:
|
||||
// For buffer management on output
|
||||
MimeRebuffer *mBufferMgr;
|
||||
|
@ -72,6 +74,9 @@ protected:
|
|||
// For header determination...
|
||||
PRBool mDocHeader;
|
||||
|
||||
// For content type...
|
||||
char *mAttachContentType;
|
||||
|
||||
#ifdef DEBUG
|
||||
PRBool mReallyOutput;
|
||||
PRFileDesc *mLogFile; /* Temp file to put generated HTML into. */
|
||||
|
|
|
@ -18,6 +18,6 @@
|
|||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DIRS= src html xml
|
||||
DIRS= src html xml raw
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
|
@ -1122,7 +1122,8 @@ mime_bridge_create_stream(MimePluginInstance *newPluginObj,
|
|||
msd->options->headers = MimeHeadersAll;
|
||||
|
||||
// Get the libmime prefs...
|
||||
MIME_NoInlineAttachments = PR_TRUE;
|
||||
MIME_NoInlineAttachments = PR_TRUE; // false - no attachment display
|
||||
// true - attachment display
|
||||
if (msd->prefs)
|
||||
msd->prefs->GetBoolPref("mail.inline_attachments", &MIME_NoInlineAttachments);
|
||||
MIME_NoInlineAttachments = !MIME_NoInlineAttachments;
|
||||
|
|
|
@ -114,16 +114,68 @@ MimePluginInstance::~MimePluginInstance(void)
|
|||
|
||||
static NS_DEFINE_IID(kMimeHTMLEmitterCID, NS_HTML_MIME_EMITTER_CID);
|
||||
static NS_DEFINE_IID(kMimeXMLEmitterCID, NS_XML_MIME_EMITTER_CID);
|
||||
static NS_DEFINE_IID(kMimeRawEmitterCID, NS_RAW_MIME_EMITTER_CID);
|
||||
|
||||
NS_METHOD
|
||||
MimePluginInstance::DetermineOutputFormat(const char *url)
|
||||
{
|
||||
// For now, we need to see what we are outputting...headers, body or all of it.
|
||||
//
|
||||
// Do sanity checking...
|
||||
if ( (!url) || (!*url) )
|
||||
{
|
||||
mOutputFormat = PL_strdup("text/html");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
char *format = PL_strcasestr(url, "?outformat=");
|
||||
char *part = PL_strcasestr(url, "?part=");
|
||||
char *header = PL_strcasestr(url, "?header=");
|
||||
char *ptr;
|
||||
|
||||
if (!format) format = PL_strcasestr(url, "&outformat=");
|
||||
if (!part) part = PL_strcasestr(url, "&part=");
|
||||
if (!header) header = PL_strcasestr(url, "&header=");
|
||||
|
||||
// First, did someone pass in a desired output format. They will be able to
|
||||
// pass in any content type (i.e. image/gif, text/html, etc...but the "/" will
|
||||
// have to be represented via the "%2F" value
|
||||
if (format)
|
||||
{
|
||||
format += PL_strlen("?outformat=");
|
||||
while (*format == ' ')
|
||||
++format;
|
||||
|
||||
if ((format) && (*format))
|
||||
{
|
||||
char *ptr;
|
||||
PR_FREEIF(mOutputFormat);
|
||||
mOutputFormat = PL_strdup(format);
|
||||
ptr = mOutputFormat;
|
||||
do
|
||||
{
|
||||
if ( (*ptr == '?') || (*ptr == '&') ||
|
||||
(*ptr == ';') || (*ptr == ' ') )
|
||||
{
|
||||
*ptr = '\0';
|
||||
break;
|
||||
}
|
||||
else if (*ptr == '%')
|
||||
{
|
||||
if ( (*(ptr+1) == '2') &&
|
||||
( (*(ptr+2) == 'F') || (*(ptr+2) == 'f') )
|
||||
)
|
||||
{
|
||||
*ptr = '/';
|
||||
memmove(ptr+1, ptr+3, PL_strlen(ptr+3));
|
||||
*(ptr + PL_strlen(ptr+3) + 1) = '\0';
|
||||
ptr += 3;
|
||||
}
|
||||
}
|
||||
} while (*ptr++);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (!part)
|
||||
{
|
||||
if (header)
|
||||
|
@ -168,12 +220,19 @@ MimePluginInstance::Initialize(nsINetOStream* stream, const char *stream_name)
|
|||
NULL, nsIMimeEmitter::GetIID(),
|
||||
(void **) &mEmitter);
|
||||
}
|
||||
else
|
||||
else if (PL_strcmp(mOutputFormat, "text/html") == 0)
|
||||
{
|
||||
res = nsRepository::CreateInstance(kMimeHTMLEmitterCID,
|
||||
NULL, nsIMimeEmitter::GetIID(),
|
||||
(void **) &mEmitter);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Need to create a raw emitter here!
|
||||
res = nsRepository::CreateInstance(kMimeRawEmitterCID,
|
||||
NULL, nsIMimeEmitter::GetIID(),
|
||||
(void **) &mEmitter);
|
||||
}
|
||||
|
||||
if ((NS_OK != res) || (!mEmitter))
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче