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