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