From dbd786a2dded4808518c91cb2414d173e50f5aa9 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Wed, 19 May 2004 07:02:12 +0000 Subject: if we end up with an application/octet-stream part, pre-snoop it so we set 2004-05-19 Not Zed * 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 --- mail/em-utils.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'mail/em-utils.c') 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 #include +#include +#include +#include + #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 */ +} -- cgit v1.2.3