Skip to content

Commit

Permalink
Introduce e_win32_get_mime_type(). Fix Makefile.am glade linkage.
Browse files Browse the repository at this point in the history
Please DELETE ALL EV2W EVOLUTION CACHE FILES BEFORE APPLYING THIS PATCH

usage: gchar * e_win32_get_mime_type (GFile *file, gchar *buf)
Returns NULL on failure; consumes buf pointer, file pointer REMAINS
Implemenations fall back to g_content_type_get_mime_type if failed.
  • Loading branch information
asctime committed May 29, 2023
1 parent aae8b42 commit b13cb23
Show file tree
Hide file tree
Showing 171 changed files with 1,324 additions and 481 deletions.
8 changes: 4 additions & 4 deletions evolution-2.32.3/addressbook/gui/widgets/e-minicard-label.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <misc/e-canvas-utils.h>
#include <gdk/gdkkeysyms.h>

static void e_minicard_label_init (EMinicardLabel *card);
static void e_minicard_label_class_init (EMinicardLabelClass *klass);
static void e_minicard_label_init (EMinicardLabel *card, gpointer class_data);
static void e_minicard_label_class_init (EMinicardLabelClass *klassi, gpointer class_data);
static void e_minicard_label_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void e_minicard_label_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static gboolean e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event);
Expand Down Expand Up @@ -94,7 +94,7 @@ e_minicard_label_get_type (void)
}

static void
e_minicard_label_class_init (EMinicardLabelClass *klass)
e_minicard_label_class_init (EMinicardLabelClass *klass, gpointer class_data)
{
GObjectClass *object_class;
GnomeCanvasItemClass *item_class;
Expand Down Expand Up @@ -183,7 +183,7 @@ e_minicard_label_class_init (EMinicardLabelClass *klass)
}

static void
e_minicard_label_init (EMinicardLabel *minicard_label)
e_minicard_label_init (EMinicardLabel *minicard_label, gpointer class_data)
{
minicard_label->width = 10;
minicard_label->height = 10;
Expand Down
3 changes: 1 addition & 2 deletions evolution-2.32.3/calendar/gui/gnome-cal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2371,8 +2371,7 @@ gnome_calendar_purge (GnomeCalendar *gcal, time_t older_than)
}
}

g_list_foreach (objects, (GFunc) icalcomponent_free, NULL);
g_list_free (objects);
g_list_free_full (objects, (GDestroyNotify) icalcomponent_free);
}

g_list_free (clients);
Expand Down
4 changes: 3 additions & 1 deletion evolution-2.32.3/e-util/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ruledir = $(privdatadir)

if OS_WIN32
PLATFORM_SOURCES = e-win32-reloc.c e-win32-defaults.c e-win32-defaults.h
URLMON = -lurlmon
endif

privsolib_LTLIBRARIES = libeutil.la
Expand Down Expand Up @@ -147,7 +148,8 @@ libeutil_la_LIBADD = \
$(ICONV_LIBS) \
$(E_UTIL_LIBS) \
$(GNOME_PLATFORM_LIBS) \
$(INTLLIBS)
$(INTLLIBS) \
$(URLMON)

error_DATA = e-system.error
errordir = $(privdatadir)/errors
Expand Down
7 changes: 5 additions & 2 deletions evolution-2.32.3/e-util/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ am__installdirs = "$(DESTDIR)$(privsolibdir)" "$(DESTDIR)$(errordir)" \
LTLIBRARIES = $(privsolib_LTLIBRARIES)
am__DEPENDENCIES_1 =
libeutil_la_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1)
am__libeutil_la_SOURCES_DIST = e-account-utils.h e-activity.h \
e-alert.h e-alert-activity.h e-alert-dialog.h e-binding.h \
e-bit-array.h e-categories-config.h e-charset.h e-config.h \
Expand Down Expand Up @@ -511,6 +512,7 @@ eutilincludedir = $(privincludedir)/e-util
ecpsdir = $(privdatadir)/ecps
ruledir = $(privdatadir)
@OS_WIN32_TRUE@PLATFORM_SOURCES = e-win32-reloc.c e-win32-defaults.c e-win32-defaults.h
@OS_WIN32_TRUE@URLMON = -lurlmon
privsolib_LTLIBRARIES = libeutil.la
eutilinclude_HEADERS = \
e-account-utils.h \
Expand Down Expand Up @@ -648,7 +650,8 @@ libeutil_la_LIBADD = \
$(ICONV_LIBS) \
$(E_UTIL_LIBS) \
$(GNOME_PLATFORM_LIBS) \
$(INTLLIBS)
$(INTLLIBS) \
$(URLMON)

