Fix untranslatable concatenated strings (i.e. "Default "+"To:"),
[claws.git] / src / messageview.c
index 48ae56093fd60cc6700a383bc8b8bc4755f41ec3..05bf9565ab163f23527958130b701d34c4e436a5 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * 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-2016 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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 #include "defs.h"
@@ -67,7 +66,8 @@
 #include "version.h"
 #include "statusbar.h"
 #include "folder_item_prefs.h"
-#ifndef USE_NEW_ADDRBOOK
+#include "avatars.h"
+#ifndef USE_ALT_ADDRBOOK
        #include "addressbook.h"
 #else
        #include "addressadd.h"
@@ -80,11 +80,9 @@ static gint messageview_delete_cb    (GtkWidget              *widget,
                                         MessageView            *messageview);
 static void messageview_size_allocate_cb(GtkWidget     *widget,
                                         GtkAllocation  *allocation);
-#ifndef MAEMO
 static gboolean key_pressed            (GtkWidget      *widget,
                                         GdkEventKey    *event,
                                         MessageView    *messageview);
-#endif
 static void return_receipt_show                (NoticeView     *noticeview, 
                                         MsgInfo        *msginfo);      
 static void return_receipt_send_clicked (NoticeView    *noticeview, 
@@ -252,7 +250,7 @@ static GtkActionEntry msgview_entries[] =
        {"View/Goto/ParentMessage",     NULL, N_("Parent message"), "<control>Up", NULL, G_CALLBACK(parent_cb) },
        /* {"View/Goto/---",            NULL, "---", NULL, NULL, NULL }, */
        {"View/Goto/NextUnreadFolder",  NULL, N_("Next unread _folder"), "<shift>G", NULL, G_CALLBACK(goto_unread_folder_cb) },
-       {"View/Goto/OtherFolder",       NULL, N_("_Other folder..."), "G", NULL, G_CALLBACK(goto_folder_cb) },
+       {"View/Goto/Folder",            NULL, N_("F_older..."), "G", NULL, G_CALLBACK(goto_folder_cb) },
        /* {"View/Goto/---",            NULL, "---", NULL, NULL, NULL }, */
        {"View/Goto/NextPart",          NULL, N_("Next part"), "A", NULL, G_CALLBACK(goto_next_part_cb) },
        {"View/Goto/PrevPart",          NULL, N_("Previous part"), "Z", NULL, G_CALLBACK(goto_prev_part_cb) },
@@ -367,6 +365,7 @@ static GtkRadioActionEntry msgview_radio_enc_entries[] =
        ENC_ACTION(CS_ISO_8859_9, C_ISO_8859_9, N_("Turkish (ISO-8859-_9)")), /* RADIO set_charset_cb */
        ENC_ACTION("Cyrillic/"CS_ISO_8859_5, C_ISO_8859_5, "ISO-8859-_5"), /* RADIO set_charset_cb */
        ENC_ACTION("Cyrillic/"CS_KOI8_R, C_KOI8_R, "KOI8-_R"), /* RADIO set_charset_cb */
+       ENC_ACTION("Cyrillic/"CS_MACCYR, C_MACCYR, "MAC_CYR"), /* RADIO set_charset_cb */
        ENC_ACTION("Cyrillic/"CS_KOI8_U, C_KOI8_U, "KOI8-_U"), /* RADIO set_charset_cb */
        ENC_ACTION("Cyrillic/"CS_WINDOWS_1251, C_WINDOWS_1251, "Windows-1251"), /* RADIO set_charset_cb */
        ENC_ACTION("Japanese/"CS_ISO_2022_JP, C_ISO_2022_JP, "ISO-2022-_JP"), /* RADIO set_charset_cb */
@@ -443,7 +442,7 @@ MessageView *messageview_create(MainWindow *mainwin)
        return messageview;
 }
 
-GList *messageview_get_msgview_list(void)
+const GList *messageview_get_msgview_list(void)
 {
        return msgview_list;
 }
