[evolution/camel-gobject] Adapt to more Camel API changes.
- From: Matthew Barnes <mbarnes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution/camel-gobject] Adapt to more Camel API changes.
- Date: Fri, 1 Jan 2010 05:53:55 +0000 (UTC)
commit 58be8dd15174fe053483859e7137a8ab60b96dd1
Author: Matthew Barnes <mbarnes redhat com>
Date: Thu Dec 31 23:30:33 2009 -0600
Adapt to more Camel API changes.
calendar/gui/dialogs/comp-editor.c | 2 +-
composer/e-composer-autosave.c | 2 +-
composer/e-msg-composer.c | 52 +-
e-util/e-signature-utils.c | 11 +-
em-format/em-format-quote.c | 403 ++++---
em-format/em-format.c | 1028 +++++++++------
em-format/em-format.h | 81 +-
mail/em-composer-utils.c | 39 +-
mail/em-format-hook.c | 16 +-
mail/em-format-html-display.c | 157 ++-
mail/em-format-html.c | 1854 +++++++++++++++------------
mail/em-html-stream.c | 2 +-
mail/em-inline-filter.c | 2 +-
mail/em-sync-stream.c | 11 +-
mail/em-utils.c | 86 +-
mail/em-utils.h | 4 +-
mail/importers/mail-importer.c | 2 +-
mail/mail-ops.c | 29 +-
mail/message-list.c | 2 +-
modules/calendar/e-cal-attachment-handler.c | 2 +-
modules/mail/e-mail-attachment-handler.c | 6 +-
plugins/audio-inline/audio-inline.c | 8 +-
plugins/bogo-junk-plugin/bf-junk-filter.c | 12 +-
plugins/groupwise-features/install-shared.c | 4 +-
plugins/image-inline/image-inline.c | 5 +-
plugins/itip-formatter/itip-formatter.c | 26 +-
plugins/mail-to-task/mail-to-task.c | 2 +-
plugins/prefer-plain/prefer-plain.c | 14 +-
plugins/pst-import/pst-importer.c | 8 +-
plugins/sa-junk-plugin/em-junk-filter.c | 10 +-
plugins/templates/templates.c | 9 +-
plugins/tnef-attachments/tnef-plugin.c | 16 +-
plugins/vcard-inline/vcard-inline.c | 5 +-
widgets/misc/e-attachment.c | 9 +-
34 files changed, 2264 insertions(+), 1655 deletions(-)
---
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c
index 0794c49..17492b4 100644
--- a/calendar/gui/dialogs/comp-editor.c
+++ b/calendar/gui/dialogs/comp-editor.c
@@ -2910,7 +2910,7 @@ comp_editor_get_mime_attach_list (CompEditor *editor)
byte_array = g_byte_array_new ();
mstream = camel_stream_mem_new_with_byte_array (byte_array);
- camel_data_wrapper_decode_to_stream (wrapper, mstream);
+ camel_data_wrapper_decode_to_stream (wrapper, mstream, NULL);
buffer = g_memdup (byte_array->data, byte_array->len);
camel_mime_part_set_content_id (mime_part, NULL);
diff --git a/composer/e-composer-autosave.c b/composer/e-composer-autosave.c
index c41c74b..f48c2f5 100644
--- a/composer/e-composer-autosave.c
+++ b/composer/e-composer-autosave.c
@@ -364,7 +364,7 @@ autosave_snapshot_cb (GFile *file,
camel_stream_mem_set_byte_array (
CAMEL_STREAM_MEM (camel_stream), buffer);
camel_data_wrapper_decode_to_stream (
- CAMEL_DATA_WRAPPER (message), camel_stream);
+ CAMEL_DATA_WRAPPER (message), camel_stream, NULL);
g_object_unref (message);
g_object_unref (camel_stream);
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 4ddfcc3..fdf3e25 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -118,30 +118,37 @@ static gchar *
emcu_part_to_html (CamelMimePart *part, gssize *len, EMFormat *source)
{
EMFormatQuote *emfq;
- CamelStreamMem *mem;
+ CamelStream *stream;
GByteArray *buf;
gchar *text;
buf = g_byte_array_new ();
- mem = (CamelStreamMem *) camel_stream_mem_new ();
- camel_stream_mem_set_byte_array (mem, buf);
+ stream = camel_stream_mem_new_with_byte_array (buf);
- emfq = em_format_quote_new (NULL, (CamelStream *)mem, EM_FORMAT_QUOTE_KEEP_SIG);
+ emfq = em_format_quote_new (
+ NULL, stream, EM_FORMAT_QUOTE_KEEP_SIG);
((EMFormat *) emfq)->composer = TRUE;
- if (source) {
- /* copy over things we can, other things are internal, perhaps need different api than 'clone' */
+
+ if (source != NULL) {
+ /* copy over things we can, other things are internal,
+ * perhaps need different api than 'clone' */
if (source->default_charset)
- em_format_set_default_charset((EMFormat *)emfq, source->default_charset);
+ em_format_set_default_charset (
+ EM_FORMAT (emfq), source->default_charset);
if (source->charset)
- em_format_set_default_charset((EMFormat *)emfq, source->charset);
+ em_format_set_default_charset (
+ EM_FORMAT (emfq), source->charset);
}
- em_format_part((EMFormat *) emfq, (CamelStream *)mem, part);
- g_object_unref(emfq);
- camel_stream_write((CamelStream *) mem, "", 1);
- g_object_unref(mem);
+ /* XXX Not handling errors. */
+ em_format_part (EM_FORMAT (emfq), stream, part, NULL);
+
+ g_object_unref (emfq);
+
+ camel_stream_write (stream, "", 1, NULL);
+ g_object_unref (stream);
- text = (gchar *)buf->data;
+ text = (gchar *) buf->data;
if (len)
*len = buf->len-1;
g_byte_array_free (buf, FALSE);
@@ -673,7 +680,7 @@ build_message (EMsgComposer *composer,
/* construct the content object */
plain = camel_data_wrapper_new ();
- camel_data_wrapper_construct_from_stream (plain, stream);
+ camel_data_wrapper_construct_from_stream (plain, stream, NULL);
g_object_unref (stream);
if (plain_encoding == CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE) {
@@ -728,7 +735,7 @@ build_message (EMsgComposer *composer,
g_object_unref (mf);
}
- camel_data_wrapper_construct_from_stream (html, stream);
+ camel_data_wrapper_construct_from_stream (html, stream, NULL);
g_object_unref (stream);
camel_data_wrapper_set_mime_type (html, "text/html; charset=utf-8");
@@ -1372,12 +1379,12 @@ autosave_load_draft (const gchar *filename)
g_return_val_if_fail (filename != NULL, NULL);
- if (!(stream = camel_stream_fs_new_with_name (filename, O_RDONLY, 0)))
+ if (!(stream = camel_stream_fs_new_with_name (filename, O_RDONLY, 0, NULL)))
return NULL;
msg = camel_mime_message_new ();
camel_data_wrapper_construct_from_stream (
- CAMEL_DATA_WRAPPER (msg), stream);
+ CAMEL_DATA_WRAPPER (msg), stream, NULL);
g_object_unref (stream);
composer = e_msg_composer_new_with_message (msg);
@@ -2038,7 +2045,7 @@ msg_composer_uri_requested (GtkhtmlEditor *editor,
array = g_byte_array_new ();
camel_stream = camel_stream_mem_new_with_byte_array (array);
wrapper = camel_medium_get_content (CAMEL_MEDIUM (part));
- camel_data_wrapper_decode_to_stream (wrapper, camel_stream);
+ camel_data_wrapper_decode_to_stream (wrapper, camel_stream, NULL);
gtk_html_write (
gtkhtml_editor_get_html (editor), stream,
@@ -3551,12 +3558,13 @@ e_msg_composer_add_inline_image_from_file (EMsgComposer *composer,
if (!g_file_test (dec_file_name, G_FILE_TEST_IS_REGULAR))
return NULL;
- stream = camel_stream_fs_new_with_name (dec_file_name, O_RDONLY, 0);
+ stream = camel_stream_fs_new_with_name (
+ dec_file_name, O_RDONLY, 0, NULL);
if (!stream)
return NULL;
wrapper = camel_data_wrapper_new ();
- camel_data_wrapper_construct_from_stream (wrapper, stream);
+ camel_data_wrapper_construct_from_stream (wrapper, stream, NULL);
g_object_unref (CAMEL_OBJECT (stream));
mime_type = e_util_guess_mime_type (dec_file_name, TRUE);
@@ -3977,13 +3985,13 @@ e_msg_composer_load_from_file (const gchar *filename)
g_return_val_if_fail (filename != NULL, NULL);
- stream = camel_stream_fs_new_with_name (filename, O_RDONLY, 0);
+ stream = camel_stream_fs_new_with_name (filename, O_RDONLY, 0, NULL);
if (stream == NULL)
return NULL;
msg = camel_mime_message_new ();
camel_data_wrapper_construct_from_stream (
- CAMEL_DATA_WRAPPER (msg), stream);
+ CAMEL_DATA_WRAPPER (msg), stream, NULL);
g_object_unref (stream);
composer = e_msg_composer_new_with_message (msg);
diff --git a/e-util/e-signature-utils.c b/e-util/e-signature-utils.c
index 5077dfc..0bb5ec5 100644
--- a/e-util/e-signature-utils.c
+++ b/e-util/e-signature-utils.c
@@ -152,6 +152,7 @@ e_read_signature_file (ESignature *signature,
gboolean is_html;
gchar *content;
gsize length;
+ gint retval;
gint fd;
g_return_val_if_fail (E_IS_SIGNATURE (signature), NULL);
@@ -195,10 +196,14 @@ e_read_signature_file (ESignature *signature,
output_stream = camel_stream_mem_new ();
camel_stream_mem_set_byte_array (
CAMEL_STREAM_MEM (output_stream), buffer);
- camel_stream_write_to_stream (input_stream, output_stream);
+ retval = camel_stream_write_to_stream (
+ input_stream, output_stream, error);
g_object_unref (output_stream);
g_object_unref (input_stream);
+ if (retval == -1)
+ return NULL;
+
/* Make sure the buffer is nul-terminated. */
length = (gsize) buffer->len;
g_byte_array_append (buffer, (guint8 *) "", 1);
@@ -288,8 +293,10 @@ e_run_signature_script (const gchar *filename)
camel_stream_mem_set_byte_array (
CAMEL_STREAM_MEM (output_stream), buffer);
+ /* XXX Improve error checking here. */
input_stream = camel_stream_fs_new_with_fd (in_fds[0]);
- camel_stream_write_to_stream (input_stream, output_stream);
+ camel_stream_write_to_stream (
+ input_stream, output_stream, NULL);
g_object_unref (input_stream);
g_object_unref (output_stream);
diff --git a/em-format/em-format-quote.c b/em-format/em-format-quote.c
index 5ab39a5..5d4b605 100644
--- a/em-format/em-format-quote.c
+++ b/em-format/em-format-quote.c
@@ -37,12 +37,6 @@ struct _EMFormatQuotePrivate {
gint dummy;
};
-static void emfq_format_clone(EMFormat *, CamelFolder *, const gchar *, CamelMimeMessage *, EMFormat *);
-static void emfq_format_error(EMFormat *emf, CamelStream *stream, const gchar *txt);
-static void emfq_format_message(EMFormat *, CamelStream *, CamelMimePart *, const EMFormatHandler *);
-static void emfq_format_source(EMFormat *, CamelStream *, CamelMimePart *);
-static void emfq_format_attachment(EMFormat *, CamelStream *, CamelMimePart *, const gchar *, const EMFormatHandler *);
-
static void emfq_builtin_init(EMFormatQuoteClass *efhc);
static gpointer parent_class;
@@ -71,9 +65,127 @@ emfq_finalize (GObject *object)
}
static void
-emfq_base_init(EMFormatQuoteClass *emfqclass)
+emfq_format_clone (EMFormat *emf,
+ CamelFolder *folder,
+ const gchar *uid,
+ CamelMimeMessage *msg,
+ EMFormat *src)
{
- emfq_builtin_init(emfqclass);
+ EMFormatClass *format_class;
+ EMFormatQuote *emfq = (EMFormatQuote *) emf;
+ const EMFormatHandler *handle;
+ CamelStream *stream;
+ GConfClient *gconf;
+
+ /* Chain up to parent's format_clone() method. */
+ format_class = EM_FORMAT_CLASS (parent_class);
+ format_class->format_clone (emf, folder, uid, msg, src);
+
+ stream = emfq->stream;
+
+ /* For the top-posters... */
+ gconf = gconf_client_get_default ();
+ camel_stream_reset (stream, NULL);
+ if (gconf_client_get_bool(gconf, "/apps/evolution/mail/composer/top_signature", NULL))
+ camel_stream_write (stream, "<br>\n", 5, NULL);
+ g_object_unref (gconf);
+
+ handle = em_format_find_handler(emf, "x-evolution/message/prefix");
+ g_return_if_fail (handle != NULL);
+
+ /* XXX Pass an error. */
+ handle->handler (emf, stream, CAMEL_MIME_PART (msg), handle, NULL);
+
+ handle = em_format_find_handler(emf, "x-evolution/message/rfc822");
+ g_return_if_fail (handle != NULL);
+
+ /* XXX Here too. */
+ handle->handler (emf, stream, CAMEL_MIME_PART (msg), handle, NULL);
+
+ camel_stream_flush (stream, NULL);
+
+ g_signal_emit_by_name (emf, "complete");
+}
+
+static gboolean
+emfq_format_error (EMFormat *emf,
+ CamelStream *stream,
+ const gchar *txt,
+ GError **error)
+{
+ /* XXX Should we even bother writing error
+ * text for quoting? Probably not. */
+
+ return TRUE;
+}
+
+static gboolean
+emfq_format_source (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ GError **error)
+{
+ CamelStream *filtered_stream;
+ CamelMimeFilter *html_filter;
+ gboolean success;
+
+ filtered_stream = camel_stream_filter_new (stream);
+
+ html_filter = camel_mime_filter_tohtml_new (
+ CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+ CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
+ CAMEL_MIME_FILTER_TOHTML_ESCAPE_8BIT, 0);
+ camel_stream_filter_add (
+ CAMEL_STREAM_FILTER (filtered_stream), html_filter);
+ g_object_unref (html_filter);
+
+ success = em_format_format_text (
+ emf, filtered_stream, CAMEL_DATA_WRAPPER (part), error);
+
+ g_object_unref (filtered_stream);
+
+ return success;
+}
+
+static gboolean
+emfq_format_attachment (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const gchar *mime_type,
+ const EMFormatHandler *handle,
+ GError **error)
+{
+ gchar *text, *html;
+
+ /* XXX Emit a warning too? */
+ if (handle == NULL)
+ return TRUE;
+
+ if (!em_format_is_inline (emf, emf->part_id->str, part, handle))
+ return TRUE;
+
+ camel_stream_write_string (
+ stream, "<table border=1 cellspacing=0 cellpadding=0>"
+ "<tr><td><font size=-1>\n", NULL);
+
+ /* output some info about it */
+ text = em_format_describe_part (part, mime_type);
+ html = camel_text_to_html (
+ text, EM_FORMAT_QUOTE (emf)->text_html_flags &
+ CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
+ camel_stream_write_string (stream, html, NULL);
+ g_free (html);
+ g_free (text);
+
+ camel_stream_write_string (stream, "</font></td></tr></table>", NULL);
+
+ return handle->handler (emf, stream, part, handle, error);
+}
+
+static void
+emfq_base_init (EMFormatQuoteClass *emfqclass)
+{
+ emfq_builtin_init (emfqclass);
}
static void
@@ -137,53 +249,20 @@ em_format_quote_new (const gchar *credits,
return emfq;
}
-static void
-emfq_format_empty_line(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
-{
- camel_stream_printf(stream, "<br>\n");
-}
-
-static void
-emfq_format_clone(EMFormat *emf, CamelFolder *folder, const gchar *uid, CamelMimeMessage *msg, EMFormat *src)
-{
- EMFormatQuote *emfq = (EMFormatQuote *) emf;
- const EMFormatHandler *handle;
- GConfClient *gconf;
-
- /* Chain up to parent's format_clone() method. */
- EM_FORMAT_CLASS (parent_class)->format_clone (emf, folder, uid, msg, src);
-
- gconf = gconf_client_get_default ();
- camel_stream_reset(emfq->stream);
- if (gconf_client_get_bool(gconf, "/apps/evolution/mail/composer/top_signature", NULL))
- emfq_format_empty_line(emf, emfq->stream, (CamelMimePart *)msg, NULL);
- g_object_unref (gconf);
- handle = em_format_find_handler(emf, "x-evolution/message/prefix");
- if (handle)
- handle->handler(emf, emfq->stream, (CamelMimePart *)msg, handle);
- handle = em_format_find_handler(emf, "x-evolution/message/rfc822");
- if (handle)
- handle->handler(emf, emfq->stream, (CamelMimePart *)msg, handle);
-
- camel_stream_flush(emfq->stream);
-
- g_signal_emit_by_name(emf, "complete");
-}
-
-static void
-emfq_format_error(EMFormat *emf, CamelStream *stream, const gchar *txt)
-{
- /* FIXME: should we even bother writing error text for quoting? probably not... */
-}
-
-static void
-emfq_format_text_header (EMFormatQuote *emfq, CamelStream *stream, const gchar *label, const gchar *value, guint32 flags, gint is_html)
+static gboolean
+emfq_format_text_header (EMFormatQuote *emfq,
+ CamelStream *stream,
+ const gchar *label,
+ const gchar *value,
+ guint32 flags,
+ gboolean is_html,
+ GError **error)
{
const gchar *html;
gchar *mhtml = NULL;
if (value == NULL)
- return;
+ return TRUE;
while (*value == ' ')
value++;
@@ -194,11 +273,15 @@ emfq_format_text_header (EMFormatQuote *emfq, CamelStream *stream, const gchar *
html = value;
if (flags & EM_FORMAT_HEADER_BOLD)
- camel_stream_printf (stream, "<b>%s</b>: %s<br>", label, html);
+ camel_stream_printf (
+ stream, NULL, "<b>%s</b>: %s<br>", label, html);
else
- camel_stream_printf (stream, "%s: %s<br>", label, html);
+ camel_stream_printf (
+ stream, NULL, "%s: %s<br>", label, html);
g_free (mhtml);
+
+ return TRUE;
}
static const gchar *addrspec_hdrs[] = {
@@ -295,16 +378,23 @@ canon_header_name (gchar *name)
}
}
-static void
-emfq_format_header (EMFormat *emf, CamelStream *stream, CamelMedium *part, const gchar *namein, guint32 flags, const gchar *charset)
+static gboolean
+emfq_format_header (EMFormat *emf,
+ CamelStream *stream,
+ CamelMedium *part,
+ const gchar *namein,
+ guint32 flags,
+ const gchar *charset,
+ GError **error)
{
CamelMimeMessage *msg = (CamelMimeMessage *) part;
EMFormatQuote *emfq = (EMFormatQuote *) emf;
gchar *name, *buf, *value = NULL;
const gchar *txt, *label;
gboolean addrspec = FALSE;
- gint is_html = FALSE;
+ gboolean is_html = FALSE;
gint i;
+ gboolean success;
name = g_alloca (strlen (namein) + 1);
strcpy (name, namein);
@@ -324,12 +414,12 @@ emfq_format_header (EMFormat *emf, CamelStream *stream, CamelMedium *part, const
GString *html;
if (!(txt = camel_medium_get_header (part, name)))
- return;
+ return TRUE;
buf = camel_header_unfold (txt);
if (!(addrs = camel_header_address_decode (txt, emf->charset ? emf->charset : emf->default_charset))) {
g_free (buf);
- return;
+ return TRUE;
}
g_free (buf);
@@ -350,7 +440,7 @@ emfq_format_header (EMFormat *emf, CamelStream *stream, CamelMedium *part, const
if (!(txt = camel_medium_get_header (part, "user-agent")))
if (!(txt = camel_medium_get_header (part, "x-newsreader")))
if (!(txt = camel_medium_get_header (part, "x-mimeole")))
- return;
+ return TRUE;
txt = value = camel_header_format_ctext (txt, charset);
@@ -358,7 +448,7 @@ emfq_format_header (EMFormat *emf, CamelStream *stream, CamelMedium *part, const
flags |= EM_FORMAT_HEADER_BOLD;
} else if (!strcmp (name, "Date") || !strcmp (name, "Resent-Date")) {
if (!(txt = camel_medium_get_header (part, name)))
- return;
+ return TRUE;
flags |= EM_FORMAT_HEADER_BOLD;
} else {
@@ -368,21 +458,28 @@ emfq_format_header (EMFormat *emf, CamelStream *stream, CamelMedium *part, const
g_free (buf);
}
- emfq_format_text_header (emfq, stream, label, txt, flags, is_html);
+ success = emfq_format_text_header (
+ emfq, stream, label, txt, flags, is_html, error);
g_free (value);
+
+ return success;
}
-static void
-emfq_format_headers (EMFormatQuote *emfq, CamelStream *stream, CamelMedium *part)
+static gboolean
+emfq_format_headers (EMFormatQuote *emfq,
+ CamelStream *stream,
+ CamelMedium *part,
+ GError **error)
{
EMFormat *emf = (EMFormat *) emfq;
CamelContentType *ct;
const gchar *charset;
GList *link;
+ gboolean success = TRUE;
if (!part)
- return;
+ return TRUE;
ct = camel_mime_part_get_content_type ((CamelMimePart *) part);
charset = camel_content_type_param (ct, "charset");
@@ -390,88 +487,75 @@ emfq_format_headers (EMFormatQuote *emfq, CamelStream *stream, CamelMedium *part
/* dump selected headers */
link = g_queue_peek_head_link (&emf->header_list);
- while (link != NULL) {
+ while (link != NULL && success) {
EMFormatHeader *h = link->data;
- emfq_format_header (
- emf, stream, part, h->name, h->flags, charset);
+ success = emfq_format_header (
+ emf, stream, part, h->name, h->flags, charset, error);
link = g_list_next (link);
}
- camel_stream_printf(stream, "<br>\n");
+ camel_stream_printf (stream, NULL, "<br>\n");
+
+ return success;
}
static void
-emfq_format_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+emfq_format_message_prefix (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info)
{
EMFormatQuote *emfq = (EMFormatQuote *) emf;
if (emfq->credits)
- camel_stream_printf(stream, "%s<br>\n", emfq->credits);
+ camel_stream_printf (stream, NULL, "%s<br>\n", emfq->credits);
}
-static void
-emfq_format_message(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emfq_format_message (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
EMFormatQuote *emfq = (EMFormatQuote *) emf;
+ gboolean success = TRUE;
if (emfq->flags & EM_FORMAT_QUOTE_CITE)
- camel_stream_printf(stream, "<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"orig\" value=\"1\">-->\n"
- "<blockquote type=cite>\n");
-
- if (((CamelMimePart *)emf->message) != part) {
- camel_stream_printf(stream, "%s</br>\n", _("-------- Forwarded Message --------"));
- emfq_format_headers (emfq, stream, (CamelMedium *)part);
+ camel_stream_printf (
+ stream, NULL,
+ "<!--+GtkHTML:<DATA class=\"ClueFlow\" "
+ "key=\"orig\" value=\"1\">-->\n"
+ "<blockquote type=cite>\n");
+
+ if (CAMEL_MIME_PART (emf->message) != part) {
+ camel_stream_printf (
+ stream, NULL, "%s</br>\n",
+ _("-------- Forwarded Message --------"));
+ success = emfq_format_headers (
+ emfq, stream, CAMEL_MEDIUM (part), error);
} else if (emfq->flags & EM_FORMAT_QUOTE_HEADERS)
- emfq_format_headers (emfq, stream, (CamelMedium *)part);
+ success = emfq_format_headers (
+ emfq, stream, CAMEL_MEDIUM (part), error);
- em_format_part (emf, stream, part);
+ if (success)
+ success = em_format_part (emf, stream, part, error);
if (emfq->flags & EM_FORMAT_QUOTE_CITE)
- camel_stream_write_string(stream, "</blockquote><!--+GtkHTML:<DATA class=\"ClueFlow\" clear=\"orig\">-->");
-}
-
-static void
-emfq_format_source(EMFormat *emf, CamelStream *stream, CamelMimePart *part)
-{
- CamelStream *filtered_stream;
- CamelMimeFilter *html_filter;
-
- filtered_stream = camel_stream_filter_new ((CamelStream *) stream);
- html_filter = camel_mime_filter_tohtml_new (CAMEL_MIME_FILTER_TOHTML_CONVERT_NL
- | CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES
- | CAMEL_MIME_FILTER_TOHTML_ESCAPE_8BIT, 0);
- camel_stream_filter_add (
- CAMEL_STREAM_FILTER (filtered_stream), html_filter);
- g_object_unref(html_filter);
-
- em_format_format_text(emf, filtered_stream, (CamelDataWrapper *)part);
- g_object_unref(filtered_stream);
-}
-
-static void
-emfq_format_attachment(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const gchar *mime_type, const EMFormatHandler *handle)
-{
- if (handle && em_format_is_inline(emf, emf->part_id->str, part, handle)) {
- gchar *text, *html;
+ camel_stream_write_string (
+ stream, "</blockquote>"
+ "<!--+GtkHTML:<DATA class=\"ClueFlow\" "
+ "clear=\"orig\">-->", NULL);
- camel_stream_write_string(stream,
- "<table border=1 cellspacing=0 cellpadding=0><tr><td><font size=-1>\n");
-
- /* output some info about it */
- text = em_format_describe_part(part, mime_type);
- html = camel_text_to_html(text, ((EMFormatQuote *)emf)->text_html_flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
- camel_stream_write_string(stream, html);
- g_free(html);
- g_free(text);
-
- camel_stream_write_string(stream, "</font></td></tr></table>");
-
- handle->handler(emf, stream, part, handle);
- }
+ return success;
}
-static void
-emfq_text_plain(EMFormatQuote *emfq, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
+static gboolean
+emfq_text_plain (EMFormatQuote *emfq,
+ CamelStream *stream,
+ CamelMimePart *part,
+ EMFormatHandler *info,
+ GError **error)
{
CamelStream *filtered_stream;
CamelMimeFilter *html_filter;
@@ -480,9 +564,11 @@ emfq_text_plain(EMFormatQuote *emfq, CamelStream *stream, CamelMimePart *part, E
CamelContentType *type;
const gchar *format;
guint32 rgb = 0x737373, flags;
+ gboolean success;
+ /* XXX Emit a warning? */
if (!part)
- return;
+ return TRUE;
flags = emfq->text_html_flags;
@@ -502,60 +588,89 @@ emfq_text_plain(EMFormatQuote *emfq, CamelStream *stream, CamelMimePart *part, E
g_object_unref (sig_strip);
}
- wrap_filter = camel_mime_filter_linewrap_new (70, 70, 0, CAMEL_MIME_FILTER_LINEWRAP_WORD);
+ wrap_filter = camel_mime_filter_linewrap_new (
+ 70, 70, 0, CAMEL_MIME_FILTER_LINEWRAP_WORD);
camel_stream_filter_add (
CAMEL_STREAM_FILTER (filtered_stream), wrap_filter);
g_object_unref (wrap_filter);
- html_filter = camel_mime_filter_tohtml_new(flags, rgb);
+ html_filter = camel_mime_filter_tohtml_new (flags, rgb);
camel_stream_filter_add (
CAMEL_STREAM_FILTER (filtered_stream), html_filter);
- g_object_unref(html_filter);
+ g_object_unref (html_filter);
+
+ success = em_format_format_text (
+ EM_FORMAT (emfq), filtered_stream,
+ CAMEL_DATA_WRAPPER (part), error);
+
+ camel_stream_flush (filtered_stream, NULL);
+ g_object_unref (filtered_stream);
- em_format_format_text((EMFormat *)emfq, filtered_stream, (CamelDataWrapper *)part);
- camel_stream_flush(filtered_stream);
- g_object_unref(filtered_stream);
+ return success;
}
-static void
-emfq_text_enriched(EMFormatQuote *emfq, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
+static gboolean
+emfq_text_enriched (EMFormatQuote *emfq,
+ CamelStream *stream,
+ CamelMimePart *part,
+ EMFormatHandler *info,
+ GError **error)
{
CamelStream *filtered_stream;
CamelMimeFilter *enriched;
CamelDataWrapper *dw;
guint32 flags = 0;
+ gboolean success;
dw = camel_medium_get_content((CamelMedium *)part);
if (!strcmp(info->mime_type, "text/richtext")) {
flags = CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT;
- camel_stream_write_string(stream, "\n<!-- text/richtext -->\n");
+ camel_stream_write_string (
+ stream, "\n<!-- text/richtext -->\n", NULL);
} else {
- camel_stream_write_string(stream, "\n<!-- text/enriched -->\n");
+ camel_stream_write_string (
+ stream, "\n<!-- text/enriched -->\n", NULL);
}
- enriched = camel_mime_filter_enriched_new(flags);
+ enriched = camel_mime_filter_enriched_new (flags);
filtered_stream = camel_stream_filter_new (stream);
camel_stream_filter_add (
CAMEL_STREAM_FILTER (filtered_stream), enriched);
- g_object_unref(enriched);
+ g_object_unref (enriched);
+
+ camel_stream_write_string (stream, "<br><hr><br>", NULL);
+
+ success = em_format_format_text (
+ EM_FORMAT (emfq), filtered_stream,
+ CAMEL_DATA_WRAPPER (part), error);
+
+ g_object_unref (filtered_stream);
- camel_stream_write_string(stream, "<br><hr><br>");
- em_format_format_text((EMFormat *)emfq, filtered_stream, (CamelDataWrapper *)part);
- g_object_unref(filtered_stream);
+ return success;
}
-static void
-emfq_text_html(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
+static gboolean
+emfq_text_html (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ EMFormatHandler *info,
+ GError **error)
{
- camel_stream_write_string(stream, "\n<!-- text/html -->\n");
- em_format_format_text(emf, stream, (CamelDataWrapper *)part);
+ camel_stream_write_string (stream, "\n<!-- text/html -->\n", NULL);
+
+ return em_format_format_text (
+ emf, stream, CAMEL_DATA_WRAPPER (part), error);
}
-static void
-emfq_ignore(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
+static gboolean
+emfq_ignore (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ EMFormatHandler *info,
+ GError **error)
{
- /* NOOP */
+ return TRUE;
}
static EMFormatHandler type_builtin_table[] = {
diff --git a/em-format/em-format.c b/em-format/em-format.c
index 2d69005..d4408bd 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -41,6 +41,8 @@
#define d(x)
+typedef struct _EMFormatCache EMFormatCache;
+
/* Used to cache various data/info for redraws
The validity stuff could be cached at a higher level but this is easier
This absolutely relies on the partid being _globally unique_
@@ -61,10 +63,6 @@ struct _EMFormatCache {
static void emf_builtin_init(EMFormatClass *);
-static const EMFormatHandler *emf_find_handler(EMFormat *emf, const gchar *mime_type);
-static void emf_format_clone(EMFormat *emf, CamelFolder *folder, const gchar *uid, CamelMimeMessage *msg, EMFormat *emfsource);
-static void emf_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid);
-static gboolean emf_busy(EMFormat *emf);
enum {
EMF_COMPLETE,
EMF_LAST_SIGNAL
@@ -74,7 +72,7 @@ static gpointer parent_class;
static guint signals[EMF_LAST_SIGNAL];
static void
-emf_free_cache(struct _EMFormatCache *efc)
+emf_free_cache (EMFormatCache *efc)
{
if (efc->valid)
camel_cipher_validity_free(efc->valid);
@@ -83,10 +81,10 @@ emf_free_cache(struct _EMFormatCache *efc)
g_free(efc);
}
-static struct _EMFormatCache *
+static EMFormatCache *
emf_insert_cache(EMFormat *emf, const gchar *partid)
{
- struct _EMFormatCache *new;
+ EMFormatCache *new;
new = g_malloc0(sizeof(*new)+strlen(partid));
strcpy(new->partid, partid);
@@ -96,6 +94,21 @@ emf_insert_cache(EMFormat *emf, const gchar *partid)
}
static void
+emf_clone_inlines (gpointer key,
+ EMFormatCache *emfc,
+ EMFormat *emf)
+{
+ EMFormatCache *new;
+
+ new = emf_insert_cache (emf, emfc->partid);
+ new->state = emfc->state;
+ if (emfc->valid != NULL)
+ new->valid = camel_cipher_validity_clone (emfc->valid);
+ if (emfc->secured != NULL)
+ new->secured = g_object_ref (emfc->secured);
+}
+
+static void
emf_finalize (GObject *object)
{
EMFormat *emf = EM_FORMAT (object);
@@ -117,6 +130,123 @@ emf_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
+static const EMFormatHandler *
+emf_find_handler (EMFormat *emf,
+ const gchar *mime_type)
+{
+ EMFormatClass *class = EM_FORMAT_GET_CLASS (emf);
+
+ return g_hash_table_lookup (class->type_handlers, mime_type);
+}
+
+static void
+emf_format_clone (EMFormat *emf,
+ CamelFolder *folder,
+ const gchar *uid,
+ CamelMimeMessage *msg,
+ EMFormat *emfsource)
+{
+ em_format_clear_puri_tree (emf);
+
+ if (emf != emfsource) {
+ g_hash_table_remove_all(emf->inline_table);
+ if (emfsource) {
+ GList *link;
+
+ /* We clone the current state here */
+ g_hash_table_foreach (
+ emfsource->inline_table,
+ (GHFunc) emf_clone_inlines, emf);
+ emf->mode = emfsource->mode;
+ g_free(emf->charset);
+ emf->charset = g_strdup(emfsource->charset);
+ g_free (emf->default_charset);
+ emf->default_charset = g_strdup (emfsource->default_charset);
+
+ em_format_clear_headers(emf);
+
+ link = g_queue_peek_head_link (&emfsource->header_list);
+ while (link != NULL) {
+ struct _EMFormatHeader *h = link->data;
+ em_format_add_header (emf, h->name, h->flags);
+ link = g_list_next (link);
+ }
+ }
+ }
+
+ /* what a mess */
+ if (folder != emf->folder) {
+ if (emf->folder)
+ g_object_unref(emf->folder);
+ if (folder)
+ g_object_ref(folder);
+ emf->folder = folder;
+ }
+
+ if (uid != emf->uid) {
+ g_free(emf->uid);
+ emf->uid = g_strdup(uid);
+ }
+
+ if (msg != emf->message) {
+ if (emf->message)
+ g_object_unref(emf->message);
+ if (msg)
+ g_object_ref(msg);
+ emf->message = msg;
+ }
+
+ g_string_truncate(emf->part_id, 0);
+ if (folder != NULL)
+ /* TODO build some string based on the folder name/location? */
+ g_string_append_printf(emf->part_id, ".%p", (gpointer) folder);
+ if (uid != NULL)
+ g_string_append_printf(emf->part_id, ".%s", uid);
+}
+
+static gboolean
+emf_format_secure (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ CamelCipherValidity *valid,
+ GError **error)
+{
+ CamelCipherValidity *save = emf->valid_parent;
+ gboolean success;
+ gint len;
+
+ /* Note that this also requires support from higher up in the
+ * class chain.
+ *
+ * - Validity needs to be cleared when you start output.
+ * - also needs to be cleared (but saved) whenever you
+ * start a new message. */
+
+ if (emf->valid == NULL) {
+ emf->valid = valid;
+ } else {
+ camel_dlist_addtail(&emf->valid_parent->children, (CamelDListNode *)valid);
+ camel_cipher_validity_envelope(emf->valid_parent, valid);
+ }
+
+ emf->valid_parent = valid;
+
+ len = emf->part_id->len;
+ g_string_append_printf (emf->part_id, ".secured");
+ success = em_format_part (emf, stream, part, error);
+ g_string_truncate (emf->part_id, len);
+
+ emf->valid_parent = save;
+
+ return success;
+}
+
+static gboolean
+emf_busy (EMFormat *emf)
+{
+ return FALSE;
+}
+
static void
emf_base_init (EMFormatClass *class)
{
@@ -306,23 +436,6 @@ em_format_find_handler (EMFormat *emf,
}
/**
- * em_format_find_handler:
- * @emf:
- * @mime_type:
- *
- * Find a format handler by @mime_type.
- *
- * Return value: NULL if no handler is available.
- **/
-static const EMFormatHandler *
-emf_find_handler(EMFormat *emf, const gchar *mime_type)
-{
- EMFormatClass *emfc = (EMFormatClass *)G_OBJECT_GET_CLASS(emf);
-
- return g_hash_table_lookup(emfc->type_handlers, mime_type);
-}
-
-/**
* em_format_fallback_handler:
* @emf:
* @mime_type:
@@ -610,13 +723,18 @@ em_format_clear_puri_tree(EMFormat *emf)
}
/* use mime_type == NULL to force showing as application/octet-stream */
-void
-em_format_part_as(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const gchar *mime_type)
+gboolean
+em_format_part_as (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const gchar *mime_type,
+ GError **error)
{
const EMFormatHandler *handle = NULL;
const gchar *snoop_save = emf->snoop_mime_type, *tmp;
CamelURL *base_save = emf->base, *base = NULL;
gchar *basestr = NULL;
+ gboolean success = TRUE;
d(printf("format_part_as()\n"));
@@ -659,7 +777,8 @@ em_format_part_as(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const
d(printf("running handler for type '%s'\n", mime_type));
if (is_fallback)
camel_object_meta_set (part, "EMF-Fallback", "1");
- handle->handler(emf, stream, part, handle);
+ success = handle->handler (
+ emf, stream, part, handle, error);
if (is_fallback)
camel_object_meta_set (part, "EMF-Fallback", NULL);
goto finish;
@@ -669,134 +788,42 @@ em_format_part_as(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const
mime_type = "application/octet-stream";
}
- ((EMFormatClass *)G_OBJECT_GET_CLASS(emf))->format_attachment(emf, stream, part, mime_type, handle);
+ return EM_FORMAT_GET_CLASS (emf)->format_attachment (
+ emf, stream, part, mime_type, handle, error);
+
finish:
emf->base = base_save;
emf->snoop_mime_type = snoop_save;
if (base)
camel_url_free(base);
-}
-void
-em_format_part(EMFormat *emf, CamelStream *stream, CamelMimePart *part)
-{
- gchar *mime_type;
- CamelDataWrapper *dw;
-
- dw = camel_medium_get_content((CamelMedium *)part);
- mime_type = camel_data_wrapper_get_mime_type(dw);
- if (mime_type) {
- camel_strdown(mime_type);
- em_format_part_as(emf, stream, part, mime_type);
- g_free(mime_type);
- } else
- em_format_part_as(emf, stream, part, "text/plain");
-}
-
-static void
-emf_clone_inlines(gpointer key, gpointer val, gpointer data)
-{
- struct _EMFormatCache *emfc = val, *new;
-
- new = emf_insert_cache((EMFormat *)data, emfc->partid);
- new->state = emfc->state;
- if (emfc->valid)
- new->valid = camel_cipher_validity_clone(emfc->valid);
- if (emfc->secured)
- g_object_ref((new->secured = emfc->secured));
+ return success;
}
-static void
-emf_format_clone(EMFormat *emf, CamelFolder *folder, const gchar *uid, CamelMimeMessage *msg, EMFormat *emfsource)
-{
- em_format_clear_puri_tree(emf);
-
- if (emf != emfsource) {
- g_hash_table_remove_all(emf->inline_table);
- if (emfsource) {
- GList *link;
-
- /* We clone the current state here */
- g_hash_table_foreach(emfsource->inline_table, emf_clone_inlines, emf);
- emf->mode = emfsource->mode;
- g_free(emf->charset);
- emf->charset = g_strdup(emfsource->charset);
- g_free (emf->default_charset);
- emf->default_charset = g_strdup (emfsource->default_charset);
-
- em_format_clear_headers(emf);
-
- link = g_queue_peek_head_link (&emfsource->header_list);
- while (link != NULL) {
- struct _EMFormatHeader *h = link->data;
- em_format_add_header (emf, h->name, h->flags);
- link = g_list_next (link);
- }
- }
- }
-
- /* what a mess */
- if (folder != emf->folder) {
- if (emf->folder)
- g_object_unref(emf->folder);
- if (folder)
- g_object_ref(folder);
- emf->folder = folder;
- }
-
- if (uid != emf->uid) {
- g_free(emf->uid);
- emf->uid = g_strdup(uid);
- }
-
- if (msg != emf->message) {
- if (emf->message)
- g_object_unref(emf->message);
- if (msg)
- g_object_ref(msg);
- emf->message = msg;
- }
-
- g_string_truncate(emf->part_id, 0);
- if (folder != NULL)
- /* TODO build some string based on the folder name/location? */
- g_string_append_printf(emf->part_id, ".%p", (gpointer) folder);
- if (uid != NULL)
- g_string_append_printf(emf->part_id, ".%s", uid);
-}
-
-static void
-emf_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid)
+gboolean
+em_format_part (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ GError **error)
{
- CamelCipherValidity *save = emf->valid_parent;
- gint len;
+ CamelDataWrapper *wrapper;
+ gchar *mime_type;
+ gboolean success;
- /* Note that this also requires support from higher up in the class chain
- - validity needs to be cleared when you start output
- - also needs to be cleared (but saved) whenever you start a new message. */
+ wrapper = camel_medium_get_content (CAMEL_MEDIUM (part));
+ mime_type = camel_data_wrapper_get_mime_type (wrapper);
- if (emf->valid == NULL) {
- emf->valid = valid;
- } else {
- camel_dlist_addtail(&emf->valid_parent->children, (CamelDListNode *)valid);
- camel_cipher_validity_envelope(emf->valid_parent, valid);
- }
+ if (mime_type == NULL)
+ mime_type = g_strdup ("text/plain");
- emf->valid_parent = valid;
+ camel_strdown (mime_type);
- len = emf->part_id->len;
- g_string_append_printf(emf->part_id, ".secured");
- em_format_part(emf, stream, part);
- g_string_truncate(emf->part_id, len);
+ success = em_format_part_as (emf, stream, part, mime_type, error);
- emf->valid_parent = save;
-}
+ g_free (mime_type);
-static gboolean
-emf_busy(EMFormat *emf)
-{
- return FALSE;
+ return success;
}
/**
@@ -1045,7 +1072,7 @@ gint em_format_is_attachment(EMFormat *emf, CamelMimePart *part)
**/
gint em_format_is_inline(EMFormat *emf, const gchar *partid, CamelMimePart *part, const EMFormatHandler *handle)
{
- struct _EMFormatCache *emfc;
+ EMFormatCache *emfc;
const gchar *tmp;
if (handle == NULL)
@@ -1079,7 +1106,7 @@ gint em_format_is_inline(EMFormat *emf, const gchar *partid, CamelMimePart *part
**/
void em_format_set_inline(EMFormat *emf, const gchar *partid, gint state)
{
- struct _EMFormatCache *emfc;
+ EMFormatCache *emfc;
emfc = g_hash_table_lookup(emf->inline_table, partid);
if (emfc == NULL) {
@@ -1093,87 +1120,101 @@ void em_format_set_inline(EMFormat *emf, const gchar *partid, gint state)
em_format_redraw(emf);
}
-void
+gboolean
em_format_format_attachment (EMFormat *emf,
CamelStream *stream,
CamelMimePart *mime_part,
const gchar *mime_type,
- const struct _EMFormatHandler *info)
+ const struct _EMFormatHandler *info,
+ GError **error)
{
EMFormatClass *class;
- g_return_if_fail (EM_IS_FORMAT (emf));
- g_return_if_fail (CAMEL_IS_STREAM (stream));
- g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
- g_return_if_fail (mime_type != NULL);
- g_return_if_fail (info != NULL);
+ g_return_val_if_fail (EM_IS_FORMAT (emf), FALSE);
+ g_return_val_if_fail (CAMEL_IS_STREAM (stream), FALSE);
+ g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), FALSE);
+ g_return_val_if_fail (mime_type != NULL, FALSE);
+ g_return_val_if_fail (info != NULL, FALSE);
class = EM_FORMAT_GET_CLASS (emf);
- g_return_if_fail (class->format_attachment != NULL);
- class->format_attachment (emf, stream, mime_part, mime_type, info);
+ g_return_val_if_fail (class->format_attachment != NULL, FALSE);
+
+ return class->format_attachment (
+ emf, stream, mime_part, mime_type, info, error);
}
-void
+gboolean
em_format_format_error (EMFormat *emf,
CamelStream *stream,
+ GError **error,
const gchar *format,
...)
{
EMFormatClass *class;
gchar *errmsg;
va_list ap;
+ gboolean success;
- g_return_if_fail (EM_IS_FORMAT (emf));
- g_return_if_fail (CAMEL_IS_STREAM (stream));
- g_return_if_fail (format != NULL);
+ g_return_val_if_fail (EM_IS_FORMAT (emf), FALSE);
+ g_return_val_if_fail (CAMEL_IS_STREAM (stream), FALSE);
+ g_return_val_if_fail (format != NULL, FALSE);
class = EM_FORMAT_GET_CLASS (emf);
- g_return_if_fail (class->format_error != NULL);
+ g_return_val_if_fail (class->format_error != NULL, FALSE);
va_start (ap, format);
errmsg = g_strdup_vprintf (format, ap);
- class->format_error (emf, stream, errmsg);
+ success = class->format_error (emf, stream, errmsg, error);
g_free (errmsg);
va_end (ap);
+
+ return success;
}
-void
+gboolean
em_format_format_secure (EMFormat *emf,
CamelStream *stream,
CamelMimePart *mime_part,
- CamelCipherValidity *valid)
+ CamelCipherValidity *valid,
+ GError **error)
{
EMFormatClass *class;
+ gboolean success;
- g_return_if_fail (EM_IS_FORMAT (emf));
- g_return_if_fail (CAMEL_IS_STREAM (stream));
- g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
- g_return_if_fail (valid != NULL);
+ g_return_val_if_fail (EM_IS_FORMAT (emf), FALSE);
+ g_return_val_if_fail (CAMEL_IS_STREAM (stream), FALSE);
+ g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), FALSE);
+ g_return_val_if_fail (valid != NULL, FALSE);
class = EM_FORMAT_GET_CLASS (emf);
- g_return_if_fail (class->format_secure != NULL);
- class->format_secure (emf, stream, mime_part, valid);
+ g_return_val_if_fail (class->format_secure != NULL, FALSE);
+
+ success = class->format_secure (emf, stream, mime_part, valid, error);
if (emf->valid_parent == NULL && emf->valid != NULL) {
camel_cipher_validity_free (emf->valid);
emf->valid = NULL;
}
+
+ return success;
}
-void
+gboolean
em_format_format_source (EMFormat *emf,
CamelStream *stream,
- CamelMimePart *mime_part)
+ CamelMimePart *mime_part,
+ GError **error)
{
EMFormatClass *class;
- g_return_if_fail (EM_IS_FORMAT (emf));
- g_return_if_fail (CAMEL_IS_STREAM (stream));
- g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+ g_return_val_if_fail (EM_IS_FORMAT (emf), FALSE);
+ g_return_val_if_fail (CAMEL_IS_STREAM (stream), FALSE);
+ g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), FALSE);
class = EM_FORMAT_GET_CLASS (emf);
- g_return_if_fail (class->format_source != NULL);
- class->format_source (emf, stream, mime_part);
+ g_return_val_if_fail (class->format_source != NULL, FALSE);
+
+ return class->format_source (emf, stream, mime_part, error);
}
gboolean
@@ -1189,15 +1230,25 @@ em_format_busy (EMFormat *emf)
}
/* should this be virtual? */
-void
-em_format_format_content(EMFormat *emf, CamelStream *stream, CamelMimePart *part)
+gboolean
+em_format_format_content (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ GError **error)
{
- CamelDataWrapper *dw = camel_medium_get_content((CamelMedium *)part);
+ CamelDataWrapper *wrapper;
+ gssize bytes_written;
- if (camel_content_type_is (dw->mime_type, "text", "*"))
- em_format_format_text(emf, stream, (CamelDataWrapper *)part);
- else
- camel_data_wrapper_decode_to_stream(dw, stream);
+ wrapper = camel_medium_get_content (CAMEL_MEDIUM (part));
+
+ if (camel_content_type_is (wrapper->mime_type, "text", "*"))
+ return em_format_format_text (
+ emf, stream, CAMEL_DATA_WRAPPER (part), error);
+
+ bytes_written =
+ camel_data_wrapper_decode_to_stream (wrapper, stream, error);
+
+ return (bytes_written >= 0);
}
/**
@@ -1205,20 +1256,25 @@ em_format_format_content(EMFormat *emf, CamelStream *stream, CamelMimePart *part
* @emf:
* @stream: Where to write the converted text
* @part: Part whose container is to be formatted
+ * @error: return location for a #GError, or %NULL
*
* Decode/output a part's content to @stream.
**/
-void
-em_format_format_text(EMFormat *emf, CamelStream *stream, CamelDataWrapper *dw)
+gboolean
+em_format_format_text (EMFormat *emf,
+ CamelStream *stream,
+ CamelDataWrapper *dw,
+ GError **error)
{
CamelStream *filter_stream;
CamelMimeFilter *filter;
const gchar *charset = NULL;
- CamelMimeFilterWindows *windows = NULL;
+ CamelMimeFilter *windows = NULL;
CamelStream *mem_stream = NULL;
gsize size;
gsize max;
GConfClient *gconf;
+ gboolean success = TRUE;
if (emf->charset) {
charset = emf->charset;
@@ -1236,16 +1292,16 @@ em_format_format_text(EMFormat *emf, CamelStream *stream, CamelDataWrapper *dw)
filter_stream = camel_stream_filter_new (null);
g_object_unref(null);
- windows = (CamelMimeFilterWindows *)camel_mime_filter_windows_new(charset);
+ windows = camel_mime_filter_windows_new (charset);
camel_stream_filter_add (
- CAMEL_STREAM_FILTER (filter_stream),
- (CamelMimeFilter *)windows);
+ CAMEL_STREAM_FILTER (filter_stream), windows);
- camel_data_wrapper_decode_to_stream(dw, filter_stream);
- camel_stream_flush(filter_stream);
- g_object_unref(filter_stream);
+ camel_data_wrapper_decode_to_stream (dw, filter_stream, NULL);
+ camel_stream_flush (filter_stream, NULL);
+ g_object_unref (filter_stream);
- charset = camel_mime_filter_windows_real_charset (windows);
+ charset = camel_mime_filter_windows_real_charset (
+ CAMEL_MIME_FILTER_WINDOWS (windows));
} else if (charset == NULL) {
charset = emf->default_charset;
}
@@ -1269,20 +1325,27 @@ em_format_format_text(EMFormat *emf, CamelStream *stream, CamelDataWrapper *dw)
}
g_object_unref (gconf);
- size = camel_data_wrapper_decode_to_stream(emf->mode == EM_FORMAT_SOURCE ? (CamelDataWrapper *)dw: camel_medium_get_content((CamelMedium *)dw), filter_stream);
- camel_stream_flush (filter_stream);
+ size = camel_data_wrapper_decode_to_stream (
+ emf->mode == EM_FORMAT_SOURCE ? dw :
+ camel_medium_get_content (CAMEL_MEDIUM (dw)),
+ filter_stream, NULL);
+ camel_stream_flush (filter_stream, NULL);
g_object_unref (filter_stream);
- camel_stream_reset (mem_stream);
+ camel_stream_reset (mem_stream, NULL);
if (max == -1 || size == -1 || size < (max * 1024) || emf->composer) {
- camel_stream_write_to_stream(mem_stream, (CamelStream *)stream);
- camel_stream_flush((CamelStream *)stream);
+ success = camel_stream_write_to_stream (
+ mem_stream, stream, error);
+ camel_stream_flush (stream, NULL);
} else {
- ((EMFormatClass *)G_OBJECT_GET_CLASS(emf))->format_optional(emf, stream, (CamelMimePart *)dw, mem_stream);
+ success = EM_FORMAT_GET_CLASS (emf)->format_optional (
+ emf, stream, CAMEL_MIME_PART (dw), mem_stream, error);
}
if (windows)
- g_object_unref(windows);
+ g_object_unref (windows);
+
+ return success;
}
/**
@@ -1336,119 +1399,155 @@ add_validity_found (EMFormat *emf, CamelCipherValidity *valid)
/* ********************************************************************** */
#ifdef ENABLE_SMIME
-static void
-emf_application_xpkcs7mime(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emf_application_xpkcs7mime (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
CamelCipherContext *context;
CamelMimePart *opart;
CamelCipherValidity *valid;
- struct _EMFormatCache *emfc;
- GError *error = NULL;
+ EMFormatCache *emfc;
+ gboolean success = TRUE;
/* should this perhaps run off a key of ".secured" ? */
emfc = g_hash_table_lookup(emf->inline_table, emf->part_id->str);
- if (emfc && emfc->valid) {
- em_format_format_secure(emf, stream, emfc->secured, camel_cipher_validity_clone(emfc->valid));
- return;
- }
+
+ if (emfc != NULL && emfc->valid)
+ success = em_format_format_secure (
+ emf, stream, emfc->secured,
+ camel_cipher_validity_clone (emfc->valid), error);
+
+ if (!success)
+ return FALSE;
context = camel_smime_context_new(emf->session);
- emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_ENCRYPTED | EM_FORMAT_VALIDITY_FOUND_SMIME;
+ emf->validity_found |=
+ EM_FORMAT_VALIDITY_FOUND_ENCRYPTED |
+ EM_FORMAT_VALIDITY_FOUND_SMIME;
- opart = camel_mime_part_new();
- valid = camel_cipher_decrypt(context, part, opart, &error);
+ opart = camel_mime_part_new ();
+ valid = camel_cipher_decrypt (context, part, opart, error);
if (valid == NULL) {
- em_format_format_error (
- emf, stream,
- _("Could not parse S/MIME message: %s"),
- error->message);
- em_format_part_as(emf, stream, part, NULL);
- g_error_free (error);
+ g_prefix_error (error, _("Could not parse S/MIME message: "));
+ success = FALSE;
+ goto exit;
} else {
if (emfc == NULL)
emfc = emf_insert_cache(emf, emf->part_id->str);
emfc->valid = camel_cipher_validity_clone(valid);
- g_object_ref((emfc->secured = opart));
+ emfc->secured = g_object_ref (opart);
add_validity_found (emf, valid);
- em_format_format_secure(emf, stream, opart, valid);
+
+ success = em_format_format_secure (
+ emf, stream, opart, valid, error);
}
+exit:
g_object_unref(opart);
g_object_unref(context);
+
+ return success;
}
#endif
/* RFC 1740 */
-static void
-emf_multipart_appledouble(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emf_multipart_appledouble (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
- CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content((CamelMedium *)part);
+ CamelMultipart *multipart;
CamelMimePart *mime_part;
+ gboolean success;
gint len;
- if (!CAMEL_IS_MULTIPART(mp)) {
- em_format_format_source(emf, stream, part);
- return;
- }
+ multipart = (CamelMultipart *)
+ camel_medium_get_content (CAMEL_MEDIUM (part));
- mime_part = camel_multipart_get_part(mp, 1);
- if (mime_part) {
- /* try the data fork for something useful, doubtful but who knows */
+ if (!CAMEL_IS_MULTIPART (multipart))
+ return em_format_format_source (emf, stream, part, error);
+
+ mime_part = camel_multipart_get_part (multipart, 1);
+
+ if (mime_part != NULL) {
+ /* Try the data fork for something
+ * useful, doubtful but who knows. */
len = emf->part_id->len;
- g_string_append_printf(emf->part_id, ".appledouble.1");
- em_format_part(emf, stream, mime_part);
- g_string_truncate(emf->part_id, len);
+ g_string_append_printf (emf->part_id, ".appledouble.1");
+ success = em_format_part (emf, stream, mime_part, error);
+ g_string_truncate (emf->part_id, len);
} else
- em_format_format_source(emf, stream, part);
+ success = em_format_format_source (emf, stream, part, error);
+ return success;
}
/* RFC ??? */
-static void
-emf_multipart_mixed(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emf_multipart_mixed (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
- CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content((CamelMedium *)part);
- gint i, nparts, len;
+ CamelMultipart *multipart;
+ gboolean success = TRUE;
+ gint ii, nparts, len;
- if (!CAMEL_IS_MULTIPART(mp)) {
- em_format_format_source(emf, stream, part);
- return;
- }
+ multipart = (CamelMultipart *)
+ camel_medium_get_content (CAMEL_MEDIUM (part));
+
+ if (!CAMEL_IS_MULTIPART (multipart))
+ return em_format_format_source (emf, stream, part, error);
len = emf->part_id->len;
- nparts = camel_multipart_get_number(mp);
- for (i = 0; i < nparts; i++) {
- part = camel_multipart_get_part(mp, i);
- g_string_append_printf(emf->part_id, ".mixed.%d", i);
- em_format_part(emf, stream, part);
- g_string_truncate(emf->part_id, len);
+ nparts = camel_multipart_get_number (multipart);
+
+ for (ii = 0; ii < nparts && success; ii++) {
+ part = camel_multipart_get_part (multipart, ii);
+ g_string_append_printf (emf->part_id, ".mixed.%d", ii);
+ success = em_format_part (emf, stream, part, error);
+ g_string_truncate (emf->part_id, len);
}
+
+ return success;
}
/* RFC 1740 */
-static void
-emf_multipart_alternative(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emf_multipart_alternative (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
- CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content((CamelMedium *)part);
- gint i, nparts, bestid = 0;
+ CamelMultipart *multipart;
CamelMimePart *best = NULL;
+ gint ii, nparts, bestid = 0;
- if (!CAMEL_IS_MULTIPART(mp)) {
- em_format_format_source(emf, stream, part);
- return;
- }
+ multipart = (CamelMultipart *)
+ camel_medium_get_content (CAMEL_MEDIUM (part));
- /* as per rfc, find the last part we know how to display */
- nparts = camel_multipart_get_number(mp);
- for (i = 0; i < nparts; i++) {
+ if (!CAMEL_IS_MULTIPART (multipart))
+ return em_format_format_source (emf, stream, part, error);
+
+ /* As per RFC, find the last part we know how to display. */
+ nparts = camel_multipart_get_number (multipart);
+
+ for (ii = 0; ii < nparts; ii++) {
CamelContentType *type;
gchar *mime_type;
/* is it correct to use the passed in *part here? */
- part = camel_multipart_get_part(mp, i);
+ part = camel_multipart_get_part (multipart, ii);
if (!part || !camel_mime_part_get_content_size (part))
continue;
@@ -1464,7 +1563,7 @@ emf_multipart_alternative(EMFormat *emf, CamelStream *stream, CamelMimePart *par
if (em_format_find_handler(emf, mime_type)
|| (best == NULL && em_format_fallback_handler(emf, mime_type))) {
best = part;
- bestid = i;
+ bestid = ii;
}
g_free(mime_type);
@@ -1472,104 +1571,140 @@ emf_multipart_alternative(EMFormat *emf, CamelStream *stream, CamelMimePart *par
if (best) {
gint len = emf->part_id->len;
+ gboolean success;
- g_string_append_printf(emf->part_id, ".alternative.%d", bestid);
- em_format_part(emf, stream, best);
- g_string_truncate(emf->part_id, len);
- } else
- emf_multipart_mixed(emf, stream, part, info);
+ g_string_append_printf (
+ emf->part_id, ".alternative.%d", bestid);
+ success = em_format_part (emf, stream, best, error);
+ g_string_truncate (emf->part_id, len);
+
+ return success;
+ }
+
+ return emf_multipart_mixed (emf, stream, part, info, error);
}
-static void
-emf_multipart_encrypted(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emf_multipart_encrypted (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
CamelCipherContext *context;
const gchar *protocol;
CamelMimePart *opart;
CamelCipherValidity *valid;
CamelMultipartEncrypted *mpe;
- struct _EMFormatCache *emfc;
- GError *error = NULL;
+ EMFormatCache *emfc;
+ gboolean success = TRUE;
+ GError *local_error = NULL;
/* should this perhaps run off a key of ".secured" ? */
emfc = g_hash_table_lookup(emf->inline_table, emf->part_id->str);
- if (emfc && emfc->valid) {
- em_format_format_secure(emf, stream, emfc->secured, camel_cipher_validity_clone(emfc->valid));
- return;
- }
+ if (emfc && emfc->valid)
+ return em_format_format_secure (
+ emf, stream, emfc->secured,
+ camel_cipher_validity_clone (emfc->valid), error);
+
+ mpe = (CamelMultipartEncrypted *)
+ camel_medium_get_content (CAMEL_MEDIUM (part));
- mpe = (CamelMultipartEncrypted*)camel_medium_get_content((CamelMedium *)part);
if (!CAMEL_IS_MULTIPART_ENCRYPTED(mpe)) {
- em_format_format_error(emf, stream, _("Could not parse MIME message. Displaying as source."));
- em_format_format_source(emf, stream, part);
- return;
+ em_format_format_error (
+ emf, stream, NULL, _("Could not parse "
+ "MIME message. Displaying as source."));
+ return em_format_format_source(emf, stream, part, error);
}
/* Currently we only handle RFC2015-style PGP encryption. */
protocol = camel_content_type_param(((CamelDataWrapper *)mpe)->mime_type, "protocol");
if (!protocol || g_ascii_strcasecmp (protocol, "application/pgp-encrypted") != 0) {
- em_format_format_error(emf, stream, _("Unsupported encryption type for multipart/encrypted"));
- em_format_part_as(emf, stream, part, "multipart/mixed");
- return;
+ em_format_format_error (
+ emf, stream, NULL, _("Unsupported "
+ "encryption type for multipart/encrypted"));
+ return em_format_part_as (
+ emf, stream, part, "multipart/mixed", error);
}
- emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_ENCRYPTED | EM_FORMAT_VALIDITY_FOUND_PGP;
+ emf->validity_found |=
+ EM_FORMAT_VALIDITY_FOUND_ENCRYPTED |
+ EM_FORMAT_VALIDITY_FOUND_PGP;
context = camel_gpg_context_new(emf->session);
opart = camel_mime_part_new();
- valid = camel_cipher_decrypt(context, part, opart, &error);
+ valid = camel_cipher_decrypt(context, part, opart, &local_error);
if (valid == NULL) {
em_format_format_error (
- emf, stream,
+ emf, stream, NULL,
_("Could not parse PGP/MIME message: %s"),
- error->message);
- em_format_part_as(emf, stream, part, "multipart/mixed");
- g_error_free (error);
+ local_error->message);
+ success = em_format_part_as (
+ emf, stream, part, "multipart/mixed", error);
+ g_clear_error (&local_error);
+ goto exit;
} else {
if (emfc == NULL)
emfc = emf_insert_cache(emf, emf->part_id->str);
emfc->valid = camel_cipher_validity_clone(valid);
- g_object_ref((emfc->secured = opart));
+ emfc->secured = g_object_ref (opart);
add_validity_found (emf, valid);
- em_format_format_secure(emf, stream, opart, valid);
+ success = em_format_format_secure (
+ emf, stream, opart, valid, error);
}
+exit:
/* TODO: Make sure when we finalize this part, it is zero'd out */
- g_object_unref(opart);
- g_object_unref(context);
+ g_object_unref (opart);
+ g_object_unref (context);
+
+ return success;
}
-static void
-emf_write_related(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri)
+static gboolean
+emf_write_related (EMFormat *emf,
+ CamelStream *stream,
+ EMFormatPURI *puri,
+ GError **error)
{
- em_format_format_content(emf, stream, puri->part);
- camel_stream_close(stream);
+ gboolean success;
+
+ success = em_format_format_content (emf, stream, puri->part, error);
+ camel_stream_close (stream, NULL);
+
+ return success;
}
/* RFC 2387 */
-static void
-emf_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emf_multipart_related (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
- CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content((CamelMedium *)part);
+ CamelMultipart *mp;
CamelMimePart *body_part, *display_part = NULL;
CamelContentType *content_type;
const gchar *start;
gint i, nparts, partidlen, displayid = 0;
gchar *oldpartid;
GList *link;
+ gboolean success;
- if (!CAMEL_IS_MULTIPART(mp)) {
- em_format_format_source(emf, stream, part);
- return;
- }
+ mp = (CamelMultipart *)
+ camel_medium_get_content (CAMEL_MEDIUM (part));
+
+ if (!CAMEL_IS_MULTIPART (mp))
+ return em_format_format_source(emf, stream, part, error);
/* FIXME: put this stuff in a shared function */
- nparts = camel_multipart_get_number(mp);
- content_type = camel_mime_part_get_content_type(part);
+ nparts = camel_multipart_get_number (mp);
+ content_type = camel_mime_part_get_content_type (part);
start = camel_content_type_param (content_type, "start");
- if (start && strlen(start)>2) {
+ if (start && strlen(start) > 2) {
gint len;
const gchar *cid;
@@ -1591,12 +1726,10 @@ emf_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
display_part = camel_multipart_get_part(mp, 0);
}
- if (display_part == NULL) {
- emf_multipart_mixed(emf, stream, part, info);
- return;
- }
+ if (display_part == NULL)
+ return emf_multipart_mixed (emf, stream, part, info, error);
- em_format_push_level(emf);
+ em_format_push_level (emf);
oldpartid = g_strdup(emf->part_id->str);
partidlen = emf->part_id->len;
@@ -1616,20 +1749,25 @@ emf_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
}
g_string_append_printf(emf->part_id, ".related.%d", displayid);
- em_format_part(emf, stream, display_part);
- g_string_truncate(emf->part_id, partidlen);
- camel_stream_flush(stream);
+ success = em_format_part(emf, stream, display_part, error);
+ g_string_truncate (emf->part_id, partidlen);
+ camel_stream_flush (stream, NULL);
+
+ if (!success)
+ goto exit;
link = g_queue_peek_head_link (emf->pending_uri_level->data);
- while (link && link->next != NULL) {
+ while (link && link->next != NULL && success) {
EMFormatPURI *puri = link->data;
if (puri->use_count == 0) {
d(printf("part '%s' '%s' used '%d'\n", puri->uri?puri->uri:"", puri->cid, puri->use_count));
if (puri->func == emf_write_related) {
- g_string_printf(emf->part_id, "%s", puri->part_id);
- em_format_part(emf, stream, puri->part);
+ g_string_printf (
+ emf->part_id, "%s", puri->part_id);
+ success = em_format_part (
+ emf, stream, puri->part, error);
} else {
d(printf("unreferenced uri generated by format code: %s\n", puri->uri?puri->uri:puri->cid));
}
@@ -1638,33 +1776,46 @@ emf_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
link = g_list_next (link);
}
- g_string_printf(emf->part_id, "%s", oldpartid);
- g_free(oldpartid);
+ g_string_printf (emf->part_id, "%s", oldpartid);
+ g_free (oldpartid);
+
+exit:
+ em_format_pull_level (emf);
- em_format_pull_level(emf);
+ return success;
}
-static void
-emf_multipart_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emf_multipart_signed (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
CamelMimePart *cpart;
CamelMultipartSigned *mps;
CamelCipherContext *cipher = NULL;
- struct _EMFormatCache *emfc;
+ CamelCipherValidity *valid;
+ EMFormatCache *emfc;
+ gboolean success;
+ GError *local_error = NULL;
/* should this perhaps run off a key of ".secured" ? */
emfc = g_hash_table_lookup(emf->inline_table, emf->part_id->str);
- if (emfc && emfc->valid) {
- em_format_format_secure(emf, stream, emfc->secured, camel_cipher_validity_clone(emfc->valid));
- return;
- }
+ if (emfc && emfc->valid)
+ return em_format_format_secure (
+ emf, stream, emfc->secured,
+ camel_cipher_validity_clone (emfc->valid), error);
+
+ mps = (CamelMultipartSigned *)
+ camel_medium_get_content (CAMEL_MEDIUM (part));
- mps = (CamelMultipartSigned *)camel_medium_get_content((CamelMedium *)part);
if (!CAMEL_IS_MULTIPART_SIGNED(mps)
|| (cpart = camel_multipart_get_part((CamelMultipart *)mps, CAMEL_MULTIPART_SIGNED_CONTENT)) == NULL) {
- em_format_format_error(emf, stream, _("Could not parse MIME message. Displaying as source."));
- em_format_format_source(emf, stream, part);
- return;
+ em_format_format_error (
+ emf, stream, NULL, _("Could not parse "
+ "MIME message. Displaying as source."));
+ return em_format_format_source(emf, stream, part, error);
}
/* FIXME: Should be done via a plugin interface */
@@ -1686,49 +1837,56 @@ emf_multipart_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *part, co
emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_SIGNED;
if (cipher == NULL) {
- em_format_format_error(emf, stream, _("Unsupported signature format"));
- em_format_part_as(emf, stream, part, "multipart/mixed");
- } else {
- CamelCipherValidity *valid;
- GError *error = NULL;
+ em_format_format_error (
+ emf, stream, NULL, _("Unsupported signature format"));
+ return em_format_part_as (
+ emf, stream, part, "multipart/mixed", error);
+ }
- valid = camel_cipher_verify(cipher, part, &error);
- if (valid == NULL) {
+ valid = camel_cipher_verify (cipher, part, &local_error);
+ if (valid == NULL) {
+ em_format_format_error (
+ emf, stream, NULL,
+ (local_error->message != NULL) ?
+ _("Error verifying signature") :
+ _("Unknown error verifying signature"));
+ if (local_error->message != NULL)
em_format_format_error (
- emf, stream, (error->message != NULL) ?
- _("Error verifying signature") :
- _("Unknown error verifying signature"));
- if (error->message != NULL)
- em_format_format_error(emf, stream, "%s", error->message);
- em_format_part_as(emf, stream, part, "multipart/mixed");
- } else {
- if (emfc == NULL)
- emfc = emf_insert_cache(emf, emf->part_id->str);
-
- emfc->valid = camel_cipher_validity_clone(valid);
- g_object_ref((emfc->secured = cpart));
+ emf, stream, NULL, "%s",
+ local_error->message);
+ success = em_format_part_as (
+ emf, stream, part, "multipart/mixed", error);
+ g_clear_error (&local_error);
+ } else {
+ if (emfc == NULL)
+ emfc = emf_insert_cache(emf, emf->part_id->str);
- add_validity_found (emf, valid);
- em_format_format_secure(emf, stream, cpart, valid);
- }
+ emfc->valid = camel_cipher_validity_clone(valid);
+ g_object_ref((emfc->secured = cpart));
- if (error != NULL)
- g_error_free (error);
- g_object_unref(cipher);
+ add_validity_found (emf, valid);
+ success = em_format_format_secure (
+ emf, stream, cpart, valid, error);
}
+
+ g_object_unref (cipher);
+
+ return success;
}
/* RFC 4155 */
-static void
+static gboolean
emf_application_mbox (EMFormat *emf,
CamelStream *stream,
CamelMimePart *mime_part,
- const EMFormatHandler *info)
+ const EMFormatHandler *info,
+ GError **error)
{
const EMFormatHandler *handle;
CamelMimeParser *parser;
CamelStream *mem_stream;
camel_mime_parser_state_t state;
+ gboolean success = TRUE;
/* Extract messages from the application/mbox part and
* render them as a flat list of messages. */
@@ -1745,34 +1903,36 @@ emf_application_mbox (EMFormat *emf,
* to a folder? */
handle = em_format_find_handler (emf, "x-evolution/message/rfc822");
- g_return_if_fail (handle != NULL);
+ g_return_val_if_fail (handle != NULL, FALSE);
parser = camel_mime_parser_new ();
camel_mime_parser_scan_from (parser, TRUE);
mem_stream = camel_stream_mem_new ();
camel_data_wrapper_decode_to_stream (
- CAMEL_DATA_WRAPPER (mime_part), mem_stream);
+ CAMEL_DATA_WRAPPER (mime_part), mem_stream, NULL);
camel_seekable_stream_seek (
- CAMEL_SEEKABLE_STREAM (mem_stream), 0, CAMEL_STREAM_SET);
- camel_mime_parser_init_with_stream (parser, mem_stream);
+ CAMEL_SEEKABLE_STREAM (mem_stream),
+ 0, CAMEL_STREAM_SET, NULL);
+ camel_mime_parser_init_with_stream (parser, mem_stream, NULL);
g_object_unref (mem_stream);
/* Extract messages from the mbox. */
state = camel_mime_parser_step (parser, NULL, NULL);
- while (state == CAMEL_MIME_PARSER_STATE_FROM) {
+ while (state == CAMEL_MIME_PARSER_STATE_FROM && success) {
CamelMimeMessage *message;
message = camel_mime_message_new ();
mime_part = CAMEL_MIME_PART (message);
- if (camel_mime_part_construct_from_parser (mime_part, parser) == -1) {
+ if (camel_mime_part_construct_from_parser (mime_part, parser, NULL) == -1) {
g_object_unref (message);
break;
}
/* Render the message. */
- handle->handler (emf, stream, mime_part, handle);
+ success = handle->handler (
+ emf, stream, mime_part, handle, error);
g_object_unref (message);
@@ -1783,38 +1943,59 @@ emf_application_mbox (EMFormat *emf,
}
g_object_unref (parser);
+
+ return success;
}
-static void
-emf_message_rfc822(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emf_message_rfc822 (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
- CamelDataWrapper *dw = camel_medium_get_content((CamelMedium *)part);
+ CamelDataWrapper *dw;
const EMFormatHandler *handle;
+ gboolean success;
gint len;
- if (!CAMEL_IS_MIME_MESSAGE(dw)) {
- em_format_format_source(emf, stream, part);
- return;
- }
+ dw = camel_medium_get_content (CAMEL_MEDIUM (part));
+
+ if (!CAMEL_IS_MIME_MESSAGE (dw))
+ return em_format_format_source (emf, stream, part, error);
len = emf->part_id->len;
- g_string_append_printf(emf->part_id, ".rfc822");
+ g_string_append_printf (emf->part_id, ".rfc822");
+
+ handle = em_format_find_handler (emf, "x-evolution/message/rfc822");
+ g_return_val_if_fail (handle != NULL, FALSE);
- handle = em_format_find_handler(emf, "x-evolution/message/rfc822");
- if (handle)
- handle->handler(emf, stream, (CamelMimePart *)dw, handle);
+ success = handle->handler (
+ emf, stream, CAMEL_MIME_PART (dw), handle, error);
- g_string_truncate(emf->part_id, len);
+ g_string_truncate (emf->part_id, len);
+
+ return success;
}
-static void
-emf_message_deliverystatus(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emf_message_deliverystatus (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
- em_format_format_text(emf, stream, (CamelDataWrapper *)part);
+ CamelDataWrapper *wrapper = CAMEL_DATA_WRAPPER (part);
+
+ return em_format_format_text (emf, stream, wrapper, error);
}
-static void
-emf_inlinepgp_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart, EMFormatHandler *info)
+static gboolean
+emf_inlinepgp_signed (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *ipart,
+ EMFormatHandler *info,
+ GError **error)
{
CamelStream *filtered_stream;
CamelMimeFilterPgp *pgp_filter;
@@ -1825,27 +2006,33 @@ emf_inlinepgp_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart, E
CamelMimePart *opart;
CamelStream *ostream;
gchar *type;
- GError *error = NULL;
+ gboolean success;
+ GError *local_error = NULL;
- if (!ipart) {
- em_format_format_error(emf, stream, _("Unknown error verifying signature"));
- return;
- }
+ if (ipart == NULL)
+ return em_format_format_error (
+ emf, stream, NULL,
+ _("Unknown error verifying signature"));
- emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_SIGNED | EM_FORMAT_VALIDITY_FOUND_PGP;
+ emf->validity_found |=
+ EM_FORMAT_VALIDITY_FOUND_SIGNED |
+ EM_FORMAT_VALIDITY_FOUND_PGP;
cipher = camel_gpg_context_new(emf->session);
/* Verify the signature of the message */
- valid = camel_cipher_verify(cipher, ipart, &error);
+ valid = camel_cipher_verify(cipher, ipart, &local_error);
if (!valid) {
em_format_format_error (
- emf, stream, _("Error verifying signature: %s"),
- error->message);
- em_format_format_source(emf, stream, ipart);
+ emf, stream, NULL,
+ _("Error verifying signature: %s"),
+ local_error->message);
+ success = em_format_format_source (
+ emf, stream, ipart, error);
/* I think this will loop: em_format_part_as(emf, stream, part, "text/plain"); */
- g_error_free (error);
- g_object_unref(cipher);
- return;
+ g_clear_error (&local_error);
+ g_object_unref (cipher);
+
+ return success;
}
/* Setup output stream */
@@ -1860,10 +2047,10 @@ emf_inlinepgp_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart, E
g_object_unref(pgp_filter);
/* Pass through the filters that have been setup */
- dw = camel_medium_get_content((CamelMedium *)ipart);
- camel_data_wrapper_decode_to_stream(dw, filtered_stream);
- camel_stream_flush(filtered_stream);
- g_object_unref(filtered_stream);
+ dw = camel_medium_get_content (CAMEL_MEDIUM (ipart));
+ camel_data_wrapper_decode_to_stream (dw, filtered_stream, NULL);
+ camel_stream_flush (filtered_stream, NULL);
+ g_object_unref (filtered_stream);
/* Create a new text/plain MIME part containing the signed content preserving the original part's Content-Type params */
content_type = camel_mime_part_get_content_type (ipart);
@@ -1879,7 +2066,7 @@ emf_inlinepgp_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart, E
camel_content_type_unref (content_type);
dw = camel_data_wrapper_new ();
- camel_data_wrapper_construct_from_stream (dw, ostream);
+ camel_data_wrapper_construct_from_stream (dw, ostream, NULL);
camel_data_wrapper_set_mime_type (dw, type);
g_free (type);
@@ -1889,45 +2076,55 @@ emf_inlinepgp_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart, E
add_validity_found (emf, valid);
/* Pass it off to the real formatter */
- em_format_format_secure(emf, stream, opart, valid);
+ success = em_format_format_secure(emf, stream, opart, valid, error);
/* Clean Up */
- g_object_unref(dw);
- g_object_unref(opart);
- g_object_unref(ostream);
- g_object_unref(cipher);
+ g_object_unref (dw);
+ g_object_unref (opart);
+ g_object_unref (ostream);
+ g_object_unref (cipher);
+
+ return success;
}
-static void
-emf_inlinepgp_encrypted(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart, EMFormatHandler *info)
+static gboolean
+emf_inlinepgp_encrypted (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *ipart,
+ EMFormatHandler *info,
+ GError **error)
{
CamelCipherContext *cipher;
CamelCipherValidity *valid;
CamelMimePart *opart;
CamelDataWrapper *dw;
gchar *mime_type;
- GError *error = NULL;
+ gboolean success;
+ GError *local_error = NULL;
- emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_ENCRYPTED | EM_FORMAT_VALIDITY_FOUND_PGP;
+ emf->validity_found |=
+ EM_FORMAT_VALIDITY_FOUND_ENCRYPTED |
+ EM_FORMAT_VALIDITY_FOUND_PGP;
cipher = camel_gpg_context_new(emf->session);
opart = camel_mime_part_new();
/* Decrypt the message */
- valid = camel_cipher_decrypt (cipher, ipart, opart, &error);
+ valid = camel_cipher_decrypt (cipher, ipart, opart, &local_error);
if (!valid) {
em_format_format_error (
- emf, stream,
+ emf, stream, NULL,
_("Could not parse PGP message: %s"),
- error->message);
- em_format_format_source(emf, stream, ipart);
+ local_error->message);
+ success = em_format_format_source(emf, stream, ipart, error);
/* I think this will loop: em_format_part_as(emf, stream, part, "text/plain"); */
- g_error_free (error);
- g_object_unref(cipher);
- g_object_unref(opart);
- return;
+ g_clear_error (&local_error);
+ g_object_unref (cipher);
+ g_object_unref (opart);
+
+ return success;
}
- dw = camel_medium_get_content ((CamelMedium *)opart);
+ dw = camel_medium_get_content (CAMEL_MEDIUM (opart));
mime_type = camel_data_wrapper_get_mime_type (dw);
/* this ensures to show the 'opart' as inlined, if possible */
@@ -1941,12 +2138,15 @@ emf_inlinepgp_encrypted(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart
g_free (mime_type);
add_validity_found (emf, valid);
+
/* Pass it off to the real formatter */
- em_format_format_secure(emf, stream, opart, valid);
+ success = em_format_format_secure(emf, stream, opart, valid, error);
/* Clean Up */
- g_object_unref(opart);
+ g_object_unref (opart);
g_object_unref (cipher);
+
+ return success;
}
static EMFormatHandler type_builtin_table[] = {
@@ -2015,7 +2215,7 @@ em_format_snoop_type (CamelMimePart *part)
buffer = g_byte_array_new ();
stream = camel_stream_mem_new_with_byte_array (buffer);
- if (camel_data_wrapper_decode_to_stream(dw, stream) > 0) {
+ if (camel_data_wrapper_decode_to_stream (dw, stream, NULL) > 0) {
gchar *ct = g_content_type_guess (filename, buffer->data, buffer->len, NULL);
if (ct)
diff --git a/em-format/em-format.h b/em-format/em-format.h
index beea159..ede690f 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -59,7 +59,11 @@ typedef struct _EMFormatPrivate EMFormatPrivate;
typedef struct _EMFormatHandler EMFormatHandler;
typedef struct _EMFormatHeader EMFormatHeader;
-typedef void (*EMFormatFunc) (EMFormat *md, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info);
+typedef gboolean (*EMFormatFunc) (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error);
typedef enum _em_format_mode_t {
EM_FORMAT_NORMAL,
@@ -100,7 +104,10 @@ enum _em_format_handler_t {
};
typedef struct _EMFormatPURI EMFormatPURI;
-typedef void (*EMFormatPURIFunc)(EMFormat *md, CamelStream *stream, EMFormatPURI *puri);
+typedef gboolean (*EMFormatPURIFunc) (EMFormat *emf,
+ CamelStream *stream,
+ EMFormatPURI *puri,
+ GError **error);
/**
* struct _EMFormatPURI - Pending URI object.
@@ -235,21 +242,41 @@ struct _EMFormatClass {
void (*format_clone)(EMFormat *, CamelFolder *, const gchar *uid, CamelMimeMessage *, EMFormat *);
/* some internel error/inconsistency */
- void (*format_error)(EMFormat *, CamelStream *, const gchar *msg);
+ gboolean (*format_error) (EMFormat *emf,
+ CamelStream *stream,
+ const gchar *msg,
+ GError **error);
/* use for external structured parts */
- void (*format_attachment)(EMFormat *, CamelStream *, CamelMimePart *, const gchar *mime_type, const EMFormatHandler *info);
+ gboolean (*format_attachment) (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const gchar *mime_type,
+ const EMFormatHandler *info,
+ GError **error);
/* use for unparsable content */
- void (*format_source)(EMFormat *, CamelStream *, CamelMimePart *);
+ gboolean (*format_source) (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ GError **error);
+
/* for outputing secure(d) content */
- void (*format_secure)(EMFormat *, CamelStream *, CamelMimePart *, CamelCipherValidity *);
+ gboolean (*format_secure) (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ CamelCipherValidity *valid,
+ GError **error);
/* returns true if the formatter is still busy with pending stuff */
gboolean (*busy)(EMFormat *);
/* Shows optional way to open messages */
- void (*format_optional)(EMFormat *, CamelStream *, CamelMimePart *, CamelStream* );
+ gboolean (*format_optional) (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ CamelStream *mem_stream,
+ GError **error);
/* signals */
/* complete, alternative to polling busy, for asynchronous work */
@@ -329,42 +356,50 @@ void em_format_format (EMFormat *emf,
const gchar *uid,
CamelMimeMessage *message);
void em_format_redraw (EMFormat *emf);
-void em_format_format_attachment (EMFormat *emf,
+gboolean em_format_format_attachment (EMFormat *emf,
CamelStream *stream,
CamelMimePart *mime_part,
const gchar *mime_type,
- const EMFormatHandler *info);
-void em_format_format_error (EMFormat *emf,
+ const EMFormatHandler *info,
+ GError **error);
+gboolean em_format_format_error (EMFormat *emf,
CamelStream *stream,
+ GError **error,
const gchar *format,
- ...) G_GNUC_PRINTF (3, 4);
-void em_format_format_secure (EMFormat *emf,
+ ...) G_GNUC_PRINTF (4, 5);
+gboolean em_format_format_secure (EMFormat *emf,
CamelStream *stream,
CamelMimePart *mime_part,
- CamelCipherValidity *valid);
-void em_format_format_source (EMFormat *emf,
+ CamelCipherValidity *valid,
+ GError **error);
+gboolean em_format_format_source (EMFormat *emf,
CamelStream *stream,
- CamelMimePart *mime_part);
+ CamelMimePart *mime_part,
+ GError **error);
gboolean em_format_busy (EMFormat *emf);
/* raw content only */
-void em_format_format_content (EMFormat *emf,
+gboolean em_format_format_content (EMFormat *emf,
CamelStream *stream,
- CamelMimePart *part);
+ CamelMimePart *part,
+ GError **error);
/* raw content text parts - should this just be checked/done by above? */
-void em_format_format_text (EMFormat *emf,
+gboolean em_format_format_text (EMFormat *emf,
CamelStream *stream,
- CamelDataWrapper *part);
+ CamelDataWrapper *part,
+ GError **error);
-void em_format_part_as (EMFormat *emf,
+gboolean em_format_part_as (EMFormat *emf,
CamelStream *stream,
CamelMimePart *part,
- const gchar *mime_type);
-void em_format_part (EMFormat *emf,
+ const gchar *mime_type,
+ GError **error);
+gboolean em_format_part (EMFormat *emf,
CamelStream *stream,
- CamelMimePart *part);
+ CamelMimePart *part,
+ GError **error);
void em_format_merge_handler (EMFormat *new,
EMFormat *old);
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 1d82d20..ebcba06 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -936,7 +936,7 @@ traverse_parts (GSList *clues, CamelMimeMessage *message, CamelDataWrapper *cont
byte_array = g_byte_array_new ();
mem = camel_stream_mem_new_with_byte_array (byte_array);
- camel_data_wrapper_decode_to_stream (content, mem);
+ camel_data_wrapper_decode_to_stream (content, mem, NULL);
str = g_strndup (
(const gchar *) byte_array->data,
@@ -945,8 +945,9 @@ traverse_parts (GSList *clues, CamelMimeMessage *message, CamelDataWrapper *cont
if (replace_variables (clues, message, &str)) {
mem = camel_stream_mem_new_with_buffer (str, strlen (str));
- camel_stream_reset (mem);
- camel_data_wrapper_construct_from_stream (content, mem);
+ camel_stream_reset (mem, NULL);
+ camel_data_wrapper_construct_from_stream (
+ content, mem, NULL);
g_object_unref (mem);
}
@@ -1563,10 +1564,10 @@ em_utils_send_receipt (CamelFolder *folder, CamelMimeMessage *message)
camel_data_wrapper_set_mime_type_field (receipt_text, type);
camel_content_type_unref (type);
stream = camel_stream_mem_new ();
- camel_stream_printf (stream,
- "Your message to %s about \"%s\" on %s has been read.",
- self_address, message_subject, message_date);
- camel_data_wrapper_construct_from_stream (receipt_text, stream);
+ camel_stream_printf (
+ stream, NULL, "Your message to %s about \"%s\" on %s "
+ "has been read.", self_address, message_subject, message_date);
+ camel_data_wrapper_construct_from_stream (receipt_text, stream, NULL);
g_object_unref (stream);
part = camel_mime_part_new ();
@@ -1588,13 +1589,14 @@ em_utils_send_receipt (CamelFolder *folder, CamelMimeMessage *message)
camel_content_type_unref (type);
stream = camel_stream_mem_new ();
- camel_stream_printf (stream,
- "Reporting-UA: %s\n"
- "Final-Recipient: %s\n"
- "Original-Message-ID: %s\n"
- "Disposition: manual-action/MDN-sent-manually; displayed\n",
- ua, recipient, message_id);
- camel_data_wrapper_construct_from_stream (receipt_data, stream);
+ camel_stream_printf (
+ stream, NULL,
+ "Reporting-UA: %s\n"
+ "Final-Recipient: %s\n"
+ "Original-Message-ID: %s\n"
+ "Disposition: manual-action/MDN-sent-manually; displayed\n",
+ ua, recipient, message_id);
+ camel_data_wrapper_construct_from_stream (receipt_data, stream, NULL);
g_object_unref (stream);
g_free (ua);
@@ -1699,9 +1701,12 @@ em_utils_forward_message_raw (CamelFolder *folder,
/* make copy of the message, because we are going to modify it */
stream = camel_stream_mem_new ();
- camel_data_wrapper_write_to_stream ((CamelDataWrapper *)message, stream);
- camel_seekable_stream_seek (CAMEL_SEEKABLE_STREAM (stream), 0, CAMEL_STREAM_SET);
- camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)forward, stream);
+ camel_data_wrapper_write_to_stream (
+ CAMEL_DATA_WRAPPER (message), stream, NULL);
+ camel_seekable_stream_seek (
+ CAMEL_SEEKABLE_STREAM (stream), 0, CAMEL_STREAM_SET, NULL);
+ camel_data_wrapper_construct_from_stream (
+ CAMEL_DATA_WRAPPER (forward), stream, NULL);
g_object_unref (stream);
/* clear previous recipients */
diff --git a/mail/em-format-hook.c b/mail/em-format-hook.c
index 31aa123..228f625 100644
--- a/mail/em-format-hook.c
+++ b/mail/em-format-hook.c
@@ -62,20 +62,28 @@ static const EPluginHookTargetKey emfh_flag_map[] = {
{ NULL }
};
-static void
-emfh_format_format(EMFormat *md, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+emfh_format_format (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
struct _EMFormatHookItem *item = (EMFormatHookItem *)info;
if (item->hook->hook.plugin->enabled) {
EMFormatHookTarget target = {
- md, stream, part, item
+ emf, stream, part, item
};
+ /* FIXME No way for plugins to report errors. */
e_plugin_invoke(item->hook->hook.plugin, item->format, &target);
+ return TRUE;
} else if (info->old) {
- info->old->handler(md, stream, part, info->old);
+ return info->old->handler(emf, stream, part, info->old, error);
}
+
+ return TRUE;
}
static void
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index 8fb063b..cf14045 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -109,7 +109,7 @@ static const gchar *smime_sign_colour[5] = {
"", " bgcolor=\"#88bb88\"", " bgcolor=\"#bb8888\"", " bgcolor=\"#e8d122\"",""
};
-static void efhd_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri);
+static gboolean efhd_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri, GError **error);
static void efhd_message_add_bar(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info);
static gboolean efhd_attachment_button (EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject);
static gboolean efhd_attachment_optional (EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *object);
@@ -395,15 +395,17 @@ efhd_format_clone (EMFormat *emf,
format_clone (emf, folder, uid, msg, src);
}
-static void
+static gboolean
efhd_format_attachment (EMFormat *emf,
CamelStream *stream,
CamelMimePart *part,
const gchar *mime_type,
- const EMFormatHandler *handle)
+ const EMFormatHandler *handle,
+ GError **error)
{
gchar *classid, *text, *html;
struct _attach_puri *info;
+ gboolean success = TRUE;
classid = g_strdup_printf ("attachment%s", emf->part_id->str);
info = (struct _attach_puri *) em_format_add_puri (
@@ -427,14 +429,15 @@ efhd_format_attachment (EMFormat *emf,
stream, EM_FORMAT_HTML_VPAD
"<table cellspacing=0 cellpadding=0><tr><td>"
"<table width=10 cellspacing=0 cellpadding=0>"
- "<tr><td></td></tr></table></td>");
+ "<tr><td></td></tr></table></td>", NULL);
camel_stream_printf (
- stream, "<td><object classid=\"%s\"></object></td>", classid);
+ stream, NULL, "<td><object classid=\"%s\"></object></td>",
+ classid);
camel_stream_write_string (
stream, "<td><table width=3 cellspacing=0 cellpadding=0>"
- "<tr><td></td></tr></table></td><td><font size=-1>");
+ "<tr><td></td></tr></table></td><td><font size=-1>", NULL);
/* output some info about it */
/* FIXME: should we look up mime_type from object again? */
@@ -442,25 +445,28 @@ efhd_format_attachment (EMFormat *emf,
html = camel_text_to_html (
text, EM_FORMAT_HTML (emf)->text_html_flags &
CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
- camel_stream_write_string (stream, html);
+ camel_stream_write_string (stream, html, NULL);
g_free (html);
g_free (text);
camel_stream_write_string (
stream, "</font></td></tr><tr></table>\n"
- EM_FORMAT_HTML_VPAD);
+ EM_FORMAT_HTML_VPAD, NULL);
if (handle && info->shown)
- handle->handler (emf, stream, part, handle);
+ success = handle->handler (emf, stream, part, handle, error);
g_free (classid);
+
+ return success;
}
-static void
+static gboolean
efhd_format_optional (EMFormat *emf,
CamelStream *fstream,
CamelMimePart *part,
- CamelStream *mstream)
+ CamelStream *mstream,
+ GError **error)
{
gchar *classid, *html;
struct _attach_puri *info;
@@ -493,7 +499,7 @@ efhd_format_optional (EMFormat *emf,
camel_stream_write_string (
stream, EM_FORMAT_HTML_VPAD
"<table cellspacing=0 cellpadding=0><tr><td>"
- "<h3><font size=-1 color=red>");
+ "<h3><font size=-1 color=red>", NULL);
html = camel_text_to_html (
_("Evolution cannot render this email as it is too "
@@ -501,33 +507,37 @@ efhd_format_optional (EMFormat *emf,
"with an external text editor."),
EM_FORMAT_HTML (emf)->text_html_flags &
CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
- camel_stream_write_string (stream, html);
+ camel_stream_write_string (stream, html, NULL);
camel_stream_write_string (
- stream, "</font></h3></td></tr></table>\n");
+ stream, "</font></h3></td></tr></table>\n", NULL);
camel_stream_write_string (
- stream, "<table cellspacing=0 cellpadding=0><tr>");
+ stream, "<table cellspacing=0 cellpadding=0><tr>", NULL);
camel_stream_printf (
- stream, "<td><object classid=\"%s\"></object>"
+ stream, NULL, "<td><object classid=\"%s\"></object>"
"</td></tr></table>", classid);
g_free(html);
camel_stream_write_string (
- stream, EM_FORMAT_HTML_VPAD);
+ stream, EM_FORMAT_HTML_VPAD, NULL);
g_free (classid);
+
+ return TRUE;
}
-static void
+static gboolean
efhd_format_secure (EMFormat *emf,
CamelStream *stream,
CamelMimePart *part,
- CamelCipherValidity *valid)
+ CamelCipherValidity *valid,
+ GError **error)
{
EMFormatClass *format_class;
format_class = g_type_class_peek (EM_TYPE_FORMAT);
- format_class->format_secure (emf, stream, part, valid);
+ if (!format_class->format_secure (emf, stream, part, valid, error))
+ return FALSE;
if (emf->valid == valid
&& (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE
@@ -536,7 +546,7 @@ efhd_format_secure (EMFormat *emf,
struct _smime_pobject *pobj;
camel_stream_printf (
- stream, "<table border=0 width=\"100%%\" "
+ stream, NULL, "<table border=0 width=\"100%%\" "
"cellpadding=3 cellspacing=0%s><tr>",
smime_sign_colour[valid->sign.status]);
@@ -549,8 +559,9 @@ efhd_format_secure (EMFormat *emf,
pobj->valid = camel_cipher_validity_clone(valid);
pobj->object.free = efhd_xpkcs7mime_free;
camel_stream_printf (
- stream, "<td valign=center><object classid=\"%s\">"
- "</object></td><td width=100%% valign=center>",
+ stream, NULL, "<td valign=center>"
+ "<object classid=\"%s\"></object>"
+ "</td><td width=100%% valign=center>",
classid);
g_free (classid);
@@ -559,8 +570,8 @@ efhd_format_secure (EMFormat *emf,
gint status;
status = valid->sign.status;
- desc = smime_sign_table[status].shortdesc;
- camel_stream_printf (stream, "%s", gettext (desc));
+ desc = gettext (smime_sign_table[status].shortdesc);
+ camel_stream_printf (stream, NULL, "%s", desc);
}
if (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE) {
@@ -568,16 +579,19 @@ efhd_format_secure (EMFormat *emf,
gint status;
if (valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE) {
- camel_stream_printf (stream, "<br>");
+ camel_stream_write_string (
+ stream, "<br>", NULL);
}
status = valid->encrypt.status;
- desc = smime_encrypt_table[status].shortdesc;
- camel_stream_printf (stream, "%s", gettext (desc));
+ desc = gettext (smime_encrypt_table[status].shortdesc);
+ camel_stream_printf (stream, NULL, "%s", desc);
}
- camel_stream_printf(stream, "</td></tr></table>");
+ camel_stream_write_string (stream, "</td></tr></table>", NULL);
}
+
+ return TRUE;
}
static void
@@ -668,22 +682,37 @@ efhd_builtin_init(EMFormatHTMLDisplayClass *efhc)
em_format_class_add_handler((EMFormatClass *)efhc, &type_builtin_table[i]);
}
-static void
-efhd_write_image(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri)
+static gboolean
+efhd_write_image (EMFormat *emf,
+ CamelStream *stream,
+ EMFormatPURI *puri,
+ GError **error)
{
- CamelDataWrapper *dw = camel_medium_get_content((CamelMedium *)puri->part);
+ CamelDataWrapper *wrapper;
+ gssize bytes_written;
/* TODO: identical to efh_write_image */
d(printf("writing image '%s'\n", puri->cid));
- camel_data_wrapper_decode_to_stream(dw, stream);
- camel_stream_close(stream);
+
+ wrapper = camel_medium_get_content (CAMEL_MEDIUM (puri->part));
+
+ bytes_written =
+ camel_data_wrapper_decode_to_stream (wrapper, stream, error);
+
+ camel_stream_close (stream, NULL);
+
+ return (bytes_written >= 0);
}
static void
-efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
+efhd_message_prefix (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ EMFormatHandler *info)
{
const gchar *flag, *comp, *due;
time_t date;
+ const gchar *icon_name;
gchar *iconpath, *due_date_str;
if (emf->folder == NULL || emf->uid == NULL
@@ -692,10 +721,18 @@ efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMF
return;
/* header displayed for message-flags in mail display */
- camel_stream_printf(stream, "<table border=1 width=\"100%%\" cellspacing=2 cellpadding=2><tr>");
+ camel_stream_printf (
+ stream, NULL, "<table border=1 width=\"100%%\" "
+ "cellspacing=2 cellpadding=2><tr>");
- comp = camel_folder_get_message_user_tag(emf->folder, emf->uid, "completed-on");
- iconpath = e_icon_factory_get_icon_filename (comp && comp[0] ? "stock_flag-for-followup-done" : "stock_flag-for-followup", GTK_ICON_SIZE_MENU);
+ comp = camel_folder_get_message_user_tag (
+ emf->folder, emf->uid, "completed-on");
+ if (comp != NULL && *comp != '\0')
+ icon_name = "stock_flag-for-followup-done";
+ else
+ icon_name = "stock_flag-for-followup";
+ iconpath = e_icon_factory_get_icon_filename (
+ icon_name, GTK_ICON_SIZE_MENU);
if (iconpath) {
CamelMimePart *iconpart;
@@ -705,19 +742,25 @@ efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMF
gchar *classid;
classid = g_strdup_printf("icon:///em-format-html-display/%s/%s", emf->part_id->str, comp&&comp[0]?"comp":"uncomp");
- camel_stream_printf(stream, "<td align=\"left\"><img src=\"%s\"></td>", classid);
- (void)em_format_add_puri(emf, sizeof(EMFormatPURI), classid, iconpart, efhd_write_image);
+ camel_stream_printf (
+ stream, NULL, "<td align=\"left\">"
+ "<img src=\"%s\"></td>", classid);
+ em_format_add_puri(emf, sizeof(EMFormatPURI), classid, iconpart, efhd_write_image);
g_free(classid);
g_object_unref(iconpart);
}
}
- camel_stream_printf(stream, "<td align=\"left\" width=\"100%%\">");
+ camel_stream_printf (
+ stream, NULL, "<td align=\"left\" width=\"100%%\">");
if (comp && comp[0]) {
date = camel_header_decode_date (comp, NULL);
- due_date_str = e_datetime_format_format ("mail", "header", DTFormatKindDateTime, date);
- camel_stream_printf (stream, "%s, %s %s", flag, _("Completed on"), due_date_str ? due_date_str : "???");
+ due_date_str = e_datetime_format_format (
+ "mail", "header", DTFormatKindDateTime, date);
+ camel_stream_printf (
+ stream, NULL, "%s, %s %s", flag, _("Completed on"),
+ due_date_str ? due_date_str : "???");
g_free (due_date_str);
} else if ((due = camel_folder_get_message_user_tag(emf->folder, emf->uid, "due-by")) != NULL && due[0]) {
time_t now;
@@ -725,16 +768,19 @@ efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMF
date = camel_header_decode_date(due, NULL);
now = time(NULL);
if (now > date)
- camel_stream_printf(stream, "<b>%s</b> ", _("Overdue:"));
+ camel_stream_printf (
+ stream, NULL, "<b>%s</b> ", _("Overdue:"));
due_date_str = e_datetime_format_format ("mail", "header", DTFormatKindDateTime, date);
/* To Translators: the "by" is part of the string, like "Follow-up by Tuesday, January 13, 2009" */
- camel_stream_printf (stream, "%s %s %s", flag, _("by"), due_date_str ? due_date_str : "???");
+ camel_stream_printf (
+ stream, NULL, "%s %s %s", flag, _("by"),
+ due_date_str ? due_date_str : "???");
} else {
- camel_stream_printf(stream, "%s", flag);
+ camel_stream_printf (stream, NULL, "%s", flag);
}
- camel_stream_printf(stream, "</td></tr></table>");
+ camel_stream_printf (stream, NULL, "</td></tr></table>");
}
/* ********************************************************************** */
@@ -826,18 +872,22 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje
return TRUE;
}
-static void
+static gboolean
efhd_attachment_frame (EMFormat *emf,
CamelStream *stream,
- EMFormatPURI *puri)
+ EMFormatPURI *puri,
+ GError **error)
{
struct _attach_puri *info = (struct _attach_puri *)puri;
+ gboolean success = TRUE;
if (info->shown)
- info->handle->handler (
- emf, stream, info->puri.part, info->handle);
+ success = info->handle->handler (
+ emf, stream, info->puri.part, info->handle, error);
+
+ camel_stream_close (stream, NULL);
- camel_stream_close (stream);
+ return success;
}
static void
@@ -903,7 +953,8 @@ efhd_message_add_bar (EMFormat *emf,
classid, part, efhd_add_bar);
camel_stream_printf (
- stream, "<td><object classid=\"%s\"></object></td>", classid);
+ stream, NULL, "<td><object classid=\"%s\">"
+ "</object></td>", classid);
}
static void
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index cc3c7d2..774635f 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -113,18 +113,36 @@ enum {
PROP_TEXT_COLOR
};
+/* FIXME: This is duplicated in em-format-html-display, should be exported or in security module */
+static const struct {
+ const gchar *icon, *shortdesc;
+} smime_sign_table[5] = {
+ { "stock_signature-bad", N_("Unsigned") },
+ { "stock_signature-ok", N_("Valid signature") },
+ { "stock_signature-bad", N_("Invalid signature") },
+ { "stock_signature", N_("Valid signature, but cannot verify sender") },
+ { "stock_signature-bad", N_("Signature exists, but need public key") },
+};
+
+static const struct {
+ const gchar *icon, *shortdesc;
+} smime_encrypt_table[4] = {
+ { "stock_lock-broken", N_("Unencrypted") },
+ { "stock_lock", N_("Encrypted, weak"),},
+ { "stock_lock-ok", N_("Encrypted") },
+ { "stock_lock-ok", N_("Encrypted, strong") },
+};
+
+static const gchar *smime_sign_colour[4] = {
+ "", " bgcolor=\"#88bb88\"", " bgcolor=\"#bb8888\"", " bgcolor=\"#e8d122\""
+};
+
static void efh_url_requested(GtkHTML *html, const gchar *url, GtkHTMLStream *handle, EMFormatHTML *efh);
static gboolean efh_object_requested(GtkHTML *html, GtkHTMLEmbedded *eb, EMFormatHTML *efh);
static void efh_gtkhtml_destroy(GtkHTML *html, EMFormatHTML *efh);
-static void efh_format_message(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info);
-
-static void efh_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid);
-
static void efh_builtin_init(EMFormatHTMLClass *efhc);
-static void efh_write_image(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri);
-
static gpointer parent_class;
static CamelDataCache *emfh_http_cache;
@@ -163,7 +181,7 @@ efh_format_exec (struct _format_msg *m)
format = EM_FORMAT (m->format);
camel_stream_printf (
- (CamelStream *)m->estream,
+ (CamelStream *)m->estream, NULL,
"<!doctype html public \"-//W3C//DTD HTML 4.0 TRANSITIONAL//EN\">\n<html>\n"
"<head>\n<meta name=\"generator\" content=\"Evolution Mail Component\">\n</head>\n"
"<body bgcolor =\"#%06x\" text=\"#%06x\" marginwidth=6 marginheight=6>\n",
@@ -179,29 +197,29 @@ efh_format_exec (struct _format_msg *m)
if (format->mode == EM_FORMAT_SOURCE) {
em_format_format_source (
format, (CamelStream *) m->estream,
- (CamelMimePart *) m->message);
+ (CamelMimePart *) m->message, NULL);
} else {
const EMFormatHandler *handle;
const gchar *mime_type;
mime_type = "x-evolution/message/prefix";
handle = em_format_find_handler (format, mime_type);
+ g_return_if_fail (handle != NULL);
- if (handle != NULL)
- handle->handler (
- format, (CamelStream *) m->estream,
- (CamelMimePart *) m->message, handle);
+ handle->handler (
+ format, (CamelStream *) m->estream,
+ (CamelMimePart *) m->message, handle, NULL);
mime_type = "x-evolution/message/rfc822";
handle = em_format_find_handler (format, mime_type);
+ g_return_if_fail (handle != NULL);
- if (handle != NULL)
- handle->handler (
- format, (CamelStream *) m->estream,
- (CamelMimePart *) m->message, handle);
+ handle->handler (
+ format, (CamelStream *) m->estream,
+ (CamelMimePart *) m->message, handle, NULL);
}
- camel_stream_flush((CamelStream *)m->estream);
+ camel_stream_flush ((CamelStream *)m->estream, NULL);
puri_level = format->pending_uri_level;
base = format->base;
@@ -241,9 +259,11 @@ efh_format_exec (struct _format_msg *m)
/* Closing this base stream can queue more jobs, so we need
to check the list again after we've finished */
d(printf("out of jobs, closing root stream\n"));
- camel_stream_write_string((CamelStream *)m->estream, "</body>\n</html>\n");
- camel_stream_close((CamelStream *)m->estream);
- g_object_unref(m->estream);
+ camel_stream_write_string (
+ CAMEL_STREAM (m->estream),
+ "</body>\n</html>\n", NULL);
+ camel_stream_close ((CamelStream *)m->estream, NULL);
+ g_object_unref (m->estream);
m->estream = NULL;
}
@@ -271,7 +291,7 @@ efh_format_free (struct _format_msg *m)
d(printf("formatter freed\n"));
g_object_unref(m->format);
if (m->estream) {
- camel_stream_close((CamelStream *)m->estream);
+ camel_stream_close((CamelStream *)m->estream, NULL);
g_object_unref(m->estream);
}
if (m->folder)
@@ -364,6 +384,25 @@ efh_format_timeout(struct _format_msg *m)
return FALSE;
}
+static gboolean
+efh_write_image (EMFormat *emf,
+ CamelStream *stream,
+ EMFormatPURI *puri,
+ GError **error)
+{
+ CamelDataWrapper *wrapper;
+ gssize bytes_written;
+
+ wrapper = camel_medium_get_content (CAMEL_MEDIUM (puri->part));
+
+ bytes_written =
+ camel_data_wrapper_decode_to_stream (wrapper, stream, error);
+
+ camel_stream_close (stream, NULL);
+
+ return (bytes_written >= 0);
+}
+
static void
efh_free_cache(struct _EMFormatHTMLCache *efhc)
{
@@ -405,6 +444,700 @@ efh_insert_cache(EMFormatHTML *efh, const gchar *partid)
}
static void
+canon_header_name (gchar *name)
+{
+ gchar *inptr = name;
+
+ /* canonicalise the header name... first letter is
+ * capitalised and any letter following a '-' also gets
+ * capitalised */
+
+ if (*inptr >= 'a' && *inptr <= 'z')
+ *inptr -= 0x20;
+
+ inptr++;
+
+ while (*inptr) {
+ if (inptr[-1] == '-' && *inptr >= 'a' && *inptr <= 'z')
+ *inptr -= 0x20;
+ else if (*inptr >= 'A' && *inptr <= 'Z')
+ *inptr += 0x20;
+
+ inptr++;
+ }
+}
+
+static gchar *
+efh_format_address (EMFormatHTML *efh,
+ GString *out,
+ struct _camel_header_address *a,
+ const gchar *field)
+{
+ guint32 flags = CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES;
+ gchar *name, *mailto, *addr;
+ gint i=0;
+ gboolean wrap = FALSE;
+ gchar *str = NULL;
+ gint limit = mail_config_get_address_count ();
+
+ if (field ) {
+ if ((!strcmp (field, _("To")) && !(efh->header_wrap_flags & EM_FORMAT_HTML_HEADER_TO))
+ || (!strcmp (field, _("Cc")) && !(efh->header_wrap_flags & EM_FORMAT_HTML_HEADER_CC))
+ || (!strcmp (field, _("Bcc")) && !(efh->header_wrap_flags & EM_FORMAT_HTML_HEADER_BCC)))
+ wrap = TRUE;
+ }
+
+ while (a) {
+ if (a->name)
+ name = camel_text_to_html (a->name, flags, 0);
+ else
+ name = NULL;
+
+ switch (a->type) {
+ case CAMEL_HEADER_ADDRESS_NAME:
+ if (name && *name) {
+ gchar *real, *mailaddr;
+
+ g_string_append_printf (out, "%s <", name);
+ /* rfc2368 for mailto syntax and url encoding extras */
+ if ((real = camel_header_encode_phrase ((guchar *)a->name))) {
+ mailaddr = g_strdup_printf("%s <%s>", real, a->v.addr);
+ g_free (real);
+ mailto = camel_url_encode (mailaddr, "?=&()");
+ g_free (mailaddr);
+ } else {
+ mailto = camel_url_encode (a->v.addr, "?=&()");
+ }
+ } else {
+ mailto = camel_url_encode (a->v.addr, "?=&()");
+ }
+ addr = camel_text_to_html (a->v.addr, flags, 0);
+ g_string_append_printf (out, "<a href=\"mailto:%s\">%s</a>", mailto, addr);
+ g_free (mailto);
+ g_free (addr);
+
+ if (name && *name)
+ g_string_append (out, ">");
+ break;
+ case CAMEL_HEADER_ADDRESS_GROUP:
+ g_string_append_printf (out, "%s: ", name);
+ efh_format_address (efh, out, a->v.members, field);
+ g_string_append_printf (out, ";");
+ break;
+ default:
+ g_warning ("Invalid address type");
+ break;
+ }
+
+ g_free (name);
+
+ i++;
+ a = a->next;
+ if (a)
+ g_string_append (out, ", ");
+
+ /* Let us add a '...' if we have more addresses */
+ if (limit > 0 && wrap && a && (i>(limit-1))) {
+
+ if (!strcmp (field, _("To"))) {
+
+ g_string_append (out, "<a href=\"##TO##\">...</a>");
+ str = g_strdup_printf ("<a href=\"##TO##\"><img src=\"%s/plus.png\" /></a> ", EVOLUTION_ICONSDIR);
+
+ return str;
+ }
+ else if (!strcmp (field, _("Cc"))) {
+ g_string_append (out, "<a href=\"##CC##\">...</a>");
+ str = g_strdup_printf ("<a href=\"##CC##\"><img src=\"%s/plus.png\" /></a> ", EVOLUTION_ICONSDIR);
+
+ return str;
+ }
+ else if (!strcmp (field, _("Bcc"))) {
+ g_string_append (out, "<a href=\"##BCC##\">...</a>");
+ str = g_strdup_printf ("<a href=\"##BCC##\"><img src=\"%s/plus.png\" /></a> ", EVOLUTION_ICONSDIR);
+
+ return str;
+ }
+ }
+
+ }
+
+ if (limit > 0 && i>(limit)) {
+
+ if (!strcmp (field, _("To"))) {
+ str = g_strdup_printf ("<a href=\"##TO##\"><img src=\"%s/minus.png\" /></a> ", EVOLUTION_ICONSDIR);
+ }
+ else if (!strcmp (field, _("Cc"))) {
+ str = g_strdup_printf ("<a href=\"##CC##\"><img src=\"%s/minus.png\" /></a> ", EVOLUTION_ICONSDIR);
+ }
+ else if (!strcmp (field, _("Bcc"))) {
+ str = g_strdup_printf ("<a href=\"##BCC##\"><img src=\"%s/minus.png\" /></a> ", EVOLUTION_ICONSDIR);
+ }
+ }
+
+ return str;
+
+}
+
+static void
+efh_format_text_header (EMFormatHTML *emfh, CamelStream *stream, const gchar *label, const gchar *value, guint32 flags)
+{
+ const gchar *fmt, *html;
+ gchar *mhtml = NULL;
+ gboolean is_rtl;
+
+ if (value == NULL)
+ return;
+
+ while (*value == ' ')
+ value++;
+
+ if (!(flags & EM_FORMAT_HTML_HEADER_HTML))
+ html = mhtml = camel_text_to_html (value, emfh->text_html_flags, 0);
+ else
+ html = value;
+
+ is_rtl = gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL;
+ if (emfh->simple_headers) {
+ fmt = "<b>%s</b>: %s<br>";
+ } else {
+ if (flags & EM_FORMAT_HTML_HEADER_NOCOLUMNS) {
+ if (flags & EM_FORMAT_HEADER_BOLD) {
+ fmt = "<tr><td><b>%s:</b> %s</td></tr>";
+ } else {
+ fmt = "<tr><td>%s: %s</td></tr>";
+ }
+ } else if (flags & EM_FORMAT_HTML_HEADER_NODEC) {
+ if (is_rtl)
+ fmt = "<tr><td align=\"right\" valign=\"top\" width=\"100%%\">%2$s</td><th valign=top align=\"left\" nowrap>%1$s<b> </b></th></tr>";
+ else
+ fmt = "<tr><th align=\"right\" valign=\"top\" nowrap>%s<b> </b></th><td valign=top>%s</td></tr>";
+ } else {
+
+ if (flags & EM_FORMAT_HEADER_BOLD) {
+ if (is_rtl)
+ fmt = "<tr><td align=\"right\" valign=\"top\" width=\"100%%\">%2$s</td><th align=\"left\" nowrap>%1$s:<b> </b></th></tr>";
+ else
+ fmt = "<tr><th align=\"right\" valign=\"top\" nowrap>%s:<b> </b></th><td>%s</td></tr>";
+ } else {
+ if (is_rtl)
+ fmt = "<tr><td align=\"right\" valign=\"top\" width=\"100%\">%2$s</td><td align=\"left\" nowrap>%1$s:<b> </b></td></tr>";
+ else
+ fmt = "<tr><td align=\"right\" valign=\"top\" nowrap>%s:<b> </b></td><td>%s</td></tr>";
+ }
+ }
+ }
+
+ camel_stream_printf(stream, NULL, fmt, label, html);
+ g_free(mhtml);
+}
+
+static const gchar *addrspec_hdrs[] = {
+ "Sender", "From", "Reply-To", "To", "Cc", "Bcc",
+ "Resent-Sender", "Resent-From", "Resent-Reply-To",
+ "Resent-To", "Resent-Cc", "Resent-Bcc", NULL
+};
+
+static void
+efh_format_header (EMFormat *emf,
+ CamelStream *stream,
+ CamelMedium *part,
+ CamelHeaderRaw *raw_header,
+ guint32 flags,
+ const gchar *charset)
+{
+ EMFormatHTML *efh = (EMFormatHTML *)emf;
+ gchar *name, *buf, *value = NULL;
+ const gchar *label, *txt;
+ const gchar *header_name;
+ const gchar *header_value;
+ gboolean addrspec = FALSE;
+ gchar *str_field = NULL;
+ gint i;
+
+ header_name = camel_header_raw_get_name (raw_header);
+ header_value = camel_header_raw_get_value (raw_header);
+
+ name = alloca(strlen(header_name)+1);
+ strcpy(name, header_name);
+ canon_header_name (name);
+
+ for (i = 0; addrspec_hdrs[i]; i++) {
+ if (!strcmp(name, addrspec_hdrs[i])) {
+ addrspec = TRUE;
+ break;
+ }
+ }
+
+ label = _(name);
+
+ if (addrspec) {
+ struct _camel_header_address *addrs;
+ GString *html;
+ gchar *img;
+
+ buf = camel_header_unfold (header_value);
+ if (!(addrs = camel_header_address_decode (buf, emf->charset ? emf->charset : emf->default_charset))) {
+ g_free (buf);
+ return;
+ }
+
+ g_free (buf);
+
+ html = g_string_new("");
+ img = efh_format_address(efh, html, addrs, (gchar *)label);
+
+ if (img) {
+ str_field = g_strdup_printf ("%s%s:", img, label);
+ label = str_field;
+ flags |= EM_FORMAT_HTML_HEADER_NODEC;
+ g_free (img);
+ }
+
+ camel_header_address_unref(addrs);
+ txt = value = html->str;
+ g_string_free(html, FALSE);
+
+ flags |= EM_FORMAT_HEADER_BOLD | EM_FORMAT_HTML_HEADER_HTML;
+ } else if (!strcmp (name, "Subject")) {
+ buf = camel_header_unfold (header_value);
+ txt = value = camel_header_decode_string (buf, charset);
+ g_free (buf);
+
+ flags |= EM_FORMAT_HEADER_BOLD;
+ } else if (!strcmp(name, "X-evolution-mailer")) {
+ /* pseudo-header */
+ label = _("Mailer");
+ txt = value = camel_header_format_ctext (header_value, charset);
+ flags |= EM_FORMAT_HEADER_BOLD;
+ } else if (!strcmp (name, "Date") || !strcmp (name, "Resent-Date")) {
+ gint msg_offset, local_tz;
+ time_t msg_date;
+ struct tm local;
+ gchar *html;
+ gboolean hide_real_date;
+
+ hide_real_date = !em_format_html_get_show_real_date (efh);
+
+ txt = header_value;
+ while (*txt == ' ' || *txt == '\t')
+ txt++;
+
+ html = camel_text_to_html (txt, efh->text_html_flags, 0);
+
+ msg_date = camel_header_decode_date(txt, &msg_offset);
+ e_localtime_with_offset (msg_date, &local, &local_tz);
+
+ /* Convert message offset to minutes (e.g. -0400 --> -240) */
+ msg_offset = ((msg_offset / 100) * 60) + (msg_offset % 100);
+ /* Turn into offset from localtime, not UTC */
+ msg_offset -= local_tz / 60;
+
+ /* value will be freed at the end */
+ if (!hide_real_date && !msg_offset) {
+ /* No timezone difference; just show the real Date: header */
+ txt = value = html;
+ } else {
+ gchar *date_str;
+
+ date_str = e_datetime_format_format ("mail", "header",
+ DTFormatKindDateTime, msg_date);
+
+ if (hide_real_date) {
+ /* Show only the local-formatted date, losing all timezone
+ information like Outlook does. Should we attempt to show
+ it somehow? */
+ txt = value = date_str;
+ } else {
+ txt = value = g_strdup_printf ("%s (<I>%s</I>)", html, date_str);
+ g_free (date_str);
+ }
+ g_free (html);
+ }
+ flags |= EM_FORMAT_HTML_HEADER_HTML | EM_FORMAT_HEADER_BOLD;
+ } else if (!strcmp(name, "Newsgroups")) {
+ struct _camel_header_newsgroup *ng, *scan;
+ GString *html;
+
+ buf = camel_header_unfold (header_value);
+
+ if (!(ng = camel_header_newsgroups_decode (buf))) {
+ g_free (buf);
+ return;
+ }
+
+ g_free (buf);
+
+ html = g_string_new("");
+ scan = ng;
+ while (scan) {
+ g_string_append_printf(html, "<a href=\"news:%s\">%s</a>", scan->newsgroup, scan->newsgroup);
+ scan = scan->next;
+ if (scan)
+ g_string_append_printf(html, ", ");
+ }
+
+ camel_header_newsgroups_free(ng);
+
+ txt = html->str;
+ g_string_free(html, FALSE);
+ flags |= EM_FORMAT_HEADER_BOLD|EM_FORMAT_HTML_HEADER_HTML;
+ } else if (!strcmp (name, "Received") || !strncmp (name, "X-", 2)) {
+ /* don't unfold Received nor extension headers */
+ txt = value = camel_header_decode_string(header_value, charset);
+ } else {
+ /* don't unfold Received nor extension headers */
+ buf = camel_header_unfold (header_value);
+ txt = value = camel_header_decode_string (buf, charset);
+ g_free (buf);
+ }
+
+ efh_format_text_header(efh, stream, label, txt, flags);
+
+ g_free (value);
+ g_free (str_field);
+}
+
+static gboolean
+efh_format_headers (EMFormatHTML *efh,
+ CamelStream *stream,
+ CamelMedium *part,
+ GError **error)
+{
+ EMFormat *emf = (EMFormat *) efh;
+ const gchar *charset;
+ CamelContentType *ct;
+ gboolean have_icon = FALSE;
+ const gchar *photo_name = NULL;
+ CamelInternetAddress *cia = NULL;
+ CamelMimePart *mime_part;
+ GQueue *header_queue;
+ GList *link;
+ gboolean face_decoded = FALSE, contact_has_photo = FALSE;
+ guchar *face_header_value = NULL;
+ gsize face_header_len = 0;
+ gchar *header_sender = NULL, *header_from = NULL, *name;
+ gboolean mail_from_delegate = FALSE;
+ const gchar *hdr_charset;
+
+ /* FIXME For crying out loud, break this function up! */
+
+ if (!part || efh->hide_headers)
+ return TRUE;
+
+ ct = camel_mime_part_get_content_type((CamelMimePart *)part);
+ charset = camel_content_type_param (ct, "charset");
+ charset = camel_iconv_charset_name(charset);
+
+ if (!efh->simple_headers)
+ camel_stream_printf (
+ stream, NULL, "<font color=\"#%06x\">\n"
+ "<table cellpadding=\"0\" width=\"100%%\">",
+ e_color_to_value (
+ &efh->priv->colors[
+ EM_FORMAT_HTML_COLOR_HEADER]));
+
+ hdr_charset = emf->charset ? emf->charset : emf->default_charset;
+
+ mime_part = CAMEL_MIME_PART (part);
+ header_queue = camel_mime_part_get_raw_headers (mime_part);
+ link = g_queue_peek_head_link (header_queue);
+
+ while (link != NULL) {
+ CamelHeaderRaw *raw_header = link->data;
+ const gchar *header_name;
+ const gchar *header_value;
+
+ header_name = camel_header_raw_get_name (raw_header);
+ header_value = camel_header_raw_get_value (raw_header);
+
+ if (!g_ascii_strcasecmp (header_name, "Sender")) {
+ struct _camel_header_address *addrs;
+ GString *html;
+
+ if (!(addrs = camel_header_address_decode (header_value, hdr_charset)))
+ break;
+
+ html = g_string_new("");
+ name = efh_format_address(efh, html, addrs, header_name);
+
+ header_sender = html->str;
+ camel_header_address_unref(addrs);
+
+ g_string_free(html, FALSE);
+ g_free (name);
+ } else if (!g_ascii_strcasecmp (header_name, "From")) {
+ struct _camel_header_address *addrs;
+ GString *html;
+
+ if (!(addrs = camel_header_address_decode (header_value, hdr_charset)))
+ break;
+
+ html = g_string_new("");
+ name = efh_format_address(efh, html, addrs, header_name);
+
+ header_from = html->str;
+ camel_header_address_unref(addrs);
+
+ g_string_free(html, FALSE);
+ g_free(name);
+ } else if (!g_ascii_strcasecmp (header_name, "X-Evolution-Mail-From-Delegate")) {
+ mail_from_delegate = TRUE;
+ }
+
+ link = g_list_next (link);
+ }
+
+ if (header_sender && header_from && mail_from_delegate) {
+ camel_stream_printf (
+ stream, NULL, "<tr><td><table border=1 "
+ "width=\"100%%\" cellspacing=2 cellpadding=2><tr>");
+ if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
+ camel_stream_printf (
+ stream, NULL,
+ "<td align=\"right\" width=\"100%%\">");
+ else
+ camel_stream_printf (
+ stream, NULL,
+ "<td align=\"left\" width=\"100%%\">");
+ /* To translators: This message suggests to the receipients that the sender of the mail is
+ different from the one listed in From field.
+ */
+ camel_stream_printf (
+ stream, NULL, _("This message was sent by <b>%s</b> "
+ "on behalf of <b>%s</b>"), header_sender, header_from);
+ camel_stream_printf (stream, NULL, "</td></tr></table></td></tr>");
+ }
+
+ g_free (header_sender);
+ g_free (header_from);
+
+ if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
+ camel_stream_printf (
+ stream, NULL, "<tr><td><table width=\"100%%\" "
+ "border=0 cellpadding=\"0\">\n");
+ else
+ camel_stream_printf (
+ stream, NULL, "<tr><td><table border=0 "
+ "cellpadding=\"0\">\n");
+
+ /* dump selected headers */
+ if (emf->mode == EM_FORMAT_ALLHEADERS) {
+ link = g_queue_peek_head_link (header_queue);
+ while (link != NULL) {
+ efh_format_header(
+ emf, stream, part, link->data,
+ EM_FORMAT_HTML_HEADER_NOCOLUMNS, charset);
+ link = g_list_next (link);
+ }
+ } else {
+ GList *link;
+ gint mailer_shown = FALSE;
+
+ link = g_queue_peek_head_link (&emf->header_list);
+
+ while (link != NULL) {
+ EMFormatHeader *h = link->data;
+ gint mailer, face;
+
+ link = g_queue_peek_head_link (header_queue);
+
+ mailer = !g_ascii_strcasecmp (h->name, "X-Evolution-Mailer");
+ face = !g_ascii_strcasecmp (h->name, "Face");
+
+ while (link != NULL) {
+ CamelHeaderRaw *raw_header = link->data;
+ const gchar *header_name;
+ const gchar *header_value;
+
+ header_name = camel_header_raw_get_name (raw_header);
+ header_value = camel_header_raw_get_value (raw_header);
+
+ if (em_format_html_get_show_sender_photo (efh) &&
+ !photo_name && !g_ascii_strcasecmp (header_name, "From"))
+ photo_name = header_value;
+
+ if (!mailer_shown && mailer && (!g_ascii_strcasecmp (header_name, "X-Mailer") ||
+ !g_ascii_strcasecmp (header_name, "User-Agent") ||
+ !g_ascii_strcasecmp (header_name, "X-Newsreader") ||
+ !g_ascii_strcasecmp (header_name, "X-MimeOLE"))) {
+ CamelHeaderRaw *mailer_header;
+ GQueue mailer_queue = G_QUEUE_INIT;
+ GList *mailer_link = NULL;
+ const gchar *mailer_value;
+
+ if (!g_ascii_strcasecmp (header_name, "X-MimeOLE")) {
+ for (mailer_link = link->next; mailer_link != NULL; mailer_link = mailer_link->next) {
+ CamelHeaderRaw *mailer_header = mailer_link->data;
+ const gchar *mailer_name;
+
+ mailer_name = camel_header_raw_get_name (mailer_header);
+
+ if (!g_ascii_strcasecmp (mailer_name, "X-Mailer") ||
+ !g_ascii_strcasecmp (mailer_name, "User-Agent") ||
+ !g_ascii_strcasecmp (mailer_name, "X-Newsreader")) {
+ /* even we have X-MimeOLE, then use rather the standard one, when available */
+ break;
+ }
+ }
+ }
+
+ if (mailer_link == NULL)
+ mailer_link = link;
+
+ mailer_header = mailer_link->data;
+ mailer_value = camel_header_raw_get_value (mailer_header);
+ camel_header_raw_append (&mailer_queue, "X-Evolution-Mailer", mailer_value, -1);
+ mailer_shown = TRUE;
+
+ efh_format_header (emf, stream, part, mailer_header, h->flags, charset);
+ if (strstr(mailer_value, "Evolution"))
+ have_icon = TRUE;
+ camel_header_raw_clear (&mailer_queue);
+ } else if (!face_decoded && face && !g_ascii_strcasecmp (header_name, "Face")) {
+ const gchar *cp = header_value;
+
+ /* Skip over spaces */
+ while (*cp == ' ')
+ cp++;
+
+ face_header_value = g_base64_decode (cp, &face_header_len);
+ face_header_value = g_realloc (face_header_value, face_header_len + 1);
+ face_header_value[face_header_len] = 0;
+ face_decoded = TRUE;
+ /* Showing an encoded "Face" header makes little sense */
+ } else if (!g_ascii_strcasecmp (header_name, h->name) && !face) {
+ efh_format_header(emf, stream, part, raw_header, h->flags, charset);
+ }
+
+ link = g_list_next (link);
+ }
+
+ link = g_list_next (link);
+ }
+ }
+
+ if (!efh->simple_headers) {
+ camel_stream_printf(stream, NULL, "</table></td>");
+
+ if (photo_name) {
+ gchar *classid;
+ CamelMimePart *photopart;
+ gboolean only_local_photo;
+
+ cia = camel_internet_address_new();
+ camel_address_decode((CamelAddress *) cia, (const gchar *) photo_name);
+ only_local_photo = em_format_html_get_only_local_photos (efh);
+ photopart = em_utils_contact_photo (cia, only_local_photo);
+
+ if (photopart) {
+ contact_has_photo = TRUE;
+ classid = g_strdup_printf("icon:///em-format-html/%s/photo/header",
+ emf->part_id->str);
+ camel_stream_printf(
+ stream, NULL,
+ "<td align=\"right\" valign=\"top\"><img width=64 src=\"%s\"></td>",
+ classid);
+ em_format_add_puri(emf, sizeof(EMFormatPURI), classid,
+ photopart, efh_write_image);
+ g_object_unref(photopart);
+
+ g_free(classid);
+ }
+ g_object_unref(cia);
+ }
+
+ if (!contact_has_photo && face_decoded) {
+ gchar *classid;
+ CamelMimePart *part;
+
+ part = camel_mime_part_new ();
+ camel_mime_part_set_content ((CamelMimePart *) part, (const gchar *) face_header_value, face_header_len, "image/png");
+ classid = g_strdup_printf("icon:///em-format-html/face/photo/header");
+ camel_stream_printf (
+ stream, NULL, "<td align=\"right\" "
+ "valign=\"top\"><img width=48 src=\"%s\">"
+ "</td>", classid);
+ em_format_add_puri(emf, sizeof(EMFormatPURI), classid, part, efh_write_image);
+ g_object_unref(part);
+ }
+
+ if (have_icon && efh->show_icon) {
+ GtkIconInfo *icon_info;
+ gchar *classid;
+ CamelMimePart *iconpart = NULL;
+
+ classid = g_strdup_printf("icon:///em-format-html/%s/icon/header", emf->part_id->str);
+ camel_stream_printf (
+ stream, NULL, "<td align=\"right\" "
+ "valign=\"top\"><img width=16 height=16 "
+ "src=\"%s\"></td>", classid);
+
+ icon_info = gtk_icon_theme_lookup_icon (
+ gtk_icon_theme_get_default (),
+ "evolution", 16, GTK_ICON_LOOKUP_NO_SVG);
+ if (icon_info != NULL) {
+ iconpart = em_format_html_file_part (
+ (EMFormatHTML *) emf, "image/png",
+ gtk_icon_info_get_filename (icon_info));
+ gtk_icon_info_free (icon_info);
+ }
+
+ if (iconpart) {
+ em_format_add_puri(emf, sizeof(EMFormatPURI), classid, iconpart, efh_write_image);
+ g_object_unref(iconpart);
+ }
+ g_free(classid);
+ }
+ camel_stream_printf (stream, NULL, "</tr></table>\n</font>\n");
+ }
+
+ return TRUE;
+}
+
+static gboolean
+efh_format_message (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
+{
+ const EMFormatHandler *handle;
+ gboolean success;
+
+ /* TODO: make this validity stuff a method */
+ EMFormatHTML *efh = (EMFormatHTML *) emf;
+ CamelCipherValidity *save = emf->valid, *save_parent = emf->valid_parent;
+
+ emf->valid = NULL;
+ emf->valid_parent = NULL;
+
+ if (emf->message != (CamelMimeMessage *)part)
+ camel_stream_printf (stream, NULL, "<blockquote>\n");
+
+ if (!efh_format_headers (efh, stream, CAMEL_MEDIUM (part), error))
+ return FALSE;
+
+ handle = em_format_find_handler(emf, "x-evolution/message/post-header");
+ g_return_val_if_fail (handle != NULL, FALSE);
+
+ if (!handle->handler (emf, stream, part, handle, error))
+ return FALSE;
+
+ camel_stream_printf (stream, NULL, EM_FORMAT_HTML_VPAD);
+ success = em_format_part (emf, stream, part, error);
+
+ if (emf->message != (CamelMimeMessage *)part)
+ camel_stream_printf (stream, NULL, "</blockquote>\n");
+
+ camel_cipher_validity_free(emf->valid);
+
+ emf->valid = save;
+ emf->valid_parent = save_parent;
+
+ return success;
+}
+static void
efh_set_property (GObject *object,
guint property_id,
const GValue *value,
@@ -648,10 +1381,11 @@ efh_format_clone (EMFormat *emf,
}
}
-static void
+static gboolean
efh_format_error (EMFormat *emf,
CamelStream *stream,
- const gchar *txt)
+ const gchar *txt,
+ GError **error)
{
gchar *html;
@@ -659,18 +1393,23 @@ efh_format_error (EMFormat *emf,
txt, CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
camel_stream_printf (
- stream, "<em><font color=\"red\">%s</font></em><br>", html);
+ stream, NULL,
+ "<em><font color=\"red\">%s</font></em><br>", html);
g_free (html);
+
+ return TRUE;
}
-static void
+static gboolean
efh_format_source (EMFormat *emf,
CamelStream *stream,
- CamelMimePart *part)
+ CamelMimePart *part,
+ GError **error)
{
CamelStream *filtered_stream;
CamelMimeFilter *filter;
CamelDataWrapper *dw = (CamelDataWrapper *) part;
+ gboolean success;
filtered_stream = camel_stream_filter_new (stream);
@@ -682,20 +1421,24 @@ efh_format_source (EMFormat *emf,
CAMEL_STREAM_FILTER (filtered_stream), filter);
g_object_unref (filter);
- camel_stream_write_string (stream, "<table><tr><td><tt>");
- em_format_format_text (emf, filtered_stream, dw);
+ camel_stream_write_string (stream, "<table><tr><td><tt>", NULL);
+ success = em_format_format_text (emf, filtered_stream, dw, error);
+ camel_stream_write_string(stream, "</tt></td></tr></table>", NULL);
+
g_object_unref (filtered_stream);
- camel_stream_write_string(stream, "</tt></td></tr></table>");
+ return success;
}
-static void
+static gboolean
efh_format_attachment (EMFormat *emf,
CamelStream *stream,
CamelMimePart *part,
const gchar *mime_type,
- const EMFormatHandler *handle)
+ const EMFormatHandler *handle,
+ GError **error)
{
+ gboolean success = TRUE;
gchar *text, *html;
/* we display all inlined attachments only */
@@ -707,21 +1450,95 @@ efh_format_attachment (EMFormat *emf,
"<table width=10 cellspacing=0 cellpadding=0>"
"<tr><td></td></tr></table></td>"
"<td><table width=3 cellspacing=0 cellpadding=0>"
- "<tr><td></td></tr></table></td><td><font size=-1>\n");
+ "<tr><td></td></tr></table></td><td><font size=-1>\n",
+ NULL);
/* output some info about it */
text = em_format_describe_part(part, mime_type);
html = camel_text_to_html (
text, ((EMFormatHTML *)emf)->text_html_flags &
CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
- camel_stream_write_string (stream, html);
+ camel_stream_write_string (stream, html, NULL);
g_free (html);
g_free (text);
- camel_stream_write_string (stream, "</font></td></tr><tr></table>");
+ camel_stream_write_string (
+ stream, "</font></td></tr><tr></table>", NULL);
if (handle && em_format_is_inline (emf, emf->part_id->str, part, handle))
- handle->handler (emf, stream, part, handle);
+ success = handle->handler (emf, stream, part, handle, error);
+
+ return success;
+}
+
+/* TODO: this could probably be virtual on em-format-html
+ then we only need one version of each type handler */
+static gboolean
+efh_format_secure (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ CamelCipherValidity *valid,
+ GError **error)
+{
+ EMFormatClass *format_class;
+
+ format_class = EM_FORMAT_CLASS (parent_class);
+ g_return_val_if_fail (format_class->format_secure != NULL, FALSE);
+ if (!format_class->format_secure (emf, stream, part, valid, error))
+ return FALSE;
+
+ /* To explain, if the validity is the same, then we are the
+ base validity and now have a combined sign/encrypt validity
+ we can display. Primarily a new verification context is
+ created when we have an embeded message. */
+ if (emf->valid == valid
+ && (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE
+ || valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE)) {
+ gchar *classid, *iconpath;
+ const gchar *icon;
+ CamelMimePart *iconpart;
+
+ camel_stream_printf (
+ stream, NULL, "<table border=0 width=\"100%%\" "
+ "cellpadding=3 cellspacing=0%s><tr>",
+ smime_sign_colour[valid->sign.status]);
+
+ classid = g_strdup_printf (
+ "smime:///em-format-html/%s/icon/signed",
+ emf->part_id->str);
+ camel_stream_printf (
+ stream, NULL, "<td valign=\"top\"><img src=\"%s\">"
+ "</td><td valign=\"top\" width=\"100%%\">", classid);
+
+ if (valid->sign.status != 0)
+ icon = smime_sign_table[valid->sign.status].icon;
+ else
+ icon = smime_encrypt_table[valid->encrypt.status].icon;
+ iconpath = e_icon_factory_get_icon_filename(icon, GTK_ICON_SIZE_DIALOG);
+ iconpart = em_format_html_file_part((EMFormatHTML *)emf, "image/png", iconpath);
+ if (iconpart) {
+ (void)em_format_add_puri(emf, sizeof(EMFormatPURI), classid, iconpart, efh_write_image);
+ g_object_unref(iconpart);
+ }
+ g_free (iconpath);
+ g_free(classid);
+
+ if (valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE) {
+ camel_stream_printf (
+ stream, NULL, "%s<br>",
+ _(smime_sign_table[valid->sign.status].shortdesc));
+ }
+
+ if (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE) {
+ camel_stream_printf (
+ stream, NULL, "%s<br>",
+ _(smime_encrypt_table[valid->encrypt.status].shortdesc));
+ }
+
+ camel_stream_printf (stream, NULL, "</td></tr></table>");
+ }
+
+ return TRUE;
}
static gboolean
@@ -733,6 +1550,7 @@ efh_busy (EMFormat *emf)
return (priv->format_id != -1);
}
+
static void
efh_base_init (EMFormatHTMLClass *class)
{
@@ -1164,20 +1982,22 @@ em_format_html_set_show_real_date (EMFormatHTML *efh,
}
CamelMimePart *
-em_format_html_file_part(EMFormatHTML *efh, const gchar *mime_type, const gchar *filename)
+em_format_html_file_part (EMFormatHTML *efh,
+ const gchar *mime_type,
+ const gchar *filename)
{
CamelMimePart *part;
CamelStream *stream;
CamelDataWrapper *dw;
gchar *basename;
- stream = camel_stream_fs_new_with_name(filename, O_RDONLY, 0);
+ stream = camel_stream_fs_new_with_name(filename, O_RDONLY, 0, NULL);
if (stream == NULL)
return NULL;
part = camel_mime_part_new();
dw = camel_data_wrapper_new();
- camel_data_wrapper_construct_from_stream(dw, stream);
+ camel_data_wrapper_construct_from_stream(dw, stream, NULL);
g_object_unref(stream);
if (mime_type)
camel_data_wrapper_set_mime_type(dw, mime_type);
@@ -1318,11 +2138,14 @@ em_format_html_job_queue(EMFormatHTML *emfh, struct _EMFormatHTMLJob *job)
/* ********************************************************************** */
-static void emfh_getpuri(struct _EMFormatHTMLJob *job, gint cancelled)
+static void
+emfh_getpuri (struct _EMFormatHTMLJob *job, gint cancelled)
{
d(printf(" running getpuri task\n"));
if (!cancelled)
- job->u.puri->func((EMFormat *)job->format, job->stream, job->u.puri);
+ job->u.puri->func (
+ EM_FORMAT (job->format),
+ job->stream, job->u.puri, NULL);
}
static void emfh_gethttp(struct _EMFormatHTMLJob *job, gint cancelled)
@@ -1370,7 +2193,7 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, gint cancelled)
}
camel_operation_start(NULL, _("Retrieving `%s'"), job->u.uri);
tmp_stream = (CamelHttpStream *)instream;
- content_type = camel_http_stream_get_content_type(tmp_stream);
+ content_type = camel_http_stream_get_content_type(tmp_stream, NULL);
length = camel_header_raw_find(tmp_stream->raw_headers, "Content-Length", NULL);
d(printf(" Content-Length: %s\n", length));
if (length != NULL)
@@ -1393,7 +2216,7 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, gint cancelled)
break;
}
/* FIXME: progress reporting in percentage, can we get the length always? do we care? */
- n = camel_stream_read(instream, buffer, sizeof (buffer));
+ n = camel_stream_read(instream, buffer, sizeof (buffer), NULL);
if (n > 0) {
nread += n;
/* If we didn't get a valid Content-Length header, do not try to calculate percentage */
@@ -1402,18 +2225,18 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, gint cancelled)
camel_operation_progress(NULL, pc_complete);
}
d(printf(" read %d bytes\n", n));
- if (costream && camel_stream_write (costream, buffer, n) == -1) {
+ if (costream && camel_stream_write (costream, buffer, n, NULL) == -1) {
n = -1;
break;
}
- camel_stream_write(job->stream, buffer, n);
+ camel_stream_write (job->stream, buffer, n, NULL);
}
} while (n>0);
/* indicates success */
if (n == 0)
- camel_stream_close(job->stream);
+ camel_stream_close (job->stream, NULL);
if (costream) {
/* do not store broken files in a cache */
@@ -1512,83 +2335,6 @@ efh_object_requested(GtkHTML *html, GtkHTMLEmbedded *eb, EMFormatHTML *efh)
/* ********************************************************************** */
#include "em-inline-filter.h"
-/* FIXME: This is duplicated in em-format-html-display, should be exported or in security module */
-static const struct {
- const gchar *icon, *shortdesc;
-} smime_sign_table[5] = {
- { "stock_signature-bad", N_("Unsigned") },
- { "stock_signature-ok", N_("Valid signature") },
- { "stock_signature-bad", N_("Invalid signature") },
- { "stock_signature", N_("Valid signature, but cannot verify sender") },
- { "stock_signature-bad", N_("Signature exists, but need public key") },
-};
-
-static const struct {
- const gchar *icon, *shortdesc;
-} smime_encrypt_table[4] = {
- { "stock_lock-broken", N_("Unencrypted") },
- { "stock_lock", N_("Encrypted, weak"),},
- { "stock_lock-ok", N_("Encrypted") },
- { "stock_lock-ok", N_("Encrypted, strong") },
-};
-
-static const gchar *smime_sign_colour[4] = {
- "", " bgcolor=\"#88bb88\"", " bgcolor=\"#bb8888\"", " bgcolor=\"#e8d122\""
-};
-
-/* TODO: this could probably be virtual on em-format-html
- then we only need one version of each type handler */
-static void
-efh_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid)
-{
- EMFormatClass *format_class;
-
- format_class = EM_FORMAT_CLASS (parent_class);
- g_return_if_fail (format_class->format_secure != NULL);
- format_class->format_secure (emf, stream, part, valid);
-
- /* To explain, if the validity is the same, then we are the
- base validity and now have a combined sign/encrypt validity
- we can display. Primarily a new verification context is
- created when we have an embeded message. */
- if (emf->valid == valid
- && (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE
- || valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE)) {
- gchar *classid, *iconpath;
- const gchar *icon;
- CamelMimePart *iconpart;
-
- camel_stream_printf (stream, "<table border=0 width=\"100%%\" cellpadding=3 cellspacing=0%s><tr>",
- smime_sign_colour[valid->sign.status]);
-
- classid = g_strdup_printf("smime:///em-format-html/%s/icon/signed", emf->part_id->str);
- camel_stream_printf(stream, "<td valign=\"top\"><img src=\"%s\"></td><td valign=\"top\" width=\"100%%\">", classid);
-
- if (valid->sign.status != 0)
- icon = smime_sign_table[valid->sign.status].icon;
- else
- icon = smime_encrypt_table[valid->encrypt.status].icon;
- iconpath = e_icon_factory_get_icon_filename(icon, GTK_ICON_SIZE_DIALOG);
- iconpart = em_format_html_file_part((EMFormatHTML *)emf, "image/png", iconpath);
- if (iconpart) {
- (void)em_format_add_puri(emf, sizeof(EMFormatPURI), classid, iconpart, efh_write_image);
- g_object_unref(iconpart);
- }
- g_free (iconpath);
- g_free(classid);
-
- if (valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE) {
- camel_stream_printf(stream, "%s<br>", _(smime_sign_table[valid->sign.status].shortdesc));
- }
-
- if (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE) {
- camel_stream_printf(stream, "%s<br>", _(smime_encrypt_table[valid->encrypt.status].shortdesc));
- }
-
- camel_stream_printf(stream, "</td></tr></table>");
- }
-}
-
static void
efh_text_plain(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
{
@@ -1651,8 +2397,8 @@ efh_text_plain(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFo
camel_stream_filter_add (
CAMEL_STREAM_FILTER (filtered_stream),
(CamelMimeFilter *)inline_filter);
- camel_data_wrapper_write_to_stream(dw, filtered_stream);
- camel_stream_close(filtered_stream);
+ camel_data_wrapper_write_to_stream(dw, filtered_stream, NULL);
+ camel_stream_close(filtered_stream, NULL);
g_object_unref(filtered_stream);
mp = em_inline_filter_get_multipart(inline_filter);
@@ -1685,7 +2431,10 @@ efh_text_plain(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFo
type = camel_mime_part_get_content_type(newpart);
if (camel_content_type_is (type, "text", "*") && (is_fallback || !camel_content_type_is (type, "text", "calendar"))) {
camel_stream_printf (
- stream, "<div style=\"border: solid #%06x 1px; background-color: #%06x; padding: 10px; color: #%06x;\">\n",
+ stream, NULL,
+ "<div style=\"border: solid #%06x 1px; "
+ "background-color: #%06x; padding: 10px; "
+ "color: #%06x;\">\n",
e_color_to_value (
&efh->priv->colors[
EM_FORMAT_HTML_COLOR_FRAME]),
@@ -1695,14 +2444,17 @@ efh_text_plain(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFo
e_color_to_value (
&efh->priv->colors[
EM_FORMAT_HTML_COLOR_TEXT]));
- camel_stream_write_string(stream, "<tt>\n" EFH_MESSAGE_START);
- em_format_format_text((EMFormat *)efh, filtered_stream, (CamelDataWrapper *)newpart);
- camel_stream_flush(filtered_stream);
- camel_stream_write_string(stream, "</tt>\n");
- camel_stream_write_string(stream, "</div>\n");
+ camel_stream_write_string (
+ stream, "<tt>\n" EFH_MESSAGE_START, NULL);
+ em_format_format_text (
+ EM_FORMAT (efh), filtered_stream,
+ CAMEL_DATA_WRAPPER (newpart), NULL);
+ camel_stream_flush(filtered_stream, NULL);
+ camel_stream_write_string(stream, "</tt>\n", NULL);
+ camel_stream_write_string(stream, "</div>\n", NULL);
} else {
g_string_append_printf(((EMFormat *)efh)->part_id, ".inline.%d", i);
- em_format_part((EMFormat *)efh, stream, newpart);
+ em_format_part (EM_FORMAT (efh), stream, newpart, NULL);
g_string_truncate(((EMFormat *)efh)->part_id, len);
}
}
@@ -1722,9 +2474,11 @@ efh_text_enriched(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, E
if (!strcmp(info->mime_type, "text/richtext")) {
flags = CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT;
- camel_stream_write_string( stream, "\n<!-- text/richtext -->\n");
+ camel_stream_write_string (
+ stream, "\n<!-- text/richtext -->\n", NULL);
} else {
- camel_stream_write_string( stream, "\n<!-- text/enriched -->\n");
+ camel_stream_write_string (
+ stream, "\n<!-- text/enriched -->\n", NULL);
}
enriched = camel_mime_filter_enriched_new(flags);
@@ -1734,7 +2488,9 @@ efh_text_enriched(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, E
g_object_unref(enriched);
camel_stream_printf (
- stream, "<div style=\"border: solid #%06x 1px; background-color: #%06x; padding: 10px; color: #%06x;\">\n" EFH_MESSAGE_START,
+ stream, NULL, "<div style=\"border: solid #%06x 1px; "
+ "background-color: #%06x; padding: 10px; color: #%06x;\">\n"
+ EFH_MESSAGE_START,
e_color_to_value (
&efh->priv->colors[
EM_FORMAT_HTML_COLOR_FRAME]),
@@ -1745,14 +2501,19 @@ efh_text_enriched(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, E
&efh->priv->colors[
EM_FORMAT_HTML_COLOR_TEXT]));
- em_format_format_text((EMFormat *)efh, filtered_stream, (CamelDataWrapper *)part);
+ em_format_format_text (
+ EM_FORMAT (efh), filtered_stream,
+ CAMEL_DATA_WRAPPER (part), NULL);
g_object_unref(filtered_stream);
- camel_stream_write_string(stream, "</div>");
+ camel_stream_write_string(stream, "</div>", NULL);
}
-static void
-efh_write_text_html(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri)
+static gboolean
+efh_write_text_html (EMFormat *emf,
+ CamelStream *stream,
+ EMFormatPURI *puri,
+ GError **error)
{
#if d(!)0
CamelStream *out;
@@ -1767,11 +2528,16 @@ efh_write_text_html(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri)
camel_data_wrapper_write_to_stream(dw, out);
g_object_unref(out);
#endif
- em_format_format_text(emf, stream, (CamelDataWrapper *)puri->part);
+
+ return em_format_format_text (
+ emf, stream, CAMEL_DATA_WRAPPER (puri->part), error);
}
static void
-efh_text_html(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
+efh_text_html (EMFormatHTML *efh,
+ CamelStream *stream,
+ CamelMimePart *part,
+ EMFormatHandler *info)
{
const gchar *location;
/* This is set but never used for anything */
@@ -1779,7 +2545,8 @@ efh_text_html(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFor
gchar *cid = NULL;
camel_stream_printf (
- stream, "<div style=\"border: solid #%06x 1px; background-color: #%06x; color: #%06x;\">\n"
+ stream, NULL, "<div style=\"border: solid #%06x 1px; "
+ "background-color: #%06x; color: #%06x;\">\n"
"<!-- text/html -->\n" EFH_MESSAGE_START,
e_color_to_value (
&efh->priv->colors[
@@ -1814,34 +2581,42 @@ efh_text_html(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFor
}
}
- puri = em_format_add_puri((EMFormat *)efh, sizeof(EMFormatPURI), cid, part, efh_write_text_html);
+ puri = em_format_add_puri (
+ EM_FORMAT (efh), sizeof (EMFormatPURI),
+ cid, part, efh_write_text_html);
d(printf("adding iframe, location %s\n", cid));
- camel_stream_printf(stream,
- "<iframe src=\"%s\" frameborder=0 scrolling=no>could not get %s</iframe>\n"
- "</div>\n",
- cid, cid);
+ camel_stream_printf (
+ stream, NULL,
+ "<iframe src=\"%s\" frameborder=0 scrolling=no>"
+ "could not get %s</iframe>\n</div>\n", cid, cid);
g_free(cid);
}
/* This is a lot of code for something useless ... */
-static void
-efh_message_external(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
+static gboolean
+efh_message_external (EMFormatHTML *efh,
+ CamelStream *stream,
+ CamelMimePart *part,
+ EMFormatHandler *info,
+ GError **error)
{
CamelContentType *type;
const gchar *access_type;
gchar *url = NULL, *desc = NULL;
- if (!part) {
- camel_stream_printf(stream, _("Unknown external-body part."));
- return;
+ if (part == NULL) {
+ camel_stream_printf (
+ stream, NULL, _("Unknown external-body part."));
+ return TRUE;
}
/* needs to be cleaner */
type = camel_mime_part_get_content_type(part);
access_type = camel_content_type_param (type, "access-type");
if (!access_type) {
- camel_stream_printf(stream, _("Malformed external-body part."));
- return;
+ camel_stream_printf (
+ stream, NULL, _("Malformed external-body part."));
+ return TRUE;
}
if (!g_ascii_strcasecmp(access_type, "ftp") ||
@@ -1908,26 +2683,37 @@ efh_message_external(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part
} else
goto fail;
- camel_stream_printf(stream, "<a href=\"%s\">%s</a>", url, desc);
+ camel_stream_printf (stream, NULL, "<a href=\"%s\">%s</a>", url, desc);
g_free(url);
g_free(desc);
- return;
+ return TRUE;
fail:
- camel_stream_printf(stream, _("Pointer to unknown external data (\"%s\" type)"), access_type);
+ camel_stream_printf (
+ stream, NULL,
+ _("Pointer to unknown external data (\"%s\" type)"),
+ access_type);
+
+ return TRUE;
}
-static void
-efh_message_deliverystatus(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
+static gboolean
+efh_message_deliverystatus (EMFormatHTML *efh,
+ CamelStream *stream,
+ CamelMimePart *part,
+ EMFormatHandler *info,
+ GError **error)
{
CamelStream *filtered_stream;
CamelMimeFilter *html_filter;
guint32 rgb = 0x737373;
+ gboolean success;
/* Yuck, this is copied from efh_text_plain */
camel_stream_printf (
- stream, "<div style=\"border: solid #%06x 1px; background-color: #%06x; padding: 10px; color: #%06x;\">\n",
+ stream, NULL, "<div style=\"border: solid #%06x 1px; "
+ "background-color: #%06x; padding: 10px; color: #%06x;\">\n",
e_color_to_value (
&efh->priv->colors[
EM_FORMAT_HTML_COLOR_FRAME]),
@@ -1939,24 +2725,35 @@ efh_message_deliverystatus(EMFormatHTML *efh, CamelStream *stream, CamelMimePart
EM_FORMAT_HTML_COLOR_TEXT]));
filtered_stream = camel_stream_filter_new (stream);
- html_filter = camel_mime_filter_tohtml_new(efh->text_html_flags, rgb);
+ html_filter = camel_mime_filter_tohtml_new (efh->text_html_flags, rgb);
camel_stream_filter_add (
CAMEL_STREAM_FILTER (filtered_stream), html_filter);
g_object_unref(html_filter);
- camel_stream_write_string(stream, "<tt>\n" EFH_MESSAGE_START);
- em_format_format_text((EMFormat *)efh, filtered_stream, (CamelDataWrapper *)part);
- camel_stream_flush(filtered_stream);
- camel_stream_write_string(stream, "</tt>\n");
+ camel_stream_write_string (stream, "<tt>\n" EFH_MESSAGE_START, NULL);
+ success = em_format_format_text (
+ EM_FORMAT (efh), filtered_stream,
+ CAMEL_DATA_WRAPPER (part), error);
+ camel_stream_flush(filtered_stream, NULL);
+ camel_stream_write_string(stream, "</tt>\n", NULL);
+
+ camel_stream_write_string(stream, "</div>", NULL);
- camel_stream_write_string(stream, "</div>");
+ return success;
}
-static void
-emfh_write_related(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri)
+static gboolean
+emfh_write_related (EMFormat *emf,
+ CamelStream *stream,
+ EMFormatPURI *puri,
+ GError **error)
{
- em_format_format_content(emf, stream, puri->part);
- camel_stream_close(stream);
+ gboolean success;
+
+ success = em_format_format_content (emf, stream, puri->part, error);
+ camel_stream_close (stream, NULL);
+
+ return success;
}
static void
@@ -1989,7 +2786,7 @@ emfh_multipart_related_check(struct _EMFormatHTMLJob *job, gint cancelled)
d(printf("part '%s' '%s' used '%d'\n", puri->uri?puri->uri:"", puri->cid, puri->use_count));
if (puri->func == emfh_write_related) {
g_string_printf (format->part_id, "%s", puri->part_id);
- em_format_part (format, (CamelStream *)job->stream, puri->part);
+ em_format_part (format, (CamelStream *)job->stream, puri->part, NULL);
}
/* else it was probably added by a previous format this loop */
}
@@ -2002,10 +2799,14 @@ emfh_multipart_related_check(struct _EMFormatHTMLJob *job, gint cancelled)
}
/* RFC 2387 */
-static void
-efh_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
+static gboolean
+efh_multipart_related (EMFormat *emf,
+ CamelStream *stream,
+ CamelMimePart *part,
+ const EMFormatHandler *info,
+ GError **error)
{
- CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content((CamelMedium *)part);
+ CamelMultipart *mp;
CamelMimePart *body_part, *display_part = NULL;
CamelContentType *content_type;
const gchar *start;
@@ -2013,11 +2814,13 @@ efh_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
/* puri is set but never used */
EMFormatPURI *puri;
struct _EMFormatHTMLJob *job;
+ gboolean success;
- if (!CAMEL_IS_MULTIPART(mp)) {
- em_format_format_source(emf, stream, part);
- return;
- }
+ mp = (CamelMultipart *)
+ camel_medium_get_content (CAMEL_MEDIUM (part));
+
+ if (!CAMEL_IS_MULTIPART (mp))
+ return em_format_format_source(emf, stream, part, error);
nparts = camel_multipart_get_number(mp);
content_type = camel_mime_part_get_content_type(part);
@@ -2044,10 +2847,9 @@ efh_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
display_part = camel_multipart_get_part(mp, 0);
}
- if (display_part == NULL) {
- em_format_part_as(emf, stream, part, "multipart/mixed");
- return;
- }
+ if (display_part == NULL)
+ return em_format_part_as (
+ emf, stream, part, "multipart/mixed", error);
em_format_push_level(emf);
@@ -2065,9 +2867,9 @@ efh_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
}
g_string_append_printf(emf->part_id, "related.%d", displayid);
- em_format_part(emf, stream, display_part);
+ success = em_format_part(emf, stream, display_part, error);
g_string_truncate(emf->part_id, partidlen);
- camel_stream_flush(stream);
+ camel_stream_flush(stream, NULL);
/* queue a job to check for un-referenced parts to add as attachments */
job = em_format_html_job_new((EMFormatHTML *)emf, emfh_multipart_related_check, NULL);
@@ -2075,26 +2877,28 @@ efh_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
em_format_html_job_queue((EMFormatHTML *)emf, job);
em_format_pull_level(emf);
-}
-
-static void
-efh_write_image(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri)
-{
- CamelDataWrapper *dw = camel_medium_get_content((CamelMedium *)puri->part);
- d(printf("writing image '%s'\n", puri->cid));
- camel_data_wrapper_decode_to_stream(dw, stream);
- camel_stream_close(stream);
+ return success;
}
-static void
-efh_image(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info)
+static gboolean
+efh_image (EMFormatHTML *efh,
+ CamelStream *stream,
+ CamelMimePart *part,
+ EMFormatHandler *info,
+ GError **error)
{
EMFormatPURI *puri;
- puri = em_format_add_puri((EMFormat *)efh, sizeof(EMFormatPURI), NULL, part, efh_write_image);
+ puri = em_format_add_puri (
+ EM_FORMAT (efh), sizeof(EMFormatPURI),
+ NULL, part, efh_write_image);
d(printf("adding image '%s'\n", puri->cid));
- camel_stream_printf(stream, "<img hspace=10 vspace=10 src=\"%s\">", puri->cid);
+ camel_stream_printf (
+ stream, NULL,
+ "<img hspace=10 vspace=10 src=\"%s\">", puri->cid);
+
+ return TRUE;
}
static EMFormatHandler type_builtin_table[] = {
@@ -2149,661 +2953,3 @@ efh_builtin_init(EMFormatHTMLClass *efhc)
/* ********************************************************************** */
-static void
-efh_format_text_header (EMFormatHTML *emfh, CamelStream *stream, const gchar *label, const gchar *value, guint32 flags)
-{
- const gchar *fmt, *html;
- gchar *mhtml = NULL;
- gboolean is_rtl;
-
- if (value == NULL)
- return;
-
- while (*value == ' ')
- value++;
-
- if (!(flags & EM_FORMAT_HTML_HEADER_HTML))
- html = mhtml = camel_text_to_html (value, emfh->text_html_flags, 0);
- else
- html = value;
-
- is_rtl = gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL;
- if (emfh->simple_headers) {
- fmt = "<b>%s</b>: %s<br>";
- } else {
- if (flags & EM_FORMAT_HTML_HEADER_NOCOLUMNS) {
- if (flags & EM_FORMAT_HEADER_BOLD) {
- fmt = "<tr><td><b>%s:</b> %s</td></tr>";
- } else {
- fmt = "<tr><td>%s: %s</td></tr>";
- }
- } else if (flags & EM_FORMAT_HTML_HEADER_NODEC) {
- if (is_rtl)
- fmt = "<tr><td align=\"right\" valign=\"top\" width=\"100%%\">%2$s</td><th valign=top align=\"left\" nowrap>%1$s<b> </b></th></tr>";
- else
- fmt = "<tr><th align=\"right\" valign=\"top\" nowrap>%s<b> </b></th><td valign=top>%s</td></tr>";
- } else {
-
- if (flags & EM_FORMAT_HEADER_BOLD) {
- if (is_rtl)
- fmt = "<tr><td align=\"right\" valign=\"top\" width=\"100%%\">%2$s</td><th align=\"left\" nowrap>%1$s:<b> </b></th></tr>";
- else
- fmt = "<tr><th align=\"right\" valign=\"top\" nowrap>%s:<b> </b></th><td>%s</td></tr>";
- } else {
- if (is_rtl)
- fmt = "<tr><td align=\"right\" valign=\"top\" width=\"100%\">%2$s</td><td align=\"left\" nowrap>%1$s:<b> </b></td></tr>";
- else
- fmt = "<tr><td align=\"right\" valign=\"top\" nowrap>%s:<b> </b></td><td>%s</td></tr>";
- }
- }
- }
-
- camel_stream_printf(stream, fmt, label, html);
- g_free(mhtml);
-}
-
-static const gchar *addrspec_hdrs[] = {
- "Sender", "From", "Reply-To", "To", "Cc", "Bcc",
- "Resent-Sender", "Resent-From", "Resent-Reply-To",
- "Resent-To", "Resent-Cc", "Resent-Bcc", NULL
-};
-
-static gchar *
-efh_format_address (EMFormatHTML *efh, GString *out, struct _camel_header_address *a, const gchar *field)
-{
- guint32 flags = CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES;
- gchar *name, *mailto, *addr;
- gint i=0;
- gboolean wrap = FALSE;
- gchar *str = NULL;
- gint limit = mail_config_get_address_count ();
-
- if (field ) {
- if ((!strcmp (field, _("To")) && !(efh->header_wrap_flags & EM_FORMAT_HTML_HEADER_TO))
- || (!strcmp (field, _("Cc")) && !(efh->header_wrap_flags & EM_FORMAT_HTML_HEADER_CC))
- || (!strcmp (field, _("Bcc")) && !(efh->header_wrap_flags & EM_FORMAT_HTML_HEADER_BCC)))
- wrap = TRUE;
- }
-
- while (a) {
- if (a->name)
- name = camel_text_to_html (a->name, flags, 0);
- else
- name = NULL;
-
- switch (a->type) {
- case CAMEL_HEADER_ADDRESS_NAME:
- if (name && *name) {
- gchar *real, *mailaddr;
-
- g_string_append_printf (out, "%s <", name);
- /* rfc2368 for mailto syntax and url encoding extras */
- if ((real = camel_header_encode_phrase ((guchar *)a->name))) {
- mailaddr = g_strdup_printf("%s <%s>", real, a->v.addr);
- g_free (real);
- mailto = camel_url_encode (mailaddr, "?=&()");
- g_free (mailaddr);
- } else {
- mailto = camel_url_encode (a->v.addr, "?=&()");
- }
- } else {
- mailto = camel_url_encode (a->v.addr, "?=&()");
- }
- addr = camel_text_to_html (a->v.addr, flags, 0);
- g_string_append_printf (out, "<a href=\"mailto:%s\">%s</a>", mailto, addr);
- g_free (mailto);
- g_free (addr);
-
- if (name && *name)
- g_string_append (out, ">");
- break;
- case CAMEL_HEADER_ADDRESS_GROUP:
- g_string_append_printf (out, "%s: ", name);
- efh_format_address (efh, out, a->v.members, field);
- g_string_append_printf (out, ";");
- break;
- default:
- g_warning ("Invalid address type");
- break;
- }
-
- g_free (name);
-
- i++;
- a = a->next;
- if (a)
- g_string_append (out, ", ");
-
- /* Let us add a '...' if we have more addresses */
- if (limit > 0 && wrap && a && (i>(limit-1))) {
-
- if (!strcmp (field, _("To"))) {
-
- g_string_append (out, "<a href=\"##TO##\">...</a>");
- str = g_strdup_printf ("<a href=\"##TO##\"><img src=\"%s/plus.png\" /></a> ", EVOLUTION_ICONSDIR);
-
- return str;
- }
- else if (!strcmp (field, _("Cc"))) {
- g_string_append (out, "<a href=\"##CC##\">...</a>");
- str = g_strdup_printf ("<a href=\"##CC##\"><img src=\"%s/plus.png\" /></a> ", EVOLUTION_ICONSDIR);
-
- return str;
- }
- else if (!strcmp (field, _("Bcc"))) {
- g_string_append (out, "<a href=\"##BCC##\">...</a>");
- str = g_strdup_printf ("<a href=\"##BCC##\"><img src=\"%s/plus.png\" /></a> ", EVOLUTION_ICONSDIR);
-
- return str;
- }
- }
-
- }
-
- if (limit > 0 && i>(limit)) {
-
- if (!strcmp (field, _("To"))) {
- str = g_strdup_printf ("<a href=\"##TO##\"><img src=\"%s/minus.png\" /></a> ", EVOLUTION_ICONSDIR);
- }
- else if (!strcmp (field, _("Cc"))) {
- str = g_strdup_printf ("<a href=\"##CC##\"><img src=\"%s/minus.png\" /></a> ", EVOLUTION_ICONSDIR);
- }
- else if (!strcmp (field, _("Bcc"))) {
- str = g_strdup_printf ("<a href=\"##BCC##\"><img src=\"%s/minus.png\" /></a> ", EVOLUTION_ICONSDIR);
- }
- }
-
- return str;
-
-}
-
-static void
-canon_header_name (gchar *name)
-{
- gchar *inptr = name;
-
- /* canonicalise the header name... first letter is
- * capitalised and any letter following a '-' also gets
- * capitalised */
-
- if (*inptr >= 'a' && *inptr <= 'z')
- *inptr -= 0x20;
-
- inptr++;
-
- while (*inptr) {
- if (inptr[-1] == '-' && *inptr >= 'a' && *inptr <= 'z')
- *inptr -= 0x20;
- else if (*inptr >= 'A' && *inptr <= 'Z')
- *inptr += 0x20;
-
- inptr++;
- }
-}
-
-static void
-efh_format_header (EMFormat *emf,
- CamelStream *stream,
- CamelMedium *part,
- CamelHeaderRaw *raw_header,
- guint32 flags,
- const gchar *charset)
-{
- EMFormatHTML *efh = (EMFormatHTML *)emf;
- gchar *name, *buf, *value = NULL;
- const gchar *label, *txt;
- const gchar *header_name;
- const gchar *header_value;
- gboolean addrspec = FALSE;
- gchar *str_field = NULL;
- gint i;
-
- header_name = camel_header_raw_get_name (raw_header);
- header_value = camel_header_raw_get_value (raw_header);
-
- name = alloca(strlen(header_name)+1);
- strcpy(name, header_name);
- canon_header_name (name);
-
- for (i = 0; addrspec_hdrs[i]; i++) {
- if (!strcmp(name, addrspec_hdrs[i])) {
- addrspec = TRUE;
- break;
- }
- }
-
- label = _(name);
-
- if (addrspec) {
- struct _camel_header_address *addrs;
- GString *html;
- gchar *img;
-
- buf = camel_header_unfold (header_value);
- if (!(addrs = camel_header_address_decode (buf, emf->charset ? emf->charset : emf->default_charset))) {
- g_free (buf);
- return;
- }
-
- g_free (buf);
-
- html = g_string_new("");
- img = efh_format_address(efh, html, addrs, (gchar *)label);
-
- if (img) {
- str_field = g_strdup_printf ("%s%s:", img, label);
- label = str_field;
- flags |= EM_FORMAT_HTML_HEADER_NODEC;
- g_free (img);
- }
-
- camel_header_address_unref(addrs);
- txt = value = html->str;
- g_string_free(html, FALSE);
-
- flags |= EM_FORMAT_HEADER_BOLD | EM_FORMAT_HTML_HEADER_HTML;
- } else if (!strcmp (name, "Subject")) {
- buf = camel_header_unfold (header_value);
- txt = value = camel_header_decode_string (buf, charset);
- g_free (buf);
-
- flags |= EM_FORMAT_HEADER_BOLD;
- } else if (!strcmp(name, "X-evolution-mailer")) {
- /* pseudo-header */
- label = _("Mailer");
- txt = value = camel_header_format_ctext (header_value, charset);
- flags |= EM_FORMAT_HEADER_BOLD;
- } else if (!strcmp (name, "Date") || !strcmp (name, "Resent-Date")) {
- gint msg_offset, local_tz;
- time_t msg_date;
- struct tm local;
- gchar *html;
- gboolean hide_real_date;
-
- hide_real_date = !em_format_html_get_show_real_date (efh);
-
- txt = header_value;
- while (*txt == ' ' || *txt == '\t')
- txt++;
-
- html = camel_text_to_html (txt, efh->text_html_flags, 0);
-
- msg_date = camel_header_decode_date(txt, &msg_offset);
- e_localtime_with_offset (msg_date, &local, &local_tz);
-
- /* Convert message offset to minutes (e.g. -0400 --> -240) */
- msg_offset = ((msg_offset / 100) * 60) + (msg_offset % 100);
- /* Turn into offset from localtime, not UTC */
- msg_offset -= local_tz / 60;
-
- /* value will be freed at the end */
- if (!hide_real_date && !msg_offset) {
- /* No timezone difference; just show the real Date: header */
- txt = value = html;
- } else {
- gchar *date_str;
-
- date_str = e_datetime_format_format ("mail", "header",
- DTFormatKindDateTime, msg_date);
-
- if (hide_real_date) {
- /* Show only the local-formatted date, losing all timezone
- information like Outlook does. Should we attempt to show
- it somehow? */
- txt = value = date_str;
- } else {
- txt = value = g_strdup_printf ("%s (<I>%s</I>)", html, date_str);
- g_free (date_str);
- }
- g_free (html);
- }
- flags |= EM_FORMAT_HTML_HEADER_HTML | EM_FORMAT_HEADER_BOLD;
- } else if (!strcmp(name, "Newsgroups")) {
- struct _camel_header_newsgroup *ng, *scan;
- GString *html;
-
- buf = camel_header_unfold (header_value);
-
- if (!(ng = camel_header_newsgroups_decode (buf))) {
- g_free (buf);
- return;
- }
-
- g_free (buf);
-
- html = g_string_new("");
- scan = ng;
- while (scan) {
- g_string_append_printf(html, "<a href=\"news:%s\">%s</a>", scan->newsgroup, scan->newsgroup);
- scan = scan->next;
- if (scan)
- g_string_append_printf(html, ", ");
- }
-
- camel_header_newsgroups_free(ng);
-
- txt = html->str;
- g_string_free(html, FALSE);
- flags |= EM_FORMAT_HEADER_BOLD|EM_FORMAT_HTML_HEADER_HTML;
- } else if (!strcmp (name, "Received") || !strncmp (name, "X-", 2)) {
- /* don't unfold Received nor extension headers */
- txt = value = camel_header_decode_string(header_value, charset);
- } else {
- /* don't unfold Received nor extension headers */
- buf = camel_header_unfold (header_value);
- txt = value = camel_header_decode_string (buf, charset);
- g_free (buf);
- }
-
- efh_format_text_header(efh, stream, label, txt, flags);
-
- g_free (value);
- g_free (str_field);
-}
-
-static void
-efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part)
-{
- EMFormat *emf = (EMFormat *) efh;
- const gchar *charset;
- CamelContentType *ct;
- gboolean have_icon = FALSE;
- const gchar *photo_name = NULL;
- CamelInternetAddress *cia = NULL;
- CamelMimePart *mime_part;
- GQueue *header_queue;
- GList *link;
- gboolean face_decoded = FALSE, contact_has_photo = FALSE;
- guchar *face_header_value = NULL;
- gsize face_header_len = 0;
- gchar *header_sender = NULL, *header_from = NULL, *name;
- gboolean mail_from_delegate = FALSE;
- const gchar *hdr_charset;
-
- /* FIXME For crying out loud, break this function up! */
-
- if (!part)
- return;
-
- ct = camel_mime_part_get_content_type((CamelMimePart *)part);
- charset = camel_content_type_param (ct, "charset");
- charset = camel_iconv_charset_name(charset);
-
- if (!efh->simple_headers)
- camel_stream_printf (
- stream, "<font color=\"#%06x\">\n"
- "<table cellpadding=\"0\" width=\"100%%\">",
- e_color_to_value (
- &efh->priv->colors[
- EM_FORMAT_HTML_COLOR_HEADER]));
-
- hdr_charset = emf->charset ? emf->charset : emf->default_charset;
-
- mime_part = CAMEL_MIME_PART (part);
- header_queue = camel_mime_part_get_raw_headers (mime_part);
- link = g_queue_peek_head_link (header_queue);
-
- while (link != NULL) {
- CamelHeaderRaw *raw_header = link->data;
- const gchar *header_name;
- const gchar *header_value;
-
- header_name = camel_header_raw_get_name (raw_header);
- header_value = camel_header_raw_get_value (raw_header);
-
- if (!g_ascii_strcasecmp (header_name, "Sender")) {
- struct _camel_header_address *addrs;
- GString *html;
-
- if (!(addrs = camel_header_address_decode (header_value, hdr_charset)))
- break;
-
- html = g_string_new("");
- name = efh_format_address(efh, html, addrs, header_name);
-
- header_sender = html->str;
- camel_header_address_unref(addrs);
-
- g_string_free(html, FALSE);
- g_free (name);
- } else if (!g_ascii_strcasecmp (header_name, "From")) {
- struct _camel_header_address *addrs;
- GString *html;
-
- if (!(addrs = camel_header_address_decode (header_value, hdr_charset)))
- break;
-
- html = g_string_new("");
- name = efh_format_address(efh, html, addrs, header_name);
-
- header_from = html->str;
- camel_header_address_unref(addrs);
-
- g_string_free(html, FALSE);
- g_free(name);
- } else if (!g_ascii_strcasecmp (header_name, "X-Evolution-Mail-From-Delegate")) {
- mail_from_delegate = TRUE;
- }
-
- link = g_list_next (link);
- }
-
- if (header_sender && header_from && mail_from_delegate) {
- camel_stream_printf(stream, "<tr><td><table border=1 width=\"100%%\" cellspacing=2 cellpadding=2><tr>");
- if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
- camel_stream_printf (stream, "<td align=\"right\" width=\"100%%\">");
- else
- camel_stream_printf (stream, "<td align=\"left\" width=\"100%%\">");
- /* To translators: This message suggests to the receipients that the sender of the mail is
- different from the one listed in From field.
- */
- camel_stream_printf(stream, _("This message was sent by <b>%s</b> on behalf of <b>%s</b>"), header_sender, header_from);
- camel_stream_printf(stream, "</td></tr></table></td></tr>");
- }
-
- g_free (header_sender);
- g_free (header_from);
-
- if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
- camel_stream_printf (stream, "<tr><td><table width=\"100%%\" border=0 cellpadding=\"0\">\n");
- else
- camel_stream_printf (stream, "<tr><td><table border=0 cellpadding=\"0\">\n");
-
- /* dump selected headers */
- if (emf->mode == EM_FORMAT_ALLHEADERS) {
- link = g_queue_peek_head_link (header_queue);
- while (link != NULL) {
- efh_format_header(
- emf, stream, part, link->data,
- EM_FORMAT_HTML_HEADER_NOCOLUMNS, charset);
- link = g_list_next (link);
- }
- } else {
- GList *link;
- gint mailer_shown = FALSE;
-
- link = g_queue_peek_head_link (&emf->header_list);
-
- while (link != NULL) {
- EMFormatHeader *h = link->data;
- gint mailer, face;
-
- link = g_queue_peek_head_link (header_queue);
-
- mailer = !g_ascii_strcasecmp (h->name, "X-Evolution-Mailer");
- face = !g_ascii_strcasecmp (h->name, "Face");
-
- while (link != NULL) {
- CamelHeaderRaw *raw_header = link->data;
- const gchar *header_name;
- const gchar *header_value;
-
- header_name = camel_header_raw_get_name (raw_header);
- header_value = camel_header_raw_get_value (raw_header);
-
- if (em_format_html_get_show_sender_photo (efh) &&
- !photo_name && !g_ascii_strcasecmp (header_name, "From"))
- photo_name = header_value;
-
- if (!mailer_shown && mailer && (!g_ascii_strcasecmp (header_name, "X-Mailer") ||
- !g_ascii_strcasecmp (header_name, "User-Agent") ||
- !g_ascii_strcasecmp (header_name, "X-Newsreader") ||
- !g_ascii_strcasecmp (header_name, "X-MimeOLE"))) {
- CamelHeaderRaw *mailer_header;
- GQueue mailer_queue = G_QUEUE_INIT;
- GList *mailer_link = NULL;
- const gchar *mailer_value;
-
- if (!g_ascii_strcasecmp (header_name, "X-MimeOLE")) {
- for (mailer_link = link->next; mailer_link != NULL; mailer_link = mailer_link->next) {
- CamelHeaderRaw *mailer_header = mailer_link->data;
- const gchar *mailer_name;
-
- mailer_name = camel_header_raw_get_name (mailer_header);
-
- if (!g_ascii_strcasecmp (mailer_name, "X-Mailer") ||
- !g_ascii_strcasecmp (mailer_name, "User-Agent") ||
- !g_ascii_strcasecmp (mailer_name, "X-Newsreader")) {
- /* even we have X-MimeOLE, then use rather the standard one, when available */
- break;
- }
- }
- }
-
- if (mailer_link == NULL)
- mailer_link = link;
-
- mailer_header = mailer_link->data;
- mailer_value = camel_header_raw_get_value (mailer_header);
- camel_header_raw_append (&mailer_queue, "X-Evolution-Mailer", mailer_value, -1);
- mailer_shown = TRUE;
-
- efh_format_header (emf, stream, part, mailer_header, h->flags, charset);
- if (strstr(mailer_value, "Evolution"))
- have_icon = TRUE;
- camel_header_raw_clear (&mailer_queue);
- } else if (!face_decoded && face && !g_ascii_strcasecmp (header_name, "Face")) {
- const gchar *cp = header_value;
-
- /* Skip over spaces */
- while (*cp == ' ')
- cp++;
-
- face_header_value = g_base64_decode (cp, &face_header_len);
- face_header_value = g_realloc (face_header_value, face_header_len + 1);
- face_header_value[face_header_len] = 0;
- face_decoded = TRUE;
- /* Showing an encoded "Face" header makes little sense */
- } else if (!g_ascii_strcasecmp (header_name, h->name) && !face) {
- efh_format_header(emf, stream, part, raw_header, h->flags, charset);
- }
-
- link = g_list_next (link);
- }
-
- link = g_list_next (link);
- }
- }
-
- if (!efh->simple_headers) {
- camel_stream_printf(stream, "</table></td>");
-
- if (photo_name) {
- gchar *classid;
- CamelMimePart *photopart;
- gboolean only_local_photo;
-
- cia = camel_internet_address_new();
- camel_address_decode((CamelAddress *) cia, (const gchar *) photo_name);
- only_local_photo = em_format_html_get_only_local_photos (efh);
- photopart = em_utils_contact_photo (cia, only_local_photo);
-
- if (photopart) {
- contact_has_photo = TRUE;
- classid = g_strdup_printf("icon:///em-format-html/%s/photo/header",
- emf->part_id->str);
- camel_stream_printf(stream,
- "<td align=\"right\" valign=\"top\"><img width=64 src=\"%s\"></td>",
- classid);
- em_format_add_puri(emf, sizeof(EMFormatPURI), classid,
- photopart, efh_write_image);
- g_object_unref(photopart);
-
- g_free(classid);
- }
- g_object_unref(cia);
- }
-
- if (!contact_has_photo && face_decoded) {
- gchar *classid;
- CamelMimePart *part;
-
- part = camel_mime_part_new ();
- camel_mime_part_set_content ((CamelMimePart *) part, (const gchar *) face_header_value, face_header_len, "image/png");
- classid = g_strdup_printf("icon:///em-format-html/face/photo/header");
- camel_stream_printf(stream, "<td align=\"right\" valign=\"top\"><img width=48 src=\"%s\"></td>", classid);
- em_format_add_puri(emf, sizeof(EMFormatPURI), classid, part, efh_write_image);
- g_object_unref(part);
- }
-
- if (have_icon && efh->show_icon) {
- GtkIconInfo *icon_info;
- gchar *classid;
- CamelMimePart *iconpart = NULL;
-
- classid = g_strdup_printf("icon:///em-format-html/%s/icon/header", emf->part_id->str);
- camel_stream_printf(stream, "<td align=\"right\" valign=\"top\"><img width=16 height=16 src=\"%s\"></td>", classid);
-
- icon_info = gtk_icon_theme_lookup_icon (
- gtk_icon_theme_get_default (),
- "evolution", 16, GTK_ICON_LOOKUP_NO_SVG);
- if (icon_info != NULL) {
- iconpart = em_format_html_file_part (
- (EMFormatHTML *) emf, "image/png",
- gtk_icon_info_get_filename (icon_info));
- gtk_icon_info_free (icon_info);
- }
-
- if (iconpart) {
- em_format_add_puri(emf, sizeof(EMFormatPURI), classid, iconpart, efh_write_image);
- g_object_unref(iconpart);
- }
- g_free(classid);
- }
- camel_stream_printf (stream, "</tr></table>\n</font>\n");
- }
-}
-
-static void
-efh_format_message(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info)
-{
- const EMFormatHandler *handle;
-
- /* TODO: make this validity stuff a method */
- EMFormatHTML *efh = (EMFormatHTML *) emf;
- CamelCipherValidity *save = emf->valid, *save_parent = emf->valid_parent;
-
- emf->valid = NULL;
- emf->valid_parent = NULL;
-
- if (emf->message != (CamelMimeMessage *)part)
- camel_stream_printf(stream, "<blockquote>\n");
-
- if (!efh->hide_headers)
- efh_format_headers(efh, stream, (CamelMedium *)part);
-
- handle = em_format_find_handler(emf, "x-evolution/message/post-header");
- if (handle)
- handle->handler(emf, stream, part, handle);
-
- camel_stream_printf(stream, EM_FORMAT_HTML_VPAD);
- em_format_part(emf, stream, part);
-
- if (emf->message != (CamelMimeMessage *)part)
- camel_stream_printf(stream, "</blockquote>\n");
-
- camel_cipher_validity_free(emf->valid);
-
- emf->valid = save;
- emf->valid_parent = save_parent;
-}
diff --git a/mail/em-html-stream.c b/mail/em-html-stream.c
index d2f5770..afd8504 100644
--- a/mail/em-html-stream.c
+++ b/mail/em-html-stream.c
@@ -63,7 +63,7 @@ em_html_stream_dispose (GObject *object)
if (emhs->html_stream != NULL) {
/* set 'in finalise' flag */
- camel_stream_close (CAMEL_STREAM (emhs));
+ camel_stream_close (CAMEL_STREAM (emhs), NULL);
}
/* Chain up to parent's dispose() method. */
diff --git a/mail/em-inline-filter.c b/mail/em-inline-filter.c
index 835a022..3043214 100644
--- a/mail/em-inline-filter.c
+++ b/mail/em-inline-filter.c
@@ -145,7 +145,7 @@ emif_add_part(EMInlineFilter *emif, const gchar *data, gint len)
emif->data = g_byte_array_new();
dw = camel_data_wrapper_new();
- camel_data_wrapper_construct_from_stream(dw, mem);
+ camel_data_wrapper_construct_from_stream(dw, mem, NULL);
g_object_unref(mem);
if (emif_types[emif->state].plain && emif->base_type) {
diff --git a/mail/em-sync-stream.c b/mail/em-sync-stream.c
index 988f7b7..c685385 100644
--- a/mail/em-sync-stream.c
+++ b/mail/em-sync-stream.c
@@ -132,7 +132,10 @@ em_sync_stream_finalize (GObject *object)
}
static gssize
-emss_stream_write (CamelStream *stream, const gchar *string, gsize len)
+emss_stream_write (CamelStream *stream,
+ const gchar *string,
+ gsize len,
+ GError **error)
{
EMSyncStream *emss = EM_SYNC_STREAM (stream);
@@ -154,7 +157,8 @@ emss_stream_write (CamelStream *stream, const gchar *string, gsize len)
}
static gint
-emss_stream_flush (CamelStream *stream)
+emss_stream_flush (CamelStream *stream,
+ GError **error)
{
EMSyncStream *emss = EM_SYNC_STREAM (stream);
@@ -170,7 +174,8 @@ emss_stream_flush (CamelStream *stream)
}
static gint
-emss_stream_close (CamelStream *stream)
+emss_stream_close (CamelStream *stream,
+ GError **error)
{
EMSyncStream *emss = EM_SYNC_STREAM (stream);
diff --git a/mail/em-utils.c b/mail/em-utils.c
index e8ef993..2f34ac2 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -556,7 +556,10 @@ em_utils_flag_for_followup_completed (GtkWindow *parent, CamelFolder *folder, GP
/* This kind of sucks, because for various reasons most callers need to run synchronously
in the gui thread, however this could take a long, blocking time, to run */
static gint
-em_utils_write_messages_to_stream(CamelFolder *folder, GPtrArray *uids, CamelStream *stream)
+em_utils_write_messages_to_stream (CamelFolder *folder,
+ GPtrArray *uids,
+ CamelStream *stream,
+ GError **error)
{
CamelStream *filtered_stream;
CamelMimeFilter *from_filter;
@@ -581,10 +584,10 @@ em_utils_write_messages_to_stream(CamelFolder *folder, GPtrArray *uids, CamelStr
/* we need to flush after each stream write since we are writing to the same stream */
from = camel_mime_message_build_mbox_from(message);
- if (camel_stream_write_string(stream, from) == -1
- || camel_stream_flush(stream) == -1
- || camel_data_wrapper_write_to_stream((CamelDataWrapper *)message, filtered_stream) == -1
- || camel_stream_flush(filtered_stream) == -1)
+ if (camel_stream_write_string(stream, from, error) == -1
+ || camel_stream_flush(stream, error) == -1
+ || camel_data_wrapper_write_to_stream((CamelDataWrapper *)message, filtered_stream, error) == -1
+ || camel_stream_flush(filtered_stream, error) == -1)
res = -1;
g_free(from);
@@ -601,21 +604,24 @@ em_utils_write_messages_to_stream(CamelFolder *folder, GPtrArray *uids, CamelStr
/* This kind of sucks, because for various reasons most callers need to run synchronously
in the gui thread, however this could take a long, blocking time, to run */
-static gint
-em_utils_read_messages_from_stream(CamelFolder *folder, CamelStream *stream)
+static gboolean
+em_utils_read_messages_from_stream (CamelFolder *folder,
+ CamelStream *stream,
+ GError **error)
{
CamelMimeParser *mp = camel_mime_parser_new();
gboolean success = FALSE;
- camel_mime_parser_scan_from(mp, TRUE);
- camel_mime_parser_init_with_stream(mp, stream);
+ camel_mime_parser_scan_from (mp, TRUE);
+ if (camel_mime_parser_init_with_stream (mp, stream, error) == -1)
+ return FALSE;
while (camel_mime_parser_step(mp, NULL, NULL) == CAMEL_MIME_PARSER_STATE_FROM) {
CamelMimeMessage *msg;
/* NB: de-from filter, once written */
msg = camel_mime_message_new();
- if (camel_mime_part_construct_from_parser((CamelMimePart *)msg, mp) == -1) {
+ if (camel_mime_part_construct_from_parser((CamelMimePart *)msg, mp, error) == -1) {
g_object_unref(msg);
break;
}
@@ -632,7 +638,7 @@ em_utils_read_messages_from_stream(CamelFolder *folder, CamelStream *stream)
g_object_unref(mp);
- return success ? 0 : -1;
+ return success;
}
/**
@@ -640,53 +646,68 @@ em_utils_read_messages_from_stream(CamelFolder *folder, CamelStream *stream)
* @data: selection data
* @folder: folder containign messages to copy into the selection
* @uids: uids of the messages to copy into the selection
+ * @error: return location for a #GError, or %NULL
*
* Creates a mailbox-format selection.
* Warning: Could be BIG!
* Warning: This could block the ui for an extended period.
**/
-void
+gboolean
em_utils_selection_set_mailbox (GtkSelectionData *data,
CamelFolder *folder,
- GPtrArray *uids)
+ GPtrArray *uids,
+ GError **error)
{
CamelStream *stream;
GByteArray *buffer;
+ gint retval;
buffer = g_byte_array_new ();
stream = camel_stream_mem_new_with_byte_array (buffer);
- if (em_utils_write_messages_to_stream (folder, uids, stream) == 0)
+ retval = em_utils_write_messages_to_stream (
+ folder, uids, stream, error);
+
+ if (retval == 0)
gtk_selection_data_set (
data, data->target, 8,
buffer->data, buffer->len);
g_object_unref (stream);
+
+ return (retval == 0);
}
/**
* em_utils_selection_get_mailbox:
* @data: selection data
* @folder:
+ * @error: return location for a #GError, or %NULL
*
* Receive a mailbox selection/dnd
* Warning: Could be BIG!
* Warning: This could block the ui for an extended period.
* FIXME: Exceptions?
**/
-void
-em_utils_selection_get_mailbox(GtkSelectionData *data, CamelFolder *folder)
+gboolean
+em_utils_selection_get_mailbox (GtkSelectionData *data,
+ CamelFolder *folder,
+ GError **error)
{
CamelStream *stream;
+ gboolean success;
if (data->data == NULL || data->length == -1)
- return;
+ return TRUE;
/* TODO: a stream mem with read-only access to existing data? */
/* NB: Although copying would let us run this async ... which it should */
- stream = (CamelStream *)camel_stream_mem_new_with_buffer((gchar *)data->data, data->length);
- em_utils_read_messages_from_stream(folder, stream);
- g_object_unref(stream);
+ stream = camel_stream_mem_new_with_buffer (
+ (gchar *)data->data, data->length);
+ success = em_utils_read_messages_from_stream (folder, stream, error);
+ g_object_unref (stream);
+
+ return success;
}
/**
@@ -707,7 +728,7 @@ em_utils_selection_get_message(GtkSelectionData *data, CamelFolder *folder)
stream = (CamelStream *)camel_stream_mem_new_with_buffer((gchar *)data->data, data->length);
msg = camel_mime_message_new();
- if (camel_data_wrapper_construct_from_stream((CamelDataWrapper *)msg, stream) == 0)
+ if (camel_data_wrapper_construct_from_stream((CamelDataWrapper *)msg, stream, NULL) == 0)
camel_folder_append_message(folder, msg, NULL, NULL, NULL);
g_object_unref(msg);
g_object_unref(stream);
@@ -844,7 +865,7 @@ em_utils_selection_set_urilist(GtkSelectionData *data, CamelFolder *folder, GPtr
g_free(tmpfile);
fstream = camel_stream_fs_new_with_fd(fd);
if (fstream) {
- if (em_utils_write_messages_to_stream(folder, uids, fstream) == 0) {
+ if (em_utils_write_messages_to_stream(folder, uids, fstream, NULL) == 0) {
/* terminate with \r\n to be compliant with the spec */
gchar *uri_crlf = g_strconcat(uri, "\r\n", NULL);
@@ -874,7 +895,8 @@ em_utils_selection_get_urilist(GtkSelectionData *data, CamelFolder *folder)
{
CamelStream *stream;
CamelURL *url;
- gint fd, i, res = 0;
+ gint fd, i;
+ gboolean success = TRUE;
gchar *tmp, **uris;
d(printf(" * drop uri list\n"));
@@ -882,7 +904,7 @@ em_utils_selection_get_urilist(GtkSelectionData *data, CamelFolder *folder)
tmp = g_strndup((gchar *)data->data, data->length);
uris = g_strsplit(tmp, "\n", 0);
g_free(tmp);
- for (i=0;res == 0 && uris[i];i++) {
+ for (i=0;success && uris[i];i++) {
g_strstrip(uris[i]);
if (uris[i][0] == '#')
continue;
@@ -895,7 +917,7 @@ em_utils_selection_get_urilist(GtkSelectionData *data, CamelFolder *folder)
&& (fd = g_open(url->path, O_RDONLY | O_BINARY, 0)) != -1) {
stream = camel_stream_fs_new_with_fd(fd);
if (stream) {
- res = em_utils_read_messages_from_stream(folder, stream);
+ success = em_utils_read_messages_from_stream(folder, stream, NULL);
g_object_unref(stream);
} else
close(fd);
@@ -1243,15 +1265,15 @@ gchar *
em_utils_message_to_html (CamelMimeMessage *message, const gchar *credits, guint32 flags, gssize *len, EMFormat *source, const gchar *append, guint32 *validity_found)
{
EMFormatQuote *emfq;
- CamelStreamMem *mem;
+ CamelStream *stream;
GByteArray *buf;
gchar *text;
buf = g_byte_array_new ();
- mem = (CamelStreamMem *) camel_stream_mem_new ();
- camel_stream_mem_set_byte_array (mem, buf);
+ stream = camel_stream_mem_new ();
+ camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), buf);
- emfq = em_format_quote_new(credits, (CamelStream *)mem, flags);
+ emfq = em_format_quote_new (credits, stream, flags);
((EMFormat *) emfq)->composer = TRUE;
if (!source) {
@@ -1272,10 +1294,10 @@ em_utils_message_to_html (CamelMimeMessage *message, const gchar *credits, guint
g_object_unref (emfq);
if (append && *append)
- camel_stream_write ((CamelStream*)mem, append, strlen (append));
+ camel_stream_write (stream, append, strlen (append), NULL);
- camel_stream_write((CamelStream *)mem, "", 1);
- g_object_unref(mem);
+ camel_stream_write (stream, "", 1, NULL);
+ g_object_unref (stream);
text = (gchar *)buf->data;
if (len)
diff --git a/mail/em-utils.h b/mail/em-utils.h
index 699dceb..34505c8 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -54,8 +54,8 @@ void em_utils_flag_for_followup_completed (GtkWindow *parent, CamelFolder *folde
/* This stuff that follows probably doesn't belong here, then again, the stuff above probably belongs elsewhere */
-void em_utils_selection_set_mailbox(GtkSelectionData *data, CamelFolder *folder, GPtrArray *uids);
-void em_utils_selection_get_mailbox(GtkSelectionData *data, CamelFolder *folder);
+gboolean em_utils_selection_set_mailbox(GtkSelectionData *data, CamelFolder *folder, GPtrArray *uids, GError **error);
+gboolean em_utils_selection_get_mailbox(GtkSelectionData *data, CamelFolder *folder, GError **error);
void em_utils_selection_get_message(GtkSelectionData *data, CamelFolder *folder);
/* FIXME: be nice if these also worked on CamelFolder's, no easy way to get uri from folder yet tho */
void em_utils_selection_set_uidlist(GtkSelectionData *data, const gchar *uri, GPtrArray *uids);
diff --git a/mail/importers/mail-importer.c b/mail/importers/mail-importer.c
index 99c5d35..c24ce7d 100644
--- a/mail/importers/mail-importer.c
+++ b/mail/importers/mail-importer.c
@@ -161,7 +161,7 @@ import_mbox_exec (struct _import_mbox_msg *m)
camel_operation_progress(NULL, pc);
msg = camel_mime_message_new();
- if (camel_mime_part_construct_from_parser((CamelMimePart *)msg, mp) == -1) {
+ if (camel_mime_part_construct_from_parser((CamelMimePart *)msg, mp, NULL) == -1) {
/* set exception? */
g_object_unref(msg);
break;
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index d033799..f5c7bd1 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -2146,17 +2146,16 @@ save_messages_exec (struct _save_messages_msg *m)
/* we need to flush after each stream write since we are writing to the same fd */
from = camel_mime_message_build_mbox_from(message);
- if (camel_stream_write_string(stream, from) == -1
- || camel_stream_flush(stream) == -1
- || camel_data_wrapper_write_to_stream((CamelDataWrapper *)message, filtered_stream) == -1
- || camel_stream_flush(filtered_stream) == -1
- || camel_stream_write_string(stream, "\n") == -1
- || camel_stream_flush(stream) == -1) {
- g_set_error (
+ if (camel_stream_write_string(stream, from, &m->base.error) == -1
+ || camel_stream_flush(stream, &m->base.error) == -1
+ || camel_data_wrapper_write_to_stream((CamelDataWrapper *)message, filtered_stream, &m->base.error) == -1
+ || camel_stream_flush(filtered_stream, &m->base.error) == -1
+ || camel_stream_write_string(stream, "\n", &m->base.error) == -1
+ || camel_stream_flush(stream, &m->base.error) == -1) {
+ g_prefix_error (
&m->base.error,
- CAMEL_ERROR, CAMEL_ERROR_SYSTEM,
- _("Error saving messages to: %s:\n %s"),
- m->path, g_strerror (errno));
+ _("Error saving messages to: %s:\n "),
+ m->path);
g_free(from);
g_object_unref((CamelObject *)message);
break;
@@ -2269,13 +2268,9 @@ save_part_exec (struct _save_part_msg *m)
content = camel_medium_get_content (CAMEL_MEDIUM (m->part));
- if (camel_data_wrapper_decode_to_stream (content, stream) == -1
- || camel_stream_flush (stream) == -1)
- g_set_error (
- &m->base.error,
- CAMEL_ERROR, CAMEL_ERROR_SYSTEM,
- _("Could not write data: %s"),
- g_strerror (errno));
+ if (camel_data_wrapper_decode_to_stream (content, stream, &m->base.error) == -1
+ || camel_stream_flush (stream, &m->base.error) == -1)
+ g_prefix_error (&m->base.error, _("Could not write data: "));
g_object_unref (stream);
}
diff --git a/mail/message-list.c b/mail/message-list.c
index b84fa72..85c3a1d 100644
--- a/mail/message-list.c
+++ b/mail/message-list.c
@@ -1985,7 +1985,7 @@ ml_selection_get(GtkWidget *widget, GtkSelectionData *data, guint info, guint ti
if (info & 2) {
/* text/plain */
d(printf("setting text/plain selection for uids\n"));
- em_utils_selection_set_mailbox(data, selection->folder, selection->uids);
+ em_utils_selection_set_mailbox(data, selection->folder, selection->uids, NULL);
} else {
/* x-uid-list */
d(printf("setting x-uid-list selection for uids\n"));
diff --git a/modules/calendar/e-cal-attachment-handler.c b/modules/calendar/e-cal-attachment-handler.c
index c18795f..b11712d 100644
--- a/modules/calendar/e-cal-attachment-handler.c
+++ b/modules/calendar/e-cal-attachment-handler.c
@@ -80,7 +80,7 @@ attachment_handler_get_component (EAttachment *attachment)
stream = camel_stream_mem_new ();
camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), buffer);
wrapper = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
- camel_data_wrapper_decode_to_stream (wrapper, stream);
+ camel_data_wrapper_decode_to_stream (wrapper, stream, NULL);
g_object_unref (stream);
component = e_cal_util_parse_ics_string ((gchar *) buffer->data);
diff --git a/modules/mail/e-mail-attachment-handler.c b/modules/mail/e-mail-attachment-handler.c
index 794ee78..be65975 100644
--- a/modules/mail/e-mail-attachment-handler.c
+++ b/modules/mail/e-mail-attachment-handler.c
@@ -182,13 +182,13 @@ mail_attachment_handler_message_rfc822 (EAttachmentView *view,
length = gtk_selection_data_get_length (selection_data);
stream = camel_stream_mem_new ();
- camel_stream_write (stream, data, length);
- camel_stream_reset (stream);
+ camel_stream_write (stream, data, length, NULL);
+ camel_stream_reset (stream, NULL);
message = camel_mime_message_new ();
wrapper = CAMEL_DATA_WRAPPER (message);
- if (camel_data_wrapper_construct_from_stream (wrapper, stream) == -1)
+ if (camel_data_wrapper_construct_from_stream (wrapper, stream, NULL) == -1)
goto exit;
store = e_attachment_view_get_store (view);
diff --git a/plugins/audio-inline/audio-inline.c b/plugins/audio-inline/audio-inline.c
index af78668..3ab99c9 100644
--- a/plugins/audio-inline/audio-inline.c
+++ b/plugins/audio-inline/audio-inline.c
@@ -202,10 +202,10 @@ org_gnome_audio_inline_play_clicked (GtkWidget *button, EMFormatHTMLPObject *pob
d(printf ("audio inline formatter: write to temp file %s\n", po->filename));
- stream = camel_stream_fs_new_with_name (po->filename, O_RDWR | O_CREAT | O_TRUNC, 0600);
+ stream = camel_stream_fs_new_with_name (po->filename, O_RDWR | O_CREAT | O_TRUNC, 0600, NULL);
data = camel_medium_get_content (CAMEL_MEDIUM (po->part));
- camel_data_wrapper_decode_to_stream (data, stream);
- camel_stream_flush (stream);
+ camel_data_wrapper_decode_to_stream (data, stream, NULL);
+ camel_stream_flush (stream, NULL);
g_object_unref (stream);
d(printf ("audio inline formatter: init gst playbin\n"));
@@ -305,5 +305,5 @@ org_gnome_audio_inline_format (gpointer ep, EMFormatHookTarget *t)
pobj->object.free = org_gnome_audio_inline_pobject_free;
pobj->target_state = GST_STATE_NULL;
- camel_stream_printf (t->stream, "<object classid=%s></object>\n", classid);
+ camel_stream_printf (t->stream, NULL, "<object classid=%s></object>\n", classid);
}
diff --git a/plugins/bogo-junk-plugin/bf-junk-filter.c b/plugins/bogo-junk-plugin/bf-junk-filter.c
index d668eba..949864f 100644
--- a/plugins/bogo-junk-plugin/bf-junk-filter.c
+++ b/plugins/bogo-junk-plugin/bf-junk-filter.c
@@ -84,7 +84,7 @@ static gboolean em_junk_bf_unicode = TRUE;
static void
init_db (void)
{
- CamelStream *stream = camel_stream_fs_new_with_name (WELCOME_MESSAGE, O_RDONLY, 0);
+ CamelStream *stream = camel_stream_fs_new_with_name (WELCOME_MESSAGE, O_RDONLY, 0, NULL);
CamelMimeParser *parser = camel_mime_parser_new ();
CamelMimeMessage *msg = camel_mime_message_new ();
const gchar *argv[] = {
@@ -94,11 +94,11 @@ init_db (void)
NULL
};
- camel_mime_parser_init_with_stream (parser, stream);
+ camel_mime_parser_init_with_stream (parser, stream, NULL);
camel_mime_parser_scan_from (parser, FALSE);
g_object_unref (stream);
- camel_mime_part_construct_from_parser ((CamelMimePart *) msg, parser);
+ camel_mime_part_construct_from_parser ((CamelMimePart *) msg, parser, NULL);
g_object_unref (parser);
d(fprintf (stderr, "Initing the bogofilter DB with Welcome message\n"));
@@ -165,9 +165,9 @@ retry:
}
stream = camel_stream_fs_new_with_fd (bf_in);
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (msg), stream);
- camel_stream_flush (stream);
- camel_stream_close (stream);
+ camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (msg), stream, NULL);
+ camel_stream_flush (stream, NULL);
+ camel_stream_close (stream, NULL);
g_object_unref (stream);
#ifndef G_OS_WIN32
diff --git a/plugins/groupwise-features/install-shared.c b/plugins/groupwise-features/install-shared.c
index 8d3f2f9..c776824 100644
--- a/plugins/groupwise-features/install-shared.c
+++ b/plugins/groupwise-features/install-shared.c
@@ -207,8 +207,8 @@ org_gnome_popup_wizard (EPlugin *ep, EMEventTargetMessage *target)
byte_array = g_byte_array_new ();
content = camel_stream_mem_new_with_byte_array (byte_array);
- camel_data_wrapper_write_to_stream(dw, content);
- camel_stream_write(content, "", 1);
+ camel_data_wrapper_write_to_stream(dw, content, NULL);
+ camel_stream_write(content, "", 1, NULL);
from_addr = camel_mime_message_get_from ((CamelMimeMessage *)target->message);
if (from_addr && camel_internet_address_get(from_addr, 0, &name, &email)) {
diff --git a/plugins/image-inline/image-inline.c b/plugins/image-inline/image-inline.c
index 9574eea..e9782ce 100644
--- a/plugins/image-inline/image-inline.c
+++ b/plugins/image-inline/image-inline.c
@@ -222,7 +222,7 @@ org_gnome_image_inline_decode (ImageInlinePObject *image_object)
/* Stream takes ownership of the byte array. */
stream = camel_stream_mem_new_with_byte_array (array);
data_wrapper = camel_medium_get_content (medium);
- camel_data_wrapper_decode_to_stream (data_wrapper, stream);
+ camel_data_wrapper_decode_to_stream (data_wrapper, stream, NULL);
/* Don't trust the content type in the MIME part. It could
* be lying or it could be "application/octet-stream". Let
@@ -321,7 +321,8 @@ org_gnome_image_inline_format (gpointer ep, EMFormatHookTarget *target)
org_gnome_image_inline_decode (image_object);
camel_stream_printf (
- target->stream, "<object classid=%s></object>", classid);
+ target->stream, NULL,
+ "<object classid=%s></object>", classid);
g_free (classid);
}
diff --git a/plugins/itip-formatter/itip-formatter.c b/plugins/itip-formatter/itip-formatter.c
index 7e8f0cd..d0f1e53 100644
--- a/plugins/itip-formatter/itip-formatter.c
+++ b/plugins/itip-formatter/itip-formatter.c
@@ -133,7 +133,7 @@ struct _itip_puri {
void format_itip (EPlugin *ep, EMFormatHookTarget *target);
GtkWidget *itip_formatter_page_factory (EPlugin *ep, EConfigHookItemFactoryData *hook_data);
-static void itip_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri);
+static gboolean itip_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri, GError **error);
typedef struct {
struct _itip_puri *puri;
@@ -2539,7 +2539,7 @@ format_itip (EPlugin *ep, EMFormatHookTarget *target)
content = camel_medium_get_content ((CamelMedium *) target->part);
byte_array = g_byte_array_new ();
stream = camel_stream_mem_new_with_byte_array (byte_array);
- camel_data_wrapper_decode_to_stream (content, stream);
+ camel_data_wrapper_decode_to_stream (content, stream, NULL);
if (byte_array->len == 0)
puri->vcalendar = NULL;
@@ -2547,9 +2547,9 @@ format_itip (EPlugin *ep, EMFormatHookTarget *target)
puri->vcalendar = g_strndup ((gchar *)byte_array->data, byte_array->len);
g_object_unref (stream);
- camel_stream_printf (target->stream, "<table border=0 width=\"100%%\" cellpadding=3><tr>");
- camel_stream_printf (target->stream, "<td valign=top><object classid=\"%s\"></object></td><td width=100%% valign=top>", classid);
- camel_stream_printf (target->stream, "</td></tr></table>");
+ camel_stream_printf (target->stream, NULL, "<table border=0 width=\"100%%\" cellpadding=3><tr>");
+ camel_stream_printf (target->stream, NULL, "<td valign=top><object classid=\"%s\"></object></td><td width=100%% valign=top>", classid);
+ camel_stream_printf (target->stream, NULL, "</td></tr></table>");
g_free (classid);
}
@@ -2712,13 +2712,21 @@ itip_formatter_page_factory (EPlugin *ep, EConfigHookItemFactoryData *hook_data)
return page;
}
-static void
-itip_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri)
+static gboolean
+itip_attachment_frame (EMFormat *emf,
+ CamelStream *stream,
+ EMFormatPURI *puri,
+ GError **error)
{
struct _itip_puri *info = (struct _itip_puri *)puri;
+ gboolean success;
d(printf("writing to frame content, handler is '%s'\n", info->handle->mime_type));
- info->handle->handler(emf, stream, info->puri.part, info->handle);
- camel_stream_close(stream);
+ success = info->handle->handler (
+ emf, stream, info->puri.part, info->handle, error);
+
+ camel_stream_close (stream, NULL);
+
+ return success;
}
diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c
index b3e517e..2f9c540 100644
--- a/plugins/mail-to-task/mail-to-task.c
+++ b/plugins/mail-to-task/mail-to-task.c
@@ -203,7 +203,7 @@ set_description (ECalComponent *comp, CamelMimeMessage *message)
byte_array = g_byte_array_new ();
stream = camel_stream_mem_new_with_byte_array (byte_array);
- camel_data_wrapper_decode_to_stream (content, stream);
+ camel_data_wrapper_decode_to_stream (content, stream, NULL);
str = g_strndup ((const gchar *)byte_array->data, byte_array->len);
g_object_unref (stream);
diff --git a/plugins/prefer-plain/prefer-plain.c b/plugins/prefer-plain/prefer-plain.c
index 77cf072..3b9082f 100644
--- a/plugins/prefer-plain/prefer-plain.c
+++ b/plugins/prefer-plain/prefer-plain.c
@@ -68,9 +68,9 @@ make_part_attachment (EMFormat *format, CamelStream *stream, CamelMimePart *part
g_free (str);
}
- em_format_part_as (format, stream, part, "application/octet-stream");
+ em_format_part_as (format, stream, part, "application/octet-stream", NULL);
} else
- em_format_part (format, stream, part);
+ em_format_part (format, stream, part, NULL);
g_string_truncate (format->part_id, partidlen);
}
@@ -82,7 +82,7 @@ org_gnome_prefer_plain_text_html (gpointer ep, EMFormatHookTarget *t)
if (epp_mode != EPP_TEXT
|| strstr (t->format->part_id->str, ".alternative-prefer-plain.") != NULL
|| em_format_is_inline (t->format, t->format->part_id->str, t->part, &(t->item->handler)))
- t->item->handler.old->handler (t->format, t->stream, t->part, t->item->handler.old);
+ t->item->handler.old->handler (t->format, t->stream, t->part, t->item->handler.old, NULL);
else if (epp_show_suppressed)
make_part_attachment (t->format, t->stream, t->part, -1);
}
@@ -157,14 +157,14 @@ org_gnome_prefer_plain_multipart_alternative(gpointer ep, EMFormatHookTarget *t)
if (display_part && have_plain && nparts == 2) {
g_string_append_printf (t->format->part_id, ".alternative-prefer-plain.%d", displayid);
- em_format_part_as (t->format, t->stream, display_part, "text/html");
+ em_format_part_as (t->format, t->stream, display_part, "text/html", NULL);
g_string_truncate (t->format->part_id, partidlen);
} else {
- t->item->handler.old->handler (t->format, t->stream, t->part, t->item->handler.old);
+ t->item->handler.old->handler (t->format, t->stream, t->part, t->item->handler.old, NULL);
}
return;
} else if (!CAMEL_IS_MULTIPART(mp)) {
- em_format_format_source(t->format, t->stream, t->part);
+ em_format_format_source(t->format, t->stream, t->part, NULL);
return;
}
@@ -181,7 +181,7 @@ org_gnome_prefer_plain_multipart_alternative(gpointer ep, EMFormatHookTarget *t)
/* if we found a text part, show it */
if (display_part) {
g_string_append_printf(t->format->part_id, ".alternative-prefer-plain.%d", displayid);
- em_format_part_as(t->format, t->stream, display_part, "text/plain");
+ em_format_part_as(t->format, t->stream, display_part, "text/plain", NULL);
g_string_truncate(t->format->part_id, partidlen);
}
diff --git a/plugins/pst-import/pst-importer.c b/plugins/pst-import/pst-importer.c
index eee8183..37cc223 100644
--- a/plugins/pst-import/pst-importer.c
+++ b/plugins/pst-import/pst-importer.c
@@ -815,7 +815,7 @@ pst_process_email (PstImporter *m, pst_item *item)
/*g_message (" Email headers... %s...", item->email->header);*/
stream = camel_stream_mem_new_with_buffer (item->email->header.str, strlen (item->email->header.str));
- if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)msg, stream) == -1)
+ if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)msg, stream, NULL) == -1)
g_warning ("Error reading headers, skipped");
} else {
@@ -1218,7 +1218,7 @@ set_cal_attachments (ECal *cal, ECalComponent *ec, PstImporter *m, pst_item_atta
continue;
}
- if (!(stream = camel_stream_fs_new_with_name (path, O_WRONLY | O_CREAT | O_TRUNC, 0666))) {
+ if (!(stream = camel_stream_fs_new_with_name (path, O_WRONLY | O_CREAT | O_TRUNC, 0666, NULL))) {
g_warning ("Could not create stream for file %s - %s", path, g_strerror (errno));
attach = attach->next;
continue;
@@ -1226,8 +1226,8 @@ set_cal_attachments (ECal *cal, ECalComponent *ec, PstImporter *m, pst_item_atta
content = camel_medium_get_content (CAMEL_MEDIUM (part));
- if (camel_data_wrapper_decode_to_stream (content, stream) == -1
- || camel_stream_flush (stream) == -1)
+ if (camel_data_wrapper_decode_to_stream (content, stream, NULL) == -1
+ || camel_stream_flush (stream, NULL) == -1)
{
g_warning ("Could not write attachment to %s: %s", path, g_strerror (errno));
g_object_unref (stream);
diff --git a/plugins/sa-junk-plugin/em-junk-filter.c b/plugins/sa-junk-plugin/em-junk-filter.c
index 9256405..ecc1c6d 100644
--- a/plugins/sa-junk-plugin/em-junk-filter.c
+++ b/plugins/sa-junk-plugin/em-junk-filter.c
@@ -187,12 +187,12 @@ pipe_to_sa_full (CamelMimeMessage *msg, const gchar *in, const gchar **argv, gin
if (msg) {
stream = camel_stream_fs_new_with_fd (fds[1]);
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (msg), stream);
- camel_stream_flush (stream);
- camel_stream_close (stream);
+ camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (msg), stream, NULL);
+ camel_stream_flush (stream, NULL);
+ camel_stream_close (stream, NULL);
g_object_unref (stream);
} else if (in) {
- camel_write (fds[1], in, strlen (in));
+ camel_write (fds[1], in, strlen (in), NULL);
close (fds[1]);
}
@@ -204,7 +204,7 @@ pipe_to_sa_full (CamelMimeMessage *msg, const gchar *in, const gchar **argv, gin
memstream = (CamelStreamMem *) camel_stream_mem_new ();
camel_stream_mem_set_byte_array (memstream, output_buffer);
- camel_stream_write_to_stream (stream, (CamelStream *) memstream);
+ camel_stream_write_to_stream (stream, (CamelStream *) memstream, NULL);
g_object_unref (stream);
g_byte_array_append (output_buffer, (guchar *)"", 1);
diff --git a/plugins/templates/templates.c b/plugins/templates/templates.c
index 8421967..35aeb31 100644
--- a/plugins/templates/templates.c
+++ b/plugins/templates/templates.c
@@ -474,7 +474,6 @@ create_new_message (CamelFolder *folder, const gchar *uid, CamelMimeMessage *mes
CamelStream *mem;
GQueue *header_queue;
GList *link;
- gchar *cont;
g_return_if_fail (data != NULL);
g_return_if_fail (message != NULL);
@@ -488,9 +487,11 @@ create_new_message (CamelFolder *folder, const gchar *uid, CamelMimeMessage *mes
/* make the exact copy of the template message, with all
its attachments and message structure */
mem = camel_stream_mem_new ();
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (template), mem);
- camel_stream_reset (mem);
- camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (new), mem);
+ camel_data_wrapper_write_to_stream (
+ CAMEL_DATA_WRAPPER (template), mem, NULL);
+ camel_stream_reset (mem, NULL);
+ camel_data_wrapper_construct_from_stream (
+ CAMEL_DATA_WRAPPER (new), mem, NULL);
g_object_unref (mem);
/* Add the headers from the message we are replying to, so CC and that
diff --git a/plugins/tnef-attachments/tnef-plugin.c b/plugins/tnef-attachments/tnef-plugin.c
index 8a81ca1..63368ed 100644
--- a/plugins/tnef-attachments/tnef-plugin.c
+++ b/plugins/tnef-attachments/tnef-plugin.c
@@ -89,14 +89,14 @@ org_gnome_format_tnef(gpointer ep, EMFormatHookTarget *t)
name = g_build_filename(tmpdir, ".evo-attachment.tnef", NULL);
- out = camel_stream_fs_new_with_name(name, O_RDWR|O_CREAT, 0666);
+ out = camel_stream_fs_new_with_name(name, O_RDWR|O_CREAT, 0666, NULL);
if (out == NULL)
goto fail;
content = camel_medium_get_content((CamelMedium *)t->part);
if (content == NULL)
goto fail;
- if (camel_data_wrapper_decode_to_stream(content, out) == -1
- || camel_stream_close(out) == -1) {
+ if (camel_data_wrapper_decode_to_stream(content, out, NULL) == -1
+ || camel_stream_close(out, NULL) == -1) {
g_object_unref(out);
goto fail;
}
@@ -139,9 +139,9 @@ org_gnome_format_tnef(gpointer ep, EMFormatHookTarget *t)
path = g_build_filename(tmpdir, d->d_name, NULL);
- stream = camel_stream_fs_new_with_name(path, O_RDONLY, 0);
+ stream = camel_stream_fs_new_with_name(path, O_RDONLY, 0, NULL);
content = camel_data_wrapper_new();
- camel_data_wrapper_construct_from_stream(content, stream);
+ camel_data_wrapper_construct_from_stream(content, stream, NULL);
g_object_unref(stream);
part = camel_mime_part_new();
@@ -168,9 +168,9 @@ org_gnome_format_tnef(gpointer ep, EMFormatHookTarget *t)
g_string_append_printf(t->format->part_id, ".tnef");
if (camel_multipart_get_number(mp) > 0)
- em_format_part_as(t->format, t->stream, mainpart, "multipart/mixed");
+ em_format_part_as(t->format, t->stream, mainpart, "multipart/mixed", NULL);
else if (t->item->handler.old)
- t->item->handler.old->handler(t->format, t->stream, t->part, t->item->handler.old);
+ t->item->handler.old->handler(t->format, t->stream, t->part, t->item->handler.old, NULL);
g_string_truncate(t->format->part_id, len);
@@ -180,7 +180,7 @@ org_gnome_format_tnef(gpointer ep, EMFormatHookTarget *t)
goto ok;
fail:
if (t->item->handler.old)
- t->item->handler.old->handler(t->format, t->stream, t->part, t->item->handler.old);
+ t->item->handler.old->handler(t->format, t->stream, t->part, t->item->handler.old, NULL);
ok:
g_free(name);
g_free(tmpdir);
diff --git a/plugins/vcard-inline/vcard-inline.c b/plugins/vcard-inline/vcard-inline.c
index 478a65c..ef222bb 100644
--- a/plugins/vcard-inline/vcard-inline.c
+++ b/plugins/vcard-inline/vcard-inline.c
@@ -93,7 +93,7 @@ org_gnome_vcard_inline_decode (VCardInlinePObject *vcard_object,
/* Stream takes ownership of the byte array. */
stream = camel_stream_mem_new_with_byte_array (array);
data_wrapper = camel_medium_get_content (medium);
- camel_data_wrapper_decode_to_stream (data_wrapper, stream);
+ camel_data_wrapper_decode_to_stream (data_wrapper, stream, NULL);
/* because the result is not NULL-terminated */
g_byte_array_append (array, padding, 2);
@@ -284,7 +284,8 @@ org_gnome_vcard_inline_format (gpointer ep, EMFormatHookTarget *target)
org_gnome_vcard_inline_decode (vcard_object, target->part);
camel_stream_printf (
- target->stream, "<object classid=%s></object>", classid);
+ target->stream, NULL,
+ "<object classid=%s></object>", classid);
g_free (classid);
}
diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c
index a60bff2..e2aeb7a 100644
--- a/widgets/misc/e-attachment.c
+++ b/widgets/misc/e-attachment.c
@@ -1040,7 +1040,8 @@ e_attachment_add_to_multipart (EAttachment *attachment,
CAMEL_BESTENC_GET_ENCODING);
camel_stream_filter_add (
CAMEL_STREAM_FILTER (filtered_stream), filter);
- camel_data_wrapper_decode_to_stream (wrapper, filtered_stream);
+ camel_data_wrapper_decode_to_stream (
+ wrapper, filtered_stream, NULL);
g_object_unref (filtered_stream);
g_object_unref (stream);
@@ -1515,9 +1516,9 @@ attachment_load_finish (LoadContext *load_context)
size = g_memory_output_stream_get_data_size (output_stream);
stream = camel_stream_mem_new_with_buffer (data, size);
- camel_data_wrapper_construct_from_stream (wrapper, stream);
+ camel_data_wrapper_construct_from_stream (wrapper, stream, NULL);
camel_data_wrapper_set_mime_type (wrapper, mime_type);
- camel_stream_close (stream);
+ camel_stream_close (stream, NULL);
g_object_unref (stream);
mime_part = camel_mime_part_new ();
@@ -2435,7 +2436,7 @@ attachment_save_got_output_stream (SaveContext *save_context)
stream = camel_stream_mem_new ();
camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), buffer);
wrapper = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
- camel_data_wrapper_decode_to_stream (wrapper, stream);
+ camel_data_wrapper_decode_to_stream (wrapper, stream, NULL);
g_object_unref (stream);
/* Load the buffer into a GMemoryInputStream.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]