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