9413a009c02a3439ff6e0ef520bbbcc80b61ed65
[claws.git] / src / summaryview.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2016 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "defs.h"
20
21 #include <glib.h>
22 #include <glib/gi18n.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtk.h>
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <ctype.h>
30
31 #include "main.h"
32 #include "menu.h"
33 #include "mbox.h"
34 #include "mainwindow.h"
35 #include "folderview.h"
36 #include "summaryview.h"
37 #include "messageview.h"
38 #include "mimeview.h"
39 #include "foldersel.h"
40 #include "procmsg.h"
41 #include "procheader.h"
42 #include "sourcewindow.h"
43 #include "prefs_common.h"
44 #include "prefs_summary_column.h"
45 #include "prefs_summary_open.h"
46 #include "prefs_filtering.h"
47 #include "account.h"
48 #include "compose.h"
49 #include "utils.h"
50 #include "gtkutils.h"
51 #include "stock_pixmap.h"
52 #include "filesel.h"
53 #include "alertpanel.h"
54 #include "inputdialog.h"
55 #include "statusbar.h"
56 #include "folder.h"
57 #include "colorlabel.h"
58 #include "inc.h"
59 #include "imap.h"
60 #ifndef USE_ALT_ADDRBOOK
61         #include "addressbook.h"
62 #else
63         #include "addressbook-dbus.h"
64         #include "addressadd.h"
65 #endif
66 #include "addr_compl.h"
67 #include "folder_item_prefs.h"
68 #include "filtering.h"
69 #include "string_match.h"
70 #include "toolbar.h"
71 #include "news.h"
72 #include "hooks.h"
73 #include "description_window.h"
74 #include "folderutils.h"
75 #include "quicksearch.h"
76 #include "partial_download.h"
77 #include "tags.h"
78 #include "timing.h"
79 #include "log.h"
80 #include "edittags.h"
81 #include "manual.h"
82 #include "manage_window.h"
83 #include "avatars.h"
84
85 #define SUMMARY_COL_MARK_WIDTH          10
86 #define SUMMARY_COL_STATUS_WIDTH        13
87 #define SUMMARY_COL_LOCKED_WIDTH        13
88 #define SUMMARY_COL_MIME_WIDTH          11
89
90 static int normal_row_height = -1;
91 static GtkStyle *bold_style;
92 static GtkStyle *bold_marked_style;
93 static GtkStyle *bold_deleted_style;
94 static GtkStyle *small_style;
95 static GtkStyle *small_marked_style;
96 static GtkStyle *small_deleted_style;
97
98 static GdkPixbuf *markxpm;
99 static GdkPixbuf *deletedxpm;
100 static GdkPixbuf *movedxpm;
101 static GdkPixbuf *copiedxpm;
102
103 static GdkPixbuf *newxpm;
104 static GdkPixbuf *unreadxpm;
105 static GdkPixbuf *repliedxpm;
106 static GdkPixbuf *forwardedxpm;
107 static GdkPixbuf *repliedandforwardedxpm;
108 static GdkPixbuf *ignorethreadxpm;
109 static GdkPixbuf *watchthreadxpm;
110 static GdkPixbuf *lockedxpm;
111 static GdkPixbuf *spamxpm;
112
113 static GdkPixbuf *clipxpm;
114 static GdkPixbuf *keyxpm;
115 static GdkPixbuf *clipkeyxpm;
116 static GdkPixbuf *keysignxpm;
117 static GdkPixbuf *gpgsignedxpm;
118 static GdkPixbuf *clipgpgsignedxpm;
119
120 static void summary_free_msginfo_func   (GtkCMCTree             *ctree,
121                                          GtkCMCTreeNode         *node,
122                                          gpointer                data);
123 static void summary_set_marks_func      (GtkCMCTree             *ctree,
124                                          GtkCMCTreeNode         *node,
125                                          gpointer                data);
126
127 void  summary_set_menu_sensitive        (SummaryView            *summaryview);
128 guint summary_get_msgnum                (SummaryView            *summaryview,
129                                          GtkCMCTreeNode         *node);
130
131
132 static void summary_set_hide_menu (SummaryView *summaryview,
133                                    const gchar *menu_item,
134                                    guint action);
135
136 static GtkCMCTreeNode *summary_find_prev_msg
137                                         (SummaryView            *summaryview,
138                                          GtkCMCTreeNode         *current_node,
139                                          gboolean                start_from_prev);
140 static GtkCMCTreeNode *summary_find_next_msg
141                                         (SummaryView            *summaryview,
142                                          GtkCMCTreeNode         *current_node,
143                                          gboolean                start_from_next);
144
145 static GtkCMCTreeNode *summary_find_prev_flagged_msg
146                                         (SummaryView    *summaryview,
147                                          GtkCMCTreeNode *current_node,
148                                          MsgPermFlags    flags,
149                                          gboolean        start_from_prev);
150 static GtkCMCTreeNode *summary_find_next_flagged_msg
151                                         (SummaryView    *summaryview,
152                                          GtkCMCTreeNode *current_node,
153                                          MsgPermFlags    flags,
154                                          gboolean        start_from_next);
155
156 static GtkCMCTreeNode *summary_find_msg_by_msgnum
157                                         (SummaryView            *summaryview,
158                                          guint                   msgnum);
159
160 static void summary_update_status       (SummaryView            *summaryview);
161
162 static void summary_select_node_real(SummaryView *summaryview, GtkCMCTreeNode *node,
163                          gint force_display, gboolean ignore_mark_read);
164
165 static void summary_select_node_no_mark_read(SummaryView *summaryview, GtkCMCTreeNode *node,
166                          gint force_display);
167
168 /* display functions */
169 static void summary_status_show         (SummaryView            *summaryview);
170 static void summary_set_column_titles   (SummaryView            *summaryview);
171 static void summary_set_ctree_from_list (SummaryView            *summaryview,
172                                          GSList                 *mlist);
173 static inline void summary_set_header   (SummaryView            *summaryview,
174                                          gchar                  *text[],
175                                          MsgInfo                *msginfo);
176 static void summary_display_msg         (SummaryView            *summaryview,
177                                          GtkCMCTreeNode         *row);
178 static void summary_display_msg_full    (SummaryView            *summaryview,
179                                          GtkCMCTreeNode         *row,
180                                          gboolean                new_window,
181                                          gboolean                all_headers);
182 static void summary_set_row_marks       (SummaryView            *summaryview,
183                                          GtkCMCTreeNode         *row);
184
185 static gboolean summary_set_row_tag     (SummaryView            *summaryview, 
186                                          GtkCMCTreeNode                 *row, 
187                                          gboolean                refresh,
188                                          gboolean                set, 
189                                          gint                    id);
190 /* message handling */
191 static void summary_mark_row            (SummaryView            *summaryview,
192                                          GtkCMCTreeNode         *row);
193 static void summary_lock_row            (SummaryView            *summaryview,
194                                          GtkCMCTreeNode         *row);
195 static void summary_unlock_row          (SummaryView            *summaryview,
196                                          GtkCMCTreeNode         *row);
197 static void summary_mark_row_as_read    (SummaryView            *summaryview,
198                                          GtkCMCTreeNode         *row);
199 static void summary_mark_row_as_unread  (SummaryView            *summaryview,
200                                          GtkCMCTreeNode         *row);
201 static void summary_delete_row          (SummaryView            *summaryview,
202                                          GtkCMCTreeNode         *row);
203 static void summary_unmark_row          (SummaryView            *summaryview,
204                                          GtkCMCTreeNode         *row);
205 static void summary_move_row_to         (SummaryView            *summaryview,
206                                          GtkCMCTreeNode         *row,
207                                          FolderItem             *to_folder);
208 static void summary_copy_row_to         (SummaryView            *summaryview,
209                                          GtkCMCTreeNode         *row,
210                                          FolderItem             *to_folder);
211
212 static gint summary_execute_move        (SummaryView            *summaryview);
213 static void summary_execute_move_func   (GtkCMCTree             *ctree,
214                                          GtkCMCTreeNode         *node,
215                                          gpointer                data);
216 static void summary_execute_copy        (SummaryView            *summaryview);
217 static void summary_execute_copy_func   (GtkCMCTree             *ctree,
218                                          GtkCMCTreeNode         *node,
219                                          gpointer                data);
220 static void summary_execute_delete      (SummaryView            *summaryview);
221 static void summary_execute_delete_func (GtkCMCTree             *ctree,
222                                          GtkCMCTreeNode         *node,
223                                          gpointer                data);
224 static void summary_execute_expunge     (SummaryView            *summaryview);
225
226 static void summary_thread_init         (SummaryView            *summaryview);
227
228 static void summary_unthread_for_exec           (SummaryView    *summaryview);
229 static void summary_unthread_for_exec_func      (GtkCMCTree     *ctree,
230                                                  GtkCMCTreeNode *node,
231                                                  gpointer        data);
232
233 void summary_simplify_subject(SummaryView *summaryview, gchar * rexp,
234                               GSList * mlist);
235
236 static void summary_filter_func         (MsgInfo *msginfo);
237
238 static void summary_colorlabel_menu_item_activate_cb
239                                           (GtkWidget    *widget,
240                                            gpointer      data);
241 static void summary_colorlabel_menu_item_activate_item_cb
242                                           (GtkMenuItem  *label_menu_item,
243                                            gpointer      data);
244 static void summary_colorlabel_menu_create(SummaryView  *summaryview,
245                                            gboolean  refresh);
246 static void summary_tags_menu_item_activate_cb
247                                           (GtkWidget    *widget,
248                                            gpointer      data);
249 static void summary_tags_menu_item_activate_item_cb
250                                           (GtkMenuItem  *label_menu_item,
251                                            gpointer      data);
252 static void summary_tags_menu_create(SummaryView        *summaryview,
253                                            gboolean  refresh);
254
255 static GtkWidget *summary_ctree_create  (SummaryView    *summaryview);
256
257 /* callback functions */
258 static gint summary_toggle_pressed      (GtkWidget              *eventbox,
259                                          GdkEventButton         *event,
260                                          SummaryView            *summaryview);
261 #ifdef GENERIC_UMPC
262 static void summary_toggle_multiple_pressed
263                                         (GtkWidget              *widget,
264                                          SummaryView            *summaryview);
265 #endif
266 static gint summary_folder_eventbox_pressed     
267                                         (GtkWidget              *eventbox,
268                                          GdkEventButton         *event,
269                                          SummaryView            *summaryview);
270 static gboolean summary_button_pressed  (GtkWidget              *ctree,
271                                          GdkEventButton         *event,
272                                          SummaryView            *summaryview);
273 static gboolean summary_button_released (GtkWidget              *ctree,
274                                          GdkEventButton         *event,
275                                          SummaryView            *summaryview);
276 static gboolean summary_key_pressed     (GtkWidget              *ctree,
277                                          GdkEventKey            *event,
278                                          SummaryView            *summaryview);
279 static void summary_tree_expanded       (GtkCMCTree             *ctree,
280                                          GtkCMCTreeNode         *node,
281                                          SummaryView            *summaryview);
282 static void summary_tree_collapsed      (GtkCMCTree             *ctree,
283                                          GtkCMCTreeNode         *node,
284                                          SummaryView            *summaryview);
285 static void summary_selected            (GtkCMCTree             *ctree,
286                                          GtkCMCTreeNode         *row,
287                                          gint                    column,
288                                          SummaryView            *summaryview);
289 static void summary_unselected          (GtkCMCTree             *ctree,
290                                          GtkCMCTreeNode         *row,
291                                          gint                    column,
292                                          SummaryView            *summaryview);
293 static void summary_col_resized         (GtkCMCList             *clist,
294                                          gint                    column,
295                                          gint                    width,
296                                          SummaryView            *summaryview);
297 static void summary_mark_clicked        (GtkWidget              *button,
298                                          SummaryView            *summaryview);
299 static void summary_status_clicked      (GtkWidget              *button,
300                                          SummaryView            *summaryview);
301 static void summary_mime_clicked        (GtkWidget              *button,
302                                          SummaryView            *summaryview);
303 static void summary_num_clicked         (GtkWidget              *button,
304                                          SummaryView            *summaryview);
305 static void summary_score_clicked       (GtkWidget *button,
306                                          SummaryView *summaryview);
307 static void summary_size_clicked        (GtkWidget              *button,
308                                          SummaryView            *summaryview);
309 static void summary_date_clicked        (GtkWidget              *button,
310                                          SummaryView            *summaryview);
311 static void summary_from_clicked        (GtkWidget              *button,
312                                          SummaryView            *summaryview);
313 static void summary_to_clicked          (GtkWidget              *button,
314                                          SummaryView            *summaryview);
315 static void summary_subject_clicked     (GtkWidget              *button,
316                                          SummaryView            *summaryview);
317 static void summary_score_clicked       (GtkWidget              *button,
318                                          SummaryView            *summaryview);
319 static void summary_locked_clicked      (GtkWidget              *button,
320                                          SummaryView            *summaryview);
321 static void summary_tags_clicked        (GtkWidget              *button,
322                                          SummaryView            *summaryview);
323
324 static void summary_start_drag          (GtkWidget        *widget, 
325                                          int button,
326                                          GdkEvent *event,
327                                          SummaryView      *summaryview);
328 static void summary_drag_data_get       (GtkWidget        *widget,
329                                          GdkDragContext   *drag_context,
330                                          GtkSelectionData *selection_data,
331                                          guint             info,
332                                          guint             time,
333                                          SummaryView      *summaryview);
334 static void summary_drag_data_received(GtkWidget        *widget,
335                                         GdkDragContext   *drag_context,
336                                         gint              x,
337                                         gint              y,
338                                         GtkSelectionData *data,
339                                         guint             info,
340                                         guint             time,
341                                         SummaryView       *summaryview);
342 static gboolean summary_drag_motion_cb(GtkWidget      *widget,
343                                           GdkDragContext *context,
344                                           gint            x,
345                                           gint            y,
346                                           guint           time,
347                                           SummaryView    *summaryview);
348 static void summary_drag_end(GtkWidget *widget,
349                                           GdkDragContext *drag_context,
350                                           SummaryView    *summaryview);
351
352 /* custom compare functions for sorting */
353 static gint summary_cmp_by_mark         (GtkCMCList             *clist,
354                                          gconstpointer           ptr1,
355                                          gconstpointer           ptr2);
356 static gint summary_cmp_by_status       (GtkCMCList             *clist,
357                                          gconstpointer           ptr1,
358                                          gconstpointer           ptr2);
359 static gint summary_cmp_by_mime         (GtkCMCList             *clist,
360                                          gconstpointer           ptr1,
361                                          gconstpointer           ptr2);
362 static gint summary_cmp_by_num          (GtkCMCList             *clist,
363                                          gconstpointer           ptr1,
364                                          gconstpointer           ptr2);
365 static gint summary_cmp_by_size         (GtkCMCList             *clist,
366                                          gconstpointer           ptr1,
367                                          gconstpointer           ptr2);
368 static gint summary_cmp_by_date         (GtkCMCList             *clist,
369                                          gconstpointer           ptr1,
370                                          gconstpointer           ptr2);
371 static gint summary_cmp_by_thread_date  (GtkCMCList             *clist,
372                                          gconstpointer           ptr1,
373                                          gconstpointer           ptr2);
374 static gint summary_cmp_by_from         (GtkCMCList             *clist,
375                                          gconstpointer           ptr1,
376                                          gconstpointer           ptr2);
377 static gint summary_cmp_by_simplified_subject
378                                         (GtkCMCList             *clist, 
379                                          gconstpointer           ptr1, 
380                                          gconstpointer           ptr2);
381 static gint summary_cmp_by_score        (GtkCMCList             *clist,
382                                          gconstpointer           ptr1,
383                                          gconstpointer           ptr2);
384 static gint summary_cmp_by_label        (GtkCMCList             *clist,
385                                          gconstpointer           ptr1,
386                                          gconstpointer           ptr2);
387 static gint summary_cmp_by_to           (GtkCMCList             *clist,
388                                          gconstpointer           ptr1,
389                                          gconstpointer           ptr2);
390 static gint summary_cmp_by_subject      (GtkCMCList             *clist,
391                                          gconstpointer           ptr1,
392                                          gconstpointer           ptr2);
393 static gint summary_cmp_by_locked       (GtkCMCList             *clist,
394                                          gconstpointer           ptr1, 
395                                          gconstpointer           ptr2);
396 static gint summary_cmp_by_tags         (GtkCMCList             *clist,
397                                          gconstpointer           ptr1, 
398                                          gconstpointer           ptr2);
399
400 static void quicksearch_execute_cb      (QuickSearch    *quicksearch,
401                                          gpointer        data);
402
403 static void tog_searchbar_cb            (GtkWidget      *w,
404                                          gpointer        data);
405
406 static void summary_find_answers        (SummaryView    *summaryview, 
407                                          MsgInfo        *msg);
408
409 static gboolean summary_update_msg      (gpointer source, gpointer data);
410 static gboolean summary_update_folder_item_hook(gpointer source, gpointer data);
411 static gboolean summary_update_folder_hook(gpointer source, gpointer data);
412 static void summary_set_colorlabel_color (GtkCMCTree            *ctree,
413                                    GtkCMCTreeNode               *node,
414                                    guint                 labelcolor);
415 static void summary_thread_build(SummaryView *summaryview);
416
417 GtkTargetEntry summary_drag_types[3] =
418 {
419         {"text/uri-list", 0, TARGET_MAIL_URI_LIST},
420         {"claws-mail/internal", GTK_TARGET_SAME_APP, TARGET_DUMMY},
421         {"claws-mail/msg-path-list", 0, TARGET_MAIL_CM_PATH_LIST},
422 };
423
424 #define DO_ACTION(name, act) {                                          \
425         if(!strcmp(name, a_name)) {                                     \
426                 act;                                                    \
427         }                                                               \
428 }
429
430 static GtkActionEntry summary_popup_entries[] =
431 {
432         {"SummaryViewPopup",                      NULL, "SummaryViewPopup", NULL, NULL, NULL },
433         {"SummaryViewPopup/ReplyTo",              NULL, N_("Repl_y to"), NULL, NULL, NULL },
434         {"SummaryViewPopup/Mark",                 NULL, N_("_Mark"), NULL, NULL, NULL },
435         {"SummaryViewPopup/ColorLabel",           NULL, N_("Color la_bel"), NULL, NULL, NULL },
436         {"SummaryViewPopup/Tags",                 NULL, N_("Ta_gs"), NULL, NULL, NULL },
437         {"SummaryViewPopup/CreateFilterRule",     NULL, N_("Create _filter rule"), NULL, NULL, NULL },
438 #ifndef GENERIC_UMPC
439         {"SummaryViewPopup/CreateProcessingRule", NULL, N_("Create processing rule"), NULL, NULL, NULL },
440 #endif
441         {"SummaryViewPopup/View",                 NULL, N_("_View"), NULL, NULL, NULL },
442 };
443
444 static const gchar *const col_label[N_SUMMARY_COLS] = {
445         "",            /* S_COL_MARK    */
446         N_("S"),       /* S_COL_STATUS  */
447         "",            /* S_COL_MIME    */
448         N_("Subject"), /* S_COL_SUBJECT */
449         N_("From"),    /* S_COL_FROM    */
450         N_("To"),      /* S_COL_TO      */
451         N_("Date"),    /* S_COL_DATE    */
452         N_("Size"),    /* S_COL_SIZE    */
453         N_("#"),       /* S_COL_NUMBER  */
454         N_("Score"),   /* S_COL_SCORE   */
455         "",            /* S_COL_LOCKED  */
456         N_("Tags"),    /* S_COL_TAGS    */
457 };
458
459 void summary_freeze(SummaryView *summaryview)
460 {
461         if (summaryview)
462                 gtk_cmclist_freeze(GTK_CMCLIST(summaryview->ctree));
463 }
464
465 void summary_thaw(SummaryView *summaryview)
466 {
467         if (summaryview)
468                 gtk_cmclist_thaw(GTK_CMCLIST(summaryview->ctree));
469 }
470
471 void summary_thaw_with_status(SummaryView *summaryview)
472 {
473         if (summaryview) {
474                 summary_status_show(summaryview);
475                 gtk_cmclist_thaw(GTK_CMCLIST(summaryview->ctree));
476         }
477 }
478
479 void summary_grab_focus(SummaryView *summaryview)
480 {
481         if (summaryview)
482                 gtk_widget_grab_focus(summaryview->ctree);
483 }
484
485 GtkWidget *summary_get_main_widget(SummaryView *summaryview)
486 {
487         if (summaryview)
488                 return summaryview->ctree;
489         else
490                 return NULL;
491 }
492
493 #define START_LONG_OPERATION(summaryview,force_freeze) {        \
494         summary_lock(summaryview);                              \
495         main_window_cursor_wait(summaryview->mainwin);          \
496         if (force_freeze || sc_g_list_bigger(GTK_CMCLIST(summaryview->ctree)->selection, 1)) {\
497                 froze = TRUE;                                           \
498                 summary_freeze(summaryview);    \
499         }                                                       \
500         folder_item_update_freeze();                            \
501         inc_lock();                                             \
502         hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,          \
503                       summaryview->msginfo_update_callback_id); \
504 }
505 #define END_LONG_OPERATION(summaryview) {                       \
506         inc_unlock();                                           \
507         folder_item_update_thaw();                              \
508         if (froze)                                              \
509                 summary_thaw(summaryview);      \
510         main_window_cursor_normal(summaryview->mainwin);        \
511         summary_unlock(summaryview);                            \
512         summaryview->msginfo_update_callback_id =               \
513                 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,    \
514                 summary_update_msg, (gpointer) summaryview);    \
515 }
516
517 SummaryView *summary_create(MainWindow *mainwin)
518 {
519         SummaryView *summaryview;
520         GtkWidget *vbox;
521         GtkWidget *scrolledwin;
522         GtkWidget *ctree;
523         GtkWidget *hbox;
524         GtkWidget *hbox_l;
525         GtkWidget *stat_box;
526         GtkWidget *stat_box2;
527         GtkWidget *stat_vbox;
528         GtkWidget *statlabel_folder;
529         GtkWidget *statlabel_select;
530         GtkWidget *statlabel_msgs;
531         GtkWidget *hbox_spc;
532         GtkWidget *toggle_eventbox;
533 #ifdef GENERIC_UMPC
534         GtkWidget *multiple_sel_togbtn;
535 #endif
536         GtkWidget *toggle_arrow;
537         GtkWidget *toggle_search;
538         QuickSearch *quicksearch;
539
540         debug_print("Creating summary view...\n");
541         summaryview = g_new0(SummaryView, 1);
542
543 #define SUMMARY_VBOX_SPACING 3
544         vbox = gtk_vbox_new(FALSE, SUMMARY_VBOX_SPACING);
545         
546         /* create status label */
547         hbox = gtk_hbox_new(FALSE, 0);
548         gtk_widget_show(hbox);
549
550         stat_vbox = gtk_vbox_new(FALSE, 0);
551         gtk_widget_show(stat_vbox);
552
553         stat_box = gtk_hbox_new(FALSE, 0);
554         gtk_widget_show(stat_box);
555         
556         stat_box2 = gtk_hbox_new(FALSE, 0);
557         gtk_widget_show(stat_box2);
558         
559         toggle_search = gtk_toggle_button_new();
560         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_search),
561                                      prefs_common.show_searchbar);
562         gtkut_widget_set_can_focus(toggle_search, FALSE);
563         gtk_widget_show(toggle_search);
564
565         CLAWS_SET_TIP(toggle_search, _("Toggle quick search bar"));
566         
567         gtk_box_pack_start(GTK_BOX(hbox), toggle_search, FALSE, FALSE, 2);      
568
569         gtk_box_pack_start(GTK_BOX(hbox), stat_vbox, TRUE, TRUE, 0);    
570         gtk_box_pack_start(GTK_BOX(stat_vbox), stat_box, TRUE, TRUE, 0);        
571         gtk_box_pack_start(GTK_BOX(stat_vbox), stat_box2, TRUE, TRUE, 0);       
572
573         hbox_l = gtk_hbox_new(FALSE, 0);
574         gtk_widget_show(hbox_l);
575         gtk_box_pack_start(GTK_BOX(stat_box), hbox_l, TRUE, TRUE, 0);
576  
577         statlabel_folder = gtk_label_new("");
578         gtk_widget_show(statlabel_folder);
579         gtk_box_pack_start(GTK_BOX(hbox_l), statlabel_folder, FALSE, FALSE, 2);
580         statlabel_select = gtk_label_new("");
581         gtk_widget_show(statlabel_select);
582         gtk_box_pack_start(GTK_BOX(hbox_l), statlabel_select, FALSE, FALSE, 12);
583  
584         /* toggle view button */
585         toggle_eventbox = gtk_event_box_new();
586         gtk_widget_show(toggle_eventbox);
587         
588         gtk_box_pack_end(GTK_BOX(hbox), toggle_eventbox, FALSE, FALSE, 4);
589
590         toggle_arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
591         gtk_widget_show(toggle_arrow);
592         gtk_container_add(GTK_CONTAINER(toggle_eventbox), toggle_arrow);
593         g_signal_connect(G_OBJECT(toggle_eventbox), "button_press_event",
594                          G_CALLBACK(summary_toggle_pressed),
595                          summaryview);
596
597 #ifdef GENERIC_UMPC
598         multiple_sel_togbtn = gtk_toggle_button_new();
599         gtk_widget_show(multiple_sel_togbtn);
600         gtk_box_pack_end(GTK_BOX(hbox), multiple_sel_togbtn, FALSE, FALSE, 4);
601         CLAWS_SET_TIP(multiple_sel_togbtn,
602                              _("Toggle multiple selection"));
603         g_signal_connect(G_OBJECT(multiple_sel_togbtn), "toggled",
604                          G_CALLBACK(summary_toggle_multiple_pressed),
605                          summaryview);
606 #endif
607         
608         statlabel_msgs = gtk_label_new("");
609         gtk_widget_show(statlabel_msgs);
610         gtk_box_pack_end(GTK_BOX(stat_box), statlabel_msgs, FALSE, FALSE, 4);
611
612         hbox_spc = gtk_hbox_new(FALSE, 0);
613         gtk_widget_show(hbox_spc);
614         gtk_box_pack_end(GTK_BOX(hbox), hbox_spc, FALSE, FALSE, 6);
615
616         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
617         gtk_widget_show(scrolledwin);
618         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
619                                        GTK_POLICY_AUTOMATIC,
620                                        GTK_POLICY_AUTOMATIC);
621         summaryview->mainwidget_book = gtk_notebook_new();
622         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(summaryview->mainwidget_book), FALSE);
623         gtk_notebook_set_show_border(GTK_NOTEBOOK(summaryview->mainwidget_book), FALSE);
624 #ifndef GENERIC_UMPC
625         gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
626                 scrolledwin);
627         gtk_box_pack_start(GTK_BOX(vbox), summaryview->mainwidget_book, TRUE, TRUE, 0);
628 #endif
629         gtk_widget_set_size_request(vbox,
630                              prefs_common.summaryview_width,
631                              prefs_common.summaryview_height);
632
633         ctree = summary_ctree_create(summaryview);
634         gtk_widget_show(ctree);
635
636         gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
637                                             GTK_CMCLIST(ctree)->hadjustment);
638         gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
639                                             GTK_CMCLIST(ctree)->vadjustment);
640         gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
641
642         /* status label */
643         gtk_widget_show_all(stat_vbox);
644         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
645
646         /* quick search */
647         quicksearch = quicksearch_new();
648         gtk_box_pack_start(GTK_BOX(vbox), quicksearch_get_widget(quicksearch), FALSE, FALSE, 0);
649
650 #ifdef GENERIC_UMPC
651         gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
652                 scrolledwin);
653         gtk_box_pack_start(GTK_BOX(vbox), summaryview->mainwidget_book, TRUE, TRUE, 0);
654 #endif
655         quicksearch_set_execute_callback(quicksearch, quicksearch_execute_cb, summaryview);
656
657         g_signal_connect (G_OBJECT(toggle_search), "toggled",
658                           G_CALLBACK(tog_searchbar_cb), summaryview);
659
660         /* create popup menu */
661         
662         gtk_action_group_add_actions(mainwin->action_group, summary_popup_entries,
663                         G_N_ELEMENTS(summary_popup_entries), (gpointer)summaryview);
664
665         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/", "Menus", "Menus", GTK_UI_MANAGER_MENUBAR)
666         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus", "SummaryViewPopup", "SummaryViewPopup", GTK_UI_MANAGER_MENU)
667         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Reply", "Message/Reply", GTK_UI_MANAGER_MENUITEM)
668 #ifndef GENERIC_UMPC
669         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ReplyTo", "SummaryViewPopup/ReplyTo", GTK_UI_MANAGER_MENU)
670         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator1", "Message/---", GTK_UI_MANAGER_SEPARATOR)
671 #endif
672         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Forward", "Message/Forward", GTK_UI_MANAGER_MENUITEM)
673 #ifndef GENERIC_UMPC
674         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ForwardAtt", "Message/ForwardAtt", GTK_UI_MANAGER_MENUITEM)
675         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Redirect", "Message/Redirect", GTK_UI_MANAGER_MENUITEM)
676 #endif
677         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
678         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Move", "Message/Move", GTK_UI_MANAGER_MENUITEM)
679         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Copy", "Message/Copy", GTK_UI_MANAGER_MENUITEM)
680         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Trash", "Message/Trash", GTK_UI_MANAGER_MENUITEM)
681 #ifndef GENERIC_UMPC
682         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Delete", "Message/Delete", GTK_UI_MANAGER_MENUITEM)
683 #endif
684         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator3", "Message/---", GTK_UI_MANAGER_SEPARATOR)
685         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Mark", "SummaryViewPopup/Mark", GTK_UI_MANAGER_MENU)
686         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ColorLabel", "SummaryViewPopup/ColorLabel", GTK_UI_MANAGER_MENU)
687         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Tags", "SummaryViewPopup/Tags", GTK_UI_MANAGER_MENU)
688
689         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator4", "Message/---", GTK_UI_MANAGER_SEPARATOR)
690 #ifndef GENERIC_UMPC
691         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "AddSenderToAB", "Tools/AddSenderToAB", GTK_UI_MANAGER_MENUITEM)
692 #endif
693         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "CreateFilterRule", "SummaryViewPopup/CreateFilterRule", GTK_UI_MANAGER_MENU)
694 #ifndef GENERIC_UMPC
695         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "CreateProcessingRule", "SummaryViewPopup/CreateProcessingRule", GTK_UI_MANAGER_MENU)
696 #endif
697         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator5", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
698         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "View", "SummaryViewPopup/View", GTK_UI_MANAGER_MENU)
699         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
700 #ifndef GENERIC_UMPC
701         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
702 #endif
703         /* last separator, for plugins */
704         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator6", "File/---", GTK_UI_MANAGER_SEPARATOR)
705
706         /* submenus - replyto */
707         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "All", "Message/ReplyTo/All", GTK_UI_MANAGER_MENUITEM)
708         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "Sender", "Message/ReplyTo/Sender", GTK_UI_MANAGER_MENUITEM)
709         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "MailingList", "Message/ReplyTo/List", GTK_UI_MANAGER_MENUITEM)
710
711         /* submenus - mark */
712         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Mark", "Message/Mark/Mark", GTK_UI_MANAGER_MENUITEM)
713         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Unmark", "Message/Mark/Unmark", GTK_UI_MANAGER_MENUITEM)
714         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator1", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
715         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkRead", "Message/Mark/MarkRead", GTK_UI_MANAGER_MENUITEM)
716         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkUnread", "Message/Mark/MarkUnread", GTK_UI_MANAGER_MENUITEM)
717         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator2", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
718         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkAllRead", "Message/Mark/MarkAllRead", GTK_UI_MANAGER_MENUITEM)
719         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkAllUnread", "Message/Mark/MarkAllUnread", GTK_UI_MANAGER_MENUITEM)
720         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator3", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
721         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "IgnoreThread", "Message/Mark/IgnoreThread", GTK_UI_MANAGER_MENUITEM)
722         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "UnignoreThread", "Message/Mark/UnignoreThread", GTK_UI_MANAGER_MENUITEM)
723         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "WatchThread", "Message/Mark/WatchThread", GTK_UI_MANAGER_MENUITEM)
724         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "UnwatchThread", "Message/Mark/UnwatchThread", GTK_UI_MANAGER_MENUITEM)
725         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator4", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
726         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkSpam", "Message/Mark/MarkSpam", GTK_UI_MANAGER_MENUITEM)
727         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkHam", "Message/Mark/MarkHam", GTK_UI_MANAGER_MENUITEM)
728         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator5", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
729         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Lock", "Message/Mark/Lock", GTK_UI_MANAGER_MENUITEM)
730         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Unlock", "Message/Mark/Unlock", GTK_UI_MANAGER_MENUITEM)
731
732         /* submenus - colorlabel and tags are dynamic */
733         /* submenus - createfilterrule */
734         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "Automatically", "Tools/CreateFilterRule/Automatically", GTK_UI_MANAGER_MENUITEM)
735         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "ByFrom", "Tools/CreateFilterRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
736         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "ByTo", "Tools/CreateFilterRule/ByTo", GTK_UI_MANAGER_MENUITEM)
737         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "BySubject", "Tools/CreateFilterRule/BySubject", GTK_UI_MANAGER_MENUITEM)
738                 
739 #ifndef GENERIC_UMPC
740         /* submenus - createprocessingrule */
741         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "Automatically", "Tools/CreateProcessingRule/Automatically", GTK_UI_MANAGER_MENUITEM)
742         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "ByFrom", "Tools/CreateProcessingRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
743         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "ByTo", "Tools/CreateProcessingRule/ByTo", GTK_UI_MANAGER_MENUITEM)
744         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "BySubject", "Tools/CreateProcessingRule/BySubject", GTK_UI_MANAGER_MENUITEM)
745 #endif
746                 
747         /* submenus - view */
748         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "OpenNewWindow", "View/OpenNewWindow", GTK_UI_MANAGER_MENUITEM)
749         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "MessageSource", "View/MessageSource", GTK_UI_MANAGER_MENUITEM)
750 #ifndef GENERIC_UMPC
751         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "AllHeaders", "View/AllHeaders", GTK_UI_MANAGER_MENUITEM)
752 #endif          
753         summaryview->popupmenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
754                                 gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menus/SummaryViewPopup")) );
755
756
757         summaryview->vbox = vbox;
758         summaryview->scrolledwin = scrolledwin;
759         summaryview->ctree = ctree;
760         summaryview->hbox = hbox;
761         summaryview->hbox_l = hbox_l;
762         summaryview->hbox_spc = hbox_spc;
763         summaryview->stat_box = stat_box;
764         summaryview->stat_box2 = stat_box2;
765         summaryview->statlabel_folder = statlabel_folder;
766         summaryview->statlabel_select = statlabel_select;
767         summaryview->statlabel_msgs = statlabel_msgs;
768         summaryview->toggle_eventbox = toggle_eventbox;
769         summaryview->toggle_arrow = toggle_arrow;
770 #ifdef GENERIC_UMPC
771         summaryview->multiple_sel_togbtn = multiple_sel_togbtn;
772 #endif
773         summaryview->toggle_search = toggle_search;
774         summaryview->lock_count = 0;
775         summaryview->msginfo_update_callback_id =
776                 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, summary_update_msg, (gpointer) summaryview);
777         summaryview->folder_item_update_callback_id =
778                 hooks_register_hook(FOLDER_ITEM_UPDATE_HOOKLIST,
779                                 summary_update_folder_item_hook,
780                                 (gpointer) summaryview);
781         summaryview->folder_update_callback_id =
782                 hooks_register_hook(FOLDER_UPDATE_HOOKLIST,
783                                 summary_update_folder_hook,
784                                 (gpointer) summaryview);
785
786         summaryview->target_list = gtk_target_list_new(summary_drag_types, 3);
787
788         summaryview->quicksearch = quicksearch;
789
790         /* CLAWS: need this to get the SummaryView * from
791          * the CList */
792         g_object_set_data(G_OBJECT(ctree), "summaryview", (gpointer)summaryview); 
793
794         gtk_widget_show_all(vbox);
795
796         gtk_widget_show(vbox);
797
798         if (prefs_common.show_searchbar)
799                 quicksearch_show(quicksearch);
800         else
801                 quicksearch_hide(quicksearch);
802         
803         if (prefs_common.layout_mode == WIDE_MSGLIST_LAYOUT ||
804             prefs_common.layout_mode == SMALL_LAYOUT)
805                 gtk_widget_hide(summaryview->toggle_eventbox);
806
807         return summaryview;
808 }
809
810 void summary_relayout(SummaryView *summaryview)
811 {
812         gtk_widget_realize(summaryview->stat_box);
813
814         g_object_ref(summaryview->hbox_l);
815         g_object_ref(summaryview->statlabel_msgs);
816         
817         gtkut_container_remove(GTK_CONTAINER(
818                 gtk_widget_get_parent(summaryview->hbox_l)), summaryview->hbox_l);
819         gtkut_container_remove(GTK_CONTAINER(
820                 gtk_widget_get_parent(summaryview->statlabel_msgs)), summaryview->statlabel_msgs);
821
822         switch (prefs_common.layout_mode) {
823         case NORMAL_LAYOUT:
824         case WIDE_LAYOUT:
825         case WIDE_MSGLIST_LAYOUT:
826                 gtk_box_pack_start(GTK_BOX(summaryview->stat_box), summaryview->hbox_l, TRUE, TRUE, 0);
827                 gtk_box_pack_end(GTK_BOX(summaryview->stat_box), summaryview->statlabel_msgs, FALSE, FALSE, 4);
828                 gtk_widget_show_all(summaryview->stat_box);
829                 gtk_widget_show_all(summaryview->stat_box2);
830                 if (prefs_common.layout_mode == WIDE_MSGLIST_LAYOUT ||
831                     prefs_common.layout_mode == SMALL_LAYOUT)
832                         gtk_widget_hide(summaryview->toggle_eventbox);
833                 else
834                         gtk_widget_show(summaryview->toggle_eventbox);
835                 break;
836         case VERTICAL_LAYOUT:
837         case SMALL_LAYOUT:
838                 gtk_box_pack_start(GTK_BOX(summaryview->stat_box), summaryview->hbox_l, TRUE, TRUE, 0);
839                 gtk_box_pack_start(GTK_BOX(summaryview->stat_box2), summaryview->statlabel_msgs, FALSE, FALSE, 4);
840                 gtk_widget_show_all(summaryview->stat_box);
841                 gtk_widget_show_all(summaryview->stat_box2);
842                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
843                         gtk_widget_hide(summaryview->toggle_eventbox);
844                         gtk_widget_hide(summaryview->statlabel_msgs);
845                 } else {
846                         gtk_widget_show(summaryview->toggle_eventbox);
847                         gtk_widget_show(summaryview->statlabel_msgs);
848                 }
849                         
850                 break;
851         }
852         summary_set_column_order(summaryview);
853
854         g_object_unref(summaryview->hbox_l);
855         g_object_unref(summaryview->statlabel_msgs);
856         quicksearch_relayout(summaryview->quicksearch);
857         if (prefs_common.show_searchbar)
858                 quicksearch_show(summaryview->quicksearch);
859         else
860                 quicksearch_hide(summaryview->quicksearch);
861 }
862
863 static void summary_set_fonts(SummaryView *summaryview)
864 {
865         PangoFontDescription *font_desc;
866         gint size;
867
868         font_desc = pango_font_description_from_string(NORMAL_FONT);
869         if (font_desc) {
870                 gtk_widget_modify_font(summaryview->ctree, font_desc);
871                 pango_font_description_free(font_desc);
872         }
873
874         if (!bold_style) {
875                 bold_style = gtk_style_copy
876                         (gtk_widget_get_style(summaryview->ctree));
877
878                 if (prefs_common.derive_from_normal_font || !BOLD_FONT) {
879                         font_desc = pango_font_description_from_string(NORMAL_FONT);
880                         if (font_desc) {
881                                 pango_font_description_free(bold_style->font_desc);
882                                 bold_style->font_desc = font_desc;
883                         }
884                         pango_font_description_set_weight
885                                         (bold_style->font_desc, PANGO_WEIGHT_BOLD);
886                 } else {
887                         font_desc = pango_font_description_from_string(BOLD_FONT);
888                         if (font_desc) {
889                                 pango_font_description_free(bold_style->font_desc);
890                                 bold_style->font_desc = font_desc;
891                         }
892                 }
893                 bold_marked_style = gtk_style_copy(bold_style);
894                 bold_marked_style->fg[GTK_STATE_NORMAL] =
895                         summaryview->color_marked;
896                 bold_deleted_style = gtk_style_copy(bold_style);
897                 bold_deleted_style->fg[GTK_STATE_NORMAL] =
898                         summaryview->color_dim;
899         }
900
901         if (prefs_common.derive_from_normal_font || !SMALL_FONT) {
902                 font_desc = pango_font_description_new();
903                 size = pango_font_description_get_size
904                         (gtk_widget_get_style(summaryview->ctree)->font_desc);
905                 pango_font_description_set_size(font_desc, size * PANGO_SCALE_SMALL);
906         } else {
907                 font_desc = pango_font_description_from_string(SMALL_FONT);
908         }
909         if (font_desc) {
910                 gtk_widget_modify_font(summaryview->statlabel_folder, font_desc);
911                 gtk_widget_modify_font(summaryview->statlabel_select, font_desc);
912                 gtk_widget_modify_font(summaryview->statlabel_msgs, font_desc);
913                 pango_font_description_free(font_desc);
914         }
915
916 }
917
918 static void summary_set_folder_pixmap(SummaryView *summaryview, StockPixmap icon)
919 {
920         GtkWidget *pixmap; 
921         if (!summaryview->folder_pixmap_eventbox) {
922                 summaryview->folder_pixmap_eventbox = gtk_event_box_new();
923                 gtk_widget_show(summaryview->folder_pixmap_eventbox);
924                 gtk_box_pack_start(GTK_BOX(summaryview->hbox_l), summaryview->folder_pixmap_eventbox, FALSE, FALSE, 4);
925                 gtk_box_reorder_child(GTK_BOX(summaryview->hbox_l), summaryview->folder_pixmap_eventbox, 0); /* search_toggle before */
926                 g_signal_connect(G_OBJECT(summaryview->folder_pixmap_eventbox), "button_press_event",
927                          G_CALLBACK(summary_folder_eventbox_pressed),
928                          summaryview);
929         }
930         if (summaryview->folder_pixmap)
931                 gtk_widget_destroy(summaryview->folder_pixmap);
932
933         pixmap = stock_pixmap_widget(icon);
934         gtk_container_add(GTK_CONTAINER(summaryview->folder_pixmap_eventbox), pixmap);
935         gtk_widget_show(pixmap);
936         summaryview->folder_pixmap = pixmap; 
937 }
938
939 void summary_init(SummaryView *summaryview)
940 {
941         GtkWidget *pixmap;
942
943         gtk_widget_realize(summaryview->ctree);
944         stock_pixbuf_gdk(STOCK_PIXMAP_MARK, &markxpm);
945         stock_pixbuf_gdk(STOCK_PIXMAP_DELETED, &deletedxpm);
946         stock_pixbuf_gdk(STOCK_PIXMAP_NEW, &newxpm);
947         stock_pixbuf_gdk(STOCK_PIXMAP_UNREAD, &unreadxpm);
948         stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED, &repliedxpm);
949         stock_pixbuf_gdk(STOCK_PIXMAP_FORWARDED, &forwardedxpm);
950         stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED_AND_FORWARDED, &repliedandforwardedxpm);
951         stock_pixbuf_gdk(STOCK_PIXMAP_CLIP, &clipxpm);
952         stock_pixbuf_gdk(STOCK_PIXMAP_LOCKED, &lockedxpm);
953         stock_pixbuf_gdk(STOCK_PIXMAP_IGNORETHREAD, &ignorethreadxpm);
954         stock_pixbuf_gdk(STOCK_PIXMAP_WATCHTHREAD, &watchthreadxpm);
955         stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_KEY, &clipkeyxpm);
956         stock_pixbuf_gdk(STOCK_PIXMAP_KEY_SIGN, &keysignxpm);
957         stock_pixbuf_gdk(STOCK_PIXMAP_KEY, &keyxpm);
958         stock_pixbuf_gdk(STOCK_PIXMAP_GPG_SIGNED, &gpgsignedxpm);
959         stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_GPG_SIGNED, &clipgpgsignedxpm);
960         stock_pixbuf_gdk(STOCK_PIXMAP_SPAM, &spamxpm);
961         stock_pixbuf_gdk(STOCK_PIXMAP_MOVED, &movedxpm);
962         stock_pixbuf_gdk(STOCK_PIXMAP_COPIED, &copiedxpm);
963
964         summary_set_fonts(summaryview);
965
966         summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
967
968         pixmap = stock_pixmap_widget(STOCK_PIXMAP_QUICKSEARCH);
969         gtk_container_add (GTK_CONTAINER(summaryview->toggle_search), pixmap);
970         gtk_widget_show(pixmap);
971         summaryview->quick_search_pixmap = pixmap;
972         
973 #ifdef GENERIC_UMPC
974         pixmap = stock_pixmap_widget(STOCK_PIXMAP_SELECTION);
975         gtk_container_add(GTK_CONTAINER(summaryview->multiple_sel_togbtn), pixmap);
976         gtk_widget_show(pixmap);
977         summaryview->multiple_sel_image = pixmap;
978 #endif
979
980         /* Init summaryview prefs */
981         summaryview->sort_key = SORT_BY_NONE;
982         summaryview->sort_type = SORT_ASCENDING;
983
984         /* Init summaryview extra data */
985         summaryview->simplify_subject_preg = NULL;
986         summary_clear_list(summaryview);
987         summary_set_column_titles(summaryview);
988         summary_colorlabel_menu_create(summaryview, FALSE);
989         summary_tags_menu_create(summaryview, FALSE);
990         main_create_mailing_list_menu (summaryview->mainwin, NULL);     
991         summary_set_menu_sensitive(summaryview);
992
993 }
994
995 #define CURRENTLY_DISPLAYED(m) \
996 ( (m->msgnum == displayed_msgnum) \
997   && (!g_ascii_strcasecmp(m->folder->name,item->name)) )
998
999 #define FOLDER_SHOWS_TO_HDR(i) \
1000 ( i && (folder_has_parent_of_type(i, F_OUTBOX) \
1001         || folder_has_parent_of_type(i, F_DRAFT) \
1002         || folder_has_parent_of_type(i, F_QUEUE)) )
1003   
1004 static void summary_switch_from_to(SummaryView *summaryview, FolderItem *item)
1005 {
1006         gboolean show_from = FALSE, show_to = FALSE;
1007         gboolean showing_from = FALSE, showing_to = FALSE;
1008         gint from_pos = 0, to_pos = 0;
1009         SummaryColumnState *col_state = summaryview->col_state;
1010         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1011         
1012         if (!item || ((prefs_common.layout_mode == VERTICAL_LAYOUT || prefs_common.layout_mode == SMALL_LAYOUT) && prefs_common.two_line_vert) )
1013                 return;
1014         if (FOLDER_SHOWS_TO_HDR(item))
1015                 show_to = TRUE;
1016         else
1017                 show_from = TRUE;
1018         
1019         from_pos = summaryview->col_pos[S_COL_FROM];
1020         to_pos = summaryview->col_pos[S_COL_TO];
1021         showing_from = col_state[from_pos].visible;
1022         showing_to = col_state[to_pos].visible;
1023         
1024         if (showing_from && showing_to) {
1025                 debug_print("showing both\n");
1026                 return;
1027         }
1028
1029         if (!showing_from && !showing_to) {
1030                 debug_print("showing none\n");
1031                 return;
1032         }
1033
1034         debug_print("showing %s %s, must show %s %s\n", 
1035                 showing_from?"From":"",
1036                 showing_to?"To":"",
1037                 show_from?"From":"",
1038                 show_to?"To":"");
1039
1040         if (showing_from == show_from && showing_to == show_to)
1041                 return;
1042         /* else we'll switch both */
1043
1044         debug_print("switching columns\n");
1045         col_state[from_pos].type = S_COL_TO;
1046         col_state[from_pos].visible = show_to;
1047
1048         col_state[to_pos].type = S_COL_FROM;
1049         col_state[to_pos].visible = show_from;
1050
1051         summaryview->col_pos[S_COL_TO] = from_pos;
1052         summaryview->col_pos[S_COL_FROM] = to_pos;
1053
1054         gtk_cmclist_set_column_visibility
1055                 (GTK_CMCLIST(ctree), from_pos, col_state[from_pos].visible);
1056         gtk_cmclist_set_column_visibility
1057                 (GTK_CMCLIST(ctree), to_pos, col_state[to_pos].visible);
1058
1059         summary_set_column_titles(summaryview);
1060 }
1061
1062 static void summaryview_reset_recursive_folder_match(SummaryView *summaryview)
1063 {
1064         GSList *cur;
1065
1066         for (cur = summaryview->recursive_matched_folders; cur != NULL; cur = cur->next) {
1067                 folderview_update_search_icon(cur->data, FALSE);
1068         }
1069
1070         g_slist_free(summaryview->recursive_matched_folders);
1071         summaryview->recursive_matched_folders = NULL;
1072         summaryview->search_root_folder = NULL;
1073 }
1074
1075 static gboolean summaryview_quicksearch_recursive_progress(gpointer data, guint at, guint matched, guint total)
1076 {
1077         QuickSearch *search = (QuickSearch*) data;
1078         gint interval = quicksearch_is_fast(search) ? 5000 : 100;
1079
1080         statusbar_progress_all(at, total, interval);
1081         if (at % interval == 0)
1082                 GTK_EVENTS_FLUSH();
1083
1084         if (matched > 0)
1085                 return FALSE;
1086
1087         return TRUE;
1088 }
1089
1090 static void summaryview_quicksearch_recurse_step(SummaryView *summaryview, FolderItem *item)
1091 {
1092         MsgInfoList *msgs = NULL;
1093         gboolean result = TRUE;
1094
1095         statusbar_print_all(_("Searching in %s... \n"),
1096                 item->path ? item->path : "(null)");
1097         folder_item_update_freeze();
1098
1099         quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_quicksearch_recursive_progress, summaryview->quicksearch);
1100         if (!quicksearch_run_on_folder(summaryview->quicksearch, item, &msgs))
1101                 result = FALSE;
1102
1103         result = result && msgs != NULL;
1104
1105         if (msgs != NULL)
1106                 procmsg_msg_list_free(msgs);
1107
1108         folder_item_update_thaw();
1109         statusbar_progress_all(0, 0, 0);
1110         statusbar_pop_all();
1111
1112         if (result) {
1113                 summaryview->recursive_matched_folders = g_slist_prepend(
1114                                 summaryview->recursive_matched_folders, item);
1115         
1116                 folderview_update_search_icon(item, TRUE);
1117         }
1118 }
1119
1120 static void summaryview_quicksearch_search_subfolders(SummaryView *summaryview, FolderItem *folder_item)
1121 {
1122         FolderItem *cur = NULL;
1123         GNode *node = folder_item->node->children;
1124
1125         if (!prefs_common.summary_quicksearch_recurse
1126                         || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1127                         || quicksearch_is_in_typing(summaryview->quicksearch))
1128                 return;
1129
1130         for (; node != NULL; node = node->next) {
1131                 if (!quicksearch_has_sat_predicate(summaryview->quicksearch))
1132                         return;
1133
1134                 cur = FOLDER_ITEM(node->data);
1135                 summaryview_quicksearch_recurse_step(summaryview, cur);
1136                 if (cur->node->children)
1137                         summaryview_quicksearch_search_subfolders(summaryview, cur);
1138         }
1139 }
1140
1141 static void summaryview_quicksearch_recurse(SummaryView *summaryview)
1142 {
1143         if (!prefs_common.summary_quicksearch_recurse
1144                 || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1145                 || summaryview->folder_item == NULL) {
1146                 return;
1147         }
1148
1149         main_window_cursor_wait(summaryview->mainwin);
1150
1151         summaryview_reset_recursive_folder_match(summaryview);
1152         summaryview->search_root_folder = summaryview->folder_item;
1153
1154         summaryview_quicksearch_search_subfolders(summaryview, summaryview->folder_item);
1155         
1156         main_window_cursor_normal(summaryview->mainwin);
1157 }
1158
1159 static gboolean summary_check_consistency(FolderItem *item, GSList *mlist)
1160 {
1161         int u = 0, n = 0, m = 0, t = 0, r = 0, f = 0, l = 0, i = 0, w = 0;
1162         GSList *cur;
1163         START_TIMING("");
1164         for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1165                 MsgInfo * msginfo = (MsgInfo *) cur->data;
1166                 t++;
1167                 if (MSG_IS_NEW(msginfo->flags))
1168                         n++;
1169                 if (MSG_IS_UNREAD(msginfo->flags))
1170                         u++;
1171                 if (MSG_IS_MARKED(msginfo->flags))
1172                         m++;            
1173                 if (MSG_IS_REPLIED(msginfo->flags))
1174                         r++;
1175                 if (MSG_IS_FORWARDED(msginfo->flags))
1176                         f++;
1177                 if (MSG_IS_LOCKED(msginfo->flags))
1178                         l++;
1179                 if (MSG_IS_IGNORE_THREAD(msginfo->flags))
1180                         i++;
1181                 if (MSG_IS_WATCH_THREAD(msginfo->flags))
1182                         w++;
1183         }
1184         if (t != item->total_msgs
1185         ||  n != item->new_msgs
1186         ||  u != item->unread_msgs
1187         ||  m != item->marked_msgs
1188         ||  r != item->replied_msgs
1189         ||  f != item->forwarded_msgs
1190         ||  l != item->locked_msgs
1191         ||  i != item->ignored_msgs
1192         ||  w != item->watched_msgs
1193         ||  (m == 0 && item->unreadmarked_msgs != 0)
1194         ||  item->unreadmarked_msgs < 0) {
1195                 debug_print("Inconsistency\n");
1196                 folder_item_scan_full(item, FALSE);
1197                 END_TIMING();
1198                 return FALSE;
1199         } 
1200         END_TIMING();
1201         return TRUE;
1202 }
1203
1204 gboolean summaryview_search_root_progress(gpointer data, guint at, guint matched, guint total)
1205 {
1206         SummaryView *summaryview = (SummaryView*) data;
1207
1208         gint interval = quicksearch_is_fast(summaryview->quicksearch) ? 5000 : 100;
1209         
1210         statusbar_progress_all(at, total, interval);
1211
1212         if (at % interval == 0)
1213                 GTK_EVENTS_FLUSH();
1214
1215         return TRUE;
1216 }
1217
1218 gboolean summary_show(SummaryView *summaryview, FolderItem *item)
1219 {
1220         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1221         GtkCMCTreeNode *node = NULL;
1222         GSList *mlist = NULL;
1223         gchar *buf;
1224         gboolean is_refresh;
1225         guint selected_msgnum = 0;
1226         guint displayed_msgnum = 0;
1227         GSList *cur;
1228         GSList *not_killed;
1229         gboolean hidden_removed = FALSE;
1230
1231         if (summary_is_locked(summaryview)) return FALSE;
1232
1233         if (!summaryview->mainwin)
1234                 return FALSE;
1235         START_TIMING("");
1236         summary_switch_from_to(summaryview, item);
1237
1238         inc_lock();
1239         summary_lock(summaryview);
1240         
1241         menu_set_sensitive_all(GTK_MENU_SHELL(summaryview->popupmenu), TRUE);
1242         
1243         utils_free_regex();
1244
1245         is_refresh = (item == summaryview->folder_item) ? TRUE : FALSE;
1246
1247         if (item && item->folder->klass->item_opened) {
1248                 item->folder->klass->item_opened(item);
1249         }
1250
1251         if (!is_refresh) {
1252                 main_create_mailing_list_menu (summaryview->mainwin, NULL);
1253                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
1254                         if (item) {
1255                                 mainwindow_enter_folder(summaryview->mainwin);
1256                                 gtk_widget_grab_focus(summaryview->ctree);
1257                         }
1258                 }
1259         }
1260         if (!prefs_common.summary_quicksearch_sticky
1261          && (!prefs_common.summary_quicksearch_recurse
1262           || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1263           || (item && !folder_is_child_of(item, summaryview->search_root_folder)))
1264          && !quicksearch_is_running(summaryview->quicksearch)
1265          && !is_refresh) {
1266                 quicksearch_set(summaryview->quicksearch, prefs_common.summary_quicksearch_type, "");
1267         }
1268
1269         /* STATUSBAR_POP(summaryview->mainwin); */
1270
1271         if (is_refresh) {
1272                 selected_msgnum = summary_get_msgnum(summaryview,
1273                                                      summaryview->selected);
1274                 displayed_msgnum = summary_get_msgnum(summaryview,
1275                                                       summaryview->displayed);
1276         }
1277
1278         /* process the marks if any */
1279         if (!is_refresh &&
1280                         (summaryview->mainwin->lock_count == 0 &&
1281                          (summaryview->moved > 0 || summaryview->copied > 0))) {
1282                 AlertValue val;
1283                 gboolean changed = FALSE;
1284
1285                 val = alertpanel(_("Process mark"),
1286                                  _("Some marks are left. Process them?"),
1287                                  GTK_STOCK_NO, GTK_STOCK_YES, GTK_STOCK_CANCEL);
1288                 if (G_ALERTALTERNATE == val) {
1289                         summary_unlock(summaryview);
1290                         summary_execute(summaryview);
1291                         summary_lock(summaryview);
1292                         changed = TRUE;
1293                 } else if (G_ALERTDEFAULT == val) {
1294                         /* DO NOTHING */
1295                 } else {
1296                         summary_unlock(summaryview);
1297                         inc_unlock();
1298                         END_TIMING();
1299                         return FALSE;
1300                 }
1301                 if (changed || !quicksearch_has_sat_predicate(summaryview->quicksearch))
1302                         folder_update_op_count();
1303         }
1304         
1305         summary_freeze(summaryview);
1306
1307         summary_clear_list(summaryview);
1308
1309         buf = NULL;
1310         if (!item || !item->path || !folder_item_parent(item) || item->no_select) {
1311                 g_free(buf);
1312                 debug_print("empty folder (%p %s %p %d)\n",
1313                                 item, 
1314                                 (item && item->path)?item->path:"(null)",
1315                                 item?folder_item_parent(item):0x0,
1316                                 item?item->no_select:FALSE);
1317                 summary_set_hide_menu(summaryview, "/Menu/View/HideReadMessages", FALSE);
1318                 summary_set_hide_menu(summaryview, "/Menu/View/HideDelMessages", FALSE);
1319                 summary_set_hide_menu(summaryview, "/Menu/View/HideReadThreads", FALSE);
1320                 summary_clear_all(summaryview);
1321                 summaryview->folder_item = item;
1322                 summary_thaw(summaryview);
1323                 summary_unlock(summaryview);
1324                 inc_unlock();
1325                 END_TIMING();
1326                 return TRUE;
1327         }
1328         g_free(buf);
1329
1330         if (!is_refresh)
1331                 messageview_clear(summaryview->messageview);
1332
1333         summaryview->folder_item = item;
1334         item->opened = TRUE;
1335
1336         buf = g_strdup_printf(_("Scanning folder (%s)..."), item->path);
1337         debug_print("%s\n", buf);
1338         STATUSBAR_PUSH(summaryview->mainwin, buf);
1339         g_free(buf);
1340
1341         main_window_cursor_wait(summaryview->mainwin);
1342
1343         mlist = folder_item_get_msg_list(item);
1344
1345         if (!summary_check_consistency(item, mlist)) {
1346                 debug_print("reloading due to inconsistency\n");
1347                 procmsg_msg_list_free(mlist);
1348                 mlist = folder_item_get_msg_list(item);
1349         }
1350
1351         if (quicksearch_has_sat_predicate(summaryview->quicksearch)) {
1352                 procmsg_msg_list_free(mlist);
1353                 mlist = NULL;
1354
1355                 START_TIMING("quicksearch");
1356
1357                 statusbar_print_all(_("Searching in %s... \n"), 
1358                         summaryview->folder_item->path ? 
1359                         summaryview->folder_item->path : "(null)");
1360
1361                 folder_item_update_freeze();
1362
1363                 quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_search_root_progress, summaryview);
1364                 quicksearch_run_on_folder(summaryview->quicksearch, summaryview->folder_item, &mlist);
1365
1366                 folder_item_update_thaw();
1367                 statusbar_progress_all(0, 0, 0);
1368                 statusbar_pop_all();
1369
1370                 if (!quicksearch_has_sat_predicate(summaryview->quicksearch)) {
1371                         debug_print("search cancelled!\n");
1372                         summary_thaw(summaryview);
1373                         STATUSBAR_POP(summaryview->mainwin);
1374                         main_window_cursor_normal(summaryview->mainwin);
1375                         summary_unlock(summaryview);
1376                         inc_unlock();
1377                         summary_show(summaryview, summaryview->folder_item);
1378                         END_TIMING();
1379                         return FALSE;
1380                 }
1381                 END_TIMING();
1382         }
1383
1384         if ((summaryview->folder_item->hide_read_msgs
1385              || summaryview->folder_item->hide_del_msgs
1386              || summaryview->folder_item->hide_read_threads) &&
1387             quicksearch_has_sat_predicate(summaryview->quicksearch) == FALSE) {
1388                 GSList *not_killed;
1389                 
1390                 summary_set_hide_menu(summaryview, "/Menu/View/HideReadMessages",
1391                                                 summaryview->folder_item->hide_read_msgs);
1392                 summary_set_hide_menu(summaryview, "/Menu/View/HideDelMessages",
1393                                                 summaryview->folder_item->hide_del_msgs);
1394                 summary_set_hide_menu(summaryview, "/Menu/View/HideReadThreads",
1395                                                 summaryview->folder_item->hide_read_threads);
1396                 not_killed = NULL;
1397                 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1398                         MsgInfo * msginfo = (MsgInfo *) cur->data;
1399                         
1400                         if (!msginfo->hidden) {
1401                                 if (MSG_IS_DELETED(msginfo->flags) && summaryview->folder_item->hide_del_msgs) {
1402                                         procmsg_msginfo_free(&msginfo);
1403                                         continue;
1404                                 }
1405                                 if (summaryview->folder_item->hide_read_msgs) {
1406                                         if (MSG_IS_UNREAD(msginfo->flags) &&
1407                                             !MSG_IS_IGNORE_THREAD(msginfo->flags))
1408                                                 not_killed = g_slist_prepend(not_killed, msginfo);
1409                                         else if (MSG_IS_MARKED(msginfo->flags) ||
1410                                                  MSG_IS_LOCKED(msginfo->flags))
1411                                                 not_killed = g_slist_prepend(not_killed, msginfo);
1412                                         else if (is_refresh &&
1413                                                 (msginfo->msgnum == selected_msgnum ||
1414                                                  msginfo->msgnum == displayed_msgnum))
1415                                                 not_killed = g_slist_prepend(not_killed, msginfo);
1416                                         else
1417                                                 procmsg_msginfo_free(&msginfo);
1418                                 } else {
1419                                         not_killed = g_slist_prepend(not_killed, msginfo);
1420                                 }
1421                          } else
1422                                 procmsg_msginfo_free(&msginfo);
1423                 }
1424                 hidden_removed = TRUE;
1425                 g_slist_free(mlist);
1426                 mlist = not_killed;
1427         } else {
1428                 summary_set_hide_menu(summaryview, "/Menu/View/HideReadMessages",
1429                                                 FALSE);
1430                 summary_set_hide_menu(summaryview, "/Menu/View/HideDelMessages",
1431                                                 FALSE);
1432                 summary_set_hide_menu(summaryview, "/Menu/View/HideReadThreads",
1433                                                 FALSE);
1434         }
1435
1436         if (!hidden_removed) {
1437                 START_TIMING("removing hidden");
1438                 not_killed = NULL;
1439                 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1440                         MsgInfo * msginfo = (MsgInfo *) cur->data;
1441
1442                         if (!msginfo->hidden)
1443                                 not_killed = g_slist_prepend(not_killed, msginfo);
1444                         else
1445                                 procmsg_msginfo_free(&msginfo);
1446                 }
1447                 g_slist_free(mlist);
1448                 mlist = not_killed;
1449                 END_TIMING();
1450         }
1451
1452         STATUSBAR_POP(summaryview->mainwin);
1453
1454         /* set ctree and hash table from the msginfo list, and
1455            create the thread */
1456         summary_set_ctree_from_list(summaryview, mlist);
1457
1458         g_slist_free(mlist);
1459
1460         if (is_refresh) {
1461                 if (!quicksearch_is_in_typing(summaryview->quicksearch)) {
1462                         summaryview->displayed =
1463                                 summary_find_msg_by_msgnum(summaryview,
1464                                                            displayed_msgnum);
1465                         if (!summaryview->displayed)
1466                                 messageview_clear(summaryview->messageview);
1467                         summary_unlock(summaryview);
1468                         summary_select_by_msgnum(summaryview, selected_msgnum);
1469                         summary_lock(summaryview);
1470                         if (!summaryview->selected) {
1471                                 /* no selected message - select first unread
1472                                    message, but do not display it */
1473                                 node = summary_find_next_flagged_msg(summaryview, NULL,
1474                                                                      MSG_UNREAD, FALSE);
1475                                 if (node == NULL && GTK_CMCLIST(ctree)->row_list != NULL)
1476                                         node = gtk_cmctree_node_nth
1477                                                 (ctree,
1478                                                  item->sort_type == SORT_DESCENDING
1479                                                  ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1480                                 summary_unlock(summaryview);
1481                                 summary_select_node(summaryview, node, 0);
1482                                 summary_lock(summaryview);
1483                         }
1484                 } else {
1485                         /* just select first/last */
1486                         if (GTK_CMCLIST(ctree)->row_list != NULL)
1487                                 node = gtk_cmctree_node_nth
1488                                         (ctree,
1489                                          item->sort_type == SORT_DESCENDING
1490                                          ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1491                         summary_select_node(summaryview, node, -1);
1492                 }
1493         } else {
1494                 /* backward compat */
1495                 int i = 0;
1496                 gboolean set = FALSE, stop = FALSE;
1497                 for (i = 0; i < 6; i++) {
1498                         EntryAction act = prefs_common.summary_select_prio[i];
1499
1500                         if (act != ACTION_UNSET) {
1501                                 set = TRUE;
1502                                 break;
1503                         }
1504                 }
1505                 if (!set)
1506                         prefs_summary_open_set_defaults();
1507
1508                 for (i = 0; i < 6 && node == NULL; i++) {
1509                         EntryAction act = prefs_common.summary_select_prio[i];
1510                         
1511                         switch(act) {
1512                         case ACTION_MARKED:
1513                                 node = summary_find_next_flagged_msg(summaryview, NULL,
1514                                              MSG_MARKED, FALSE);
1515                                 break;
1516                         case ACTION_NEW:
1517                                 node = summary_find_next_flagged_msg(summaryview, NULL,
1518                                              MSG_NEW, FALSE);
1519                                 break;
1520                         case ACTION_UNREAD:
1521                                 node = summary_find_next_flagged_msg(summaryview, NULL,
1522                                              MSG_UNREAD, FALSE);
1523                                 break;
1524                         case ACTION_LAST_OPENED:
1525                                 if (summaryview->folder_item) {
1526                                         node = summary_find_msg_by_msgnum(summaryview, 
1527                                                         summaryview->folder_item->last_seen);
1528                                 }
1529                                 break;
1530                         case ACTION_LAST_LIST:
1531                                 if (GTK_CMCLIST(ctree)->row_list != NULL) {
1532                                         node = gtk_cmctree_node_nth
1533                                                 (ctree,
1534                                                  item->sort_type == SORT_DESCENDING
1535                                                  ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1536                                 }
1537                                 break;
1538                         case ACTION_FIRST_LIST:
1539                                 if (GTK_CMCLIST(ctree)->row_list != NULL) {
1540                                         node = gtk_cmctree_node_nth
1541                                                 (ctree,
1542                                                  item->sort_type == SORT_ASCENDING
1543                                                  ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1544                                 }
1545                                 break;
1546                         case ACTION_NOTHING:
1547                         case ACTION_UNSET:
1548                                 node = NULL;
1549                                 stop = TRUE;
1550                                 break;
1551                         }
1552                         
1553                         if (stop || node)
1554                                 break;
1555                 }
1556
1557                 summary_unlock(summaryview);
1558
1559                 if (node) {
1560                         gint open_selected = -1;
1561                         if (!is_refresh) {
1562                                 if (prefs_common.open_selected_on_folder_open)
1563                                         open_selected = 1;
1564                                 else
1565                                         open_selected = 0;
1566                         }
1567                         summary_select_node_no_mark_read(summaryview, node, open_selected);
1568                 }
1569
1570                 summary_lock(summaryview);
1571         }
1572
1573         summary_status_show(summaryview);
1574         summary_set_menu_sensitive(summaryview);
1575         toolbar_main_set_sensitive(summaryview->mainwin);
1576         
1577         summary_thaw(summaryview);
1578         debug_print("\n");
1579         STATUSBAR_PUSH(summaryview->mainwin, _("Done."));
1580         STATUSBAR_POP(summaryview->mainwin);
1581         main_window_cursor_normal(summaryview->mainwin);
1582         summary_unlock(summaryview);
1583         inc_unlock();
1584         END_TIMING();
1585         return TRUE;
1586 }
1587
1588 #undef CURRENTLY_DISPLAYED
1589
1590 static void summary_cancel_mark_read_timeout(SummaryView *summaryview) {
1591         if (summaryview->mark_as_read_timeout_tag != 0) {
1592                 g_source_remove(summaryview->mark_as_read_timeout_tag);
1593                 summaryview->mark_as_read_timeout_tag = 0;
1594         }
1595 }
1596
1597 void summary_clear_list(SummaryView *summaryview)
1598 {
1599         GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
1600         gint optimal_width;
1601
1602         summary_freeze(summaryview);
1603
1604         gtk_cmctree_pre_recursive(GTK_CMCTREE(summaryview->ctree),
1605                                 NULL, summary_free_msginfo_func, NULL);
1606
1607         if (summaryview->folder_item) {
1608                 summaryview->folder_item->opened = FALSE;
1609                 summaryview->folder_item = NULL;
1610         }
1611
1612         summary_cancel_mark_read_timeout(summaryview);
1613
1614         summaryview->display_msg = FALSE;
1615
1616         summaryview->selected = NULL;
1617         summaryview->displayed = NULL;
1618         summaryview->total_size = 0;
1619         summaryview->deleted = summaryview->moved = 0;
1620         summaryview->copied = 0;
1621         if (summaryview->msgid_table) {
1622                 g_hash_table_destroy(summaryview->msgid_table);
1623                 summaryview->msgid_table = NULL;
1624         }
1625         if (summaryview->subject_table) {
1626                 g_hash_table_destroy(summaryview->subject_table);
1627                 summaryview->subject_table = NULL;
1628         }
1629         summaryview->mlist = NULL;
1630
1631         gtk_cmclist_clear(clist);
1632         if (summaryview->col_pos[S_COL_SUBJECT] == N_SUMMARY_COLS - 1) {
1633                 optimal_width = gtk_cmclist_optimal_column_width
1634                         (clist, summaryview->col_pos[S_COL_SUBJECT]);
1635                 gtk_cmclist_set_column_width
1636                         (clist, summaryview->col_pos[S_COL_SUBJECT],
1637                          optimal_width);
1638         }
1639
1640         summary_thaw(summaryview);
1641 }
1642
1643 void summary_clear_all(SummaryView *summaryview)
1644 {
1645         messageview_clear(summaryview->messageview);
1646         summary_clear_list(summaryview);
1647         summary_set_menu_sensitive(summaryview);
1648         toolbar_main_set_sensitive(summaryview->mainwin);
1649         summary_status_show(summaryview);
1650 }
1651
1652 void summary_lock(SummaryView *summaryview)
1653 {
1654         summaryview->lock_count++;
1655 }
1656
1657 void summary_unlock(SummaryView *summaryview)
1658 {
1659         if (summaryview->lock_count)
1660                 summaryview->lock_count--;
1661 }
1662
1663 gboolean summary_is_locked(SummaryView *summaryview)
1664 {
1665         return summaryview->lock_count > 0;
1666 }
1667
1668 SummarySelection summary_get_selection_type(SummaryView *summaryview)
1669 {
1670         GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
1671         SummarySelection selection;
1672
1673         if (!clist->row_list)
1674                 selection = SUMMARY_NONE;
1675         else if (!clist->selection)
1676                 selection = SUMMARY_SELECTED_NONE;
1677         else if (!clist->selection->next)
1678                 selection = SUMMARY_SELECTED_SINGLE;
1679         else
1680                 selection = SUMMARY_SELECTED_MULTIPLE;
1681
1682         return selection;
1683 }
1684
1685 /*!
1686  *\return       MsgInfo * Selected message if there's one selected;
1687  *              if multiple selected, or none, return NULL.
1688  */ 
1689 MsgInfo *summary_get_selected_msg(SummaryView *summaryview)
1690 {
1691         /* summaryview->selected may be valid when multiple 
1692          * messages were selected */
1693         GList *sellist = GTK_CMCLIST(summaryview->ctree)->selection;
1694
1695         if (sellist == NULL || sellist->next) 
1696                 return NULL;
1697         
1698         return GTKUT_CTREE_NODE_GET_ROW_DATA(sellist->data);
1699 }
1700
1701 GSList *summary_get_selected_msg_list(SummaryView *summaryview)
1702 {
1703         GSList *mlist = NULL;
1704         GList *cur;
1705         MsgInfo *msginfo;
1706
1707         for (cur = GTK_CMCLIST(summaryview->ctree)->selection; cur != NULL && cur->data != NULL;
1708              cur = cur->next) {
1709                 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(cur->data);
1710                 mlist = g_slist_prepend(mlist, msginfo);
1711         }
1712
1713         mlist = g_slist_reverse(mlist);
1714
1715         return mlist;
1716 }
1717
1718 void summary_set_menu_sensitive(SummaryView *summaryview)
1719 {
1720         SensitiveCondMask state;
1721         gboolean sensitive;
1722         gint i;
1723
1724 #define N_ENTRIES 39
1725         static struct {
1726                 const gchar *entry;
1727                 SensitiveCondMask cond;
1728         } entry[N_ENTRIES];
1729
1730         i = 0;
1731 #define FILL_TABLE(entry_str, ...) \
1732 do { \
1733         entry[i].entry = (const gchar *) entry_str; entry[i++].cond = main_window_get_mask(__VA_ARGS__, -1); \
1734 } while (0)
1735
1736         FILL_TABLE("Menus/SummaryViewPopup/Reply", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1737 #ifndef GENERIC_UMPC
1738         FILL_TABLE("Menus/SummaryViewPopup/ReplyTo", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1739         FILL_TABLE("Menus/SummaryViewPopup/ReplyTo/All", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1740         FILL_TABLE("Menus/SummaryViewPopup/ReplyTo/Sender", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1741         FILL_TABLE("Menus/SummaryViewPopup/ReplyTo/MailingList", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1742 #endif
1743
1744         FILL_TABLE("Menus/SummaryViewPopup/Forward", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1745 #ifndef GENERIC_UMPC
1746         FILL_TABLE("Menus/SummaryViewPopup/ForwardAtt", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1747         FILL_TABLE("Menus/SummaryViewPopup/Redirect", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1748 #endif
1749
1750         FILL_TABLE("Menus/SummaryViewPopup/Move", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS);
1751         FILL_TABLE("Menus/SummaryViewPopup/Copy", M_TARGET_EXIST, M_EXEC);
1752         FILL_TABLE("Menus/SummaryViewPopup/Trash", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS, M_NOT_TRASH);
1753 #ifndef GENERIC_UMPC
1754         FILL_TABLE("Menus/SummaryViewPopup/Delete", M_TARGET_EXIST, M_ALLOW_DELETE);
1755 #endif
1756
1757         FILL_TABLE("Menus/SummaryViewPopup/Mark", M_TARGET_EXIST);
1758         FILL_TABLE("Menus/SummaryViewPopup/Mark/Mark", M_TARGET_EXIST);
1759         FILL_TABLE("Menus/SummaryViewPopup/Mark/Unmark", M_TARGET_EXIST);
1760         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkRead", M_TARGET_EXIST);
1761         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkUnread", M_TARGET_EXIST);
1762         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkAllRead", M_TARGET_EXIST);
1763         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkAllUnread", M_TARGET_EXIST);
1764         FILL_TABLE("Menus/SummaryViewPopup/Mark/IgnoreThread", M_TARGET_EXIST);
1765         FILL_TABLE("Menus/SummaryViewPopup/Mark/UnignoreThread", M_TARGET_EXIST);
1766         FILL_TABLE("Menus/SummaryViewPopup/Mark/WatchThread", M_TARGET_EXIST);
1767         FILL_TABLE("Menus/SummaryViewPopup/Mark/UnwatchThread", M_TARGET_EXIST);
1768         FILL_TABLE("Menus/SummaryViewPopup/Mark/Lock", M_TARGET_EXIST);
1769         FILL_TABLE("Menus/SummaryViewPopup/Mark/Unlock", M_TARGET_EXIST);
1770         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkSpam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
1771         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkHam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
1772         FILL_TABLE("Menus/SummaryViewPopup/ColorLabel", M_TARGET_EXIST);
1773         FILL_TABLE("Menus/SummaryViewPopup/Tags", M_TARGET_EXIST);
1774
1775 #ifndef GENERIC_UMPC
1776         FILL_TABLE("Menus/SummaryViewPopup/AddSenderToAB", M_SINGLE_TARGET_EXIST);
1777 #endif
1778         FILL_TABLE("Menus/SummaryViewPopup/CreateFilterRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
1779 #ifndef GENERIC_UMPC
1780         FILL_TABLE("Menus/SummaryViewPopup/CreateProcessingRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
1781 #endif
1782
1783         FILL_TABLE("Menus/SummaryViewPopup/View", M_SINGLE_TARGET_EXIST);
1784         FILL_TABLE("Menus/SummaryViewPopup/View/OpenNewWindow", M_SINGLE_TARGET_EXIST);
1785         FILL_TABLE("Menus/SummaryViewPopup/View/MessageSource", M_SINGLE_TARGET_EXIST);
1786 #ifndef GENERIC_UMPC
1787         FILL_TABLE("Menus/SummaryViewPopup/View/AllHeaders", M_SINGLE_TARGET_EXIST);
1788 #endif
1789         FILL_TABLE("Menus/SummaryViewPopup/SaveAs", M_TARGET_EXIST);
1790 #ifndef GENERIC_UMPC
1791         FILL_TABLE("Menus/SummaryViewPopup/Print", M_TARGET_EXIST);
1792 #endif
1793         FILL_TABLE(NULL, -1);
1794 #undef FILL_TABLE
1795         if (i != N_ENTRIES)
1796                 g_error("summaryview menu entry table size mismatch (%d/%d)", i, N_ENTRIES);
1797 #undef ENTRIES
1798
1799         main_window_set_menu_sensitive(summaryview->mainwin);
1800
1801         state = main_window_get_current_state(summaryview->mainwin);
1802
1803         for (i = 0; entry[i].entry != NULL; i++) {
1804                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1805                 cm_menu_set_sensitive_full(summaryview->mainwin->ui_manager, entry[i].entry, sensitive);
1806         }
1807
1808         summary_lock(summaryview);
1809 #ifndef GENERIC_UMPC
1810         if (summaryview->messageview 
1811         &&  summaryview->messageview->mimeview
1812         &&  summaryview->messageview->mimeview->textview)
1813                 cm_toggle_menu_set_active_full(summaryview->mainwin->ui_manager, "Menus/SummaryViewPopup/View/AllHeaders",
1814                         prefs_common.show_all_headers);
1815 #endif
1816         summary_unlock(summaryview);
1817 }
1818 void summary_select_prev(SummaryView *summaryview)
1819 {
1820         GtkCMCTreeNode *node = summaryview->selected;
1821         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1822
1823         if (summaryview->sort_type == SORT_ASCENDING)
1824                 node = gtkut_ctree_node_prev(ctree, node);
1825         else
1826                 node = gtkut_ctree_node_next(ctree, node);
1827
1828         if (node && node != summaryview->selected)
1829                 summary_select_node(summaryview, node, -1);
1830 }
1831
1832 void summary_select_next(SummaryView *summaryview)
1833 {
1834         GtkCMCTreeNode *node = summaryview->selected;
1835         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1836
1837         if (summaryview->sort_type == SORT_ASCENDING)
1838                 node = gtkut_ctree_node_next(ctree, node);
1839         else
1840                 node = gtkut_ctree_node_prev(ctree, node);
1841
1842         if (node && node != summaryview->selected)
1843                 summary_select_node(summaryview, node, -1);
1844 }
1845
1846 void summary_select_prev_unread(SummaryView *summaryview)
1847 {
1848         GtkCMCTreeNode *node;
1849
1850         if (summaryview->sort_type == SORT_ASCENDING)
1851                 node = summary_find_prev_flagged_msg
1852                         (summaryview, summaryview->selected, MSG_UNREAD, TRUE);
1853         else
1854                 node = summary_find_next_flagged_msg
1855                         (summaryview, summaryview->selected, MSG_UNREAD, TRUE);
1856
1857         if (!node || node == summaryview->selected) {
1858                 AlertValue val = 0;
1859
1860                 switch (prefs_common.next_unread_msg_dialog) {
1861                         case NEXTUNREADMSGDIALOG_ALWAYS:
1862                                 val = alertpanel(_("No more unread messages"),
1863                                                  _("No unread message found. "
1864                                                    "Search from the end?"),
1865                                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1866                                 break;
1867                         case NEXTUNREADMSGDIALOG_ASSUME_YES:
1868                                 val = G_ALERTALTERNATE;
1869                                 break;
1870                         case NEXTUNREADMSGDIALOG_ASSUME_NO:
1871                                 val = !G_ALERTALTERNATE;
1872                                 break;
1873                         default:
1874                                 debug_print(
1875                                         _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1876                 }
1877                 if (val != G_ALERTALTERNATE) return;
1878                 if (summaryview->sort_type == SORT_ASCENDING)
1879                         node = summary_find_prev_flagged_msg(summaryview, NULL,
1880                                                              MSG_UNREAD, FALSE);
1881                 else
1882                         node = summary_find_next_flagged_msg(summaryview, NULL,
1883                                                              MSG_UNREAD, FALSE);
1884         }
1885
1886         if (!node)
1887                 alertpanel_notice(_("No unread messages."));
1888         else
1889                 summary_select_node(summaryview, node, -1);
1890 }
1891
1892 void summary_select_next_unread(SummaryView *summaryview)
1893 {
1894         GtkCMCTreeNode *node = summaryview->selected;
1895
1896         if (summaryview->sort_type == SORT_ASCENDING)
1897                 node = summary_find_next_flagged_msg
1898                         (summaryview, node, MSG_UNREAD, TRUE);
1899         else
1900                 node = summary_find_prev_flagged_msg
1901                         (summaryview, node, MSG_UNREAD, TRUE);
1902         
1903         if (node)
1904                 summary_select_node(summaryview, node, -1);
1905         else {
1906                 AlertValue val = 0;
1907
1908                 switch (prefs_common.next_unread_msg_dialog) {
1909                         case NEXTUNREADMSGDIALOG_ALWAYS:
1910                                 val = alertpanel(_("No more unread messages"),
1911                                                  _("No unread message found. "
1912                                                    "Go to next folder?"),
1913                                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1914                                 break;
1915                         case NEXTUNREADMSGDIALOG_ASSUME_YES:
1916                                 val = G_ALERTALTERNATE;
1917                                 break;
1918                         case NEXTUNREADMSGDIALOG_ASSUME_NO:
1919                                 val = G_ALERTOTHER;
1920                                 break;
1921                         default:
1922                                 debug_print(
1923                                         _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1924                 }
1925
1926                 if (val == G_ALERTALTERNATE)
1927                         folderview_select_next_with_flag(summaryview->folderview, MSG_UNREAD);
1928         }
1929 }
1930
1931 void summary_select_prev_new(SummaryView *summaryview)
1932 {
1933         GtkCMCTreeNode *node;
1934
1935         if (summaryview->sort_type == SORT_ASCENDING)
1936                 node = summary_find_prev_flagged_msg
1937                         (summaryview, summaryview->selected, MSG_NEW, TRUE);
1938         else
1939                 node = summary_find_next_flagged_msg
1940                         (summaryview, summaryview->selected, MSG_NEW, TRUE);
1941
1942         if (!node || node == summaryview->selected) {
1943                 AlertValue val = 0;
1944
1945                 switch (prefs_common.next_unread_msg_dialog) {
1946                         case NEXTUNREADMSGDIALOG_ALWAYS:
1947                                 val = alertpanel(_("No more new messages"),
1948                                                  _("No new message found. "
1949                                                    "Search from the end?"),
1950                                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1951                                 break;
1952                         case NEXTUNREADMSGDIALOG_ASSUME_YES:
1953                                 val = G_ALERTALTERNATE;
1954                                 break;
1955                         case NEXTUNREADMSGDIALOG_ASSUME_NO:
1956                                 val = !G_ALERTALTERNATE;
1957                                 break;
1958                         default:
1959                                 debug_print(
1960                                         _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1961                 }
1962                 if (val != G_ALERTALTERNATE) return;
1963                 if (summaryview->sort_type == SORT_ASCENDING)
1964                         node = summary_find_prev_flagged_msg(summaryview, NULL,
1965                                                              MSG_NEW, FALSE);
1966                 else
1967                         node = summary_find_next_flagged_msg(summaryview, NULL,
1968                                                              MSG_NEW, FALSE);
1969         }
1970
1971         if (!node)
1972                 alertpanel_notice(_("No new messages."));
1973         else
1974                 summary_select_node(summaryview, node, -1);
1975 }
1976
1977 void summary_select_next_new(SummaryView *summaryview)
1978 {
1979         GtkCMCTreeNode *node = summaryview->selected;
1980
1981         if (summaryview->sort_type == SORT_ASCENDING)
1982                 node = summary_find_next_flagged_msg
1983                         (summaryview, node, MSG_NEW, TRUE);
1984         else
1985                 node = summary_find_prev_flagged_msg
1986                         (summaryview, node, MSG_NEW, TRUE);
1987         
1988         if (node)
1989                 summary_select_node(summaryview, node, -1);
1990         else {
1991                 AlertValue val = 0;
1992
1993                 switch (prefs_common.next_unread_msg_dialog) {
1994                         case NEXTUNREADMSGDIALOG_ALWAYS:
1995                                 val = alertpanel(_("No more new messages"),
1996                                                  _("No new message found. "
1997                                                    "Go to next folder?"),
1998                                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1999                                 break;
2000                         case NEXTUNREADMSGDIALOG_ASSUME_YES:
2001                                 val = G_ALERTALTERNATE;
2002                                 break;
2003                         case NEXTUNREADMSGDIALOG_ASSUME_NO:
2004                                 val = G_ALERTOTHER;
2005                                 break;
2006                         default:
2007                                 debug_print(
2008                                         _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
2009                 }
2010                 if (val == G_ALERTALTERNATE)
2011                         folderview_select_next_with_flag(summaryview->folderview, MSG_NEW);
2012         }
2013 }
2014
2015 void summary_select_prev_marked(SummaryView *summaryview)
2016 {
2017         GtkCMCTreeNode *node;
2018
2019         if (summaryview->sort_type == SORT_ASCENDING)
2020                 node = summary_find_prev_flagged_msg
2021                         (summaryview, summaryview->selected, MSG_MARKED, TRUE);
2022         else
2023                 node = summary_find_next_flagged_msg
2024                         (summaryview, summaryview->selected, MSG_MARKED, TRUE);
2025
2026         if (!node) {
2027                 AlertValue val;
2028
2029                 val = alertpanel(_("No more marked messages"),
2030                                  _("No marked message found. "
2031                                    "Search from the end?"),
2032                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2033                 if (val != G_ALERTALTERNATE) return;
2034                 node = summary_find_prev_flagged_msg(summaryview, NULL,
2035                                                      MSG_MARKED, TRUE);
2036         }
2037
2038         if (!node)
2039                 alertpanel_notice(_("No marked messages."));
2040         else
2041                 summary_select_node(summaryview, node, -1);
2042 }
2043
2044 void summary_select_next_marked(SummaryView *summaryview)
2045 {
2046         GtkCMCTreeNode *node = summaryview->selected;
2047
2048         if (summaryview->sort_type == SORT_ASCENDING)
2049                 node = summary_find_next_flagged_msg
2050                         (summaryview, node, MSG_MARKED, TRUE);
2051         else
2052                 node = summary_find_prev_flagged_msg
2053                         (summaryview, node, MSG_MARKED, TRUE);
2054         
2055         if (node)
2056                 summary_select_node(summaryview, node, -1);
2057         else {
2058                 AlertValue val = 0;
2059
2060                 switch (prefs_common.next_unread_msg_dialog) {
2061                         case NEXTUNREADMSGDIALOG_ALWAYS:
2062                                 val = alertpanel(_("No more marked messages"),
2063                                                  _("No marked message found. "
2064                                                    "Go to next folder?"),
2065                                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2066                                 break;
2067                         case NEXTUNREADMSGDIALOG_ASSUME_YES:
2068                                 val = G_ALERTALTERNATE;
2069                                 break;
2070                         case NEXTUNREADMSGDIALOG_ASSUME_NO:
2071                                 val = G_ALERTOTHER;
2072                                 break;
2073                         default:
2074                                 debug_print(
2075                                         _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
2076                 }
2077                 if (val == G_ALERTALTERNATE)
2078                         folderview_select_next_with_flag(summaryview->folderview, MSG_MARKED);
2079         }
2080 }
2081
2082 void summary_select_prev_labeled(SummaryView *summaryview)
2083 {
2084         GtkCMCTreeNode *node;
2085
2086         if (summaryview->sort_type == SORT_ASCENDING)
2087                 node = summary_find_prev_flagged_msg
2088                         (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2089         else
2090                 node = summary_find_next_flagged_msg
2091                         (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2092
2093         if (!node) {
2094                 AlertValue val;
2095
2096                 val = alertpanel(_("No more labeled messages"),
2097                                  _("No labeled message found. "
2098                                    "Search from the end?"),
2099                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2100                 if (val != G_ALERTALTERNATE) return;
2101                 node = summary_find_prev_flagged_msg(summaryview, NULL,
2102                                                      MSG_CLABEL_FLAG_MASK, TRUE);
2103         }
2104
2105         if (!node)
2106                 alertpanel_notice(_("No labeled messages."));
2107         else
2108                 summary_select_node(summaryview, node, -1);
2109 }
2110
2111 void summary_select_next_labeled(SummaryView *summaryview)
2112 {
2113         GtkCMCTreeNode *node;
2114
2115         if (summaryview->sort_type == SORT_ASCENDING)
2116                 node = summary_find_next_flagged_msg
2117                         (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2118         else
2119                 node = summary_find_prev_flagged_msg
2120                         (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2121
2122         if (!node) {
2123                 AlertValue val;
2124
2125                 val = alertpanel(_("No more labeled messages"),
2126                                  _("No labeled message found. "
2127                                    "Search from the beginning?"),
2128                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2129                 if (val != G_ALERTALTERNATE) return;
2130                 if (summaryview->sort_type == SORT_ASCENDING)
2131                         node = summary_find_next_flagged_msg(summaryview, NULL,
2132                                                              MSG_CLABEL_FLAG_MASK, TRUE);
2133                 else
2134                         node = summary_find_prev_flagged_msg(summaryview, NULL,
2135                                                              MSG_CLABEL_FLAG_MASK, TRUE);
2136         }
2137
2138         if (!node)
2139                 alertpanel_notice(_("No labeled messages."));
2140         else
2141                 summary_select_node(summaryview, node, -1);
2142 }
2143
2144 void summary_select_parent(SummaryView *summaryview)
2145 {
2146         GtkCMCTreeNode *node = NULL;
2147
2148         if (summaryview->selected)
2149                 node = GTK_CMCTREE_ROW(summaryview->selected)->parent;
2150         if (node)
2151                 summary_select_node(summaryview, node, -1);
2152 }
2153
2154 void summary_select_by_msgnum(SummaryView *summaryview, guint msgnum)
2155 {
2156         GtkCMCTreeNode *node;
2157
2158         node = summary_find_msg_by_msgnum(summaryview, msgnum);
2159         summary_select_node(summaryview, node, 0);
2160 }
2161
2162 void summary_display_by_msgnum(SummaryView *summaryview, guint msgnum)
2163 {
2164         GtkCMCTreeNode *node;
2165
2166         node = summary_find_msg_by_msgnum(summaryview, msgnum);
2167         summary_select_node(summaryview, node, 1);
2168 }
2169
2170 void summary_select_by_msg_list(SummaryView     *summaryview, GSList *msginfos)
2171 {
2172         GtkCMCTree *ctree;
2173         GSList *msgnum_list, *walk;
2174         gboolean froze = FALSE;
2175
2176         ctree = GTK_CMCTREE(summaryview->ctree);
2177
2178         msgnum_list = procmsg_get_number_list_for_msgs(msginfos);
2179
2180         START_LONG_OPERATION(summaryview, FALSE);
2181         for(walk = msgnum_list; walk; walk = walk->next) {
2182                 GtkCMCTreeNode *node;
2183                 node = summary_find_msg_by_msgnum(summaryview, GPOINTER_TO_UINT(walk->data));
2184                 gtk_cmctree_select(ctree, node);
2185         }
2186         END_LONG_OPERATION(summaryview);
2187         g_slist_free(msgnum_list);
2188 }
2189
2190 typedef struct _PostponedSelectData
2191 {
2192         GtkCMCTree *ctree;
2193         GtkCMCTreeNode *row;
2194         GtkCMCTreeNode *node;
2195         GtkScrollType type;
2196         gint column;
2197         SummaryView *summaryview;
2198         gboolean display_msg;
2199 } PostponedSelectData;
2200
2201 static gboolean summary_select_retry(void *data)
2202 {
2203         PostponedSelectData *psdata = (PostponedSelectData *)data;
2204         debug_print("trying again\n");
2205         if (psdata->row)
2206                 summary_selected(psdata->ctree, psdata->row,
2207                             psdata->column, psdata->summaryview);
2208         else if (psdata->node)
2209                 summary_select_node(psdata->summaryview, psdata->node,
2210                             psdata->display_msg);
2211         g_free(psdata);
2212         return FALSE;
2213 }
2214
2215 /**
2216  * summary_select_node:
2217  * @summaryview: Summary view.
2218  * @node: Summary tree node.
2219  * @force_display: -1 unset, 0 don't show the msg, 1 show the msg.
2220  *
2221  * Select @node (bringing it into view by scrolling and expanding its
2222  * thread, if necessary) and unselect all others.  If @force_display is
2223  * 1, display the corresponding message in the message view, if
2224  * @force_display is -1, obey prefs_common.always_show_msg.
2225  **/
2226
2227 void summary_select_node(SummaryView *summaryview, GtkCMCTreeNode *node,
2228                          gint force_display)
2229 {
2230         summary_select_node_real(summaryview, node, force_display, FALSE);
2231
2232 }
2233
2234 static void summary_select_node_no_mark_read(SummaryView *summaryview, GtkCMCTreeNode *node,
2235                          gint force_display)
2236 {
2237         summary_select_node_real(summaryview, node, force_display, TRUE);
2238 }
2239
2240 static void summary_select_node_real(SummaryView *summaryview, GtkCMCTreeNode *node,
2241                          gint force_display, gboolean ignore_mark_read)
2242 {
2243         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2244         gboolean display_msg;
2245         
2246         display_msg = force_display > -1? force_display :
2247                 (prefs_common.always_show_msg == OPENMSG_YES) ||
2248                 ((prefs_common.always_show_msg == OPENMSG_WHEN_VIEW_VISIBLE &&
2249                                 messageview_is_visible(summaryview->messageview)));
2250
2251         if (summary_is_locked(summaryview)
2252         && !GTK_SCTREE(ctree)->selecting_range
2253         && summaryview->messageview->mimeview
2254         && summaryview->messageview->mimeview->type == MIMEVIEW_TEXT
2255         && summaryview->messageview->mimeview->textview->loading) {
2256                 PostponedSelectData *data = g_new0(PostponedSelectData, 1);
2257                 summaryview->messageview->mimeview->textview->stop_loading = TRUE;
2258                 
2259                 data->ctree = ctree;
2260                 data->row = NULL;
2261                 data->node = node;
2262                 data->summaryview = summaryview;
2263                 data->display_msg = display_msg;
2264                 debug_print("postponing open of message till end of load\n");
2265                 g_timeout_add(100, summary_select_retry, data);
2266                 return;
2267         }
2268         if (summary_is_locked(summaryview)) {
2269                 return;
2270         }
2271         if (!summaryview->folder_item)
2272                 return;
2273         if (node) {
2274                 if (!ignore_mark_read)
2275                         summary_cancel_mark_read_timeout(summaryview);
2276                 gtkut_ctree_expand_parent_all(ctree, node);
2277
2278                 summary_lock(summaryview);
2279                 GTK_EVENTS_FLUSH();
2280                 summary_unlock(summaryview);
2281                 gtk_widget_grab_focus(GTK_WIDGET(ctree));
2282                 gtkut_ctree_node_move_if_on_the_edge(ctree, node, -1);
2283
2284                 if (display_msg && summaryview->displayed == node)
2285                         summaryview->displayed = NULL;
2286                 summaryview->display_msg = display_msg;
2287                 gtk_sctree_select(GTK_SCTREE(ctree), node);
2288                 if (summaryview->selected == NULL)
2289                         summaryview->selected = node;
2290         }
2291 }
2292
2293 guint summary_get_msgnum(SummaryView *summaryview, GtkCMCTreeNode *node)
2294 {
2295         GtkCMCTree *ctree =NULL;
2296         MsgInfo *msginfo;
2297
2298         if (!summaryview)
2299                 return 0;
2300         ctree = GTK_CMCTREE(summaryview->ctree);
2301         if (!node)
2302                 return 0;
2303         msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2304         if (msginfo)
2305                 return msginfo->msgnum;
2306         else 
2307                 return -1;
2308 }
2309
2310 static GtkCMCTreeNode *summary_find_prev_msg(SummaryView *summaryview,
2311                                              GtkCMCTreeNode *current_node,
2312                                              gboolean start_from_prev)
2313 {
2314         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2315         GtkCMCTreeNode *node;
2316         MsgInfo *msginfo;
2317
2318         if (current_node) {
2319                 if (start_from_prev)
2320                         node = gtkut_ctree_node_prev(ctree, current_node);
2321                 else
2322                         node = current_node;
2323         } else
2324                 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2325
2326         for (; node != NULL; node = gtkut_ctree_node_prev(ctree, node)) {
2327                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2328                 if (msginfo && !MSG_IS_DELETED(msginfo->flags)) break;
2329         }
2330
2331         return node;
2332 }
2333
2334 static GtkCMCTreeNode *summary_find_next_msg(SummaryView *summaryview,
2335                                             GtkCMCTreeNode *current_node,
2336                                             gboolean start_from_next)
2337 {
2338         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2339         GtkCMCTreeNode *node;
2340         MsgInfo *msginfo;
2341
2342         if (current_node) {
2343                 if (start_from_next)
2344                         node = gtkut_ctree_node_next(ctree, current_node);
2345                 else
2346                         node = current_node;
2347         } else
2348                 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2349
2350         for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2351                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2352                 if (msginfo && !MSG_IS_DELETED(msginfo->flags) 
2353                 && !MSG_IS_MOVE(msginfo->flags)) break;
2354         }
2355
2356         return node;
2357 }
2358
2359 static GtkCMCTreeNode *summary_find_prev_flagged_msg(SummaryView *summaryview,
2360                                                    GtkCMCTreeNode *current_node,
2361                                                    MsgPermFlags flags,
2362                                                    gboolean start_from_prev)
2363 {
2364         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2365         GtkCMCTreeNode *node;
2366         MsgInfo *msginfo;
2367
2368         if (current_node) {
2369                 if (start_from_prev)
2370                         node = gtkut_ctree_node_prev(ctree, current_node);
2371                 else
2372                         node = current_node;
2373         } else
2374                 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2375
2376         for (; node != NULL; node = gtkut_ctree_node_prev(ctree, node)) {
2377                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2378                 if (msginfo && (msginfo->flags.perm_flags & flags) != 0) break;
2379         }
2380
2381         return node;
2382 }
2383
2384 static GtkCMCTreeNode *summary_find_next_flagged_msg(SummaryView *summaryview,
2385                                                    GtkCMCTreeNode *current_node,
2386                                                    MsgPermFlags flags,
2387                                                    gboolean start_from_next)
2388 {
2389         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2390         GtkCMCTreeNode *node;
2391         MsgInfo *msginfo;
2392
2393         if (current_node) {
2394                 if (start_from_next)
2395                         node = gtkut_ctree_node_next(ctree, current_node);
2396                 else
2397                         node = current_node;
2398         } else
2399                 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2400
2401         for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2402                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2403                 /* Find msg with matching flags but ignore messages with
2404                    ignore flags, if searching for new or unread messages */
2405                 if ((msginfo && (msginfo->flags.perm_flags & flags) != 0) &&
2406                     !(((flags & (MSG_NEW | MSG_UNREAD)) != 0) && MSG_IS_IGNORE_THREAD(msginfo->flags)) 
2407                         )
2408                         break;
2409         }
2410
2411         return node;
2412 }
2413
2414 static GtkCMCTreeNode *summary_find_msg_by_msgnum(SummaryView *summaryview,
2415                                                 guint msgnum)
2416 {
2417         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2418         GtkCMCTreeNode *node;
2419         MsgInfo *msginfo;
2420
2421         node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2422
2423         for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2424                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2425                 if (msginfo && msginfo->msgnum == msgnum) break;
2426         }
2427
2428         return node;
2429 }
2430
2431 static guint attract_hash_func(gconstpointer key)
2432 {
2433         gchar *str;
2434         gchar *p;
2435         guint h;
2436
2437         Xstrdup_a(str, (const gchar *)key, return 0);
2438         trim_subject(str);
2439
2440         p = str;
2441         h = *p;
2442
2443         if (h) {
2444                 for (p += 1; *p != '\0'; p++)
2445                         h = (h << 5) - h + *p;
2446         }
2447
2448         return h;
2449 }
2450
2451 static gint attract_compare_func(gconstpointer a, gconstpointer b)
2452 {
2453         return subject_compare((const gchar *)a, (const gchar *)b) == 0;
2454 }
2455
2456 void summary_attract_by_subject(SummaryView *summaryview)
2457 {
2458         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2459         GtkCMCList *clist = GTK_CMCLIST(ctree);
2460         GtkCMCTreeNode *src_node;
2461         GtkCMCTreeNode *dst_node, *sibling;
2462         GtkCMCTreeNode *tmp;
2463         MsgInfo *src_msginfo, *dst_msginfo;
2464         GHashTable *subject_table;
2465
2466         debug_print("Attracting messages by subject...\n");
2467         STATUSBAR_PUSH(summaryview->mainwin,
2468                        _("Attracting messages by subject..."));
2469
2470         main_window_cursor_wait(summaryview->mainwin);
2471         summary_freeze(summaryview);
2472
2473         subject_table = g_hash_table_new(attract_hash_func,
2474                                          attract_compare_func);
2475
2476         for (src_node = GTK_CMCTREE_NODE(clist->row_list);
2477              src_node != NULL;
2478              src_node = tmp) {
2479                 tmp = GTK_CMCTREE_ROW(src_node)->sibling;
2480                 src_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(src_node);
2481                 if (!src_msginfo) continue;
2482                 if (!src_msginfo->subject) continue;
2483
2484                 /* find attracting node */
2485                 dst_node = g_hash_table_lookup(subject_table,
2486                                                src_msginfo->subject);
2487
2488                 if (dst_node) {
2489                         dst_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(dst_node);
2490
2491                         /* if the time difference is more than 20 days,
2492                            don't attract */
2493                         if (ABS(src_msginfo->date_t - dst_msginfo->date_t)
2494                             > 60 * 60 * 24 * 20)
2495                                 continue;
2496
2497                         sibling = GTK_CMCTREE_ROW(dst_node)->sibling;
2498                         if (src_node != sibling)
2499                                 gtk_cmctree_move(ctree, src_node, NULL, sibling);
2500                 }
2501
2502                 g_hash_table_insert(subject_table,
2503                                     src_msginfo->subject, src_node);
2504         }
2505
2506         g_hash_table_destroy(subject_table);
2507
2508         gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
2509
2510         summary_thaw(summaryview);
2511
2512         debug_print("Attracting messages by subject done.\n");
2513         STATUSBAR_POP(summaryview->mainwin);
2514
2515         main_window_cursor_normal(summaryview->mainwin);
2516 }
2517
2518 static void summary_free_msginfo_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2519                                       gpointer data)
2520 {
2521         MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2522
2523         if (msginfo)
2524                 procmsg_msginfo_free(&msginfo);
2525 }
2526
2527 static void summary_set_marks_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2528                                    gpointer data)
2529 {
2530         SummaryView *summaryview = data;
2531         MsgInfo *msginfo;
2532
2533         msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2534
2535         cm_return_if_fail(msginfo != NULL);
2536
2537         if (MSG_IS_DELETED(msginfo->flags))
2538                 summaryview->deleted++;
2539
2540         summaryview->total_size += msginfo->size;
2541
2542         summary_set_row_marks(summaryview, node);
2543 }
2544
2545 static void summary_update_status(SummaryView *summaryview)
2546 {
2547         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2548         GtkCMCTreeNode *node;
2549         MsgInfo *msginfo;
2550
2551         summaryview->total_size =
2552         summaryview->deleted = summaryview->moved = summaryview->copied = 0;
2553
2554         for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2555              node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2556                 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
2557                 
2558                 if (!msginfo)
2559                         continue;
2560
2561                 if (MSG_IS_DELETED(msginfo->flags))
2562                         summaryview->deleted++;
2563                 if (MSG_IS_MOVE(msginfo->flags))
2564                         summaryview->moved++;
2565                 if (MSG_IS_COPY(msginfo->flags))
2566                         summaryview->copied++;
2567                 summaryview->total_size += msginfo->size;
2568         }
2569 }
2570
2571 static void summary_status_show(SummaryView *summaryview)
2572 {
2573         gchar *str;
2574         gchar *del, *mv, *cp;
2575         gchar *sel;
2576         gchar *spc;
2577         gchar *itstr;
2578         GList *rowlist, *cur;
2579         guint n_selected = 0, n_new = 0, n_unread = 0, n_total = 0;
2580         guint n_marked = 0, n_replied = 0, n_forwarded = 0, n_locked = 0, n_ignored = 0, n_watched = 0;
2581         goffset sel_size = 0, n_size = 0;
2582         MsgInfo *msginfo;
2583         gchar *name;
2584         gchar *tooltip;
2585         
2586         if (!summaryview->folder_item) {
2587                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), "");
2588                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), "");
2589                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs),   "");
2590                 toolbar_main_set_sensitive(summaryview->mainwin);
2591                 return;
2592         }
2593
2594         rowlist = GTK_CMCLIST(summaryview->ctree)->selection;
2595         for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2596                 msginfo = gtk_cmctree_node_get_row_data
2597                         (GTK_CMCTREE(summaryview->ctree),
2598                          GTK_CMCTREE_NODE(cur->data));
2599                 if (msginfo) {
2600                         sel_size += msginfo->size;
2601                         n_selected++;
2602                 }
2603         }
2604         
2605         if (summaryview->folder_item->hide_read_msgs 
2606         || summaryview->folder_item->hide_del_msgs
2607         || summaryview->folder_item->hide_read_threads
2608         || quicksearch_has_sat_predicate(summaryview->quicksearch)) {
2609                 rowlist = GTK_CMCLIST(summaryview->ctree)->row_list;
2610                 for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2611                         msginfo = gtk_cmctree_node_get_row_data
2612                                 (GTK_CMCTREE(summaryview->ctree),
2613                                  GTK_CMCTREE_NODE(cur));
2614                         if (msginfo) {
2615                                 n_size += msginfo->size;
2616                                 n_total++;
2617                                 if (MSG_IS_NEW(msginfo->flags))
2618                                         n_new++;
2619                                 if (MSG_IS_UNREAD(msginfo->flags))
2620                                         n_unread++;
2621                                 if (MSG_IS_MARKED(msginfo->flags))
2622                                         n_marked++;
2623                                 if (MSG_IS_REPLIED(msginfo->flags))
2624                                         n_replied++;
2625                                 if (MSG_IS_FORWARDED(msginfo->flags))
2626                                         n_forwarded++;
2627                                 if (MSG_IS_LOCKED(msginfo->flags))
2628                                         n_locked++;
2629                                 if (MSG_IS_IGNORE_THREAD(msginfo->flags))
2630                                         n_ignored++;
2631                                 if (MSG_IS_WATCH_THREAD(msginfo->flags))
2632                                         n_watched++;
2633                         }
2634                 }
2635         } else {
2636                 n_new = summaryview->folder_item->new_msgs;
2637                 n_unread = summaryview->folder_item->unread_msgs;
2638                 n_marked = summaryview->folder_item->marked_msgs;
2639                 n_replied = summaryview->folder_item->replied_msgs;
2640                 n_forwarded = summaryview->folder_item->forwarded_msgs;
2641                 n_locked = summaryview->folder_item->locked_msgs;
2642                 n_ignored = summaryview->folder_item->ignored_msgs;
2643                 n_watched = summaryview->folder_item->watched_msgs;
2644                 n_total = summaryview->folder_item->total_msgs;
2645                 n_size = summaryview->total_size;
2646         }
2647
2648         name = folder_item_get_name(summaryview->folder_item);
2649         gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), name);
2650         g_free(name);
2651
2652         if (summaryview->deleted)
2653                 del = g_strdup_printf(_("%d deleted"), summaryview->deleted);
2654         else
2655                 del = g_strdup("");
2656         if (summaryview->moved)
2657                 mv = g_strdup_printf(_("%s%d moved"),
2658                                      summaryview->deleted ? _(", ") : "",
2659                                      summaryview->moved);
2660         else
2661                 mv = g_strdup("");
2662         if (summaryview->copied)
2663                 cp = g_strdup_printf(_("%s%d copied"),
2664                                      summaryview->deleted ||
2665                                      summaryview->moved ? _(", ") : "",
2666                                      summaryview->copied);
2667         else
2668                 cp = g_strdup("");
2669
2670         if (summaryview->deleted || summaryview->moved || summaryview->copied)
2671                 spc = "    ";
2672         else
2673                 spc = "";
2674
2675         if (n_selected) {
2676                 sel = g_strdup_printf(" (%s)", to_human_readable((goffset)sel_size));
2677                 itstr = g_strdup_printf(ngettext(" item selected"," items selected", n_selected));
2678         } else {
2679                 sel = g_strdup("");
2680                 itstr = g_strdup("");
2681         }
2682                 
2683         if (prefs_common.layout_mode != SMALL_LAYOUT) {
2684                 str = g_strconcat(n_selected ? itos(n_selected) : "",
2685                                                 itstr, sel, spc, del, mv, cp, NULL);
2686                 g_free(sel);
2687                 g_free(del);
2688                 g_free(mv);
2689                 g_free(cp);
2690                 g_free(itstr);
2691                 
2692                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2693                 g_free(str);
2694
2695                 str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2696                                               n_new, n_unread, n_total,
2697                                               to_human_readable((goffset)n_size));
2698
2699
2700                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs), str);
2701                 g_free(str);
2702                 tooltip = g_strdup_printf("<b>%s</b>\n"
2703                                         "<b>%s</b> %d\n"
2704                                         "<b>%s</b> %d\n"
2705                                         "<b>%s</b> %d\n"
2706                                         "<b>%s</b> %s\n\n"
2707                                         "<b>%s</b> %d\n"
2708                                         "<b>%s</b> %d\n"
2709                                         "<b>%s</b> %d\n"
2710                                         "<b>%s</b> %d\n"
2711                                         "<b>%s</b> %d\n"
2712                                         "<b>%s</b> %d",
2713                                         _("Message summary"),
2714                                         _("New:"), n_new,
2715                                         _("Unread:"), n_unread,
2716                                         _("Total:"), n_total,
2717                                         _("Size:"), to_human_readable((goffset)n_size),
2718                                         _("Marked:"), n_marked,
2719                                         _("Replied:"), n_replied,
2720                                         _("Forwarded:"), n_forwarded,
2721                                         _("Locked:"), n_locked,
2722                                         _("Ignored:"), n_ignored,
2723                                         _("Watched:"), n_watched);
2724
2725                 gtk_widget_set_tooltip_markup(GTK_WIDGET(summaryview->statlabel_msgs),
2726                                             tooltip); 
2727                 g_free(tooltip);
2728         } else {
2729                 gchar *ssize, *tsize;
2730                 if (n_selected) {
2731                         ssize = g_strdup(to_human_readable((goffset)sel_size));
2732                         tsize = g_strdup(to_human_readable((goffset)n_size));
2733                         str = g_strdup_printf(_("%d/%d selected (%s/%s), %d unread"),
2734                                 n_selected, n_total, ssize, tsize, n_unread);
2735                         g_free(ssize);
2736                         g_free(tsize);
2737                 } else
2738                         str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2739                                 n_new, n_unread, n_total, to_human_readable((goffset)n_size));
2740                 g_free(sel);
2741                 g_free(del);
2742                 g_free(mv);
2743                 g_free(cp);
2744                 g_free(itstr);
2745                 
2746                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2747                 g_free(str);
2748         }
2749
2750         summary_set_menu_sensitive(summaryview);
2751         toolbar_main_set_sensitive(summaryview->mainwin);
2752 }
2753
2754 static void summary_set_column_titles(SummaryView *summaryview)
2755 {
2756         GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
2757         FolderItem *item = summaryview->folder_item;
2758         GtkWidget *hbox;
2759         GtkWidget *label;
2760         GtkWidget *arrow;
2761         gint pos;
2762         const gchar *title;
2763         SummaryColumnType type;
2764         GtkJustification justify;
2765
2766         static FolderSortKey sort_by[N_SUMMARY_COLS] = {
2767                 SORT_BY_MARK,
2768                 SORT_BY_STATUS,
2769                 SORT_BY_MIME,
2770                 SORT_BY_SUBJECT,
2771                 SORT_BY_FROM,
2772                 SORT_BY_TO,
2773                 SORT_BY_DATE,
2774                 SORT_BY_SIZE,
2775                 SORT_BY_NUMBER,
2776                 SORT_BY_SCORE,
2777                 SORT_BY_LOCKED,
2778                 SORT_BY_TAGS
2779         };
2780
2781         for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
2782                 type = summaryview->col_state[pos].type;
2783
2784                 /* CLAWS: mime and unread are single char headers */
2785                 justify = (type == S_COL_NUMBER || type == S_COL_SIZE)
2786                         ? GTK_JUSTIFY_RIGHT : GTK_JUSTIFY_LEFT;
2787
2788                 switch (type) {
2789                 case S_COL_SUBJECT:
2790                 case S_COL_FROM:
2791                 case S_COL_TO:
2792                 case S_COL_DATE:
2793                 case S_COL_NUMBER:
2794                         if(type == S_COL_FROM && item != NULL &&
2795                                         FOLDER_SHOWS_TO_HDR(item) &&
2796                                         !summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
2797                                 type = S_COL_TO;
2798                         if(type == S_COL_NUMBER)
2799                                 title = gettext(col_label[type]);
2800                         else
2801                                 title = prefs_common_translated_header_name(col_label[type]);
2802                         break;
2803                 default:
2804                         title = gettext(col_label[type]);
2805                 }
2806
2807                 if (type == S_COL_MIME) {
2808                         label = gtk_image_new_from_pixbuf(clipxpm);
2809                         gtk_widget_show(label);
2810                         gtk_cmclist_set_column_widget(clist, pos, label);
2811                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Attachment"));
2812                         continue;
2813                 } else if (type == S_COL_MARK) {
2814                         label = gtk_image_new_from_pixbuf(markxpm);
2815                         gtk_widget_show(label);
2816                         gtk_cmclist_set_column_widget(clist, pos, label);
2817                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Mark"));
2818                         continue;
2819                 } else if (type == S_COL_LOCKED) {
2820                         label = gtk_image_new_from_pixbuf(lockedxpm);
2821                         gtk_widget_show(label);
2822                         gtk_cmclist_set_column_widget(clist, pos, label);
2823                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Locked"));
2824                         continue;
2825                 } else if (type == S_COL_STATUS) {
2826                         gtk_cmclist_set_column_title(clist, pos, title);
2827                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Status"));
2828                         continue;
2829                 }
2830
2831                 hbox  = gtk_hbox_new(FALSE, 4);
2832                 label = gtk_label_new(title);
2833 #ifdef GENERIC_UMPC
2834         gtk_widget_set_size_request(hbox, -1, 20);
2835 #endif
2836
2837                 if (justify == GTK_JUSTIFY_RIGHT)
2838                         gtk_box_pack_end(GTK_BOX(hbox), label,
2839                                          FALSE, FALSE, 0);
2840                 else
2841                         gtk_box_pack_start(GTK_BOX(hbox), label,
2842                                            FALSE, FALSE, 0);
2843
2844                 if (summaryview->sort_key == sort_by[type] ||
2845                     (summaryview->sort_key == SORT_BY_THREAD_DATE &&
2846                      sort_by[SORT_BY_DATE] && type == S_COL_DATE)) {
2847                         arrow = gtk_arrow_new
2848                                 (summaryview->sort_type == SORT_ASCENDING
2849                                  ? GTK_ARROW_DOWN : GTK_ARROW_UP,
2850                                  GTK_SHADOW_IN);
2851                         gtk_widget_set_size_request(GTK_WIDGET(arrow), 10, 10);
2852                         if (justify == GTK_JUSTIFY_RIGHT)
2853                                 gtk_box_pack_start(GTK_BOX(hbox), arrow,
2854                                                    FALSE, FALSE, 0);
2855                         else
2856                                 gtk_box_pack_end(GTK_BOX(hbox), arrow,
2857                                                  FALSE, FALSE, 0);
2858                 }
2859
2860                 gtk_widget_show_all(hbox);
2861                 gtk_cmclist_set_column_widget(clist, pos, hbox);
2862         }
2863 }
2864
2865 void summary_reflect_tags_changes(SummaryView *summaryview)
2866 {
2867         GtkMenuShell *menu;
2868         GList *children, *cur;
2869         GtkCMCTreeNode *node;
2870         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2871         gboolean froze = FALSE;
2872         gboolean redisplay = FALSE;
2873
2874         /* re-create colorlabel submenu */
2875         menu = GTK_MENU_SHELL(summaryview->tags_menu);
2876         cm_return_if_fail(menu != NULL);
2877
2878         /* clear items. get item pointers. */
2879         children = gtk_container_get_children(GTK_CONTAINER(menu));
2880         for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
2881                 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
2882         }
2883         g_list_free(children);
2884         summary_tags_menu_create(summaryview, TRUE);
2885
2886         START_LONG_OPERATION(summaryview, TRUE);
2887         for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
2888              node = gtkut_ctree_node_next(ctree, node)) {
2889                 redisplay |= summary_set_row_tag(summaryview,
2890                                            node, TRUE, FALSE, 0);
2891         }
2892         END_LONG_OPERATION(summaryview);
2893         if (redisplay)
2894                 summary_redisplay_msg(summaryview);
2895 }
2896
2897
2898 void summary_reflect_prefs(void)
2899 {
2900         static gchar *last_smallfont = NULL;
2901         static gchar *last_normalfont = NULL;
2902         static gchar *last_boldfont = NULL;
2903         static gboolean last_derive = 0;
2904         gboolean update_font = FALSE;
2905         SummaryView *summaryview = NULL;
2906
2907         if (!mainwindow_get_mainwindow())
2908                 return;
2909         summaryview = mainwindow_get_mainwindow()->summaryview;
2910
2911         if (!last_smallfont || strcmp(last_smallfont, SMALL_FONT) ||
2912                         !last_normalfont || strcmp(last_normalfont, NORMAL_FONT) ||
2913                         !last_boldfont || strcmp(last_boldfont, BOLD_FONT) ||
2914                         last_derive != prefs_common.derive_from_normal_font)
2915                 update_font = TRUE;
2916
2917         g_free(last_smallfont);
2918         last_smallfont = g_strdup(SMALL_FONT);
2919         g_free(last_normalfont);
2920         last_normalfont = g_strdup(NORMAL_FONT);
2921         g_free(last_boldfont);
2922         last_boldfont = g_strdup(BOLD_FONT);
2923         last_derive = prefs_common.derive_from_normal_font;
2924
2925 #define STYLE_FREE(s)                   \
2926         if (s != NULL) {                \
2927                 g_object_unref(s);      \
2928                 s = NULL;               \
2929         }
2930
2931         if (update_font) {
2932                 STYLE_FREE(bold_style);
2933                 STYLE_FREE(bold_style);
2934                 STYLE_FREE(bold_marked_style);
2935                 STYLE_FREE(bold_deleted_style);
2936                 STYLE_FREE(small_style);
2937                 STYLE_FREE(small_marked_style);
2938                 STYLE_FREE(small_deleted_style);
2939                 summary_set_fonts(summaryview);
2940         }
2941
2942 #undef STYLE_FREE
2943
2944         summary_set_column_titles(summaryview);
2945         summary_relayout(summaryview);
2946         
2947         if (summaryview->folder_item)
2948                 summary_show(summaryview, summaryview->folder_item);
2949 }
2950
2951 void summary_sort(SummaryView *summaryview,
2952                   FolderSortKey sort_key, FolderSortType sort_type)
2953 {
2954         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2955         GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
2956         GtkCMCListCompareFunc cmp_func = NULL;
2957         START_TIMING("");
2958         g_signal_handlers_block_by_func(G_OBJECT(summaryview->ctree),
2959                                        G_CALLBACK(summary_tree_expanded), summaryview);
2960         summary_freeze(summaryview);
2961
2962         switch (sort_key) {
2963         case SORT_BY_MARK:
2964                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_mark;
2965                 break;
2966         case SORT_BY_STATUS:
2967                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_status;
2968                 break;
2969         case SORT_BY_MIME:
2970                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_mime;
2971                 break;
2972         case SORT_BY_NUMBER:
2973                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_num;
2974                 break;
2975         case SORT_BY_SIZE:
2976                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_size;
2977                 break;
2978         case SORT_BY_DATE:
2979                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_date;
2980                 break;
2981         case SORT_BY_THREAD_DATE:
2982                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_thread_date;
2983                 break;
2984         case SORT_BY_FROM:
2985                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_from;
2986                 break;
2987         case SORT_BY_SUBJECT:
2988                 if (summaryview->simplify_subject_preg)
2989                         cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_simplified_subject;
2990                 else
2991                         cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_subject;
2992                 break;
2993         case SORT_BY_SCORE:
2994                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_score;
2995                 break;
2996         case SORT_BY_LABEL:
2997                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_label;
2998                 break;
2999         case SORT_BY_TO:
3000                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_to;
3001                 break;
3002         case SORT_BY_LOCKED:
3003                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_locked;
3004                 break;
3005         case SORT_BY_TAGS:
3006                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_tags;
3007                 break;
3008         case SORT_BY_NONE:
3009                 break;
3010         default:
3011                 goto unlock;
3012         }
3013
3014         summaryview->sort_key = sort_key;
3015         summaryview->sort_type = sort_type;
3016
3017         summary_set_column_titles(summaryview);
3018         summary_set_menu_sensitive(summaryview);
3019
3020         /* allow fallback to don't sort */
3021         if (summaryview->sort_key == SORT_BY_NONE)
3022                 goto unlock;
3023
3024         if (cmp_func != NULL) {
3025                 debug_print("Sorting summary...\n");
3026                 STATUSBAR_PUSH(summaryview->mainwin, _("Sorting summary..."));
3027
3028                 main_window_cursor_wait(summaryview->mainwin);
3029
3030                 gtk_cmclist_set_compare_func(clist, cmp_func);
3031
3032                 gtk_cmclist_set_sort_type(clist, (GtkSortType)sort_type);
3033                 gtk_sctree_sort_recursive(ctree, NULL);
3034
3035                 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
3036
3037                 main_window_cursor_normal(summaryview->mainwin);
3038
3039                 debug_print("Sorting summary done.\n");
3040                 STATUSBAR_POP(summaryview->mainwin);
3041         }
3042 unlock:
3043         summary_thaw(summaryview);
3044         g_signal_handlers_unblock_by_func(G_OBJECT(summaryview->ctree),
3045                                        G_CALLBACK(summary_tree_expanded), summaryview);
3046         END_TIMING();
3047 }
3048
3049 static gboolean summary_update_thread_age(GNode *node, gpointer data)
3050 {
3051         MsgInfo *msginfo = node->data;
3052         time_t *most_recent = (time_t *)data;
3053
3054         if (msginfo->date_t > *most_recent) {
3055                 *most_recent = msginfo->date_t;
3056         }
3057         return FALSE;
3058 }       
3059
3060 static void summary_find_thread_age(GNode *gnode)
3061 {
3062         MsgInfo *msginfo = (MsgInfo *)gnode->data;
3063         time_t most_recent;
3064
3065         if (!msginfo)
3066                 return;
3067         most_recent = msginfo->thread_date = msginfo->date_t;
3068
3069         g_node_traverse(gnode, G_IN_ORDER, G_TRAVERSE_ALL, -1, summary_update_thread_age, &most_recent);
3070
3071         msginfo->thread_date = most_recent;
3072 }
3073
3074 static gboolean summary_update_is_read(GNode *node, gpointer data)
3075 {
3076         MsgInfo *msginfo = node->data;
3077         gboolean *all_read = (gboolean *)data;
3078
3079         if (MSG_IS_UNREAD(msginfo->flags)) {
3080                 *all_read = FALSE;
3081                 return TRUE;
3082         }
3083         return FALSE;
3084 }       
3085
3086 static gboolean summary_thread_is_read(GNode *gnode)
3087 {
3088         MsgInfo *msginfo = (MsgInfo *)gnode->data;
3089         gboolean all_read = TRUE;
3090
3091         if (!msginfo)
3092                 return all_read;
3093
3094         g_node_traverse(gnode, G_IN_ORDER, G_TRAVERSE_ALL, -1, summary_update_is_read, &all_read);
3095     return all_read;
3096 }
3097
3098 static gboolean summary_insert_gnode_func(GtkCMCTree *ctree, guint depth, GNode *gnode,
3099                                    GtkCMCTreeNode *cnode, gpointer data)
3100 {
3101         SummaryView *summaryview = (SummaryView *)data;
3102         MsgInfo *msginfo = (MsgInfo *)gnode->data;
3103         gchar *text[N_SUMMARY_COLS];
3104         gint *col_pos = summaryview->col_pos;
3105         const gchar *msgid = msginfo->msgid;
3106         GHashTable *msgid_table = summaryview->msgid_table;
3107         gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3108         gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
3109
3110         summary_set_header(summaryview, text, msginfo);
3111
3112         gtk_cmctree_set_node_info(ctree, cnode, text[col_pos[S_COL_SUBJECT]], 2,
3113                                 NULL, NULL, FALSE, summaryview->threaded && !summaryview->thread_collapsed);
3114 #define SET_TEXT(col) {                                         \
3115         gtk_cmctree_node_set_text(ctree, cnode, col_pos[col],   \
3116                                 text[col_pos[col]]);            \
3117 }
3118
3119         if (summaryview->col_state[summaryview->col_pos[S_COL_NUMBER]].visible)
3120                 SET_TEXT(S_COL_NUMBER);
3121         if (summaryview->col_state[summaryview->col_pos[S_COL_SCORE]].visible)
3122                 SET_TEXT(S_COL_SCORE);
3123         if (summaryview->col_state[summaryview->col_pos[S_COL_SIZE]].visible)
3124                 SET_TEXT(S_COL_SIZE);
3125         if (summaryview->col_state[summaryview->col_pos[S_COL_DATE]].visible)
3126                 SET_TEXT(S_COL_DATE);
3127         if (summaryview->col_state[summaryview->col_pos[S_COL_FROM]].visible)
3128                 SET_TEXT(S_COL_FROM);
3129         if (summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
3130                 SET_TEXT(S_COL_TO);
3131         if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible)
3132                 SET_TEXT(S_COL_TAGS);
3133
3134         if ((vert_layout || small_layout) && prefs_common.two_line_vert)
3135                 g_free(text[summaryview->col_pos[S_COL_SUBJECT]]);
3136
3137 #undef SET_TEXT
3138
3139         GTKUT_CTREE_NODE_SET_ROW_DATA(cnode, msginfo);
3140         summary_set_marks_func(ctree, cnode, summaryview);
3141
3142         if (msgid && msgid[0] != '\0')
3143                 g_hash_table_insert(msgid_table, (gchar *)msgid, cnode);
3144
3145         return TRUE;
3146 }
3147
3148 static void summary_set_ctree_from_list(SummaryView *summaryview,
3149                                         GSList *mlist)
3150 {
3151         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3152         MsgInfo *msginfo;
3153         GtkCMCTreeNode *node = NULL;
3154         GHashTable *msgid_table;
3155         GHashTable *subject_table = NULL;
3156         GSList * cur;
3157         gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3158         gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
3159         START_TIMING("");
3160         
3161         if (!mlist) return;
3162
3163         debug_print("Setting summary from message data...\n");
3164         STATUSBAR_PUSH(summaryview->mainwin,
3165                        _("Setting summary from message data..."));
3166         gdk_flush();
3167
3168         g_signal_handlers_block_by_func(G_OBJECT(ctree),
3169                                        G_CALLBACK(summary_tree_expanded), summaryview);
3170
3171         msgid_table = g_hash_table_new(g_str_hash, g_str_equal);
3172         summaryview->msgid_table = msgid_table;
3173
3174         if (prefs_common.thread_by_subject) {
3175                 subject_table = g_hash_table_new(g_str_hash, g_str_equal);
3176                 summaryview->subject_table = subject_table;
3177         } else {
3178                 summaryview->subject_table = NULL;
3179         }
3180
3181         if (prefs_common.use_addr_book)
3182                 start_address_completion(NULL);
3183         
3184         if (summaryview->threaded) {
3185                 GNode *root, *gnode;
3186                 START_TIMING("threaded");
3187                 root = procmsg_get_thread_tree(mlist);
3188
3189                 
3190                 for (gnode = root->children; gnode != NULL;
3191                      gnode = gnode->next) {
3192             if (!summaryview->folder_item->hide_read_threads ||
3193                     !summary_thread_is_read(gnode))
3194             {
3195                 summary_find_thread_age(gnode);
3196                 node = gtk_sctree_insert_gnode
3197                     (ctree, NULL, node, gnode,
3198                      summary_insert_gnode_func, summaryview);
3199             }
3200                 }
3201
3202                 g_node_destroy(root);
3203                 
3204                 END_TIMING();
3205         } else {
3206                 gchar *text[N_SUMMARY_COLS];
3207                 START_TIMING("unthreaded");
3208                 cur = mlist;
3209                 for (; mlist != NULL; mlist = mlist->next) {
3210                         msginfo = (MsgInfo *)mlist->data;
3211
3212                         summary_set_header(summaryview, text, msginfo);
3213
3214                         node = gtk_sctree_insert_node
3215                                 (ctree, NULL, node, text, 2,
3216                                  NULL, NULL,
3217                                  FALSE, FALSE);
3218                         if ((vert_layout || small_layout) && prefs_common.two_line_vert)
3219                                 g_free(text[summaryview->col_pos[S_COL_SUBJECT]]);
3220
3221                         GTKUT_CTREE_NODE_SET_ROW_DATA(node, msginfo);
3222                         summary_set_marks_func(ctree, node, summaryview);
3223
3224                         if (msginfo->msgid && msginfo->msgid[0] != '\0')
3225                                 g_hash_table_insert(msgid_table,
3226                                                     msginfo->msgid, node);
3227
3228                         if (prefs_common.thread_by_subject)
3229                                 subject_table_insert(subject_table,
3230                                              msginfo->subject,
3231                                              node);
3232                 }
3233                 mlist = cur;
3234                 END_TIMING();
3235         }
3236
3237         if (prefs_common.enable_hscrollbar &&
3238             summaryview->col_pos[S_COL_SUBJECT] == N_SUMMARY_COLS - 1) {
3239                 gint optimal_width;
3240
3241                 optimal_width = gtk_cmclist_optimal_column_width
3242                         (GTK_CMCLIST(ctree), summaryview->col_pos[S_COL_SUBJECT]);
3243                 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree),
3244                                            summaryview->col_pos[S_COL_SUBJECT],
3245                                            optimal_width);
3246         }
3247
3248         if (prefs_common.use_addr_book)
3249                 end_address_completion();
3250
3251         debug_print("Setting summary from message data done.\n");
3252         STATUSBAR_POP(summaryview->mainwin);
3253         if (debug_get_mode()) {
3254                 debug_print("\tmsgid hash table size = %d\n",
3255                             g_hash_table_size(msgid_table));
3256                 if (prefs_common.thread_by_subject)
3257                         debug_print("\tsubject hash table size = %d\n",
3258                             g_hash_table_size(subject_table));
3259         }
3260
3261         summary_sort(summaryview, summaryview->sort_key, summaryview->sort_type);
3262
3263         node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
3264
3265         if (prefs_common.bold_unread) {
3266                 START_TIMING("bold_unread");
3267                 while (node) {
3268                         GtkCMCTreeNode *next = GTK_CMCTREE_NODE_NEXT(node);
3269                         if (GTK_CMCTREE_ROW(node)->children)
3270                                 summary_set_row_marks(summaryview, node);
3271                         node = next;
3272                 }
3273                 END_TIMING();
3274         }
3275
3276         g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
3277                                        G_CALLBACK(summary_tree_expanded), summaryview);
3278         END_TIMING();
3279 }
3280
3281 static gchar *summary_complete_address(const gchar *addr)
3282 {
3283         gint count;
3284         gchar *res, *tmp, *email_addr;
3285         
3286         if (addr == NULL || !strchr(addr, '@'))
3287                 return NULL;
3288
3289         Xstrdup_a(email_addr, addr, return NULL);
3290         extract_address(email_addr);
3291         if (!*email_addr)
3292                 return NULL;
3293
3294         /*
3295          * completion stuff must be already initialized
3296          */
3297         res = NULL;
3298         if (1 < (count = complete_address(email_addr))) {
3299                 tmp = get_complete_address(1);
3300                 res = procheader_get_fromname(tmp);
3301                 g_free(tmp);
3302         }
3303
3304         return res;
3305 }
3306
3307 static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
3308                                MsgInfo *msginfo)
3309 {
3310         static gchar date_modified[80];
3311         static gchar col_score[11];
3312         static gchar buf[BUFFSIZE], tmp1[BUFFSIZE], tmp2[BUFFSIZE], tmp3[BUFFSIZE];
3313         gint *col_pos = summaryview->col_pos;
3314         gchar *from_text = NULL, *to_text = NULL, *tags_text = NULL;
3315         gboolean should_swap = FALSE;
3316         gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3317         gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
3318         static const gchar *color_dim_rgb = NULL;
3319         if (!color_dim_rgb)
3320                 color_dim_rgb = gdk_color_to_string(&summaryview->color_dim);
3321         text[col_pos[S_COL_FROM]]   = "";
3322         text[col_pos[S_COL_TO]]     = "";
3323         text[col_pos[S_COL_SUBJECT]]= "";
3324         text[col_pos[S_COL_MARK]]   = "";
3325         text[col_pos[S_COL_STATUS]] = "";
3326         text[col_pos[S_COL_MIME]]   = "";
3327         text[col_pos[S_COL_LOCKED]] = "";
3328         text[col_pos[S_COL_DATE]]   = "";
3329         text[col_pos[S_COL_TAGS]]   = "";
3330         if (summaryview->col_state[summaryview->col_pos[S_COL_NUMBER]].visible)
3331                 text[col_pos[S_COL_NUMBER]] = itos(msginfo->msgnum);
3332         else
3333                 text[col_pos[S_COL_NUMBER]] = "";
3334
3335         /* slow! */
3336         if (summaryview->col_state[summaryview->col_pos[S_COL_SIZE]].visible)
3337                 text[col_pos[S_COL_SIZE]] = to_human_readable(msginfo->size);
3338         else
3339                 text[col_pos[S_COL_SIZE]] = "";
3340
3341         if (summaryview->col_state[summaryview->col_pos[S_COL_SCORE]].visible)
3342                 text[col_pos[S_COL_SCORE]] = itos_buf(col_score, msginfo->score);
3343         else
3344                 text[col_pos[S_COL_SCORE]] = "";
3345
3346         if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible) {
3347                 tags_text = procmsg_msginfo_get_tags_str(msginfo);
3348                 if (!tags_text) {
3349                         text[col_pos[S_COL_TAGS]] = "-";
3350                 } else {
3351                         strncpy2(tmp1, tags_text, sizeof(tmp1));
3352                         tmp1[sizeof(tmp1)-1]='\0';
3353                         g_free(tags_text);
3354                         text[col_pos[S_COL_TAGS]] = tmp1;
3355                 }
3356         } else
3357                 text[col_pos[S_COL_TAGS]] = "";
3358
3359         /* slow! */
3360         if (summaryview->col_state[summaryview->col_pos[S_COL_DATE]].visible || 
3361             ((vert_layout || small_layout) && prefs_common.two_line_vert)) {
3362                 if (msginfo->date_t && msginfo->date_t > 0) {
3363                         procheader_date_get_localtime(date_modified,
3364                                                       sizeof(date_modified),
3365                                                       msginfo->date_t);
3366                         text[col_pos[S_COL_DATE]] = date_modified;
3367                 } else if (msginfo->date)
3368                         text[col_pos[S_COL_DATE]] = msginfo->date;
3369                 else
3370                         text[col_pos[S_COL_DATE]] = _("(No Date)");
3371         }
3372         
3373         if (prefs_common.swap_from && msginfo->from && msginfo->to
3374         &&  !summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible) {
3375                 gchar *addr = NULL;
3376                 
3377                 addr = g_strdup(msginfo->from);
3378
3379                 if (addr) {
3380                         extract_address(addr);
3381                         if (account_find_from_address(addr, FALSE)) {
3382                                 should_swap = TRUE;
3383                         }
3384                         g_free(addr);
3385                 }
3386         }
3387
3388         if (!prefs_common.use_addr_book) {
3389                 if (prefs_common.summary_from_show == SHOW_NAME)
3390                         from_text = msginfo->fromname;
3391                 else if (prefs_common.summary_from_show == SHOW_BOTH)
3392                         from_text = msginfo->from;
3393                 else {
3394                         from_text = msginfo->from;
3395                         extract_address(from_text);
3396                 }
3397                 if (!from_text)
3398                         from_text = _("(No From)");
3399         } else {
3400                 gchar *tmp = summary_complete_address(msginfo->from);
3401                 if (tmp) {
3402                         strncpy2(buf, tmp, sizeof(buf));
3403                         g_free(tmp);
3404                         from_text = buf;
3405                 } else {
3406                         if (prefs_common.summary_from_show == SHOW_NAME)
3407                                 from_text = msginfo->fromname;
3408                         else if (prefs_common.summary_from_show == SHOW_BOTH)
3409                                 from_text = msginfo->from;
3410                         else {
3411                                 from_text = msginfo->from;
3412                                 if (from_text)
3413                                         extract_address(from_text);
3414                         }
3415                         if (!from_text)
3416                                 from_text = _("(No From)");
3417                 }
3418         }
3419         
3420         to_text = msginfo->to ? msginfo->to : 
3421                    (msginfo->cc ? msginfo->cc :
3422                      (msginfo->newsgroups ? msginfo->newsgroups : _("(No Recipient)")
3423                      )
3424                    );
3425
3426         text[col_pos[S_COL_TO]] = to_text;
3427         if (!should_swap) {
3428                 text[col_pos[S_COL_FROM]] = from_text;
3429         } else {
3430                 if (prefs_common.use_addr_book) {
3431                         gchar *tmp = summary_complete_address(to_text);
3432                         if (tmp) {
3433                                 strncpy2(buf, tmp, sizeof(buf));
3434                                 g_free(tmp);
3435                                 to_text = buf;
3436                         } else {
3437                                 to_text = to_text ? to_text : _("(No From)");
3438                         }
3439                 }
3440                 snprintf(tmp2, BUFFSIZE-1, "➜ %s", to_text);
3441                 tmp2[BUFFSIZE-1]='\0';
3442                 text[col_pos[S_COL_FROM]] = tmp2;
3443         }
3444         
3445         if (summaryview->simplify_subject_preg != NULL)
3446                 text[col_pos[S_COL_SUBJECT]] = msginfo->subject ? 
3447                         string_remove_match(tmp3, BUFFSIZE, msginfo->subject, 
3448                                         summaryview->simplify_subject_preg) : 
3449                         _("(No Subject)");
3450         else 
3451                 text[col_pos[S_COL_SUBJECT]] = msginfo->subject ? msginfo->subject :
3452                         _("(No Subject)");
3453         if ((vert_layout || small_layout) && prefs_common.two_line_vert) {
3454                 if (!FOLDER_SHOWS_TO_HDR(summaryview->folder_item)) {
3455                         gchar *tmp = g_markup_printf_escaped(g_strconcat("%s\n",
3456                                                                         "<span color='%s' style='italic'>",
3457                                                                         _("From: %s, on %s"), "</span>", NULL),
3458                                         text[col_pos[S_COL_SUBJECT]],
3459                                         color_dim_rgb,
3460                                         text[col_pos[S_COL_FROM]],
3461                                         text[col_pos[S_COL_DATE]]);
3462                         text[col_pos[S_COL_SUBJECT]] = tmp;
3463                 } else {
3464                         gchar *tmp = g_markup_printf_escaped(g_strconcat("%s\n",
3465                                                                          "<span color='%s' style='italic'>",
3466                                                                         _("To: %s, on %s"), "</span>", NULL),
3467                                         text[col_pos[S_COL_SUBJECT]],
3468                                         color_dim_rgb,
3469                                         text[col_pos[S_COL_TO]],
3470                                         text[col_pos[S_COL_DATE]]);
3471                         text[col_pos[S_COL_SUBJECT]] = tmp;
3472                 }
3473         }
3474 }
3475
3476 static void summary_display_msg(SummaryView *summaryview, GtkCMCTreeNode *row)
3477 {
3478         summary_display_msg_full(summaryview, row, FALSE, FALSE);
3479 }
3480
3481 static gboolean defer_change(gpointer data);
3482 typedef struct _ChangeData {
3483         MsgInfo *info;
3484         gint op; /* 0, 1, 2 for unset, set, change */
3485         MsgPermFlags set_flags;
3486         MsgTmpFlags  set_tmp_flags;
3487         MsgPermFlags unset_flags;
3488         MsgTmpFlags  unset_tmp_flags;
3489 } ChangeData;
3490
3491 static void summary_msginfo_unset_flags(MsgInfo *msginfo, MsgPermFlags flags, MsgTmpFlags tmp_flags)
3492 {
3493         if (!msginfo->folder || !msginfo->folder->processing_pending) {
3494                 debug_print("flags: doing unset now\n");
3495                 procmsg_msginfo_unset_flags(msginfo, flags, tmp_flags);
3496         } else {
3497                 ChangeData *unset_data = g_new0(ChangeData, 1);
3498                 unset_data->info = msginfo;
3499                 unset_data->op = 0;
3500                 unset_data->unset_flags = flags;
3501                 unset_data->unset_tmp_flags = tmp_flags;
3502                 debug_print("flags: deferring unset\n");
3503                 g_timeout_add(100, defer_change, unset_data);
3504         }
3505 }
3506
3507 static void summary_msginfo_set_flags(MsgInfo *msginfo, MsgPermFlags flags, MsgTmpFlags tmp_flags)
3508 {
3509         if (!msginfo->folder || !msginfo->folder->processing_pending) {
3510                 debug_print("flags: doing set now\n");
3511                 procmsg_msginfo_set_flags(msginfo, flags, tmp_flags);
3512         } else {
3513                 ChangeData *set_data = g_new0(ChangeData, 1);
3514                 set_data->info = msginfo;
3515                 set_data->op = 1;
3516                 set_data->set_flags = flags;
3517                 set_data->set_tmp_flags = tmp_flags;
3518                 debug_print("flags: deferring set\n");
3519                 g_timeout_add(100, defer_change, set_data);
3520         }
3521 }
3522
3523 static void summary_msginfo_change_flags(MsgInfo *msginfo, 
3524                 MsgPermFlags add_flags, MsgTmpFlags add_tmp_flags,
3525                 MsgPermFlags rem_flags, MsgTmpFlags rem_tmp_flags)
3526 {
3527         if (!msginfo->folder || !msginfo->folder->processing_pending) {
3528                 debug_print("flags: doing change now\n");
3529                 procmsg_msginfo_change_flags(msginfo, add_flags, add_tmp_flags,
3530                         rem_flags, rem_tmp_flags);
3531         } else {
3532                 ChangeData *change_data = g_new0(ChangeData, 1);
3533                 change_data->info = msginfo;
3534                 change_data->op = 2;
3535                 change_data->set_flags = add_flags;
3536                 change_data->set_tmp_flags = add_tmp_flags;
3537                 change_data->unset_flags = rem_flags;
3538                 change_data->unset_tmp_flags = rem_tmp_flags;
3539                 debug_print("flags: deferring change\n");
3540                 g_timeout_add(100, defer_change, change_data);
3541         }
3542 }
3543
3544 gboolean defer_change(gpointer data)
3545 {
3546         ChangeData *chg = (ChangeData *)data;
3547         if (chg->info->folder && chg->info->folder->processing_pending) {
3548                 debug_print("flags: trying later\n");
3549                 return TRUE; /* try again */
3550         } else {
3551                 debug_print("flags: finally doing it\n");
3552                 switch(chg->op) {
3553                 case 0:
3554                         procmsg_msginfo_unset_flags(chg->info, chg->unset_flags, chg->unset_tmp_flags);
3555                         break;
3556                 case 1:
3557                         procmsg_msginfo_set_flags(chg->info, chg->set_flags, chg->set_tmp_flags);
3558                         break;
3559                 case 2:
3560                         procmsg_msginfo_change_flags(chg->info, chg->set_flags, chg->set_tmp_flags,
3561                                 chg->unset_flags, chg->unset_tmp_flags);
3562                         break;
3563                 default:
3564                         g_warning("unknown change op");
3565                 }
3566                 g_free(chg);
3567         }
3568         return FALSE;
3569 }
3570
3571 static void msginfo_mark_as_read (SummaryView *summaryview, MsgInfo *msginfo,
3572                                       GtkCMCTreeNode *row)
3573 {
3574         cm_return_if_fail(summaryview != NULL);
3575         cm_return_if_fail(msginfo != NULL);
3576         cm_return_if_fail(row != NULL);
3577
3578         if (MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)) {
3579                 summary_msginfo_unset_flags
3580                         (msginfo, MSG_NEW | MSG_UNREAD, 0);
3581                 summary_set_row_marks(summaryview, row);
3582                 summary_status_show(summaryview);
3583         }
3584 }
3585
3586 typedef struct  {
3587         MsgInfo *msginfo;
3588         SummaryView *summaryview;
3589 } MarkAsReadData;
3590
3591 static int msginfo_mark_as_read_timeout(void *data)
3592 {
3593         MarkAsReadData *mdata = (MarkAsReadData *)data;
3594         if (!mdata)
3595                 return FALSE;
3596
3597         summary_lock(mdata->summaryview);
3598         if (mdata->msginfo == summary_get_selected_msg(mdata->summaryview))
3599                 msginfo_mark_as_read(mdata->summaryview, mdata->msginfo,
3600                                      mdata->summaryview->selected);
3601         procmsg_msginfo_free(&(mdata->msginfo));
3602
3603         mdata->summaryview->mark_as_read_timeout_tag = 0;
3604         summary_unlock(mdata->summaryview);
3605
3606         g_free(mdata);
3607         return FALSE;
3608 }
3609
3610 static void summary_display_msg_full(SummaryView *summaryview,
3611                                      GtkCMCTreeNode *row,
3612                                      gboolean new_window, gboolean all_headers)
3613 {
3614         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3615         MsgInfo *msginfo;
3616         gint val;
3617         START_TIMING("");
3618         if (!new_window) {
3619                 if (summaryview->displayed == row &&
3620                     messageview_is_visible(summaryview->messageview))
3621                         return;
3622                 else if (summaryview->messageview)
3623                         summaryview->messageview->filtered = FALSE;
3624         }                       
3625         cm_return_if_fail(row != NULL);
3626
3627         if (summary_is_locked(summaryview)) return;
3628         summary_lock(summaryview);
3629
3630         STATUSBAR_POP(summaryview->mainwin);
3631         GTK_EVENTS_FLUSH();
3632
3633         msginfo = gtk_cmctree_node_get_row_data(ctree, row);
3634
3635         if (!msginfo) {
3636                 debug_print("NULL msginfo\n");
3637                 summary_unlock(summaryview);
3638                 END_TIMING();
3639                 return;
3640         }       
3641
3642         if (new_window && prefs_common.layout_mode != SMALL_LAYOUT) {
3643                 MessageView *msgview;
3644
3645                 msgview = messageview_create_with_new_window(summaryview->mainwin);
3646                 val = messageview_show(msgview, msginfo, all_headers);
3647         } else {
3648                 MessageView *msgview;
3649
3650                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
3651                         if (summaryview->ext_messageview == NULL)
3652                                 summaryview->ext_messageview = messageview_create_with_new_window(summaryview->mainwin);
3653                         else
3654                                 gtkut_window_popup(summaryview->ext_messageview->window);
3655                         msgview = summaryview->ext_messageview;
3656                         summaryview->displayed = row;
3657                         val = messageview_show(msgview, msginfo, all_headers);
3658                         if (mimeview_tree_is_empty(msgview->mimeview))
3659                                 gtk_widget_grab_focus(summaryview->ctree);
3660                         gtkut_ctree_node_move_if_on_the_edge(ctree, row,
3661                                 GTK_CMCLIST(summaryview->ctree)->focus_row);
3662                 } else {
3663                         msgview = summaryview->messageview;
3664                         summaryview->displayed = row;
3665                         if (!messageview_is_visible(msgview) &&
3666                             gtk_window_is_active(GTK_WINDOW(summaryview->mainwin->window))) {
3667                                 main_window_toggle_message_view(summaryview->mainwin);
3668                                 GTK_EVENTS_FLUSH();
3669                         }
3670                         val = messageview_show(msgview, msginfo, all_headers);
3671                         if (mimeview_tree_is_empty(msgview->mimeview))
3672                                 gtk_widget_grab_focus(summaryview->ctree);
3673                         gtkut_ctree_node_move_if_on_the_edge(ctree, row,
3674                                 GTK_CMCLIST(summaryview->ctree)->focus_row);
3675                 }
3676         }
3677
3678         if (val == 0 && MSG_IS_UNREAD(msginfo->flags)) {
3679                 if (!prefs_common.mark_as_read_on_new_window &&
3680                     prefs_common.mark_as_read_delay) {
3681                         MarkAsReadData *data = g_new0(MarkAsReadData, 1);
3682                         data->summaryview = summaryview;
3683                         data->msginfo = procmsg_msginfo_new_ref(msginfo);
3684                         if (summaryview->mark_as_read_timeout_tag != 0)
3685                                 g_source_remove(summaryview->mark_as_read_timeout_tag);
3686                         summaryview->mark_as_read_timeout_tag = 
3687                                 g_timeout_add_seconds(prefs_common.mark_as_read_delay,
3688                                         msginfo_mark_as_read_timeout, data);
3689                 } else if (new_window || !prefs_common.mark_as_read_on_new_window) {
3690                         msginfo_mark_as_read(summaryview, msginfo, row);
3691                 }
3692         }
3693
3694         summary_set_menu_sensitive(summaryview);
3695         toolbar_main_set_sensitive(summaryview->mainwin);
3696         messageview_set_menu_sensitive(summaryview->messageview);
3697
3698         summary_unlock(summaryview);
3699         END_TIMING();
3700 }
3701
3702 void summary_display_msg_selected(SummaryView *summaryview,
3703                                   gboolean all_headers)
3704 {
3705         if (summary_is_locked(summaryview)) return;
3706         summaryview->displayed = NULL;
3707         summary_display_msg_full(summaryview, summaryview->selected, FALSE,
3708                                  all_headers);
3709 }
3710
3711 void summary_redisplay_msg(SummaryView *summaryview)
3712 {
3713         GtkCMCTreeNode *node;
3714
3715         if (summaryview->displayed) {
3716                 node&nbs