2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 22:33:16 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-03-19 23:00:36 +03:00
|
|
|
*
|
2004-04-17 22:33:16 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
1999-03-19 23:00:36 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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.
|
|
|
|
*
|
2004-04-17 22:33:16 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 22:33:16 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 22:33:16 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 22:33:16 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-03-19 23:00:36 +03:00
|
|
|
|
1999-05-29 00:00:32 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-03-19 23:00:36 +03:00
|
|
|
#include "mimeeobj.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "plstr.h"
|
1999-04-13 07:14:46 +04:00
|
|
|
#include "prlog.h"
|
1999-05-29 00:00:32 +04:00
|
|
|
#include "nsMimeStringResources.h"
|
|
|
|
#include "mimemoz2.h"
|
1999-10-06 22:35:16 +04:00
|
|
|
#include "nsCRT.h"
|
2001-02-01 02:22:18 +03:00
|
|
|
#include "mimemapl.h"
|
|
|
|
#include "nsMimeTypes.h"
|
|
|
|
|
1999-03-19 23:00:36 +03:00
|
|
|
|
|
|
|
#define MIME_SUPERCLASS mimeLeafClass
|
|
|
|
MimeDefClass(MimeExternalObject, MimeExternalObjectClass,
|
|
|
|
mimeExternalObjectClass, &MIME_SUPERCLASS);
|
|
|
|
|
|
|
|
static int MimeExternalObject_initialize (MimeObject *);
|
|
|
|
static void MimeExternalObject_finalize (MimeObject *);
|
|
|
|
static int MimeExternalObject_parse_begin (MimeObject *);
|
2004-01-04 10:57:16 +03:00
|
|
|
static int MimeExternalObject_parse_buffer (const char *, PRInt32, MimeObject *);
|
1999-03-19 23:00:36 +03:00
|
|
|
static int MimeExternalObject_parse_line (char *, PRInt32, MimeObject *);
|
2004-01-04 10:57:16 +03:00
|
|
|
static int MimeExternalObject_parse_decoded_buffer (const char*, PRInt32, MimeObject*);
|
1999-03-19 23:00:36 +03:00
|
|
|
static PRBool MimeExternalObject_displayable_inline_p (MimeObjectClass *clazz,
|
|
|
|
MimeHeaders *hdrs);
|
|
|
|
|
|
|
|
static int
|
|
|
|
MimeExternalObjectClassInitialize(MimeExternalObjectClass *clazz)
|
|
|
|
{
|
|
|
|
MimeObjectClass *oclass = (MimeObjectClass *) clazz;
|
|
|
|
MimeLeafClass *lclass = (MimeLeafClass *) clazz;
|
|
|
|
|
2002-07-04 15:51:54 +04:00
|
|
|
NS_ASSERTION(!oclass->class_initialized, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
|
1999-03-19 23:00:36 +03:00
|
|
|
oclass->initialize = MimeExternalObject_initialize;
|
|
|
|
oclass->finalize = MimeExternalObject_finalize;
|
|
|
|
oclass->parse_begin = MimeExternalObject_parse_begin;
|
|
|
|
oclass->parse_buffer = MimeExternalObject_parse_buffer;
|
|
|
|
oclass->parse_line = MimeExternalObject_parse_line;
|
|
|
|
oclass->displayable_inline_p = MimeExternalObject_displayable_inline_p;
|
|
|
|
lclass->parse_decoded_buffer = MimeExternalObject_parse_decoded_buffer;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
MimeExternalObject_initialize (MimeObject *object)
|
|
|
|
{
|
|
|
|
return ((MimeObjectClass*)&MIME_SUPERCLASS)->initialize(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
MimeExternalObject_finalize (MimeObject *object)
|
|
|
|
{
|
|
|
|
((MimeObjectClass*)&MIME_SUPERCLASS)->finalize(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
MimeExternalObject_parse_begin (MimeObject *obj)
|
|
|
|
{
|
|
|
|
int status;
|
1999-08-11 04:29:59 +04:00
|
|
|
|
1999-03-19 23:00:36 +03:00
|
|
|
status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_begin(obj);
|
|
|
|
if (status < 0) return status;
|
1999-08-11 04:29:59 +04:00
|
|
|
|
1999-11-11 22:21:11 +03:00
|
|
|
// If we're writing this object, and we're doing it in raw form, then
|
|
|
|
// now is the time to inform the backend what the type of this data is.
|
|
|
|
//
|
1999-03-19 23:00:36 +03:00
|
|
|
if (obj->output_p &&
|
1999-08-11 04:29:59 +04:00
|
|
|
obj->options &&
|
|
|
|
!obj->options->write_html_p &&
|
|
|
|
!obj->options->state->first_data_written_p)
|
|
|
|
{
|
|
|
|
status = MimeObject_output_init(obj, 0);
|
|
|
|
if (status < 0) return status;
|
2002-07-04 15:51:54 +04:00
|
|
|
NS_ASSERTION(obj->options->state->first_data_written_p, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
|
1999-08-11 04:29:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-11 22:21:11 +03:00
|
|
|
//
|
|
|
|
// If we're writing this object as HTML, do all the work now -- just write
|
|
|
|
// out a table with a link in it. (Later calls to the `parse_buffer' method
|
|
|
|
// will simply discard the data of the object itself.)
|
|
|
|
//
|
1999-03-19 23:00:36 +03:00
|
|
|
if (obj->options &&
|
1999-08-11 04:29:59 +04:00
|
|
|
obj->output_p &&
|
|
|
|
obj->options->write_html_p &&
|
|
|
|
obj->options->output_fn)
|
|
|
|
{
|
1999-11-11 22:21:11 +03:00
|
|
|
MimeDisplayOptions newopt = *obj->options; // copy it
|
1999-08-11 04:29:59 +04:00
|
|
|
char *id = 0;
|
|
|
|
char *id_url = 0;
|
|
|
|
char *id_name = 0;
|
2002-01-04 03:17:48 +03:00
|
|
|
nsXPIDLCString id_imap;
|
1999-08-11 04:29:59 +04:00
|
|
|
PRBool all_headers_p = obj->options->headers == MimeHeadersAll;
|
|
|
|
|
|
|
|
id = mime_part_address (obj);
|
|
|
|
if (obj->options->missing_parts)
|
2002-01-04 03:17:48 +03:00
|
|
|
id_imap.Adopt(mime_imap_part_address (obj));
|
1999-08-11 04:29:59 +04:00
|
|
|
if (! id) return MIME_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (obj->options && obj->options->url)
|
|
|
|
{
|
|
|
|
const char *url = obj->options->url;
|
|
|
|
if (id_imap && id)
|
|
|
|
{
|
1999-11-11 22:21:11 +03:00
|
|
|
// if this is an IMAP part.
|
2002-01-04 03:17:48 +03:00
|
|
|
id_url = mime_set_url_imap_part(url, id_imap.get(), id);
|
1999-08-11 04:29:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-11-11 22:21:11 +03:00
|
|
|
// This is just a normal MIME part as usual.
|
1999-08-11 04:29:59 +04:00
|
|
|
id_url = mime_set_url_part(url, id, PR_TRUE);
|
|
|
|
}
|
|
|
|
if (!id_url)
|
|
|
|
{
|
|
|
|
PR_Free(id);
|
|
|
|
return MIME_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
1999-10-06 22:35:16 +04:00
|
|
|
if (!nsCRT::strcmp (id, "0"))
|
1999-08-11 04:29:59 +04:00
|
|
|
{
|
|
|
|
PR_Free(id);
|
|
|
|
id = MimeGetStringByID(MIME_MSG_ATTACHMENT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-11-11 22:21:11 +03:00
|
|
|
const char *p = "Part ";
|
2002-02-19 11:42:48 +03:00
|
|
|
char *s = (char *)PR_MALLOC(strlen(p) + strlen(id) + 1);
|
1999-08-11 04:29:59 +04:00
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
PR_Free(id);
|
|
|
|
PR_Free(id_url);
|
|
|
|
return MIME_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-11-11 22:21:11 +03:00
|
|
|
// we have a valid id
|
1999-08-11 04:29:59 +04:00
|
|
|
if (id)
|
|
|
|
id_name = mime_find_suggested_name_of_part(id, obj);
|
|
|
|
PL_strcpy(s, p);
|
|
|
|
PL_strcat(s, id);
|
|
|
|
PR_Free(id);
|
|
|
|
id = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all_headers_p &&
|
1999-11-11 22:21:11 +03:00
|
|
|
// Don't bother showing all headers on this part if it's the only
|
|
|
|
// part in the message: in that case, we've already shown these
|
|
|
|
// headers.
|
1999-08-11 04:29:59 +04:00
|
|
|
obj->options->state &&
|
|
|
|
obj->options->state->root == obj->parent)
|
|
|
|
all_headers_p = PR_FALSE;
|
|
|
|
|
|
|
|
newopt.fancy_headers_p = PR_TRUE;
|
1999-10-14 06:05:20 +04:00
|
|
|
newopt.headers = (all_headers_p ? MimeHeadersAll : MimeHeadersSome);
|
1999-11-11 22:21:11 +03:00
|
|
|
|
|
|
|
/******
|
|
|
|
RICHIE SHERRY
|
|
|
|
GOTTA STILL DO THIS FOR QUOTING!
|
|
|
|
status = MimeHeaders_write_attachment_box (obj->headers, &newopt,
|
|
|
|
obj->content_type,
|
|
|
|
obj->encoding,
|
2000-08-17 03:22:26 +04:00
|
|
|
id_name? id_name : id, id_url, 0)
|
1999-11-11 22:21:11 +03:00
|
|
|
*****/
|
|
|
|
|
2000-08-17 03:22:26 +04:00
|
|
|
// obj->options really owns the storage for this.
|
|
|
|
newopt.part_to_load = nsnull;
|
|
|
|
newopt.default_charset = nsnull;
|
1999-08-11 04:29:59 +04:00
|
|
|
PR_FREEIF(id);
|
|
|
|
PR_FREEIF(id_url);
|
|
|
|
PR_FREEIF(id_name);
|
|
|
|
if (status < 0) return status;
|
|
|
|
}
|
|
|
|
|
1999-03-19 23:00:36 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-01-04 10:57:16 +03:00
|
|
|
MimeExternalObject_parse_buffer (const char *buffer, PRInt32 size, MimeObject *obj)
|
1999-03-19 23:00:36 +03:00
|
|
|
{
|
2002-07-04 15:51:54 +04:00
|
|
|
NS_ASSERTION(!obj->closed_p, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
|
1999-03-19 23:00:36 +03:00
|
|
|
if (obj->closed_p) return -1;
|
|
|
|
|
|
|
|
if (obj->output_p &&
|
|
|
|
obj->options &&
|
|
|
|
!obj->options->write_html_p)
|
|
|
|
{
|
|
|
|
/* The data will be base64-decoded and passed to
|
|
|
|
MimeExternalObject_parse_decoded_buffer. */
|
|
|
|
return ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_buffer(buffer, size,
|
|
|
|
obj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, simply ignore the data. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2004-01-04 10:57:16 +03:00
|
|
|
MimeExternalObject_parse_decoded_buffer (const char *buf, PRInt32 size,
|
1999-03-19 23:00:36 +03:00
|
|
|
MimeObject *obj)
|
|
|
|
{
|
|
|
|
/* This is called (by MimeLeafClass->parse_buffer) with blocks of data
|
|
|
|
that have already been base64-decoded. This will only be called in
|
|
|
|
the case where we're not emitting HTML, and want access to the raw
|
|
|
|
data itself.
|
|
|
|
|
|
|
|
We override the `parse_decoded_buffer' method provided by MimeLeaf
|
|
|
|
because, unlike most children of MimeLeaf, we do not want to line-
|
|
|
|
buffer the decoded data -- we want to simply pass it along to the
|
|
|
|
backend, without going through our `parse_line' method.
|
|
|
|
*/
|
|
|
|
if (!obj->output_p ||
|
|
|
|
!obj->options ||
|
|
|
|
obj->options->write_html_p)
|
|
|
|
{
|
2002-07-04 15:51:54 +04:00
|
|
|
NS_ASSERTION(0, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
|
1999-03-19 23:00:36 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MimeObject_write(obj, buf, size, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
MimeExternalObject_parse_line (char *line, PRInt32 length, MimeObject *obj)
|
|
|
|
{
|
|
|
|
/* This method should never be called (externals do no line buffering).
|
|
|
|
*/
|
2002-07-04 15:51:54 +04:00
|
|
|
NS_ASSERTION(0, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
|
1999-03-19 23:00:36 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
MimeExternalObject_displayable_inline_p (MimeObjectClass *clazz,
|
|
|
|
MimeHeaders *hdrs)
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|