aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/ChangeLog8
-rw-r--r--widgets/misc/e-attachment.c51
2 files changed, 58 insertions, 1 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog
index 4bc064f4f8..2899ec0fa4 100644
--- a/widgets/misc/ChangeLog
+++ b/widgets/misc/ChangeLog
@@ -1,3 +1,11 @@
+2007-10-01 Milan Crha <mcrha@redhat.com>
+
+ ** Fix for bug #413420
+
+ * e-attachment.c: (file_ext_is): New helper function.
+ * e-attachment.c: (attachment_guess_mime_type): Change mimetype
+ if knows the extension and if the content of file is valid.
+
2007-09-26 Milan Crha <mcrha@redhat.com>
** Fix for bug #423401
diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c
index 14dad294f9..d9ec749ebc 100644
--- a/widgets/misc/e-attachment.c
+++ b/widgets/misc/e-attachment.c
@@ -54,6 +54,8 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
+#include <libebook/e-vcard.h>
+
#include "e-util/e-error.h"
#include "e-util/e-mktemp.h"
#include "e-util/e-util-private.h"
@@ -194,6 +196,33 @@ e_attachment_get_type (void)
return type;
}
+/**
+ * file_ext_is:
+ * @param file_name: path for file
+ * @param ext: desired extension, with a dot
+ * @return if file_name has extension ext or not
+ **/
+
+static gboolean
+file_ext_is (const char *file_name, const char *ext)
+{
+ int i, dot = -1;
+
+ if (!file_name || !ext)
+ return FALSE;
+
+ for (i = 0; file_name[i]; i++) {
+ if (file_name [i] == '.')
+ dot = i;
+ }
+
+ if (dot > 0) {
+ return 0 == g_ascii_strcasecmp (file_name + dot, ext);
+ }
+
+ return FALSE;
+}
+
static char *
attachment_guess_mime_type (const char *file_name)
{
@@ -206,9 +235,29 @@ attachment_guess_mime_type (const char *file_name)
GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE |
GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
- if (result == GNOME_VFS_OK)
+ if (result == GNOME_VFS_OK) {
+ gchar *content = NULL;
+
type = g_strdup (gnome_vfs_file_info_get_mime_type (info));
+ if (type && strcmp (type, "text/directory") == 0 &&
+ file_ext_is (file_name, ".vcf") &&
+ g_file_get_contents (file_name, &content, NULL, NULL) &&
+ content) {
+ EVCard *vc = e_vcard_new_from_string (content);
+
+ if (vc) {
+ g_free (type);
+ g_object_unref (G_OBJECT (vc));
+
+ type = g_strdup ("text/x-vcard");
+ }
+
+ }
+
+ g_free (content);
+ }
+
gnome_vfs_file_info_unref (info);
return type;