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