From cea054cd54d84479352a43bbabc19c9ce9af5efb Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 8 Aug 2008 04:26:12 +0000 Subject: Merge revisions 35747:35930 from trunk. svn path=/branches/kill-bonobo/; revision=35931 --- mail/em-format-html.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 5c76c5e861..bb2d176b6e 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -84,7 +84,6 @@ #define d(x) -#define EFH_TABLE_OPEN "" #define EFM_MESSAGE_START_ANAME "evolution#message#start" #define EFH_MESSAGE_START "" @@ -1868,7 +1867,7 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) GString *html; if (!(addrs = camel_header_address_decode (header->value, hdr_charset))) - return; + break; html = g_string_new(""); name = efh_format_address(efh, html, addrs, header->name); @@ -1883,7 +1882,7 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) GString *html; if (!(addrs = camel_header_address_decode (header->value, hdr_charset))) - return; + break; html = g_string_new(""); name = efh_format_address(efh, html, addrs, header->name); @@ -1942,15 +1941,30 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) 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"))) { - struct _camel_header_raw xmailer; + !g_ascii_strcasecmp (header->name, "X-Newsreader") || + !g_ascii_strcasecmp (header->name, "X-MimeOLE"))) { + struct _camel_header_raw xmailer, *use_header = NULL; + + if (!g_ascii_strcasecmp (header->name, "X-MimeOLE")) { + for (use_header = header->next; use_header; use_header = use_header->next) { + if (!g_ascii_strcasecmp (use_header->name, "X-Mailer") || + !g_ascii_strcasecmp (use_header->name, "User-Agent") || + !g_ascii_strcasecmp (use_header->name, "X-Newsreader")) { + /* even we have X-MimeOLE, then use rather the standard one, when available */ + break; + } + } + } + + if (!use_header) + use_header = header; xmailer.name = "X-Evolution-Mailer"; - xmailer.value = header->value; + xmailer.value = use_header->value; mailer_shown = TRUE; efh_format_header (emf, stream, part, &xmailer, h->flags, charset); - if (strstr(header->value, "Evolution")) + if (strstr(use_header->value, "Evolution")) have_icon = TRUE; } else if (!g_ascii_strcasecmp (header->name, "Face") && !face_decoded) { char *cp = header->value; @@ -2086,7 +2100,7 @@ static void efh_format_source(EMFormat *emf, CamelStream *stream, CamelMimePart camel_stream_filter_add(filtered_stream, html_filter); camel_object_unref(html_filter); - camel_stream_write_string((CamelStream *)stream, EFH_TABLE_OPEN ""; } else { - + if (flags & EM_FORMAT_HEADER_BOLD) { if (is_rtl) fmt = ""; @@ -1667,22 +1667,22 @@ static void canon_header_name (char *name) { char *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++; } } @@ -1707,22 +1707,22 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct break; } } - + label = _(name); - + if (addrspec) { struct _camel_header_address *addrs; GString *html; char *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, (char *)label); @@ -1732,7 +1732,7 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct flags |= EM_FORMAT_HTML_HEADER_NODEC; g_free (img); } - + camel_header_address_unref(addrs); txt = value = html->str; g_string_free(html, FALSE); @@ -1742,7 +1742,7 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct 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 */ @@ -1769,7 +1769,7 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct if (msg_offset) { char buf[256], *html; - + msg_offset += (local.tm_hour * 60) + local.tm_min; if (msg_offset >= (24 * 60) || msg_offset < 0) { /* translators: strftime format for local time equivalent in Date header display, with day */ @@ -1782,27 +1782,27 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct e_utf8_strftime(buf, sizeof(buf), msg, &local); g_free(msg); } - + html = camel_text_to_html(txt, efh->text_html_flags, 0); txt = value = g_strdup_printf("%s %s", html, buf); g_free(html); flags |= EM_FORMAT_HTML_HEADER_HTML; } - + flags |= 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) { @@ -1811,9 +1811,9 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct 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; @@ -1826,9 +1826,9 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct 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); } @@ -1850,7 +1850,7 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) char *header_sender = NULL, *header_from = NULL, *name; gboolean mail_from_delegate = FALSE; const char *hdr_charset; - + if (!part) return; @@ -1863,9 +1863,9 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) "\n" "
"); + camel_stream_write_string((CamelStream *)stream, ""); - break; } header = header->next; } + + if (header_sender && header_from && mail_from_delegate) { + camel_stream_printf(stream, ""); + } g_free (header_sender); g_free (header_from); @@ -1918,7 +1919,7 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) /* dump selected headers */ h = (EMFormatHeader *)emf->header_list.head; - if (h->next == NULL || emf->mode == EM_FORMAT_ALLHEADERS) { + if (emf->mode == EM_FORMAT_ALLHEADERS) { header = ((CamelMimePart *)part)->headers; while (header) { efh_format_header(emf, stream, part, header, EM_FORMAT_HTML_HEADER_NOCOLUMNS, charset); -- cgit v1.2.3 From 8d8e4ac1c23905892a42b779188c852fdead7f5f Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 7 Jan 2009 18:23:46 +0000 Subject: Tweak the EShell API. Disable File -> Close Window when there's only one window. Replace EMMessageBrowser with EMailBrowser. svn path=/branches/kill-bonobo/; revision=37009 --- mail/em-format-html.c | 1 - 1 file changed, 1 deletion(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 8aed5e814c..99377cce74 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -159,7 +159,6 @@ efh_init(GObject *o) gtk_html_set_default_content_type(efh->html, "text/html; charset=utf-8"); gtk_html_set_editable(efh->html, FALSE); - g_signal_connect(efh->html, "destroy", G_CALLBACK(efh_gtkhtml_destroy), efh); g_signal_connect(efh->html, "url_requested", G_CALLBACK(efh_url_requested), efh); g_signal_connect(efh->html, "object_requested", G_CALLBACK(efh_object_requested), efh); -- cgit v1.2.3 From f7e298665b02f72890c6681e6d21ef5601beccbb Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 15 Feb 2009 03:27:31 +0000 Subject: Merge revisions 37200:3266 from trunk. svn path=/branches/kill-bonobo/; revision=37270 --- mail/em-format-html.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 99377cce74..02e07939fc 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -493,9 +493,11 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) instream = camel_http_stream_new(CAMEL_HTTP_METHOD_GET, ((EMFormat *)job->format)->session, url); camel_http_stream_set_user_agent((CamelHttpStream *)instream, "CamelHttpStream/1.0 Evolution/" VERSION); - proxy = em_utils_get_proxy_uri(); - camel_http_stream_set_proxy((CamelHttpStream *)instream, proxy); - g_free(proxy); + proxy = em_utils_get_proxy_uri (job->u.uri); + if (proxy) { + camel_http_stream_set_proxy ((CamelHttpStream *)instream, proxy); + g_free (proxy); + } camel_operation_start(NULL, _("Retrieving `%s'"), job->u.uri); tmp_stream = (CamelHttpStream *)instream; content_type = camel_http_stream_get_content_type(tmp_stream); @@ -516,6 +518,10 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) costream = camel_data_cache_add(emfh_http_cache, EMFH_HTTP_CACHE_PATH, job->u.uri, NULL); do { + if (camel_operation_cancel_check (NULL)) { + n = -1; + break; + } /* FIXME: progress reporting in percentage, can we get the length always? do we care? */ n = camel_stream_read(instream, buffer, sizeof (buffer)); if (n > 0) { @@ -526,17 +532,12 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) camel_operation_progress(NULL, pc_complete); } d(printf(" read %d bytes\n", n)); - if (costream && camel_stream_write(costream, buffer, n) == -1) { - camel_data_cache_remove(emfh_http_cache, EMFH_HTTP_CACHE_PATH, job->u.uri, NULL); - camel_object_unref(costream); - costream = NULL; + if (costream && camel_stream_write (costream, buffer, n) == -1) { + n = -1; + break; } camel_stream_write(job->stream, buffer, n); - } else if (n < 0 && costream) { - camel_data_cache_remove(emfh_http_cache, EMFH_HTTP_CACHE_PATH, job->u.uri, NULL); - camel_object_unref(costream); - costream = NULL; } } while (n>0); @@ -544,8 +545,12 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) if (n == 0) camel_stream_close(job->stream); - if (costream) + if (costream) { + /* do not store broken files in a cache */ + if (n != 0) + camel_data_cache_remove(emfh_http_cache, EMFH_HTTP_CACHE_PATH, job->u.uri, NULL); camel_object_unref(costream); + } camel_object_unref(instream); done: @@ -1263,7 +1268,7 @@ efh_format_exec (struct _format_msg *m) if (handle) handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); handle = em_format_find_handler((EMFormat *)m->format, "x-evolution/message/post-header-closure"); - if (handle) + if (handle && !((EMFormat *)m->format)->print) handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); } -- cgit v1.2.3 From fd564be3203400024147469faaa7de0884861566 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 19 Feb 2009 01:36:04 +0000 Subject: Clean up the EMFormat stack. Add some GObject properties to bind to. Add some handy color conversion functions to e-util. svn path=/branches/kill-bonobo/; revision=37290 --- mail/em-format-html.c | 795 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 650 insertions(+), 145 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 02e07939fc..bafb82ae36 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -48,7 +48,6 @@ #include "e-util/e-util.h" #include -#include #include #include @@ -83,6 +82,10 @@ #define d(x) +#define EM_FORMAT_HTML_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), EM_TYPE_FORMAT_HTML, EMFormatHTMLPrivate)) + #define EFM_MESSAGE_START_ANAME "evolution#message#start" #define EFH_MESSAGE_START "" @@ -103,6 +106,27 @@ struct _EMFormatHTMLPrivate { EDList pending_jobs; GMutex *lock; + + GdkColor colors[EM_FORMAT_HTML_NUM_COLOR_TYPES]; + MailConfigHTTPMode image_loading_policy; + + guint load_images_now : 1; + guint only_local_photos : 1; + guint show_sender_photo : 1; +}; + +enum { + PROP_0, + PROP_BODY_COLOR, + PROP_CITATION_COLOR, + PROP_CONTENT_COLOR, + PROP_FRAME_COLOR, + PROP_HEADER_COLOR, + PROP_IMAGE_LOADING_POLICY, + PROP_MARK_CITATIONS, + PROP_ONLY_LOCAL_PHOTOS, + PROP_SHOW_SENDER_PHOTO, + PROP_TEXT_COLOR }; static void efh_url_requested(GtkHTML *html, const char *url, GtkHTMLStream *handle, EMFormatHTML *efh); @@ -122,7 +146,7 @@ static void efh_builtin_init(EMFormatHTMLClass *efhc); static void efh_write_image(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri); -static EMFormatClass *efh_parent; +static gpointer parent_class; static CamelDataCache *emfh_http_cache; #define EMFH_HTTP_CACHE_PATH "http" @@ -135,44 +159,6 @@ efh_free_cache(struct _EMFormatHTMLCache *efhc) g_free(efhc); } -static void -efh_init(GObject *o) -{ - EMFormatHTML *efh = (EMFormatHTML *)o; - - efh->priv = g_malloc0(sizeof(*efh->priv)); - - e_dlist_init(&efh->pending_object_list); - e_dlist_init(&efh->priv->pending_jobs); - efh->priv->lock = g_mutex_new(); - efh->priv->format_id = -1; - efh->priv->text_inline_parts = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) NULL, - (GDestroyNotify) efh_free_cache); - - efh->html = (GtkHTML *)gtk_html_new(); - gtk_html_set_blocking(efh->html, FALSE); - gtk_html_set_caret_first_focus_anchor (efh->html, EFM_MESSAGE_START_ANAME); - g_object_ref_sink(efh->html); - - gtk_html_set_default_content_type(efh->html, "text/html; charset=utf-8"); - gtk_html_set_editable(efh->html, FALSE); - - g_signal_connect(efh->html, "url_requested", G_CALLBACK(efh_url_requested), efh); - g_signal_connect(efh->html, "object_requested", G_CALLBACK(efh_object_requested), efh); - - efh->body_colour = 0xeeeeee; - efh->header_colour = 0xeeeeee; - efh->text_colour = 0; - efh->frame_colour = 0x3f3f3f; - efh->content_colour = 0xffffff; - efh->text_html_flags = CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES - | CAMEL_MIME_FILTER_TOHTML_MARK_CITATION; - efh->show_icon = TRUE; - efh->state = EM_FORMAT_HTML_STATE_NONE; -} - static void efh_gtkhtml_destroy(GtkHTML *html, EMFormatHTML *efh) { @@ -187,8 +173,8 @@ efh_gtkhtml_destroy(GtkHTML *html, EMFormatHTML *efh) if (efh->priv->format_id != -1) mail_msg_cancel(efh->priv->format_id); - if (efh->html) { - g_object_unref(efh->html); + if (efh->html != NULL) { + g_object_unref (efh->html); efh->html = NULL; } } @@ -205,121 +191,583 @@ efh_insert_cache(EMFormatHTML *efh, const char *partid) return efhc; } +static void +efh_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_BODY_COLOR: + em_format_html_set_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_BODY, + g_value_get_boxed (value)); + return; + + case PROP_CITATION_COLOR: + em_format_html_set_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_CITATION, + g_value_get_boxed (value)); + return; + + case PROP_CONTENT_COLOR: + em_format_html_set_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_CONTENT, + g_value_get_boxed (value)); + return; + + case PROP_FRAME_COLOR: + em_format_html_set_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_FRAME, + g_value_get_boxed (value)); + return; + + case PROP_HEADER_COLOR: + em_format_html_set_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_HEADER, + g_value_get_boxed (value)); + return; + + case PROP_IMAGE_LOADING_POLICY: + em_format_html_set_image_loading_policy ( + EM_FORMAT_HTML (object), + g_value_get_int (value)); + return; + + case PROP_MARK_CITATIONS: + em_format_html_set_mark_citations ( + EM_FORMAT_HTML (object), + g_value_get_boolean (value)); + return; + + case PROP_ONLY_LOCAL_PHOTOS: + em_format_html_set_only_local_photos ( + EM_FORMAT_HTML (object), + g_value_get_boolean (value)); + return; + + case PROP_SHOW_SENDER_PHOTO: + em_format_html_set_show_sender_photo ( + EM_FORMAT_HTML (object), + g_value_get_boolean (value)); + return; + + case PROP_TEXT_COLOR: + em_format_html_set_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_TEXT, + g_value_get_boxed (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} static void -efh_finalise(GObject *o) +efh_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - EMFormatHTML *efh = (EMFormatHTML *)o; + GdkColor color; + + switch (property_id) { + case PROP_BODY_COLOR: + em_format_html_get_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_BODY, + &color); + g_value_set_boxed (value, &color); + return; - /* FIXME: check for leaked stuff */ + case PROP_CITATION_COLOR: + em_format_html_get_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_CITATION, + &color); + g_value_set_boxed (value, &color); + return; + + case PROP_CONTENT_COLOR: + em_format_html_get_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_CONTENT, + &color); + g_value_set_boxed (value, &color); + return; + + case PROP_FRAME_COLOR: + em_format_html_get_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_FRAME, + &color); + g_value_set_boxed (value, &color); + return; + + case PROP_HEADER_COLOR: + em_format_html_get_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_HEADER, + &color); + g_value_set_boxed (value, &color); + return; + + case PROP_IMAGE_LOADING_POLICY: + g_value_set_int ( + value, + em_format_html_get_image_loading_policy ( + EM_FORMAT_HTML (object))); + return; + + case PROP_MARK_CITATIONS: + g_value_set_boolean ( + value, em_format_html_get_mark_citations ( + EM_FORMAT_HTML (object))); + return; + + case PROP_ONLY_LOCAL_PHOTOS: + g_value_set_boolean ( + value, em_format_html_get_only_local_photos ( + EM_FORMAT_HTML (object))); + return; - em_format_html_clear_pobject(efh); + case PROP_SHOW_SENDER_PHOTO: + g_value_set_boolean ( + value, em_format_html_get_show_sender_photo ( + EM_FORMAT_HTML (object))); + return; + + case PROP_TEXT_COLOR: + em_format_html_get_color ( + EM_FORMAT_HTML (object), + EM_FORMAT_HTML_COLOR_TEXT, + &color); + g_value_set_boxed (value, &color); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} - efh_gtkhtml_destroy(efh->html, efh); +static void +efh_finalize (GObject *object) +{ + EMFormatHTML *efh = EM_FORMAT_HTML (object); + + /* FIXME: check for leaked stuff */ - g_hash_table_destroy(efh->priv->text_inline_parts); + em_format_html_clear_pobject (efh); + efh_gtkhtml_destroy (efh->html, efh); - g_free(efh->priv); + g_hash_table_destroy (efh->priv->text_inline_parts); - ((GObjectClass *)efh_parent)->finalize(o); + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); } static void -efh_base_init(EMFormatHTMLClass *efhklass) +efh_base_init (EMFormatHTMLClass *class) { - efh_builtin_init(efhklass); + efh_builtin_init (class); } static void -efh_class_init(GObjectClass *klass) +efh_class_init (EMFormatHTMLClass *class) { - ((EMFormatClass *)klass)->format_clone = efh_format_clone; - ((EMFormatClass *)klass)->format_error = efh_format_error; - ((EMFormatClass *)klass)->format_source = efh_format_source; - ((EMFormatClass *)klass)->format_attachment = efh_format_attachment; - ((EMFormatClass *)klass)->format_secure = efh_format_secure; - ((EMFormatClass *)klass)->busy = efh_busy; - - klass->finalize = efh_finalise; + GObjectClass *object_class; + EMFormatClass *format_class; + gchar *pathname; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMFormatHTMLPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = efh_set_property; + object_class->get_property = efh_get_property; + object_class->finalize = efh_finalize; + + format_class = EM_FORMAT_CLASS (class); + format_class->format_clone = efh_format_clone; + format_class->format_error = efh_format_error; + format_class->format_source = efh_format_source; + format_class->format_attachment = efh_format_attachment; + format_class->format_secure = efh_format_secure; + format_class->busy = efh_busy; + + g_object_class_install_property ( + object_class, + PROP_BODY_COLOR, + g_param_spec_boxed ( + "body-color", + "Body Color", + NULL, + GDK_TYPE_COLOR, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_CITATION_COLOR, + g_param_spec_boxed ( + "citation-color", + "Citation Color", + NULL, + GDK_TYPE_COLOR, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_CONTENT_COLOR, + g_param_spec_boxed ( + "content-color", + "Content Color", + NULL, + GDK_TYPE_COLOR, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_FRAME_COLOR, + g_param_spec_boxed ( + "frame-color", + "Frame Color", + NULL, + GDK_TYPE_COLOR, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_HEADER_COLOR, + g_param_spec_boxed ( + "header-color", + "Header Color", + NULL, + GDK_TYPE_COLOR, + G_PARAM_READWRITE)); + + /* FIXME Make this a proper enum property. */ + g_object_class_install_property ( + object_class, + PROP_IMAGE_LOADING_POLICY, + g_param_spec_int ( + "image-loading-policy", + "Image Loading Policy", + NULL, + 0, + G_MAXINT, + MAIL_CONFIG_HTTP_ALWAYS, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_MARK_CITATIONS, + g_param_spec_boolean ( + "mark-citations", + "Mark Citations", + NULL, + TRUE, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_ONLY_LOCAL_PHOTOS, + g_param_spec_boolean ( + "only-local-photos", + "Only Local Photos", + NULL, + TRUE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property ( + object_class, + PROP_SHOW_SENDER_PHOTO, + g_param_spec_boolean ( + "show-sender-photo", + "Show Sender Photo", + NULL, + TRUE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property ( + object_class, + PROP_TEXT_COLOR, + g_param_spec_boxed ( + "text-color", + "Text Color", + NULL, + GDK_TYPE_COLOR, + G_PARAM_READWRITE)); + + /* cache expiry - 2 hour access, 1 day max */ + pathname = g_build_filename ( + e_get_user_data_dir (), "cache", NULL); + emfh_http_cache = camel_data_cache_new (pathname, 0, NULL); + if (emfh_http_cache) { + camel_data_cache_set_expire_age(emfh_http_cache, 24*60*60); + camel_data_cache_set_expire_access(emfh_http_cache, 2*60*60); + } + g_free (pathname); +} + +static void +efh_init (EMFormatHTML *efh) +{ + GdkColor *color; + + efh->priv = EM_FORMAT_HTML_GET_PRIVATE (efh); + + e_dlist_init(&efh->pending_object_list); + e_dlist_init(&efh->priv->pending_jobs); + efh->priv->lock = g_mutex_new(); + efh->priv->format_id = -1; + efh->priv->text_inline_parts = g_hash_table_new_full ( + g_str_hash, g_str_equal, + (GDestroyNotify) NULL, + (GDestroyNotify) efh_free_cache); + + efh->html = (GtkHTML *) gtk_html_new (); + g_object_ref_sink(efh->html); + + gtk_html_set_blocking (efh->html, FALSE); + gtk_html_set_caret_first_focus_anchor (efh->html, EFM_MESSAGE_START_ANAME); + + gtk_html_set_default_content_type(efh->html, "text/html; charset=utf-8"); + gtk_html_set_editable(efh->html, FALSE); + + g_signal_connect(efh->html, "url_requested", G_CALLBACK(efh_url_requested), efh); + g_signal_connect(efh->html, "object_requested", G_CALLBACK(efh_object_requested), efh); + + color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_BODY]; + gdk_color_parse ("0xeeeeee", color); + + color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_CONTENT]; + gdk_color_parse ("0xffffff", color); + + color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_FRAME]; + gdk_color_parse ("0x3f3f3f", color); + + color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_HEADER]; + gdk_color_parse ("0xeeeeee", color); + + color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_TEXT]; + gdk_color_parse ("0x000000", color); + + efh->text_html_flags = + CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | + CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES | + CAMEL_MIME_FILTER_TOHTML_MARK_CITATION; + efh->show_icon = TRUE; + efh->state = EM_FORMAT_HTML_STATE_NONE; + + g_signal_connect_swapped ( + efh, "notify::mark-citations", + G_CALLBACK (em_format_redraw), NULL); } GType -em_format_html_get_type(void) +em_format_html_get_type (void) { static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof(EMFormatHTMLClass), - (GBaseInitFunc)efh_base_init, NULL, - (GClassInitFunc)efh_class_init, - NULL, NULL, - sizeof(EMFormatHTML), 0, - (GInstanceInitFunc)efh_init + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EMFormatHTMLClass), + (GBaseInitFunc) efh_base_init, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) efh_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMFormatHTML), + 0, /* n_preallocs */ + (GInstanceInitFunc) efh_init, + NULL /* value_table */ }; - const char *base_directory = e_get_user_data_dir (); - char *path; - - efh_parent = g_type_class_ref(em_format_get_type()); - type = g_type_register_static(em_format_get_type(), "EMFormatHTML", &info, 0); - /* cache expiry - 2 hour access, 1 day max */ - path = alloca(strlen(base_directory)+16); - sprintf(path, "%s/cache", base_directory); - emfh_http_cache = camel_data_cache_new(path, 0, NULL); - if (emfh_http_cache) { - camel_data_cache_set_expire_age(emfh_http_cache, 24*60*60); - camel_data_cache_set_expire_access(emfh_http_cache, 2*60*60); - } + type = g_type_register_static ( + em_format_get_type(), "EMFormatHTML", &type_info, 0); } return type; } -EMFormatHTML *em_format_html_new(void) +EMFormatHTML * +em_format_html_new(void) +{ + return g_object_new (EM_TYPE_FORMAT_HTML, NULL); +} + +void +em_format_html_load_images (EMFormatHTML *efh) { - EMFormatHTML *efh; + g_return_if_fail (EM_IS_FORMAT_HTML (efh)); - efh = g_object_new(em_format_html_get_type(), NULL); + if (efh->priv->image_loading_policy == MAIL_CONFIG_HTTP_ALWAYS) + return; - return efh; + /* This will remain set while we're still + * rendering the same message, then it wont be. */ + efh->priv->load_images_now = TRUE; + em_format_redraw (EM_FORMAT (efh)); } -/* force loading of http images */ -void em_format_html_load_http(EMFormatHTML *emfh) +void +em_format_html_get_color (EMFormatHTML *efh, + EMFormatHTMLColorType type, + GdkColor *color) { - if (emfh->load_http == MAIL_CONFIG_HTTP_ALWAYS) - return; + GdkColor *format_color; + + g_return_if_fail (EM_IS_FORMAT_HTML (efh)); + g_return_if_fail (type >= 0); + g_return_if_fail (type < EM_FORMAT_HTML_NUM_COLOR_TYPES); + g_return_if_fail (color != NULL); - /* This will remain set while we're still rendering the same message, then it wont be */ - emfh->load_http_now = TRUE; - d(printf("redrawing with images forced on\n")); - em_format_redraw((EMFormat *)emfh); + format_color = &efh->priv->colors[type]; + + color->red = format_color->red; + color->green = format_color->green; + color->blue = format_color->blue; } void -em_format_html_set_load_http(EMFormatHTML *emfh, int style) +em_format_html_set_color (EMFormatHTML *efh, + EMFormatHTMLColorType type, + const GdkColor *color) { - if (emfh->load_http != style) { - emfh->load_http = style; - em_format_redraw((EMFormat *)emfh); + GdkColor *format_color; + const gchar *property_name; + + g_return_if_fail (EM_IS_FORMAT_HTML (efh)); + g_return_if_fail (type >= 0); + g_return_if_fail (type < EM_FORMAT_HTML_NUM_COLOR_TYPES); + g_return_if_fail (color != NULL); + + format_color = &efh->priv->colors[type]; + + if (gdk_color_equal (color, format_color)) + return; + + format_color->red = color->red; + format_color->green = color->green; + format_color->blue = color->blue; + + switch (type) { + case EM_FORMAT_HTML_COLOR_BODY: + property_name = "body-color"; + break; + case EM_FORMAT_HTML_COLOR_CITATION: + property_name = "citation-color"; + break; + case EM_FORMAT_HTML_COLOR_CONTENT: + property_name = "content-color"; + break; + case EM_FORMAT_HTML_COLOR_FRAME: + property_name = "frame-color"; + break; + case EM_FORMAT_HTML_COLOR_HEADER: + property_name = "header-color"; + break; + case EM_FORMAT_HTML_COLOR_TEXT: + property_name = "text-color"; + break; + default: + g_return_if_reached (); } + + g_object_notify (G_OBJECT (efh), property_name); +} + +MailConfigHTTPMode +em_format_html_get_image_loading_policy (EMFormatHTML *efh) +{ + g_return_val_if_fail (EM_IS_FORMAT_HTML (efh), 0); + + return efh->priv->image_loading_policy;; } void -em_format_html_set_mark_citations(EMFormatHTML *emfh, int state, guint32 citation_colour) +em_format_html_set_image_loading_policy (EMFormatHTML *efh, + MailConfigHTTPMode policy) { - if (emfh->mark_citations ^ state || emfh->citation_colour != citation_colour) { - emfh->mark_citations = state; - emfh->citation_colour = citation_colour; + g_return_if_fail (EM_IS_FORMAT_HTML (efh)); - if (state) - emfh->text_html_flags |= CAMEL_MIME_FILTER_TOHTML_MARK_CITATION; - else - emfh->text_html_flags &= ~CAMEL_MIME_FILTER_TOHTML_MARK_CITATION; + if (policy == efh->priv->image_loading_policy) + return; - em_format_redraw((EMFormat *)emfh); - } + efh->priv->image_loading_policy = policy; + + g_object_notify (G_OBJECT (efh), "image-loading-policy"); +} + +gboolean +em_format_html_get_mark_citations (EMFormatHTML *efh) +{ + guint32 flags; + + g_return_val_if_fail (EM_IS_FORMAT_HTML (efh), FALSE); + + flags = efh->text_html_flags; + + return ((flags & CAMEL_MIME_FILTER_TOHTML_MARK_CITATION) != 0); +} + +void +em_format_html_set_mark_citations (EMFormatHTML *efh, + gboolean mark_citations) +{ + g_return_if_fail (EM_IS_FORMAT_HTML (efh)); + + if (mark_citations) + efh->text_html_flags |= + CAMEL_MIME_FILTER_TOHTML_MARK_CITATION; + efh->text_html_flags &= + ~CAMEL_MIME_FILTER_TOHTML_MARK_CITATION; + + g_object_notify (G_OBJECT (efh), "mark-citations"); +} + +gboolean +em_format_html_get_only_local_photos (EMFormatHTML *efh) +{ + g_return_val_if_fail (EM_IS_FORMAT_HTML (efh), FALSE); + + return efh->priv->only_local_photos; +} + +void +em_format_html_set_only_local_photos (EMFormatHTML *efh, + gboolean only_local_photos) +{ + g_return_if_fail (EM_IS_FORMAT_HTML (efh)); + + efh->priv->only_local_photos = only_local_photos; + + g_object_notify (G_OBJECT (efh), "only-local-photos"); +} + +gboolean +em_format_html_get_show_sender_photo (EMFormatHTML *efh) +{ + g_return_val_if_fail (EM_IS_FORMAT_HTML (efh), FALSE); + + return efh->priv->show_sender_photo; +} + +void +em_format_html_set_show_sender_photo (EMFormatHTML *efh, + gboolean show_sender_photo) +{ + g_return_if_fail (EM_IS_FORMAT_HTML (efh)); + + efh->priv->show_sender_photo = show_sender_photo; + + g_object_notify (G_OBJECT (efh), "show-sender-photo"); } CamelMimePart * @@ -477,13 +925,15 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) instream = cistream = camel_data_cache_get(emfh_http_cache, EMFH_HTTP_CACHE_PATH, job->u.uri, NULL); if (instream == NULL) { + MailConfigHTTPMode policy; char *proxy; + policy = em_format_html_get_image_loading_policy (job->format); - if (!(job->format->load_http_now - || job->format->load_http == MAIL_CONFIG_HTTP_ALWAYS - || (job->format->load_http == MAIL_CONFIG_HTTP_SOMETIMES - && em_utils_in_addressbook((CamelInternetAddress *)camel_mime_message_get_from(job->format->format.message), FALSE)))) { + if (!(job->format->priv->load_images_now + || policy == MAIL_CONFIG_HTTP_ALWAYS + || (policy == MAIL_CONFIG_HTTP_SOMETIMES + && em_utils_in_addressbook((CamelInternetAddress *)camel_mime_message_get_from(job->format->parent.message), FALSE)))) { /* TODO: Ideally we would put the http requests into another queue and only send them out if the user selects 'load images', when they do. The problem is how to maintain this state with multiple renderings, and how to adjust the thread dispatch/setup routine to handle it */ @@ -672,7 +1122,11 @@ static const char *smime_sign_colour[4] = { static void efh_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid) { - efh_parent->format_secure(emf, stream, part, valid); + EMFormatClass *format_class; + + format_class = EM_FORMAT_GET_CLASS (emf); + 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 @@ -726,6 +1180,7 @@ efh_text_plain(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFo CamelContentType *type; const char *format; guint32 flags; + guint32 rgb; int i, count, len; struct _EMFormatHTMLCache *efhc; @@ -782,8 +1237,10 @@ efh_text_plain(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFo camel_content_type_unref(ct); } + rgb = e_color_to_value ( + &efh->priv->colors[EM_FORMAT_HTML_COLOR_CITATION]); filtered_stream = camel_stream_filter_new_with_stream(stream); - html_filter = camel_mime_filter_tohtml_new(flags, efh->citation_colour); + html_filter = camel_mime_filter_tohtml_new(flags, rgb); camel_stream_filter_add(filtered_stream, html_filter); camel_object_unref(html_filter); @@ -799,9 +1256,17 @@ 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", "*") && !camel_content_type_is(type, "text", "calendar")) { - camel_stream_printf (stream, - "
\n", - efh->frame_colour & 0xffffff, efh->content_colour & 0xffffff, efh->text_colour & 0xffffff); + camel_stream_printf ( + stream, "
\n", + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_FRAME]), + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_CONTENT]), + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_TEXT])); camel_stream_write_string(stream, "\n" EFH_MESSAGE_START); em_format_format_text((EMFormat *)efh, (CamelStream *)filtered_stream, (CamelDataWrapper *)newpart); camel_stream_flush((CamelStream *)filtered_stream); @@ -839,9 +1304,17 @@ efh_text_enriched(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, E camel_stream_filter_add(filtered_stream, enriched); camel_object_unref(enriched); - camel_stream_printf (stream, - "
\n" EFH_MESSAGE_START, - efh->frame_colour & 0xffffff, efh->content_colour & 0xffffff, efh->text_colour & 0xffffff); + camel_stream_printf ( + stream, "
\n" EFH_MESSAGE_START, + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_FRAME]), + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_CONTENT]), + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_TEXT])); em_format_format_text((EMFormat *)efh, (CamelStream *)filtered_stream, (CamelDataWrapper *)part); @@ -876,10 +1349,18 @@ efh_text_html(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFor EMFormatPURI *puri; char *cid = NULL; - camel_stream_printf (stream, - "
\n" - "\n" EFH_MESSAGE_START, - efh->frame_colour & 0xffffff, efh->content_colour & 0xffffff, efh->text_colour & 0xffffff); + camel_stream_printf ( + stream, "
\n" + "\n" EFH_MESSAGE_START, + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_FRAME]), + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_CONTENT]), + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_TEXT])); /* TODO: perhaps we don't need to calculate this anymore now base is handled better */ /* calculate our own location string so add_puri doesn't do it @@ -1016,9 +1497,17 @@ efh_message_deliverystatus(EMFormatHTML *efh, CamelStream *stream, CamelMimePart guint32 rgb = 0x737373; /* Yuck, this is copied from efh_text_plain */ - camel_stream_printf (stream, - "
\n", - efh->frame_colour & 0xffffff, efh->content_colour & 0xffffff, efh->text_colour & 0xffffff); + camel_stream_printf ( + stream, "
\n", + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_FRAME]), + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_CONTENT]), + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_TEXT])); filtered_stream = camel_stream_filter_new_with_stream(stream); html_filter = camel_mime_filter_tohtml_new(efh->text_html_flags, rgb); @@ -1210,10 +1699,14 @@ static EMFormatHandler type_builtin_table[] = { static void efh_builtin_init(EMFormatHTMLClass *efhc) { - int i; + EMFormatClass *efc; + gint ii; + + efc = (EMFormatClass *) efhc; - for (i=0;iformat->html == NULL) return; - camel_stream_printf((CamelStream *)m->estream, - "\n\n" - "\n\n\n" - "\n", - m->format->body_colour & 0xffffff, - m->format->header_colour & 0xffffff); + camel_stream_printf ( + (CamelStream *)m->estream, + "\n\n" + "\n\n\n" + "\n", + e_color_to_value ( + &m->format->priv->colors[ + EM_FORMAT_HTML_COLOR_BODY]), + e_color_to_value ( + &m->format->priv->colors[ + EM_FORMAT_HTML_COLOR_HEADER])); /* */ @@ -1332,8 +1830,8 @@ efh_format_done (struct _format_msg *m) { d(printf("formatting finished\n")); - m->format->load_http_now = FALSE; m->format->priv->format_id = -1; + m->format->priv->load_images_now = FALSE; m->format->state = EM_FORMAT_HTML_STATE_NONE; g_signal_emit_by_name(m->format, "complete"); } @@ -1387,7 +1885,9 @@ efh_format_timeout(struct _format_msg *m) d(printf(" ready to go, firing off format thread\n")); /* call super-class to kick it off */ - efh_parent->format_clone((EMFormat *)efh, m->folder, m->uid, m->message, m->format_source); + EM_FORMAT_CLASS (parent_class)->format_clone ( + EM_FORMAT (efh), m->folder, m->uid, + m->message, m->format_source); em_format_html_clear_pobject(m->format); /* FIXME: method off EMFormat? */ @@ -1854,10 +2354,12 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) charset = camel_iconv_charset_name(charset); if (!efh->simple_headers) - camel_stream_printf(stream, - "\n" - "
"); em_format_format_text(emf, (CamelStream *)filtered_stream, dw); camel_object_unref(filtered_stream); -- cgit v1.2.3 From 7ade227e6409c98a4010992450e111cf7bb10520 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 14 Aug 2008 20:19:12 +0000 Subject: Merge revisions 35951:35992 from trunk. svn path=/branches/kill-bonobo/; revision=35994 --- mail/em-format-html.c | 1 + 1 file changed, 1 insertion(+) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index bb2d176b6e..99c670e5ae 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -497,6 +497,7 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) } instream = camel_http_stream_new(CAMEL_HTTP_METHOD_GET, ((EMFormat *)job->format)->session, url); + camel_http_stream_set_user_agent((CamelHttpStream *)instream, "CamelHttpStream/1.0 Evolution/" VERSION); proxy = em_utils_get_proxy_uri(); camel_http_stream_set_proxy((CamelHttpStream *)instream, proxy); g_free(proxy); -- cgit v1.2.3 From b2cda1d0c6d44f53f71bad9e256f41188677dfba Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 1 Oct 2008 20:56:04 +0000 Subject: Merge revisions 36016:36533 from trunk. svn path=/branches/kill-bonobo/; revision=36534 --- mail/em-format-html.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 99c670e5ae..caa5c0f51c 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -1,22 +1,22 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Authors: Michael Zucchi + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Authors: + * Michael Zucchi + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) * */ @@ -1931,10 +1931,11 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) } else { int mailer_shown = FALSE; while (h->next) { - int mailer; + int mailer, face; header = ((CamelMimePart *)part)->headers; mailer = !g_ascii_strcasecmp (h->name, "X-Evolution-Mailer"); + face = !g_ascii_strcasecmp (h->name, "Face"); while (header) { if (emf->show_photo && !photo_name && !g_ascii_strcasecmp (header->name, "From")) @@ -1967,7 +1968,7 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) efh_format_header (emf, stream, part, &xmailer, h->flags, charset); if (strstr(use_header->value, "Evolution")) have_icon = TRUE; - } else if (!g_ascii_strcasecmp (header->name, "Face") && !face_decoded) { + } else if (!face_decoded && face && !g_ascii_strcasecmp (header->name, "Face")) { char *cp = header->value; /* Skip over spaces */ @@ -1978,7 +1979,8 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) face_header_value = g_realloc (face_header_value, face_header_len + 1); face_header_value[face_header_len] = 0; face_decoded = TRUE; - } else if (!g_ascii_strcasecmp (header->name, h->name)) { + /* Showing an encoded "Face" header makes little sense */ + } else if (!g_ascii_strcasecmp (header->name, h->name) && !face) { efh_format_header(emf, stream, part, header, h->flags, charset); } -- cgit v1.2.3 From 54b80a7271e8ce1b2f3ccc68bb553940a24b80e2 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 17 Oct 2008 03:48:03 +0000 Subject: Get the mail folder tree compiling, though I'm not yet sure why it's not showing anything. Probably something stupid. Also enabled the composer. svn path=/branches/kill-bonobo/; revision=36623 --- mail/em-format-html.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index caa5c0f51c..12e2b5975c 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -74,7 +74,6 @@ #include -#include "mail-component.h" #include "mail-config.h" #include "mail-mt.h" @@ -262,9 +261,6 @@ em_format_html_get_type(void) const char *base_directory = e_get_user_data_dir (); char *path; - /* Trigger creation of mail component. */ - mail_component_peek (); - efh_parent = g_type_class_ref(em_format_get_type()); type = g_type_register_static(em_format_get_type(), "EMFormatHTML", &info, 0); -- cgit v1.2.3 From d6445f8abfa78c0a9c8680a3ba7422d331391f8f Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 7 Nov 2008 22:04:53 +0000 Subject: Merge revisions 36685:36729 from trunk. svn path=/branches/kill-bonobo/; revision=36763 --- mail/em-format-html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 12e2b5975c..3ad759bfef 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -1056,7 +1056,7 @@ emfh_multipart_related_check(struct _EMFormatHTMLJob *job, int cancelled) 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 == emfh_write_related) { - g_string_printf(((EMFormat *)job->format)->part_id, puri->part_id); + g_string_printf(((EMFormat *)job->format)->part_id, "%s", puri->part_id); em_format_part((EMFormat *)job->format, (CamelStream *)job->stream, puri->part); } /* else it was probably added by a previous format this loop */ -- cgit v1.2.3 From 4f4615a46d5ba518c1e6a0c2412b1edf1e268d99 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 24 Nov 2008 05:14:44 +0000 Subject: Merge revisions 36737:36810 from trunk. svn path=/branches/kill-bonobo/; revision=36811 --- mail/em-format-html.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 3ad759bfef..8aed5e814c 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -1891,22 +1891,23 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) g_free(name); } else if (!g_ascii_strcasecmp (header->name, "X-Evolution-Mail-From-Delegate")) { mail_from_delegate = TRUE; - } else if (header_sender && header_from && mail_from_delegate) { - camel_stream_printf(stream, "
"); - if(gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) - camel_stream_printf (stream, "
"); - else - camel_stream_printf (stream, ""); - /* 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 %s on behalf of %s"), header_sender, header_from); - camel_stream_printf(stream, "
"); + if(gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) + camel_stream_printf (stream, "
"); + else + camel_stream_printf (stream, ""); + /* 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 %s on behalf of %s"), header_sender, header_from); + camel_stream_printf(stream, "
", - efh->header_colour & 0xffffff); + camel_stream_printf ( + stream, "\n" + "
", + e_color_to_value ( + &efh->priv->colors[ + EM_FORMAT_HTML_COLOR_HEADER])); hdr_charset = emf->charset ? emf->charset : emf->default_charset; @@ -1939,7 +2441,8 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) face = !g_ascii_strcasecmp (h->name, "Face"); while (header) { - if (emf->show_photo && !photo_name && !g_ascii_strcasecmp (header->name, "From")) + 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") || @@ -1997,10 +2500,12 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) if (photo_name) { char *classid; CamelMimePart *photopart; + gboolean only_local_photo; cia = camel_internet_address_new(); camel_address_decode((CamelAddress *) cia, (const char *) photo_name); - photopart = em_utils_contact_photo (cia, emf->photo_local); + 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; -- cgit v1.2.3 From 08b1d0ae8e36ef20da800bf6358ca0cd9fb4e026 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 1 Mar 2009 13:16:31 +0000 Subject: Split the interactive parts of the message display out of EMFormatHTMLDisplay to a new GtkHTML subclass named EMailDisplay, and have EMFormatHTML create an instance of that. EMailDisplay will handle link clicking, mousing over URIs, popup menus, and interactive search. This makes EMFormatHTMLDisplay and EMailReader more lightweight. Clean up more of the EMFormat stack. svn path=/branches/kill-bonobo/; revision=37346 --- mail/em-format-html.c | 1049 +++++++++++++++++++++++++------------------------ 1 file changed, 538 insertions(+), 511 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index bafb82ae36..6308947a26 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -135,12 +135,7 @@ 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_clone(EMFormat *emf, CamelFolder *folder, const char *uid, CamelMimeMessage *msg, EMFormat *emfsource); -static void efh_format_error(EMFormat *emf, CamelStream *stream, const char *txt); -static void efh_format_source(EMFormat *, CamelStream *, CamelMimePart *); -static void efh_format_attachment(EMFormat *, CamelStream *, CamelMimePart *, const char *, const EMFormatHandler *); static void efh_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid); -static gboolean efh_busy(EMFormat *); static void efh_builtin_init(EMFormatHTMLClass *efhc); @@ -151,6 +146,230 @@ static CamelDataCache *emfh_http_cache; #define EMFH_HTTP_CACHE_PATH "http" +/* Sigh, this is so we have a cancellable, async rendering thread */ +struct _format_msg { + MailMsg base; + + EMFormatHTML *format; + EMFormat *format_source; + EMHTMLStream *estream; + CamelFolder *folder; + char *uid; + CamelMimeMessage *message; +}; + +static gchar * +efh_format_desc (struct _format_msg *m) +{ + return g_strdup(_("Formatting message")); +} + +static void +efh_format_exec (struct _format_msg *m) +{ + struct _EMFormatHTMLJob *job; + struct _EMFormatPURITree *puri_level; + int cancelled = FALSE; + CamelURL *base; + + if (m->format->html == NULL) + return; + + camel_stream_printf ( + (CamelStream *)m->estream, + "\n\n" + "\n\n\n" + "\n", + e_color_to_value ( + &m->format->priv->colors[ + EM_FORMAT_HTML_COLOR_BODY]), + e_color_to_value ( + &m->format->priv->colors[ + EM_FORMAT_HTML_COLOR_HEADER])); + + /* */ + + if (((EMFormat *)m->format)->mode == EM_FORMAT_SOURCE) { + em_format_format_source((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message); + } else { + const EMFormatHandler *handle; + + handle = em_format_find_handler((EMFormat *)m->format, "x-evolution/message/prefix"); + if (handle) + handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); + handle = em_format_find_handler((EMFormat *)m->format, "x-evolution/message/rfc822"); + if (handle) + handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); + handle = em_format_find_handler((EMFormat *)m->format, "x-evolution/message/post-header-closure"); + if (handle && !((EMFormat *)m->format)->print) + handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); + + } + + camel_stream_flush((CamelStream *)m->estream); + + puri_level = ((EMFormat *)m->format)->pending_uri_level; + base = ((EMFormat *)m->format)->base; + + do { + /* now dispatch any added tasks ... */ + g_mutex_lock(m->format->priv->lock); + while ((job = (struct _EMFormatHTMLJob *)e_dlist_remhead(&m->format->priv->pending_jobs))) { + g_mutex_unlock(m->format->priv->lock); + + /* This is an implicit check to see if the gtkhtml has been destroyed */ + if (!cancelled) + cancelled = m->format->html == NULL; + + /* Now do an explicit check for user cancellation */ + if (!cancelled) + cancelled = camel_operation_cancel_check(NULL); + + /* call jobs even if cancelled, so they can clean up resources */ + ((EMFormat *)m->format)->pending_uri_level = job->puri_level; + if (job->base) + ((EMFormat *)m->format)->base = job->base; + job->callback(job, cancelled); + ((EMFormat *)m->format)->base = base; + + /* clean up the job */ + camel_object_unref(job->stream); + if (job->base) + camel_url_free(job->base); + g_free(job); + + g_mutex_lock(m->format->priv->lock); + } + g_mutex_unlock(m->format->priv->lock); + + if (m->estream) { + /* 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, "\n\n"); + camel_stream_close((CamelStream *)m->estream); + camel_object_unref(m->estream); + m->estream = NULL; + } + + /* e_dlist_empty is atomic and doesn't need locking */ + } while (!e_dlist_empty(&m->format->priv->pending_jobs)); + + d(printf("out of jobs, done\n")); + + ((EMFormat *)m->format)->pending_uri_level = puri_level; +} + +static void +efh_format_done (struct _format_msg *m) +{ + d(printf("formatting finished\n")); + + m->format->priv->format_id = -1; + m->format->priv->load_images_now = FALSE; + m->format->state = EM_FORMAT_HTML_STATE_NONE; + g_signal_emit_by_name(m->format, "complete"); +} + +static void +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_object_unref(m->estream); + } + if (m->folder) + camel_object_unref(m->folder); + g_free(m->uid); + if (m->message) + camel_object_unref(m->message); + if (m->format_source) + g_object_unref(m->format_source); +} + +static MailMsgInfo efh_format_info = { + sizeof (struct _format_msg), + (MailMsgDescFunc) efh_format_desc, + (MailMsgExecFunc) efh_format_exec, + (MailMsgDoneFunc) efh_format_done, + (MailMsgFreeFunc) efh_format_free +}; + +static gboolean +efh_format_timeout(struct _format_msg *m) +{ + GtkHTMLStream *hstream; + EMFormatHTML *efh = m->format; + struct _EMFormatHTMLPrivate *p = efh->priv; + + if (m->format->html == NULL) { + mail_msg_unref(m); + return FALSE; + } + + d(printf("timeout called ...\n")); + if (p->format_id != -1) { + d(printf(" still waiting for cancellation to take effect, waiting ...\n")); + return TRUE; + } + + g_return_val_if_fail (e_dlist_empty(&p->pending_jobs), FALSE); + + d(printf(" ready to go, firing off format thread\n")); + + /* call super-class to kick it off */ + EM_FORMAT_CLASS (parent_class)->format_clone ( + EM_FORMAT (efh), m->folder, m->uid, + m->message, m->format_source); + em_format_html_clear_pobject(m->format); + + /* FIXME: method off EMFormat? */ + if (((EMFormat *)efh)->valid) { + camel_cipher_validity_free(((EMFormat *)efh)->valid); + ((EMFormat *)efh)->valid = NULL; + ((EMFormat *)efh)->valid_parent = NULL; + } + + if (m->message == NULL) { + hstream = gtk_html_begin(efh->html); + gtk_html_stream_close(hstream, GTK_HTML_STREAM_OK); + mail_msg_unref(m); + p->last_part = NULL; + } else { + efh->state = EM_FORMAT_HTML_STATE_RENDERING; + + if (p->last_part != m->message) { + hstream = gtk_html_begin (efh->html); + gtk_html_stream_printf (hstream, "
%s
", _("Formatting Message...")); + gtk_html_stream_close (hstream, GTK_HTML_STREAM_OK); + } + + hstream = NULL; + m->estream = (EMHTMLStream *)em_html_stream_new(efh->html, hstream); + + if (p->last_part == m->message) { + em_html_stream_set_flags (m->estream, + GTK_HTML_BEGIN_KEEP_SCROLL | GTK_HTML_BEGIN_KEEP_IMAGES + | GTK_HTML_BEGIN_BLOCK_UPDATES | GTK_HTML_BEGIN_BLOCK_IMAGES); + } else { + /* clear cache of inline-scanned text parts */ + g_hash_table_remove_all(p->text_inline_parts); + + p->last_part = m->message; + } + + efh->priv->format_id = m->base.seq; + mail_msg_unordered_push (m); + } + + efh->priv->format_timeout_id = 0; + efh->priv->format_timeout_msg = NULL; + + return FALSE; +} + static void efh_free_cache(struct _EMFormatHTMLCache *efhc) { @@ -371,34 +590,173 @@ efh_finalize (GObject *object) } static void -efh_base_init (EMFormatHTMLClass *class) +efh_format_clone (EMFormat *emf, + CamelFolder *folder, + const gchar *uid, + CamelMimeMessage *msg, + EMFormat *emfsource) { - efh_builtin_init (class); -} + EMFormatHTML *efh = EM_FORMAT_HTML (emf); + struct _format_msg *m; -static void -efh_class_init (EMFormatHTMLClass *class) -{ - GObjectClass *object_class; - EMFormatClass *format_class; - gchar *pathname; + /* How to sub-class ? Might need to adjust api ... */ - parent_class = g_type_class_peek_parent (class); - g_type_class_add_private (class, sizeof (EMFormatHTMLPrivate)); + if (efh->html == NULL) + return; - object_class = G_OBJECT_CLASS (class); - object_class->set_property = efh_set_property; - object_class->get_property = efh_get_property; - object_class->finalize = efh_finalize; + d(printf("efh_format called\n")); + if (efh->priv->format_timeout_id != 0) { + d(printf(" timeout for last still active, removing ...\n")); + g_source_remove(efh->priv->format_timeout_id); + efh->priv->format_timeout_id = 0; + mail_msg_unref(efh->priv->format_timeout_msg); + efh->priv->format_timeout_msg = NULL; + } - format_class = EM_FORMAT_CLASS (class); - format_class->format_clone = efh_format_clone; - format_class->format_error = efh_format_error; - format_class->format_source = efh_format_source; - format_class->format_attachment = efh_format_attachment; + if (emfsource != NULL) + g_object_ref (emfsource); + + if (folder != NULL) + camel_object_ref (folder); + + if (msg != NULL) + camel_object_ref (msg); + + m = mail_msg_new (&efh_format_info); + m->format = g_object_ref (emf); + m->format_source = emfsource; + m->folder = folder; + m->uid = g_strdup (uid); + m->message = msg; + + if (efh->priv->format_id == -1) { + d(printf(" idle, forcing format\n")); + efh_format_timeout (m); + } else { + d(printf(" still busy, cancelling and queuing wait\n")); + /* cancel and poll for completion */ + mail_msg_cancel (efh->priv->format_id); + efh->priv->format_timeout_msg = m; + efh->priv->format_timeout_id = g_timeout_add ( + 100, (GSourceFunc) efh_format_timeout, m); + } +} + +static void +efh_format_error (EMFormat *emf, + CamelStream *stream, + const gchar *txt) +{ + gchar *html; + + html = camel_text_to_html ( + txt, CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | + CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0); + camel_stream_printf ( + stream, "%s
", html); + g_free (html); +} + +static void +efh_format_source (EMFormat *emf, + CamelStream *stream, + CamelMimePart *part) +{ + CamelStreamFilter *filtered_stream; + CamelMimeFilter *filter; + CamelDataWrapper *dw = (CamelDataWrapper *) part; + + filtered_stream = camel_stream_filter_new_with_stream (stream); + + filter = camel_mime_filter_tohtml_new ( + CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | + CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES | + CAMEL_MIME_FILTER_TOHTML_PRESERVE_8BIT, 0); + camel_stream_filter_add (filtered_stream, filter); + camel_object_unref (filter); + + camel_stream_write_string (stream, "
"); + em_format_format_text (emf, (CamelStream *) filtered_stream, dw); + camel_object_unref (filtered_stream); + + camel_stream_write_string(stream, "
"); +} + +static void +efh_format_attachment (EMFormat *emf, + CamelStream *stream, + CamelMimePart *part, + const gchar *mime_type, + const EMFormatHandler *handle) +{ + char *text, *html; + + /* we display all inlined attachments only */ + + /* this could probably be cleaned up ... */ + camel_stream_write_string ( + stream, + "" + "
" + "" + "
" + "
\n"); + + /* 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); + g_free (html); + g_free (text); + + camel_stream_write_string (stream, "
"); + + if (handle && em_format_is_inline (emf, emf->part_id->str, part, handle)) + handle->handler (emf, stream, part, handle); +} + +static gboolean +efh_busy (EMFormat *emf) +{ + EMFormatHTMLPrivate *priv; + + priv = EM_FORMAT_HTML_GET_PRIVATE (emf); + + return (priv->format_id != -1); +} +static void +efh_base_init (EMFormatHTMLClass *class) +{ + efh_builtin_init (class); +} + +static void +efh_class_init (EMFormatHTMLClass *class) +{ + GObjectClass *object_class; + EMFormatClass *format_class; + gchar *pathname; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMFormatHTMLPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = efh_set_property; + object_class->get_property = efh_get_property; + object_class->finalize = efh_finalize; + + format_class = EM_FORMAT_CLASS (class); + format_class->format_clone = efh_format_clone; + format_class->format_error = efh_format_error; + format_class->format_source = efh_format_source; + format_class->format_attachment = efh_format_attachment; format_class->format_secure = efh_format_secure; format_class->busy = efh_busy; + class->html_widget_type = GTK_TYPE_HTML; + g_object_class_install_property ( object_class, PROP_BODY_COLOR, @@ -516,8 +874,10 @@ efh_class_init (EMFormatHTMLClass *class) } static void -efh_init (EMFormatHTML *efh) +efh_init (EMFormatHTML *efh, + EMFormatHTMLClass *class) { + GtkHTML *html; GdkColor *color; efh->priv = EM_FORMAT_HTML_GET_PRIVATE (efh); @@ -531,32 +891,35 @@ efh_init (EMFormatHTML *efh) (GDestroyNotify) NULL, (GDestroyNotify) efh_free_cache); - efh->html = (GtkHTML *) gtk_html_new (); - g_object_ref_sink(efh->html); + html = g_object_new (class->html_widget_type, NULL); + efh->html = g_object_ref_sink (html); - gtk_html_set_blocking (efh->html, FALSE); - gtk_html_set_caret_first_focus_anchor (efh->html, EFM_MESSAGE_START_ANAME); + gtk_html_set_blocking (html, FALSE); + gtk_html_set_caret_first_focus_anchor (html, EFM_MESSAGE_START_ANAME); + gtk_html_set_default_content_type (html, "text/html; charset=utf-8"); + gtk_html_set_editable (html, FALSE); - gtk_html_set_default_content_type(efh->html, "text/html; charset=utf-8"); - gtk_html_set_editable(efh->html, FALSE); - - g_signal_connect(efh->html, "url_requested", G_CALLBACK(efh_url_requested), efh); - g_signal_connect(efh->html, "object_requested", G_CALLBACK(efh_object_requested), efh); + g_signal_connect ( + html, "url-requested", + G_CALLBACK (efh_url_requested), efh); + g_signal_connect ( + html, "object-requested", + G_CALLBACK (efh_object_requested), efh); color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_BODY]; - gdk_color_parse ("0xeeeeee", color); + gdk_color_parse ("#eeeeee", color); color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_CONTENT]; - gdk_color_parse ("0xffffff", color); + gdk_color_parse ("#ffffff", color); color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_FRAME]; - gdk_color_parse ("0x3f3f3f", color); + gdk_color_parse ("#3f3f3f", color); color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_HEADER]; - gdk_color_parse ("0xeeeeee", color); + gdk_color_parse ("#eeeeee", color); color = &efh->priv->colors[EM_FORMAT_HTML_COLOR_TEXT]; - gdk_color_parse ("0x000000", color); + gdk_color_parse ("#000000", color); efh->text_html_flags = CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | @@ -590,18 +953,13 @@ em_format_html_get_type (void) }; type = g_type_register_static ( - em_format_get_type(), "EMFormatHTML", &type_info, 0); + em_format_get_type(), "EMFormatHTML", + &type_info, G_TYPE_FLAG_ABSTRACT); } return type; } -EMFormatHTML * -em_format_html_new(void) -{ - return g_object_new (EM_TYPE_FORMAT_HTML, NULL); -} - void em_format_html_load_images (EMFormatHTML *efh) { @@ -688,7 +1046,7 @@ em_format_html_get_image_loading_policy (EMFormatHTML *efh) { g_return_val_if_fail (EM_IS_FORMAT_HTML (efh), 0); - return efh->priv->image_loading_policy;; + return efh->priv->image_loading_policy; } void @@ -1548,447 +1906,169 @@ emfh_multipart_related_check(struct _EMFormatHTMLJob *job, int cancelled) while (purin) { 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 == emfh_write_related) { - g_string_printf(((EMFormat *)job->format)->part_id, "%s", puri->part_id); - em_format_part((EMFormat *)job->format, (CamelStream *)job->stream, puri->part); - } - /* else it was probably added by a previous format this loop */ - } - puri = purin; - purin = purin->next; - } - - g_string_printf(((EMFormat *)job->format)->part_id, "%s", oldpartid); - g_free(oldpartid); -} - -/* RFC 2387 */ -static void -efh_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) -{ - CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)part); - CamelMimePart *body_part, *display_part = NULL; - CamelContentType *content_type; - const char *start; - int i, nparts, partidlen, displayid = 0; - /* puri is set but never used */ - EMFormatPURI *puri; - struct _EMFormatHTMLJob *job; - - if (!CAMEL_IS_MULTIPART(mp)) { - em_format_format_source(emf, stream, part); - return; - } - - 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) { - int len; - const char *cid; - - /* strip <>'s */ - len = strlen (start) - 2; - start++; - - for (i=0; ipart_id->len; - - /* queue up the parts for possible inclusion */ - for (i = 0; i < nparts; i++) { - body_part = camel_multipart_get_part(mp, i); - if (body_part != display_part) { - g_string_append_printf(emf->part_id, "related.%d", i); - puri = em_format_add_puri(emf, sizeof(EMFormatPURI), NULL, body_part, emfh_write_related); - g_string_truncate(emf->part_id, partidlen); - d(printf(" part '%s' '%s' added\n", puri->uri?puri->uri:"", puri->cid)); - } - } - - 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); - - /* 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); - job->stream = stream; - camel_object_ref(stream); - 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_object((CamelMedium *)puri->part); - - d(printf("writing image '%s'\n", puri->cid)); - camel_data_wrapper_decode_to_stream(dw, stream); - camel_stream_close(stream); -} - -static void -efh_image(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info) -{ - EMFormatPURI *puri; - - puri = em_format_add_puri((EMFormat *)efh, sizeof(EMFormatPURI), NULL, part, efh_write_image); - d(printf("adding image '%s'\n", puri->cid)); - camel_stream_printf(stream, "", puri->cid); -} - -static EMFormatHandler type_builtin_table[] = { - { "image/gif", (EMFormatFunc)efh_image }, - { "image/jpeg", (EMFormatFunc)efh_image }, - { "image/png", (EMFormatFunc)efh_image }, - { "image/x-png", (EMFormatFunc)efh_image }, - { "image/tiff", (EMFormatFunc)efh_image }, - { "image/x-bmp", (EMFormatFunc)efh_image }, - { "image/bmp", (EMFormatFunc)efh_image }, - { "image/svg", (EMFormatFunc)efh_image }, - { "image/x-cmu-raster", (EMFormatFunc)efh_image }, - { "image/x-ico", (EMFormatFunc)efh_image }, - { "image/x-portable-anymap", (EMFormatFunc)efh_image }, - { "image/x-portable-bitmap", (EMFormatFunc)efh_image }, - { "image/x-portable-graymap", (EMFormatFunc)efh_image }, - { "image/x-portable-pixmap", (EMFormatFunc)efh_image }, - { "image/x-xpixmap", (EMFormatFunc)efh_image }, - { "text/enriched", (EMFormatFunc)efh_text_enriched }, - { "text/plain", (EMFormatFunc)efh_text_plain }, - { "text/html", (EMFormatFunc)efh_text_html }, - { "text/richtext", (EMFormatFunc)efh_text_enriched }, - { "text/*", (EMFormatFunc)efh_text_plain }, - { "message/external-body", (EMFormatFunc)efh_message_external }, - { "message/delivery-status", (EMFormatFunc)efh_message_deliverystatus }, - { "multipart/related", (EMFormatFunc)efh_multipart_related }, - - /* This is where one adds those busted, non-registered types, - that some idiot mailer writers out there decide to pull out - of their proverbials at random. */ - - { "image/jpg", (EMFormatFunc)efh_image }, - { "image/pjpeg", (EMFormatFunc)efh_image }, - - /* special internal types */ - - { "x-evolution/message/rfc822", (EMFormatFunc)efh_format_message } -}; - -static void -efh_builtin_init(EMFormatHTMLClass *efhc) -{ - EMFormatClass *efc; - gint ii; - - efc = (EMFormatClass *) efhc; - - for (ii = 0; ii < G_N_ELEMENTS (type_builtin_table); ii++) - em_format_class_add_handler ( - efc, &type_builtin_table[ii]); -} - -/* ********************************************************************** */ - -/* Sigh, this is so we have a cancellable, async rendering thread */ -struct _format_msg { - MailMsg base; - - EMFormatHTML *format; - EMFormat *format_source; - EMHTMLStream *estream; - CamelFolder *folder; - char *uid; - CamelMimeMessage *message; -}; - -static gchar * -efh_format_desc (struct _format_msg *m) -{ - return g_strdup(_("Formatting message")); -} - -static void -efh_format_exec (struct _format_msg *m) -{ - struct _EMFormatHTMLJob *job; - struct _EMFormatPURITree *puri_level; - int cancelled = FALSE; - CamelURL *base; - - if (m->format->html == NULL) - return; - - camel_stream_printf ( - (CamelStream *)m->estream, - "\n\n" - "\n\n\n" - "\n", - e_color_to_value ( - &m->format->priv->colors[ - EM_FORMAT_HTML_COLOR_BODY]), - e_color_to_value ( - &m->format->priv->colors[ - EM_FORMAT_HTML_COLOR_HEADER])); - - /* */ - - if (((EMFormat *)m->format)->mode == EM_FORMAT_SOURCE) { - em_format_format_source((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message); - } else { - const EMFormatHandler *handle; - - handle = em_format_find_handler((EMFormat *)m->format, "x-evolution/message/prefix"); - if (handle) - handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); - handle = em_format_find_handler((EMFormat *)m->format, "x-evolution/message/rfc822"); - if (handle) - handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); - handle = em_format_find_handler((EMFormat *)m->format, "x-evolution/message/post-header-closure"); - if (handle && !((EMFormat *)m->format)->print) - handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); - - } - - camel_stream_flush((CamelStream *)m->estream); - - puri_level = ((EMFormat *)m->format)->pending_uri_level; - base = ((EMFormat *)m->format)->base; - - do { - /* now dispatch any added tasks ... */ - g_mutex_lock(m->format->priv->lock); - while ((job = (struct _EMFormatHTMLJob *)e_dlist_remhead(&m->format->priv->pending_jobs))) { - g_mutex_unlock(m->format->priv->lock); - - /* This is an implicit check to see if the gtkhtml has been destroyed */ - if (!cancelled) - cancelled = m->format->html == NULL; - - /* Now do an explicit check for user cancellation */ - if (!cancelled) - cancelled = camel_operation_cancel_check(NULL); - - /* call jobs even if cancelled, so they can clean up resources */ - ((EMFormat *)m->format)->pending_uri_level = job->puri_level; - if (job->base) - ((EMFormat *)m->format)->base = job->base; - job->callback(job, cancelled); - ((EMFormat *)m->format)->base = base; - - /* clean up the job */ - camel_object_unref(job->stream); - if (job->base) - camel_url_free(job->base); - g_free(job); - - g_mutex_lock(m->format->priv->lock); - } - g_mutex_unlock(m->format->priv->lock); - - if (m->estream) { - /* 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, "\n\n"); - camel_stream_close((CamelStream *)m->estream); - camel_object_unref(m->estream); - m->estream = NULL; - } - - /* e_dlist_empty is atomic and doesn't need locking */ - } while (!e_dlist_empty(&m->format->priv->pending_jobs)); - - d(printf("out of jobs, done\n")); - - ((EMFormat *)m->format)->pending_uri_level = puri_level; -} - -static void -efh_format_done (struct _format_msg *m) -{ - d(printf("formatting finished\n")); - - m->format->priv->format_id = -1; - m->format->priv->load_images_now = FALSE; - m->format->state = EM_FORMAT_HTML_STATE_NONE; - g_signal_emit_by_name(m->format, "complete"); -} - -static void -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_object_unref(m->estream); + if (puri->func == emfh_write_related) { + g_string_printf(((EMFormat *)job->format)->part_id, "%s", puri->part_id); + em_format_part((EMFormat *)job->format, (CamelStream *)job->stream, puri->part); + } + /* else it was probably added by a previous format this loop */ + } + puri = purin; + purin = purin->next; } - if (m->folder) - camel_object_unref(m->folder); - g_free(m->uid); - if (m->message) - camel_object_unref(m->message); - if (m->format_source) - g_object_unref(m->format_source); -} -static MailMsgInfo efh_format_info = { - sizeof (struct _format_msg), - (MailMsgDescFunc) efh_format_desc, - (MailMsgExecFunc) efh_format_exec, - (MailMsgDoneFunc) efh_format_done, - (MailMsgFreeFunc) efh_format_free -}; + g_string_printf(((EMFormat *)job->format)->part_id, "%s", oldpartid); + g_free(oldpartid); +} -static gboolean -efh_format_timeout(struct _format_msg *m) +/* RFC 2387 */ +static void +efh_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) { - GtkHTMLStream *hstream; - EMFormatHTML *efh = m->format; - struct _EMFormatHTMLPrivate *p = efh->priv; + CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)part); + CamelMimePart *body_part, *display_part = NULL; + CamelContentType *content_type; + const char *start; + int i, nparts, partidlen, displayid = 0; + /* puri is set but never used */ + EMFormatPURI *puri; + struct _EMFormatHTMLJob *job; - if (m->format->html == NULL) { - mail_msg_unref(m); - return FALSE; + if (!CAMEL_IS_MULTIPART(mp)) { + em_format_format_source(emf, stream, part); + return; } - d(printf("timeout called ...\n")); - if (p->format_id != -1) { - d(printf(" still waiting for cancellation to take effect, waiting ...\n")); - return TRUE; - } + 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) { + int len; + const char *cid; - g_return_val_if_fail (e_dlist_empty(&p->pending_jobs), FALSE); + /* strip <>'s */ + len = strlen (start) - 2; + start++; - d(printf(" ready to go, firing off format thread\n")); + for (i=0; iformat_clone ( - EM_FORMAT (efh), m->folder, m->uid, - m->message, m->format_source); - em_format_html_clear_pobject(m->format); + if (cid && !strncmp(cid, start, len) && strlen(cid) == len) { + display_part = body_part; + displayid = i; + break; + } + } + } else { + display_part = camel_multipart_get_part(mp, 0); + } - /* FIXME: method off EMFormat? */ - if (((EMFormat *)efh)->valid) { - camel_cipher_validity_free(((EMFormat *)efh)->valid); - ((EMFormat *)efh)->valid = NULL; - ((EMFormat *)efh)->valid_parent = NULL; + if (display_part == NULL) { + em_format_part_as(emf, stream, part, "multipart/mixed"); + return; } - if (m->message == NULL) { - hstream = gtk_html_begin(efh->html); - gtk_html_stream_close(hstream, GTK_HTML_STREAM_OK); - mail_msg_unref(m); - p->last_part = NULL; - } else { - efh->state = EM_FORMAT_HTML_STATE_RENDERING; + em_format_push_level(emf); - if (p->last_part != m->message) { - hstream = gtk_html_begin (efh->html); - gtk_html_stream_printf (hstream, "
%s
", _("Formatting Message...")); - gtk_html_stream_close (hstream, GTK_HTML_STREAM_OK); - } + partidlen = emf->part_id->len; - hstream = NULL; - m->estream = (EMHTMLStream *)em_html_stream_new(efh->html, hstream); + /* queue up the parts for possible inclusion */ + for (i = 0; i < nparts; i++) { + body_part = camel_multipart_get_part(mp, i); + if (body_part != display_part) { + g_string_append_printf(emf->part_id, "related.%d", i); + puri = em_format_add_puri(emf, sizeof(EMFormatPURI), NULL, body_part, emfh_write_related); + g_string_truncate(emf->part_id, partidlen); + d(printf(" part '%s' '%s' added\n", puri->uri?puri->uri:"", puri->cid)); + } + } - if (p->last_part == m->message) { - em_html_stream_set_flags (m->estream, - GTK_HTML_BEGIN_KEEP_SCROLL | GTK_HTML_BEGIN_KEEP_IMAGES - | GTK_HTML_BEGIN_BLOCK_UPDATES | GTK_HTML_BEGIN_BLOCK_IMAGES); - } else { - /* clear cache of inline-scanned text parts */ - g_hash_table_remove_all(p->text_inline_parts); + 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); - p->last_part = m->message; - } + /* 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); + job->stream = stream; + camel_object_ref(stream); + em_format_html_job_queue((EMFormatHTML *)emf, job); - efh->priv->format_id = m->base.seq; - mail_msg_unordered_push (m); - } + em_format_pull_level(emf); +} - efh->priv->format_timeout_id = 0; - efh->priv->format_timeout_msg = NULL; +static void +efh_write_image(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri) +{ + CamelDataWrapper *dw = camel_medium_get_content_object((CamelMedium *)puri->part); - return FALSE; + d(printf("writing image '%s'\n", puri->cid)); + camel_data_wrapper_decode_to_stream(dw, stream); + camel_stream_close(stream); } -static void efh_format_clone(EMFormat *emf, CamelFolder *folder, const char *uid, CamelMimeMessage *msg, EMFormat *emfsource) +static void +efh_image(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info) { - EMFormatHTML *efh = (EMFormatHTML *)emf; - struct _format_msg *m; + EMFormatPURI *puri; - /* How to sub-class ? Might need to adjust api ... */ + puri = em_format_add_puri((EMFormat *)efh, sizeof(EMFormatPURI), NULL, part, efh_write_image); + d(printf("adding image '%s'\n", puri->cid)); + camel_stream_printf(stream, "", puri->cid); +} - if (efh->html == NULL) - return; +static EMFormatHandler type_builtin_table[] = { + { "image/gif", (EMFormatFunc)efh_image }, + { "image/jpeg", (EMFormatFunc)efh_image }, + { "image/png", (EMFormatFunc)efh_image }, + { "image/x-png", (EMFormatFunc)efh_image }, + { "image/tiff", (EMFormatFunc)efh_image }, + { "image/x-bmp", (EMFormatFunc)efh_image }, + { "image/bmp", (EMFormatFunc)efh_image }, + { "image/svg", (EMFormatFunc)efh_image }, + { "image/x-cmu-raster", (EMFormatFunc)efh_image }, + { "image/x-ico", (EMFormatFunc)efh_image }, + { "image/x-portable-anymap", (EMFormatFunc)efh_image }, + { "image/x-portable-bitmap", (EMFormatFunc)efh_image }, + { "image/x-portable-graymap", (EMFormatFunc)efh_image }, + { "image/x-portable-pixmap", (EMFormatFunc)efh_image }, + { "image/x-xpixmap", (EMFormatFunc)efh_image }, + { "text/enriched", (EMFormatFunc)efh_text_enriched }, + { "text/plain", (EMFormatFunc)efh_text_plain }, + { "text/html", (EMFormatFunc)efh_text_html }, + { "text/richtext", (EMFormatFunc)efh_text_enriched }, + { "text/*", (EMFormatFunc)efh_text_plain }, + { "message/external-body", (EMFormatFunc)efh_message_external }, + { "message/delivery-status", (EMFormatFunc)efh_message_deliverystatus }, + { "multipart/related", (EMFormatFunc)efh_multipart_related }, - d(printf("efh_format called\n")); - if (efh->priv->format_timeout_id != 0) { - d(printf(" timeout for last still active, removing ...\n")); - g_source_remove(efh->priv->format_timeout_id); - efh->priv->format_timeout_id = 0; - mail_msg_unref(efh->priv->format_timeout_msg); - efh->priv->format_timeout_msg = NULL; - } + /* This is where one adds those busted, non-registered types, + that some idiot mailer writers out there decide to pull out + of their proverbials at random. */ - m = mail_msg_new(&efh_format_info); - m->format = (EMFormatHTML *)emf; - g_object_ref(emf); - m->format_source = emfsource; - if (emfsource) - g_object_ref(emfsource); - m->folder = folder; - if (folder) - camel_object_ref(folder); - m->uid = g_strdup(uid); - m->message = msg; - if (msg) - camel_object_ref(msg); + { "image/jpg", (EMFormatFunc)efh_image }, + { "image/pjpeg", (EMFormatFunc)efh_image }, - if (efh->priv->format_id == -1) { - d(printf(" idle, forcing format\n")); - efh_format_timeout(m); - } else { - d(printf(" still busy, cancelling and queuing wait\n")); - /* cancel and poll for completion */ - mail_msg_cancel(efh->priv->format_id); - efh->priv->format_timeout_msg = m; - efh->priv->format_timeout_id = g_timeout_add(100, (GSourceFunc)efh_format_timeout, m); - } -} + /* special internal types */ + + { "x-evolution/message/rfc822", (EMFormatFunc)efh_format_message } +}; -static void efh_format_error(EMFormat *emf, CamelStream *stream, const char *txt) +static void +efh_builtin_init(EMFormatHTMLClass *efhc) { - char *html; + EMFormatClass *efc; + gint ii; + + efc = (EMFormatClass *) efhc; - html = camel_text_to_html (txt, CAMEL_MIME_FILTER_TOHTML_CONVERT_NL|CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0); - camel_stream_printf(stream, "%s
", html); - g_free(html); + for (ii = 0; ii < G_N_ELEMENTS (type_builtin_table); ii++) + em_format_class_add_handler ( + efc, &type_builtin_table[ii]); } +/* ********************************************************************** */ + static void efh_format_text_header (EMFormatHTML *emfh, CamelStream *stream, const char *label, const char *value, guint32 flags) { @@ -2563,7 +2643,8 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) } } -static void efh_format_message(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) +static void +efh_format_message(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) { const EMFormatHandler *handle; @@ -2595,57 +2676,3 @@ static void efh_format_message(EMFormat *emf, CamelStream *stream, CamelMimePart emf->valid = save; emf->valid_parent = save_parent; } - -static void efh_format_source(EMFormat *emf, CamelStream *stream, CamelMimePart *part) -{ - CamelStreamFilter *filtered_stream; - CamelMimeFilter *html_filter; - CamelDataWrapper *dw = (CamelDataWrapper *)part; - - filtered_stream = camel_stream_filter_new_with_stream ((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_PRESERVE_8BIT, 0); - camel_stream_filter_add(filtered_stream, html_filter); - camel_object_unref(html_filter); - - camel_stream_write_string((CamelStream *)stream, "
"); - em_format_format_text(emf, (CamelStream *)filtered_stream, dw); - camel_object_unref(filtered_stream); - - camel_stream_write_string(stream, "
"); -} - -static void -efh_format_attachment(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const char *mime_type, const EMFormatHandler *handle) -{ - char *text, *html; - - /* we display all inlined attachments only */ - - /* this could probably be cleaned up ... */ - camel_stream_write_string(stream, - "" - "
" - "" - "
" - "
\n"); - - /* 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); - g_free(html); - g_free(text); - - camel_stream_write_string(stream, "
"); - - if (handle && em_format_is_inline(emf, emf->part_id->str, part, handle)) - handle->handler(emf, stream, part, handle); -} - -static gboolean -efh_busy(EMFormat *emf) -{ - return (((EMFormatHTML *)emf)->priv->format_id != -1); -} -- cgit v1.2.3 From 6e163b39c75dbba470d073b4f79a897aa6fb0e54 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 24 Mar 2009 02:05:26 +0000 Subject: Saving progress again on the attachment rewrite. svn path=/branches/kill-bonobo/; revision=37470 --- mail/em-format-html.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 6308947a26..fae1566876 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -200,10 +200,6 @@ efh_format_exec (struct _format_msg *m) handle = em_format_find_handler((EMFormat *)m->format, "x-evolution/message/rfc822"); if (handle) handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); - handle = em_format_find_handler((EMFormat *)m->format, "x-evolution/message/post-header-closure"); - if (handle && !((EMFormat *)m->format)->print) - handle->handler((EMFormat *)m->format, (CamelStream *)m->estream, (CamelMimePart *)m->message, handle); - } camel_stream_flush((CamelStream *)m->estream); -- cgit v1.2.3 From 2393a5d17e92435cb3d7726b04ff6f4a5c27c8db Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 24 May 2009 11:54:43 -0400 Subject: Eliminate redundant E_ICON_SIZE_* enumeration. --- mail/em-format-html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index fae1566876..cbf90a9214 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -1503,7 +1503,7 @@ efh_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, Camel 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, E_ICON_SIZE_DIALOG); + 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); -- cgit v1.2.3 From e4afd3f9fb962ea1295a0657ec9f83a427829171 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 26 May 2009 23:21:02 -0400 Subject: Remove trailing whitespace, again. --- mail/em-format-html.c | 70 +++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index d0172ea8ef..aa82851bc9 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -10,7 +10,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see + * License along with the program; if not, see * * * Authors: @@ -1500,18 +1500,18 @@ efh_format_text_header (EMFormatHTML *emfh, CamelStream *stream, const char *lab const char *fmt, *html; char *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 + else html = value; - + is_rtl = gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL; if (emfh->simple_headers) { fmt = "%s: %s
"; @@ -1528,7 +1528,7 @@ efh_format_text_header (EMFormatHTML *emfh, CamelStream *stream, const char *lab else fmt = "
%s %s
%2$s%1$s: 
", efh->header_colour & 0xffffff); - + hdr_charset = emf->charset ? emf->charset : emf->default_charset; - + header = ((CamelMimePart *)part)->headers; while (header) { if (!g_ascii_strcasecmp (header->name, "Sender")) { @@ -1904,7 +1904,7 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) header = header->next; } - + if (header_sender && header_from && mail_from_delegate) { camel_stream_printf(stream, ""); if (photo_name) { - char *classid; + gchar *classid; CamelMimePart *photopart; gboolean only_local_photo; cia = camel_internet_address_new(); - camel_address_decode((CamelAddress *) cia, (const char *) photo_name); + 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); @@ -2598,11 +2598,11 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) } if (!contact_has_photo && face_decoded) { - char *classid; + gchar *classid; CamelMimePart *part; part = camel_mime_part_new (); - camel_mime_part_set_content ((CamelMimePart *) part, (const char *) face_header_value, face_header_len, "image/png"); + 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, "", classid); em_format_add_puri(emf, sizeof(EMFormatPURI), classid, part, efh_write_image); @@ -2611,7 +2611,7 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) if (have_icon && efh->show_icon) { GtkIconInfo *icon_info; - char *classid; + gchar *classid; CamelMimePart *iconpart = NULL; classid = g_strdup_printf("icon:///em-format-html/%s/icon/header", emf->part_id->str); -- cgit v1.2.3 From 433eac7844481b8ceda0bae8bf08f6bb623185b0 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 1 Jun 2009 19:09:19 -0400 Subject: More code cleanup. --- mail/em-format-html.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 1991c0d67f..0d1b6c545a 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -1153,7 +1153,7 @@ em_format_html_file_part(EMFormatHTML *efh, const gchar *mime_type, const gchar /* all this api is a pain in the bum ... */ EMFormatHTMLPObject * -em_format_html_add_pobject(EMFormatHTML *efh, size_t size, const gchar *classid, CamelMimePart *part, EMFormatHTMLPObjectFunc func) +em_format_html_add_pobject(EMFormatHTML *efh, gsize size, const gchar *classid, CamelMimePart *part, EMFormatHTMLPObjectFunc func) { EMFormatHTMLPObject *pobj; @@ -1263,7 +1263,7 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, gint cancelled) CamelURL *url; CamelContentType *content_type; CamelHttpStream *tmp_stream; - ssize_t n, total = 0, pc_complete = 0, nread = 0; + gssize n, total = 0, pc_complete = 0, nread = 0; gchar buffer[1500]; const gchar *length; @@ -1822,7 +1822,7 @@ efh_message_external(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part s = d = url; while (*s) { /* FIXME: use camel_isspace */ - if (!isspace ((unsigned char)*s)) + if (!isspace ((guchar)*s)) *d++ = *s; s++; } -- cgit v1.2.3 From c0d998229d5a3d2b65445b9025de7b23112f4063 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 18 Jun 2009 15:26:21 -0400 Subject: Stop abusing forward declarations. --- mail/em-format-html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 0d1b6c545a..9da3484f99 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -96,7 +96,7 @@ struct _EMFormatHTMLCache { }; struct _EMFormatHTMLPrivate { - struct _CamelMimeMessage *last_part; /* not reffed, DO NOT dereference */ + CamelMimeMessage *last_part; /* not reffed, DO NOT dereference */ volatile gint format_id; /* format thread id */ guint format_timeout_id; struct _format_msg *format_timeout_msg; -- cgit v1.2.3 From 374bd42f69aca2e132fd854c9619f3d7491f1f96 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 12 Jul 2009 23:33:07 -0400 Subject: Fix excessive whitespace. --- mail/em-format-html.c | 1 - 1 file changed, 1 deletion(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 9da3484f99..31c4cf0e88 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -2216,7 +2216,6 @@ efh_format_address (EMFormatHTML *efh, GString *out, struct _camel_header_addres if (limit > 0 && i>(limit)) { - if (!strcmp (field, _("To"))) { str = g_strdup_printf (" ", EVOLUTION_ICONSDIR); } -- cgit v1.2.3 From fa360fde289f9b850191f89059d1a5e6d67c07c7 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 18 Jul 2009 14:07:42 -0400 Subject: More whitespace cleanup. --- mail/em-format-html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 31c4cf0e88..fa713282c1 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -2477,7 +2477,7 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) if (header_sender && header_from && mail_from_delegate) { camel_stream_printf(stream, "
"); if(gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) @@ -1976,11 +1976,11 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) have_icon = TRUE; } else if (!face_decoded && face && !g_ascii_strcasecmp (header->name, "Face")) { char *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; -- cgit v1.2.3 From 948235c3d1076dbe6ed2e57a24c16a083bbd9f01 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 27 May 2009 10:29:19 -0400 Subject: Prefer GLib basic types over C types. --- mail/em-format-html.c | 156 +++++++++++++++++++++++++------------------------- 1 file changed, 78 insertions(+), 78 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 6bc4a79794..1991c0d67f 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -92,12 +92,12 @@ struct _EMFormatHTMLCache { CamelMultipart *textmp; - char partid[1]; + gchar partid[1]; }; struct _EMFormatHTMLPrivate { struct _CamelMimeMessage *last_part; /* not reffed, DO NOT dereference */ - volatile int format_id; /* format thread id */ + volatile gint format_id; /* format thread id */ guint format_timeout_id; struct _format_msg *format_timeout_msg; @@ -129,7 +129,7 @@ enum { PROP_TEXT_COLOR }; -static void efh_url_requested(GtkHTML *html, const char *url, GtkHTMLStream *handle, EMFormatHTML *efh); +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); @@ -154,7 +154,7 @@ struct _format_msg { EMFormat *format_source; EMHTMLStream *estream; CamelFolder *folder; - char *uid; + gchar *uid; CamelMimeMessage *message; }; @@ -169,7 +169,7 @@ efh_format_exec (struct _format_msg *m) { struct _EMFormatHTMLJob *job; struct _EMFormatPURITree *puri_level; - int cancelled = FALSE; + gint cancelled = FALSE; CamelURL *base; if (m->format->html == NULL) @@ -395,7 +395,7 @@ efh_gtkhtml_destroy(GtkHTML *html, EMFormatHTML *efh) } static struct _EMFormatHTMLCache * -efh_insert_cache(EMFormatHTML *efh, const char *partid) +efh_insert_cache(EMFormatHTML *efh, const gchar *partid) { struct _EMFormatHTMLCache *efhc; @@ -685,7 +685,7 @@ efh_format_attachment (EMFormat *emf, const gchar *mime_type, const EMFormatHandler *handle) { - char *text, *html; + gchar *text, *html; /* we display all inlined attachments only */ @@ -1123,12 +1123,12 @@ em_format_html_set_show_sender_photo (EMFormatHTML *efh, } CamelMimePart * -em_format_html_file_part(EMFormatHTML *efh, const char *mime_type, const char *filename) +em_format_html_file_part(EMFormatHTML *efh, const gchar *mime_type, const gchar *filename) { CamelMimePart *part; CamelStream *stream; CamelDataWrapper *dw; - char *basename; + gchar *basename; stream = camel_stream_fs_new_with_name(filename, O_RDONLY, 0); if (stream == NULL) @@ -1153,7 +1153,7 @@ em_format_html_file_part(EMFormatHTML *efh, const char *mime_type, const char *f /* all this api is a pain in the bum ... */ EMFormatHTMLPObject * -em_format_html_add_pobject(EMFormatHTML *efh, size_t size, const char *classid, CamelMimePart *part, EMFormatHTMLPObjectFunc func) +em_format_html_add_pobject(EMFormatHTML *efh, size_t size, const gchar *classid, CamelMimePart *part, EMFormatHTMLPObjectFunc func) { EMFormatHTMLPObject *pobj; @@ -1178,7 +1178,7 @@ em_format_html_add_pobject(EMFormatHTML *efh, size_t size, const char *classid, } EMFormatHTMLPObject * -em_format_html_find_pobject(EMFormatHTML *emf, const char *classid) +em_format_html_find_pobject(EMFormatHTML *emf, const gchar *classid) { EMFormatHTMLPObject *pw; @@ -1226,7 +1226,7 @@ em_format_html_clear_pobject(EMFormatHTML *emf) } struct _EMFormatHTMLJob * -em_format_html_job_new(EMFormatHTML *emfh, void (*callback)(struct _EMFormatHTMLJob *job, int cancelled), void *data) +em_format_html_job_new(EMFormatHTML *emfh, void (*callback)(struct _EMFormatHTMLJob *job, gint cancelled), gpointer data) { struct _EMFormatHTMLJob *job = g_malloc0(sizeof(*job)); @@ -1250,22 +1250,22 @@ em_format_html_job_queue(EMFormatHTML *emfh, struct _EMFormatHTMLJob *job) /* ********************************************************************** */ -static void emfh_getpuri(struct _EMFormatHTMLJob *job, int 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); } -static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) +static void emfh_gethttp(struct _EMFormatHTMLJob *job, gint cancelled) { CamelStream *cistream = NULL, *costream = NULL, *instream = NULL; CamelURL *url; CamelContentType *content_type; CamelHttpStream *tmp_stream; ssize_t n, total = 0, pc_complete = 0, nread = 0; - char buffer[1500]; - const char *length; + gchar buffer[1500]; + const gchar *length; if (cancelled || (url = camel_url_new(job->u.uri, NULL)) == NULL) @@ -1278,7 +1278,7 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) if (instream == NULL) { MailConfigHTTPMode policy; - char *proxy; + gchar *proxy; policy = em_format_html_get_image_loading_policy (job->format); @@ -1364,7 +1364,7 @@ badurl: /* ********************************************************************** */ static void -efh_url_requested(GtkHTML *html, const char *url, GtkHTMLStream *handle, EMFormatHTML *efh) +efh_url_requested(GtkHTML *html, const gchar *url, GtkHTMLStream *handle, EMFormatHTML *efh) { EMFormatPURI *puri; struct _EMFormatHTMLJob *job = NULL; @@ -1398,7 +1398,7 @@ efh_url_requested(GtkHTML *html, const char *url, GtkHTMLStream *handle, EMForma d(printf(" adding job, get %s\n", url)); job = em_format_html_job_new(efh, emfh_gethttp, g_strdup(url)); } else if (g_ascii_strncasecmp(url, "/", 1) == 0) { - char *data = NULL; + gchar *data = NULL; gsize length = 0; gboolean status; @@ -1423,7 +1423,7 @@ static gboolean efh_object_requested(GtkHTML *html, GtkHTMLEmbedded *eb, EMFormatHTML *efh) { EMFormatHTMLPObject *pobject; - int res = FALSE; + gint res = FALSE; if (eb->classid == NULL) return FALSE; @@ -1447,7 +1447,7 @@ efh_object_requested(GtkHTML *html, GtkHTMLEmbedded *eb, EMFormatHTML *efh) /* FIXME: This is duplicated in em-format-html-display, should be exported or in security module */ static const struct { - const char *icon, *shortdesc; + const gchar *icon, *shortdesc; } smime_sign_table[5] = { { "stock_signature-bad", N_("Unsigned") }, { "stock_signature-ok", N_("Valid signature") }, @@ -1457,7 +1457,7 @@ static const struct { }; static const struct { - const char *icon, *shortdesc; + const gchar *icon, *shortdesc; } smime_encrypt_table[4] = { { "stock_lock-broken", N_("Unencrypted") }, { "stock_lock", N_("Encrypted, weak"),}, @@ -1465,7 +1465,7 @@ static const struct { { "stock_lock-ok", N_("Encrypted, strong") }, }; -static const char *smime_sign_colour[4] = { +static const gchar *smime_sign_colour[4] = { "", " bgcolor=\"#88bb88\"", " bgcolor=\"#bb8888\"", " bgcolor=\"#e8d122\"" }; @@ -1487,8 +1487,8 @@ efh_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, Camel if (emf->valid == valid && (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE || valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE)) { - char *classid, *iconpath; - const char *icon; + gchar *classid, *iconpath; + const gchar *icon; CamelMimePart *iconpart; camel_stream_printf (stream, "
", @@ -1530,10 +1530,10 @@ efh_text_plain(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFo CamelMultipart *mp; CamelDataWrapper *dw; CamelContentType *type; - const char *format; + const gchar *format; guint32 flags; guint32 rgb; - int i, count, len; + gint i, count, len; struct _EMFormatHTMLCache *efhc; flags = efh->text_html_flags; @@ -1679,7 +1679,7 @@ efh_write_text_html(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri) { #if d(!)0 CamelStream *out; - int fd; + gint fd; CamelDataWrapper *dw; fd = dup(STDOUT_FILENO); @@ -1696,10 +1696,10 @@ efh_write_text_html(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri) static void efh_text_html(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info) { - const char *location; + const gchar *location; /* This is set but never used for anything */ EMFormatPURI *puri; - char *cid = NULL; + gchar *cid = NULL; camel_stream_printf ( stream, "
\n" @@ -1751,8 +1751,8 @@ static void efh_message_external(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info) { CamelContentType *type; - const char *access_type; - char *url = NULL, *desc = NULL; + const gchar *access_type; + gchar *url = NULL, *desc = NULL; if (!part) { camel_stream_printf(stream, _("Unknown external-body part.")); @@ -1769,9 +1769,9 @@ efh_message_external(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part if (!g_ascii_strcasecmp(access_type, "ftp") || !g_ascii_strcasecmp(access_type, "anon-ftp")) { - const char *name, *site, *dir, *mode; - char *path; - char ftype[16]; + const gchar *name, *site, *dir, *mode; + gchar *path; + gchar ftype[16]; name = camel_content_type_param (type, "name"); site = camel_content_type_param (type, "site"); @@ -1795,7 +1795,7 @@ efh_message_external(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part g_free (path); desc = g_strdup_printf (_("Pointer to FTP site (%s)"), url); } else if (!g_ascii_strcasecmp (access_type, "local-file")) { - const char *name, *site; + const gchar *name, *site; name = camel_content_type_param (type, "name"); site = camel_content_type_param (type, "site"); @@ -1808,8 +1808,8 @@ efh_message_external(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part else desc = g_strdup_printf(_("Pointer to local file (%s)"), name); } else if (!g_ascii_strcasecmp (access_type, "URL")) { - const char *urlparam; - char *s, *d; + const gchar *urlparam; + gchar *s, *d; /* RFC 2017 */ @@ -1882,11 +1882,11 @@ emfh_write_related(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri) } static void -emfh_multipart_related_check(struct _EMFormatHTMLJob *job, int cancelled) +emfh_multipart_related_check(struct _EMFormatHTMLJob *job, gint cancelled) { struct _EMFormatPURITree *ptree; EMFormatPURI *puri, *purin; - char *oldpartid; + gchar *oldpartid; if (cancelled) return; @@ -1921,8 +1921,8 @@ efh_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)part); CamelMimePart *body_part, *display_part = NULL; CamelContentType *content_type; - const char *start; - int i, nparts, partidlen, displayid = 0; + const gchar *start; + gint i, nparts, partidlen, displayid = 0; /* puri is set but never used */ EMFormatPURI *puri; struct _EMFormatHTMLJob *job; @@ -1936,8 +1936,8 @@ efh_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c content_type = camel_mime_part_get_content_type(part); start = camel_content_type_param (content_type, "start"); if (start && strlen(start)>2) { - int len; - const char *cid; + gint len; + const gchar *cid; /* strip <>'s */ len = strlen (start) - 2; @@ -2064,10 +2064,10 @@ efh_builtin_init(EMFormatHTMLClass *efhc) /* ********************************************************************** */ static void -efh_format_text_header (EMFormatHTML *emfh, CamelStream *stream, const char *label, const char *value, guint32 flags) +efh_format_text_header (EMFormatHTML *emfh, CamelStream *stream, const gchar *label, const gchar *value, guint32 flags) { - const char *fmt, *html; - char *mhtml = NULL; + const gchar *fmt, *html; + gchar *mhtml = NULL; gboolean is_rtl; if (value == NULL) @@ -2126,11 +2126,11 @@ static gchar * efh_format_address (EMFormatHTML *efh, GString *out, struct _camel_header_address *a, gchar *field) { guint32 flags = CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES; - char *name, *mailto, *addr; - int i=0; + gchar *name, *mailto, *addr; + gint i=0; gboolean wrap = FALSE; - char *str = NULL; - int limit = mail_config_get_address_count (); + 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)) @@ -2148,11 +2148,11 @@ efh_format_address (EMFormatHTML *efh, GString *out, struct _camel_header_addres switch (a->type) { case CAMEL_HEADER_ADDRESS_NAME: if (name && *name) { - char *real, *mailaddr; + gchar *real, *mailaddr; g_string_append_printf (out, "%s <", name); /* rfc2368 for mailto syntax and url encoding extras */ - if ((real = camel_header_encode_phrase ((unsigned char *)a->name))) { + 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, "?=&()"); @@ -2233,9 +2233,9 @@ efh_format_address (EMFormatHTML *efh, GString *out, struct _camel_header_addres } static void -canon_header_name (char *name) +canon_header_name (gchar *name) { - char *inptr = name; + gchar *inptr = name; /* canonicalise the header name... first letter is * capitalised and any letter following a '-' also gets @@ -2257,14 +2257,14 @@ canon_header_name (char *name) } static void -efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct _camel_header_raw *header, guint32 flags, const char *charset) +efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct _camel_header_raw *header, guint32 flags, const gchar *charset) { EMFormatHTML *efh = (EMFormatHTML *)emf; - char *name, *buf, *value = NULL; - const char *label, *txt; + gchar *name, *buf, *value = NULL; + const gchar *label, *txt; gboolean addrspec = FALSE; - char *str_field = NULL; - int i; + gchar *str_field = NULL; + gint i; name = alloca(strlen(header->name)+1); strcpy(name, header->name); @@ -2282,7 +2282,7 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct if (addrspec) { struct _camel_header_address *addrs; GString *html; - char *img; + gchar *img; buf = camel_header_unfold (header->value); if (!(addrs = camel_header_address_decode (buf, emf->charset ? emf->charset : emf->default_charset))) { @@ -2293,7 +2293,7 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct g_free (buf); html = g_string_new(""); - img = efh_format_address(efh, html, addrs, (char *)label); + img = efh_format_address(efh, html, addrs, (gchar *)label); if (img) { str_field = g_strdup_printf ("%s%s:", img, label); @@ -2319,7 +2319,7 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct txt = value = camel_header_format_ctext (header->value, charset); flags |= EM_FORMAT_HEADER_BOLD; } else if (!strcmp (name, "Date") || !strcmp (name, "Resent-Date")) { - int msg_offset, local_tz; + gint msg_offset, local_tz; time_t msg_date; struct tm local; @@ -2337,17 +2337,17 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct msg_offset -= local_tz / 60; if (msg_offset) { - char buf[256], *html; + gchar buf[256], *html; msg_offset += (local.tm_hour * 60) + local.tm_min; if (msg_offset >= (24 * 60) || msg_offset < 0) { /* translators: strftime format for local time equivalent in Date header display, with day */ - char *msg = g_strdup_printf("%s", _(" (%a, %R %Z)")); + gchar *msg = g_strdup_printf("%s", _(" (%a, %R %Z)")); e_utf8_strftime(buf, sizeof(buf), msg, &local); g_free(msg); } else { /* translators: strftime format for local time equivalent in Date header display, without day */ - char *msg = g_strdup_printf("%s", _(" (%R %Z)")); + gchar *msg = g_strdup_printf("%s", _(" (%R %Z)")); e_utf8_strftime(buf, sizeof(buf), msg, &local); g_free(msg); } @@ -2407,18 +2407,18 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) { EMFormat *emf = (EMFormat *) efh; EMFormatHeader *h; - const char *charset; + const gchar *charset; CamelContentType *ct; struct _camel_header_raw *header; gboolean have_icon = FALSE; - const char *photo_name = NULL; + const gchar *photo_name = NULL; CamelInternetAddress *cia = NULL; gboolean face_decoded = FALSE, contact_has_photo = FALSE; guchar *face_header_value = NULL; gsize face_header_len = 0; - char *header_sender = NULL, *header_from = NULL, *name; + gchar *header_sender = NULL, *header_from = NULL, *name; gboolean mail_from_delegate = FALSE; - const char *hdr_charset; + const gchar *hdr_charset; if (!part) return; @@ -2506,9 +2506,9 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) header = header->next; } } else { - int mailer_shown = FALSE; + gint mailer_shown = FALSE; while (h->next) { - int mailer, face; + gint mailer, face; header = ((CamelMimePart *)part)->headers; mailer = !g_ascii_strcasecmp (h->name, "X-Evolution-Mailer"); @@ -2547,7 +2547,7 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) if (strstr(use_header->value, "Evolution")) have_icon = TRUE; } else if (!face_decoded && face && !g_ascii_strcasecmp (header->name, "Face")) { - char *cp = header->value; + gchar *cp = header->value; /* Skip over spaces */ while (*cp == ' ') @@ -2572,12 +2572,12 @@ efh_format_headers(EMFormatHTML *efh, CamelStream *stream, CamelMedium *part) camel_stream_printf(stream, "
"); - if(gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) + if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) camel_stream_printf (stream, "
"); else camel_stream_printf (stream, ""); -- cgit v1.2.3 From 50302d03b3ce145b165db2ddef4e92ad190cbef9 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 4 Aug 2009 15:04:02 +0200 Subject: Bug #205137 - Configurable date formats in components --- mail/em-format-html.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'mail/em-format-html.c') diff --git a/mail/em-format-html.c b/mail/em-format-html.c index fa713282c1..b9657a1fd9 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -43,6 +43,7 @@ #include /* for e_utf8_strftime, what about e_time_format_time? */ #include +#include "e-util/e-datetime-format.h" #include "e-util/e-icon-factory.h" #include "e-util/e-util-private.h" #include "e-util/e-util.h" @@ -2321,14 +2322,16 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct gint msg_offset, local_tz; time_t msg_date; struct tm local; + gchar *date_str; txt = header->value; while (*txt == ' ' || *txt == '\t') txt++; - /* Show the local timezone equivalent in brackets if the sender is remote */ msg_date = camel_header_decode_date(txt, &msg_offset); - e_localtime_with_offset(msg_date, &local, &local_tz); + e_localtime_with_offset (msg_date, &local, &local_tz); + + date_str = e_datetime_format_format ("mail", "header", DTFormatKindDateTime, msg_date); /* Convert message offset to minutes (e.g. -0400 --> -240) */ msg_offset = ((msg_offset / 100) * 60) + (msg_offset % 100); @@ -2336,25 +2339,18 @@ efh_format_header(EMFormat *emf, CamelStream *stream, CamelMedium *part, struct msg_offset -= local_tz / 60; if (msg_offset) { - gchar buf[256], *html; - - msg_offset += (local.tm_hour * 60) + local.tm_min; - if (msg_offset >= (24 * 60) || msg_offset < 0) { - /* translators: strftime format for local time equivalent in Date header display, with day */ - gchar *msg = g_strdup_printf("%s", _(" (%a, %R %Z)")); - e_utf8_strftime(buf, sizeof(buf), msg, &local); - g_free(msg); - } else { - /* translators: strftime format for local time equivalent in Date header display, without day */ - gchar *msg = g_strdup_printf("%s", _(" (%R %Z)")); - e_utf8_strftime(buf, sizeof(buf), msg, &local); - g_free(msg); - } + gchar *html; + + html = camel_text_to_html (txt, efh->text_html_flags, 0); + txt = value = g_strdup_printf ("%s (%s)", date_str, html); + + g_free (html); + g_free (date_str); - html = camel_text_to_html(txt, efh->text_html_flags, 0); - txt = value = g_strdup_printf("%s %s", html, buf); - g_free(html); flags |= EM_FORMAT_HTML_HEADER_HTML; + } else { + /* date_str will be freed at the end */ + txt = value = date_str; } flags |= EM_FORMAT_HEADER_BOLD; -- cgit v1.2.3