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