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