744e781acfa8d07aeacc91db1c0969351ea4ea8d
[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_read_msgs_menu (SummaryView *summaryview,
134                                              guint action);
135 static void summary_set_hide_del_msgs_menu (SummaryView *summaryview,
136                                              guint action);
137 static void summary_set_hide_read_threads_menu (SummaryView *summaryview,
138                                              guint action);
139
140 static GtkCMCTreeNode *summary_find_prev_msg
141                                         (SummaryView            *summaryview,
142                                          GtkCMCTreeNode         *current_node);
143 static GtkCMCTreeNode *summary_find_next_msg
144                                         (SummaryView            *summaryview,
145                                          GtkCMCTreeNode         *current_node);
146
147 static GtkCMCTreeNode *summary_find_prev_flagged_msg
148                                         (SummaryView    *summaryview,
149                                          GtkCMCTreeNode *current_node,
150                                          MsgPermFlags    flags,
151                                          gboolean        start_from_prev);
152 static GtkCMCTreeNode *summary_find_next_flagged_msg
153                                         (SummaryView    *summaryview,
154                                          GtkCMCTreeNode *current_node,
155                                          MsgPermFlags    flags,
156                                          gboolean        start_from_next);
157
158 static GtkCMCTreeNode *summary_find_msg_by_msgnum
159                                         (SummaryView            *summaryview,
160                                          guint                   msgnum);
161
162 static void summary_update_status       (SummaryView            *summaryview);
163
164 /* display functions */
165 static void summary_status_show         (SummaryView            *summaryview);
166 static void summary_set_column_titles   (SummaryView            *summaryview);
167 static void summary_set_ctree_from_list (SummaryView            *summaryview,
168                                          GSList                 *mlist);
169 static inline void summary_set_header   (SummaryView            *summaryview,
170                                          gchar                  *text[],
171                                          MsgInfo                *msginfo);
172 static void summary_display_msg         (SummaryView            *summaryview,
173                                          GtkCMCTreeNode         *row);
174 static void summary_display_msg_full    (SummaryView            *summaryview,
175                                          GtkCMCTreeNode         *row,
176                                          gboolean                new_window,
177                                          gboolean                all_headers);
178 static void summary_set_row_marks       (SummaryView            *summaryview,
179                                          GtkCMCTreeNode         *row);
180
181 static gboolean summary_set_row_tag     (SummaryView            *summaryview, 
182                                          GtkCMCTreeNode                 *row, 
183                                          gboolean                refresh,
184                                          gboolean                set, 
185                                          gint                    id);
186 /* message handling */
187 static void summary_mark_row            (SummaryView            *summaryview,
188                                          GtkCMCTreeNode         *row);
189 static void summary_lock_row            (SummaryView            *summaryview,
190                                          GtkCMCTreeNode         *row);
191 static void summary_unlock_row          (SummaryView            *summaryview,
192                                          GtkCMCTreeNode         *row);
193 static void summary_mark_row_as_read    (SummaryView            *summaryview,
194                                          GtkCMCTreeNode         *row);
195 static void summary_mark_row_as_unread  (SummaryView            *summaryview,
196                                          GtkCMCTreeNode         *row);
197 static void summary_delete_row          (SummaryView            *summaryview,
198                                          GtkCMCTreeNode         *row);
199 static void summary_unmark_row          (SummaryView            *summaryview,
200                                          GtkCMCTreeNode         *row);
201 static void summary_move_row_to         (SummaryView            *summaryview,
202                                          GtkCMCTreeNode         *row,
203                                          FolderItem             *to_folder);
204 static void summary_copy_row_to         (SummaryView            *summaryview,
205                                          GtkCMCTreeNode         *row,
206                                          FolderItem             *to_folder);
207
208 static gint summary_execute_move        (SummaryView            *summaryview);
209 static void summary_execute_move_func   (GtkCMCTree             *ctree,
210                                          GtkCMCTreeNode         *node,
211                                          gpointer                data);
212 static void summary_execute_copy        (SummaryView            *summaryview);
213 static void summary_execute_copy_func   (GtkCMCTree             *ctree,
214                                          GtkCMCTreeNode         *node,
215                                          gpointer                data);
216 static void summary_execute_delete      (SummaryView            *summaryview);
217 static void summary_execute_delete_func (GtkCMCTree             *ctree,
218                                          GtkCMCTreeNode         *node,
219                                          gpointer                data);
220 static void summary_execute_expunge     (SummaryView            *summaryview);
221
222 static void summary_thread_init         (SummaryView            *summaryview);
223
224 static void summary_unthread_for_exec           (SummaryView    *summaryview);
225 static void summary_unthread_for_exec_func      (GtkCMCTree     *ctree,
226                                                  GtkCMCTreeNode *node,
227                                                  gpointer        data);
228
229 void summary_simplify_subject(SummaryView *summaryview, gchar * rexp,
230                               GSList * mlist);
231
232 static void summary_filter_func         (MsgInfo *msginfo);
233
234 static void summary_colorlabel_menu_item_activate_cb
235                                           (GtkWidget    *widget,
236                                            gpointer      data);
237 static void summary_colorlabel_menu_item_activate_item_cb
238                                           (GtkMenuItem  *label_menu_item,
239                                            gpointer      data);
240 static void summary_colorlabel_menu_create(SummaryView  *summaryview,
241                                            gboolean  refresh);
242 static void summary_tags_menu_item_activate_cb
243                                           (GtkWidget    *widget,
244                                            gpointer      data);
245 static void summary_tags_menu_item_activate_item_cb
246                                           (GtkMenuItem  *label_menu_item,
247                                            gpointer      data);
248 static void summary_tags_menu_create(SummaryView        *summaryview,
249                                            gboolean  refresh);
250
251 static GtkWidget *summary_ctree_create  (SummaryView    *summaryview);
252
253 /* callback functions */
254 static gint summary_toggle_pressed      (GtkWidget              *eventbox,
255                                          GdkEventButton         *event,
256                                          SummaryView            *summaryview);
257 #ifdef GENERIC_UMPC
258 static void summary_toggle_multiple_pressed
259                                         (GtkWidget              *widget,
260                                          SummaryView            *summaryview);
261 #endif
262 static gint summary_folder_eventbox_pressed     
263                                         (GtkWidget              *eventbox,
264                                          GdkEventButton         *event,
265                                          SummaryView            *summaryview);
266 static gboolean summary_button_pressed  (GtkWidget              *ctree,
267                                          GdkEventButton         *event,
268                                          SummaryView            *summaryview);
269 static gboolean summary_button_released (GtkWidget              *ctree,
270                                          GdkEventButton         *event,
271                                          SummaryView            *summaryview);
272 static gboolean summary_key_pressed     (GtkWidget              *ctree,
273                                          GdkEventKey            *event,
274                                          SummaryView            *summaryview);
275 static void summary_tree_expanded       (GtkCMCTree             *ctree,
276                                          GtkCMCTreeNode         *node,
277                                          SummaryView            *summaryview);
278 static void summary_tree_collapsed      (GtkCMCTree             *ctree,
279                                          GtkCMCTreeNode         *node,
280                                          SummaryView            *summaryview);
281 static void summary_selected            (GtkCMCTree             *ctree,
282                                          GtkCMCTreeNode         *row,
283                                          gint                    column,
284                                          SummaryView            *summaryview);
285 static void summary_unselected          (GtkCMCTree             *ctree,
286                                          GtkCMCTreeNode         *row,
287                                          gint                    column,
288                                          SummaryView            *summaryview);
289 static void summary_col_resized         (GtkCMCList             *clist,
290                                          gint                    column,
291                                          gint                    width,
292                                          SummaryView            *summaryview);
293 static void summary_mark_clicked        (GtkWidget              *button,
294                                          SummaryView            *summaryview);
295 static void summary_status_clicked      (GtkWidget              *button,
296                                          SummaryView            *summaryview);
297 static void summary_mime_clicked        (GtkWidget              *button,
298                                          SummaryView            *summaryview);
299 static void summary_num_clicked         (GtkWidget              *button,
300                                          SummaryView            *summaryview);
301 static void summary_score_clicked       (GtkWidget *button,
302                                          SummaryView *summaryview);
303 static void summary_size_clicked        (GtkWidget              *button,
304                                          SummaryView            *summaryview);
305 static void summary_date_clicked        (GtkWidget              *button,
306                                          SummaryView            *summaryview);
307 static void summary_from_clicked        (GtkWidget              *button,
308                                          SummaryView            *summaryview);
309 static void summary_to_clicked          (GtkWidget              *button,
310                                          SummaryView            *summaryview);
311 static void summary_subject_clicked     (GtkWidget              *button,
312                                          SummaryView            *summaryview);
313 static void summary_score_clicked       (GtkWidget              *button,
314                                          SummaryView            *summaryview);
315 static void summary_locked_clicked      (GtkWidget              *button,
316                                          SummaryView            *summaryview);
317 static void summary_tags_clicked        (GtkWidget              *button,
318                                          SummaryView            *summaryview);
319
320 static void summary_start_drag          (GtkWidget        *widget, 
321                                          int button,
322                                          GdkEvent *event,
323                                          SummaryView      *summaryview);
324 static void summary_drag_data_get       (GtkWidget        *widget,
325                                          GdkDragContext   *drag_context,
326                                          GtkSelectionData *selection_data,
327                                          guint             info,
328                                          guint             time,
329                                          SummaryView      *summaryview);
330 static void summary_drag_data_received(GtkWidget        *widget,
331                                         GdkDragContext   *drag_context,
332                                         gint              x,
333                                         gint              y,
334                                         GtkSelectionData *data,
335                                         guint             info,
336                                         guint             time,
337                                         SummaryView       *summaryview);
338 static gboolean summary_drag_motion_cb(GtkWidget      *widget,
339                                           GdkDragContext *context,
340                                           gint            x,
341                                           gint            y,
342                                           guint           time,
343                                           SummaryView    *summaryview);
344 static void summary_drag_end(GtkWidget *widget,
345                                           GdkDragContext *drag_context,
346                                           SummaryView    *summaryview);
347 /* custom compare functions for sorting */
348
349 static gint summary_cmp_by_mark         (GtkCMCList             *clist,
350                                          gconstpointer           ptr1,
351                                          gconstpointer           ptr2);
352 static gint summary_cmp_by_status       (GtkCMCList             *clist,
353                                          gconstpointer           ptr1,
354                                          gconstpointer           ptr2);
355 static gint summary_cmp_by_mime         (GtkCMCList             *clist,
356                                          gconstpointer           ptr1,
357                                          gconstpointer           ptr2);
358 static gint summary_cmp_by_num          (GtkCMCList             *clist,
359                                          gconstpointer           ptr1,
360                                          gconstpointer           ptr2);
361 static gint summary_cmp_by_size         (GtkCMCList             *clist,
362                                          gconstpointer           ptr1,
363                                          gconstpointer           ptr2);
364 static gint summary_cmp_by_date         (GtkCMCList             *clist,
365                                          gconstpointer           ptr1,
366                                          gconstpointer           ptr2);
367 static gint summary_cmp_by_thread_date  (GtkCMCList             *clist,
368                                          gconstpointer           ptr1,
369                                          gconstpointer           ptr2);
370 static gint summary_cmp_by_from         (GtkCMCList             *clist,
371                                          gconstpointer           ptr1,
372                                          gconstpointer           ptr2);
373 static gint summary_cmp_by_simplified_subject
374                                         (GtkCMCList             *clist, 
375                                          gconstpointer           ptr1, 
376                                          gconstpointer           ptr2);
377 static gint summary_cmp_by_score        (GtkCMCList             *clist,
378                                          gconstpointer           ptr1,
379                                          gconstpointer           ptr2);
380 static gint summary_cmp_by_label        (GtkCMCList             *clist,
381                                          gconstpointer           ptr1,
382                                          gconstpointer           ptr2);
383 static gint summary_cmp_by_to           (GtkCMCList             *clist,
384                                          gconstpointer           ptr1,
385                                          gconstpointer           ptr2);
386 static gint summary_cmp_by_subject      (GtkCMCList             *clist,
387                                          gconstpointer           ptr1,
388                                          gconstpointer           ptr2);
389 static gint summary_cmp_by_locked       (GtkCMCList             *clist,
390                                          gconstpointer           ptr1, 
391                                          gconstpointer           ptr2);
392 static gint summary_cmp_by_tags         (GtkCMCList             *clist,
393                                          gconstpointer           ptr1, 
394                                          gconstpointer           ptr2);
395
396 static void quicksearch_execute_cb      (QuickSearch    *quicksearch,
397                                          gpointer        data);
398
399 static void tog_searchbar_cb            (GtkWidget      *w,
400                                          gpointer        data);
401
402 static void summary_find_answers        (SummaryView    *summaryview, 
403                                          MsgInfo        *msg);
404
405 static gboolean summary_update_msg      (gpointer source, gpointer data);
406 static gboolean summary_update_folder_item_hook(gpointer source, gpointer data);
407 static gboolean summary_update_folder_hook(gpointer source, gpointer data);
408 static void summary_set_colorlabel_color (GtkCMCTree            *ctree,
409                                    GtkCMCTreeNode               *node,
410                                    guint                 labelcolor);
411 static void summary_thread_build(SummaryView *summaryview);
412
413 GtkTargetEntry summary_drag_types[3] =
414 {
415         {"text/uri-list", 0, TARGET_MAIL_URI_LIST},
416         {"claws-mail/internal", GTK_TARGET_SAME_APP, TARGET_DUMMY},
417         {"claws-mail/msg-path-list", 0, TARGET_MAIL_CM_PATH_LIST},
418 };
419
420 #define DO_ACTION(name, act) {                                          \
421         if(!strcmp(name, a_name)) {                                     \
422                 act;                                                    \
423         }                                                               \
424 }
425
426 static GtkActionEntry summary_popup_entries[] =
427 {
428         {"SummaryViewPopup",                            NULL, "SummaryViewPopup" },
429         {"SummaryViewPopup/ReplyTo",                    NULL, N_("Repl_y to") },
430         {"SummaryViewPopup/Mark",                       NULL, N_("_Mark") },
431         {"SummaryViewPopup/ColorLabel",                 NULL, N_("Color la_bel") },
432         {"SummaryViewPopup/Tags",                       NULL, N_("Ta_gs") },
433         {"SummaryViewPopup/CreateFilterRule",           NULL, N_("Create _filter rule") },
434 #ifndef GENERIC_UMPC
435         {"SummaryViewPopup/CreateProcessingRule",       NULL, N_("Create processing rule") },
436 #endif
437         {"SummaryViewPopup/View",                       NULL, N_("_View") },
438 };
439
440 static const gchar *const col_label[N_SUMMARY_COLS] = {
441         "",             /* S_COL_MARK    */
442         N_("S"),        /* S_COL_STATUS  */
443         "",             /* S_COL_MIME    */
444         N_("Subject"),  /* S_COL_SUBJECT */
445         N_("From"),     /* S_COL_FROM    */
446         N_("To"),       /* S_COL_TO      */
447         N_("Date"),     /* S_COL_DATE    */
448         N_("Size"),     /* S_COL_SIZE    */
449         N_("#"),        /* S_COL_NUMBER  */
450         N_("Score"),    /* S_COL_SCORE   */
451         "",             /* S_COL_LOCKED  */
452         N_("Tags"),     /* S_COL_TAGS    */
453 };
454
455 void summary_freeze(SummaryView *summaryview)
456 {
457         if (summaryview)
458                 gtk_cmclist_freeze(GTK_CMCLIST(summaryview->ctree));
459 }
460
461 void summary_thaw(SummaryView *summaryview)
462 {
463         if (summaryview)
464                 gtk_cmclist_thaw(GTK_CMCLIST(summaryview->ctree));
465 }
466
467 void summary_grab_focus(SummaryView *summaryview)
468 {
469         if (summaryview)
470                 gtk_widget_grab_focus(summaryview->ctree);
471 }
472
473 GtkWidget *summary_get_main_widget(SummaryView *summaryview)
474 {
475         if (summaryview)
476                 return summaryview->ctree;
477         else
478                 return NULL;
479 }
480
481 #define START_LONG_OPERATION(summaryview,force_freeze) {        \
482         summary_lock(summaryview);                              \
483         main_window_cursor_wait(summaryview->mainwin);          \
484         if (force_freeze || sc_g_list_bigger(GTK_CMCLIST(summaryview->ctree)->selection, 1)) {\
485                 froze = TRUE;                                           \
486                 summary_freeze(summaryview);    \
487         }                                                       \
488         folder_item_update_freeze();                            \
489         inc_lock();                                             \
490         hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,          \
491                       summaryview->msginfo_update_callback_id); \
492 }
493 #define END_LONG_OPERATION(summaryview) {                       \
494         inc_unlock();                                           \
495         folder_item_update_thaw();                              \
496         if (froze)                                              \
497                 summary_thaw(summaryview);      \
498         main_window_cursor_normal(summaryview->mainwin);        \
499         summary_unlock(summaryview);                            \
500         summaryview->msginfo_update_callback_id =               \
501                 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,    \
502                 summary_update_msg, (gpointer) summaryview);    \
503 }
504
505 SummaryView *summary_create(MainWindow *mainwin)
506 {
507         SummaryView *summaryview;
508         GtkWidget *vbox;
509         GtkWidget *scrolledwin;
510         GtkWidget *ctree;
511         GtkWidget *hbox;
512         GtkWidget *hbox_l;
513         GtkWidget *stat_box;
514         GtkWidget *stat_box2;
515         GtkWidget *stat_vbox;
516         GtkWidget *statlabel_folder;
517         GtkWidget *statlabel_select;
518         GtkWidget *statlabel_msgs;
519         GtkWidget *hbox_spc;
520         GtkWidget *toggle_eventbox;
521 #ifdef GENERIC_UMPC
522         GtkWidget *multiple_sel_togbtn;
523 #endif
524         GtkWidget *toggle_arrow;
525         GtkWidget *toggle_search;
526         QuickSearch *quicksearch;
527
528         debug_print("Creating summary view...\n");
529         summaryview = g_new0(SummaryView, 1);
530
531 #if !(GTK_CHECK_VERSION(2,12,0))
532         summaryview->tooltips = tips;
533 #endif
534 #define SUMMARY_VBOX_SPACING 3
535         vbox = gtk_vbox_new(FALSE, SUMMARY_VBOX_SPACING);
536         
537         /* create status label */
538         hbox = gtk_hbox_new(FALSE, 0);
539         gtk_widget_show(hbox);
540
541         stat_vbox = gtk_vbox_new(FALSE, 0);
542         gtk_widget_show(stat_vbox);
543
544         stat_box = gtk_hbox_new(FALSE, 0);
545         gtk_widget_show(stat_box);
546         
547         stat_box2 = gtk_hbox_new(FALSE, 0);
548         gtk_widget_show(stat_box2);
549         
550         toggle_search = gtk_toggle_button_new();
551         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_search),
552                                      prefs_common.show_searchbar);
553         gtkut_widget_set_can_focus(toggle_search, FALSE);
554         gtk_widget_show(toggle_search);
555
556         CLAWS_SET_TIP(toggle_search, _("Toggle quick search bar"));
557         
558         gtk_box_pack_start(GTK_BOX(hbox), toggle_search, FALSE, FALSE, 2);      
559
560         gtk_box_pack_start(GTK_BOX(hbox), stat_vbox, TRUE, TRUE, 0);    
561         gtk_box_pack_start(GTK_BOX(stat_vbox), stat_box, TRUE, TRUE, 0);        
562         gtk_box_pack_start(GTK_BOX(stat_vbox), stat_box2, TRUE, TRUE, 0);       
563
564         hbox_l = gtk_hbox_new(FALSE, 0);
565         gtk_widget_show(hbox_l);
566         gtk_box_pack_start(GTK_BOX(stat_box), hbox_l, TRUE, TRUE, 0);
567  
568         statlabel_folder = gtk_label_new("");
569         gtk_widget_show(statlabel_folder);
570         gtk_box_pack_start(GTK_BOX(hbox_l), statlabel_folder, FALSE, FALSE, 2);
571         statlabel_select = gtk_label_new("");
572         gtk_widget_show(statlabel_select);
573         gtk_box_pack_start(GTK_BOX(hbox_l), statlabel_select, FALSE, FALSE, 12);
574  
575         /* toggle view button */
576         toggle_eventbox = gtk_event_box_new();
577         gtk_widget_show(toggle_eventbox);
578         
579         gtk_box_pack_end(GTK_BOX(hbox), toggle_eventbox, FALSE, FALSE, 4);
580
581         toggle_arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
582         gtk_widget_show(toggle_arrow);
583         gtk_container_add(GTK_CONTAINER(toggle_eventbox), toggle_arrow);
584         g_signal_connect(G_OBJECT(toggle_eventbox), "button_press_event",
585                          G_CALLBACK(summary_toggle_pressed),
586                          summaryview);
587
588 #ifdef GENERIC_UMPC
589         multiple_sel_togbtn = gtk_toggle_button_new();
590         gtk_widget_show(multiple_sel_togbtn);
591         gtk_box_pack_end(GTK_BOX(hbox), multiple_sel_togbtn, FALSE, FALSE, 4);
592         CLAWS_SET_TIP(multiple_sel_togbtn,
593                              _("Toggle multiple selection"));
594         g_signal_connect(G_OBJECT(multiple_sel_togbtn), "toggled",
595                          G_CALLBACK(summary_toggle_multiple_pressed),
596                          summaryview);
597 #endif
598         
599         statlabel_msgs = gtk_label_new("");
600         gtk_widget_show(statlabel_msgs);
601         gtk_box_pack_end(GTK_BOX(stat_box), statlabel_msgs, FALSE, FALSE, 4);
602
603         hbox_spc = gtk_hbox_new(FALSE, 0);
604         gtk_widget_show(hbox_spc);
605         gtk_box_pack_end(GTK_BOX(hbox), hbox_spc, FALSE, FALSE, 6);
606
607         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
608         gtk_widget_show(scrolledwin);
609         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
610                                        GTK_POLICY_AUTOMATIC,
611                                        GTK_POLICY_AUTOMATIC);
612         summaryview->mainwidget_book = gtk_notebook_new();
613         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(summaryview->mainwidget_book), FALSE);
614         gtk_notebook_set_show_border(GTK_NOTEBOOK(summaryview->mainwidget_book), FALSE);
615 #ifndef GENERIC_UMPC
616         gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
617                 scrolledwin);
618         gtk_box_pack_start(GTK_BOX(vbox), summaryview->mainwidget_book, TRUE, TRUE, 0);
619 #endif
620         gtk_widget_set_size_request(vbox,
621                              prefs_common.summaryview_width,
622                              prefs_common.summaryview_height);
623
624         ctree = summary_ctree_create(summaryview);
625         gtk_widget_show(ctree);
626
627         gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
628                                             GTK_CMCLIST(ctree)->hadjustment);
629         gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
630                                             GTK_CMCLIST(ctree)->vadjustment);
631         gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
632
633         /* status label */
634         gtk_widget_show_all(stat_vbox);
635         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
636
637         /* quick search */
638         quicksearch = quicksearch_new();
639         gtk_box_pack_start(GTK_BOX(vbox), quicksearch_get_widget(quicksearch), FALSE, FALSE, 0);
640
641 #ifdef GENERIC_UMPC
642         gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
643                 scrolledwin);
644         gtk_box_pack_start(GTK_BOX(vbox), summaryview->mainwidget_book, TRUE, TRUE, 0);
645 #endif
646         quicksearch_set_execute_callback(quicksearch, quicksearch_execute_cb, summaryview);
647
648         g_signal_connect (G_OBJECT(toggle_search), "toggled",
649                           G_CALLBACK(tog_searchbar_cb), summaryview);
650
651         /* create popup menu */
652         
653         gtk_action_group_add_actions(mainwin->action_group, summary_popup_entries,
654                         G_N_ELEMENTS(summary_popup_entries), (gpointer)summaryview);
655
656         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/", "Menus", "Menus", GTK_UI_MANAGER_MENUBAR)
657         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus", "SummaryViewPopup", "SummaryViewPopup", GTK_UI_MANAGER_MENU)
658         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Reply", "Message/Reply", GTK_UI_MANAGER_MENUITEM)
659 #ifndef GENERIC_UMPC
660         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ReplyTo", "SummaryViewPopup/ReplyTo", GTK_UI_MANAGER_MENU)
661         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator1", "Message/---", GTK_UI_MANAGER_SEPARATOR)
662 #endif
663         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Forward", "Message/Forward", GTK_UI_MANAGER_MENUITEM)
664 #ifndef GENERIC_UMPC
665         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ForwardAtt", "Message/ForwardAtt", GTK_UI_MANAGER_MENUITEM)
666         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Redirect", "Message/Redirect", GTK_UI_MANAGER_MENUITEM)
667 #endif
668         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
669         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Move", "Message/Move", GTK_UI_MANAGER_MENUITEM)
670         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Copy", "Message/Copy", GTK_UI_MANAGER_MENUITEM)
671         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Trash", "Message/Trash", GTK_UI_MANAGER_MENUITEM)
672 #ifndef GENERIC_UMPC
673         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Delete", "Message/Delete", GTK_UI_MANAGER_MENUITEM)
674 #endif
675         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator3", "Message/---", GTK_UI_MANAGER_SEPARATOR)
676         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Mark", "SummaryViewPopup/Mark", GTK_UI_MANAGER_MENU)
677         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ColorLabel", "SummaryViewPopup/ColorLabel", GTK_UI_MANAGER_MENU)
678         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Tags", "SummaryViewPopup/Tags", GTK_UI_MANAGER_MENU)
679
680         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator4", "Message/---", GTK_UI_MANAGER_SEPARATOR)
681 #ifndef GENERIC_UMPC
682         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "AddSenderToAB", "Tools/AddSenderToAB", GTK_UI_MANAGER_MENUITEM)
683 #endif
684         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "CreateFilterRule", "SummaryViewPopup/CreateFilterRule", GTK_UI_MANAGER_MENU)
685 #ifndef GENERIC_UMPC
686         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "CreateProcessingRule", "SummaryViewPopup/CreateProcessingRule", GTK_UI_MANAGER_MENU)
687 #endif
688         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator5", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
689         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "View", "SummaryViewPopup/View", GTK_UI_MANAGER_MENU)
690         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
691 #ifndef GENERIC_UMPC
692         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
693 #endif
694         /* last separator, for plugins */
695         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator6", "File/---", GTK_UI_MANAGER_SEPARATOR)
696
697         /* submenus - replyto */
698         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "All", "Message/ReplyTo/All", GTK_UI_MANAGER_MENUITEM)
699         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "Sender", "Message/ReplyTo/Sender", GTK_UI_MANAGER_MENUITEM)
700         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "MailingList", "Message/ReplyTo/List", GTK_UI_MANAGER_MENUITEM)
701
702         /* submenus - mark */
703         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Mark", "Message/Mark/Mark", GTK_UI_MANAGER_MENUITEM)
704         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Unmark", "Message/Mark/Unmark", GTK_UI_MANAGER_MENUITEM)
705         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator1", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
706         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkUnread", "Message/Mark/MarkUnread", GTK_UI_MANAGER_MENUITEM)
707         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkRead", "Message/Mark/MarkRead", GTK_UI_MANAGER_MENUITEM)
708         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator2", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
709         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkAllRead", "Message/Mark/MarkAllRead", GTK_UI_MANAGER_MENUITEM)
710         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator3", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
711         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "IgnoreThread", "Message/Mark/IgnoreThread", GTK_UI_MANAGER_MENUITEM)
712         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "UnignoreThread", "Message/Mark/UnignoreThread", GTK_UI_MANAGER_MENUITEM)
713         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "WatchThread", "Message/Mark/WatchThread", GTK_UI_MANAGER_MENUITEM)
714         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "UnwatchThread", "Message/Mark/UnwatchThread", GTK_UI_MANAGER_MENUITEM)
715         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator4", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
716         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkSpam", "Message/Mark/MarkSpam", GTK_UI_MANAGER_MENUITEM)
717         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkHam", "Message/Mark/MarkHam", GTK_UI_MANAGER_MENUITEM)
718         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator5", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
719         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Lock", "Message/Mark/Lock", GTK_UI_MANAGER_MENUITEM)
720         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Unlock", "Message/Mark/Unlock", GTK_UI_MANAGER_MENUITEM)
721
722         /* submenus - colorlabel and tags are dynamic */
723         /* submenus - createfilterrule */
724         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "Automatically", "Tools/CreateFilterRule/Automatically", GTK_UI_MANAGER_MENUITEM)
725         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "ByFrom", "Tools/CreateFilterRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
726         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "ByTo", "Tools/CreateFilterRule/ByTo", GTK_UI_MANAGER_MENUITEM)
727         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "BySubject", "Tools/CreateFilterRule/BySubject", GTK_UI_MANAGER_MENUITEM)
728                 
729 #ifndef GENERIC_UMPC
730         /* submenus - createprocessingrule */
731         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "Automatically", "Tools/CreateProcessingRule/Automatically", GTK_UI_MANAGER_MENUITEM)
732         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "ByFrom", "Tools/CreateProcessingRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
733         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "ByTo", "Tools/CreateProcessingRule/ByTo", GTK_UI_MANAGER_MENUITEM)
734         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "BySubject", "Tools/CreateProcessingRule/BySubject", GTK_UI_MANAGER_MENUITEM)
735 #endif
736                 
737         /* submenus - view */
738         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "OpenNewWindow", "View/OpenNewWindow", GTK_UI_MANAGER_MENUITEM)
739         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "MessageSource", "View/MessageSource", GTK_UI_MANAGER_MENUITEM)
740 #ifndef GENERIC_UMPC
741         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "AllHeaders", "View/AllHeaders", GTK_UI_MANAGER_MENUITEM)
742 #endif          
743         summaryview->popupmenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
744                                 gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menus/SummaryViewPopup")) );
745
746
747         summaryview->vbox = vbox;
748         summaryview->scrolledwin = scrolledwin;
749         summaryview->ctree = ctree;
750         summaryview->hbox = hbox;
751         summaryview->hbox_l = hbox_l;
752         summaryview->hbox_spc = hbox_spc;
753         summaryview->stat_box = stat_box;
754         summaryview->stat_box2 = stat_box2;
755         summaryview->statlabel_folder = statlabel_folder;
756         summaryview->statlabel_select = statlabel_select;
757         summaryview->statlabel_msgs = statlabel_msgs;
758         summaryview->toggle_eventbox = toggle_eventbox;
759         summaryview->toggle_arrow = toggle_arrow;
760 #ifdef GENERIC_UMPC
761         summaryview->multiple_sel_togbtn = multiple_sel_togbtn;
762 #endif
763         summaryview->toggle_search = toggle_search;
764         summaryview->lock_count = 0;
765         summaryview->msginfo_update_callback_id =
766                 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, summary_update_msg, (gpointer) summaryview);
767         summaryview->folder_item_update_callback_id =
768                 hooks_register_hook(FOLDER_ITEM_UPDATE_HOOKLIST,
769                                 summary_update_folder_item_hook,
770                                 (gpointer) summaryview);
771         summaryview->folder_update_callback_id =
772                 hooks_register_hook(FOLDER_UPDATE_HOOKLIST,
773                                 summary_update_folder_hook,
774                                 (gpointer) summaryview);
775
776         summaryview->target_list = gtk_target_list_new(summary_drag_types, 3);
777
778         summaryview->quicksearch = quicksearch;
779
780         /* CLAWS: need this to get the SummaryView * from
781          * the CList */
782         g_object_set_data(G_OBJECT(ctree), "summaryview", (gpointer)summaryview); 
783
784         gtk_widget_show_all(vbox);
785
786         gtk_widget_show(vbox);
787
788         if (prefs_common.show_searchbar)
789                 quicksearch_show(quicksearch);
790         else
791                 quicksearch_hide(quicksearch);
792         
793         if (prefs_common.layout_mode == WIDE_MSGLIST_LAYOUT ||
794             prefs_common.layout_mode == SMALL_LAYOUT)
795                 gtk_widget_hide(summaryview->toggle_eventbox);
796
797         return summaryview;
798 }
799
800 void summary_relayout(SummaryView *summaryview)
801 {
802         gtk_widget_realize(summaryview->stat_box);
803
804         g_object_ref(summaryview->hbox_l);
805         g_object_ref(summaryview->statlabel_msgs);
806         
807         gtkut_container_remove(GTK_CONTAINER(
808                 gtk_widget_get_parent(summaryview->hbox_l)), summaryview->hbox_l);
809         gtkut_container_remove(GTK_CONTAINER(
810                 gtk_widget_get_parent(summaryview->statlabel_msgs)), summaryview->statlabel_msgs);
811
812         switch (prefs_common.layout_mode) {
813         case NORMAL_LAYOUT:
814         case WIDE_LAYOUT:
815         case WIDE_MSGLIST_LAYOUT:
816                 gtk_box_pack_start(GTK_BOX(summaryview->stat_box), summaryview->hbox_l, TRUE, TRUE, 0);
817                 gtk_box_pack_end(GTK_BOX(summaryview->stat_box), summaryview->statlabel_msgs, FALSE, FALSE, 4);
818                 gtk_widget_show_all(summaryview->stat_box);
819                 gtk_widget_show_all(summaryview->stat_box2);
820                 if (prefs_common.layout_mode == WIDE_MSGLIST_LAYOUT ||
821                     prefs_common.layout_mode == SMALL_LAYOUT)
822                         gtk_widget_hide(summaryview->toggle_eventbox);
823                 else
824                         gtk_widget_show(summaryview->toggle_eventbox);
825                 break;
826         case VERTICAL_LAYOUT:
827         case SMALL_LAYOUT:
828                 gtk_box_pack_start(GTK_BOX(summaryview->stat_box), summaryview->hbox_l, TRUE, TRUE, 0);
829                 gtk_box_pack_start(GTK_BOX(summaryview->stat_box2), summaryview->statlabel_msgs, FALSE, FALSE, 4);
830                 gtk_widget_show_all(summaryview->stat_box);
831                 gtk_widget_show_all(summaryview->stat_box2);
832                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
833                         gtk_widget_hide(summaryview->toggle_eventbox);
834                         gtk_widget_hide(summaryview->statlabel_msgs);
835                 } else {
836                         gtk_widget_show(summaryview->toggle_eventbox);
837                         gtk_widget_show(summaryview->statlabel_msgs);
838                 }
839                         
840                 break;
841         }
842         summary_set_column_order(summaryview);
843
844         g_object_unref(summaryview->hbox_l);
845         g_object_unref(summaryview->statlabel_msgs);
846         quicksearch_relayout(summaryview->quicksearch);
847         if (prefs_common.show_searchbar)
848                 quicksearch_show(summaryview->quicksearch);
849         else
850                 quicksearch_hide(summaryview->quicksearch);
851 }
852
853 static void summary_set_fonts(SummaryView *summaryview)
854 {
855         PangoFontDescription *font_desc;
856         gint size;
857
858         font_desc = pango_font_description_from_string(NORMAL_FONT);
859         if (font_desc) {
860                 gtk_widget_modify_font(summaryview->ctree, font_desc);
861                 pango_font_description_free(font_desc);
862         }
863
864         if (!bold_style) {
865                 bold_style = gtk_style_copy
866                         (gtk_widget_get_style(summaryview->ctree));
867
868                 if (prefs_common.derive_from_normal_font || !BOLD_FONT) {
869                         font_desc = pango_font_description_from_string(NORMAL_FONT);
870                         if (font_desc) {
871                                 pango_font_description_free(bold_style->font_desc);
872                                 bold_style->font_desc = font_desc;
873                         }
874                         pango_font_description_set_weight
875                                         (bold_style->font_desc, PANGO_WEIGHT_BOLD);
876                 } else {
877                         font_desc = pango_font_description_from_string(BOLD_FONT);
878                         if (font_desc) {
879                                 pango_font_description_free(bold_style->font_desc);
880                                 bold_style->font_desc = font_desc;
881                         }
882                 }
883                 bold_marked_style = gtk_style_copy(bold_style);
884                 bold_marked_style->fg[GTK_STATE_NORMAL] =
885                         summaryview->color_marked;
886                 bold_deleted_style = gtk_style_copy(bold_style);
887                 bold_deleted_style->fg[GTK_STATE_NORMAL] =
888                         summaryview->color_dim;
889         }
890
891         if (prefs_common.derive_from_normal_font || !SMALL_FONT) {
892                 font_desc = pango_font_description_new();
893                 size = pango_font_description_get_size
894                         (gtk_widget_get_style(summaryview->ctree)->font_desc);
895                 pango_font_description_set_size(font_desc, size * PANGO_SCALE_SMALL);
896         } else {
897                 font_desc = pango_font_description_from_string(SMALL_FONT);
898         }
899         if (font_desc) {
900                 gtk_widget_modify_font(summaryview->statlabel_folder, font_desc);
901                 gtk_widget_modify_font(summaryview->statlabel_select, font_desc);
902                 gtk_widget_modify_font(summaryview->statlabel_msgs, font_desc);
903                 pango_font_description_free(font_desc);
904         }
905
906 }
907
908 static void summary_set_folder_pixmap(SummaryView *summaryview, StockPixmap icon)
909 {
910         GtkWidget *pixmap; 
911         if (!summaryview->folder_pixmap_eventbox) {
912                 summaryview->folder_pixmap_eventbox = gtk_event_box_new();
913                 gtk_widget_show(summaryview->folder_pixmap_eventbox);
914                 gtk_box_pack_start(GTK_BOX(summaryview->hbox_l), summaryview->folder_pixmap_eventbox, FALSE, FALSE, 4);
915                 gtk_box_reorder_child(GTK_BOX(summaryview->hbox_l), summaryview->folder_pixmap_eventbox, 0); /* search_toggle before */
916                 g_signal_connect(G_OBJECT(summaryview->folder_pixmap_eventbox), "button_press_event",
917                          G_CALLBACK(summary_folder_eventbox_pressed),
918                          summaryview);
919         }
920         if (summaryview->folder_pixmap)
921                 gtk_widget_destroy(summaryview->folder_pixmap);
922
923         pixmap = stock_pixmap_widget(summaryview->hbox_l, icon);
924         gtk_container_add(GTK_CONTAINER(summaryview->folder_pixmap_eventbox), pixmap);
925         gtk_widget_show(pixmap);
926         summaryview->folder_pixmap = pixmap; 
927 }
928
929 void summary_init(SummaryView *summaryview)
930 {
931         GtkWidget *pixmap;
932
933         gtk_widget_realize(summaryview->ctree);
934         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_MARK,
935                          &markxpm);
936         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_DELETED,
937                          &deletedxpm);
938         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_NEW,
939                          &newxpm);
940         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_UNREAD,
941                          &unreadxpm);
942         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_REPLIED,
943                          &repliedxpm);
944         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_FORWARDED,
945                          &forwardedxpm);
946         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_REPLIED_AND_FORWARDED,
947                          &repliedandforwardedxpm);
948         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_CLIP,
949                          &clipxpm);
950         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_LOCKED,
951                          &lockedxpm);
952         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_IGNORETHREAD,
953                          &ignorethreadxpm);
954         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_WATCHTHREAD,
955                          &watchthreadxpm);
956         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_CLIP_KEY,
957                          &clipkeyxpm);
958         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_KEY_SIGN,
959                          &keysignxpm);
960         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_KEY,
961                          &keyxpm);
962         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_GPG_SIGNED,
963                          &gpgsignedxpm);
964         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_CLIP_GPG_SIGNED,
965                          &clipgpgsignedxpm);
966         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_SPAM,
967                          &spamxpm);
968         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_MOVED,
969                          &movedxpm);
970         stock_pixbuf_gdk(summaryview->ctree, STOCK_PIXMAP_COPIED,
971                          &copiedxpm);
972
973         summary_set_fonts(summaryview);
974
975         summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
976
977         pixmap = stock_pixmap_widget(summaryview->hbox, STOCK_PIXMAP_QUICKSEARCH);
978         gtk_container_add (GTK_CONTAINER(summaryview->toggle_search), pixmap);
979         gtk_widget_show(pixmap);
980         summaryview->quick_search_pixmap = pixmap;
981         
982 #ifdef GENERIC_UMPC
983         pixmap = stock_pixmap_widget(summaryview->hbox, STOCK_PIXMAP_SELECTION);
984         gtk_container_add(GTK_CONTAINER(summaryview->multiple_sel_togbtn), pixmap);
985         gtk_widget_show(pixmap);
986         summaryview->multiple_sel_image = pixmap;
987 #endif
988
989         /* Init summaryview prefs */
990         summaryview->sort_key = SORT_BY_NONE;
991         summaryview->sort_type = SORT_ASCENDING;
992
993         /* Init summaryview extra data */
994 #ifndef G_OS_WIN32
995         summaryview->simplify_subject_preg = NULL;
996 #endif
997         summary_clear_list(summaryview);
998         summary_set_column_titles(summaryview);
999         summary_colorlabel_menu_create(summaryview, FALSE);
1000         summary_tags_menu_create(summaryview, FALSE);
1001         main_create_mailing_list_menu (summaryview->mainwin, NULL);     
1002         summary_set_menu_sensitive(summaryview);
1003
1004 }
1005
1006 #define CURRENTLY_DISPLAYED(m) \
1007 ( (m->msgnum == displayed_msgnum) \
1008   && (!g_ascii_strcasecmp(m->folder->name,item->name)) )
1009
1010 #define FOLDER_SHOWS_TO_HDR(i) \
1011 ( i && (folder_has_parent_of_type(i, F_OUTBOX) \
1012         || folder_has_parent_of_type(i, F_DRAFT) \
1013         || folder_has_parent_of_type(i, F_QUEUE)) )
1014   
1015 static void summary_switch_from_to(SummaryView *summaryview, FolderItem *item)
1016 {
1017         gboolean show_from = FALSE, show_to = FALSE;
1018         gboolean showing_from = FALSE, showing_to = FALSE;
1019         gint from_pos = 0, to_pos = 0;
1020         SummaryColumnState *col_state = summaryview->col_state;
1021         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1022         
1023         if (!item || ((prefs_common.layout_mode == VERTICAL_LAYOUT || prefs_common.layout_mode == SMALL_LAYOUT) && prefs_common.two_line_vert) )
1024                 return;
1025         if (FOLDER_SHOWS_TO_HDR(item))
1026                 show_to = TRUE;
1027         else
1028                 show_from = TRUE;
1029         
1030         from_pos = summaryview->col_pos[S_COL_FROM];
1031         to_pos = summaryview->col_pos[S_COL_TO];
1032         showing_from = col_state[from_pos].visible;
1033         showing_to = col_state[to_pos].visible;
1034         
1035         if (showing_from && showing_to) {
1036                 debug_print("showing both\n");
1037                 return;
1038         }
1039
1040         if (!showing_from && !showing_to) {
1041                 debug_print("showing none\n");
1042                 return;
1043         }
1044
1045         debug_print("showing %s %s, must show %s %s\n", 
1046                 showing_from?"From":"",
1047                 showing_to?"To":"",
1048                 show_from?"From":"",
1049                 show_to?"To":"");
1050
1051         if (showing_from == show_from && showing_to == show_to)
1052                 return;
1053         /* else we'll switch both */
1054
1055         debug_print("switching columns\n");
1056         col_state[from_pos].type = S_COL_TO;
1057         col_state[from_pos].visible = show_to;
1058
1059         col_state[to_pos].type = S_COL_FROM;
1060         col_state[to_pos].visible = show_from;
1061
1062         summaryview->col_pos[S_COL_TO] = from_pos;
1063         summaryview->col_pos[S_COL_FROM] = to_pos;
1064
1065         gtk_cmclist_set_column_visibility
1066                 (GTK_CMCLIST(ctree), from_pos, col_state[from_pos].visible);
1067         gtk_cmclist_set_column_visibility
1068                 (GTK_CMCLIST(ctree), to_pos, col_state[to_pos].visible);
1069
1070         summary_set_column_titles(summaryview);
1071 }
1072
1073 static void summaryview_reset_recursive_folder_match(SummaryView *summaryview)
1074 {
1075         GSList *cur;
1076
1077         for (cur = summaryview->recursive_matched_folders; cur != NULL; cur = cur->next) {
1078                 folderview_update_search_icon(cur->data, FALSE);
1079         }
1080
1081         g_slist_free(summaryview->recursive_matched_folders);
1082         summaryview->recursive_matched_folders = NULL;
1083         summaryview->search_root_folder = NULL;
1084 }
1085
1086 static gboolean summaryview_quicksearch_recursive_progress(gpointer data, guint at, guint matched, guint total)
1087 {
1088         QuickSearch *search = (QuickSearch*) data;
1089         gint interval = quicksearch_is_fast(search) ? 5000 : 100;
1090
1091         statusbar_progress_all(at, total, interval);
1092         if (at % interval == 0)
1093                 GTK_EVENTS_FLUSH();
1094
1095         if (matched > 0)
1096                 return FALSE;
1097
1098         return TRUE;
1099 }
1100
1101 static void summaryview_quicksearch_recurse_step(SummaryView *summaryview, FolderItem *item)
1102 {
1103         MsgInfoList *msgs = NULL;
1104         gboolean result = TRUE;
1105
1106         statusbar_print_all(_("Searching in %s... \n"),
1107                 item->path ? item->path : "(null)");
1108         folder_item_update_freeze();
1109
1110         quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_quicksearch_recursive_progress, summaryview->quicksearch);
1111         if (!quicksearch_run_on_folder(summaryview->quicksearch, item, &msgs))
1112                 result = FALSE;
1113
1114         result = result && msgs != NULL;
1115
1116         if (msgs != NULL)
1117                 procmsg_msg_list_free(msgs);
1118
1119         folder_item_update_thaw();
1120         statusbar_progress_all(0, 0, 0);
1121         statusbar_pop_all();
1122
1123         if (result) {
1124                 summaryview->recursive_matched_folders = g_slist_prepend(
1125                                 summaryview->recursive_matched_folders, item);
1126         
1127                 folderview_update_search_icon(item, TRUE);
1128         }
1129 }
1130
1131 static void summaryview_quicksearch_search_subfolders(SummaryView *summaryview, FolderItem *folder_item)
1132 {
1133         FolderItem *cur = NULL;
1134         GNode *node = folder_item->node->children;
1135
1136         if (!prefs_common.summary_quicksearch_recurse
1137                         || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1138                         || quicksearch_is_in_typing(summaryview->quicksearch))
1139                 return;
1140
1141         for (; node != NULL; node = node->next) {
1142                 if (!quicksearch_has_sat_predicate(summaryview->quicksearch))
1143                         return;
1144
1145                 cur = FOLDER_ITEM(node->data);
1146                 summaryview_quicksearch_recurse_step(summaryview, cur);
1147                 if (cur->node->children)
1148                         summaryview_quicksearch_search_subfolders(summaryview, cur);
1149         }
1150 }
1151
1152 static void summaryview_quicksearch_recurse(SummaryView *summaryview)
1153 {
1154         if (!prefs_common.summary_quicksearch_recurse
1155                 || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1156                 || summaryview->folder_item == NULL) {
1157                 return;
1158         }
1159
1160         main_window_cursor_wait(summaryview->mainwin);
1161
1162         summaryview_reset_recursive_folder_match(summaryview);
1163         summaryview->search_root_folder = summaryview->folder_item;
1164
1165         summaryview_quicksearch_search_subfolders(summaryview, summaryview->folder_item);
1166         
1167         main_window_cursor_normal(summaryview->mainwin);
1168 }
1169
1170 static gboolean summary_check_consistency(FolderItem *item, GSList *mlist)
1171 {
1172         int u = 0, n = 0, m = 0, t = 0, r = 0, f = 0, l = 0, i = 0, w = 0;
1173         GSList *cur;
1174         START_TIMING("");
1175         for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1176                 MsgInfo * msginfo = (MsgInfo *) cur->data;
1177                 t++;
1178                 if (MSG_IS_NEW(msginfo->flags))
1179                         n++;
1180                 if (MSG_IS_UNREAD(msginfo->flags))
1181                         u++;
1182                 if (MSG_IS_MARKED(msginfo->flags))
1183                         m++;            
1184                 if (MSG_IS_REPLIED(msginfo->flags))
1185                         r++;
1186                 if (MSG_IS_FORWARDED(msginfo->flags))
1187                         f++;
1188                 if (MSG_IS_LOCKED(msginfo->flags))
1189                         l++;
1190                 if (MSG_IS_IGNORE_THREAD(msginfo->flags))
1191                         i++;
1192                 if (MSG_IS_WATCH_THREAD(msginfo->flags))
1193                         w++;
1194         }
1195         if (t != item->total_msgs
1196         ||  n != item->new_msgs
1197         ||  u != item->unread_msgs
1198         ||  m != item->marked_msgs
1199         ||  r != item->replied_msgs
1200         ||  f != item->forwarded_msgs
1201         ||  l != item->locked_msgs
1202         ||  i != item->ignored_msgs
1203         ||  w != item->watched_msgs
1204         ||  (m == 0 && item->unreadmarked_msgs != 0)
1205         ||  item->unreadmarked_msgs < 0) {
1206                 debug_print("Inconsistency\n");
1207                 folder_item_scan_full(item, FALSE);
1208                 END_TIMING();
1209                 return FALSE;
1210         } 
1211         END_TIMING();
1212         return TRUE;
1213 }
1214
1215 gboolean summaryview_search_root_progress(gpointer data, guint at, guint matched, guint total)
1216 {
1217         SummaryView *summaryview = (SummaryView*) data;
1218
1219         gint interval = quicksearch_is_fast(summaryview->quicksearch) ? 5000 : 100;
1220         
1221         statusbar_progress_all(at, total, interval);
1222
1223         if (at % interval == 0)
1224                 GTK_EVENTS_FLUSH();
1225
1226         return TRUE;
1227 }
1228
1229 gboolean summary_show(SummaryView *summaryview, FolderItem *item)
1230 {
1231         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1232         GtkCMCTreeNode *node = NULL;
1233         GSList *mlist = NULL;
1234         gchar *buf;
1235         gboolean is_refresh;
1236         guint selected_msgnum = 0;
1237         guint displayed_msgnum = 0;
1238         GSList *cur;
1239         GSList *not_killed;
1240         gboolean hidden_removed = FALSE;
1241
1242         if (summary_is_locked(summaryview)) return FALSE;
1243
1244         if (!summaryview->mainwin)
1245                 return FALSE;
1246         START_TIMING("");
1247         summary_switch_from_to(summaryview, item);
1248
1249         inc_lock();
1250         summary_lock(summaryview);
1251         
1252         menu_set_sensitive_all(GTK_MENU_SHELL(summaryview->popupmenu), TRUE);
1253         
1254         utils_free_regex();
1255
1256         is_refresh = (item == summaryview->folder_item) ? TRUE : FALSE;
1257
1258         if (item && item->folder->klass->item_opened) {
1259                 item->folder->klass->item_opened(item);
1260         }
1261
1262         if (!is_refresh) {
1263                 main_create_mailing_list_menu (summaryview->mainwin, NULL);
1264                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
1265                         if (item) {
1266                                 mainwindow_enter_folder(summaryview->mainwin);
1267                                 gtk_widget_grab_focus(summaryview->ctree);
1268                         }
1269                 }
1270         }
1271         if (!prefs_common.summary_quicksearch_sticky
1272          && (!prefs_common.summary_quicksearch_recurse
1273           || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1274           || (item && !folder_is_child_of(item, summaryview->search_root_folder)))
1275          && !quicksearch_is_running(summaryview->quicksearch)
1276          && !is_refresh) {
1277                 quicksearch_set(summaryview->quicksearch, prefs_common.summary_quicksearch_type, "");
1278         }
1279
1280         /* STATUSBAR_POP(summaryview->mainwin); */
1281
1282         if (is_refresh) {
1283                 selected_msgnum = summary_get_msgnum(summaryview,
1284                                                      summaryview->selected);
1285                 displayed_msgnum = summary_get_msgnum(summaryview,
1286                                                       summaryview->displayed);
1287         }
1288
1289         /* process the marks if any */
1290         if (summaryview->mainwin->lock_count == 0 &&
1291             (summaryview->moved > 0 || summaryview->copied > 0)) {
1292                 AlertValue val;
1293                 gboolean changed = FALSE;
1294
1295                 val = alertpanel(_("Process mark"),
1296                                  _("Some marks are left. Process them?"),
1297                                  GTK_STOCK_NO, GTK_STOCK_YES, GTK_STOCK_CANCEL);
1298                 if (G_ALERTALTERNATE == val) {
1299                         summary_unlock(summaryview);
1300                         summary_execute(summaryview);
1301                         summary_lock(summaryview);
1302                         changed = TRUE;
1303                 } else if (G_ALERTDEFAULT == val) {
1304                         /* DO NOTHING */
1305                 } else {
1306                         summary_unlock(summaryview);
1307                         inc_unlock();
1308                         END_TIMING();
1309                         return FALSE;
1310                 }
1311                 if (changed || !quicksearch_has_sat_predicate(summaryview->quicksearch))
1312                         folder_update_op_count();
1313         }
1314         
1315         summary_freeze(summaryview);
1316
1317         summary_clear_list(summaryview);
1318
1319         buf = NULL;
1320         if (!item || !item->path || !folder_item_parent(item) || item->no_select) {
1321                 g_free(buf);
1322                 debug_print("empty folder (%p %s %p %d)\n\n",
1323                                 item, 
1324                                 (item && item->path)?item->path:"(null)",
1325                                 item?folder_item_parent(item):0x0,
1326                                 item?item->no_select:FALSE);
1327                 summary_set_hide_read_msgs_menu(summaryview, FALSE);
1328                 summary_set_hide_del_msgs_menu(summaryview, FALSE);
1329                 summary_set_hide_read_threads_menu(summaryview, FALSE);
1330                 summary_clear_all(summaryview);
1331                 summaryview->folder_item = item;
1332                 summary_thaw(summaryview);
1333                 summary_unlock(summaryview);
1334                 inc_unlock();
1335                 END_TIMING();
1336                 return TRUE;
1337         }
1338         g_free(buf);
1339
1340         if (!is_refresh)
1341                 messageview_clear(summaryview->messageview);
1342
1343         summaryview->folder_item = item;
1344         item->opened = TRUE;
1345
1346         buf = g_strdup_printf(_("Scanning folder (%s)..."), item->path);
1347         debug_print("%s\n", buf);
1348         STATUSBAR_PUSH(summaryview->mainwin, buf);
1349         g_free(buf);
1350
1351         main_window_cursor_wait(summaryview->mainwin);
1352
1353         mlist = folder_item_get_msg_list(item);
1354
1355         if (!summary_check_consistency(item, mlist)) {
1356                 debug_print("reloading due to inconsistency\n");
1357                 procmsg_msg_list_free(mlist);
1358                 mlist = folder_item_get_msg_list(item);
1359         }
1360
1361         if (quicksearch_has_sat_predicate(summaryview->quicksearch)) {
1362                 procmsg_msg_list_free(mlist);
1363                 mlist = NULL;
1364
1365                 START_TIMING("quicksearch");
1366
1367                 statusbar_print_all(_("Searching in %s... \n"), 
1368                         summaryview->folder_item->path ? 
1369                         summaryview->folder_item->path : "(null)");
1370
1371                 folder_item_update_freeze();
1372
1373                 quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_search_root_progress, summaryview);
1374                 quicksearch_run_on_folder(summaryview->quicksearch, summaryview->folder_item, &mlist);
1375
1376                 folder_item_update_thaw();
1377                 statusbar_progress_all(0, 0, 0);
1378                 statusbar_pop_all();
1379
1380                 if (!quicksearch_has_sat_predicate(summaryview->quicksearch)) {
1381                         debug_print("search cancelled!\n");
1382                         summary_thaw(summaryview);
1383                         STATUSBAR_POP(summaryview->mainwin);
1384                         main_window_cursor_normal(summaryview->mainwin);
1385                         summary_unlock(summaryview);
1386                         inc_unlock();
1387                         summary_show(summaryview, summaryview->folder_item);
1388                         END_TIMING();
1389                         return FALSE;
1390                 }
1391                 END_TIMING();
1392         }
1393
1394         if ((summaryview->folder_item->hide_read_msgs
1395              || summaryview->folder_item->hide_del_msgs
1396              || summaryview->folder_item->hide_read_threads) &&
1397             quicksearch_has_sat_predicate(summaryview->quicksearch) == FALSE) {
1398                 GSList *not_killed;
1399                 
1400                 summary_set_hide_read_msgs_menu(summaryview, summaryview->folder_item->hide_read_msgs);
1401                 summary_set_hide_del_msgs_menu(summaryview, summaryview->folder_item->hide_del_msgs);
1402                 summary_set_hide_read_threads_menu(summaryview, summaryview->folder_item->hide_read_threads);
1403                 not_killed = NULL;
1404                 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1405                         MsgInfo * msginfo = (MsgInfo *) cur->data;
1406                         
1407                         if (!msginfo->hidden) {
1408                                 if (MSG_IS_DELETED(msginfo->flags) && summaryview->folder_item->hide_del_msgs) {
1409                                         procmsg_msginfo_free(msginfo);
1410                                         continue;
1411                                 }
1412                                 if (summaryview->folder_item->hide_read_msgs) {
1413                                         if (MSG_IS_UNREAD(msginfo->flags) &&
1414                                             !MSG_IS_IGNORE_THREAD(msginfo->flags))
1415                                                 not_killed = g_slist_prepend(not_killed, msginfo);
1416                                         else if (MSG_IS_MARKED(msginfo->flags) ||
1417                                                  MSG_IS_LOCKED(msginfo->flags))
1418                                                 not_killed = g_slist_prepend(not_killed, msginfo);
1419                                         else if (is_refresh &&
1420                                                 (msginfo->msgnum == selected_msgnum ||
1421                                                  msginfo->msgnum == displayed_msgnum))
1422                                                 not_killed = g_slist_prepend(not_killed, msginfo);
1423                                         else
1424                                                 procmsg_msginfo_free(msginfo);
1425                                 } else {
1426                                         not_killed = g_slist_prepend(not_killed, msginfo);
1427                                 }
1428                          } else
1429                                 procmsg_msginfo_free(msginfo);
1430                 }
1431                 hidden_removed = TRUE;
1432                 g_slist_free(mlist);
1433                 mlist = not_killed;
1434         } else {
1435                 summary_set_hide_read_msgs_menu(summaryview, FALSE);
1436                 summary_set_hide_del_msgs_menu(summaryview, FALSE);
1437                 summary_set_hide_read_threads_menu(summaryview, FALSE);
1438         }
1439
1440         if (!hidden_removed) {
1441                 START_TIMING("removing hidden");
1442                 not_killed = NULL;
1443                 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1444                         MsgInfo * msginfo = (MsgInfo *) cur->data;
1445
1446                         if (!msginfo->hidden)
1447                                 not_killed = g_slist_prepend(not_killed, msginfo);
1448                         else
1449                                 procmsg_msginfo_free(msginfo);
1450                 }
1451                 g_slist_free(mlist);
1452                 mlist = not_killed;
1453                 END_TIMING();
1454         }
1455
1456         STATUSBAR_POP(summaryview->mainwin);
1457
1458         /* set ctree and hash table from the msginfo list, and
1459            create the thread */
1460         summary_set_ctree_from_list(summaryview, mlist);
1461
1462         g_slist_free(mlist);
1463
1464         if (is_refresh) {
1465                 if (!quicksearch_is_in_typing(summaryview->quicksearch)) {
1466                         summaryview->displayed =
1467                                 summary_find_msg_by_msgnum(summaryview,
1468                                                            displayed_msgnum);
1469                         if (!summaryview->displayed)
1470                                 messageview_clear(summaryview->messageview);
1471                         summary_unlock(summaryview);
1472                         summary_select_by_msgnum(summaryview, selected_msgnum);
1473                         summary_lock(summaryview);
1474                         if (!summaryview->selected) {
1475                                 /* no selected message - select first unread
1476                                    message, but do not display it */
1477                                 node = summary_find_next_flagged_msg(summaryview, NULL,
1478                                                                      MSG_UNREAD, FALSE);
1479                                 if (node == NULL && GTK_CMCLIST(ctree)->row_list != NULL)
1480                                         node = gtk_cmctree_node_nth
1481                                                 (ctree,
1482                                                  item->sort_type == SORT_DESCENDING
1483                                                  ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1484                                 summary_unlock(summaryview);
1485                                 summary_select_node(summaryview, node, FALSE, TRUE);
1486                                 summary_lock(summaryview);
1487                         }
1488                 } else {
1489                         /* just select first/last */
1490                         if (GTK_CMCLIST(ctree)->row_list != NULL)
1491                                 node = gtk_cmctree_node_nth
1492                                         (ctree,
1493                                          item->sort_type == SORT_DESCENDING
1494                                          ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1495                         gtk_sctree_select(GTK_SCTREE(ctree), node);
1496                         summaryview->selected = node;
1497                         gtk_cmctree_node_moveto(ctree, node, 0, 0.5, 0);
1498                 }
1499         } else {
1500                 /* backward compat */
1501                 int i = 0;
1502                 gboolean set = FALSE, stop = FALSE;
1503                 for (i = 0; i < 6; i++) {
1504                         EntryAction act = prefs_common.summary_select_prio[i];
1505
1506                         if (act != ACTION_UNSET) {
1507                                 set = TRUE;
1508                                 break;
1509                         }
1510                 }
1511                 if (!set)
1512                         prefs_summary_open_set_defaults();
1513
1514                 for (i = 0; i < 6 && node == NULL; i++) {
1515                         EntryAction act = prefs_common.summary_select_prio[i];
1516                         
1517                         switch(act) {
1518                         case ACTION_MARKED:
1519                                 node = summary_find_next_flagged_msg(summaryview, NULL,
1520                                              MSG_MARKED, FALSE);
1521                                 break;
1522                         case ACTION_NEW:
1523                                 node = summary_find_next_flagged_msg(summaryview, NULL,
1524                                              MSG_NEW, FALSE);
1525                                 break;
1526                         case ACTION_UNREAD:
1527                                 node = summary_find_next_flagged_msg(summaryview, NULL,
1528                                              MSG_UNREAD, FALSE);
1529                                 break;
1530                         case ACTION_LAST_OPENED:
1531                                 if (summaryview->folder_item) {
1532                                         node = summary_find_msg_by_msgnum(summaryview, 
1533                                                         summaryview->folder_item->last_seen);
1534                                 }
1535                                 break;
1536                         case ACTION_LAST_LIST:
1537                                 if (GTK_CMCLIST(ctree)->row_list != NULL) {
1538                                         node = gtk_cmctree_node_nth
1539                                                 (ctree,
1540                                                  item->sort_type == SORT_DESCENDING
1541                                                  ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1542                                 }
1543                                 break;
1544                         case ACTION_FIRST_LIST:
1545                                 if (GTK_CMCLIST(ctree)->row_list != NULL) {
1546                                         node = gtk_cmctree_node_nth
1547                                                 (ctree,
1548                                                  item->sort_type == SORT_ASCENDING
1549                                                  ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1550                                 }
1551                                 break;
1552                         case ACTION_NOTHING:
1553                         case ACTION_UNSET:
1554                                 node = NULL;
1555                                 stop = TRUE;
1556                                 break;
1557                         }
1558                         
1559                         if (stop || node)
1560                                 break;
1561                 }
1562
1563                 summary_unlock(summaryview);
1564                 if (node) {
1565                         gboolean show = (prefs_common.always_show_msg == OPENMSG_ALWAYS) ||
1566                                 (prefs_common.always_show_msg == OPENMSG_WHEN_VIEW_VISIBLE &&
1567                                                 messageview_is_visible(summaryview->messageview));
1568                         summary_select_node(summaryview, node, show, TRUE);
1569                 }
1570                 summary_lock(summaryview);
1571         }
1572
1573         summary_status_show(summaryview);
1574         summary_set_menu_sensitive(summaryview);
1575         toolbar_main_set_sensitive(summaryview->mainwin);
1576         
1577         summary_thaw(summaryview);
1578         debug_print("\n");
1579         STATUSBAR_PUSH(summaryview->mainwin, _("Done."));
1580         STATUSBAR_POP(summaryview->mainwin);
1581         main_window_cursor_normal(summaryview->mainwin);
1582         summary_unlock(summaryview);
1583         inc_unlock();
1584         END_TIMING();
1585         return TRUE;
1586 }
1587
1588 #undef CURRENTLY_DISPLAYED
1589
1590
1591 void summary_clear_list(SummaryView *summaryview)
1592 {
1593         GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
1594         gint optimal_width;
1595
1596         summary_freeze(summaryview);
1597
1598         gtk_cmctree_pre_recursive(GTK_CMCTREE(summaryview->ctree),
1599                                 NULL, summary_free_msginfo_func, NULL);
1600
1601         if (summaryview->folder_item) {
1602                 summaryview->folder_item->opened = FALSE;
1603                 summaryview->folder_item = NULL;
1604         }
1605
1606         if (summaryview->mark_as_read_timeout_tag != 0) {
1607                 g_source_remove(summaryview->mark_as_read_timeout_tag);
1608                 summaryview->mark_as_read_timeout_tag = 0;
1609         }
1610
1611         summaryview->display_msg = FALSE;
1612
1613         summaryview->selected = NULL;
1614         summaryview->displayed = NULL;
1615         summaryview->total_size = 0;
1616         summaryview->deleted = summaryview->moved = 0;
1617         summaryview->copied = 0;
1618         if (summaryview->msgid_table) {
1619                 g_hash_table_destroy(summaryview->msgid_table);
1620                 summaryview->msgid_table = NULL;
1621         }
1622         if (summaryview->subject_table) {
1623                 g_hash_table_destroy(summaryview->subject_table);
1624                 summaryview->subject_table = NULL;
1625         }
1626         summaryview->mlist = NULL;
1627
1628         gtk_cmclist_clear(clist);
1629         if (summaryview->col_pos[S_COL_SUBJECT] == N_SUMMARY_COLS - 1) {
1630                 optimal_width = gtk_cmclist_optimal_column_width
1631                         (clist, summaryview->col_pos[S_COL_SUBJECT]);
1632                 gtk_cmclist_set_column_width
1633                         (clist, summaryview->col_pos[S_COL_SUBJECT],
1634                          optimal_width);
1635         }
1636
1637         summary_thaw(summaryview);
1638 }
1639
1640 void summary_clear_all(SummaryView *summaryview)
1641 {
1642         messageview_clear(summaryview->messageview);
1643         summary_clear_list(summaryview);
1644         summary_set_menu_sensitive(summaryview);
1645         toolbar_main_set_sensitive(summaryview->mainwin);
1646         summary_status_show(summaryview);
1647 }
1648
1649 void summary_lock(SummaryView *summaryview)
1650 {
1651         summaryview->lock_count++;
1652 }
1653
1654 void summary_unlock(SummaryView *summaryview)
1655 {
1656         if (summaryview->lock_count)
1657                 summaryview->lock_count--;
1658 }
1659
1660 gboolean summary_is_locked(SummaryView *summaryview)
1661 {
1662         return summaryview->lock_count > 0;
1663 }
1664
1665 SummarySelection summary_get_selection_type(SummaryView *summaryview)
1666 {
1667         GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
1668         SummarySelection selection;
1669
1670         if (!clist->row_list)
1671                 selection = SUMMARY_NONE;
1672         else if (!clist->selection)
1673                 selection = SUMMARY_SELECTED_NONE;
1674         else if (!clist->selection->next)
1675                 selection = SUMMARY_SELECTED_SINGLE;
1676         else
1677                 selection = SUMMARY_SELECTED_MULTIPLE;
1678
1679         return selection;
1680 }
1681
1682 /*!
1683  *\return       MsgInfo * Selected message if there's one selected;
1684  *              if multiple selected, or none, return NULL.
1685  */ 
1686 MsgInfo *summary_get_selected_msg(SummaryView *summaryview)
1687 {
1688         /* summaryview->selected may be valid when multiple 
1689          * messages were selected */
1690         GList *sellist = GTK_CMCLIST(summaryview->ctree)->selection;
1691
1692         if (sellist == NULL || sellist->next) 
1693                 return NULL;
1694         
1695         return GTKUT_CTREE_NODE_GET_ROW_DATA(sellist->data);
1696 }
1697
1698 GSList *summary_get_selected_msg_list(SummaryView *summaryview)
1699 {
1700         GSList *mlist = NULL;
1701         GList *cur;
1702         MsgInfo *msginfo;
1703
1704         for (cur = GTK_CMCLIST(summaryview->ctree)->selection; cur != NULL && cur->data != NULL;
1705              cur = cur->next) {
1706                 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(cur->data);
1707                 mlist = g_slist_prepend(mlist, msginfo);
1708         }
1709
1710         mlist = g_slist_reverse(mlist);
1711
1712         return mlist;
1713 }
1714
1715 void summary_set_menu_sensitive(SummaryView *summaryview)
1716 {
1717         SensitiveCondMask state;
1718         gboolean sensitive;
1719         gint i;
1720
1721 #define N_ENTRIES 38
1722         static struct {
1723                 const gchar *entry;
1724                 SensitiveCondMask cond;
1725         } entry[N_ENTRIES];
1726
1727         i = 0;
1728 #define FILL_TABLE(entry_str, ...) \
1729 do { \
1730         entry[i].entry = (const gchar *) entry_str; entry[i++].cond = main_window_get_mask(__VA_ARGS__, -1); \
1731 } while (0)
1732
1733         FILL_TABLE("Menus/SummaryViewPopup/Reply", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1734 #ifndef GENERIC_UMPC
1735         FILL_TABLE("Menus/SummaryViewPopup/ReplyTo", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1736         FILL_TABLE("Menus/SummaryViewPopup/ReplyTo/All", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1737         FILL_TABLE("Menus/SummaryViewPopup/ReplyTo/Sender", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1738         FILL_TABLE("Menus/SummaryViewPopup/ReplyTo/MailingList", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1739 #endif
1740
1741         FILL_TABLE("Menus/SummaryViewPopup/Forward", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1742 #ifndef GENERIC_UMPC
1743         FILL_TABLE("Menus/SummaryViewPopup/ForwardAtt", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1744         FILL_TABLE("Menus/SummaryViewPopup/Redirect", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1745 #endif
1746
1747         FILL_TABLE("Menus/SummaryViewPopup/Move", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS);
1748         FILL_TABLE("Menus/SummaryViewPopup/Copy", M_TARGET_EXIST, M_EXEC);
1749         FILL_TABLE("Menus/SummaryViewPopup/Trash", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS, M_NOT_TRASH);
1750 #ifndef GENERIC_UMPC
1751         FILL_TABLE("Menus/SummaryViewPopup/Delete", M_TARGET_EXIST, M_ALLOW_DELETE);
1752 #endif
1753
1754         FILL_TABLE("Menus/SummaryViewPopup/Mark", M_TARGET_EXIST);
1755         FILL_TABLE("Menus/SummaryViewPopup/Mark/Mark", M_TARGET_EXIST);
1756         FILL_TABLE("Menus/SummaryViewPopup/Mark/Unmark", M_TARGET_EXIST);
1757         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkUnread", M_TARGET_EXIST);
1758         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkRead", M_TARGET_EXIST);
1759         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkAllRead", M_TARGET_EXIST);
1760         FILL_TABLE("Menus/SummaryViewPopup/Mark/IgnoreThread", M_TARGET_EXIST);
1761         FILL_TABLE("Menus/SummaryViewPopup/Mark/UnignoreThread", M_TARGET_EXIST);
1762         FILL_TABLE("Menus/SummaryViewPopup/Mark/WatchThread", M_TARGET_EXIST);
1763         FILL_TABLE("Menus/SummaryViewPopup/Mark/UnwatchThread", M_TARGET_EXIST);
1764         FILL_TABLE("Menus/SummaryViewPopup/Mark/Unlock", M_TARGET_EXIST);
1765         FILL_TABLE("Menus/SummaryViewPopup/Mark/Lock", M_TARGET_EXIST);
1766         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkSpam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
1767         FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkHam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
1768         FILL_TABLE("Menus/SummaryViewPopup/ColorLabel", M_TARGET_EXIST);
1769         FILL_TABLE("Menus/SummaryViewPopup/Tags", M_TARGET_EXIST);
1770
1771 #ifndef GENERIC_UMPC
1772         FILL_TABLE("Menus/SummaryViewPopup/AddSenderToAB", M_SINGLE_TARGET_EXIST);
1773 #endif
1774         FILL_TABLE("Menus/SummaryViewPopup/CreateFilterRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
1775 #ifndef GENERIC_UMPC
1776         FILL_TABLE("Menus/SummaryViewPopup/CreateProcessingRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
1777 #endif
1778
1779         FILL_TABLE("Menus/SummaryViewPopup/View", M_SINGLE_TARGET_EXIST);
1780         FILL_TABLE("Menus/SummaryViewPopup/View/OpenNewWindow", M_SINGLE_TARGET_EXIST);
1781         FILL_TABLE("Menus/SummaryViewPopup/View/MessageSource", M_SINGLE_TARGET_EXIST);
1782 #ifndef GENERIC_UMPC
1783         FILL_TABLE("Menus/SummaryViewPopup/View/AllHeaders", M_SINGLE_TARGET_EXIST);
1784 #endif
1785         FILL_TABLE("Menus/SummaryViewPopup/SaveAs", M_TARGET_EXIST);
1786 #ifndef GENERIC_UMPC
1787         FILL_TABLE("Menus/SummaryViewPopup/Print", M_TARGET_EXIST);
1788 #endif
1789         FILL_TABLE(NULL, -1);
1790 #undef FILL_TABLE
1791         if (i != N_ENTRIES)
1792                 g_error("summaryview menu entry table size mismatch (%d/%d)", i, N_ENTRIES);
1793 #undef ENTRIES
1794
1795         main_window_set_menu_sensitive(summaryview->mainwin);
1796
1797         state = main_window_get_current_state(summaryview->mainwin);
1798
1799         for (i = 0; entry[i].entry != NULL; i++) {
1800                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1801                 cm_menu_set_sensitive_full(summaryview->mainwin->ui_manager, entry[i].entry, sensitive);
1802         }
1803
1804         summary_lock(summaryview);
1805 #ifndef GENERIC_UMPC
1806         if (summaryview->messageview 
1807         &&  summaryview->messageview->mimeview
1808         &&  summaryview->messageview->mimeview->textview)
1809                 cm_toggle_menu_set_active_full(summaryview->mainwin->ui_manager, "Menus/SummaryViewPopup/View/AllHeaders",
1810                         prefs_common.show_all_headers);
1811 #endif
1812         summary_unlock(summaryview);
1813 }
1814
1815 void summary_select_prev_unread(SummaryView *summaryview)
1816 {
1817         GtkCMCTreeNode *node;
1818         gboolean skip_cur = FALSE;
1819
1820         if (summaryview->displayed 
1821         &&  summaryview->selected == summaryview->displayed) {
1822                 debug_print("skipping current\n");
1823                 skip_cur = TRUE;
1824         }
1825
1826         node = summary_find_prev_flagged_msg
1827                 (summaryview, summaryview->selected, MSG_UNREAD, skip_cur);
1828
1829         if (!node || node == summaryview->selected) {
1830                 AlertValue val = 0;
1831
1832                 switch (prefs_common.next_unread_msg_dialog) {
1833                         case NEXTUNREADMSGDIALOG_ALWAYS:
1834                                 val = alertpanel(_("No more unread messages"),
1835                                                  _("No unread message found. "
1836                                                    "Search from the end?"),
1837                                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1838                                 break;
1839                         case NEXTUNREADMSGDIALOG_ASSUME_YES:
1840                                 val = G_ALERTALTERNATE;
1841                                 break;
1842                         case NEXTUNREADMSGDIALOG_ASSUME_NO:
1843                                 val = !G_ALERTALTERNATE;
1844                                 break;
1845                         default:
1846                                 debug_print(
1847                                         _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1848                 }
1849                 if (val != G_ALERTALTERNATE) return;
1850                 node = summary_find_prev_flagged_msg(summaryview, NULL,
1851                                                      MSG_UNREAD, FALSE);
1852         }
1853
1854         if (!node)
1855                 alertpanel_notice(_("No unread messages."));
1856         else
1857                 summary_select_node(summaryview, node, TRUE, FALSE);
1858 }
1859
1860 void summary_select_next_unread(SummaryView *summaryview)
1861 {
1862         GtkCMCTreeNode *node = summaryview->selected;
1863         gboolean skip_cur = FALSE;
1864         
1865         if (summaryview->displayed 
1866         &&  summaryview->selected == summaryview->displayed) {
1867                 debug_print("skipping cur (%p %p)\n",
1868                         summaryview->displayed, summaryview->selected);
1869                 skip_cur = TRUE;
1870         }
1871
1872
1873         node = summary_find_next_flagged_msg
1874                 (summaryview, node, MSG_UNREAD, skip_cur);
1875         
1876         if (node)
1877                 summary_select_node(summaryview, node, TRUE, FALSE);
1878         else {
1879                 node = summary_find_next_flagged_msg
1880                         (summaryview, NULL, MSG_UNREAD, FALSE);
1881                 if (node == NULL || node == summaryview->selected) {
1882                         AlertValue val = 0;
1883
1884                         switch (prefs_common.next_unread_msg_dialog) {
1885                                 case NEXTUNREADMSGDIALOG_ALWAYS:
1886                                         val = alertpanel(_("No more unread messages"),
1887                                                          _("No unread message found. "
1888                                                            "Go to next folder?"),
1889                                                          GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1890                                         break;
1891                                 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1892                                         val = G_ALERTALTERNATE;
1893                                         break;
1894                                 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1895                                         val = G_ALERTOTHER;
1896                                         break;
1897                                 default:
1898                                         debug_print(
1899                                                 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1900                         }
1901
1902                         if (val == G_ALERTALTERNATE) {
1903                                 folderview_select_next_unread(summaryview->folderview, TRUE);
1904                                 return;
1905                         } 
1906                         else
1907                                 return;
1908                 } else
1909                         summary_select_node(summaryview, node, TRUE, FALSE);
1910
1911         }
1912 }
1913
1914 void summary_select_prev_new(SummaryView *summaryview)
1915 {
1916         GtkCMCTreeNode *node;
1917         gboolean skip_cur = FALSE;
1918
1919         if (summaryview->displayed 
1920         &&  summaryview->selected == summaryview->displayed) {
1921                 debug_print("skipping current\n");
1922                 skip_cur = TRUE;
1923         }
1924
1925         node = summary_find_prev_flagged_msg
1926                 (summaryview, summaryview->selected, MSG_NEW, skip_cur);
1927
1928         if (!node || node == summaryview->selected) {
1929                 AlertValue val = 0;
1930
1931                 switch (prefs_common.next_unread_msg_dialog) {
1932                         case NEXTUNREADMSGDIALOG_ALWAYS:
1933                                 val = alertpanel(_("No more new messages"),
1934                                                  _("No new message found. "
1935                                                    "Search from the end?"),
1936                                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1937                                 break;
1938                         case NEXTUNREADMSGDIALOG_ASSUME_YES:
1939                                 val = G_ALERTALTERNATE;
1940                                 break;
1941                         case NEXTUNREADMSGDIALOG_ASSUME_NO:
1942                                 val = !G_ALERTALTERNATE;
1943                                 break;
1944                         default:
1945                                 debug_print(
1946                                         _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1947                 }
1948                 if (val != G_ALERTALTERNATE) return;
1949                 node = summary_find_prev_flagged_msg(summaryview, NULL,
1950                                                      MSG_NEW, FALSE);
1951         }
1952
1953         if (!node)
1954                 alertpanel_notice(_("No new messages."));
1955         else
1956                 summary_select_node(summaryview, node, TRUE, FALSE);
1957 }
1958
1959 void summary_select_next_new(SummaryView *summaryview)
1960 {
1961         GtkCMCTreeNode *node = summaryview->selected;
1962         gboolean skip_cur = FALSE;
1963         
1964         if (summaryview->displayed 
1965         &&  summaryview->selected == summaryview->displayed) {
1966                 debug_print("skipping cur (%p %p)\n",
1967                         summaryview->displayed, summaryview->selected);
1968                 skip_cur = TRUE;
1969         }
1970
1971
1972         node = summary_find_next_flagged_msg
1973                 (summaryview, node, MSG_NEW, skip_cur);
1974         
1975         if (node)
1976                 summary_select_node(summaryview, node, TRUE, FALSE);
1977         else {
1978                 node = summary_find_next_flagged_msg
1979                         (summaryview, NULL, MSG_NEW, FALSE);
1980                 if (node == NULL || node == summaryview->selected) {
1981                         AlertValue val = 0;
1982
1983                         switch (prefs_common.next_unread_msg_dialog) {
1984                                 case NEXTUNREADMSGDIALOG_ALWAYS:
1985                                         val = alertpanel(_("No more new messages"),
1986                                                          _("No new message found. "
1987                                                            "Go to next folder?"),
1988                                                          GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1989                                         break;
1990                                 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1991                                         val = G_ALERTALTERNATE;
1992                                         break;
1993                                 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1994                                         val = G_ALERTOTHER;
1995                                         break;
1996                                 default:
1997                                         debug_print(
1998                                                 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1999                         }
2000
2001                         if (val == G_ALERTALTERNATE) {
2002                                 folderview_select_next_new(summaryview->folderview);
2003                                 return;
2004                         } 
2005                         else
2006                                 return;
2007                 } else
2008                         summary_select_node(summaryview, node, TRUE, FALSE);
2009
2010         }
2011 }
2012
2013 void summary_select_prev_marked(SummaryView *summaryview)
2014 {
2015         GtkCMCTreeNode *node;
2016
2017         node = summary_find_prev_flagged_msg
2018                 (summaryview, summaryview->selected, MSG_MARKED, TRUE);
2019
2020         if (!node) {
2021                 AlertValue val;
2022
2023                 val = alertpanel(_("No more marked messages"),
2024                                  _("No marked message found. "
2025                                    "Search from the end?"),
2026                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2027                 if (val != G_ALERTALTERNATE) return;
2028                 node = summary_find_prev_flagged_msg(summaryview, NULL,
2029                                                      MSG_MARKED, TRUE);
2030         }
2031
2032         if (!node)
2033                 alertpanel_notice(_("No marked messages."));
2034         else
2035                 summary_select_node(summaryview, node, TRUE, FALSE);
2036 }
2037
2038 void summary_select_next_marked(SummaryView *summaryview)
2039 {
2040         GtkCMCTreeNode *node = summaryview->selected;
2041         gboolean skip_cur = FALSE;
2042         
2043         if (summaryview->displayed 
2044         &&  summaryview->selected == summaryview->displayed) {
2045                 debug_print("skipping cur (%p %p)\n",
2046                         summaryview->displayed, summaryview->selected);
2047                 skip_cur = TRUE;
2048         }
2049
2050
2051         node = summary_find_next_flagged_msg
2052                 (summaryview, node, MSG_MARKED, skip_cur);
2053         
2054         if (node)
2055                 summary_select_node(summaryview, node, TRUE, FALSE);
2056         else {
2057                 node = summary_find_next_flagged_msg
2058                         (summaryview, NULL, MSG_MARKED, FALSE);
2059                 if (node == NULL || node == summaryview->selected) {
2060                         AlertValue val = 0;
2061
2062                         switch (prefs_common.next_unread_msg_dialog) {
2063                                 case NEXTUNREADMSGDIALOG_ALWAYS:
2064                                         val = alertpanel(_("No more marked messages"),
2065                                                          _("No marked message found. "
2066                                                            "Go to next folder?"),
2067                                                          GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2068                                         break;
2069                                 case NEXTUNREADMSGDIALOG_ASSUME_YES:
2070                                         val = G_ALERTALTERNATE;
2071                                         break;
2072                                 case NEXTUNREADMSGDIALOG_ASSUME_NO:
2073                                         val = G_ALERTOTHER;
2074                                         break;
2075                                 default:
2076                                         debug_print(
2077                                                 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
2078                         }
2079
2080                         if (val == G_ALERTALTERNATE) {
2081                                 folderview_select_next_marked(summaryview->folderview);
2082                                 return;
2083                         } 
2084                         else
2085                                 return;
2086                 } else
2087                         summary_select_node(summaryview, node, TRUE, FALSE);
2088
2089         }
2090 }
2091
2092 void summary_select_prev_labeled(SummaryView *summaryview)
2093 {
2094         GtkCMCTreeNode *node;
2095
2096         node = summary_find_prev_flagged_msg
2097                 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2098
2099         if (!node) {
2100                 AlertValue val;
2101
2102                 val = alertpanel(_("No more labeled messages"),
2103                                  _("No labeled message found. "
2104                                    "Search from the end?"),
2105                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2106                 if (val != G_ALERTALTERNATE) return;
2107                 node = summary_find_prev_flagged_msg(summaryview, NULL,
2108                                                      MSG_CLABEL_FLAG_MASK, TRUE);
2109         }
2110
2111         if (!node)
2112                 alertpanel_notice(_("No labeled messages."));
2113         else
2114                 summary_select_node(summaryview, node, TRUE, FALSE);
2115 }
2116
2117 void summary_select_next_labeled(SummaryView *summaryview)
2118 {
2119         GtkCMCTreeNode *node;
2120
2121         node = summary_find_next_flagged_msg
2122                 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2123
2124         if (!node) {
2125                 AlertValue val;
2126
2127                 val = alertpanel(_("No more labeled messages"),
2128                                  _("No labeled message found. "
2129                                    "Search from the beginning?"),
2130                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2131                 if (val != G_ALERTALTERNATE) return;
2132                 node = summary_find_next_flagged_msg(summaryview, NULL,
2133                                                      MSG_CLABEL_FLAG_MASK, TRUE);
2134         }
2135
2136         if (!node)
2137                 alertpanel_notice(_("No labeled messages."));
2138         else
2139                 summary_select_node(summaryview, node, TRUE, FALSE);
2140 }
2141
2142 void summary_select_parent(SummaryView *summaryview)
2143 {
2144         GtkCMCTreeNode *node = NULL;
2145
2146         if (summaryview->selected)
2147                 node = GTK_CMCTREE_ROW(summaryview->selected)->parent;
2148         if (node)
2149                 summary_select_node(summaryview, node, TRUE, FALSE);
2150 }
2151
2152 void summary_select_by_msgnum(SummaryView *summaryview, guint msgnum)
2153 {
2154         GtkCMCTreeNode *node;
2155
2156         node = summary_find_msg_by_msgnum(summaryview, msgnum);
2157         summary_select_node(summaryview, node, FALSE, TRUE);
2158 }
2159
2160 void summary_display_by_msgnum(SummaryView *summaryview, guint msgnum)
2161 {
2162         GtkCMCTreeNode *node;
2163
2164         node = summary_find_msg_by_msgnum(summaryview, msgnum);
2165         summary_select_node(summaryview, node, TRUE, FALSE);
2166 }
2167
2168 void summary_select_by_msg_list(SummaryView     *summaryview, GSList *msginfos)
2169 {
2170         GtkCMCTree *ctree;
2171         GSList *msgnum_list, *walk;
2172         gboolean froze = FALSE;
2173
2174         ctree = GTK_CMCTREE(summaryview->ctree);
2175
2176         msgnum_list = procmsg_get_number_list_for_msgs(msginfos);
2177
2178         START_LONG_OPERATION(summaryview, FALSE);
2179         for(walk = msgnum_list; walk; walk = walk->next) {
2180                 GtkCMCTreeNode *node;
2181                 node = summary_find_msg_by_msgnum(summaryview, GPOINTER_TO_UINT(walk->data));
2182                 gtk_cmctree_select(ctree, node);
2183         }
2184         END_LONG_OPERATION(summaryview);
2185         g_slist_free(msgnum_list);
2186 }
2187
2188 typedef struct _PostponedSelectData
2189 {
2190         GtkCMCTree *ctree;
2191         GtkCMCTreeNode *row;
2192         GtkCMCTreeNode *node;
2193         GtkScrollType type;
2194         gint column;
2195         SummaryView *summaryview;
2196         gboolean display_msg;
2197         gboolean do_refresh;
2198 } PostponedSelectData;
2199
2200 static gboolean summary_select_retry(void *data)
2201 {
2202         PostponedSelectData *psdata = (PostponedSelectData *)data;
2203         debug_print("trying again\n");
2204         if (psdata->row)
2205                 summary_selected(psdata->ctree, psdata->row,
2206                             psdata->column, psdata->summaryview);
2207         else if (psdata->node)
2208                 summary_select_node(psdata->summaryview, psdata->node,
2209                             psdata->display_msg, psdata->do_refresh);
2210         else
2211                 summary_step(psdata->summaryview, psdata->type);
2212         g_free(psdata);
2213         return FALSE;
2214 }
2215
2216 /**
2217  * summary_select_node:
2218  * @summaryview: Summary view.
2219  * @node: Summary tree node.
2220  * @display_msg: TRUE to display the selected message.
2221  * @do_refresh: TRUE to refresh the widget.
2222  *
2223  * Select @node (bringing it into view by scrolling and expanding its
2224  * thread, if necessary) and unselect all others.  If @display_msg is
2225  * TRUE, display the corresponding message in the message view.
2226  * If @do_refresh is TRUE, the widget is refreshed.
2227  **/
2228 void summary_select_node(SummaryView *summaryview, GtkCMCTreeNode *node,
2229                          gboolean display_msg, gboolean do_refresh)
2230 {
2231         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2232         
2233         if (summary_is_locked(summaryview)
2234         && !GTK_SCTREE(ctree)->selecting_range
2235         && summaryview->messageview->mimeview
2236         && summaryview->messageview->mimeview->type == MIMEVIEW_TEXT
2237         && summaryview->messageview->mimeview->textview->loading) {
2238                 PostponedSelectData *data = g_new0(PostponedSelectData, 1);
2239                 summaryview->messageview->mimeview->textview->stop_loading = TRUE;
2240                 
2241                 data->ctree = ctree;
2242                 data->row = NULL;
2243                 data->node = node;
2244                 data->summaryview = summaryview;
2245                 data->display_msg = display_msg;
2246                 data->do_refresh = do_refresh;
2247                 debug_print("postponing open of message till end of load\n");
2248                 g_timeout_add(100, summary_select_retry, data);
2249                 return;
2250         }
2251         if (summary_is_locked(summaryview)) {
2252                 return;
2253         }
2254         if (!summaryview->folder_item)
2255                 return;
2256         if (node) {
2257                 if (summaryview->mark_as_read_timeout_tag != 0) {
2258                         g_source_remove(summaryview->mark_as_read_timeout_tag);
2259                         summaryview->mark_as_read_timeout_tag = 0;
2260                 }
2261                 gtkut_ctree_expand_parent_all(ctree, node);
2262                 if (do_refresh) {
2263                         summary_lock(summaryview);
2264                         GTK_EVENTS_FLUSH();
2265                         summary_unlock(summaryview);
2266                         gtk_widget_grab_focus(GTK_WIDGET(ctree));
2267                         gtk_cmctree_node_moveto(ctree, node, 0, 0.5, 0);
2268                 }
2269                 if (display_msg && summaryview->displayed == node)
2270                         summaryview->displayed = NULL;
2271                 summaryview->display_msg = display_msg;
2272                 gtk_sctree_select(GTK_SCTREE(ctree), node);
2273                 if (summaryview->selected == NULL)
2274                         summaryview->selected = node;
2275         }
2276 }
2277
2278 guint summary_get_msgnum(SummaryView *summaryview, GtkCMCTreeNode *node)
2279 {
2280         GtkCMCTree *ctree =NULL;
2281         MsgInfo *msginfo;
2282
2283         if (!summaryview)
2284                 return 0;
2285         ctree = GTK_CMCTREE(summaryview->ctree);
2286         if (!node)
2287                 return 0;
2288         msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2289         if (msginfo)
2290                 return msginfo->msgnum;
2291         else 
2292                 return -1;
2293 }
2294
2295 static GtkCMCTreeNode *summary_find_prev_msg(SummaryView *summaryview,
2296                                            GtkCMCTreeNode *current_node)
2297 {
2298         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2299         GtkCMCTreeNode *node;
2300         MsgInfo *msginfo;
2301
2302         if (current_node)
2303                 node = current_node;
2304         else
2305                 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2306
2307         for (; node != NULL; node = GTK_CMCTREE_NODE_PREV(node)) {
2308                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2309                 if (msginfo && !MSG_IS_DELETED(msginfo->flags)) break;
2310         }
2311
2312         return node;
2313 }
2314
2315 static GtkCMCTreeNode *summary_find_next_msg(SummaryView *summaryview,
2316                                            GtkCMCTreeNode *current_node)
2317 {
2318         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2319         GtkCMCTreeNode *node;
2320         MsgInfo *msginfo;
2321
2322         if (current_node)
2323                 node = current_node;
2324         else
2325                 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2326
2327         for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2328                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2329                 if (msginfo && !MSG_IS_DELETED(msginfo->flags) 
2330                 && !MSG_IS_MOVE(msginfo->flags)) break;
2331         }
2332
2333         return node;
2334 }
2335
2336 static GtkCMCTreeNode *summary_find_prev_flagged_msg(SummaryView *summaryview,
2337                                                    GtkCMCTreeNode *current_node,
2338                                                    MsgPermFlags flags,
2339                                                    gboolean start_from_prev)
2340 {
2341         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2342         GtkCMCTreeNode *node;
2343         MsgInfo *msginfo;
2344
2345         if (current_node) {
2346                 if (start_from_prev)
2347                         node = GTK_CMCTREE_NODE_PREV(current_node);
2348                 else
2349                         node = current_node;
2350         } else
2351                 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2352
2353         for (; node != NULL; node = GTK_CMCTREE_NODE_PREV(node)) {
2354                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2355                 if (msginfo && (msginfo->flags.perm_flags & flags) != 0) break;
2356         }
2357
2358         return node;
2359 }
2360
2361 static GtkCMCTreeNode *summary_find_next_flagged_msg(SummaryView *summaryview,
2362                                                    GtkCMCTreeNode *current_node,
2363                                                    MsgPermFlags flags,
2364                                                    gboolean start_from_next)
2365 {
2366         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2367         GtkCMCTreeNode *node;
2368         MsgInfo *msginfo;
2369
2370         if (current_node) {
2371                 if (start_from_next)
2372                         node = gtkut_ctree_node_next(ctree, current_node);
2373                 else
2374                         node = current_node;
2375         } else
2376                 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2377
2378         for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2379                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2380                 /* Find msg with matching flags but ignore messages with
2381                    ignore flags, if searching for new or unread messages */
2382                 if ((msginfo && (msginfo->flags.perm_flags & flags) != 0) &&
2383                     !(((flags & (MSG_NEW | MSG_UNREAD)) != 0) && MSG_IS_IGNORE_THREAD(msginfo->flags)) 
2384                         )
2385                         break;
2386         }
2387
2388         return node;
2389 }
2390
2391 static GtkCMCTreeNode *summary_find_msg_by_msgnum(SummaryView *summaryview,
2392                                                 guint msgnum)
2393 {
2394         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2395         GtkCMCTreeNode *node;
2396         MsgInfo *msginfo;
2397
2398         node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2399
2400         for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2401                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2402                 if (msginfo && msginfo->msgnum == msgnum) break;
2403         }
2404
2405         return node;
2406 }
2407
2408 static guint attract_hash_func(gconstpointer key)
2409 {
2410         gchar *str;
2411         gchar *p;
2412         guint h;
2413
2414         Xstrdup_a(str, (const gchar *)key, return 0);
2415         trim_subject(str);
2416
2417         p = str;
2418         h = *p;
2419
2420         if (h) {
2421                 for (p += 1; *p != '\0'; p++)
2422                         h = (h << 5) - h + *p;
2423         }
2424
2425         return h;
2426 }
2427
2428 static gint attract_compare_func(gconstpointer a, gconstpointer b)
2429 {
2430         return subject_compare((const gchar *)a, (const gchar *)b) == 0;
2431 }
2432
2433 void summary_attract_by_subject(SummaryView *summaryview)
2434 {
2435         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2436         GtkCMCList *clist = GTK_CMCLIST(ctree);
2437         GtkCMCTreeNode *src_node;
2438         GtkCMCTreeNode *dst_node, *sibling;
2439         GtkCMCTreeNode *tmp;
2440         MsgInfo *src_msginfo, *dst_msginfo;
2441         GHashTable *subject_table;
2442
2443         debug_print("Attracting messages by subject...");
2444         STATUSBAR_PUSH(summaryview->mainwin,
2445                        _("Attracting messages by subject..."));
2446
2447         main_window_cursor_wait(summaryview->mainwin);
2448         summary_freeze(summaryview);
2449
2450         subject_table = g_hash_table_new(attract_hash_func,
2451                                          attract_compare_func);
2452
2453         for (src_node = GTK_CMCTREE_NODE(clist->row_list);
2454              src_node != NULL;
2455              src_node = tmp) {
2456                 tmp = GTK_CMCTREE_ROW(src_node)->sibling;
2457                 src_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(src_node);
2458                 if (!src_msginfo) continue;
2459                 if (!src_msginfo->subject) continue;
2460
2461                 /* find attracting node */
2462                 dst_node = g_hash_table_lookup(subject_table,
2463                                                src_msginfo->subject);
2464
2465                 if (dst_node) {
2466                         dst_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(dst_node);
2467
2468                         /* if the time difference is more than 20 days,
2469                            don't attract */
2470                         if (ABS(src_msginfo->date_t - dst_msginfo->date_t)
2471                             > 60 * 60 * 24 * 20)
2472                                 continue;
2473
2474                         sibling = GTK_CMCTREE_ROW(dst_node)->sibling;
2475                         if (src_node != sibling)
2476                                 gtk_cmctree_move(ctree, src_node, NULL, sibling);
2477                 }
2478
2479                 g_hash_table_insert(subject_table,
2480                                     src_msginfo->subject, src_node);
2481         }
2482
2483         g_hash_table_destroy(subject_table);
2484
2485         gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
2486
2487         summary_thaw(summaryview);
2488
2489         debug_print("done.\n");
2490         STATUSBAR_POP(summaryview->mainwin);
2491
2492         main_window_cursor_normal(summaryview->mainwin);
2493 }
2494
2495 static void summary_free_msginfo_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2496                                       gpointer data)
2497 {
2498         MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2499
2500         if (msginfo)
2501                 procmsg_msginfo_free(msginfo);
2502 }
2503
2504 static void summary_set_marks_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2505                                    gpointer data)
2506 {
2507         SummaryView *summaryview = data;
2508         MsgInfo *msginfo;
2509
2510         msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2511
2512         if (MSG_IS_DELETED(msginfo->flags))
2513                 summaryview->deleted++;
2514
2515         summaryview->total_size += msginfo->size;
2516
2517         summary_set_row_marks(summaryview, node);
2518 }
2519
2520 static void summary_update_status(SummaryView *summaryview)
2521 {
2522         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2523         GtkCMCTreeNode *node;
2524         MsgInfo *msginfo;
2525
2526         summaryview->total_size =
2527         summaryview->deleted = summaryview->moved = summaryview->copied = 0;
2528
2529         for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2530              node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2531                 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
2532                 
2533                 if (!msginfo)
2534                         continue;
2535
2536                 if (MSG_IS_DELETED(msginfo->flags))
2537                         summaryview->deleted++;
2538                 if (MSG_IS_MOVE(msginfo->flags))
2539                         summaryview->moved++;
2540                 if (MSG_IS_COPY(msginfo->flags))
2541                         summaryview->copied++;
2542                 summaryview->total_size += msginfo->size;
2543         }
2544 }
2545
2546 static void summary_status_show(SummaryView *summaryview)
2547 {
2548         gchar *str;
2549         gchar *del, *mv, *cp;
2550         gchar *sel;
2551         gchar *spc;
2552         gchar *itstr;
2553         GList *rowlist, *cur;
2554         guint n_selected = 0, n_new = 0, n_unread = 0, n_total = 0;
2555         guint n_marked = 0, n_replied = 0, n_forwarded = 0, n_locked = 0, n_ignored = 0, n_watched = 0;
2556         goffset sel_size = 0, n_size = 0;
2557         MsgInfo *msginfo;
2558         gchar *name;
2559         gchar *tooltip;
2560         
2561         if (!summaryview->folder_item) {
2562                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), "");
2563                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), "");
2564                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs),   "");
2565                 toolbar_main_set_sensitive(summaryview->mainwin);
2566                 return;
2567         }
2568
2569         rowlist = GTK_CMCLIST(summaryview->ctree)->selection;
2570         for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2571                 msginfo = gtk_cmctree_node_get_row_data
2572                         (GTK_CMCTREE(summaryview->ctree),
2573                          GTK_CMCTREE_NODE(cur->data));
2574                 if (msginfo) {
2575                         sel_size += msginfo->size;
2576                         n_selected++;
2577                 }
2578         }
2579         
2580         if (summaryview->folder_item->hide_read_msgs 
2581         || summaryview->folder_item->hide_del_msgs
2582         || summaryview->folder_item->hide_read_threads
2583         || quicksearch_has_sat_predicate(summaryview->quicksearch)) {
2584                 rowlist = GTK_CMCLIST(summaryview->ctree)->row_list;
2585                 for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2586                         msginfo = gtk_cmctree_node_get_row_data
2587                                 (GTK_CMCTREE(summaryview->ctree),
2588                                  GTK_CMCTREE_NODE(cur));
2589                         if (msginfo) {
2590                                 n_size += msginfo->size;
2591                                 n_total++;
2592                                 if (MSG_IS_NEW(msginfo->flags))
2593                                         n_new++;
2594                                 if (MSG_IS_UNREAD(msginfo->flags))
2595                                         n_unread++;
2596                                 if (MSG_IS_MARKED(msginfo->flags))
2597                                         n_marked++;
2598                                 if (MSG_IS_REPLIED(msginfo->flags))
2599                                         n_replied++;
2600                                 if (MSG_IS_FORWARDED(msginfo->flags))
2601                                         n_forwarded++;
2602                                 if (MSG_IS_LOCKED(msginfo->flags))
2603                                         n_locked++;
2604                                 if (MSG_IS_IGNORE_THREAD(msginfo->flags))
2605                                         n_ignored++;
2606                                 if (MSG_IS_WATCH_THREAD(msginfo->flags))
2607                                         n_watched++;
2608                         }
2609                 }
2610         } else {
2611                 n_new = summaryview->folder_item->new_msgs;
2612                 n_unread = summaryview->folder_item->unread_msgs;
2613                 n_marked = summaryview->folder_item->marked_msgs;
2614                 n_replied = summaryview->folder_item->replied_msgs;
2615                 n_forwarded = summaryview->folder_item->forwarded_msgs;
2616                 n_locked = summaryview->folder_item->locked_msgs;
2617                 n_ignored = summaryview->folder_item->ignored_msgs;
2618                 n_watched = summaryview->folder_item->watched_msgs;
2619                 n_total = summaryview->folder_item->total_msgs;
2620                 n_size = summaryview->total_size;
2621         }
2622
2623         name = folder_item_get_name(summaryview->folder_item);
2624         gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), name);
2625         g_free(name);
2626
2627         if (summaryview->deleted)
2628                 del = g_strdup_printf(_("%d deleted"), summaryview->deleted);
2629         else
2630                 del = g_strdup("");
2631         if (summaryview->moved)
2632                 mv = g_strdup_printf(_("%s%d moved"),
2633                                      summaryview->deleted ? _(", ") : "",
2634                                      summaryview->moved);
2635         else
2636                 mv = g_strdup("");
2637         if (summaryview->copied)
2638                 cp = g_strdup_printf(_("%s%d copied"),
2639                                      summaryview->deleted ||
2640                                      summaryview->moved ? _(", ") : "",
2641                                      summaryview->copied);
2642         else
2643                 cp = g_strdup("");
2644
2645         if (summaryview->deleted || summaryview->moved || summaryview->copied)
2646                 spc = "    ";
2647         else
2648                 spc = "";
2649
2650         if (n_selected) {
2651                 sel = g_strdup_printf(" (%s)", to_human_readable((goffset)sel_size));
2652                 itstr = g_strdup_printf(ngettext(" item selected"," items selected", n_selected));
2653         } else {
2654                 sel = g_strdup("");
2655                 itstr = g_strdup("");
2656         }
2657                 
2658         if (prefs_common.layout_mode != SMALL_LAYOUT) {
2659                 str = g_strconcat(n_selected ? itos(n_selected) : "",
2660                                                 itstr, sel, spc, del, mv, cp, NULL);
2661                 g_free(sel);
2662                 g_free(del);
2663                 g_free(mv);
2664                 g_free(cp);
2665                 g_free(itstr);
2666                 
2667                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2668                 g_free(str);
2669
2670                 str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2671                                               n_new, n_unread, n_total,
2672                                               to_human_readable((goffset)n_size));
2673
2674
2675                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs), str);
2676                 g_free(str);
2677                 tooltip = g_strdup_printf(_("<b>Message summary</b>\n"
2678                                             "<b>New:</b> %d\n"
2679                                             "<b>Unread:</b> %d\n"
2680                                             "<b>Total:</b> %d\n"
2681                                             "<b>Size:</b> %s\n\n"
2682                                             "<b>Marked:</b> %d\n"
2683                                             "<b>Replied:</b> %d\n"
2684                                             "<b>Forwarded:</b> %d\n"
2685                                             "<b>Locked:</b> %d\n"
2686                                             "<b>Ignored:</b> %d\n"
2687                                             "<b>Watched:</b> %d"),
2688                                               n_new, n_unread, n_total,
2689                                               to_human_readable((goffset)n_size),
2690                                               n_marked,n_replied,n_forwarded,
2691                                               n_locked,n_ignored,n_watched);
2692
2693                 gtk_widget_set_tooltip_markup(GTK_WIDGET(summaryview->statlabel_msgs),
2694                                             tooltip); 
2695                 g_free(tooltip);
2696         } else {
2697                 gchar *ssize, *tsize;
2698                 if (n_selected) {
2699                         ssize = g_strdup(to_human_readable((goffset)sel_size));
2700                         tsize = g_strdup(to_human_readable((goffset)n_size));
2701                         str = g_strdup_printf(_("%d/%d selected (%s/%s), %d unread"),
2702                                 n_selected, n_total, ssize, tsize, n_unread);
2703                         g_free(ssize);
2704                         g_free(tsize);
2705                 } else
2706                         str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2707                                 n_new, n_unread, n_total, to_human_readable((goffset)n_size));
2708                 g_free(sel);
2709                 g_free(del);
2710                 g_free(mv);
2711                 g_free(cp);
2712                 g_free(itstr);
2713                 
2714                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2715                 g_free(str);
2716         }
2717
2718         summary_set_menu_sensitive(summaryview);
2719         toolbar_main_set_sensitive(summaryview->mainwin);
2720 }
2721
2722 static void summary_set_column_titles(SummaryView *summaryview)
2723 {
2724         GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
2725         FolderItem *item = summaryview->folder_item;
2726         GtkWidget *hbox;
2727         GtkWidget *label;
2728         GtkWidget *arrow;
2729         gint pos;
2730         const gchar *title;
2731         SummaryColumnType type;
2732         GtkJustification justify;
2733
2734         static FolderSortKey sort_by[N_SUMMARY_COLS] = {
2735                 SORT_BY_MARK,
2736                 SORT_BY_STATUS,
2737                 SORT_BY_MIME,
2738                 SORT_BY_SUBJECT,
2739                 SORT_BY_FROM,
2740                 SORT_BY_TO,
2741                 SORT_BY_DATE,
2742                 SORT_BY_SIZE,
2743                 SORT_BY_NUMBER,
2744                 SORT_BY_SCORE,
2745                 SORT_BY_LOCKED,
2746                 SORT_BY_TAGS
2747         };
2748
2749         for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
2750                 type = summaryview->col_state[pos].type;
2751
2752                 /* CLAWS: mime and unread are single char headers */
2753                 justify = (type == S_COL_NUMBER || type == S_COL_SIZE)
2754                         ? GTK_JUSTIFY_RIGHT : GTK_JUSTIFY_LEFT;
2755
2756                 switch (type) {
2757                 case S_COL_SUBJECT:
2758                 case S_COL_FROM:
2759                 case S_COL_TO:
2760                 case S_COL_DATE:
2761                 case S_COL_NUMBER:
2762                         if(type == S_COL_FROM && item != NULL &&
2763                                         FOLDER_SHOWS_TO_HDR(item) &&
2764                                         !summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
2765                                 type = S_COL_TO;
2766                         if(type == S_COL_NUMBER)
2767                                 title = gettext(col_label[type]);
2768                         else
2769                                 title = prefs_common_translated_header_name(col_label[type]);
2770                         break;
2771                 default:
2772                         title = gettext(col_label[type]);
2773                 }
2774
2775                 if (type == S_COL_MIME) {
2776                         label = gtk_image_new_from_pixbuf(clipxpm);
2777                         gtk_widget_show(label);
2778                         gtk_cmclist_set_column_widget(clist, pos, label);
2779                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Attachment"));
2780                         continue;
2781                 } else if (type == S_COL_MARK) {
2782                         label = gtk_image_new_from_pixbuf(markxpm);
2783                         gtk_widget_show(label);
2784                         gtk_cmclist_set_column_widget(clist, pos, label);
2785                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Mark"));
2786                         continue;
2787                 } else if (type == S_COL_LOCKED) {
2788                         label = gtk_image_new_from_pixbuf(lockedxpm);
2789                         gtk_widget_show(label);
2790                         gtk_cmclist_set_column_widget(clist, pos, label);
2791                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Locked"));
2792                         continue;
2793                 } else if (type == S_COL_STATUS) {
2794                         gtk_cmclist_set_column_title(clist, pos, title);
2795                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Status"));
2796                         continue;
2797                 }
2798
2799                 hbox  = gtk_hbox_new(FALSE, 4);
2800                 label = gtk_label_new(title);
2801 #ifdef GENERIC_UMPC
2802         gtk_widget_set_size_request(hbox, -1, 20);
2803 #endif
2804
2805                 if (justify == GTK_JUSTIFY_RIGHT)
2806                         gtk_box_pack_end(GTK_BOX(hbox), label,
2807                                          FALSE, FALSE, 0);
2808                 else
2809                         gtk_box_pack_start(GTK_BOX(hbox), label,
2810                                            FALSE, FALSE, 0);
2811
2812                 if (summaryview->sort_key == sort_by[type]) {
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                         _("(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                                 extract_address(from_text);
3368                         }
3369                         if (!from_text)
3370                                 _("(No From)");         
3371                 }
3372         }
3373         
3374         to_text = msginfo->to ? msginfo->to : 
3375                    (msginfo->cc ? msginfo->cc :
3376                      (msginfo->newsgroups ? msginfo->newsgroups : _("(No Recipient)")
3377                      )
3378                    );
3379
3380         text[col_pos[S_COL_TO]] = to_text;
3381         if (!should_swap) {
3382                 text[col_pos[S_COL_FROM]] = from_text;
3383         } else {
3384                 if (prefs_common.use_addr_book) {
3385                         gchar *tmp = summary_complete_address(to_text);
3386                         if (tmp) {
3387                                 strncpy2(buf, tmp, sizeof(buf));
3388                                 g_free(tmp);
3389                                 to_text = buf;
3390                         } else {
3391                                 to_text = to_text ? to_text : _("(No From)");
3392                         }
3393                 }
3394                 snprintf(tmp2, BUFFSIZE-1, "--> %s", to_text);
3395                 tmp2[BUFFSIZE-1]='\0';
3396                 text[col_pos[S_COL_FROM]] = tmp2;
3397         }
3398         
3399 #ifndef G_OS_WIN32
3400         if (summaryview->simplify_subject_preg != NULL)
3401                 text[col_pos[S_COL_SUBJECT]] = msginfo->subject ? 
3402                         string_remove_match(tmp3, BUFFSIZE, msginfo->subject, 
3403                                         summaryview->simplify_subject_preg) : 
3404                         _("(No Subject)");
3405         else 
3406 #endif
3407                 text[col_pos[S_COL_SUBJECT]] = msginfo->subject ? msginfo->subject :
3408                         _("(No Subject)");
3409         if ((vert_layout || small_layout) && prefs_common.two_line_vert) {
3410                 if (!FOLDER_SHOWS_TO_HDR(summaryview->folder_item)) {
3411                         gchar *tmp = g_markup_printf_escaped(_("%s\n<span color='%s' style='italic'>From: %s, on %s</span>"),
3412                                         text[col_pos[S_COL_SUBJECT]],
3413                                         color_dim_rgb,
3414                                         text[col_pos[S_COL_FROM]],
3415                                         text[col_pos[S_COL_DATE]]);
3416                         text[col_pos[S_COL_SUBJECT]] = tmp;
3417                 } else {
3418                         gchar *tmp = g_markup_printf_escaped(_("%s\n<span color='%s' style='italic'>To: %s, on %s</span>"),
3419                                         text[col_pos[S_COL_SUBJECT]],
3420                                         color_dim_rgb,
3421                                         text[col_pos[S_COL_TO]],
3422                                         text[col_pos[S_COL_DATE]]);
3423                         text[col_pos[S_COL_SUBJECT]] = tmp;
3424                 }
3425         }
3426 }
3427
3428 static void summary_display_msg(SummaryView *summaryview, GtkCMCTreeNode *row)
3429 {
3430         summary_display_msg_full(summaryview, row, FALSE, FALSE);
3431 }
3432
3433 static gboolean defer_change(gpointer data);
3434 typedef struct _ChangeData {
3435         MsgInfo *info;
3436         gint op; /* 0, 1, 2 for unset, set, change */
3437         MsgPermFlags set_flags;
3438         MsgTmpFlags  set_tmp_flags;
3439         MsgPermFlags unset_flags;
3440         MsgTmpFlags  unset_tmp_flags;
3441 } ChangeData;
3442
3443 static void summary_msginfo_unset_flags(MsgInfo *msginfo, MsgPermFlags flags, MsgTmpFlags tmp_flags)
3444 {
3445         if (!msginfo->folder || !msginfo->folder->processing_pending) {
3446                 debug_print("flags: doing unset now\n");
3447                 procmsg_msginfo_unset_flags(msginfo, flags, tmp_flags);
3448         } else {
3449                 ChangeData *unset_data = g_new0(ChangeData, 1);
3450                 unset_data->info = msginfo;
3451                 unset_data->op = 0;
3452                 unset_data->unset_flags = flags;
3453                 unset_data->unset_tmp_flags = tmp_flags;
3454                 debug_print("flags: deferring unset\n");
3455                 g_timeout_add(100, defer_change, unset_data);
3456         }
3457 }
3458
3459 static void summary_msginfo_set_flags(MsgInfo *msginfo, MsgPermFlags flags, MsgTmpFlags tmp_flags)
3460 {
3461         if (!msginfo->folder || !msginfo->folder->processing_pending) {
3462                 debug_print("flags: doing set now\n");
3463                 procmsg_msginfo_set_flags(msginfo, flags, tmp_flags);
3464         } else {
3465                 ChangeData *set_data = g_new0(ChangeData, 1);
3466                 set_data->info = msginfo;
3467                 set_data->op = 1;
3468                 set_data->set_flags = flags;
3469                 set_data->set_tmp_flags = tmp_flags;
3470                 debug_print("flags: deferring set\n");
3471                 g_timeout_add(100, defer_change, set_data);
3472         }
3473 }
3474
3475 static void summary_msginfo_change_flags(MsgInfo *msginfo, 
3476                 MsgPermFlags add_flags, MsgTmpFlags add_tmp_flags,
3477                 MsgPermFlags rem_flags, MsgTmpFlags rem_tmp_flags)
3478 {
3479         if (!msginfo->folder || !msginfo->folder->processing_pending) {
3480                 debug_print("flags: doing change now\n");
3481                 procmsg_msginfo_change_flags(msginfo, add_flags, add_tmp_flags,
3482                         rem_flags, rem_tmp_flags);
3483         } else {
3484                 ChangeData *change_data = g_new0(ChangeData, 1);
3485                 change_data->info = msginfo;
3486                 change_data->op = 2;
3487                 change_data->set_flags = add_flags;
3488                 change_data->set_tmp_flags = add_tmp_flags;
3489                 change_data->unset_flags = rem_flags;
3490                 change_data->unset_tmp_flags = rem_tmp_flags;
3491                 debug_print("flags: deferring change\n");
3492                 g_timeout_add(100, defer_change, change_data);
3493         }
3494 }
3495
3496 gboolean defer_change(gpointer data)
3497 {
3498         ChangeData *chg = (ChangeData *)data;
3499         if (chg->info->folder && chg->info->folder->processing_pending) {
3500                 debug_print("flags: trying later\n");
3501                 return TRUE; /* try again */
3502         } else {
3503                 debug_print("flags: finally doing it\n");
3504                 switch(chg->op) {
3505                 case 0:
3506                         procmsg_msginfo_unset_flags(chg->info, chg->unset_flags, chg->unset_tmp_flags);
3507                         break;
3508                 case 1:
3509                         procmsg_msginfo_set_flags(chg->info, chg->set_flags, chg->set_tmp_flags);
3510                         break;
3511                 case 2:
3512                         procmsg_msginfo_change_flags(chg->info, chg->set_flags, chg->set_tmp_flags,
3513                                 chg->unset_flags, chg->unset_tmp_flags);
3514                         break;
3515                 default:
3516                         g_warning("shouldn't happen\n");
3517                 }
3518                 g_free(chg);
3519         }
3520         return FALSE;
3521 }
3522
3523 static void msginfo_mark_as_read (SummaryView *summaryview, MsgInfo *msginfo,
3524                                       GtkCMCTreeNode *row)
3525 {
3526         cm_return_if_fail(summaryview != NULL);
3527         cm_return_if_fail(msginfo != NULL);
3528         cm_return_if_fail(row != NULL);
3529
3530         if (MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)) {
3531                 summary_msginfo_unset_flags
3532                         (msginfo, MSG_NEW | MSG_UNREAD, 0);
3533                 summary_set_row_marks(summaryview, row);
3534                 summary_status_show(summaryview);
3535         }
3536 }
3537
3538 typedef struct  {
3539         MsgInfo *msginfo;
3540         SummaryView *summaryview;
3541 } MarkAsReadData;
3542
3543 static int msginfo_mark_as_read_timeout(void *data)
3544 {
3545         MarkAsReadData *mdata = (MarkAsReadData *)data;
3546         if (!mdata)
3547                 return FALSE;
3548
3549         if (mdata->msginfo == summary_get_selected_msg(mdata->summaryview))
3550                 msginfo_mark_as_read(mdata->summaryview, mdata->msginfo,
3551                                      mdata->summaryview->selected);
3552         procmsg_msginfo_free(mdata->msginfo);
3553
3554         mdata->summaryview->mark_as_read_timeout_tag = 0;
3555
3556         g_free(mdata);
3557         return FALSE;
3558 }
3559
3560 static void summary_display_msg_full(SummaryView *summaryview,
3561                                      GtkCMCTreeNode *row,
3562                                      gboolean new_window, gboolean all_headers)
3563 {
3564         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3565         MsgInfo *msginfo;
3566         gint val;
3567         START_TIMING("");
3568         if (!new_window) {
3569                 if (summaryview->displayed == row &&
3570                     messageview_is_visible(summaryview->messageview))
3571                         return;
3572                 else if (summaryview->messageview)
3573                         summaryview->messageview->filtered = FALSE;
3574         }                       
3575         cm_return_if_fail(row != NULL);
3576
3577         if (summary_is_locked(summaryview)) return;
3578         summary_lock(summaryview);
3579
3580         STATUSBAR_POP(summaryview->mainwin);
3581         GTK_EVENTS_FLUSH();
3582
3583         msginfo = gtk_cmctree_node_get_row_data(ctree, row);
3584
3585         if (!msginfo) {
3586                 debug_print("NULL msginfo\n");
3587                 summary_unlock(summaryview);
3588                 END_TIMING();
3589                 return;
3590         }       
3591
3592         if (new_window && prefs_common.layout_mode != SMALL_LAYOUT) {
3593                 MessageView *msgview;
3594
3595                 msgview = messageview_create_with_new_window(summaryview->mainwin);
3596                 val = messageview_show(msgview, msginfo, all_headers);
3597         } else {
3598                 MessageView *msgview;
3599
3600                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
3601                         if (summaryview->ext_messageview == NULL)
3602                                 summaryview->ext_messageview = messageview_create_with_new_window(summaryview->mainwin);
3603                         else
3604                                 gtkut_window_popup(summaryview->ext_messageview->window);
3605                         msgview = summaryview->ext_messageview;
3606                         summaryview->displayed = row;
3607                         val = messageview_show(msgview, msginfo, all_headers);
3608                         if (mimeview_tree_is_empty(msgview->mimeview))
3609                                 gtk_widget_grab_focus(summaryview->ctree);
3610                         gtkut_ctree_node_move_if_on_the_edge(ctree, row,
3611                                 GTK_CMCLIST(summaryview->ctree)->focus_row);
3612                 } else {
3613                         msgview = summaryview->messageview;
3614                         summaryview->displayed = row;
3615                         if (!messageview_is_visible(msgview) &&
3616                             gtk_window_is_active(GTK_WINDOW(summaryview->mainwin->window))) {
3617                                 main_window_toggle_message_view(summaryview->mainwin);
3618                                 GTK_EVENTS_FLUSH();
3619                         }
3620                         val = messageview_show(msgview, msginfo, all_headers);
3621                         if (mimeview_tree_is_empty(msgview->mimeview))
3622                                 gtk_widget_grab_focus(summaryview->ctree);
3623                         gtkut_ctree_node_move_if_on_the_edge(ctree, row,
3624                                 GTK_CMCLIST(summaryview->ctree)->focus_row);
3625                 }
3626         }
3627
3628         if (val == 0 && MSG_IS_UNREAD(msginfo->flags)) {
3629                 if (!prefs_common.mark_as_read_on_new_window &&
3630                     prefs_common.mark_as_read_delay) {
3631                         MarkAsReadData *data = g_new0(MarkAsReadData, 1);
3632                         data->summaryview = summaryview;
3633                         data->msginfo = procmsg_msginfo_new_ref(msginfo);
3634                         if (summaryview->mark_as_read_timeout_tag != 0)
3635                                 g_source_remove(summaryview->mark_as_read_timeout_tag);
3636
3637 #if GLIB_CHECK_VERSION(2,14,0)
3638                         summaryview->mark_as_read_timeout_tag = 
3639                                 g_timeout_add_seconds(prefs_common.mark_as_read_delay,
3640                                         msginfo_mark_as_read_timeout, data);
3641 #else
3642                         summaryview->mark_as_read_timeout_tag = 
3643                                 g_timeout_add(prefs_common.mark_as_read_delay * 1000,
3644                                         msginfo_mark_as_read_timeout, data);
3645 #endif
3646                 } else if (new_window || !prefs_common.mark_as_read_on_new_window) {
3647                         msginfo_mark_as_read(summaryview, msginfo, row);
3648                 }
3649         }
3650
3651         summary_set_menu_sensitive(summaryview);
3652         toolbar_main_set_sensitive(summaryview->mainwin);
3653         messageview_set_menu_sensitive(summaryview->messageview);
3654
3655         summary_unlock(summaryview);
3656         END_TIMING();
3657 }
3658
3659 void summary_display_msg_selected(SummaryView *summaryview,
3660                                   gboolean all_headers)
3661 {
3662         if (summary_is_locked(summaryview)) return;
3663         summaryview->displayed = NULL;
3664         summary_display_msg_full(summaryview, summaryview->selected, FALSE,
3665                                  all_headers);
3666 }
3667
3668 void summary_redisplay_msg(SummaryView *summaryview)
3669 {
3670         GtkCMCTreeNode *node;
3671
3672         if (summaryview->displayed) {
3673                 node = summaryview->displayed;
3674                 summaryview->displayed = NULL;
3675                 summary_display_msg(summaryview, node);
3676         }
3677 }
3678
3679 void summary_open_msg(SummaryView *summaryview)
3680 {
3681         if (!summaryview->selected) return;
3682         
3683         /* CLAWS: if separate message view, don't open a new window
3684          * but rather use the current separated message view */
3685         summary_display_msg_full(summaryview, summaryview->selected, 
3686                                  TRUE, FALSE);
3687 }
3688
3689 void summary_view_source(SummaryView * summaryview)
3690 {
3691         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3692         MsgInfo *msginfo;
3693         SourceWindow *srcwin;
3694
3695         if (!summaryview->selected) return;
3696
3697         srcwin = source_window_create();
3698         msginfo = gtk_cmctree_node_get_row_data(ctree, summaryview->selected);
3699         source_window_show_msg(srcwin, msginfo);
3700         source_window_show(srcwin);
3701 }
3702
3703 void summary_reedit(SummaryView *summaryview)
3704 {
3705         MsgInfo *msginfo;
3706
3707         if (!summaryview->selected) return;
3708         if (!summaryview->folder_item) return;
3709         if (!FOLDER_SHOWS_TO_HDR(summaryview->folder_item))
3710                 return;
3711
3712         msginfo = gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
3713                                               summaryview->selected);
3714         if (!msginfo) return;
3715
3716         compose_reedit(msginfo, FALSE);
3717 }
3718
3719 gboolean summary_step(SummaryView *summaryview, GtkScrollType type)
3720 {
3721         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3722         GtkCMCTreeNode *node;
3723
3724         if (summary_is_locked(summaryview)
3725         && !GTK_SCTREE(ctree)->selecting_range
3726         && summaryview->messageview->mimeview
3727         && summaryview->messageview->mimeview->type&nbs