2011-01-06 [colin] 3.7.8cvs30
[claws.git] / src / messageview.c
index 2a8cedf2ed6362ea1c1e91361c658384c2bbc620..3d540cc37c04d75b808625489251e1c32db8cb37 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,7 +58,6 @@
 #include "hooks.h"
 #include "filtering.h"
 #include "partial_download.h"
-#include "gedit-print.h"
 #include "uri_opener.h"
 #include "inc.h"
 #include "log.h"
@@ -94,10 +93,8 @@ 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) && !defined(USE_GNOMEPRINT)
 static void page_setup_cb              (GtkAction      *action,
                                         gpointer        data);
-#endif
 static void print_cb                   (GtkAction      *action,
                                         gpointer        data);
 static void close_cb                   (GtkAction      *action,
@@ -193,9 +190,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) && !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) },
        {"File/---",                    NULL, "---", NULL, NULL, NULL },
        {"File/Close",                  NULL, N_("_Close"), "<control>W", NULL, G_CALLBACK(close_cb) },
@@ -276,13 +271,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) }, 
@@ -333,6 +328,7 @@ static GtkRadioActionEntry msgview_radio_enc_entries[] =
        ENC_ACTION("Japanese/"CS_ISO_2022_JP_2, C_ISO_2022_JP_2, "ISO-2022-JP-_2"), /* RADIO set_charset_cb */
        ENC_ACTION("Japanese/"CS_EUC_JP, C_EUC_JP, "_EUC-JP"), /* RADIO set_charset_cb */
        ENC_ACTION("Japanese/"CS_SHIFT_JIS, C_SHIFT_JIS, "_Shift-JIS"), /* RADIO set_charset_cb */
+       ENC_ACTION("Chinese/"CS_GB18030, C_GB18030, "_GB18030"), /* RADIO set_charset_cb */
        ENC_ACTION("Chinese/"CS_GB2312, C_GB2312, "_GB2312"), /* RADIO set_charset_cb */
        ENC_ACTION("Chinese/"CS_GBK, C_GBK, "GB_K"), /* RADIO set_charset_cb */
        ENC_ACTION("Chinese/"CS_BIG5, C_BIG5, "_Big5-JP"), /* RADIO set_charset_cb */
@@ -442,7 +438,7 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
 #ifndef MAEMO
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENUBAR)
 #else
-       MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENU)
+       MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_POPUP)
 #endif
 
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "File", "File", GTK_UI_MANAGER_MENU)
@@ -454,9 +450,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) && !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)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Separator1", "File/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Close", "File/Close", GTK_UI_MANAGER_MENUITEM)
@@ -535,6 +529,7 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Japanese", CS_SHIFT_JIS, "View/Encoding/Japanese/"CS_SHIFT_JIS, GTK_UI_MANAGER_MENUITEM)
 
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Chinese", "View/Encoding/Chinese", GTK_UI_MANAGER_MENU)
+       MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB18030, "View/Encoding/Chinese/"CS_GB18030, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB2312, "View/Encoding/Chinese/"CS_GB2312, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GBK, "View/Encoding/Chinese/"CS_GBK, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_BIG5, "View/Encoding/Chinese/"CS_BIG5, GTK_UI_MANAGER_MENUITEM)
@@ -674,6 +669,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);
 
@@ -727,8 +725,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;
 
@@ -861,7 +859,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        addrp = addr;
        
        /* write queue headers */
