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