@@ -481,12 +480,7 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
        gtk_action_group_add_radio_actions(action_group, msgview_radio_dec_entries,
                        G_N_ELEMENTS(msgview_radio_dec_entries), C_AUTO, G_CALLBACK(set_decode_cb), (gpointer)msgview);
 
-#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_POPUP)
-#endif
-
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "File", "File", GTK_UI_MANAGER_MENU)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "Edit", "Edit", GTK_UI_MANAGER_MENU)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "View", "View", GTK_UI_MANAGER_MENU)
@@ -532,7 +526,7 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "ParentMessage", "View/Goto/ParentMessage", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator7", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextUnreadFolder", "View/Goto/NextUnreadFolder", GTK_UI_MANAGER_MENUITEM)
-       MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "OtherFolder", "View/Goto/OtherFolder", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Folder", "View/Goto/Folder", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator8", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextPart", "View/Goto/NextPart", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevPart", "View/Goto/PrevPart", GTK_UI_MANAGER_MENUITEM)
@@ -578,6 +572,7 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Cyrillic", "View/Encoding/Cyrillic", GTK_UI_MANAGER_MENU)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_ISO_8859_5, "View/Encoding/Cyrillic/"CS_ISO_8859_5, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_R, "View/Encoding/Cyrillic/"CS_KOI8_R, GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_MACCYR, "View/Encoding/Cyrillic/"CS_MACCYR, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_U, "View/Encoding/Cyrillic/"CS_KOI8_U, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_WINDOWS_1251, "View/Encoding/Cyrillic/"CS_WINDOWS_1251, GTK_UI_MANAGER_MENUITEM)
 
@@ -670,11 +665,7 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
        gtk_widget_show_all(menubar);
        gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(msgview->ui_manager));
 
-#ifndef MAEMO
        gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
-#else
-       hildon_window_set_menu(HILDON_WINDOW(window), GTK_MENU(menubar));
-#endif
 
        cm_toggle_menu_set_active_full(msgview->ui_manager, "Menu/View/AllHeaders",
                                        prefs_common.show_all_headers);
@@ -686,12 +677,6 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
        }
        gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
        gtk_widget_realize(handlebox);
-#ifdef MAEMO
-       msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, window,
-                                         (gpointer)msgview);
-       msgview->statusbar = NULL;
-       msgview->statusbar_cid = 0;
-#else
        msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
                                          (gpointer)msgview);
 #ifndef GENERIC_UMPC
@@ -705,7 +690,6 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
        msgview->statusbar = NULL;
        msgview->statusbar_cid = 0;
 #endif
-#endif
 
 
        msgview->handlebox = handlebox;
@@ -749,12 +733,8 @@ static MessageView *messageview_create_with_new_window_visible(MainWindow *mainw
                         msgview);
        g_signal_connect(G_OBJECT(window), "delete_event",
                         G_CALLBACK(messageview_delete_cb), msgview);
-#ifdef MAEMO
-       maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
-#else
        g_signal_connect(G_OBJECT(window), "key_press_event",
                         G_CALLBACK(key_pressed), msgview);
-#endif
        messageview_add_toolbar(msgview, window);
 
        if (show) {
@@ -857,7 +837,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                ok = strcasecmp(to_addr, buf);
                g_free(to_addr);
        } else {
-               strncpy(buf, _("<No Return-Path found>"), 
+               g_strlcpy(buf, _("<No Return-Path found>"), 
                                sizeof(buf));
        }
        
@@ -869,7 +849,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                    "to be sent does not correspond to the return path:\n"
                    "Notification address: %s\n"
                    "Return path: %s\n"
-                   "It is advised to not to send the return receipt."),
+                   "It is advised to not send the return receipt."),
                  to, buf);
                val = alertpanel_full(_("Warning"), message,
                                _("_Don't Send"), _("_Send"), NULL, FALSE,
@@ -886,9 +866,9 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                AlertValue val = 
                alertpanel_full(_("Warning"),
                  _("This message is asking for a return receipt notification\n"
-                   "but according to its 'To:' and 'CC:' headers it was not\n"
+                   "but according to its 'To' and 'Cc' headers it was not\n"
                    "officially addressed to you.\n"
-                   "It is advised to not to send the return receipt."),
+                   "It is advised to not send the return receipt."),
                  _("_Don't Send"), _("_Send"), NULL, FALSE,
                  NULL, ALERT_WARNING, G_ALERTDEFAULT);
                if (val != G_ALERTALTERNATE)
