aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calendar/ChangeLog8
-rw-r--r--calendar/gui/dialogs/comp-editor.c2
-rw-r--r--calendar/gui/e-cal-popup.c2
-rw-r--r--composer/ChangeLog8
-rw-r--r--composer/e-msg-composer.c4
-rw-r--r--e-util/ChangeLog10
-rw-r--r--e-util/e-util.c50
-rw-r--r--e-util/e-util.h2
-rw-r--r--mail/ChangeLog8
-rw-r--r--mail/em-popup.c2
-rw-r--r--mail/em-utils.c2
-rw-r--r--widgets/misc/ChangeLog7
-rw-r--r--widgets/misc/e-attachment.c3
13 files changed, 81 insertions, 27 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 8a53aa81e7..04bfe0d70a 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,5 +1,13 @@
2008-10-01 Milan Crha <mcrha@redhat.com>
+ ** Part of fix for bug #554418
+
+ * gui/dialogs/comp-editor.c: (set_attachment_list):
+ * gui/e-cal-popup.c: (ecalp_standard_menu_factory):
+ Allow/disallow guessing of the mime_type based on the file content.
+
+2008-10-01 Milan Crha <mcrha@redhat.com>
+
** Fix for bug #554458
* gui/e-cal-popup.c: (ecalp_standard_menu_factory):
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c
index f4ecb85f24..0f3a62cfe8 100644
--- a/calendar/gui/dialogs/comp-editor.c
+++ b/calendar/gui/dialogs/comp-editor.c
@@ -2843,7 +2843,7 @@ set_attachment_list (CompEditor *editor, GSList *attach_list)
return;
}
- mime_type = e_util_guess_mime_type (file_name);
+ mime_type = e_util_guess_mime_type (file_name, TRUE);
if (mime_type) {
if (!g_ascii_strcasecmp (mime_type, "message/rfc822")) {
wrapper = (CamelDataWrapper *) camel_mime_message_new ();
diff --git a/calendar/gui/e-cal-popup.c b/calendar/gui/e-cal-popup.c
index bec0e9c94d..c18464d8ce 100644
--- a/calendar/gui/e-cal-popup.c
+++ b/calendar/gui/e-cal-popup.c
@@ -405,7 +405,7 @@ ecalp_standard_menu_factory (EPopup *ecalp, void *data)
if (filename) {
gchar *name_type;
- name_type = e_util_guess_mime_type (filename);
+ name_type = e_util_guess_mime_type (filename, FALSE);
cp = g_content_type_from_mime_type (name_type);
apps = g_app_info_get_all_for_type (cp ? cp : name_type);
g_free (cp);
diff --git a/composer/ChangeLog b/composer/ChangeLog
index ee0dfa5eee..0e5a3dd328 100644
--- a/composer/ChangeLog
+++ b/composer/ChangeLog
@@ -1,3 +1,11 @@
+2008-10-01 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #554418
+
+ * e-msg-composer.c: (handle_uri),
+ (e_msg_composer_add_inline_image_from_file): Guess mime_type based
+ on the file content, if failed, then on the filename.
+
2008-09-29 Sankar P <psankar@novell.com>
License Changes
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 5f75b79fc4..6c3fada7f3 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -3968,7 +3968,7 @@ handle_uri (EMsgComposer *composer,
return;
if (!g_ascii_strcasecmp (url->protocol, "file")) {
- type = e_util_guess_mime_type (uri + strlen ("file://"));
+ type = e_util_guess_mime_type (uri + strlen ("file://"), TRUE);
if (!type)
return;
@@ -4200,7 +4200,7 @@ e_msg_composer_add_inline_image_from_file (EMsgComposer *composer,
camel_data_wrapper_construct_from_stream (wrapper, stream);
camel_object_unref (CAMEL_OBJECT (stream));
- mime_type = e_util_guess_mime_type (dec_file_name);
+ mime_type = e_util_guess_mime_type (dec_file_name, TRUE);
if (mime_type == NULL)
mime_type = g_strdup ("application/octet-stream");
camel_data_wrapper_set_mime_type (wrapper, mime_type);
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index e85172b9ea..4c2e1d14d6 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,13 @@
+2008-10-01 Milan Crha <mcrha@redhat.com>
+
+ ** Fix for bug #554418
+
+ * e-util.h: (e_util_guess_mime_type):
+ * e-util.c: (e_util_guess_mime_type): Guess mime_type based on
+ the file content only when permitted by the caller, otherwise
+ check based on the filename only, where it fallbacks if file
+ content guess fails.
+
2008-09-29 Sankar P <psankar@novell.com>
License Changes
diff --git a/e-util/e-util.c b/e-util/e-util.c
index 21f448b15b..97cd6265a6 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -1172,37 +1172,51 @@ e_file_lock_exists ()
/**
* e_util_guess_mime_type:
* @filename: it's a local file name, or URI.
+ * @localfile: set to TRUE if can check the local file content, FALSE to check only based on the filename itself.
* Returns: NULL or newly allocated string with a mime_type of the given file. Free with g_free.
*
- * Guesses mime_type for the given file_name.
+ * Guesses mime_type for the given filename.
**/
char *
-e_util_guess_mime_type (const char *filename)
+e_util_guess_mime_type (const char *filename, gboolean localfile)
{
- GFile *file;
- GFileInfo *fi;
- char *mime_type;
+ char *mime_type = NULL;
g_return_val_if_fail (filename != NULL, NULL);
- if (strstr (filename, "://"))
- file = g_file_new_for_uri (filename);
- else
- file = g_file_new_for_path (filename);
+ if (localfile) {
+ GFile *file;
- if (!file)
- return NULL;
+ if (strstr (filename, "://"))
+ file = g_file_new_for_uri (filename);
+ else
+ file = g_file_new_for_path (filename);
- fi = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
- if (!fi) {
- g_object_unref (file);
- return NULL;
+ if (file) {
+ GFileInfo *fi;
+
+ fi = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ if (fi) {
+ mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (fi));
+
+ g_object_unref (fi);
+ }
+
+ g_object_unref (file);
+ }
}
- mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (fi));
+ if (!mime_type) {
+ /* file doesn't exists locally, thus guess based on the filename */
+ gboolean uncertain = FALSE;
+ gchar *content_type;
- g_object_unref (fi);
- g_object_unref (file);
+ content_type = g_content_type_guess (filename, NULL, 0, &uncertain);
+ if (content_type) {
+ mime_type = g_content_type_get_mime_type (content_type);
+ g_free (content_type);
+ }
+ }
return mime_type;
}
diff --git a/e-util/e-util.h b/e-util/e-util.h
index bb6f2ba5fc..78ec9e53c9 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -116,7 +116,7 @@ gboolean e_file_lock_create (void);
void e_file_lock_destroy (void);
gboolean e_file_lock_exists (void);
-gchar * e_util_guess_mime_type (const gchar *filename);
+gchar * e_util_guess_mime_type (const gchar *filename, gboolean localfile);
gchar * e_util_filename_to_uri (const gchar *filename);
gchar * e_util_uri_to_filename (const gchar *uri);
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 7ecbee7885..d8d68f1a4a 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,5 +1,13 @@
2008-10-01 Milan Crha <mcrha@redhat.com>
+ ** Part of fix for bug #554418
+
+ * em-utils.c: (em_utils_snoop_type):
+ * em-popup.c: (emp_standard_menu_factory):
+ Guess mime_type based on the filename only.
+
+2008-10-01 Milan Crha <mcrha@redhat.com>
+
** Fix for bug #554458
* em-popup.c: (emp_standard_menu_factory):
diff --git a/mail/em-popup.c b/mail/em-popup.c
index b05e7753c3..dfd09d2ad0 100644
--- a/mail/em-popup.c
+++ b/mail/em-popup.c
@@ -807,7 +807,7 @@ emp_standard_menu_factory(EPopup *emp, void *data)
if (filename != NULL) {
gchar *name_type;
- name_type = e_util_guess_mime_type (filename);
+ name_type = e_util_guess_mime_type (filename, FALSE);
cp = g_content_type_from_mime_type (name_type);
apps = g_app_info_get_all_for_type (cp ? cp : name_type);
g_free (cp);
diff --git a/mail/em-utils.c b/mail/em-utils.c
index f7555afbef..01b18eb461 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -2260,7 +2260,7 @@ em_utils_snoop_type(CamelMimePart *part)
filename = camel_mime_part_get_filename (part);
if (filename != NULL)
- name_type = e_util_guess_mime_type (filename);
+ name_type = e_util_guess_mime_type (filename, FALSE);
dw = camel_medium_get_content_object((CamelMedium *)part);
if (!camel_data_wrapper_is_offline(dw)) {
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog
index e2dc720101..57e1d25b7a 100644
--- a/widgets/misc/ChangeLog
+++ b/widgets/misc/ChangeLog
@@ -1,3 +1,10 @@
+2008-10-01 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #554418
+
+ * e-attachment.c: (attachment_guess_mime_type):
+ Allow guessing mime_type based on the file content.
+
2008-10-01 Sankar P <psankar@novell.com>
License Changes
diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c
index 073110571a..4f5e9ace34 100644
--- a/widgets/misc/e-attachment.c
+++ b/widgets/misc/e-attachment.c
@@ -229,8 +229,7 @@ attachment_guess_mime_type (const char *file_name)
char *type;
gchar *content = NULL;
- type = e_util_guess_mime_type (file_name);
-
+ type = e_util_guess_mime_type (file_name, TRUE);
if (type && strcmp (type, "text/directory") == 0 &&
file_ext_is (file_name, ".vcf") &&