2010-09-19 [colin] 3.7.6cvs39
[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         gboolean sensitive;
1624         gint i;
1625
1626         static const struct {
1627                 gchar *const entry;
1628                 SensitiveCond cond;
1629         } entry[] = {
1630                 {"Menus/SummaryViewPopup/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1631 #ifndef GENERIC_UMPC
1632                 {"Menus/SummaryViewPopup/ReplyTo"                       , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1633                 {"Menus/SummaryViewPopup/ReplyTo/All"           , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1634                 {"Menus/SummaryViewPopup/ReplyTo/Sender"             , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1635                 {"Menus/SummaryViewPopup/ReplyTo/MailingList"       , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1636 #endif
1637
1638                 {"Menus/SummaryViewPopup/Forward"                       , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1639 #ifndef GENERIC_UMPC
1640                 {"Menus/SummaryViewPopup/ForwardAtt"    , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1641                 {"Menus/SummaryViewPopup/Redirect"                      , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1642 #endif
1643
1644                 {"Menus/SummaryViewPopup/Move"                  , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
1645                 {"Menus/SummaryViewPopup/Copy"                  , M_TARGET_EXIST|M_EXEC},
1646                 {"Menus/SummaryViewPopup/Trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
1647 #ifndef GENERIC_UMPC
1648                 {"Menus/SummaryViewPopup/Delete"                        , M_TARGET_EXIST|M_ALLOW_DELETE},
1649 #endif
1650
1651                 {"Menus/SummaryViewPopup/Mark"                  , M_TARGET_EXIST},
1652                 {"Menus/SummaryViewPopup/Mark/Mark"             , M_TARGET_EXIST},
1653                 {"Menus/SummaryViewPopup/Mark/Unmark"                   , M_TARGET_EXIST},
1654                 {"Menus/SummaryViewPopup/Mark/MarkUnread"       , M_TARGET_EXIST},
1655                 {"Menus/SummaryViewPopup/Mark/MarkRead"         , M_TARGET_EXIST},
1656                 {"Menus/SummaryViewPopup/Mark/MarkAllRead"      , M_TARGET_EXIST},
1657                 {"Menus/SummaryViewPopup/Mark/IgnoreThread"     , M_TARGET_EXIST},
1658                 {"Menus/SummaryViewPopup/Mark/UnignoreThread"           , M_TARGET_EXIST},
1659                 {"Menus/SummaryViewPopup/Mark/WatchThread"              , M_TARGET_EXIST},
1660                 {"Menus/SummaryViewPopup/Mark/UnwatchThread"    , M_TARGET_EXIST},
1661                 {"Menus/SummaryViewPopup/Mark/Unlock"                   , M_TARGET_EXIST},
1662                 {"Menus/SummaryViewPopup/Mark/Lock"             , M_TARGET_EXIST},
1663                 {"Menus/SummaryViewPopup/Mark/MarkSpam"         , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
1664                 {"Menus/SummaryViewPopup/Mark/MarkHam"          , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
1665                 {"Menus/SummaryViewPopup/ColorLabel"                    , M_TARGET_EXIST},
1666                 {"Menus/SummaryViewPopup/Tags"                  , M_TARGET_EXIST},
1667
1668 #ifndef GENERIC_UMPC
1669                 {"Menus/SummaryViewPopup/AddSenderToAB" , M_SINGLE_TARGET_EXIST},
1670 #endif
1671                 {"Menus/SummaryViewPopup/CreateFilterRule"              , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1672 #ifndef GENERIC_UMPC
1673                 {"Menus/SummaryViewPopup/CreateProcessingRule"  , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1674 #endif
1675
1676                 {"Menus/SummaryViewPopup/View"                  , M_SINGLE_TARGET_EXIST},
1677                 {"Menus/SummaryViewPopup/View/OpenNewWindow"     , M_SINGLE_TARGET_EXIST},
1678                 {"Menus/SummaryViewPopup/View/MessageSource"            , M_SINGLE_TARGET_EXIST},
1679 #ifndef GENERIC_UMPC
1680                 {"Menus/SummaryViewPopup/View/AllHeaders"               , M_SINGLE_TARGET_EXIST},
1681 #endif
1682                 {"Menus/SummaryViewPopup/SaveAs"                        , M_TARGET_EXIST},
1683 #ifndef GENERIC_UMPC
1684                 {"Menus/SummaryViewPopup/Print"                 , M_TARGET_EXIST},
1685 #endif
1686                 {NULL, 0}
1687         };
1688
1689         main_window_set_menu_sensitive(summaryview->mainwin);
1690
1691         state = main_window_get_current_state(summaryview->mainwin);
1692
1693         for (i = 0; entry[i].entry != NULL; i++) {
1694                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1695                 cm_menu_set_sensitive_full(summaryview->mainwin->ui_manager, entry[i].entry, sensitive);
1696         }
1697
1698         summary_lock(summaryview);
1699 #ifndef GENERIC_UMPC
1700         if (summaryview->messageview 
1701         &&  summaryview->messageview->mimeview
1702         &&  summaryview->messageview->mimeview->textview)
1703                 cm_toggle_menu_set_active_full(summaryview->mainwin->ui_manager, "Menus/SummaryViewPopup/View/AllHeaders",
1704                         summaryview->messageview->mimeview->textview->show_all_headers);
1705 #endif
1706         summary_unlock(summaryview);
1707 }
1708
1709 void summary_select_prev_unread(SummaryView *summaryview)
1710 {
1711         GtkCMCTreeNode *node;
1712         gboolean skip_cur = FALSE;
1713
1714         if (summaryview->displayed 
1715         &&  summaryview->selected == summaryview->displayed) {
1716                 debug_print("skipping current\n");
1717                 skip_cur = TRUE;
1718         }
1719
1720         node = summary_find_prev_flagged_msg
1721                 (summaryview, summaryview->selected, MSG_UNREAD, skip_cur);
1722
1723         if (!node || node == summaryview->selected) {
1724                 AlertValue val = 0;
1725
1726                 switch (prefs_common.next_unread_msg_dialog) {
1727                         case NEXTUNREADMSGDIALOG_ALWAYS:
1728                                 val = alertpanel(_("No more unread messages"),
1729                                                  _("No unread message found. "
1730                                                    "Search from the end?"),
1731                                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1732                                 break;
1733                         case NEXTUNREADMSGDIALOG_ASSUME_YES:
1734                                 val = G_ALERTALTERNATE;
1735                                 break;
1736                         case NEXTUNREADMSGDIALOG_ASSUME_NO:
1737                                 val = !G_ALERTALTERNATE;
1738                                 break;
1739                         default:
1740                                 debug_print(
1741                                         _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1742                 }
1743                 if (val != G_ALERTALTERNATE) return;
1744                 node = summary_find_prev_flagged_msg(summaryview, NULL,
1745                                                      MSG_UNREAD, FALSE);
1746         }
1747
1748         if (!node)
1749                 alertpanel_notice(_("No unread messages."));
1750         else
1751                 summary_select_node(summaryview, node, TRUE, FALSE);
1752 }
1753
1754 void summary_select_next_unread(SummaryView *summaryview)
1755 {
1756         GtkCMCTreeNode *node = summaryview->selected;
1757         gboolean skip_cur = FALSE;
1758         
1759         if (summaryview->displayed 
1760         &&  summaryview->selected == summaryview->displayed) {
1761                 debug_print("skipping cur (%p %p)\n",
1762                         summaryview->displayed, summaryview->selected);
1763                 skip_cur = TRUE;
1764         }
1765
1766
1767         node = summary_find_next_flagged_msg
1768                 (summaryview, node, MSG_UNREAD, skip_cur);
1769         
1770         if (node)
1771                 summary_select_node(summaryview, node, TRUE, FALSE);
1772         else {
1773                 node = summary_find_next_flagged_msg
1774                         (summaryview, NULL, MSG_UNREAD, FALSE);
1775                 if (node == NULL || node == summaryview->selected) {
1776                         AlertValue val = 0;
1777
1778                         switch (prefs_common.next_unread_msg_dialog) {
1779                                 case NEXTUNREADMSGDIALOG_ALWAYS:
1780                                         val = alertpanel(_("No more unread messages"),
1781                                                          _("No unread message found. "
1782                                                            "Go to next folder?"),
1783                                                          GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1784                                         break;
1785                                 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1786                                         val = G_ALERTALTERNATE;
1787                                         break;
1788                                 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1789                                         val = G_ALERTOTHER;
1790                                         break;
1791                                 default:
1792                                         debug_print(
1793                                                 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1794                         }
1795
1796                         if (val == G_ALERTALTERNATE) {
1797                                 folderview_select_next_unread(summaryview->folderview, TRUE);
1798                                 return;
1799                         } 
1800                         else
1801                                 return;
1802                 } else
1803                         summary_select_node(summaryview, node, TRUE, FALSE);
1804
1805         }
1806 }
1807
1808 void summary_select_prev_new(SummaryView *summaryview)
1809 {
1810         GtkCMCTreeNode *node;
1811         gboolean skip_cur = FALSE;
1812
1813         if (summaryview->displayed 
1814         &&  summaryview->selected == summaryview->displayed) {
1815                 debug_print("skipping current\n");
1816                 skip_cur = TRUE;
1817         }
1818
1819         node = summary_find_prev_flagged_msg
1820                 (summaryview, summaryview->selected, MSG_NEW, skip_cur);
1821
1822         if (!node || node == summaryview->selected) {
1823                 AlertValue val = 0;
1824
1825                 switch (prefs_common.next_unread_msg_dialog) {
1826                         case NEXTUNREADMSGDIALOG_ALWAYS:
1827                                 val = alertpanel(_("No more new messages"),
1828                                                  _("No new message found. "
1829                                                    "Search from the end?"),
1830                                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1831                                 break;
1832                         case NEXTUNREADMSGDIALOG_ASSUME_YES:
1833                                 val = G_ALERTALTERNATE;
1834                                 break;
1835                         case NEXTUNREADMSGDIALOG_ASSUME_NO:
1836                                 val = !G_ALERTALTERNATE;
1837                                 break;
1838                         default:
1839                                 debug_print(
1840                                         _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1841                 }
1842                 if (val != G_ALERTALTERNATE) return;
1843                 node = summary_find_prev_flagged_msg(summaryview, NULL,
1844                                                      MSG_NEW, FALSE);
1845         }
1846
1847         if (!node)
1848                 alertpanel_notice(_("No new messages."));
1849         else
1850                 summary_select_node(summaryview, node, TRUE, FALSE);
1851 }
1852
1853 void summary_select_next_new(SummaryView *summaryview)
1854 {
1855         GtkCMCTreeNode *node = summaryview->selected;
1856         gboolean skip_cur = FALSE;
1857         
1858         if (summaryview->displayed 
1859         &&  summaryview->selected == summaryview->displayed) {
1860                 debug_print("skipping cur (%p %p)\n",
1861                         summaryview->displayed, summaryview->selected);
1862                 skip_cur = TRUE;
1863         }
1864
1865
1866         node = summary_find_next_flagged_msg
1867                 (summaryview, node, MSG_NEW, skip_cur);
1868         
1869         if (node)
1870                 summary_select_node(summaryview, node, TRUE, FALSE);
1871         else {
1872                 node = summary_find_next_flagged_msg
1873                         (summaryview, NULL, MSG_NEW, FALSE);
1874                 if (node == NULL || node == summaryview->selected) {
1875                         AlertValue val = 0;
1876
1877                         switch (prefs_common.next_unread_msg_dialog) {
1878                                 case NEXTUNREADMSGDIALOG_ALWAYS:
1879                                         val = alertpanel(_("No more new messages"),
1880                                                          _("No new message found. "
1881                                                            "Go to next folder?"),
1882                                                          GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1883                                         break;
1884                                 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1885                                         val = G_ALERTALTERNATE;
1886                                         break;
1887                                 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1888                                         val = G_ALERTOTHER;
1889                                         break;
1890                                 default:
1891                                         debug_print(
1892                                                 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1893                         }
1894
1895                         if (val == G_ALERTALTERNATE) {
1896                                 folderview_select_next_new(summaryview->folderview);
1897                                 return;
1898                         } 
1899                         else
1900                                 return;
1901                 } else
1902                         summary_select_node(summaryview, node, TRUE, FALSE);
1903
1904         }
1905 }
1906
1907 void summary_select_prev_marked(SummaryView *summaryview)
1908 {
1909         GtkCMCTreeNode *node;
1910
1911         node = summary_find_prev_flagged_msg
1912                 (summaryview, summaryview->selected, MSG_MARKED, TRUE);
1913
1914         if (!node) {
1915                 AlertValue val;
1916
1917                 val = alertpanel(_("No more marked messages"),
1918                                  _("No marked message found. "
1919                                    "Search from the end?"),
1920                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1921                 if (val != G_ALERTALTERNATE) return;
1922                 node = summary_find_prev_flagged_msg(summaryview, NULL,
1923                                                      MSG_MARKED, TRUE);
1924         }
1925
1926         if (!node)
1927                 alertpanel_notice(_("No marked messages."));
1928         else
1929                 summary_select_node(summaryview, node, TRUE, FALSE);
1930 }
1931
1932 void summary_select_next_marked(SummaryView *summaryview)
1933 {
1934         GtkCMCTreeNode *node = summaryview->selected;
1935         gboolean skip_cur = FALSE;
1936         
1937         if (summaryview->displayed 
1938         &&  summaryview->selected == summaryview->displayed) {
1939                 debug_print("skipping cur (%p %p)\n",
1940                         summaryview->displayed, summaryview->selected);
1941                 skip_cur = TRUE;
1942         }
1943
1944
1945         node = summary_find_next_flagged_msg
1946                 (summaryview, node, MSG_MARKED, skip_cur);
1947         
1948         if (node)
1949                 summary_select_node(summaryview, node, TRUE, FALSE);
1950         else {
1951                 node = summary_find_next_flagged_msg
1952                         (summaryview, NULL, MSG_MARKED, FALSE);
1953                 if (node == NULL || node == summaryview->selected) {
1954                         AlertValue val = 0;
1955
1956                         switch (prefs_common.next_unread_msg_dialog) {
1957                                 case NEXTUNREADMSGDIALOG_ALWAYS:
1958                                         val = alertpanel(_("No more marked messages"),
1959                                                          _("No marked message found. "
1960                                                            "Go to next folder?"),
1961                                                          GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1962                                         break;
1963                                 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1964                                         val = G_ALERTALTERNATE;
1965                                         break;
1966                                 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1967                                         val = G_ALERTOTHER;
1968                                         break;
1969                                 default:
1970                                         debug_print(
1971                                                 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1972                         }
1973
1974                         if (val == G_ALERTALTERNATE) {
1975                                 folderview_select_next_marked(summaryview->folderview);
1976                                 return;
1977                         } 
1978                         else
1979                                 return;
1980                 } else
1981                         summary_select_node(summaryview, node, TRUE, FALSE);
1982
1983         }
1984 }
1985
1986 void summary_select_prev_labeled(SummaryView *summaryview)
1987 {
1988         GtkCMCTreeNode *node;
1989
1990         node = summary_find_prev_flagged_msg
1991                 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
1992
1993         if (!node) {
1994                 AlertValue val;
1995
1996                 val = alertpanel(_("No more labeled messages"),
1997                                  _("No labeled message found. "
1998                                    "Search from the end?"),
1999                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2000                 if (val != G_ALERTALTERNATE) return;
2001                 node = summary_find_prev_flagged_msg(summaryview, NULL,
2002                                                      MSG_CLABEL_FLAG_MASK, TRUE);
2003         }
2004
2005         if (!node)
2006                 alertpanel_notice(_("No labeled messages."));
2007         else
2008                 summary_select_node(summaryview, node, TRUE, FALSE);
2009 }
2010
2011 void summary_select_next_labeled(SummaryView *summaryview)
2012 {
2013         GtkCMCTreeNode *node;
2014
2015         node = summary_find_next_flagged_msg
2016                 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2017
2018         if (!node) {
2019                 AlertValue val;
2020
2021                 val = alertpanel(_("No more labeled messages"),
2022                                  _("No labeled message found. "
2023                                    "Search from the beginning?"),
2024                                  GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2025                 if (val != G_ALERTALTERNATE) return;
2026                 node = summary_find_next_flagged_msg(summaryview, NULL,
2027                                                      MSG_CLABEL_FLAG_MASK, TRUE);
2028         }
2029
2030         if (!node)
2031                 alertpanel_notice(_("No labeled messages."));
2032         else
2033                 summary_select_node(summaryview, node, TRUE, FALSE);
2034 }
2035
2036 void summary_select_last_read(SummaryView *summaryview)
2037 {
2038         if (summaryview->last_displayed)
2039                 summary_select_node(summaryview, summaryview->last_displayed, TRUE, FALSE);
2040 }
2041
2042 void summary_select_parent(SummaryView *summaryview)
2043 {
2044         GtkCMCTreeNode *node = NULL;
2045
2046         if (summaryview->selected)
2047                 node = GTK_CMCTREE_ROW(summaryview->selected)->parent;
2048         if (node)
2049                 summary_select_node(summaryview, node, TRUE, FALSE);
2050 }
2051
2052 void summary_select_by_msgnum(SummaryView *summaryview, guint msgnum)
2053 {
2054         GtkCMCTreeNode *node;
2055
2056         node = summary_find_msg_by_msgnum(summaryview, msgnum);
2057         summary_select_node(summaryview, node, FALSE, TRUE);
2058 }
2059
2060 void summary_select_by_msg_list(SummaryView     *summaryview, GSList *msginfos)
2061 {
2062         GtkCMCTree *ctree;
2063         GSList *msgnum_list, *walk;
2064         gboolean froze = FALSE;
2065
2066         ctree = GTK_CMCTREE(summaryview->ctree);
2067
2068         msgnum_list = NULL;
2069         for(walk = msginfos; walk; walk = walk->next) {
2070                 MsgInfo *msginfo;
2071                 msginfo = walk->data;
2072                 msgnum_list = g_slist_prepend(msgnum_list, GUINT_TO_POINTER(msginfo->msgnum));
2073         }
2074         START_LONG_OPERATION(summaryview, FALSE);
2075         for(walk = msgnum_list; walk; walk = walk->next) {
2076                 GtkCMCTreeNode *node;
2077                 node = summary_find_msg_by_msgnum(summaryview, GPOINTER_TO_UINT(walk->data));
2078                 gtk_cmctree_select(ctree, node);
2079         }
2080         END_LONG_OPERATION(summaryview);
2081         g_slist_free(msgnum_list);
2082 }
2083
2084 typedef struct _PostponedSelectData
2085 {
2086         GtkCMCTree *ctree;
2087         GtkCMCTreeNode *row;
2088         GtkCMCTreeNode *node;
2089         GtkScrollType type;
2090         gint column;
2091         SummaryView *summaryview;
2092         gboolean display_msg;
2093         gboolean do_refresh;
2094 } PostponedSelectData;
2095
2096 static gboolean summary_select_retry(void *data)
2097 {
2098         PostponedSelectData *psdata = (PostponedSelectData *)data;
2099         debug_print("trying again\n");
2100         if (psdata->row)
2101                 summary_selected(psdata->ctree, psdata->row,
2102                             psdata->column, psdata->summaryview);
2103         else if (psdata->node)
2104                 summary_select_node(psdata->summaryview, psdata->node,
2105                             psdata->display_msg, psdata->do_refresh);
2106         else
2107                 summary_step(psdata->summaryview, psdata->type);
2108         g_free(psdata);
2109         return FALSE;
2110 }
2111
2112 /**
2113  * summary_select_node:
2114  * @summaryview: Summary view.
2115  * @node: Summary tree node.
2116  * @display_msg: TRUE to display the selected message.
2117  * @do_refresh: TRUE to refresh the widget.
2118  *
2119  * Select @node (bringing it into view by scrolling and expanding its
2120  * thread, if necessary) and unselect all others.  If @display_msg is
2121  * TRUE, display the corresponding message in the message view.
2122  * If @do_refresh is TRUE, the widget is refreshed.
2123  **/
2124 void summary_select_node(SummaryView *summaryview, GtkCMCTreeNode *node,
2125                          gboolean display_msg, gboolean do_refresh)
2126 {
2127         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2128         
2129         if (summary_is_locked(summaryview)
2130         && !GTK_SCTREE(ctree)->selecting_range
2131         && summaryview->messageview->mimeview
2132         && summaryview->messageview->mimeview->type == MIMEVIEW_TEXT
2133         && summaryview->messageview->mimeview->textview->loading) {
2134                 PostponedSelectData *data = g_new0(PostponedSelectData, 1);
2135                 summaryview->messageview->mimeview->textview->stop_loading = TRUE;
2136                 
2137                 data->ctree = ctree;
2138                 data->row = NULL;
2139                 data->node = node;
2140                 data->summaryview = summaryview;
2141                 data->display_msg = display_msg;
2142                 data->do_refresh = do_refresh;
2143                 debug_print("postponing open of message till end of load\n");
2144                 g_timeout_add(100, summary_select_retry, data);
2145                 return;
2146         }
2147         if (summary_is_locked(summaryview)) {
2148                 return;
2149         }
2150         if (!summaryview->folder_item)
2151                 return;
2152         if (node) {
2153                 gtkut_ctree_expand_parent_all(ctree, node);
2154                 if (do_refresh) {
2155                         summary_lock(summaryview);
2156                         GTK_EVENTS_FLUSH();
2157                         summary_unlock(summaryview);
2158                         gtk_widget_grab_focus(GTK_WIDGET(ctree));
2159                         gtk_cmctree_node_moveto(ctree, node, 0, 0.5, 0);
2160                 }
2161                 if (display_msg && summaryview->displayed == node)
2162                         summaryview->displayed = NULL;
2163                 summaryview->display_msg = display_msg;
2164                 gtk_sctree_select(GTK_SCTREE(ctree), node);
2165                 if (summaryview->selected == NULL)
2166                         summaryview->selected = node;
2167         }
2168 }
2169
2170 guint summary_get_msgnum(SummaryView *summaryview, GtkCMCTreeNode *node)
2171 {
2172         GtkCMCTree *ctree =NULL;
2173         MsgInfo *msginfo;
2174
2175         if (!summaryview)
2176                 return 0;
2177         ctree = GTK_CMCTREE(summaryview->ctree);
2178         if (!node)
2179                 return 0;
2180         msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2181         if (msginfo)
2182                 return msginfo->msgnum;
2183         else 
2184                 return -1;
2185 }
2186
2187 static GtkCMCTreeNode *summary_find_prev_msg(SummaryView *summaryview,
2188                                            GtkCMCTreeNode *current_node)
2189 {
2190         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2191         GtkCMCTreeNode *node;
2192         MsgInfo *msginfo;
2193
2194         if (current_node)
2195                 node = current_node;
2196         else
2197                 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2198
2199         for (; node != NULL; node = GTK_CMCTREE_NODE_PREV(node)) {
2200                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2201                 if (msginfo && !MSG_IS_DELETED(msginfo->flags)) break;
2202         }
2203
2204         return node;
2205 }
2206
2207 static GtkCMCTreeNode *summary_find_next_msg(SummaryView *summaryview,
2208                                            GtkCMCTreeNode *current_node)
2209 {
2210         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2211         GtkCMCTreeNode *node;
2212         MsgInfo *msginfo;
2213
2214         if (current_node)
2215                 node = current_node;
2216         else
2217                 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2218
2219         for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2220                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2221                 if (msginfo && !MSG_IS_DELETED(msginfo->flags) 
2222                 && !MSG_IS_MOVE(msginfo->flags)) break;
2223         }
2224
2225         return node;
2226 }
2227
2228 static GtkCMCTreeNode *summary_find_prev_flagged_msg(SummaryView *summaryview,
2229                                                    GtkCMCTreeNode *current_node,
2230                                                    MsgPermFlags flags,
2231                                                    gboolean start_from_prev)
2232 {
2233         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2234         GtkCMCTreeNode *node;
2235         MsgInfo *msginfo;
2236
2237         if (current_node) {
2238                 if (start_from_prev)
2239                         node = GTK_CMCTREE_NODE_PREV(current_node);
2240                 else
2241                         node = current_node;
2242         } else
2243                 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2244
2245         for (; node != NULL; node = GTK_CMCTREE_NODE_PREV(node)) {
2246                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2247                 if (msginfo && (msginfo->flags.perm_flags & flags) != 0) break;
2248         }
2249
2250         return node;
2251 }
2252
2253 static GtkCMCTreeNode *summary_find_next_flagged_msg(SummaryView *summaryview,
2254                                                    GtkCMCTreeNode *current_node,
2255                                                    MsgPermFlags flags,
2256                                                    gboolean start_from_next)
2257 {
2258         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2259         GtkCMCTreeNode *node;
2260         MsgInfo *msginfo;
2261
2262         if (current_node) {
2263                 if (start_from_next)
2264                         node = gtkut_ctree_node_next(ctree, current_node);
2265                 else
2266                         node = current_node;
2267         } else
2268                 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2269
2270         for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2271                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2272                 /* Find msg with matching flags but ignore messages with
2273                    ignore flags, if searching for new or unread messages */
2274                 if ((msginfo && (msginfo->flags.perm_flags & flags) != 0) &&
2275                     !(((flags & (MSG_NEW | MSG_UNREAD)) != 0) && MSG_IS_IGNORE_THREAD(msginfo->flags)) 
2276                         )
2277                         break;
2278         }
2279
2280         return node;
2281 }
2282
2283 static GtkCMCTreeNode *summary_find_msg_by_msgnum(SummaryView *summaryview,
2284                                                 guint msgnum)
2285 {
2286         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2287         GtkCMCTreeNode *node;
2288         MsgInfo *msginfo;
2289
2290         node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2291
2292         for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2293                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2294                 if (msginfo && msginfo->msgnum == msgnum) break;
2295         }
2296
2297         return node;
2298 }
2299
2300 static guint attract_hash_func(gconstpointer key)
2301 {
2302         gchar *str;
2303         gchar *p;
2304         guint h;
2305
2306         Xstrdup_a(str, (const gchar *)key, return 0);
2307         trim_subject(str);
2308
2309         p = str;
2310         h = *p;
2311
2312         if (h) {
2313                 for (p += 1; *p != '\0'; p++)
2314                         h = (h << 5) - h + *p;
2315         }
2316
2317         return h;
2318 }
2319
2320 static gint attract_compare_func(gconstpointer a, gconstpointer b)
2321 {
2322         return subject_compare((const gchar *)a, (const gchar *)b) == 0;
2323 }
2324
2325 void summary_attract_by_subject(SummaryView *summaryview)
2326 {
2327         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2328         GtkCMCList *clist = GTK_CMCLIST(ctree);
2329         GtkCMCTreeNode *src_node;
2330         GtkCMCTreeNode *dst_node, *sibling;
2331         GtkCMCTreeNode *tmp;
2332         MsgInfo *src_msginfo, *dst_msginfo;
2333         GHashTable *subject_table;
2334
2335         debug_print("Attracting messages by subject...");
2336         STATUSBAR_PUSH(summaryview->mainwin,
2337                        _("Attracting messages by subject..."));
2338
2339         main_window_cursor_wait(summaryview->mainwin);
2340         summary_freeze(summaryview);
2341
2342         subject_table = g_hash_table_new(attract_hash_func,
2343                                          attract_compare_func);
2344
2345         for (src_node = GTK_CMCTREE_NODE(clist->row_list);
2346              src_node != NULL;
2347              src_node = tmp) {
2348                 tmp = GTK_CMCTREE_ROW(src_node)->sibling;
2349                 src_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(src_node);
2350                 if (!src_msginfo) continue;
2351                 if (!src_msginfo->subject) continue;
2352
2353                 /* find attracting node */
2354                 dst_node = g_hash_table_lookup(subject_table,
2355                                                src_msginfo->subject);
2356
2357                 if (dst_node) {
2358                         dst_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(dst_node);
2359
2360                         /* if the time difference is more than 20 days,
2361                            don't attract */
2362                         if (ABS(src_msginfo->date_t - dst_msginfo->date_t)
2363                             > 60 * 60 * 24 * 20)
2364                                 continue;
2365
2366                         sibling = GTK_CMCTREE_ROW(dst_node)->sibling;
2367                         if (src_node != sibling)
2368                                 gtk_cmctree_move(ctree, src_node, NULL, sibling);
2369                 }
2370
2371                 g_hash_table_insert(subject_table,
2372                                     src_msginfo->subject, src_node);
2373         }
2374
2375         g_hash_table_destroy(subject_table);
2376
2377         gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
2378
2379         summary_thaw(summaryview);
2380
2381         debug_print("done.\n");
2382         STATUSBAR_POP(summaryview->mainwin);
2383
2384         main_window_cursor_normal(summaryview->mainwin);
2385 }
2386
2387 static void summary_free_msginfo_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2388                                       gpointer data)
2389 {
2390         MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2391
2392         if (msginfo)
2393                 procmsg_msginfo_free(msginfo);
2394 }
2395
2396 static void summary_set_marks_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2397                                    gpointer data)
2398 {
2399         SummaryView *summaryview = data;
2400         MsgInfo *msginfo;
2401
2402         msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2403
2404         if (MSG_IS_DELETED(msginfo->flags))
2405                 summaryview->deleted++;
2406
2407         summaryview->total_size += msginfo->size;
2408
2409         summary_set_row_marks(summaryview, node);
2410 }
2411
2412 static void summary_update_status(SummaryView *summaryview)
2413 {
2414         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2415         GtkCMCTreeNode *node;
2416         MsgInfo *msginfo;
2417
2418         summaryview->total_size =
2419         summaryview->deleted = summaryview->moved = summaryview->copied = 0;
2420
2421         for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2422              node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2423                 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
2424                 
2425                 if (!msginfo)
2426                         continue;
2427
2428                 if (MSG_IS_DELETED(msginfo->flags))
2429                         summaryview->deleted++;
2430                 if (MSG_IS_MOVE(msginfo->flags))
2431                         summaryview->moved++;
2432                 if (MSG_IS_COPY(msginfo->flags))
2433                         summaryview->copied++;
2434                 summaryview->total_size += msginfo->size;
2435         }
2436 }
2437
2438 static void summary_status_show(SummaryView *summaryview)
2439 {
2440         gchar *str;
2441         gchar *del, *mv, *cp;
2442         gchar *sel;
2443         gchar *spc;
2444         gchar *itstr;
2445         GList *rowlist, *cur;
2446         guint n_selected = 0, n_new = 0, n_unread = 0, n_total = 0;
2447         guint n_marked = 0, n_replied = 0, n_forwarded = 0, n_locked = 0, n_ignored = 0, n_watched = 0;
2448         goffset sel_size = 0, n_size = 0;
2449         MsgInfo *msginfo;
2450         gchar *name;
2451 #if GTK_CHECK_VERSION(2, 12, 0)
2452         gchar *tooltip;
2453 #endif
2454         
2455         if (!summaryview->folder_item) {
2456                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), "");
2457                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), "");
2458                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs),   "");
2459                 toolbar_main_set_sensitive(summaryview->mainwin);
2460                 return;
2461         }
2462
2463         rowlist = GTK_CMCLIST(summaryview->ctree)->selection;
2464         for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2465                 msginfo = gtk_cmctree_node_get_row_data
2466                         (GTK_CMCTREE(summaryview->ctree),
2467                          GTK_CMCTREE_NODE(cur->data));
2468                 if (msginfo) {
2469                         sel_size += msginfo->size;
2470                         n_selected++;
2471                 }
2472         }
2473         
2474         if (summaryview->folder_item->hide_read_msgs 
2475         || summaryview->folder_item->hide_del_msgs
2476         || quicksearch_is_active(summaryview->quicksearch)) {
2477                 rowlist = GTK_CMCLIST(summaryview->ctree)->row_list;
2478                 for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2479                         msginfo = gtk_cmctree_node_get_row_data
2480                                 (GTK_CMCTREE(summaryview->ctree),
2481                                  GTK_CMCTREE_NODE(cur));
2482                         if (msginfo) {
2483                                 n_size += msginfo->size;
2484                                 n_total++;
2485                                 if (MSG_IS_NEW(msginfo->flags))
2486                                         n_new++;
2487                                 if (MSG_IS_UNREAD(msginfo->flags))
2488                                         n_unread++;
2489                                 if (MSG_IS_MARKED(msginfo->flags))
2490                                         n_marked++;
2491                                 if (MSG_IS_REPLIED(msginfo->flags))
2492                                         n_replied++;
2493                                 if (MSG_IS_FORWARDED(msginfo->flags))
2494                                         n_forwarded++;
2495                                 if (MSG_IS_LOCKED(msginfo->flags))
2496                                         n_locked++;
2497                                 if (MSG_IS_IGNORE_THREAD(msginfo->flags))
2498                                         n_ignored++;
2499                                 if (MSG_IS_WATCH_THREAD(msginfo->flags))
2500                                         n_watched++;
2501                         }
2502                 }
2503         } else {
2504                 n_new = summaryview->folder_item->new_msgs;
2505                 n_unread = summaryview->folder_item->unread_msgs;
2506                 n_marked = summaryview->folder_item->marked_msgs;
2507                 n_replied = summaryview->folder_item->replied_msgs;
2508                 n_forwarded = summaryview->folder_item->forwarded_msgs;
2509                 n_locked = summaryview->folder_item->locked_msgs;
2510                 n_ignored = summaryview->folder_item->ignored_msgs;
2511                 n_watched = summaryview->folder_item->watched_msgs;
2512                 n_total = summaryview->folder_item->total_msgs;
2513                 n_size = summaryview->total_size;
2514         }
2515
2516         name = folder_item_get_name(summaryview->folder_item);
2517         gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), name);
2518         g_free(name);
2519
2520         if (summaryview->deleted)
2521                 del = g_strdup_printf(_("%d deleted"), summaryview->deleted);
2522         else
2523                 del = g_strdup("");
2524         if (summaryview->moved)
2525                 mv = g_strdup_printf(_("%s%d moved"),
2526                                      summaryview->deleted ? _(", ") : "",
2527                                      summaryview->moved);
2528         else
2529                 mv = g_strdup("");
2530         if (summaryview->copied)
2531                 cp = g_strdup_printf(_("%s%d copied"),
2532                                      summaryview->deleted ||
2533                                      summaryview->moved ? _(", ") : "",
2534                                      summaryview->copied);
2535         else
2536                 cp = g_strdup("");
2537
2538         if (summaryview->deleted || summaryview->moved || summaryview->copied)
2539                 spc = "    ";
2540         else
2541                 spc = "";
2542
2543         if (n_selected) {
2544                 sel = g_strdup_printf(" (%s)", to_human_readable((goffset)sel_size));
2545                 if (n_selected == 1)
2546                         itstr = g_strdup(_(" item selected"));
2547                 else
2548                         itstr = g_strdup(_(" items selected"));
2549         } else {
2550                 sel = g_strdup("");
2551                 itstr = g_strdup("");
2552         }
2553                 
2554         if (prefs_common.layout_mode != SMALL_LAYOUT) {
2555                 str = g_strconcat(n_selected ? itos(n_selected) : "",
2556                                                 itstr, sel, spc, del, mv, cp, NULL);
2557                 g_free(sel);
2558                 g_free(del);
2559                 g_free(mv);
2560                 g_free(cp);
2561                 g_free(itstr);
2562                 
2563                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2564                 g_free(str);
2565
2566                 str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2567                                               n_new, n_unread, n_total,
2568                                               to_human_readable((goffset)n_size));
2569
2570
2571                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs), str);
2572                 g_free(str);
2573 #if GTK_CHECK_VERSION(2, 12, 0)
2574                 tooltip = g_strdup_printf(_("<b>Message summary</b>\n"
2575                                             "<b>New:</b> %d\n"
2576                                             "<b>Unread:</b> %d\n"
2577                                             "<b>Total:</b> %d\n"
2578                                             "<b>Size:</b> %s\n\n"
2579                                             "<b>Marked:</b> %d\n"
2580                                             "<b>Replied:</b> %d\n"
2581                                             "<b>Forwarded:</b> %d\n"
2582                                             "<b>Locked:</b> %d\n"
2583                                             "<b>Ignored:</b> %d\n"
2584                                             "<b>Watched:</b> %d"),
2585                                               n_new, n_unread, n_total,
2586                                               to_human_readable((goffset)n_size),
2587                                               n_marked,n_replied,n_forwarded,
2588                                               n_locked,n_ignored,n_watched);
2589
2590                 gtk_widget_set_tooltip_markup(GTK_WIDGET(summaryview->statlabel_msgs),
2591                                             tooltip); 
2592                 g_free(tooltip);
2593 #endif
2594         } else {
2595                 gchar *ssize, *tsize;
2596                 if (n_selected) {
2597                         ssize = g_strdup(to_human_readable((goffset)sel_size));
2598                         tsize = g_strdup(to_human_readable((goffset)n_size));
2599                         str = g_strdup_printf(_("%d/%d selected (%s/%s), %d unread"),
2600                                 n_selected, n_total, ssize, tsize, n_unread);
2601                         g_free(ssize);
2602                         g_free(tsize);
2603                 } else
2604                         str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2605                                 n_new, n_unread, n_total, to_human_readable((goffset)n_size));
2606                 g_free(sel);
2607                 g_free(del);
2608                 g_free(mv);
2609                 g_free(cp);
2610                 g_free(itstr);
2611                 
2612                 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2613                 g_free(str);
2614         }
2615
2616         summary_set_menu_sensitive(summaryview);
2617         toolbar_main_set_sensitive(summaryview->mainwin);
2618 }
2619
2620 static void summary_set_column_titles(SummaryView *summaryview)
2621 {
2622         GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
2623         FolderItem *item = summaryview->folder_item;
2624         GtkWidget *hbox;
2625         GtkWidget *label;
2626         GtkWidget *arrow;
2627         gint pos;
2628         const gchar *title;
2629         SummaryColumnType type;
2630         GtkJustification justify;
2631
2632         static FolderSortKey sort_by[N_SUMMARY_COLS] = {
2633                 SORT_BY_MARK,
2634                 SORT_BY_STATUS,
2635                 SORT_BY_MIME,
2636                 SORT_BY_SUBJECT,
2637                 SORT_BY_FROM,
2638                 SORT_BY_TO,
2639                 SORT_BY_DATE,
2640                 SORT_BY_SIZE,
2641                 SORT_BY_NUMBER,
2642                 SORT_BY_SCORE,
2643                 SORT_BY_LOCKED,
2644                 SORT_BY_TAGS
2645         };
2646
2647         for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
2648                 type = summaryview->col_state[pos].type;
2649
2650                 /* CLAWS: mime and unread are single char headers */
2651                 justify = (type == S_COL_NUMBER || type == S_COL_SIZE)
2652                         ? GTK_JUSTIFY_RIGHT : GTK_JUSTIFY_LEFT;
2653
2654                 switch (type) {
2655                 case S_COL_SUBJECT:
2656                 case S_COL_FROM:
2657                 case S_COL_TO:
2658                 case S_COL_DATE:
2659                 case S_COL_NUMBER:
2660                         if(type == S_COL_FROM && item != NULL &&
2661                                         FOLDER_SHOWS_TO_HDR(item) &&
2662                                         !summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
2663                                 type = S_COL_TO;
2664                         if(type == S_COL_NUMBER)
2665                                 title = gettext(col_label[type]);
2666                         else
2667                                 title = prefs_common_translated_header_name(col_label[type]);
2668                         break;
2669                 default:
2670                         title = gettext(col_label[type]);
2671                 }
2672
2673                 if (type == S_COL_MIME) {
2674                         label = gtk_image_new_from_pixbuf(clipxpm);
2675                         gtk_widget_show(label);
2676                         gtk_cmclist_set_column_widget(clist, pos, label);
2677                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Attachment"));
2678                         continue;
2679                 } else if (type == S_COL_MARK) {
2680                         label = gtk_image_new_from_pixbuf(markxpm);
2681                         gtk_widget_show(label);
2682                         gtk_cmclist_set_column_widget(clist, pos, label);
2683                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Mark"));
2684                         continue;
2685                 } else if (type == S_COL_LOCKED) {
2686                         label = gtk_image_new_from_pixbuf(lockedxpm);
2687                         gtk_widget_show(label);
2688                         gtk_cmclist_set_column_widget(clist, pos, label);
2689                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Locked"));
2690                         continue;
2691                 } else if (type == S_COL_STATUS) {
2692                         gtk_cmclist_set_column_title(clist, pos, title);
2693                         gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Status"));
2694                         continue;
2695                 }
2696
2697                 hbox  = gtk_hbox_new(FALSE, 4);
2698                 label = gtk_label_new(title);
2699 #ifdef GENERIC_UMPC
2700         gtk_widget_set_size_request(hbox, -1, 20);
2701 #endif
2702
2703                 if (justify == GTK_JUSTIFY_RIGHT)
2704                         gtk_box_pack_end(GTK_BOX(hbox), label,
2705                                          FALSE, FALSE, 0);
2706                 else
2707                         gtk_box_pack_start(GTK_BOX(hbox), label,
2708                                            FALSE, FALSE, 0);
2709
2710                 if (summaryview->sort_key == sort_by[type]) {
2711                         arrow = gtk_arrow_new
2712                                 (summaryview->sort_type == SORT_ASCENDING
2713                                  ? GTK_ARROW_DOWN : GTK_ARROW_UP,
2714                                  GTK_SHADOW_IN);
2715                         gtk_widget_set_size_request(GTK_WIDGET(arrow), 10, 10);
2716                         if (justify == GTK_JUSTIFY_RIGHT)
2717                                 gtk_box_pack_start(GTK_BOX(hbox), arrow,
2718                                                    FALSE, FALSE, 0);
2719                         else
2720                                 gtk_box_pack_end(GTK_BOX(hbox), arrow,
2721                                                  FALSE, FALSE, 0);
2722                 }
2723
2724                 gtk_widget_show_all(hbox);
2725                 gtk_cmclist_set_column_widget(clist, pos, hbox);
2726         }
2727 }
2728
2729 void summary_reflect_tags_changes(SummaryView *summaryview)
2730 {
2731         GtkMenuShell *menu;
2732         GList *cur;
2733         GtkCMCTreeNode *node;
2734         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2735         gboolean froze = FALSE;
2736         gboolean redisplay = FALSE;
2737
2738         /* re-create colorlabel submenu */
2739         menu = GTK_MENU_SHELL(summaryview->tags_menu);
2740         cm_return_if_fail(menu != NULL);
2741
2742         /* clear items. get item pointers. */
2743         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
2744                 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
2745         }
2746         summary_tags_menu_create(summaryview, TRUE);
2747
2748         START_LONG_OPERATION(summaryview, TRUE);
2749         for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
2750              node = gtkut_ctree_node_next(ctree, node)) {
2751                 redisplay |= summary_set_row_tag(summaryview,
2752                                            node, TRUE, FALSE, 0);
2753         }
2754         END_LONG_OPERATION(summaryview);
2755         if (redisplay)
2756                 summary_redisplay_msg(summaryview);
2757 }
2758
2759
2760 void summary_reflect_prefs(void)
2761 {
2762         static gchar *last_smallfont = NULL;
2763         static gchar *last_normalfont = NULL;
2764         static gchar *last_boldfont = NULL;
2765         static gboolean last_derive = 0;
2766         gboolean update_font = FALSE;
2767         SummaryView *summaryview = NULL;
2768
2769         if (!mainwindow_get_mainwindow())
2770                 return;
2771         summaryview = mainwindow_get_mainwindow()->summaryview;
2772
2773         if (!last_smallfont || strcmp(last_smallfont, SMALL_FONT) ||
2774                         !last_normalfont || strcmp(last_normalfont, NORMAL_FONT) ||
2775                         !last_boldfont || strcmp(last_boldfont, BOLD_FONT) ||
2776                         last_derive != prefs_common.derive_from_normal_font)
2777                 update_font = TRUE;
2778
2779         g_free(last_smallfont);
2780         last_smallfont = g_strdup(SMALL_FONT);
2781         g_free(last_normalfont);
2782         last_normalfont = g_strdup(NORMAL_FONT);
2783         g_free(last_boldfont);
2784         last_boldfont = g_strdup(BOLD_FONT);
2785         last_derive = prefs_common.derive_from_normal_font;
2786
2787         if (update_font) {      
2788                 bold_style = bold_marked_style = bold_deleted_style = 
2789                         small_style = small_marked_style = small_deleted_style = NULL;
2790                 summary_set_fonts(summaryview);
2791         }
2792
2793         summary_set_column_titles(summaryview);
2794         summary_relayout(summaryview);
2795         
2796         if (summaryview->folder_item)
2797                 summary_show(summaryview, summaryview->folder_item);
2798 }
2799
2800 void summary_sort(SummaryView *summaryview,
2801                   FolderSortKey sort_key, FolderSortType sort_type)
2802 {
2803         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2804         GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
2805         GtkCMCListCompareFunc cmp_func = NULL;
2806         START_TIMING("");
2807         g_signal_handlers_block_by_func(G_OBJECT(summaryview->ctree),
2808                                        G_CALLBACK(summary_tree_expanded), summaryview);
2809         summary_freeze(summaryview);
2810
2811         switch (sort_key) {
2812         case SORT_BY_MARK:
2813                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_mark;
2814                 break;
2815         case SORT_BY_STATUS:
2816                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_status;
2817                 break;
2818         case SORT_BY_MIME:
2819                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_mime;
2820                 break;
2821         case SORT_BY_NUMBER:
2822                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_num;
2823                 break;
2824         case SORT_BY_SIZE:
2825                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_size;
2826                 break;
2827         case SORT_BY_DATE:
2828                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_date;
2829                 break;
2830         case SORT_BY_THREAD_DATE:
2831                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_thread_date;
2832                 break;
2833         case SORT_BY_FROM:
2834                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_from;
2835                 break;
2836         case SORT_BY_SUBJECT:
2837 #ifndef G_OS_WIN32
2838                 if (summaryview->simplify_subject_preg)
2839                         cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_simplified_subject;
2840                 else
2841 #endif
2842                         cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_subject;
2843                 break;
2844         case SORT_BY_SCORE:
2845                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_score;
2846                 break;
2847         case SORT_BY_LABEL:
2848                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_label;
2849                 break;
2850         case SORT_BY_TO:
2851                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_to;
2852                 break;
2853         case SORT_BY_LOCKED:
2854                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_locked;
2855                 break;
2856         case SORT_BY_TAGS:
2857                 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_tags;
2858                 break;
2859         case SORT_BY_NONE:
2860                 break;
2861         default:
2862                 goto unlock;
2863         }
2864
2865         summaryview->sort_key = sort_key;
2866         summaryview->sort_type = sort_type;
2867
2868         summary_set_column_titles(summaryview);
2869         summary_set_menu_sensitive(summaryview);
2870
2871         /* allow fallback to don't sort */
2872         if (summaryview->sort_key == SORT_BY_NONE)
2873                 goto unlock;
2874
2875         if (cmp_func != NULL) {
2876                 debug_print("Sorting summary...");
2877                 STATUSBAR_PUSH(summaryview->mainwin, _("Sorting summary..."));
2878
2879                 main_window_cursor_wait(summaryview->mainwin);
2880
2881                 gtk_cmclist_set_compare_func(clist, cmp_func);
2882
2883                 gtk_cmclist_set_sort_type(clist, (GtkSortType)sort_type);
2884                 gtk_sctree_sort_recursive(ctree, NULL);
2885
2886                 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
2887
2888                 main_window_cursor_normal(summaryview->mainwin);
2889
2890                 debug_print("done.\n");
2891                 STATUSBAR_POP(summaryview->mainwin);
2892         }
2893 unlock:
2894         summary_thaw(summaryview);
2895         g_signal_handlers_unblock_by_func(G_OBJECT(summaryview->ctree),
2896                                        G_CALLBACK(summary_tree_expanded), summaryview);
2897         END_TIMING();
2898 }
2899
2900 static gboolean summary_update_thread_age(GNode *node, gpointer data)
2901 {
2902         MsgInfo *msginfo = node->data;
2903         time_t *most_recent = (time_t *)data;
2904
2905         if (msginfo->date_t > *most_recent) {
2906                 *most_recent = msginfo->date_t;
2907         }
2908         return FALSE;
2909 }       
2910
2911 static void summary_find_thread_age(GNode *gnode)
2912 {
2913         MsgInfo *msginfo = (MsgInfo *)gnode->data;
2914         time_t most_recent;
2915
2916         if (!msginfo)
2917                 return;
2918         most_recent = msginfo->thread_date = msginfo->date_t;
2919
2920         g_node_traverse(gnode, G_IN_ORDER, G_TRAVERSE_ALL, -1, summary_update_thread_age, &most_recent);
2921
2922         msginfo->thread_date = most_recent;
2923 }
2924
2925 static gboolean summary_insert_gnode_func(GtkCMCTree *ctree, guint depth, GNode *gnode,
2926                                    GtkCMCTreeNode *cnode, gpointer data)
2927 {
2928         SummaryView *summaryview = (SummaryView *)data;
2929         MsgInfo *msginfo = (MsgInfo *)gnode->data;
2930         gchar *text[N_SUMMARY_COLS];
2931         gint *col_pos = summaryview->col_pos;
2932         const gchar *msgid = msginfo->msgid;
2933         GHashTable *msgid_table = summaryview->msgid_table;
2934         gboolean vert = (prefs_common.layout_mode == VERTICAL_LAYOUT);
2935
2936         summary_set_header(summaryview, text, msginfo);
2937
2938         gtk_sctree_set_node_info(ctree, cnode, text[col_pos[S_COL_SUBJECT]], 2,
2939                                 NULL, NULL, FALSE, summaryview->threaded && !summaryview->thread_collapsed);
2940 #define SET_TEXT(col) {                                         \
2941         gtk_cmctree_node_set_text(ctree, cnode, col_pos[col],   \
2942                                 text[col_pos[col]]);            \
2943 }
2944
2945         if (summaryview->col_state[summaryview->col_pos[S_COL_NUMBER]].visible)
2946                 SET_TEXT(S_COL_NUMBER);
2947         if (summaryview->col_state[summaryview->col_pos[S_COL_SCORE]].visible)
2948                 SET_TEXT(S_COL_SCORE);
2949         if (summaryview->col_state[summaryview->col_pos[S_COL_SIZE]].visible)
2950                 SET_TEXT(S_COL_SIZE);
2951         if (summaryview->col_state[summaryview->col_pos[S_COL_DATE]].visible)
2952                 SET_TEXT(S_COL_DATE);
2953         if (summaryview->col_state[summaryview->col_pos[S_COL_FROM]].visible)
2954                 SET_TEXT(S_COL_FROM);
2955         if (summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
2956                 SET_TEXT(S_COL_TO);
2957         if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible)
2958                 SET_TEXT(S_COL_TAGS);
2959
2960         if (vert && prefs_common.two_line_vert)
2961                 g_free(text[summaryview->col_pos[S_COL_SUBJECT]]);
2962
2963 #undef SET_TEXT
2964
2965         GTKUT_CTREE_NODE_SET_ROW_DATA(cnode, msginfo);
2966         summary_set_marks_func(ctree, cnode, summaryview);
2967
2968         if (msgid && msgid[0] != '\0')
2969                 g_hash_table_insert(msgid_table, (gchar *)msgid, cnode);
2970
2971         return TRUE;
2972 }
2973
2974 static void summary_set_ctree_from_list(SummaryView *summaryview,
2975                                         GSList *mlist)
2976 {
2977         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2978         MsgInfo *msginfo;
2979         GtkCMCTreeNode *node = NULL;
2980         GHashTable *msgid_table;
2981         GHashTable *subject_table = NULL;
2982         GSList * cur;
2983         gboolean vert = (prefs_common.layout_mode == VERTICAL_LAYOUT);
2984
2985         START_TIMING("");
2986         
2987         if (!mlist) return;
2988
2989         debug_print("\tSetting summary from message data...\n");
2990         STATUSBAR_PUSH(summaryview->mainwin,
2991                        _("Setting summary from message data..."));
2992         gdk_flush();
2993
2994         g_signal_handlers_block_by_func(G_OBJECT(ctree),
2995                                        G_CALLBACK(summary_tree_expanded), summaryview);
2996
2997         msgid_table = g_hash_table_new(g_str_hash, g_str_equal);
2998         summaryview->msgid_table = msgid_table;
2999
3000         if (prefs_common.thread_by_subject) {
3001                 subject_table = g_hash_table_new(g_str_hash, g_str_equal);
3002                 summaryview->subject_table = subject_table;
3003         } else {
3004                 summaryview->subject_table = NULL;
3005         }
3006
3007         if (prefs_common.use_addr_book)
3008                 start_address_completion(NULL);
3009         
3010         if (summaryview->threaded) {
3011                 GNode *root, *gnode;
3012                 START_TIMING("threaded");
3013                 root = procmsg_get_thread_tree(mlist);
3014
3015                 
3016                 for (gnode = root->children; gnode != NULL;
3017                      gnode = gnode->next) {
3018                         summary_find_thread_age(gnode);
3019                         node = gtk_sctree_insert_gnode
3020                                 (ctree, NULL, node, gnode,
3021                                  summary_insert_gnode_func, summaryview);
3022                 }
3023
3024                 g_node_destroy(root);
3025                 
3026                 END_TIMING();
3027         } else {
3028                 gchar *text[N_SUMMARY_COLS];
3029                 START_TIMING("unthreaded");
3030                 cur = mlist;
3031                 for (; mlist != NULL; mlist = mlist->next) {
3032                         msginfo = (MsgInfo *)mlist->data;
3033
3034                         summary_set_header(summaryview, text, msginfo);
3035
3036                         node = gtk_sctree_insert_node
3037                                 (ctree, NULL, node, text, 2,
3038                                  NULL, NULL,
3039                                  FALSE, FALSE);
3040                         if (vert && prefs_common.two_line_vert)
3041                                 g_free(text[summaryview->col_pos[S_COL_SUBJECT]]);
3042
3043                         GTKUT_CTREE_NODE_SET_ROW_DATA(node, msginfo);
3044                         summary_set_marks_func(ctree, node, summaryview);
3045
3046                         if (msginfo->msgid && msginfo->msgid[0] != '\0')
3047                                 g_hash_table_insert(msgid_table,
3048                                                     msginfo->msgid, node);
3049
3050                         if (prefs_common.thread_by_subject)
3051                                 subject_table_insert(subject_table,
3052                                              msginfo->subject,
3053                                              node);
3054                 }
3055                 mlist = cur;
3056                 END_TIMING();
3057         }
3058
3059         if (prefs_common.enable_hscrollbar &&
3060             summaryview->col_pos[S_COL_SUBJECT] == N_SUMMARY_COLS - 1) {
3061                 gint optimal_width;
3062
3063                 optimal_width = gtk_cmclist_optimal_column_width
3064                         (GTK_CMCLIST(ctree), summaryview->col_pos[S_COL_SUBJECT]);
3065                 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree),
3066                                            summaryview->col_pos[S_COL_SUBJECT],
3067                                            optimal_width);
3068         }
3069
3070         if (prefs_common.use_addr_book)
3071                 end_address_completion();
3072
3073         debug_print("done.\n");
3074         STATUSBAR_POP(summaryview->mainwin);
3075         if (debug_get_mode()) {
3076                 debug_print("\tmsgid hash table size = %d\n",
3077                             g_hash_table_size(msgid_table));
3078                 if (prefs_common.thread_by_subject)
3079                         debug_print("\tsubject hash table size = %d\n",
3080                             g_hash_table_size(subject_table));
3081         }
3082
3083         summary_sort(summaryview, summaryview->sort_key, summaryview->sort_type);
3084
3085         node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
3086
3087         if (prefs_common.bold_unread) {
3088                 START_TIMING("bold_unread");
3089                 while (node) {
3090                         GtkCMCTreeNode *next = GTK_CMCTREE_NODE_NEXT(node);
3091                         if (GTK_CMCTREE_ROW(node)->children)
3092                                 summary_set_row_marks(summaryview, node);
3093                         node = next;
3094                 }
3095                 END_TIMING();
3096         }
3097
3098         g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
3099                                        G_CALLBACK(summary_tree_expanded), summaryview);
3100         END_TIMING();
3101 }
3102
3103 static gchar *summary_complete_address(const gchar *addr)
3104 {
3105         gint count;
3106         gchar *res, *tmp, *email_addr;
3107         
3108         if (addr == NULL || !strchr(addr, '@'))
3109                 return NULL;
3110
3111         Xstrdup_a(email_addr, addr, return NULL);
3112         extract_address(email_addr);
3113         if (!*email_addr)
3114                 return NULL;
3115
3116         /*
3117          * completion stuff must be already initialized
3118          */
3119         res = NULL;
3120         if (1 < (count = complete_address(email_addr))) {
3121                 tmp = get_complete_address(1);
3122                 res = procheader_get_fromname(tmp);
3123                 g_free(tmp);
3124         }
3125
3126         return res;
3127 }
3128
3129 static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
3130                                MsgInfo *msginfo)
3131 {
3132         static gchar date_modified[80];
3133         static gchar col_score[11];
3134         static gchar buf[BUFFSIZE], tmp1[BUFFSIZE], tmp2[BUFFSIZE], tmp3[BUFFSIZE];
3135         gint *col_pos = summaryview->col_pos;
3136         gchar *from_text = NULL, *to_text = NULL, *tags_text = NULL;
3137         gboolean should_swap = FALSE;
3138         gboolean vert = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3139 #if GTK_CHECK_VERSION(2,12,0)
3140         static const gchar *color_dim_rgb = NULL;
3141         if (!color_dim_rgb)
3142                 color_dim_rgb = gdk_color_to_string(&summaryview->color_dim);
3143 #else
3144         static const gchar *color_dim_rgb = "#888888";
3145 #endif
3146         text[col_pos[S_COL_FROM]]   = "";
3147         text[col_pos[S_COL_TO]]     = "";
3148         text[col_pos[S_COL_SUBJECT]]= "";
3149         text[col_pos[S_COL_MARK]]   = "";
3150         text[col_pos[S_COL_STATUS]] = "";
3151         text[col_pos[S_COL_MIME]]   = "";
3152         text[col_pos[S_COL_LOCKED]] = "";
3153         text[col_pos[S_COL_DATE]]   = "";
3154         text[col_pos[S_COL_TAGS]]   = "";
3155         if (summaryview->col_state[summaryview->col_pos[S_COL_NUMBER]].visible)
3156                 text[col_pos[S_COL_NUMBER]] = itos(msginfo->msgnum);
3157         else
3158                 text[col_pos[S_COL_NUMBER]] = "";
3159
3160         /* slow! */
3161         if (summaryview->col_state[summaryview->col_pos[S_COL_SIZE]].visible)
3162                 text[col_pos[S_COL_SIZE]] = to_human_readable(msginfo->size);
3163         else
3164                 text[col_pos[S_COL_SIZE]] = "";
3165
3166         if (summaryview->col_state[summaryview->col_pos[S_COL_SCORE]].visible)
3167                 text[col_pos[S_COL_SCORE]] = itos_buf(col_score, msginfo->score);
3168         else
3169                 text[col_pos[S_COL_SCORE]] = "";
3170
3171         if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible) {
3172                 tags_text = procmsg_msginfo_get_tags_str(msginfo);
3173                 if (!tags_text) {
3174             &nbs