@@ -923,7 +903,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        /* chmod for security */
        if (change_file_mode_rw(fp, tmp) < 0) {
                FILE_OP_ERROR(tmp, "chmod");
-               g_warning("can't change file mode\n");
+               g_warning("can't change file mode");
        }
        
        addr = g_strdup(to);
@@ -996,26 +976,13 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                goto FILE_ERROR;
 
        /* Message ID */
-       if (account->set_domain && account->domain) {
-               g_snprintf(buf, sizeof(buf), "%s", account->domain); 
-       } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
-               g_snprintf(buf, sizeof(buf), "%s", 
-                       strchr(account->address, '@') ?
-                               strchr(account->address, '@')+1 :
-                               account->address);
-       } else {
-               g_snprintf(buf, sizeof(buf), "%s", "");
-       }
-       
        if (account->gen_msgid) {
-               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)
+               gchar *addr = prefs_account_generate_msgid(account);
+               if (fprintf(fp, "Message-ID: <%s>\n", addr) < 0) {
+                       g_free(addr);
                        goto FILE_ERROR;
+               }
+               g_free(addr);
        }
 
        boundary = generate_mime_boundary("DN");
@@ -1056,6 +1023,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                        "\n"
                        "--%s\n"
                        "Content-Type: application/octet-stream\n"
+                       "\n"
                        "Reporting-UA: %s\n"
                        "Original-Recipient: rfc822;%s\n"
                        "Final-Recipient: rfc822;%s\n"
@@ -1099,13 +1067,13 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        queue = account_get_special_folder(account, F_QUEUE);
        if (!queue) queue = folder_get_default_queue();
        if (!queue) {
-               g_warning("can't find queue folder\n");
+               g_warning("can't find queue folder");
                claws_unlink(tmp);
                return -1;
        }
        folder_item_scan(queue);
        if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
-               g_warning("can't queue the message\n");
+               g_warning("can't queue the message");
                claws_unlink(tmp);
                return -1;
        }
