/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ *
*/
#ifdef HAVE_CONFIG_H
#include "defs.h"
+#ifdef G_OS_WIN32
+#define UNICODE
+#define _UNICODE
+#endif
+
#include <glib.h>
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
#include <sys/types.h>
#include <sys/stat.h>
-#ifndef HAVE_APACHE_FNMATCH
-/* kludge: apache's fnmatch clashes with <regex.h>, don't include
- * fnmatch.h */
-#include <fnmatch.h>
-#endif
-
#include "main.h"
#include "mimeview.h"
#include "textview.h"
#include "manage_window.h"
#include "privacy.h"
-#ifdef MAEMO
-#include <libosso.h>
-#ifndef CHINOOK
-#include <osso-mime.h>
-#else
-#include <hildon-mime.h>
-#endif
-#endif
-
typedef enum
{
COL_MIMETYPE = 0,
static GtkActionEntry mimeview_menu_actions[] = {
{ "MimeView", NULL, "MimeView" },
{ "MimeView/Open", NULL, N_("_Open"), NULL, "Open MIME part", G_CALLBACK(mimeview_launch_cb) },
-#if (!defined MAEMO && !defined G_OS_WIN32)
+#if (!defined G_OS_WIN32)
{ "MimeView/OpenWith", NULL, N_("Open _with..."), NULL, "Open MIME part with...", G_CALLBACK(mimeview_open_with_cb) },
#endif
{ "MimeView/SendTo", NULL, N_("Send to..."), NULL, "Send to", G_CALLBACK(mimeview_send_to_cb) },
MENUITEM_ADDUI_MANAGER(mimeview->ui_manager,
"/Menus/MimeView/", "Open", "MimeView/Open",
GTK_UI_MANAGER_MENUITEM);
-#if (!defined MAEMO && !defined G_OS_WIN32)
+#if (!defined G_OS_WIN32)
MENUITEM_ADDUI_MANAGER(mimeview->ui_manager,
"/Menus/MimeView/", "OpenWith", "MimeView/OpenWith",
GTK_UI_MANAGER_MENUITEM);
mimeview->icon_mainbox = icon_mainbox;
mimeview->icon_count = 0;
mimeview->mainwin = mainwin;
-#if !(GTK_CHECK_VERSION(2,12,0))
- mimeview->tooltips = tips;
-#endif
mimeview->mime_toggle = mime_toggle;
mimeview->siginfoview = siginfoview;
mimeview->scrollbutton = scrollbutton;
GSList *cur;
MimeViewerFactory *factory = NULL;
MimeViewer *viewer = NULL;
- gchar *real_contenttype = NULL;
+ gchar *real_contenttype = NULL, *tmp;
-/*
- * FNM_CASEFOLD is a GNU extension
- */
-#ifndef FNM_CASEFOLD
-#define FNM_CASEFOLD 0
real_contenttype = g_utf8_strdown((gchar *)content_type, -1);
-#else
- real_contenttype = g_strdup(content_type);
-#endif
for (cur = mimeviewer_factories; cur != NULL; cur = g_slist_next(cur)) {
MimeViewerFactory *curfactory = cur->data;
gint i = 0;
while (curfactory->content_types[i] != NULL) {
- if(!fnmatch(curfactory->content_types[i], real_contenttype, FNM_CASEFOLD)) {
+ tmp = g_utf8_strdown(curfactory->content_types[i], -1);
+ if (g_pattern_match_simple(tmp, real_contenttype)) {
debug_print("%s\n", curfactory->content_types[i]);
factory = curfactory;
+ g_free(tmp);
break;
}
+ g_free(tmp);
i++;
}
if (factory != NULL)
(gpointer) mimeview);
noticeview_set_icon(mimeview->siginfoview, icon);
noticeview_set_tooltip(mimeview->siginfoview, button_text);
+
+ icon_list_clear(mimeview);
+ icon_list_create(mimeview, mimeview->mimeinfo);
}
#ifdef USE_PTHREAD
pthread_cancel(mimeview->check_data->cancel_th);
}
- g_free(mimeview->check_data);
- mimeview->check_data = NULL;
-
if (must_free) {
debug_print("freeing deferred mimeinfo\n");
procmime_mimeinfo_free_all(mimeview->check_data->siginfo);
}
+
+ g_free(mimeview->check_data);
+ mimeview->check_data = NULL;
+
if (must_destroy) {
debug_print("freeing deferred mimeview\n");
mimeview_free_mimeinfo(mimeview);
g_free(mimeview);
mimeviews = g_slist_remove(mimeviews, mimeview);
}
-
}
/* GUI update once the checker thread is done or killed */
if (mimeinfo == NULL) {
/* message changed !? */
- g_warning("no more siginfo!\n");
+ g_warning("no more siginfo!");
goto end;
}
if (!mimeview->check_data) {
- g_warning("nothing to check\n");
+ g_warning("nothing to check");
return FALSE;
}
if (mimeview->check_data->siginfo != mimeinfo) {
/* message changed !? */
- g_warning("different siginfo!\n");
+ g_warning("different siginfo!");
goto end;
}
else
update_signature_noticeview(mimeview, mimeview->siginfo,
FALSE, 0);
- icon_list_clear(mimeview);
- icon_list_create(mimeview, mimeview->mimeinfo);
-
+
end:
mimeview_check_data_reset(mimeview);
return FALSE;
} else {
/* that's strange! we changed message without
* getting killed. */
- g_warning("different siginfo!\n");
+ g_warning("different siginfo!");
mimeview_check_data_reset(mimeview);
return NULL;
}
debug_print("checking without thread\n");
privacy_mimeinfo_check_signature(mimeinfo);
update_signature_noticeview(mimeview, mimeview->siginfo, FALSE, 0);
- icon_list_clear(mimeview);
- icon_list_create(mimeview, mimeview->mimeinfo);
}
}
break;
}
}
+
+ if (mimeview->siginfo && privacy_auto_check_signatures(mimeview->siginfo)
+ && privacy_mimeinfo_get_sig_status(mimeview->siginfo) == SIGNATURE_UNCHECKED) {
+ mimeview_check_signature(mimeview);
+ }
}
static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
MimeInfo *partinfo = NULL;
gboolean has_next;
+ if (!mimeview->opened) return;
+
gtk_tree_model_get_iter(model, &iter, mimeview->opened);
path = gtk_tree_model_get_path(model, &iter);
skip:
MimeInfo *partinfo = NULL;
gboolean has_prev;
+ if (!mimeview->opened) return;
+
gtk_tree_model_get_iter(model, &iter, mimeview->opened);
path = gtk_tree_model_get_path(model, &iter);
skip:
FILE *fp;
fp = g_fopen(partinfo->data.filename, "rb");
- fseek(fp, partinfo->offset, SEEK_SET);
- headers = procheader_get_header_array_asis(fp);
- if (headers) {
- gint i;
- for (i = 0; i < headers->len; i++) {
- Header *header = g_ptr_array_index(headers, i);
- if (procheader_headername_equal(header->name, "Subject")) {
- unfold_line(header->body);
- name = g_strconcat(header->body, ".txt", NULL);
- subst_for_filename(name);
+ if (fp != NULL && fseek(fp, partinfo->offset, SEEK_SET) == 0) {
+ headers = procheader_get_header_array_asis(fp);
+ if (headers) {
+ gint i;
+ for (i = 0; i < headers->len; i++) {
+ Header *header = g_ptr_array_index(headers, i);
+ if (procheader_headername_equal(header->name, "Subject")) {
+ unfold_line(header->body);
+ name = g_strconcat(header->body, ".txt", NULL);
+ subst_for_filename(name);
+ }
}
+ procheader_header_array_destroy(headers);
}
- procheader_header_array_destroy(headers);
}
- fclose(fp);
+ if (fp != NULL)
+ fclose(fp);
if (name)
filename = g_path_get_basename(name);
g_free(name);
if ((err = procmime_get_part(filename, partinfo)) < 0)
alertpanel_error
(_("Couldn't save the part of multipart message: %s"),
- strerror(-err));
+ g_strerror(-err));
tmp = g_filename_to_uri(filename, NULL, NULL);
uriname = g_strconcat(tmp, "\r\n", NULL);
if ((err = procmime_get_part(filename, partinfo)) < 0) {
alertpanel_error
(_("Couldn't save the part of multipart message: %s"),
- strerror(-err));
+ g_strerror(-err));
return FALSE;
}
if ((err = procmime_get_part(filename, partinfo)) < 0)
alertpanel_error
(_("Couldn't save the part of multipart message: %s"),
- strerror(-err));
+ g_strerror(-err));
else
mimeview_view_file(filename, partinfo, NULL, mimeview);
mimeview_open_part_with(mimeview, partinfo, FALSE);
}
-#ifdef MAEMO
-osso_context_t *get_osso_context(void);
-#endif
static void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo, gboolean automatic)
{
gchar *filename;
gchar *mime_command = NULL;
gchar *content_type = NULL;
gint err;
-#ifdef MAEMO
- DBusConnection *dbusconn;
- gchar *uri;
- int r = 0;
-#endif
+
cm_return_if_fail(partinfo != NULL);
filename = procmime_get_tmp_file_name(partinfo);
if ((err = procmime_get_part(filename, partinfo)) < 0) {
alertpanel_error
(_("Couldn't save the part of multipart message: %s"),
- strerror(-err));
+ g_strerror(-err));
g_free(filename);
return;
}
partinfo->subtype);
}
-#ifdef MAEMO
- if (content_type != NULL) {
- uri = g_filename_to_uri(filename, NULL, NULL);
- dbusconn = osso_get_dbus_connection (get_osso_context());
-#ifdef CHINOOK
- r = hildon_mime_open_file_with_mime_type (dbusconn, uri, content_type);
-#else
- r = osso_mime_open_file_with_mime_type (dbusconn, uri, content_type);
-#endif
- g_free(uri);
- }
- if (r != 1) {
- alertpanel_error(_("No registered viewer for this file type."));
- }
- goto out;
-#endif
-
if ((partinfo->type == MIMETYPE_TEXT && !strcmp(partinfo->subtype, "html"))
&& prefs_common_get_uri_cmd() && prefs_common.uri_cmd[0]) {
mime_command = g_strdup(prefs_common_get_uri_cmd());
prefs_common.mime_open_cmd_history =
add_history(prefs_common.mime_open_cmd_history, cmd);
}
-#ifdef MAEMO
-out:
-#endif
+
g_free(content_type);
g_free(filename);
}
} else
alertpanel_error
(_("Couldn't save the part of multipart message: %s"),
- strerror(-err));
+ g_strerror(-err));
g_free(filename);
}
#ifndef G_OS_WIN32
gchar *p;
gchar buf[BUFFSIZE];
+
if (cmd == NULL)
mimeview_open_part_with(mimeview, partinfo, TRUE);
else {
}
#else
SHFILEINFO file_info;
- if ((SHGetFileInfo(filename, 0, &file_info, sizeof(SHFILEINFO), SHGFI_EXETYPE)) != 0) {
+ GError *error = NULL;
+ gunichar2 *fn16 = g_utf8_to_utf16(filename, -1, NULL, NULL, &error);
+
+ if (error != NULL) {
+ alertpanel_error(_("Could not convert attachment name to UTF-16:\n\n%s"),
+ error->message);
+ debug_print("filename '%s' conversion to UTF-16 failed\n", filename);
+ g_error_free(error);
+ return;
+ }
+
+ if ((SHGetFileInfo((LPCWSTR)fn16, 0, &file_info, sizeof(SHFILEINFO), SHGFI_EXETYPE)) != 0) {
AlertValue val = alertpanel_full(_("Execute untrusted binary?"),
_("This attachment is an executable file. Executing "
"untrusted binaries is dangerous and could probably "
NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
if (val == G_ALERTALTERNATE) {
debug_print("executing binary\n");
- ShellExecute(NULL, "open", filename, NULL, NULL, SW_SHOW);
+ ShellExecute(NULL, L"open", (LPCWSTR)fn16, NULL, NULL, SW_SHOW);
}
- } else
- ShellExecute(NULL, "open", filename, NULL, NULL, SW_SHOW);
+ } else {
+ ShellExecute(NULL, L"open", (LPCWSTR)fn16, NULL, NULL, SW_SHOW);
+ }
+
+ g_free(fn16);
#endif
}
#ifdef GENERIC_UMPC
GtkRequisition r;
#endif
-#if !(GTK_CHECK_VERSION(2,12,0))
- GtkTooltips *tips = mimeview->tooltips;
-#endif
if (!prefs_common.show_inline_attachments && mimeinfo->id)
return;
to_human_readable((goffset)mimeinfo->length), NULL);
g_free(content_type);
if (desc && *desc) {
- gchar *tmp = NULL;
+ gchar *tmp = NULL, *escaped = NULL;
if (!g_utf8_validate(desc, -1, NULL)) {
tmp = conv_filename_to_utf8(desc);
} else {
tmp = g_strdup(desc);
}
+ escaped = g_markup_escape_text(tmp,-1);
+
tiptmp = g_strconcat(tip, "\n<b>",
prefs_common.attach_desc && mimeinfo->description ?
_("Description:") : _("Filename:"),
- " </b>", g_markup_escape_text(tmp,-1), NULL);
+ " </b>", escaped, NULL);
g_free(tip);
tip = tiptmp;
g_free(tmp);
+ g_free(escaped);
}
if (sigshort && *sigshort) {
tiptmp = g_strjoin("\n", tip, g_markup_escape_text(sigshort, -1), NULL);
gtk_widget_show_all(button);
gtk_drag_source_set(button, GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
mimeview_mime_types, 1, GDK_ACTION_COPY);
-#ifndef MAEMO
+
g_signal_connect(G_OBJECT(button), "popup-menu",
G_CALLBACK(icon_popup_menu), mimeview);
-#else
- gtk_widget_tap_and_hold_setup(GTK_WIDGET(button), NULL, NULL,
- GTK_TAP_AND_HOLD_NONE | GTK_TAP_AND_HOLD_NO_INTERNALS);
- g_signal_connect(G_OBJECT(button), "tap-and-hold",
- G_CALLBACK(icon_popup_menu), mimeview);
-#endif
g_signal_connect(G_OBJECT(button), "button_release_event",
G_CALLBACK(icon_clicked_cb), mimeview);
g_signal_connect(G_OBJECT(button), "key_press_event",
gtk_widget_set_size_request(mimeview->icon_mainbox,
size.width, -1);
}
+ if (mimeview->opened)
+ icon_list_toggle_by_mime_info(mimeview,
+ mimeview_get_node_part(mimeview, mimeview->opened));
}
static void icon_list_toggle_by_mime_info (MimeView *mimeview,
MimeInfo *mimeinfo)
{
- GList *child;
+ GList *children, *child;
- child = gtk_container_get_children(GTK_CONTAINER(mimeview->icon_vbox));
- for (; child != NULL; child = g_list_next(child)) {
+ children = gtk_container_get_children(GTK_CONTAINER(mimeview->icon_vbox));
+ for (child = children; child != NULL; child = g_list_next(child)) {
+ gboolean *highlight = NULL;
+ GtkWidget *icon = gtk_bin_get_child(GTK_BIN(child->data));
+
if (!GTK_IS_EVENT_BOX(child->data))
continue;
- if(g_object_get_data(G_OBJECT(child->data),
- "partinfo") == (gpointer)mimeinfo) {
- gboolean *highlight = NULL;
- GtkWidget *icon = gtk_bin_get_child(GTK_BIN(child->data));
- highlight = g_object_get_data(G_OBJECT(icon), "highlight");
- *highlight = TRUE;
- gtk_widget_queue_draw(icon);
- } else {
- gint *highlight = NULL;
- GtkWidget *icon = gtk_bin_get_child(GTK_BIN(child->data));
- highlight = g_object_get_data(G_OBJECT(icon), "highlight");
- *highlight = FALSE;
- gtk_widget_queue_draw(icon);
- }
+
+ highlight = g_object_get_data(G_OBJECT(icon), "highlight");
+ *highlight = (g_object_get_data(G_OBJECT(child->data),
+ "partinfo") == (gpointer)mimeinfo);
+
+ gtk_widget_queue_draw(icon);
}
+ g_list_free(children);
}
static void ctree_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation,
return TRUE;
}
-void mimeview_update (MimeView *mimeview) {
+void mimeview_update (MimeView *mimeview)
+{
if (mimeview && mimeview->mimeinfo) {
icon_list_clear(mimeview);
icon_list_create(mimeview, mimeview->mimeinfo);