Fix for bug 71865. Don't need to emit an html box for attachments are attachments are now shown in the chrome. R=varada, SR=sspitzer

This commit is contained in:
ducarroz%netscape.com 2001-08-10 23:15:36 +00:00
Родитель baf3d5e2ac
Коммит a76348f819
2 изменённых файлов: 37 добавлений и 132 удалений

Просмотреть файл

@ -52,8 +52,6 @@ static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
*/ */
nsMimeHtmlDisplayEmitter::nsMimeHtmlDisplayEmitter() : nsMimeBaseEmitter() nsMimeHtmlDisplayEmitter::nsMimeHtmlDisplayEmitter() : nsMimeBaseEmitter()
{ {
mFirst = PR_TRUE;
mSkipAttachment = PR_FALSE;
} }
nsMimeHtmlDisplayEmitter::~nsMimeHtmlDisplayEmitter(void) nsMimeHtmlDisplayEmitter::~nsMimeHtmlDisplayEmitter(void)
@ -303,151 +301,62 @@ nsresult
nsMimeHtmlDisplayEmitter::StartAttachment(const char *name, const char *contentType, const char *url, nsMimeHtmlDisplayEmitter::StartAttachment(const char *name, const char *contentType, const char *url,
PRBool aNotDownloaded) PRBool aNotDownloaded)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIMsgHeaderSink> headerSink; nsCOMPtr<nsIMsgHeaderSink> headerSink;
rv = GetHeaderSink(getter_AddRefs(headerSink)); rv = GetHeaderSink(getter_AddRefs(headerSink));
if (headerSink) if (NS_FAILED(rv) || !headerSink)
return NS_OK; //If we don't need or cannot broadcast attachment info, just ignore it and return NS_OK
char * escapedUrl = nsEscape(url, url_Path);
nsXPIDLCString uriString;
nsCOMPtr<nsIMsgMessageUrl> msgurl (do_QueryInterface(mURL, &rv));
if (NS_SUCCEEDED(rv))
{ {
char * escapedUrl = nsEscape(url, url_Path); // HACK: news urls require us to use the originalSpec. everyone else uses GetURI
nsXPIDLCString uriString; // to get the RDF resource which describes the message.
nsCOMPtr<nsINntpUrl> nntpUrl (do_QueryInterface(mURL, &rv));
nsCOMPtr<nsIMsgMessageUrl> msgurl (do_QueryInterface(mURL, &rv)); if (NS_SUCCEEDED(rv) && nntpUrl)
if (NS_SUCCEEDED(rv)) rv = msgurl->GetOriginalSpec(getter_Copies(uriString));
{ else
// HACK: news urls require us to use the originalSpec. everyone else uses GetURI rv = msgurl->GetUri(getter_Copies(uriString));
// to get the RDF resource which describes the message.
nsCOMPtr<nsINntpUrl> nntpUrl (do_QueryInterface(mURL, &rv));
if (NS_SUCCEEDED(rv) && nntpUrl)
rv = msgurl->GetOriginalSpec(getter_Copies(uriString));
else
rv = msgurl->GetUri(getter_Copies(uriString));
}
// we need to convert the attachment name from UTF-8 to unicode before
// we emit it...
nsXPIDLString unicodeHeaderValue;
rv = NS_ERROR_FAILURE; // use failure to mean that we couldn't decode
if (mUnicodeConverter)
rv = mUnicodeConverter->DecodeMimeHeader(name,
getter_Copies(unicodeHeaderValue));
if (NS_FAILED(rv))
{
unicodeHeaderValue.Adopt(NS_ConvertUTF8toUCS2(name).ToNewUnicode());
// but it's not really a failure if we didn't have a converter in the first place
if ( !mUnicodeConverter )
rv = NS_OK;
}
headerSink->HandleAttachment(contentType, url /* was escapedUrl */, unicodeHeaderValue, uriString, aNotDownloaded);
nsCRT::free(escapedUrl);
mSkipAttachment = PR_TRUE;
} }
else
// then we need to deal with the attachments in the body by inserting them into a table.. // we need to convert the attachment name from UTF-8 to unicode before
return StartAttachmentInBody(name, contentType, url); // we emit it...
nsXPIDLString unicodeHeaderValue;
rv = NS_ERROR_FAILURE; // use failure to mean that we couldn't decode
if (mUnicodeConverter)
rv = mUnicodeConverter->DecodeMimeHeader(name,
getter_Copies(unicodeHeaderValue));
if (NS_FAILED(rv))
{
unicodeHeaderValue.Adopt(NS_ConvertUTF8toUCS2(name).ToNewUnicode());
// but it's not really a failure if we didn't have a converter in the first place
if ( !mUnicodeConverter )
rv = NS_OK;
}
headerSink->HandleAttachment(contentType, url /* was escapedUrl */, unicodeHeaderValue, uriString, aNotDownloaded);
nsCRT::free(escapedUrl);
return rv; return rv;
} }
// 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 in quoting
//
nsresult
nsMimeHtmlDisplayEmitter::StartAttachmentInBody(const char *name, const char *contentType, const char *url)
{
if ( (contentType) &&
((!nsCRT::strcmp(contentType, APPLICATION_XPKCS7_MIME)) ||
(!nsCRT::strcmp(contentType, APPLICATION_XPKCS7_SIGNATURE)) ||
(!nsCRT::strcmp(contentType, TEXT_VCARD))
)
)
{
mSkipAttachment = PR_TRUE;
return NS_OK;
}
else
mSkipAttachment = PR_FALSE;
if (!mFirst)
UtilityWrite("<hr width=\"90%\" size=4>");
mFirst = PR_FALSE;
UtilityWrite("<CENTER>");
UtilityWrite("<table border>");
UtilityWrite("<tr>");
UtilityWrite("<td>");
UtilityWrite("<div align=right class=\"headerdisplayname\" style=\"display:inline;\">");
UtilityWrite(name);
UtilityWrite("</div>");
UtilityWrite("</td>");
UtilityWrite("<td>");
UtilityWrite("<table border=0>");
return NS_OK;
}
nsresult nsresult
nsMimeHtmlDisplayEmitter::AddAttachmentField(const char *field, const char *value) nsMimeHtmlDisplayEmitter::AddAttachmentField(const char *field, const char *value)
{ {
if (mSkipAttachment || BroadCastHeadersAndAttachments())
return NS_OK;
// Don't let bad things happen
if ( (!value) || (!*value) )
return NS_OK;
// Don't output this ugly header...
if (!nsCRT::strcmp(field, HEADER_X_MOZILLA_PART_URL))
return NS_OK;
char *newValue = nsEscapeHTML(value);
UtilityWrite("<tr>");
UtilityWrite("<td>");
UtilityWrite("<div align=right class=\"headerdisplayname\" style=\"display:inline;\">");
UtilityWrite(field);
UtilityWrite(":");
UtilityWrite("</div>");
UtilityWrite("</td>");
UtilityWrite("<td>");
UtilityWrite(newValue);
UtilityWrite("</td>");
UtilityWrite("</tr>");
PR_FREEIF(newValue);
return NS_OK; return NS_OK;
} }
nsresult nsresult
nsMimeHtmlDisplayEmitter::EndAttachment() nsMimeHtmlDisplayEmitter::EndAttachment()
{ {
mSkipAttachment = PR_FALSE;
if (BroadCastHeadersAndAttachments())
return NS_OK;
UtilityWrite("</table>");
UtilityWrite("</td>");
UtilityWrite("</tr>");
UtilityWrite("</table>");
UtilityWrite("</center>");
UtilityWrite("<br>");
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -62,14 +62,10 @@ public:
virtual nsresult WriteHeaderFieldHTMLPostfix(); virtual nsresult WriteHeaderFieldHTMLPostfix();
protected: protected:
PRBool mFirst; // Attachment flag...
PRBool mSkipAttachment; // attachments we shouldn't show...
nsCOMPtr<nsIMsgHeaderSink> mHeaderSink; nsCOMPtr<nsIMsgHeaderSink> mHeaderSink;
nsresult GetHeaderSink(nsIMsgHeaderSink ** aHeaderSink); nsresult GetHeaderSink(nsIMsgHeaderSink ** aHeaderSink);
PRBool BroadCastHeadersAndAttachments(); PRBool BroadCastHeadersAndAttachments();
nsresult StartAttachmentInBody(const char *name, const char *contentType, const char *url);
nsCOMPtr<nsIDateTimeFormat> mDateFormater; nsCOMPtr<nsIDateTimeFormat> mDateFormater;
nsresult GenerateDateString(const char * dateString, PRUnichar ** formattedDate); nsresult GenerateDateString(const char * dateString, PRUnichar ** formattedDate);