@@ -1228,11 +1196,12 @@ static void messageview_register_nav(MessageView *messageview)
 }
 
 gboolean messageview_nav_has_prev(MessageView *messageview) {
-       return messageview->trail != NULL &&  messageview->trail_pos > 0;
+       return messageview != NULL && messageview->trail != NULL
+               && messageview->trail_pos > 0;
 }
 
 gboolean messageview_nav_has_next(MessageView *messageview) {
-       if (!messageview->trail)
+       if (!messageview || !messageview->trail)
                return FALSE;
        
        return sc_g_list_bigger(messageview->trail, messageview->trail_pos + 1);
@@ -1290,12 +1259,66 @@ MsgInfo *messageview_nav_get_next(MessageView *messageview) {
        return info;
 }
 
+static gboolean messageview_try_select_mimeinfo(MessageView *messageview, MsgInfo *msginfo, MimeInfo *mimeinfo)
+{
+       if (mimeinfo->type == MIMETYPE_TEXT) {
+               if (!strcasecmp(mimeinfo->subtype, "calendar")
+                               && mimeview_has_viewer_for_content_type(messageview->mimeview, "text/calendar")) {
+                       mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
+                       return TRUE;
+               } else if (!strcasecmp(mimeinfo->subtype, "html")
+                               && mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT
+                               && (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS
+                                       || (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT
+                                               && prefs_common.promote_html_part))) {
+                       mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
+                       return TRUE;
+               }
+       }
+       return FALSE;
+}
+
+static void messageview_find_part_depth_first(MimeInfoSearch *context, MimeMediaType type, const gchar *subtype)
+{
+       MimeInfo * mimeinfo = context->current;
+
+       if (!mimeinfo)
+               return;
+
+       debug_print("found part %d/%s\n", mimeinfo->type, mimeinfo->subtype);
+
+       if (mimeinfo->type == type
+                       && !strcasecmp(mimeinfo->subtype, subtype)) {
+               context->found = mimeinfo;
+       } else if (mimeinfo->type == MIMETYPE_MULTIPART) {
+               if (!strcasecmp(mimeinfo->subtype, "alternative")
+                               || !strcasecmp(mimeinfo->subtype, "related")) {
+                       context->found = procmime_mimeinfo_next(mimeinfo);
+                       while (context->found && context->found != context->parent) {
+                               if (context->found->type == type
+                                       && !strcasecmp(context->found->subtype, subtype))
+                                               break;
+                               context->found = procmime_mimeinfo_next(context->found);
+                       }
+                       if (context->found == context->parent)
+                               context->found = NULL;
+               }
+               if (!context->found
+                       && (!strcasecmp(mimeinfo->subtype, "related")
+                               || !strcasecmp(mimeinfo->subtype, "mixed"))) {
+                       context->parent = mimeinfo;
+                       context->current = procmime_mimeinfo_next(mimeinfo);
+                       messageview_find_part_depth_first(context, type, subtype);
+               }
+       }
+}
+
 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                      gboolean all_headers)
 {
        gchar *text = NULL;
        gchar *file;
-       MimeInfo *mimeinfo, *encinfo, *brokeninfo, *root;
+       MimeInfo *mimeinfo, *encinfo, *root;
        gchar *subject = NULL;
        cm_return_val_if_fail(msginfo != NULL, -1);
 
@@ -1346,7 +1369,7 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                statuswindow_pop_all();
 
        if (!file) {
-               g_warning("can't get message file path.\n");
+               g_warning("can't get message file path.");
                textview_show_error(messageview->mimeview->textview);
                return -1;
        }
@@ -1387,7 +1410,7 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
        }
                        
        if (messageview->msginfo != msginfo) {
-               procmsg_msginfo_free(messageview->msginfo);
+               procmsg_msginfo_free(&(messageview->msginfo));
                messageview->msginfo = NULL;
                messageview_set_menu_sensitive(messageview);
                messageview->msginfo = 
@@ -1399,14 +1422,12 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                messageview_set_menu_sensitive(messageview);
                messageview->msginfo = msginfo;
        }
-       headerview_show(messageview->headerview, messageview->msginfo);
+       if (prefs_common.display_header_pane)
+               headerview_show(messageview->headerview, messageview->msginfo);
 
        messageview_register_nav(messageview);
        messageview_set_position(messageview, 0);
 