-       if (fprintf(fp, "AF:\n"
+       ok = fprintf(fp, "AF:\n"
                    "NF:0\n"
                    "PS:10\n"
                    "SRH:1\n"
@@ -877,14 +875,11 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                    "R:<%s>\n", 
                    account->address,
                    account->smtp_server?account->smtp_server:"",
-                   addrp) < 0) {
-               g_free(addrp);
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+                   addrp);
 
        g_free(addrp);
+       if (ok < 0)
+               goto FILE_ERROR;
        
        /* check whether we need to save the message */
        outbox = account_get_special_folder(account, F_OUTBOX); 
@@ -892,61 +887,40 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                outbox = NULL;
        if (outbox) {
                path = folder_item_get_identifier(outbox);
-               if (fprintf(fp, "SCF:%s\n", path) < 0) {
-                       g_free(path);
-                       fclose(fp);
-                       claws_unlink(tmp);
-                       return -1;
-               }
+               ok = fprintf(fp, "SCF:%s\n", path);
                g_free(path);
+               
+               if (ok < 0)
+                       goto FILE_ERROR;
        }               
 
-       if (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+       if (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0)
+               goto FILE_ERROR;
 
        /* Date */
        get_rfc822_date(buf, sizeof(buf));
-       if (fprintf(fp, "Date: %s\n", buf) < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+       if (fprintf(fp, "Date: %s\n", buf) < 0)
+               goto FILE_ERROR;
 
        /* From */
        if (account->name && *account->name) {
                notification_convert_header
                        (buf, sizeof(buf), account->name,
                         strlen("From: "));
-               if (fprintf(fp, "From: %s <%s>\n", buf, account->address) < 0) {
-                       fclose(fp);
-                       claws_unlink(tmp);
-                       return -1;
-               }
+               if (fprintf(fp, "From: %s <%s>\n", buf, account->address) < 0)
+                       goto FILE_ERROR;
        } else
-               if (fprintf(fp, "From: %s\n", account->address) < 0) {
-                       fclose(fp);
-                       claws_unlink(tmp);
-                       return -1;
-               }
-
+               if (fprintf(fp, "From: %s\n", account->address) < 0)
+                       goto FILE_ERROR;
 
-       if (fprintf(fp, "To: %s\n", to) < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+       if (fprintf(fp, "To: %s\n", to) < 0)
+               goto FILE_ERROR;
 
        /* Subject */
        notification_convert_header(buf, sizeof(buf), msginfo->subject,
                                    strlen("Subject: "));
-       if (fprintf(fp, "Subject: Disposition notification: %s\n", buf) < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+       if (fprintf(fp, "Subject: Disposition notification: %s\n", buf) < 0)
+               goto FILE_ERROR;
 
        /* Message ID */
        if (account->set_domain && account->domain) {
@@ -961,13 +935,14 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        }
        
        if (account->gen_msgid) {
-               generate_msgid(buf, sizeof(buf));
-
-               if (fprintf(fp, "Message-ID: <%s>\n", buf) < 0) {
-                       fclose(fp);
-                       claws_unlink(tmp);
-                       return -1;
+               gchar *addr = NULL;
+               if (account->msgid_with_addr) {
+                       addr = account->address;
                }
+               generate_msgid(buf, sizeof(buf), addr);
+
+               if (fprintf(fp, "Message-ID: <%s>\n", buf) < 0)
+                       goto FILE_ERROR;
        }
 
        boundary = generate_mime_boundary("DN");
@@ -982,7 +957,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                qp_encode_line(enc_sub, (const guchar *)msginfo->subject);
                g_strstrip(enc_sub);
        }
-       if (fprintf(fp, "MIME-Version: 1.0\n"
+       ok = fprintf(fp,"MIME-Version: 1.0\n"
                        "Content-Type: multipart/report; report-type=disposition-notification;\n"
                        "  boundary=\"%s\"\n"
                        "\n"
@@ -1031,18 +1006,16 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                        orig_to?orig_to:"No To:",
                        account->address,
                        msginfo->msgid?msginfo->msgid:"NO MESSAGE ID",
-                       boundary) < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               g_free(boundary);
-               return -1;
-       }
+                       boundary);
 
        g_free(enc_sub);
        g_free(orig_to);
        g_free(date);
        g_free(boundary);
 
+       if (ok < 0)
+               goto FILE_ERROR;        
+
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmp, "fclose");
                claws_unlink(tmp);
@@ -1079,6 +1052,11 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                folder_item_remove_msg(queue, num);
 
        return ok;
+
+FILE_ERROR:
+       fclose(fp);
+       claws_unlink(tmp);
+       return -1;
 }
 
 static gboolean find_encrypted_func(GNode *node, gpointer data)
@@ -1104,13 +1082,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;
@@ -1186,8 +1188,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;
                }
        }
@@ -1260,6 +1269,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 || 
@@ -1271,8 +1300,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)) {
@@ -1288,8 +1316,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;
                                        }
