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 /mail/em-utils.c | |
parent | 1f24a7b807ce7e466971f5c75ee4d43e4dab37a3 (diff) | |
download | gsoc2013-evolution-dbd786a2dded4808518c91cb2414d173e50f5aa9.tar.gz 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
Diffstat (limited to 'mail/em-utils.c')
-rw-r--r-- | mail/em-utils.c | 59 |
1 files changed, 59 insertions, 0 deletions
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 */ +} |