diff options
author | Not Zed <NotZed@Ximian.com> | 2004-05-19 15:02:12 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-05-19 15:02:12 +0800 |
commit | dbd786a2dded4808518c91cb2414d173e50f5aa9 (patch) | |
tree | 7e19c801ded9e36ee5ea22ff4f95c97f2582b04e | |
parent | 1f24a7b807ce7e466971f5c75ee4d43e4dab37a3 (diff) | |
download | gsoc2013-evolution-dbd786a2dded4808518c91cb2414d173e50f5aa9.tar gsoc2013-evolution-dbd786a2dded4808518c91cb2414d173e50f5aa9.tar.gz gsoc2013-evolution-dbd786a2dded4808518c91cb2414d173e50f5aa9.tar.bz2 gsoc2013-evolution-dbd786a2dded4808518c91cb2414d173e50f5aa9.tar.lz gsoc2013-evolution-dbd786a2dded4808518c91cb2414d173e50f5aa9.tar.xz gsoc2013-evolution-dbd786a2dded4808518c91cb2414d173e50f5aa9.tar.zst gsoc2013-evolution-dbd786a2dded4808518c91cb2414d173e50f5aa9.zip |
if we end up with an application/octet-stream part, pre-snoop it so we set
2004-05-19 Not Zed <NotZed@Ximian.com>
* em-inline-filter.c (emif_add_part): if we end up with an
application/octet-stream part, pre-snoop it so we set the right
mime type to start with. Fixes #58554.
* em-format.c (emf_snoop_part): removed, now in em-utils.
* em-utils.c (em_utils_snoop_type): rah rah, snoop a mime part's
type.
* em-format-html.c (efh_text_plain): Revert jeff's fix for #56290.
Ugh, we already have all the citation info in local data. Removed
the need for gconf too.
svn path=/trunk/; revision=25974
-rw-r--r-- | mail/ChangeLog | 15 | ||||
-rw-r--r-- | mail/em-format-html.c | 30 | ||||
-rw-r--r-- | mail/em-format.c | 52 | ||||
-rw-r--r-- | mail/em-inline-filter.c | 19 | ||||
-rw-r--r-- | mail/em-utils.c | 59 | ||||
-rw-r--r-- | mail/em-utils.h | 2 |
6 files changed, 97 insertions, 80 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 5dfddcb7ce..c4b8061547 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,5 +1,20 @@ 2004-05-19 Not Zed <NotZed@Ximian.com> + * em-inline-filter.c (emif_add_part): if we end up with an + application/octet-stream part, pre-snoop it so we set the right + mime type to start with. Fixes #58554. + + * em-format.c (emf_snoop_part): removed, now in em-utils. + + * em-utils.c (em_utils_snoop_type): rah rah, snoop a mime part's + type. + + * em-format-html.c (efh_text_plain): Revert jeff's fix for #56290. + Ugh, we already have all the citation info in local data. Removed + the need for gconf too. + +2004-05-19 Not Zed <NotZed@Ximian.com> + * em-format-html.c (efh_format_secure): make this match the efhd stuff. diff --git a/mail/em-format-html.c b/mail/em-format-html.c index f2d346378a..684d60aed6 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -31,8 +31,6 @@ #include <fcntl.h> #include <ctype.h> -#include <gconf/gconf-client.h> - #include <gal/util/e-iconv.h> #include <gal/util/e-util.h> /* for e_utf8_strftime, what about e_time_format_time? */ #include "e-util/e-time-utils.h" @@ -635,9 +633,8 @@ efh_text_plain(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFo CamelDataWrapper *dw; CamelContentType *type; const char *format; - guint32 rgb, flags; + guint32 flags; int i, count, len; - GConfClient *gconf; camel_stream_printf (stream, "<table bgcolor=\"#%06x\" cellspacing=0 cellpadding=1 width=100%%><tr><td>\n" @@ -693,30 +690,9 @@ efh_text_plain(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFo camel_object_unref(inline_filter); camel_content_type_unref(ct); } - - gconf = gconf_client_get_default (); - if (gconf_client_get_bool (gconf, "/apps/evolution/mail/display/mark_citations", NULL)) { - GError *err = NULL; - GdkColor colour; - char *str; - - str = gconf_client_get_string (gconf, "/apps/evolution/mail/display/citation_colour", &err); - if (err == NULL) { - gdk_color_parse (str, &colour); - rgb = ((colour.red & 0xff00) << 8) | (colour.green & 0xff00) | ((colour.blue & 0xff00) >> 8); - } else { - /* default colour */ - g_error_free (err); - rgb = 0x737373; - } - g_free (str); - } else { - rgb = 0; - } - g_object_unref (gconf); - + filtered_stream = camel_stream_filter_new_with_stream(stream); - html_filter = camel_mime_filter_tohtml_new(flags, rgb); + html_filter = camel_mime_filter_tohtml_new(flags, efh->citation_colour); camel_stream_filter_add(filtered_stream, html_filter); camel_object_unref(html_filter); diff --git a/mail/em-format.c b/mail/em-format.c index e585897d94..35fed724ca 100644 --- a/mail/em-format.c +++ b/mail/em-format.c @@ -50,11 +50,11 @@ #include <camel/camel-mime-filter-windows.h> #include "em-format.h" +#include "em-utils.h" #define d(x) static void emf_builtin_init(EMFormatClass *); -static const char *emf_snoop_part(CamelMimePart *part); static const EMFormatHandler *emf_find_handler(EMFormat *emf, const char *mime_type); static void emf_format_clone(EMFormat *emf, CamelFolder *folder, const char *uid, CamelMimeMessage *msg, EMFormat *emfsource); @@ -485,7 +485,7 @@ em_format_part_as(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const if (mime_type != NULL) { if (g_ascii_strcasecmp(mime_type, "application/octet-stream") == 0) - emf->snoop_mime_type = mime_type = emf_snoop_part(part); + emf->snoop_mime_type = mime_type = em_utils_snoop_type(part); handle = em_format_find_handler(emf, mime_type); if (handle == NULL) @@ -1004,54 +1004,6 @@ em_format_describe_part(CamelMimePart *part, const char *mime_type) /* ********************************************************************** */ -/* originally from mail-identify.c */ -static const char * -emf_snoop_part(CamelMimePart *part) -{ - const char *filename, *name_type = NULL, *magic_type = NULL; - CamelDataWrapper *dw; - - filename = camel_mime_part_get_filename (part); - if (filename) { - /* GNOME-VFS will misidentify TNEF attachments as MPEG */ - if (!strcmp (filename, "winmail.dat")) - return "application/vnd.ms-tnef"; - - name_type = gnome_vfs_mime_type_from_name(filename); - } - - dw = camel_medium_get_content_object((CamelMedium *)part); - if (!camel_data_wrapper_is_offline(dw)) { - CamelStreamMem *mem = (CamelStreamMem *)camel_stream_mem_new(); - - if (camel_data_wrapper_decode_to_stream(dw, (CamelStream *)mem) > 0) - magic_type = gnome_vfs_get_mime_type_for_data(mem->buffer->data, mem->buffer->len); - camel_object_unref(mem); - } - - d(printf("snooped part, magic_type '%s' name_type '%s'\n", magic_type, name_type)); - - /* If GNOME-VFS doesn't recognize the data by magic, but it - * contains English words, it will call it text/plain. If the - * filename-based check came up with something different, use - * that instead and if it returns "application/octet-stream" - * try to do better with the filename check. - */ - - if (magic_type) { - if (name_type - && (!strcmp(magic_type, "text/plain") - || !strcmp(magic_type, "application/octet-stream"))) - return name_type; - else - return magic_type; - } else - return name_type; - - /* We used to load parts to check their type, we dont anymore, - see bug #11778 for some discussion */ -} - #ifdef ENABLE_SMIME static void emf_application_xpkcs7mime(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) diff --git a/mail/em-inline-filter.c b/mail/em-inline-filter.c index 9fc4294139..4b21cee46d 100644 --- a/mail/em-inline-filter.c +++ b/mail/em-inline-filter.c @@ -31,6 +31,8 @@ #include <camel/camel-multipart.h> #include <camel/camel-stream-mem.h> +#include "em-utils.h" + #define d(x) static void em_inline_filter_class_init (EMInlineFilterClass *klass); @@ -120,6 +122,7 @@ emif_add_part(EMInlineFilter *emif, const char *data, int len) CamelStream *mem; CamelDataWrapper *dw; CamelMimePart *part; + const char *mimetype; if (emif->state == EMIF_PLAIN) type = emif->base_encoding; @@ -144,12 +147,22 @@ emif_add_part(EMInlineFilter *emif, const char *data, int len) camel_mime_part_set_encoding(part, type); camel_object_unref(dw); - if (emif->filename) { + if (emif->filename) camel_mime_part_set_filename(part, emif->filename); - g_free(emif->filename); - emif->filename = NULL; + + /* pre-snoop the mime type of unknown objects, and poke and hack it into place */ + if (camel_content_type_is(dw->mime_type, "application", "octet-stream") + && (mimetype = em_utils_snoop_type(part)) + && strcmp(mimetype, "application/octet-stream") != 0) { + camel_data_wrapper_set_mime_type(dw, mimetype); + camel_mime_part_set_content_type(part, mimetype); + if (emif->filename) + camel_mime_part_set_filename(part, emif->filename); } + g_free(emif->filename); + emif->filename = NULL; + emif->parts = g_slist_append(emif->parts, part); } diff --git a/mail/em-utils.c b/mail/em-utils.c index e655b456c1..9cf3ff66b4 100644 --- a/mail/em-utils.c +++ b/mail/em-utils.c @@ -41,6 +41,10 @@ #include <bonobo/bonobo-widget.h> #include <bonobo/bonobo-event-source.h> +#include <libgnomevfs/gnome-vfs-mime.h> +#include <libgnomevfs/gnome-vfs-mime-utils.h> +#include <libgnomevfs/gnome-vfs-mime-handlers.h> + #include "mail-component.h" #include "mail-mt.h" #include "mail-ops.h" @@ -1765,3 +1769,58 @@ em_utils_in_addressbook(CamelInternetAddress *iaddr) return found; } + +/** + * em_utils_snoop_type: + * @part: + * + * Rries to snoop the mime type of a part. + * + * Return value: NULL if unknown (more likely application/octet-stream). + **/ +const char * +em_utils_snoop_type(CamelMimePart *part) +{ + const char *filename, *name_type = NULL, *magic_type = NULL; + CamelDataWrapper *dw; + + filename = camel_mime_part_get_filename (part); + if (filename) { + /* GNOME-VFS will misidentify TNEF attachments as MPEG */ + if (!strcmp (filename, "winmail.dat")) + return "application/vnd.ms-tnef"; + + name_type = gnome_vfs_mime_type_from_name(filename); + } + + dw = camel_medium_get_content_object((CamelMedium *)part); + if (!camel_data_wrapper_is_offline(dw)) { + CamelStreamMem *mem = (CamelStreamMem *)camel_stream_mem_new(); + + if (camel_data_wrapper_decode_to_stream(dw, (CamelStream *)mem) > 0) + magic_type = gnome_vfs_get_mime_type_for_data(mem->buffer->data, mem->buffer->len); + camel_object_unref(mem); + } + + d(printf("snooped part, magic_type '%s' name_type '%s'\n", magic_type, name_type)); + + /* If GNOME-VFS doesn't recognize the data by magic, but it + * contains English words, it will call it text/plain. If the + * filename-based check came up with something different, use + * that instead and if it returns "application/octet-stream" + * try to do better with the filename check. + */ + + if (magic_type) { + if (name_type + && (!strcmp(magic_type, "text/plain") + || !strcmp(magic_type, "application/octet-stream"))) + return name_type; + else + return magic_type; + } else + return name_type; + + /* We used to load parts to check their type, we dont anymore, + see bug #11778 for some discussion */ +} diff --git a/mail/em-utils.h b/mail/em-utils.h index 4e433ab12d..3fa6be2b1d 100644 --- a/mail/em-utils.h +++ b/mail/em-utils.h @@ -100,6 +100,8 @@ char *em_uri_to_camel (const char *euri); /* is this address in the addressbook? caches results */ gboolean em_utils_in_addressbook(struct _CamelInternetAddress *addr); +const char *em_utils_snoop_type(struct _CamelMimePart *part); + #ifdef __cplusplus } #endif /* __cplusplus */ |