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