1999-03-19 23:00:36 +03:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-03-19 23:00:36 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-03-19 23:00:36 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-03-19 23:00:36 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-03-19 23:00:36 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mimethtm.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "plstr.h"
|
1999-04-13 07:14:46 +04:00
|
|
|
#include "prlog.h"
|
|
|
|
#include "msgCore.h"
|
1999-05-29 00:00:32 +04:00
|
|
|
#include "nsMimeStringResources.h"
|
1999-03-19 23:00:36 +03:00
|
|
|
|
|
|
|
#define MIME_SUPERCLASS mimeInlineTextClass
|
|
|
|
MimeDefClass(MimeInlineTextHTML, MimeInlineTextHTMLClass,
|
|
|
|
mimeInlineTextHTMLClass, &MIME_SUPERCLASS);
|
|
|
|
|
|
|
|
static int MimeInlineTextHTML_parse_line (char *, PRInt32, MimeObject *);
|
|
|
|
static int MimeInlineTextHTML_parse_eof (MimeObject *, PRBool);
|
|
|
|
static int MimeInlineTextHTML_parse_begin (MimeObject *obj);
|
|
|
|
|
|
|
|
static int
|
|
|
|
MimeInlineTextHTMLClassInitialize(MimeInlineTextHTMLClass *clazz)
|
|
|
|
{
|
|
|
|
MimeObjectClass *oclass = (MimeObjectClass *) clazz;
|
|
|
|
PR_ASSERT(!oclass->class_initialized);
|
|
|
|
oclass->parse_begin = MimeInlineTextHTML_parse_begin;
|
|
|
|
oclass->parse_line = MimeInlineTextHTML_parse_line;
|
|
|
|
oclass->parse_eof = MimeInlineTextHTML_parse_eof;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
MimeInlineTextHTML_parse_begin (MimeObject *obj)
|
|
|
|
{
|
|
|
|
int status = ((MimeObjectClass*)&mimeLeafClass)->parse_begin(obj);
|
|
|
|
if (status < 0) return status;
|
|
|
|
|
|
|
|
if (!obj->output_p) return 0;
|
|
|
|
|
|
|
|
/* If this HTML part has a Content-Base header, and if we're displaying
|
|
|
|
to the screen (that is, not writing this part "raw") then translate
|
|
|
|
that Content-Base header into a <BASE> tag in the HTML.
|
|
|
|
*/
|
|
|
|
if (obj->options &&
|
|
|
|
obj->options->write_html_p &&
|
|
|
|
obj->options->output_fn)
|
|
|
|
{
|
|
|
|
char *base_hdr = MimeHeaders_get (obj->headers, HEADER_CONTENT_BASE,
|
|
|
|
PR_FALSE, PR_FALSE);
|
|
|
|
|
|
|
|
/* rhp - for MHTML Spec changes!!! */
|
|
|
|
if (!base_hdr)
|
|
|
|
{
|
|
|
|
base_hdr = MimeHeaders_get (obj->headers, HEADER_CONTENT_LOCATION, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
/* rhp - for MHTML Spec changes!!! */
|
|
|
|
|
|
|
|
/* Encapsulate the entire text/html part inside an in-flow
|
|
|
|
layer. This will provide it a private coordinate system and
|
|
|
|
prevent it from escaping the bounds of its clipping so that
|
|
|
|
it might, for example, spoof a mail header. */
|
|
|
|
if (obj->options->set_html_state_fn)
|
|
|
|
{
|
|
|
|
status = obj->options->set_html_state_fn(obj->options->stream_closure,
|
|
|
|
PR_TRUE, /* layer_encapulate_p */
|
|
|
|
PR_TRUE, /* start_p */
|
|
|
|
PR_FALSE); /* abort_p */
|
|
|
|
if (status < 0) return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base_hdr)
|
|
|
|
{
|
1999-10-06 22:35:16 +04:00
|
|
|
char *buf = (char *) PR_MALLOC(nsCRT::strlen(base_hdr) + 20);
|
1999-03-19 23:00:36 +03:00
|
|
|
const char *in;
|
|
|
|
char *out;
|
|
|
|
if (!buf)
|
1999-05-29 00:00:32 +04:00
|
|
|
return MIME_OUT_OF_MEMORY;
|
1999-03-19 23:00:36 +03:00
|
|
|
|
|
|
|
/* The value of the Content-Base header is a number of "words".
|
|
|
|
Whitespace in this header is not significant -- it is assumed
|
|
|
|
that any real whitespace in the URL has already been encoded,
|
|
|
|
and whitespace has been inserted to allow the lines in the
|
|
|
|
mail header to be wrapped reasonably. Creators are supposed
|
|
|
|
to insert whitespace every 40 characters or less.
|
|
|
|
*/
|
|
|
|
PL_strcpy(buf, "<BASE HREF=\"");
|
1999-10-06 22:35:16 +04:00
|
|
|
out = buf + nsCRT::strlen(buf);
|
1999-03-19 23:00:36 +03:00
|
|
|
|
|
|
|
for (in = base_hdr; *in; in++)
|
|
|
|
/* ignore whitespace and quotes */
|
1999-12-03 03:12:49 +03:00
|
|
|
if (!nsString::IsSpace(*in) && *in != '"')
|
1999-03-19 23:00:36 +03:00
|
|
|
*out++ = *in;
|
|
|
|
|
|
|
|
/* Close the tag and argument. */
|
|
|
|
*out++ = '"';
|
|
|
|
*out++ = '>';
|
|
|
|
*out++ = 0;
|
|
|
|
|
|
|
|
PR_Free(base_hdr);
|
|
|
|
|
1999-10-06 22:35:16 +04:00
|
|
|
status = MimeObject_write(obj, buf, nsCRT::strlen(buf), PR_FALSE);
|
1999-03-19 23:00:36 +03:00
|
|
|
PR_Free(buf);
|
|
|
|
if (status < 0) return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-19 18:19:53 +03:00
|
|
|
// rhp: For a change, we will write out a separator after formatted text
|
|
|
|
// bodies.
|
|
|
|
status = MimeObject_write_separator(obj);
|
|
|
|
if (status < 0) return status;
|
|
|
|
|
1999-03-19 23:00:36 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
MimeInlineTextHTML_parse_line (char *line, PRInt32 length, MimeObject *obj)
|
|
|
|
{
|
|
|
|
if (!obj->output_p) return 0;
|
|
|
|
|
|
|
|
if (obj->options && obj->options->output_fn)
|
|
|
|
return MimeObject_write(obj, line, length, PR_TRUE);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This method is the same as that of MimeInlineTextRichtext (and thus
|
|
|
|
MimeInlineTextEnriched); maybe that means that MimeInlineTextHTML
|
|
|
|
should share a common parent with them which is not also shared by
|
|
|
|
MimeInlineTextPlain?
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
MimeInlineTextHTML_parse_eof (MimeObject *obj, PRBool abort_p)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
if (obj->closed_p) return 0;
|
|
|
|
|
|
|
|
/* Run parent method first, to flush out any buffered data. */
|
|
|
|
status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_eof(obj, abort_p);
|
|
|
|
if (status < 0) return status;
|
|
|
|
|
|
|
|
if (obj->output_p &&
|
|
|
|
obj->options &&
|
|
|
|
obj->options->write_html_p &&
|
|
|
|
obj->options->set_html_state_fn)
|
|
|
|
{
|
|
|
|
return obj->options->set_html_state_fn(obj->options->stream_closure,
|
|
|
|
PR_TRUE, /* layer_encapulate_p */
|
|
|
|
PR_FALSE, /* start_p */
|
|
|
|
abort_p);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|