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