aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-08-22 04:27:30 +0800
committerDan Winship <danw@src.gnome.org>2001-08-22 04:27:30 +0800
commitc8f90c67cb998e6bf7cf1888efe385e4b29d3d93 (patch)
tree06f2f2e83ce650e6aa580937ef528187e7c1d75b
parent6af9655777dfb0acfc08ca5cacb85784ee352394 (diff)
downloadgsoc2013-evolution-c8f90c67cb998e6bf7cf1888efe385e4b29d3d93.tar.gz
gsoc2013-evolution-c8f90c67cb998e6bf7cf1888efe385e4b29d3d93.tar.zst
gsoc2013-evolution-c8f90c67cb998e6bf7cf1888efe385e4b29d3d93.zip
Don't trust gnome-vfs when it says "text/plain" if
* mail-identify.c (mail_identify_mime_part): Don't trust gnome-vfs when it says "text/plain" if gnome_vfs_mime_type_from_name says something different. Fixes a problem with recognizing icalendar attachments labeled "application/octet-stream". Also, don't bother asking gnome-vfs about winmail.dat attachments, since it will often claim that they're MPEGs due to some mis-magic. svn path=/trunk/; revision=12357
-rw-r--r--mail/ChangeLog9
-rw-r--r--mail/mail-identify.c49
2 files changed, 40 insertions, 18 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index a9c824f439..bbc8ba46a3 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,12 @@
+2001-08-21 Dan Winship <danw@ximian.com>
+
+ * mail-identify.c (mail_identify_mime_part): Don't trust gnome-vfs
+ when it says "text/plain" if gnome_vfs_mime_type_from_name says
+ something different. Fixes a problem with recognizing icalendar
+ attachments labeled "application/octet-stream". Also, don't bother
+ asking gnome-vfs about winmail.dat attachments, since it will
+ often claim that they're MPEGs due to some mis-magic.
+
2001-08-21 Jeffrey Stedfast <fejj@ximian.com>
* mail-session.c (mail_session_forget_password): zero-ize the
diff --git a/mail/mail-identify.c b/mail/mail-identify.c
index 891209186a..7742da0379 100644
--- a/mail/mail-identify.c
+++ b/mail/mail-identify.c
@@ -43,34 +43,47 @@ static const char *identify_by_magic (CamelDataWrapper *data, MailDisplay *md);
*
* Try to identify the MIME type of the data in @part (which presumably
* doesn't have a useful Content-Type).
+ *
+ * Return value: the MIME type, which the caller must free, or %NULL
+ * if it could not be identified.
**/
char *
mail_identify_mime_part (CamelMimePart *part, MailDisplay *md)
{
- const char *filename, *type;
+ const char *filename, *name_type = NULL, *magic_type = NULL;
CamelDataWrapper *data;
- /* If the MIME part data is online, try file magic first,
- * since it's more reliable.
- */
- data = camel_medium_get_content_object (CAMEL_MEDIUM (part));
- if (!camel_data_wrapper_is_offline (data)) {
- type = identify_by_magic (data, md);
- if (type)
- return g_strdup (type);
- }
-
- /* Try identifying based on name in Content-Type or
- * filename in Content-Disposition.
- */
filename = camel_mime_part_get_filename (part);
if (filename) {
- type = gnome_vfs_mime_type_from_name_or_default (filename,
- NULL);
- if (type)
- return g_strdup (type);
+ /* GNOME-VFS will misidentify TNEF attachments as MPEG */
+ if (!strcmp (filename, "winmail.dat"))
+ return g_strdup ("application/vnd.ms-tnef");
+
+ name_type = gnome_vfs_mime_type_from_name_or_default (filename, NULL);
}
+ data = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+ if (!camel_data_wrapper_is_offline (data))
+ magic_type = identify_by_magic (data, md);
+
+ /* 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.
+ */
+ if (magic_type && name_type && !strcmp (magic_type, "text/plain"))
+ return g_strdup (name_type);
+
+ /* If the MIME part data was online, and the magic check
+ * returned something, use that, since it's more reliable.
+ */
+ if (magic_type)
+ return g_strdup (magic_type);
+
+ /* Otherwise try guessing based on the filename */
+ if (name_type)
+ return g_strdup (name_type);
+
/* Another possibility to try is the x-mac-type / x-mac-creator
* parameter to Content-Type used by some Mac email clients. That
* would require a Mac type to mime type conversion table.