*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "defs.h"
#include <glib.h>
+#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtknotebook.h>
#include <gtk/gtkscrolledwindow.h>
#include <fnmatch.h>
#endif
-#include "intl.h"
#include "main.h"
#include "mimeview.h"
#include "textview.h"
#include "utils.h"
#include "gtkutils.h"
#include "prefs_common.h"
-#include "rfc2015.h"
#include "stock_pixmap.h"
#include "gtk/gtkvscrollbutton.h"
static void mimeview_open_with (MimeView *mimeview);
static void mimeview_view_file (const gchar *filename,
MimeInfo *partinfo,
- const gchar *cmdline);
+ const gchar *cmdline,
+ MimeView *mimeview);
static gboolean icon_clicked_cb (GtkWidget *button,
GdkEventButton *event,
MimeView *mimeview);
gtk_widget_show(vbox);
siginfoview = noticeview_create(mainwin);
noticeview_hide(siginfoview);
+ noticeview_set_icon_clickable(siginfoview, TRUE);
gtk_box_pack_start(GTK_BOX(vbox), mime_notebook, TRUE, TRUE, 0);
gtk_box_pack_end(GTK_BOX(vbox), GTK_WIDGET_PTR(siginfoview), FALSE, FALSE, 0);
gchar *str[N_MIMEVIEW_COLS];
if (partinfo->type != MIMETYPE_UNKNOWN && partinfo->subtype) {
- g_snprintf(content_type, 64, "%s/%s", procmime_get_type_str(partinfo->type), partinfo->subtype);
+ g_snprintf(content_type, 64, "%s/%s", procmime_get_media_type_str(partinfo->type), partinfo->subtype);
} else {
g_snprintf(content_type, 64, "UNKNOWN");
}
else
str[COL_NAME] = (gchar *) get_part_name(partinfo);
- node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
+ node = gtk_sctree_insert_node(ctree, parent, NULL, str, 0,
NULL, NULL, NULL, NULL,
FALSE, TRUE);
gtk_ctree_node_set_row_data(ctree, node, partinfo);
fname = mimeview->file;
if (!fname) return;
- if ((fp = fopen(fname, "rb")) == NULL) {
+ if ((fp = g_fopen(fname, "rb")) == NULL) {
FILE_OP_ERROR(fname, "fopen");
return;
}
MimeViewer *viewer = NULL;
if ((partinfo->type == MIMETYPE_APPLICATION) &&
- (!g_strcasecmp(partinfo->subtype, "octet-stream"))) {
+ (!g_ascii_strcasecmp(partinfo->subtype, "octet-stream"))) {
const gchar *filename;
filename = procmime_mimeinfo_get_parameter(partinfo, "filename");
return viewer;
}
-static gboolean mimeview_show_part(MimeView *mimeview, MimeInfo *partinfo)
+gboolean mimeview_show_part(MimeView *mimeview, MimeInfo *partinfo)
{
MimeViewer *viewer;
return FALSE;
}
+ if (mimeview->mimeviewer != NULL)
+ mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
+
if (mimeview->mimeviewer != viewer) {
- if (mimeview->mimeviewer != NULL)
- mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
mimeview->mimeviewer = viewer;
mimeview_change_view_type(mimeview, MIMEVIEW_VIEWER);
}
switch (type) {
case MIMEVIEW_TEXT:
- gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->mime_notebook),
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(mimeview->mime_notebook),
gtk_notebook_page_num(GTK_NOTEBOOK(mimeview->mime_notebook),
GTK_WIDGET_PTR(textview)));
break;
case MIMEVIEW_VIEWER:
- gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->mime_notebook),
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(mimeview->mime_notebook),
gtk_notebook_page_num(GTK_NOTEBOOK(mimeview->mime_notebook),
GTK_WIDGET(mimeview->mimeviewer->get_widget(mimeview->mimeviewer))));
break;
}
static void check_signature_cb(GtkWidget *widget, gpointer user_data);
+void mimeview_check_signature(MimeView *mimeview);
static void display_full_info_cb(GtkWidget *widget, gpointer user_data);
static void update_signature_noticeview(MimeView *mimeview, MimeInfo *mimeinfo)
switch (privacy_mimeinfo_get_sig_status(mimeinfo)) {
case SIGNATURE_UNCHECKED:
- button_text = _("Check");
+ button_text = _("Check signature");
func = check_signature_cb;
icon = STOCK_PIXMAP_PRIVACY_SIGNED;
break;
case SIGNATURE_OK:
- button_text = _("Full info");
+ button_text = _("View full information");
func = display_full_info_cb;
icon = STOCK_PIXMAP_PRIVACY_PASSED;
break;
case SIGNATURE_WARN:
- button_text = _("Full info");
+ button_text = _("View full information");
func = display_full_info_cb;
icon = STOCK_PIXMAP_PRIVACY_WARN;
break;
case SIGNATURE_INVALID:
- button_text = _("Full info");
+ button_text = _("View full information");
func = display_full_info_cb;
icon = STOCK_PIXMAP_PRIVACY_FAILED;
break;
default:
break;
}
- text = privacy_mimeinfo_sig_info_short(mimeinfo);
+ if (privacy_mimeinfo_get_sig_status(mimeinfo) == SIGNATURE_UNCHECKED) {
+ gchar *tmp = privacy_mimeinfo_sig_info_short(mimeinfo);
+ text = g_strdup_printf("%s %s",
+ tmp, _("Click the icon or hit 'C' to check it."));
+ g_free(tmp);
+ } else
+ text = privacy_mimeinfo_sig_info_short(mimeinfo);
noticeview_set_text(mimeview->siginfoview, text);
g_free(text);
- noticeview_set_button_text(mimeview->siginfoview, button_text);
+ noticeview_set_button_text(mimeview->siginfoview, NULL);
noticeview_set_button_press_callback(
mimeview->siginfoview,
- GTK_SIGNAL_FUNC(func),
+ G_CALLBACK(func),
(gpointer) mimeview);
noticeview_set_icon(mimeview->siginfoview, icon);
+ noticeview_set_tooltip(mimeview->siginfoview, button_text);
}
static void check_signature_cb(GtkWidget *widget, gpointer user_data)
MimeView *mimeview = (MimeView *) user_data;
MimeInfo *mimeinfo = mimeview->siginfo;
+ if (mimeinfo == NULL)
+ return;
+
+ noticeview_set_text(mimeview->siginfoview, _("Checking signature..."));
+ GTK_EVENTS_FLUSH();
privacy_mimeinfo_check_signature(mimeinfo);
update_signature_noticeview(mimeview, mimeview->siginfo);
icon_list_clear(mimeview);
icon_list_create(mimeview, mimeview->mimeinfo);
}
+void mimeview_check_signature(MimeView *mimeview)
+{
+ check_signature_cb(NULL, mimeview);
+}
+
+static void redisplay_email(GtkWidget *widget, gpointer user_data)
+{
+ MimeView *mimeview = (MimeView *) user_data;
+ GtkCTreeNode *node = mimeview->opened;
+ mimeview->opened = NULL;
+ mimeview_selected(GTK_CTREE(mimeview->ctree), node, 0, mimeview);
+}
+
static void display_full_info_cb(GtkWidget *widget, gpointer user_data)
{
MimeView *mimeview = (MimeView *) user_data;
textview_set_text(mimeview->textview, siginfo);
g_free(siginfo);
noticeview_set_button_text(mimeview->siginfoview, NULL);
+ noticeview_set_button_press_callback(
+ mimeview->siginfoview,
+ G_CALLBACK(redisplay_email),
+ (gpointer) mimeview);
+ noticeview_set_tooltip(mimeview->siginfoview, _("Go back to email"));
}
static void update_signature_info(MimeView *mimeview, MimeInfo *selected)
{
MimeInfo *siginfo;
-
+ MimeInfo *first_text;
+
g_return_if_fail(mimeview != NULL);
g_return_if_fail(selected != NULL);
+ if (selected->type == MIMETYPE_MESSAGE
+ && !g_ascii_strcasecmp(selected->subtype, "rfc822")) {
+ /* if the first text part is signed, check that */
+ first_text = selected;
+ while (first_text && first_text->type != MIMETYPE_TEXT) {
+ first_text = procmime_mimeinfo_next(first_text);
+ }
+ if (first_text) {
+ update_signature_info(mimeview, first_text);
+ return;
+ }
+ }
+
siginfo = selected;
while (siginfo != NULL) {
if (privacy_mimeinfo_is_signed(siginfo))
"/Display as text", TRUE);
if (partinfo &&
partinfo->type == MIMETYPE_APPLICATION &&
- !g_strcasecmp(partinfo->subtype, "octet-stream"))
+ !g_ascii_strcasecmp(partinfo->subtype, "octet-stream"))
menu_set_sensitive(mimeview->popupfactory,
"/Open", FALSE);
else
KEY_PRESS_EVENT_STOP();
mimeview_open_with(mimeview);
return TRUE;
+ case GDK_c:
+ BREAK_ON_MODIFIER_KEY();
+ KEY_PRESS_EVENT_STOP();
+ mimeview_check_signature(mimeview);
+ return TRUE;
default:
break;
}
alertpanel_error
(_("Can't save the part of multipart message."));
- uriname = g_strconcat("file:/", filename, NULL);
+ uriname = g_strconcat("file://", filename, NULL);
gtk_selection_data_set(selection_data, selection_data->target, 8,
uriname, strlen(uriname));
filename = g_strdup(get_part_name(partinfo));
if (!filename || !*filename)
filename = g_strdup_printf("noname.%d", number);
- subst_for_shellsafe_filename(filename);
+
+ if (!g_utf8_validate(filename, -1, NULL)) {
+ gchar *tmp = conv_filename_to_utf8(filename);
+ g_free(filename);
+ filename = tmp;
+ }
+
+ subst_for_filename(filename);
fullname = g_strconcat
(basedir, G_DIR_SEPARATOR_S, (filename[0] == G_DIR_SEPARATOR)
? &filename[1] : filename, NULL);
- subst_chars(fullname, "/\\", G_DIR_SEPARATOR);
g_free(filename);
- return fullname;
+ filename = conv_filename_from_utf8(fullname);
+ g_free(fullname);
+ return filename;
}
/**
{
gchar *dir;
- dir= g_dirname(filename);
+ dir= g_path_get_dirname(filename);
if (!is_dir_exist(dir))
make_dir_hier(dir);
g_free(dir);
if (is_file_exist(filename)) {
AlertValue aval;
gchar *res;
+ gchar *tmp;
+
+ if (!g_utf8_validate(filename, -1, NULL))
+ tmp = conv_filename_to_utf8(filename);
+ else
+ tmp = g_strdup(filename);
res = g_strdup_printf(_("Overwrite existing file '%s'?"),
- filename);
- aval = alertpanel(_("Overwrite"), res, _("OK"),
- _("Cancel"), NULL);
+ tmp);
+ g_free(tmp);
+ aval = alertpanel(_("Overwrite"), res, GTK_STOCK_OK,
+ GTK_STOCK_CANCEL, NULL);
g_free(res);
if (G_ALERTDEFAULT != aval) return FALSE;
}
startdir = g_strconcat(prefs_common.attach_save_dir,
G_DIR_SEPARATOR_S, NULL);
- dirname = filesel_select_file_open(_("Select destination folder"), startdir);
+ dirname = filesel_select_file_save_folder(_("Select destination folder"), startdir);
if (!dirname) {
if (startdir) g_free(startdir);
return;
}
if (!is_dir_exist (dirname)) {
- alertpanel_error(_("`%s' is not a directory."),
+ alertpanel_error(_("'%s' is not a directory."),
dirname);
if (startdir) g_free(startdir);
return;
if (dirname[strlen(dirname)-1] == G_DIR_SEPARATOR)
dirname[strlen(dirname)-1] = '\0';
+ /* Skip the first part, that is sometimes DISPOSITIONTYPE_UNKNOWN */
+ if (partinfo && partinfo->type == MIMETYPE_MESSAGE)
+ partinfo = procmime_mimeinfo_next(partinfo);
+ if (partinfo && partinfo->type == MIMETYPE_MULTIPART) {
+ partinfo = procmime_mimeinfo_next(partinfo);
+ if (partinfo && partinfo->type == MIMETYPE_TEXT)
+ partinfo = procmime_mimeinfo_next(partinfo);
+ }
+
while (partinfo != NULL) {
if (partinfo->type != MIMETYPE_MESSAGE &&
partinfo->type != MIMETYPE_MULTIPART &&
static void mimeview_save_as(MimeView *mimeview)
{
gchar *filename;
- gchar *defname = NULL;
gchar *filepath = NULL;
gchar *filedir = NULL;
MimeInfo *partinfo;
- const gchar *partname = NULL;
+ gchar *partname = NULL;
if (!mimeview->opened) return;
if (!mimeview->file) return;
}
g_return_if_fail(partinfo != NULL);
- if ((partname = get_part_name(partinfo)) != NULL) {
- Xstrdup_a(defname, partname, return);
- subst_for_shellsafe_filename(defname);
+ if (get_part_name(partinfo) == NULL) {
+ return;
+ }
+ partname = g_strdup(get_part_name(partinfo));
+
+ if (!g_utf8_validate(partname, -1, NULL)) {
+ gchar *tmp = conv_filename_to_utf8(partname);
+ g_free(partname);
+ partname = tmp;
}
+ subst_for_filename(partname);
+
if (prefs_common.attach_save_dir)
filepath = g_strconcat(prefs_common.attach_save_dir,
- G_DIR_SEPARATOR_S, defname, NULL);
+ G_DIR_SEPARATOR_S, partname, NULL);
else
- filepath = g_strdup(defname);
+ filepath = g_strdup(partname);
+
+ g_free(partname);
filename = filesel_select_file_save(_("Save as"), filepath);
if (!filename) {
mimeview_write_part(filename, partinfo);
- filedir = g_dirname(filename);
+ filedir = g_path_get_dirname(filename);
if (filedir && strcmp(filedir, ".")) {
if (prefs_common.attach_save_dir)
g_free(prefs_common.attach_save_dir);
alertpanel_error
(_("Can't save the part of multipart message."));
else
- mimeview_view_file(filename, partinfo, NULL);
+ mimeview_view_file(filename, partinfo, NULL, mimeview);
g_free(filename);
}
MimeInfo *partinfo;
gchar *filename;
gchar *cmd;
+ gchar *mime_command = NULL;
+ gchar *content_type = NULL;
+ if (!mimeview) return;
if (!mimeview->opened) return;
if (!mimeview->file) return;
prefs_common.mime_open_cmd_history =
add_history(NULL, prefs_common.mime_open_cmd);
+ content_type = procmime_get_content_type_str(partinfo->type,
+ partinfo->subtype);
+ mime_command = mailcap_get_command_for_type(content_type);
+ g_free(content_type);
cmd = input_dialog_combo
(_("Open with"),
_("Enter the command line to open file:\n"
- "(`%s' will be replaced with file name)"),
- prefs_common.mime_open_cmd,
+ "('%s' will be replaced with file name)"),
+ mime_command ? mime_command : prefs_common.mime_open_cmd,
prefs_common.mime_open_cmd_history,
TRUE);
+ g_free(mime_command);
if (cmd) {
- mimeview_view_file(filename, partinfo, cmd);
+ mimeview_view_file(filename, partinfo, cmd, mimeview);
g_free(prefs_common.mime_open_cmd);
prefs_common.mime_open_cmd = cmd;
prefs_common.mime_open_cmd_history =
}
static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
- const gchar *cmdline)
+ const gchar *cmdline, MimeView *mimeview)
{
- static gchar *default_image_cmdline = "display '%s'";
- static gchar *default_audio_cmdline = "play '%s'";
+ static gchar *default_image_cmdline = DEFAULT_IMAGE_VIEWER_CMD;
+ static gchar *default_audio_cmdline = DEFAULT_AUDIO_PLAYER_CMD;
static gchar *default_html_cmdline = DEFAULT_BROWSER_CMD;
- static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
+ static gchar *mime_cmdline = DEFAULT_MIME_CMD;
gchar buf[1024];
gchar m_buf[1024];
const gchar *cmd;
cmd = cmdline;
def_cmd = NULL;
} else if (MIMETYPE_APPLICATION == partinfo->type &&
- !g_strcasecmp(partinfo->subtype, "octet-stream")) {
+ !g_ascii_strcasecmp(partinfo->subtype, "octet-stream")) {
+ mimeview_open_with(mimeview);
return;
} else if (MIMETYPE_IMAGE == partinfo->type) {
cmd = prefs_common.mime_image_viewer;
g_snprintf(buf, sizeof(buf), cmd, filename);
else {
if (cmd)
- g_warning("MIME viewer command line is invalid: `%s'", cmd);
+ g_warning("MIME viewer command line is invalid: '%s'", cmd);
if (def_cmd)
g_snprintf(buf, sizeof(buf), def_cmd, filename);
- else
+ else {
+ mimeview_open_with(mimeview);
return;
+ }
}
- execute_command_line(buf, TRUE);
+ if (execute_command_line(buf, TRUE) != 0)
+ mimeview_open_with(mimeview);
}
void mimeview_register_viewer_factory(MimeViewerFactory *factory)
KEY_PRESS_EVENT_STOP();
mimeview_open_with(mimeview);
return TRUE;
+ case GDK_c:
+ BREAK_ON_MODIFIER_KEY();
+ KEY_PRESS_EVENT_STOP();
+ mimeview_check_signature(mimeview);
+ return TRUE;
default:
break;
}
static void icon_list_append_icon (MimeView *mimeview, MimeInfo *mimeinfo)
{
- GtkWidget *pixmap;
+ GtkWidget *pixmap = NULL;
GtkWidget *vbox;
GtkWidget *button;
gchar *tip;
switch (mimeinfo->type) {
case MIMETYPE_TEXT:
- if (mimeinfo->subtype && !g_strcasecmp(mimeinfo->subtype, "html"))
+ if (mimeinfo->subtype && !g_ascii_strcasecmp(mimeinfo->subtype, "html"))
stockp = STOCK_PIXMAP_MIME_TEXT_HTML;
- else if (mimeinfo->subtype && !g_strcasecmp(mimeinfo->subtype, "enriched"))
+ else if (mimeinfo->subtype && !g_ascii_strcasecmp(mimeinfo->subtype, "enriched"))
stockp = STOCK_PIXMAP_MIME_TEXT_ENRICHED;
else
stockp = STOCK_PIXMAP_MIME_TEXT_PLAIN;
to_human_readable(mimeinfo->length), NULL);
g_free(content_type);
if (desc && *desc) {
- tiptmp = g_strjoin("\n", desc, tip, NULL);
+ gchar *tmp = NULL;
+ if (!g_utf8_validate(desc, -1, NULL)) {
+ tmp = conv_filename_to_utf8(desc);
+ } else {
+ tmp = g_strdup(desc);
+ }
+ tiptmp = g_strjoin("\n", tmp, tip, NULL);
g_free(tip);
tip = tiptmp;
+ g_free(tmp);
}
if (sigshort && *sigshort) {
tiptmp = g_strjoin("\n", tip, sigshort, NULL);
}
mimeview->icon_count = 0;
adj = gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview->icon_scroll));
- adj->value = adj->lower;
+ gtk_adjustment_set_value(adj, adj->lower);
}
static void icon_list_toggle_by_mime_info(MimeView *mimeview,