2009-05-12 [holger] 3.7.1cvs55
[claws.git] / src / messageview.c
index 603caade89cd7eb9ce9e9859490874d2984ccbfc..b4eb09fa7228376905da77be4a599d5bf0e51398 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2009 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
@@ -58,6 +58,7 @@
 #include "hooks.h"
 #include "filtering.h"
 #include "partial_download.h"
+#include "gedit-print.h"
 #include "uri_opener.h"
 #include "inc.h"
 #include "log.h"
@@ -93,7 +94,7 @@ static void partial_recv_unmark_clicked (NoticeView   *noticeview,
                                          MsgInfo        *msginfo);
 static void save_as_cb                 (GtkAction      *action,
                                         gpointer        data);
-#if GTK_CHECK_VERSION(2,10,0)
+#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
 static void page_setup_cb              (GtkAction      *action,
                                         gpointer        data);
 #endif
@@ -192,7 +193,7 @@ static GtkActionEntry msgview_entries[] =
 
 /* File menu */
        {"File/SaveAs",                 NULL, N_("_Save as..."), "<control>S", NULL, G_CALLBACK(save_as_cb) },
-#if GTK_CHECK_VERSION(2,10,0)
+#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
        {"File/PageSetup",              NULL, N_("Page setup..."), NULL, NULL, G_CALLBACK(page_setup_cb) },
 #endif
        {"File/Print",                  NULL, N_("_Print..."), "<control>P", NULL, G_CALLBACK(print_cb) },
@@ -275,13 +276,13 @@ static GtkActionEntry msgview_entries[] =
        {"Tools/AddSenderToAB",         NULL, N_("Add sender to address boo_k"), NULL, NULL, G_CALLBACK(add_address_cb) }, 
        {"Tools/---",                   NULL, "---", NULL, NULL, NULL },
 
