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