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