2006-08-21 [colin] 2.4.0cvs67
[claws.git] / src / mainwindow.c
index 80e37d13790843a8185dec922007ddeb2fe174e1..d974cca8648968ba121560d91435b200ffe278f6 100644 (file)
@@ -94,6 +94,8 @@
 #include "icon_legend.h"
 #include "colorlabel.h"
 #include "textview.h"
+#include "imap.h"
+#include "socket.h"
 
 #define AC_LABEL_WIDTH 240
 
@@ -216,6 +218,10 @@ static void show_all_header_cb             (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
 
+static void hide_quotes_cb(MainWindow  *mainwin,
+                                        guint           action,
+                                        GtkWidget      *widget);
+
 static void move_to_cb                 (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -346,10 +352,19 @@ static void prev_labeled_cb        (MainWindow    *mainwin,
 static void next_labeled_cb     (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void last_read_cb        (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
+static void parent_cb           (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
 
 static void goto_folder_cb      (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void goto_unread_folder_cb(MainWindow   *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
 
 static void copy_cb             (MainWindow    *mainwin,
                                  guint          action,
@@ -402,6 +417,8 @@ static void account_selector_menu_cb         (GtkMenuItem   *menuitem,
                                          gpointer       data);
 static void account_receive_menu_cb     (GtkMenuItem   *menuitem,
                                          gpointer       data);
+static void account_compose_menu_cb     (GtkMenuItem   *menuitem,
+                                         gpointer       data);
 
 static void prefs_open_cb      (GtkMenuItem    *menuitem,
                                 gpointer        data);
@@ -443,6 +460,17 @@ void main_window_reply_cb                  (MainWindow     *mainwin,
                                                 GtkWidget      *widget);
 gboolean mainwindow_progressindicator_hook     (gpointer        source,
                                                 gpointer        userdata);
+
+static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
+                                      MsgInfo *msginfo);
+
+static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
+       
+static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
+
+static void mailing_list_compose(GtkWidget *w, gpointer *data);
+static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
 #define  SEPARATE_ACTION 500 
 static void mainwindow_quicksearch             (MainWindow     *mainwin, 
                                                 guint           action, 
@@ -559,7 +587,13 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_View/_Go to/Next la_beled message"),
                                                NULL, next_labeled_cb, 0, NULL},
        {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
-       {N_("/_View/_Go to/Other _folder..."),  "G", goto_folder_cb, 0, NULL},
+       {N_("/_View/_Go to/Last read message"),
+                                               NULL, last_read_cb, 0, NULL},
+       {N_("/_View/_Go to/Parent message"),
+                                               "<control>Up", parent_cb, 0, NULL},
+       {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
+       {N_("/_View/_Go to/Next unread _folder"),       "<shift>G", goto_unread_folder_cb, 0, NULL},
+       {N_("/_View/_Go to/_Other folder..."),  "G", goto_folder_cb, 0, NULL},
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
 
 #define ENC_SEPARATOR \
@@ -681,6 +715,10 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
        {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
        {N_("/_View/Show all headers"),         "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
+       {N_("/_View/Quotes"),                   NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Quotes/_Fold all"),         "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
+       {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
+       {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
 
@@ -708,6 +746,15 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Message/_Forward"),              "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
        {N_("/_Message/For_ward as attachment"),        NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
        {N_("/_Message/Redirect"),              NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
+
+       {N_("/_Message/Mailing-_List"),                 NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Post"),            NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Help"),            NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Subscribe"),       NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Unsubscribe"),     NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/View archive"),    NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Contact owner"),   NULL, NULL, 0, "<Branch>"},
+       
        {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
        {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
@@ -814,6 +861,7 @@ static GtkItemFactoryEntry mainwin_entries[] =
 };
 
 static gboolean offline_ask_sync = TRUE;
+static guint lastkey;
 
 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
                                             GObject *arg1,
@@ -827,7 +875,7 @@ static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
            mainwin->summaryview->quicksearch &&
            quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
            (mod == 0 || mod == GDK_SHIFT_MASK)) {
-               quicksearch_pass_key(mainwin->summaryview->quicksearch, value, mod);
+               quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
                return TRUE;
        }
        return FALSE;
@@ -1051,6 +1099,9 @@ MainWindow *main_window_create(SeparateType type)
        gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
        ifactory = gtk_item_factory_from_widget(menubar);
 
+/*     gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
+       main_create_mailing_list_menu (mainwin, NULL); */
+
        menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
 
        if (prefs_common.toolbar_detachable) {
@@ -1259,6 +1310,8 @@ MainWindow *main_window_create(SeparateType type)
        /* create actions menu */
        main_window_update_actions_menu(mainwin);
 
+       main_create_mailing_list_menu (mainwin, NULL);
+
        /* attach accel groups to main window */
 #define        ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
        gtk_window_add_accel_group                                      \
@@ -1441,6 +1494,11 @@ static gboolean reflect_prefs_timeout_cb(gpointer data)
        return FALSE;
 }
 
+void main_window_reflect_prefs_all_now(void)
+{
+       reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
+}
+
 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
 {
        GtkMenuShell *menu;
@@ -1595,6 +1653,42 @@ static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
        }
 }
 
+static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
+                                                      GList *account_list)
+{
+       GList *cur_ac, *cur_item;
+       GtkWidget *menuitem;
+       PrefsAccount *ac_prefs;
+       GtkWidget *menu = NULL;
+
+       if (mainwin->toolbar->compose_mail_btn == NULL
+       ||  mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
+               return;
+
+       menu = mainwin->toolbar->compose_combo->menu;
+
+       /* destroy all previous menu item */
+       cur_item = GTK_MENU_SHELL(menu)->children;
+       while (cur_item != NULL) {
+               GList *next = cur_item->next;
+               gtk_widget_destroy(GTK_WIDGET(cur_item->data));
+               cur_item = next;
+       }
+
+       for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
+               ac_prefs = (PrefsAccount *)cur_ac->data;
+
+               menuitem = gtk_menu_item_new_with_label
+                       (ac_prefs->account_name
+                        ? ac_prefs->account_name : _("Untitled"));
+               gtk_widget_show(menuitem);
+               gtk_menu_append(GTK_MENU(menu), menuitem);
+               g_signal_connect(G_OBJECT(menuitem), "activate",
+                                G_CALLBACK(account_compose_menu_cb),
+                                ac_prefs);
+       }
+}
+
 void main_window_set_account_menu(GList *account_list)
 {
        GList *cur;
@@ -1605,6 +1699,7 @@ void main_window_set_account_menu(GList *account_list)
                main_window_set_account_selector_menu(mainwin, account_list);
                main_window_set_account_receive_menu(mainwin, account_list);
                main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
+               main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
        }
 }
 
@@ -1616,6 +1711,7 @@ void main_window_set_account_menu_only_toolbar(GList *account_list)
        for (cur = mainwin_list; cur != NULL; cur = cur->next) {
                mainwin = (MainWindow *)cur->data;
                main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
+               main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
        }
 }
 
@@ -1882,8 +1978,7 @@ void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
        g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
-                               (cur == 0 && total == 0) ? 0 :
-                               (gfloat)cur / (gfloat)total);
+                               (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
 }
 
 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
@@ -1962,7 +2057,7 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
 
                if ((selection == SUMMARY_NONE && item->hide_read_msgs)
                    || selection != SUMMARY_NONE)
-                       state |= M_HIDE_READ_MSG;       
+                       state |= M_HIDE_READ_MSG;
        }               
        if (mainwin->summaryview->threaded)
                state |= M_THREADED;
@@ -1978,6 +2073,12 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
                state |= M_NEWS;
        else
                state |= M_NOT_NEWS;
+       if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
+               state |= M_ACTIONS_EXIST;
+
+       if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
+               state |= M_HAVE_QUEUED_MAILS;
+
        if (selection == SUMMARY_SELECTED_SINGLE &&
            (item &&
             (folder_has_parent_of_type(item, F_DRAFT) ||
@@ -2043,11 +2144,13 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                {"/View/Go to/Previous unread message" , M_MSG_EXIST},
                {"/View/Go to/Previous new message"    , M_MSG_EXIST},
                {"/View/Go to/Previous marked message" , M_MSG_EXIST},
-               {"/View/Go to/Next marked message" , M_MSG_EXIST},
                {"/View/Go to/Previous labeled message", M_MSG_EXIST},
                {"/View/Go to/Next labeled message", M_MSG_EXIST},
+               {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
+               {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
                {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
                {"/View/Show all headers"          , M_SINGLE_TARGET_EXIST},
+               {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
                {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
 
                {"/Message/Receive/Get from current account"
@@ -2056,14 +2159,14 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                                                 , M_HAVE_ACCOUNT|M_UNLOCKED},
                {"/Message/Receive/Cancel receiving"
                                                 , M_INC_ACTIVE},
-
+               {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
                {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
-               {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
-               {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
-               {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
+               {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
+               {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
+               {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
                {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
                {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
-               {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
+               {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
                {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
                {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
                {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
@@ -2083,7 +2186,7 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
                {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
                {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
-               {"/Tools/Actions"                      , M_TARGET_EXIST},
+               {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
                {"/Tools/Execute"                      , M_DELAY_EXEC},
                {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
 
@@ -2180,12 +2283,202 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                SET_CHECK_MENU_ACTIVE("/View/Show all headers",
                              mainwin->messageview->mimeview->textview->show_all_headers);
        SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
+       if (prefs_common.hide_quotes == 1)
+               SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
+       if (prefs_common.hide_quotes == 2)
+               SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
+       if (prefs_common.hide_quotes == 3)
+               SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
 
 #undef SET_CHECK_MENU_ACTIVE
 
        main_window_menu_callback_unblock(mainwin);
 }
 
+void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
+{
+       GtkItemFactory *ifactory;
+       gint is_menu = 0;
+       ifactory = gtk_item_factory_from_widget(mainwin->menubar);
+       
+       if (msginfo) 
+               is_menu = mailing_list_create_submenu (ifactory, msginfo);
+       if (is_menu)
+               gtk_widget_set_sensitive (gtk_item_factory_get_item
+                               (ifactory,"/Message/Mailing-List"), TRUE);
+       else
+               gtk_widget_set_sensitive (gtk_item_factory_get_item
+                               (ifactory,"/Message/Mailing-List"), FALSE);
+}
+
+static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
+{
+       gint menu_nb = 0;
+       GtkWidget *menuitem;
+
+       /* Mailing list post */
+       if (msginfo && !strcmp2 (msginfo->list_post, "NO")) {
+               msginfo->list_post = g_strdup (_("No posting allowed"));
+       }
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
+               
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_post);
+       /* Mailing list help */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_help);
+
+       /* Mailing list subscribe */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_subscribe);
+               
+       /* Mailing list unsubscribe */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_unsubscribe);
+       
+       /* Mailing list view archive */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_archive);
+       
+       /* Mailing list contact owner */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_owner);
+       
+       return menu_nb;
+}
+
+static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
+{
+       GtkWidget *item, *menu;
+       const gchar *url_pt ;
+       gchar url_decoded[BUFFSIZE];
+       GList *amenu, *alist;
+       gint menu_nb = 0;
+       
+       menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
+       
+       /* First delete old submenu */
+       /* FIXME: we can optimize this, and only change/add/delete necessary items */
+       for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
+               alist = amenu->next;
+               item = GTK_WIDGET (amenu->data);
+               gtk_widget_destroy (item);
+               amenu = alist;
+       }
+       if (list_header) {
+               for (url_pt = list_header; url_pt && *url_pt;) {
+                       get_url_part (&url_pt, url_decoded, BUFFSIZE);
+                       item = NULL;
+                       if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
+                               item = gtk_menu_item_new_with_label ((url_decoded));
+                               gtk_signal_connect (GTK_OBJECT(item), "activate",
+                                               GTK_SIGNAL_FUNC(mailing_list_compose), NULL);
+                       }
+                       else if (!g_strncasecmp (url_decoded, "http:", 5) ||
+                                !g_strncasecmp (url_decoded, "https:",6)) {
+
+                               item = gtk_menu_item_new_with_label ((url_decoded));
+                               gtk_signal_connect (GTK_OBJECT(item), "activate",
+                                               GTK_SIGNAL_FUNC(mailing_list_open_uri), NULL);
+                       } 
+                       if (item) {
+                               gtk_menu_append (GTK_MENU(menu), item);
+                               gtk_widget_show (item);
+                               menu_nb++;
+                       }
+               }
+       }
+       if (menu_nb)
+               gtk_widget_set_sensitive (menuitem, TRUE);
+       else
+               gtk_widget_set_sensitive (menuitem, FALSE);
+               
+
+       return menu_nb;
+}
+
+static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
+{
+       gchar tmp[BUFFSIZE];
+       const gchar *buf;
+       gint i = 0;
+       buf = *buffer;
+       
+       if (buf == 0x00) {
+               *url_decoded = '\0';
+               *buffer = NULL;
+               return;
+       }
+       /* Ignore spaces, comments  and tabs () */
+       for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
+               if (*buf == '(')
+                       for (;*buf != ')' && *buf != 0x00; buf++);
+       
+       /* First non space and non comment must be a < */
+       if (*buf =='<' ) {
+               buf++;
+               for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
+               buf++;
+       }
+       else  {
+               *buffer = NULL;
+               *url_decoded = '\0';
+               return;
+       }
+       
+       tmp[i]       = 0x00;
+       *url_decoded = '\0';
+       *buffer = NULL;
+       
+       if (i == maxlen) {
+               return;
+       }
+       decode_uri (url_decoded, (const gchar *)tmp);
+
+       /* Prepare the work for the next url in the list */
+       /* after the closing bracket >, ignore space, comments and tabs */
+       for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
+               if (*buf == '(')
+                       for (;*buf != ')' && *buf != 0x00; buf++);
+                       
+       if (!buf || !*buf) {
+               *buffer = NULL;
+               return;
+       }
+
+       /* now first non space, non comment must be a comma */
+       if (*buf != ',')
+               for (;*buf != 0x00; buf++);
+       else
+               buf++;
+       *buffer = buf;
+}
+       
+static void mailing_list_compose (GtkWidget *w, gpointer *data)
+{
+       gchar *mailto;
+
+       gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
+       compose_new(NULL, mailto+7, NULL);
+}
+ static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
+{
+       gchar *mailto;
+       gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
+       open_uri (mailto, prefs_common.uri_cmd);
+} 
+       
 void main_window_popup(MainWindow *mainwin)
 {
        gtkut_window_popup(mainwin->window);
@@ -2435,6 +2728,10 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
                                  mainwin->messageview->handlebox, 
                                  prefs_common.toolbar_style);
 
+               /* remove headerview if not in prefs */
+               headerview_set_visibility(mainwin->messageview->headerview,
+                                         prefs_common.display_header_pane);
+
                break;
        case SEPARATE_BOTH:
                messageview_add_toolbar(mainwin->messageview, messagewin);
@@ -2455,6 +2752,10 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
                                  mainwin->messageview->handlebox, 
                                  prefs_common.toolbar_style);          
 
+               /* remove headerview if not in prefs */
+               headerview_set_visibility(mainwin->messageview->headerview,
+                                         prefs_common.display_header_pane);
+
                break;
        }
 
@@ -2666,19 +2967,28 @@ static void foldersort_cb(MainWindow *mainwin, guint action,
 static void import_mbox_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
-       import_mbox(mainwin->summaryview->folder_item);
+       /* only notify if import has failed */
+       if (import_mbox(mainwin->summaryview->folder_item) == -1) {
+               alertpanel_error(_("Mbox import has failed."));
+       }
 }
 
 static void export_mbox_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
-       export_mbox(mainwin->summaryview->folder_item);
+       /* only notify if export has failed */
+       if (export_mbox(mainwin->summaryview->folder_item) == -1) {
+               alertpanel_error(_("Export to mbox has failed."));
+       }
 }
 
 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
                                GtkWidget *widget)
 {
-       summaryview_export_mbox_list(mainwin->summaryview);
+       /* only notify if export has failed */
+       if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
+               alertpanel_error(_("Export to mbox has failed."));
+       }
 }
 
 static void empty_trash_cb(MainWindow *mainwin, guint action,
@@ -2869,20 +3179,27 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
        g_return_if_fail(menuitem != NULL);
        
        if (btn == GTK_BUTTON(mainwin->online_switch)) {
-               /* go offline */
-               mainwindow_check_synchronise(mainwin, TRUE);
                gtk_widget_hide (mainwin->online_switch);
                gtk_widget_show (mainwin->offline_switch);
                menuitem->active = TRUE;
+               inc_autocheck_timer_remove();
+                       
+               /* go offline */
+               if (prefs_common.work_offline)
+                       return;
+               mainwindow_check_synchronise(mainwin, TRUE);
                prefs_common.work_offline = TRUE;
-               inc_autocheck_timer_remove();           
+               imap_disconnect_all();
        } else {
                /*go online */
+               if (!prefs_common.work_offline)
+                       return;
                gtk_widget_hide (mainwin->offline_switch);
                gtk_widget_show (mainwin->online_switch);
                menuitem->active = FALSE;
                prefs_common.work_offline = FALSE;
                inc_autocheck_timer_set();
+               refresh_resolvers();
        }
 }
 
@@ -2949,6 +3266,34 @@ static void show_all_header_cb(MainWindow *mainwin, guint action,
                                     GTK_CHECK_MENU_ITEM(widget)->active);
 }
 
+#define SET_CHECK_MENU_ACTIVE(path, active) \
+{ \
+       menuitem = gtk_item_factory_get_widget(ifactory, path); \
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
+}
+
+static void hide_quotes_cb(MainWindow *mainwin, guint action,
+                              GtkWidget *widget)
+{
+       GtkWidget *menuitem;
+       GtkItemFactory *ifactory = mainwin->menu_factory;
+
+       if (mainwin->menu_lock_count) return;
+
+       prefs_common.hide_quotes = 
+                       GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
+
+       mainwin->menu_lock_count++;
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
+       mainwin->menu_lock_count--;
+
+       summary_redisplay_msg(mainwin->summaryview);
+}
+
+#undef SET_CHECK_MENU_ACTIVE
 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        summary_mark(mainwin->summaryview);
@@ -3243,6 +3588,18 @@ static void next_labeled_cb(MainWindow *mainwin, guint action,
        summary_select_next_labeled(mainwin->summaryview);
 }
 
+static void last_read_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_select_last_read(mainwin->summaryview);
+}
+
+static void parent_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_select_parent(mainwin->summaryview);
+}
+
 static void goto_folder_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
@@ -3254,6 +3611,12 @@ static void goto_folder_cb(MainWindow *mainwin, guint action,
                folderview_select(mainwin->folderview, to_folder);
 }
 
+static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
+                          GtkWidget *widget)
+{
+       folderview_select_next_unread(mainwin->folderview);
+}
+
 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        messageview_copy_clipboard(mainwin->messageview);
@@ -3263,11 +3626,11 @@ static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        MessageView *msgview = mainwin->messageview;
 
-       if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
-               summary_select_all(mainwin->summaryview);
-       else if (messageview_is_visible(msgview) &&
+       if (messageview_is_visible(msgview) &&
                 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
                messageview_select_all(mainwin->messageview);
+       else
+               summary_select_all(mainwin->summaryview);
 }
 
 static void select_thread_cb(MainWindow *mainwin, guint action,
@@ -3293,7 +3656,8 @@ static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
 {
        prefs_filtering_open(&pre_global_processing,
                             _("Processing rules to apply before folder rules"),
-                            NULL, NULL);
+                            MANUAL_ANCHOR_PROCESSING,
+                            NULL, NULL, FALSE);
 }
 
 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
@@ -3301,7 +3665,8 @@ static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
 {
        prefs_filtering_open(&post_global_processing,
                             _("Processing rules to apply after folder rules"),
-                            NULL, NULL);
+                            MANUAL_ANCHOR_PROCESSING,
+                            NULL, NULL, FALSE);
 }
 
 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
@@ -3309,7 +3674,8 @@ static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
 {
        prefs_filtering_open(&filtering_rules,
                             _("Filtering configuration"),
-                            NULL, NULL);
+                            MANUAL_ANCHOR_FILTERING,
+                            NULL, NULL, TRUE);
 }
 
 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
@@ -3376,6 +3742,15 @@ static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
        inc_account_mail(mainwin, account);
 }
 
+static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)mainwin_list->data;
+       PrefsAccount *account = (PrefsAccount *)data;
+       FolderItem *item = mainwin->summaryview->folder_item;   
+
+       compose_new_with_folderitem(account, item);
+}
+
 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
 {
        prefs_gtk_open();
@@ -3389,7 +3764,7 @@ static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
 static void manual_open_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
-       manual_open((ManualType)action);
+       manual_open((ManualType)action, NULL);
 }
 
 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
@@ -3422,6 +3797,8 @@ static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focu
        SummaryView *summary;
 
        g_return_val_if_fail(data, FALSE);
+       if (!g_list_find(mainwin_list, data))
+               return TRUE;
        summary = ((MainWindow *)data)->summaryview;
        g_return_val_if_fail(summary, FALSE);
 
@@ -3444,7 +3821,10 @@ gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                return FALSE;
 
        if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
+       {
+               lastkey = event->keyval;
                return FALSE;
+       }
 
        switch (event->keyval) {
        case GDK_Q:             /* Quit */
@@ -3454,10 +3834,13 @@ gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                return FALSE;
        case GDK_space:
                if (mainwin->folderview && mainwin->summaryview
-                   && !mainwin->summaryview->displayed) {
-                       summary_lock(mainwin->summaryview);
+                   && ((!mainwin->summaryview->displayed
+                       && !mainwin->summaryview->selected) 
+                       || (mainwin->summaryview->folder_item
+                           && mainwin->summaryview->folder_item->total_msgs == 0))) {
+                       g_signal_stop_emission_by_name(G_OBJECT(widget), 
+                                       "key_press_event");
                        folderview_select_next_unread(mainwin->folderview);
-                       summary_unlock(mainwin->summaryview);
                }
                break;
        default:
@@ -3531,3 +3914,56 @@ void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
 {
        summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
 }
+
+void mainwindow_jump_to(const gchar *target)
+{
+       gchar *tmp = NULL;
+       gchar *p = NULL;
+       FolderItem *item = NULL;
+       gchar *msg = NULL;
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       
+       if (!target)
+               return;
+               
+       if (!mainwin) {
+               printf(_("not initialized\n"));
+               return;
+       }
+
+       tmp = g_strdup(target);
+       
+       if ((p = strstr(tmp, "\r")) != NULL)
+               *p = '\0';
+       if ((p = strstr(tmp, "\n")) != NULL)
+               *p = '\0';
+
+       if ((item = folder_find_item_from_identifier(tmp))) {
+               printf(_("selecting folder '%s'\n"), tmp);
+               folderview_select(mainwin->folderview, item);
+               main_window_popup(mainwin);
+               g_free(tmp);
+               return;
+       }
+       
+       msg = strrchr(tmp, G_DIR_SEPARATOR);
+       if (msg) {
+               *msg++ = '\0';
+               if ((item = folder_find_item_from_identifier(tmp))) {
+                       printf(_("selecting folder '%s'\n"), tmp);
+                       folderview_select(mainwin->folderview, item);
+               } 
+               if (item && msg && atoi(msg)) {
+                       printf(_("selecting message %d\n"), atoi(msg));
+                       summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
+                       summary_display_msg_selected(mainwin->summaryview, FALSE);
+                       main_window_popup(mainwin);
+                       g_free(tmp);
+                       return;
+               } 
+       }
+       
+       printf("'%s' not found\n", tmp);
+       
+       g_free(tmp);
+}