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