@@ -1298,8 +1332,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) {
@@ -1309,8 +1342,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;
                                        }
@@ -1342,6 +1381,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;
@@ -1440,7 +1482,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
@@ -1455,7 +1497,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 */
@@ -1482,7 +1524,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);
@@ -1645,7 +1687,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;
@@ -1659,7 +1701,9 @@ 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)) != 0)
+               return FALSE;
+       if (event && (event->state & GDK_SHIFT_MASK) && event->keyval != GDK_space) 
                return FALSE;
 
        g_signal_stop_emission_by_name(G_OBJECT(widget),
@@ -1859,8 +1903,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),
@@ -1896,7 +1940,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;
@@ -1908,10 +1952,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);
@@ -1935,12 +1979,9 @@ static void save_as_cb(GtkAction *action, gpointer data)
        messageview_save_as(messageview);
 }
 
-#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)
@@ -1967,15 +2008,11 @@ 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
        }
 }
 
@@ -2007,51 +2044,26 @@ void messageview_print(MsgInfo *msginfo, gboolean all_headers,
        }
        messageview_destroy(tmpview);
 }
-#endif
 
-#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
 static void page_setup_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
        printing_page_setup(messageview ?
                            GTK_WINDOW(messageview->window) : NULL);
 }
-#endif
 
 static void print_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
-#if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
-       gchar *cmdline = NULL;
-       gchar *p;
-#else
        gint sel_start = -1, sel_end = -1, partnum = 0;
-#endif
 
        if (!messageview->msginfo) return;
 
-#if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
-       cmdline = input_dialog(_("Print"),
-                              _("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'"),
-                                cmdline);
-               g_free(cmdline);
-               return;
-       }
-       procmsg_print_message(messageview->msginfo, cmdline);
-       g_free(cmdline);
-#else
        partnum = mimeview_get_selected_part_num(messageview->mimeview);
        textview_get_selection_offsets(messageview->mimeview->textview,
                &sel_start, &sel_end);
        messageview_print(messageview->msginfo, messageview->all_headers, 
                sel_start, sel_end, partnum);
-#endif
 }
 
 static void close_cb(GtkAction *action, gpointer data)
@@ -2564,7 +2576,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);
@@ -2731,7 +2743,12 @@ void messageview_list_urls (MessageView  *msgview)
 {
        GSList *cur = msgview->mimeview->textview->uri_list;
        GSList *newlist = NULL;
-       GHashTable *uri_hashtable = g_hash_table_new(g_str_hash, g_str_equal); 
+       GHashTable *uri_hashtable;
+       gchar *tmp;
+       
+       uri_hashtable = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                        (GDestroyNotify) g_free, NULL);
+       
        for (; cur; cur = cur->next) {
                ClickableText *uri = (ClickableText *)cur->data;
                if (uri->uri &&
@@ -2741,12 +2758,16 @@ void messageview_list_urls (MessageView *msgview)
                     !g_ascii_strncasecmp(uri->uri, "http:", 5) ||
                     !g_ascii_strncasecmp(uri->uri, "https:", 6)))
                {
-                       if(g_hash_table_lookup(uri_hashtable, uri->uri))
+                       tmp = g_utf8_strdown(uri->uri, -1);
+                       
+                       if (g_hash_table_lookup(uri_hashtable, tmp)) {
+                               g_free(tmp);
                                continue;
+                       }
                        
                        newlist = g_slist_prepend(newlist, uri);
-                       g_hash_table_insert(uri_hashtable, uri->uri,
-                                           GUINT_TO_POINTER(g_str_hash(uri->uri)));
+                       g_hash_table_insert(uri_hashtable, tmp,
+                                           GUINT_TO_POINTER(g_str_hash(tmp)));
                }
        }
        newlist = g_slist_reverse(newlist);