-       {"Tools/CreateFilterRule",                      NULL, "_Create filter rule" },
+       {"Tools/CreateFilterRule",                      NULL, N_("_Create filter rule") },
        {"Tools/CreateFilterRule/Automatically",        NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_AUTO */
        {"Tools/CreateFilterRule/ByFrom",               NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_FROM */
        {"Tools/CreateFilterRule/ByTo",                 NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_TO     */
        {"Tools/CreateFilterRule/BySubject",            NULL, N_("By _Subject"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_SUBJECT */
 
-       {"Tools/CreateProcessingRule",                  NULL, "Create processing rule" },
+       {"Tools/CreateProcessingRule",                  NULL, N_("Create processing rule") },
        {"Tools/CreateProcessingRule/Automatically",    NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
        {"Tools/CreateProcessingRule/ByFrom",           NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
        {"Tools/CreateProcessingRule/ByTo",             NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
@@ -453,7 +454,7 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
 
 /* File menu */
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
-#if GTK_CHECK_VERSION(2,10,0)
+#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "PageSetup", "File/PageSetup", GTK_UI_MANAGER_MENUITEM)
 #endif
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
@@ -673,6 +674,9 @@ static MessageView *messageview_create_with_new_window_visible(MainWindow *mainw
 
        gtk_widget_set_size_request(window, prefs_common.msgwin_width,
                                    prefs_common.msgwin_height);
+#ifdef G_OS_WIN32
+       gtk_window_move(GTK_WINDOW(window), 48, 48);
+#endif
 
        msgview = messageview_create(mainwin);
 
@@ -726,8 +730,8 @@ static void notification_convert_header(gchar *dest, gint len,
 {
        char *src;
 
-       g_return_if_fail(src_ != NULL);
-       g_return_if_fail(dest != NULL);
+       cm_return_if_fail(src_ != NULL);
+       cm_return_if_fail(dest != NULL);
 
        if (len < 1) return;
 
@@ -1103,13 +1107,37 @@ static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
        return encinfo;
 }
 
+static gboolean find_broken_func(GNode *node, gpointer data)
+{
+       MimeInfo *mimeinfo = (MimeInfo *) node->data;
+       MimeInfo **brokeninfo = (MimeInfo **) data;
+       
+       if (mimeinfo->broken) {
+               *brokeninfo = mimeinfo;
+               return TRUE;
+       }
+       
+       return FALSE;
+}
+
+static MimeInfo *find_broken_part(MimeInfo *rootinfo)
+{
+       MimeInfo *brokeninfo = NULL;
+
+       g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
+               find_broken_func, &brokeninfo);
+       
+       return brokeninfo;
+}
+
 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                      gboolean all_headers)
 {
+       gchar *text = NULL;
        gchar *file;
-       MimeInfo *mimeinfo, *encinfo;
+       MimeInfo *mimeinfo, *encinfo, *brokeninfo;
        gchar *subject = NULL;
-       g_return_val_if_fail(msginfo != NULL, -1);
+       cm_return_val_if_fail(msginfo != NULL, -1);
 
        if (msginfo != messageview->msginfo)
                messageview->show_full_text = FALSE;
@@ -1185,8 +1213,15 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
        while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) {
                debug_print("decrypting message part\n");
                if (privacy_mimeinfo_decrypt(encinfo) < 0) {
-                       alertpanel_error(_("Couldn't decrypt: %s"),
-                               privacy_get_error());
+                       text = g_strdup_printf(_("Couldn't decrypt: %s"),
+                                              privacy_get_error());
+                       noticeview_show(messageview->noticeview);
+                       noticeview_set_icon(messageview->noticeview,
+                                           STOCK_PIXMAP_NOTICE_WARN);
+                       noticeview_set_text(messageview->noticeview, text);
+                       gtk_widget_hide(messageview->noticeview->button);
+                       gtk_widget_hide(messageview->noticeview->button2);
+                       g_free(text);
                        break;
                }
        }
@@ -1259,6 +1294,26 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                return_receipt_show(messageview->noticeview, 
                                    messageview->msginfo);
 
+       if ((brokeninfo = find_broken_part(mimeinfo)) != NULL) {
+               noticeview_set_icon(messageview->noticeview,
+                                   STOCK_PIXMAP_NOTICE_WARN);
+               if (!noticeview_is_visible(messageview->noticeview)) {
+                       noticeview_set_text(messageview->noticeview, _("Message doesn't conform to MIME standard. "
+                                               "It may render wrongly."));
+                       gtk_widget_hide(messageview->noticeview->button);
+                       gtk_widget_hide(messageview->noticeview->button2);
+               } else {
+                       gchar *full = g_strconcat(
+                                       gtk_label_get_text(GTK_LABEL(messageview->noticeview->text)), 
+                                       "\n", 
+                                       _("Message doesn't conform to MIME standard. "
+                                       "It may render wrongly."), NULL);
+                       noticeview_set_text(messageview->noticeview, full);
+                       g_free(full);
+               }
+               noticeview_show(messageview->noticeview);
+       }
+                       
        mimeinfo = procmime_mimeinfo_next(mimeinfo);
        if (!all_headers && mimeinfo 
                        && (mimeinfo->type != MIMETYPE_TEXT || 
@@ -1270,8 +1325,7 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                        MimeInfo *alt_parent = mimeinfo;
 
                        /* if multipart/{related,mixed} part, look inside for a multipart/alternative child */
-                       if (prefs_common.promote_html_part &&
-                           mimeinfo->type == MIMETYPE_MULTIPART &&
+                       if (mimeinfo->type == MIMETYPE_MULTIPART &&
                            (!strcasecmp(mimeinfo->subtype, "related") ||
                             !strcasecmp(mimeinfo->subtype, "mixed"))) {
                                for (; mimeinfo; mimeinfo = procmime_mimeinfo_next(mimeinfo)) {
@@ -1287,8 +1341,14 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                                                break;
                                        }
                                        if (mimeinfo->type == MIMETYPE_TEXT && 
-                                           !strcasecmp(mimeinfo->subtype, "html")) {
-                                               /* we got it */
+                                           !strcasecmp(mimeinfo->subtype, "calendar") &&
+                                           mimeview_has_viewer_for_content_type(messageview->mimeview,
+                                                                                "text/calendar")) {
+                                               mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
+                                               goto done;
+                                       } else if (mimeinfo->type == MIMETYPE_TEXT && 
+                                           !strcasecmp(mimeinfo->subtype, "html") &&
+                                           prefs_common.promote_html_part) {
                                                mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
                                                goto done;
                                        }
@@ -1297,8 +1357,7 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
 
                        /* if we now have a multipart/alternative part (possibly inside a
                         * multipart/{related,mixed} part, look for an HTML part inside */
-                       if (prefs_common.promote_html_part && mimeinfo && 
-                           mimeinfo->type == MIMETYPE_MULTIPART &&
+                       if (mimeinfo && mimeinfo->type == MIMETYPE_MULTIPART &&
                            !strcasecmp(mimeinfo->subtype, "alternative")) {
                                for (; mimeinfo; mimeinfo = procmime_mimeinfo_next(mimeinfo)) {
                                        if (mimeinfo->node->parent != alt_parent->node) {
@@ -1308,8 +1367,14 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                                                continue;
                                        }
                                        if (mimeinfo->type == MIMETYPE_TEXT && 
-                                           !strcasecmp(mimeinfo->subtype, "html")) {
-                                               /* we got it */
+                                           !strcasecmp(mimeinfo->subtype, "calendar") &&
+                                           mimeview_has_viewer_for_content_type(messageview->mimeview,
+                                                                                "text/calendar")) {
+                                               mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
+                                               goto done;
+                                       } else if (mimeinfo->type == MIMETYPE_TEXT && 
+                                           !strcasecmp(mimeinfo->subtype, "html") &&
+                                           prefs_common.promote_html_part) {
                                                mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
                                                goto done;
                                        }
@@ -1341,6 +1406,9 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                }
        }
 done:
+       /* plugins may hook in here to work with the message view */
+       hooks_invoke(MESSAGE_VIEW_SHOW_DONE_HOOKLIST, messageview);
+
        g_free(file);
 
        return 0;
@@ -1439,7 +1507,7 @@ void messageview_delete(MessageView *msgview)
        } else {                
                msginfo = msgview->msginfo;
 
-               g_return_if_fail(msginfo != NULL);
+               cm_return_if_fail(msginfo != NULL);
 
                /* to get the trash folder, we have to choose either
                 * the folder's or account's trash default - we prefer
@@ -1454,7 +1522,7 @@ void messageview_delete(MessageView *msgview)
                                trash = folder_get_default_trash();
                }       
 
-               g_return_if_fail(trash != NULL);
+               cm_return_if_fail(trash != NULL);
 
                if (prefs_common.immediate_exec)
                        /* TODO: Delete from trash */
@@ -1481,7 +1549,7 @@ static void messageview_update(MessageView *msgview, MsgInfo *old_msginfo)
 {
        SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
 
-       g_return_if_fail(summaryview != NULL);
+       cm_return_if_fail(summaryview != NULL);
        
        if (summaryview->selected) {
                MsgInfo *msginfo = summary_get_selected_msg(summaryview);
@@ -1644,7 +1712,7 @@ static gint messageview_delete_cb(GtkWidget *widget, GdkEventAny *event,
 static void messageview_size_allocate_cb(GtkWidget *widget,
                                         GtkAllocation *allocation)
 {
-       g_return_if_fail(allocation != NULL);
+       cm_return_if_fail(allocation != NULL);
 
        prefs_common.msgwin_width  = allocation->width;
        prefs_common.msgwin_height = allocation->height;
@@ -1658,7 +1726,7 @@ static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
                return TRUE;
        }
 
-       if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK|GDK_SHIFT_MASK)) != 0)
+       if (event && (event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK|GDK_SHIFT_MASK)) != 0)
                return FALSE;
 
        g_signal_stop_emission_by_name(G_OBJECT(widget),
@@ -1858,8 +1926,8 @@ static PrefsAccount *select_account_from_list(GList *ac_list)
        GtkWidget *optmenu;
        gint account_id;
 
-       g_return_val_if_fail(ac_list != NULL, NULL);
-       g_return_val_if_fail(ac_list->data != NULL, NULL);
+       cm_return_val_if_fail(ac_list != NULL, NULL);
+       cm_return_val_if_fail(ac_list->data != NULL, NULL);
        
        optmenu = gtkut_account_menu_new(ac_list,
                        G_CALLBACK(select_account_cb),
@@ -1895,7 +1963,7 @@ gchar *messageview_get_selection(MessageView *msgview)
        GtkTextBuffer *textbuf;
        gint body_pos = 0;
        
-       g_return_val_if_fail(msgview != NULL, NULL);
+       cm_return_val_if_fail(msgview != NULL, NULL);
 
        if (msgview->mimeview->type == MIMEVIEW_VIEWER) {
                MimeViewer *viewer = msgview->mimeview->mimeviewer;
@@ -1907,10 +1975,10 @@ gchar *messageview_get_selection(MessageView *msgview)
        }
 
        textview = messageview_get_current_textview(msgview);
-       g_return_val_if_fail(textview != NULL, NULL);
+       cm_return_val_if_fail(textview != NULL, NULL);
 
        edit = GTK_TEXT_VIEW(textview->text);
-       g_return_val_if_fail(edit != NULL, NULL);
+       cm_return_val_if_fail(edit != NULL, NULL);
        body_pos = textview->body_pos;
 
        textbuf = gtk_text_view_get_buffer(edit);
@@ -1934,11 +2002,12 @@ static void save_as_cb(GtkAction *action, gpointer data)
        messageview_save_as(messageview);
 }
 
-#if GTK_CHECK_VERSION(2,10,0)
+#if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
 static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gint partnum) 
 {
+#if !defined(USE_GNOMEPRINT) && GTK_CHECK_VERSION(2,10,0)
        MainWindow *mainwin;
-
+#endif
        if (!mimeview 
        ||  !mimeview->textview
        ||  !mimeview->textview->text)
@@ -1965,11 +2034,15 @@ static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gin
                        gtk_text_buffer_get_iter_at_offset(buffer, &end, sel_end);
                        gtk_text_buffer_select_range(buffer, &start, &end);
                }
+#if defined(USE_GNOMEPRINT)
+               gedit_print(GTK_TEXT_VIEW(mimeview->textview->text));
+#else
                /* TODO: Get the real parent window, not the main window */
                mainwin = mainwindow_get_mainwindow();
                printing_print(GTK_TEXT_VIEW(mimeview->textview->text),
                               mainwin ? GTK_WINDOW(mainwin->window) : NULL,
                                sel_start, sel_end);
+#endif
        }
 }
 
@@ -2003,7 +2076,7 @@ void messageview_print(MsgInfo *msginfo, gboolean all_headers,
 }
 #endif
 
-#if GTK_CHECK_VERSION(2,10,0)
+#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
 static void page_setup_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
@@ -2015,7 +2088,7 @@ static void page_setup_cb(GtkAction *action, gpointer data)
 static void print_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
-#if !GTK_CHECK_VERSION(2,10,0)
+#if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
        gchar *cmdline = NULL;
        gchar *p;
 #else
@@ -2024,15 +2097,15 @@ static void print_cb(GtkAction *action, gpointer data)
 
        if (!messageview->msginfo) return;
 
-#if !GTK_CHECK_VERSION(2,10,0)
+#if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
        cmdline = input_dialog(_("Print"),
-                              _("Enter the print command line:\n"
+                              _("Enter the print command-line:\n"
                                 "('%s' will be replaced with file name)"),
                               prefs_common.print_cmd);
        if (!cmdline) return;
        if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
            strchr(p + 2, '%')) {
-               alertpanel_error(_("Print command line is invalid:\n'%s'"),
+               alertpanel_error(_("Print command-line is invalid:\n'%s'"),
                                 cmdline);
                g_free(cmdline);
                return;
@@ -2558,7 +2631,7 @@ static void reply_cb(GtkAction *gaction, gpointer data)
        gint action = COMPOSE_REPLY;
        const gchar *a_name = gtk_action_get_name(gaction);
        
-       g_return_if_fail(messageview->msginfo);
+       cm_return_if_fail(messageview->msginfo);
 
        DO_ACTION("Message/Reply", COMPOSE_REPLY);
        DO_ACTION("Message/ReplyTo/All", COMPOSE_REPLY_TO_ALL);