error_DATA = e-system.error
errordir = $(privdatadir)/errors
Expand Down
2 changes: 1 addition & 1 deletion evolution-2.32.3/e-util/e-icon-factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ e_icon_factory_pixbuf_scale (GdkPixbuf *pixbuf, gint width, gint height)
gchar *
e_icon_factory_create_thumbnail (const gchar *filename)
{
#ifdef HAVE_GNOME_DESKTOP
#if defined (HAVE_GNOME_DESKTOP) && !defined(G_OS_WIN32)
static GnomeDesktopThumbnailFactory *thumbnail_factory = NULL;
struct stat file_stat;
gchar *thumbnail = NULL;
Expand Down
108 changes: 104 additions & 4 deletions evolution-2.32.3/e-util/e-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@
#include <glib/gstdio.h>

#ifdef G_OS_WIN32
#include <windows.h>
#define WIN32_LEAN_AND_MEAN
#if defined(__MINGW32__) && !defined(_WIN32_IE) /* for urlmon api */
#define _WIN32_IE 0x0800
#endif
#include <glib.h>
#include <Windows.h>
#include <Urlmon.h>
#endif

#include <camel/camel.h>
Expand Down Expand Up @@ -671,6 +677,7 @@ e_format_number (gint number)
default:
last_count = *grouping;
grouping++;
/* coverity[fallthrough] */
case 0:
divider = epow10 (last_count);
if (number >= divider) {
Expand Down Expand Up @@ -1374,13 +1381,16 @@ e_util_guess_mime_type (const gchar *filename, gboolean localfile)

if (localfile) {
GFile *file;
GFileInfo *fi;

if (strstr (filename, "://"))
file = g_file_new_for_uri (filename);
else
file = g_file_new_for_path (filename);

#ifdef G_OS_WIN32
mime_type = g_strdup(e_win32_get_mime_type(file, NULL));
#else
GFileInfo *fi;
fi = g_file_query_info (
file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE, NULL, NULL);
Expand All @@ -1389,8 +1399,8 @@ e_util_guess_mime_type (const gchar *filename, gboolean localfile)
g_file_info_get_content_type (fi));
g_object_unref (fi);
}

g_object_unref (file);
#endif
g_object_unref (file);
}