-#ifdef MAEMO
-       maemo_window_full_screen_if_needed(GTK_WINDOW(messageview->window));
-#endif
        if (messageview->window) {
                gtk_window_set_title(GTK_WINDOW(messageview->window), 
                                _("Claws Mail - Message View"));
@@ -1452,7 +1473,7 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                return_receipt_show(messageview->noticeview, 
                                    messageview->msginfo);
 
-       if ((brokeninfo = find_broken_part(mimeinfo)) != NULL) {
+       if (find_broken_part(mimeinfo) != NULL) {
                noticeview_set_icon(messageview->noticeview,
                                    STOCK_PIXMAP_NOTICE_WARN);
                if (!noticeview_is_visible(messageview->noticeview)) {
@@ -1474,82 +1495,36 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
                        
        root = mimeinfo;
        mimeinfo = procmime_mimeinfo_next(mimeinfo);
-       if (!all_headers && mimeinfo 
-                       && (mimeinfo->type != MIMETYPE_TEXT || 
-           strcasecmp(mimeinfo->subtype, "plain")) 
-                       && (mimeinfo->type != MIMETYPE_MULTIPART || 
-           strcasecmp(mimeinfo->subtype, "signed"))) {
-               if (strcasecmp(mimeinfo->subtype, "html")) {
-                       MimeInfo *saved_mimeinfo = mimeinfo;
-                       MimeInfo *alt_parent = mimeinfo;
-
-                       /* if multipart/{related,mixed} part, look inside for a multipart/alternative child */
-                       if (mimeinfo->type == MIMETYPE_MULTIPART &&
-                           (!strcasecmp(mimeinfo->subtype, "related") ||
-                            !strcasecmp(mimeinfo->subtype, "mixed"))) {
-                               for (; mimeinfo; mimeinfo = procmime_mimeinfo_next(mimeinfo)) {
-                                       if (mimeinfo->node->parent != saved_mimeinfo->node) {
-                                               /* only consider children of the 
-                                                * multipart/{related,mixed} part */
-                                               continue;
-                                       }
-                                       if (mimeinfo->type == MIMETYPE_MULTIPART && 
-                                           !strcasecmp(mimeinfo->subtype, "alternative")) {
-                                               /* we got an alternative part */
-                                               alt_parent = mimeinfo;
-                                               break;
-                                       }
-                                       if (mimeinfo->type == MIMETYPE_TEXT && 
-                                           !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") &&
-                                           mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT &&
-                                                       (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS ||
-                                                        (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT &&
-                                                               prefs_common.promote_html_part))) {
-                                               mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
-                                               goto done;
-                                       }
-                               }
-                       }
-
-                       /* if we now have a multipart/alternative part (possibly inside a
-                        * multipart/{related,mixed} part, look for an HTML part inside */
-                       if (mimeinfo && mimeinfo->type == MIMETYPE_MULTIPART &&
-                           !strcasecmp(mimeinfo->subtype, "alternative")) {
-                               for (; mimeinfo; mimeinfo = procmime_mimeinfo_next(mimeinfo)) {
-                                       if (mimeinfo->node->parent != alt_parent->node) {
-                                               /* only consider children of the 
-                                                * multipart/alternative part, so as
-                                                * not to show html attachments */
-                                               continue;
-                                       }
-                                       
-                                       if (mimeinfo->type == MIMETYPE_TEXT && 
-                                           !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") &&
-                                           mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT &&
-                                                       (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS ||
-                                                        (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT &&
-                                                               prefs_common.promote_html_part))) {
-                                               mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
+       if (!all_headers && mimeinfo
+                       && (mimeinfo->type != MIMETYPE_TEXT
+                               || strcasecmp(mimeinfo->subtype, "plain"))
+                       && (mimeinfo->type != MIMETYPE_MULTIPART
+                               || strcasecmp(mimeinfo->subtype, "signed"))) {
+               if (strcasecmp(mimeinfo->subtype, "html")) {
+                       MimeInfoSearch context = {
+                               .parent = root,
+                               .current = mimeinfo,
+                               .found = NULL
+                       };
+                       if (mimeview_has_viewer_for_content_type(messageview->mimeview, "text/calendar")) {
+                               MimeInfoSearch cal_context = context;
+                               messageview_find_part_depth_first(&cal_context, MIMETYPE_TEXT, "calendar");
+                               if (cal_context.found) { /* calendar found */
+                                       mimeinfo = cal_context.found;
+                                       if (messageview_try_select_mimeinfo(messageview, msginfo, mimeinfo))
                                                goto done;
-                                       }
                                }
                        }
-                       
-                       /* if we didn't find anything, go back to start */
-                       if (!mimeinfo) 
-                               mimeinfo = saved_mimeinfo;
+                       messageview_find_part_depth_first(&context, MIMETYPE_TEXT, "html");
+                       if (context.found &&
+                           (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS ||
+                            (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT &&
+                             prefs_common.promote_html_part))) { /* html found */
+                               mimeinfo = context.found;
+                               if (messageview_try_select_mimeinfo(messageview, msginfo, mimeinfo))
+                                       goto done;
+                       } else
+                               mimeinfo = root; /* nothing found */
 
                        if (!mimeview_show_part(messageview->mimeview, mimeinfo))
                                mimeview_select_mimepart_icon(messageview->mimeview, root);
@@ -1575,6 +1550,7 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
 
        mimeview_select_mimepart_icon(messageview->mimeview, root);
 done:
+       messageview_set_menu_sensitive(messageview);
        /* plugins may hook in here to work with the message view */
        hooks_invoke(MESSAGE_VIEW_SHOW_DONE_HOOKLIST, messageview);
 
@@ -1599,7 +1575,7 @@ void messageview_clear(MessageView *messageview)
 {
        if (!messageview)
                return;
-       procmsg_msginfo_free(messageview->msginfo);
+       procmsg_msginfo_free(&(messageview->msginfo));
        messageview->msginfo = NULL;
        messageview->filtered = FALSE;
 
@@ -1651,7 +1627,7 @@ void messageview_destroy(MessageView *messageview)
        mimeview_destroy(messageview->mimeview);
        noticeview_destroy(messageview->noticeview);
 
-       procmsg_msginfo_free(messageview->msginfo);
+       procmsg_msginfo_free(&(messageview->msginfo));
        toolbar_clear_list(TOOLBAR_MSGVIEW);
        if (messageview->toolbar) {
                toolbar_destroy(messageview->toolbar);
@@ -1894,7 +1870,7 @@ static void messageview_size_allocate_cb(GtkWidget *widget,
        prefs_common.msgwin_width  = allocation->width;
        prefs_common.msgwin_height = allocation->height;
 }
-#ifndef MAEMO
+
 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
                        MessageView *messageview)
 {
@@ -1910,7 +1886,6 @@ static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
 
        return mimeview_pass_key_press_event(messageview->mimeview, event);
 }
-#endif
 
 static void messageview_show_partial_display_cb(NoticeView *noticeview, MessageView *messageview)
 {
@@ -1959,7 +1934,7 @@ static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
        if (from_me) {
                noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
                if (MSG_IS_RETRCPT_GOT(msginfo->flags)) {
-                       noticeview_set_text(noticeview, _("You got a return receipt for this message : "
+                       noticeview_set_text(noticeview, _("You got a return receipt for this message: "
                                                          "it has been displayed by the recipient."));
                } else {
                        noticeview_set_text(noticeview, _("You asked for a return receipt in this message."));
@@ -1984,7 +1959,7 @@ static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo
 
        file = procmsg_get_message_file_path(msginfo);
        if (!file) {
-               g_warning("can't get message file path.\n");
+               g_warning("can't get message file path.");
                return;
        }
 
@@ -1997,7 +1972,7 @@ static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo
                noticeview_hide(noticeview);
        }               
 
-       procmsg_msginfo_free(tmpmsginfo);
+       procmsg_msginfo_free(&tmpmsginfo);
        g_free(file);
 }
 
@@ -2113,9 +2088,9 @@ static PrefsAccount *select_account_from_list(GList *ac_list)
        account_id = ((PrefsAccount *) ac_list->data)->account_id;
        if (alertpanel_with_widget(
                                _("Return Receipt Notification"),
-                               _("The message was sent to several of your "
-                                 "accounts.\n"
-                                 "Please choose which account do you want to "
+                               _("More than one of your accounts uses the "
+                                 "address that this message was sent to.\n"
+                                 "Please choose which account you want to "
                                  "use for sending the receipt notification:"),
                                _("_Cancel"), _("_Send Notification"), NULL,
                                FALSE, G_ALERTDEFAULT, optmenu) != G_ALERTALTERNATE)
@@ -2138,6 +2113,8 @@ gchar *messageview_get_selection(MessageView *msgview)
        GtkTextView *edit = NULL;
        GtkTextBuffer *textbuf;
        gint body_pos = 0;
+       GtkTextIter start_iter, end_iter;
+       GtkTextMark *body_start, *body_end;
        
        cm_return_val_if_fail(msgview != NULL, NULL);
 
@@ -2159,15 +2136,35 @@ gchar *messageview_get_selection(MessageView *msgview)
 
        textbuf = gtk_text_view_get_buffer(edit);
 
-       if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL))
+       if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL)) {
                return gtkut_text_view_get_selection(edit);
-       else if (msgview->filtered) {
-               GtkTextIter start_iter, end_iter;
-               gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
-               gtk_text_buffer_get_end_iter(textbuf, &end_iter);
-               gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
-       } else
-               text = NULL;
+       } else {
+               if (msgview->filtered) {
+                       gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
+                       gtk_text_buffer_get_end_iter(textbuf, &end_iter);
+               } else {
+                       body_start = gtk_text_buffer_get_mark(textbuf, "body_start");
+
+                       /* If there is no body_start mark, an attachment is likely
+                        * selected, and we're looking at instructions on what to do
+                        * with it. No point in quoting that, so we'll just return NULL,
+                        * so that original message body is quoted instead down the line.
+                        */
+                       if (body_start == NULL) {
+                               return NULL;
+                       }
+
+                       gtk_text_buffer_get_iter_at_mark(textbuf, &start_iter, body_start);
+
+                       body_end = gtk_text_buffer_get_mark(textbuf, "body_end");
+                       if (body_end != NULL) /* Just in case */
+                               gtk_text_buffer_get_iter_at_mark(textbuf, &end_iter, body_end);
+                       else
+                               gtk_text_buffer_get_end_iter(textbuf, &end_iter);
+               }
+
+               return gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
+       }
 
        return text;
 }
@@ -2211,7 +2208,10 @@ static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gin
                mainwin = mainwindow_get_mainwindow();
                printing_print(GTK_TEXT_VIEW(mimeview->textview->text),
                               mainwin ? GTK_WINDOW(mainwin->window) : NULL,
-                               sel_start, sel_end);
+                               sel_start, sel_end,
+                               (mimeview->textview->image 
+                                       ? GTK_IMAGE(mimeview->textview->image)
+                                       : NULL));
        }
 }
 
@@ -2293,7 +2293,7 @@ static void prev_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
        messageview->updating = TRUE;
-       summary_step(messageview->mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
+       summary_select_prev(messageview->mainwin->summaryview);
        messageview->updating = FALSE;
 
        if (messageview->deferred_destroy) {
@@ -2318,7 +2318,7 @@ static void next_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
        messageview->updating = TRUE;
-       summary_step(messageview->mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
+       summary_select_next(messageview->mainwin->summaryview);
        messageview->updating = FALSE;
 
        if (messageview->deferred_destroy) {
@@ -2548,7 +2548,7 @@ static void prev_history_cb(GtkAction *action, gpointer data)
                messageview_show(messageview, info, 
                                         messageview->all_headers);
                messageview->updating = FALSE;
-               procmsg_msginfo_free(info);
+               procmsg_msginfo_free(&info);
                if (messageview->deferred_destroy) {
                        debug_print("messageview got away!\n");
                        messageview_destroy(messageview);
@@ -2566,7 +2566,7 @@ static void next_history_cb(GtkAction *action, gpointer data)
                messageview_show(messageview, info, 
                                         messageview->all_headers);
                messageview->updating = FALSE;
-               procmsg_msginfo_free(info);
+               procmsg_msginfo_free(&info);
                if (messageview->deferred_destroy) {
                        debug_print("messageview got away!\n");
                        messageview_destroy(messageview);
@@ -2603,8 +2603,9 @@ static void parent_cb(GtkAction *action, gpointer data)
 static void goto_unread_folder_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
+
        messageview->updating = TRUE;
-       folderview_select_next_unread(messageview->mainwin->folderview, FALSE);
+       folderview_select_next_with_flag(messageview->mainwin->folderview, MSG_UNREAD);
        messageview->updating = FALSE;
 
        if (messageview->deferred_destroy) {
@@ -2628,9 +2629,7 @@ static void goto_unread_folder_cb(GtkAction *action, gpointer data)
 static void goto_folder_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
-       messageview->updating = TRUE;
        FolderItem *to_folder;
-       messageview->updating = FALSE;
 
        to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL, FALSE);
 
@@ -2741,7 +2740,7 @@ static void show_all_header_cb(GtkToggleAction *action, gpointer data)
        if (!msginfo) return;
        messageview->msginfo = NULL;
        messageview_show(messageview, msginfo, messageview->all_headers);
-       procmsg_msginfo_free(msginfo);
+       procmsg_msginfo_free(&msginfo);
        main_window_set_menu_sensitive(messageview->mainwin);
        summary_redisplay_msg(messageview->mainwin->summaryview);
 }
@@ -2773,7 +2772,7 @@ static void msg_hide_quotes_cb(GtkToggleAction *action, gpointer data)
        messageview->msginfo = NULL;
        messageview_show(messageview, msginfo,
                         messageview->all_headers);
-       procmsg_msginfo_free(msginfo);
+       procmsg_msginfo_free(&msginfo);
        
        /* update main window */
        main_window_set_menu_sensitive(messageview->mainwin);
@@ -2828,15 +2827,14 @@ static void reply_cb(GtkAction *gaction, gpointer data)
 
 static void addressbook_open_cb(GtkAction *action, gpointer data)
 {
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        addressbook_open(NULL);
 #else
        GError* error = NULL;
        
        addressbook_dbus_open(FALSE, &error);
        if (error) {
-               g_warning("Failed to open address book");
-               g_warning("%s", error->message);
+               g_warning("Failed to open address book: %s", error->message);
                g_error_free(error);
        }
 #endif
@@ -2847,8 +2845,8 @@ static void add_address_cb(GtkAction *action, gpointer data)
        MessageView *messageview = (MessageView *)data;
        MsgInfo *msginfo, *full_msginfo;
        gchar *from;
-       GtkWidget *image = NULL;
        GdkPixbuf *picture = NULL;
+       AvatarRender *avatarr;
 
        if (!messageview->msginfo || !messageview->msginfo->from) 
                return;
@@ -2859,33 +2857,23 @@ static void add_address_cb(GtkAction *action, gpointer data)
        extract_address(from);
        
        full_msginfo = procmsg_msginfo_get_full_info(msginfo);
-       if (full_msginfo &&
-           full_msginfo->extradata &&
-           full_msginfo->extradata->face) {
-               image = face_get_from_header(full_msginfo->extradata->face);
-       } 
-#if HAVE_LIBCOMPFACE
-       else if (full_msginfo &&
-                full_msginfo->extradata &&
-                full_msginfo->extradata->xface) {
-               image = xface_get_from_header(full_msginfo->extradata->xface,
-                               &(gtk_widget_get_style(messageview->mainwin->summaryview->ctree)->white),
-                               gtk_widget_get_window(messageview->window));
-       }
-#endif
-       procmsg_msginfo_free(full_msginfo);
-       if (image)
-               picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
 
-#ifndef USE_NEW_ADDRBOOK
+       avatarr = avatars_avatarrender_new(full_msginfo);
+       hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
+
+       procmsg_msginfo_free(&full_msginfo);
+
+       if (avatarr->image != NULL)
+               picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
+
+#ifndef USE_ALT_ADDRBOOK
        addressbook_add_contact(msginfo->fromname, from, NULL, picture);
 #else
        if (addressadd_selection(msginfo->fromname, from, NULL, picture)) {
                debug_print( "addressbook_add_contact - added\n" );
        }
 #endif
-       if (image)
-               gtk_widget_destroy(image);
+       avatars_avatarrender_free(avatarr);
 }
 
 static void create_filter_cb(GtkAction *gaction, gpointer data)
@@ -2962,7 +2950,7 @@ static gboolean messageview_update_msg(gpointer source, gpointer data)
                                textview_show_info(messageview->mimeview->textview,
                                        MSG_IS_DELETED(old_msginfo->flags) ?
                                        _("\n  Message has been deleted") :
-                                       _("\n  Message has been moved to trash"));
+                                       _("\n  Message has been deleted or moved to another folder"));
                        } else
                                messageview->update_needed = TRUE;
 
@@ -2977,10 +2965,8 @@ static gboolean messageview_update_msg(gpointer source, gpointer data)
 
 void messageview_set_menu_sensitive(MessageView *messageview)
 {
-       if (!messageview || !messageview->new_window) 
+       if (!messageview || !messageview->ui_manager)
                return;
-       /* do some smart things */
-       if (!messageview->menubar) return;
 
        cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/CollapseAll", (prefs_common.hide_quotes == 1));
        cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/Collapse2", (prefs_common.hide_quotes == 2));