2006-07-04 [colin] 2.3.1cvs57
[claws.git] / src / mainwindow.c
index e0e8e8825d1f65f2aed7037ba600fe7a5a09a5ae..945d962a70876562a5f0d9af80cbc56df1c3bbd1 100644 (file)
@@ -94,6 +94,7 @@
 #include "icon_legend.h"
 #include "colorlabel.h"
 #include "textview.h"
+#include "imap.h"
 
 #define AC_LABEL_WIDTH 240
 
@@ -350,6 +351,9 @@ static void next_labeled_cb  (MainWindow    *mainwin,
 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 +406,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 +449,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 +576,8 @@ 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/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 \
@@ -708,6 +726,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 +841,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 +855,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 +1079,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 +1290,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                                      \
@@ -1595,6 +1628,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 +1674,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 +1686,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 +1953,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)
@@ -2043,7 +2113,6 @@ 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/Open in new window"        , M_SINGLE_TARGET_EXIST},
@@ -2058,12 +2127,12 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                                                 , M_INC_ACTIVE},
 
                {"/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},
@@ -2186,6 +2255,187 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
        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 +2685,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 +2709,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 +2924,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,
@@ -2876,6 +3143,7 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
                menuitem->active = TRUE;
                prefs_common.work_offline = TRUE;
                inc_autocheck_timer_remove();           
+               imap_disconnect_all();
        } else {
                /*go online */
                gtk_widget_hide (mainwin->offline_switch);
@@ -3035,16 +3303,18 @@ static void hide_read_messages (MainWindow *mainwin, guint action,
 
 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
+       gboolean threaded = FALSE;
        if (mainwin->menu_lock_count) return;
        if (!mainwin->summaryview->folder_item) return;
 
-       if (GTK_CHECK_MENU_ITEM(widget)->active) {
-               summary_thread_build(mainwin->summaryview);
-/*             mainwin->summaryview->folder_item->threaded = TRUE; */
-       } else {
-               summary_unthread(mainwin->summaryview);
-/*             mainwin->summaryview->folder_item->threaded = FALSE; */
-       }
+       threaded = GTK_CHECK_MENU_ITEM(widget)->active;
+
+       mainwin->summaryview->folder_item->threaded = threaded; 
+
+       mainwin->summaryview->threaded = threaded;
+
+       summary_show(mainwin->summaryview, 
+                       mainwin->summaryview->folder_item);
 }
 
 static void expand_threads_cb(MainWindow *mainwin, guint action,
@@ -3252,6 +3522,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);
@@ -3261,11 +3537,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,
@@ -3374,6 +3650,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();
@@ -3420,6 +3705,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);
 
@@ -3442,7 +3729,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 */
@@ -3452,10 +3742,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:
@@ -3529,3 +3822,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);
+}