if (!mime_type) {
Expand Down Expand Up @@ -1487,3 +1497,93 @@ e_util_set_source_combo_box_list (GtkWidget *source_combo_box,
g_object_unref (gconf_client);
}

#if defined (G_OS_WIN32_API_METHOD) || defined(G_OS_WIN32)
gchar * e_win32_get_mime_type (GFile *file, gchar *buf)
{
LPWSTR wmime_type, win_path = NULL;
gchar *mime_type = NULL;

/* if both file and buff are specified just use file */
if (file != NULL) {
win_path = g_utf8_to_utf16 (g_file_get_path (file),
-1, NULL, NULL, NULL);
} else if (buf == NULL) {
mime_type = NULL;
goto exit;
}

const HRESULT result = FindMimeFromData(NULL, win_path, buf, 120, NULL,
FMFD_ENABLEMIMESNIFFING | FMFD_IGNOREMIMETEXTPLAIN, &wmime_type, 0);

if (result == S_OK) {
mime_type = g_utf16_to_utf8 (wmime_type, -1, NULL, NULL, NULL);
} else {
g_debug ("WIN32 FindMimeFromData failed. Returning NULL");
mime_type = NULL;
}

exit:
if (buf)
g_free(buf);
/* g_object_unref (file); */ /* Some calling fuunctions still need */
/* So we free buf here but not file */
return mime_type;
}

#elif defined (G_OS_WIN32_EXTERNAL_METHOD) || defined(G_OS_WIN32)
typedef HRESULT (WINAPI *FindMimeFromData_t) (LPBC pBC,
LPCWSTR pwzUrl,
LPVOID pBuffer,
DWORD cbSize,
LPCWSTR pwzMimeProposed,
DWORD dwMimeFlags,
LPWSTR *ppwzMimeOut,
DWORD dwReserved);

static FindMimeFromData_t
find_mime_from_data (void)
{
HMODULE urlmon;
static FindMimeFromData_t result = NULL;
static gboolean beenhere = FALSE;

if (!beenhere) {
urlmon = LoadLibrary ("urlmon.dll");
if (urlmon != NULL)
result = (FindMimeFromData_t) GetProcAddress (urlmon, "FindMimeFromData");
beenhere = TRUE;
}

return result;
}

gchar * e_win32_get_mime_type (GFile *file, gchar *buf)
{
LPWSTR win_path, wmime_type;
gchar *mime_type = NULL;

/* if both file and buff are specified just use file */
if (file != NULL) {
win_path = g_utf8_to_utf16 (g_file_get_path (file),
-1, NULL, NULL, NULL);
} else if (buf == NULL) {
mime_type = NULL;
goto exit;
}

if ((find_mime_from_data ()) (NULL, win_path, buf, 0,
NULL, FMFD_ENABLEMIMESNIFFING, &wmime_type, 0) == NOERROR) {
mime_type = g_utf16_to_utf8 (wmime_type, -1, NULL, NULL, NULL);
} else {
g_debug ("WIN32 FindMimeFromData failed. Returning NULL");
mime_type = NULL;
}

exit:
if (buf)
g_free(buf);
/* g_object_unref (file); */ /* Some calling fuunctions still need */
/* So we free buf here but not file */
return mime_type;
}
#endif
5 changes: 5 additions & 0 deletions evolution-2.32.3/e-util/e-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ GList * e_util_get_searchable_categories(void);
void e_util_set_source_combo_box_list
(GtkWidget *source_combo_box,
const gchar *source_gconf_path);
#ifdef G_OS_WIN32
gchar * e_win32_get_mime_type (GFile *file, gchar *buf);
#endif



G_END_DECLS

Expand Down
44 changes: 33 additions & 11 deletions evolution-2.32.3/em-format/em-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -2248,8 +2248,8 @@ em_format_snoop_type (CamelMimePart *part)

filename = camel_mime_part_get_filename (part);
if (filename != NULL)
name_type = e_util_guess_mime_type (filename, FALSE);

name_type = e_util_guess_mime_type (filename, FALSE);
dw = camel_medium_get_content ((CamelMedium *)part);
if (!camel_data_wrapper_is_offline (dw)) {
GByteArray *byte_array;
Expand All @@ -2259,22 +2259,44 @@ em_format_snoop_type (CamelMimePart *part)
stream = camel_stream_mem_new_with_byte_array (byte_array);

if (camel_data_wrapper_decode_to_stream (dw, stream, NULL) > 0) {
gchar *content_type;

content_type = g_content_type_guess (
filename, byte_array->data,
byte_array->len, NULL);
#ifdef G_OS_WIN32
/* Commented code just for demo. Use existing byte_array! */
/* GByteArray *m_ba =
camel_stream_mem_get_byte_array((CamelStreamMem *)stream);
...
g_byte_array_free (m_ba, TRUE); */

gchar *m_ptr = g_strdup((gchar*)byte_array->data);
m_ptr[strlen(m_ptr)] = '\0';
magic_type = g_strdup(e_win32_get_mime_type (NULL, m_ptr));
/* g_free (m_ptr); */ /* Safer to free in e_win32_get_mime_type */
if (magic_type == NULL) {
g_debug ("Win32 message part \"%s\" scan failed. \
Falling back to glib.", name_type);
#endif
const gchar *content_type = g_content_type_guess (
filename, byte_array->data, byte_array->len, NULL);

if (content_type != NULL)
magic_type = g_content_type_get_mime_type (content_type);
if (content_type != NULL)
magic_type = g_content_type_get_mime_type (content_type);

g_free (content_type);
#ifdef G_OS_WIN32
}
#endif
}

g_object_unref (stream);
/* CamelStream is a CamelObject with GObject parent class.
GObjects normally are automatically removed when they are no
longer in use (external references are zero). New tnef plugin
takes ownership of stream and unrefs it but nobody told us */

/* camel_stream_mem_set_byte_array ((CamelStreamMem *) stream, NULL); */
/* g_object_ref_sink (stream); */ /* FIXME tnef ownership hack */
g_object_unref (stream); /* Avoid reference # mismatch */
}

d(printf("snooped part, magic_type '%s' name_type '%s'\n", magic_type, name_type));
g_debug("snooped part, magic_type '%s' name_type '%s'\n", magic_type, name_type);

/* If gvfs doesn't recognize the data by magic, but it
* contains English words, it will call it text/plain. If the
Expand Down
Loading

0 comments on commit b13cb23

Please sign in to comment.