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