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