2006-10-04 [wwp] 2.5.3cvs4
[claws.git] / src / prefs_folder_item.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 /* alfons - all folder item specific settings should migrate into 
21  * folderlist.xml!!! the old folderitemrc file will only serve for a few 
22  * versions (for compatibility) */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "defs.h"
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include "folder.h"
33 #include "prefs_folder_item.h"
34 #include "folderview.h"
35 #include "folder.h"
36 #include "summaryview.h"
37 #include "menu.h"
38 #include "account.h"
39 #include "prefs_gtk.h"
40 #include "manage_window.h"
41 #include "utils.h"
42 #include "addr_compl.h"
43 #include "prefs_common.h"
44 #include "gtkutils.h"
45 #include "filtering.h"
46 #include "folder_item_prefs.h"
47 #include "gtk/colorsel.h"
48 #include "string_match.h"
49
50 #if USE_ASPELL
51 #include "gtkaspell.h"
52 #endif
53
54 #define ASSIGN_STRING(string, value) \
55         { \
56                 g_free(string); \
57                 string = (value); \
58         }
59
60 typedef struct _FolderItemGeneralPage FolderItemGeneralPage;
61 typedef struct _FolderItemComposePage FolderItemComposePage;
62
63 struct _FolderItemGeneralPage
64 {
65         PrefsPage page;
66
67         FolderItem *item;
68
69         GtkWidget *table;
70         GtkWidget *folder_type;
71         GtkWidget *checkbtn_simplify_subject;
72         GtkWidget *entry_simplify_subject;
73         GtkWidget *entry_regexp_test_string;
74         GtkWidget *entry_regexp_test_result;
75         GtkWidget *checkbtn_folder_chmod;
76         GtkWidget *entry_folder_chmod;
77         GtkWidget *folder_color_btn;
78         GtkWidget *checkbtn_enable_processing;
79         GtkWidget *checkbtn_newmailcheck;
80         GtkWidget *checkbtn_offlinesync;
81
82         /* apply to sub folders */
83         GtkWidget *simplify_subject_rec_checkbtn;
84         GtkWidget *folder_chmod_rec_checkbtn;
85         GtkWidget *folder_color_rec_checkbtn;
86         GtkWidget *enable_processing_rec_checkbtn;
87         GtkWidget *newmailcheck_rec_checkbtn;
88         GtkWidget *offlinesync_rec_checkbtn;
89
90         gint       folder_color;
91 };
92
93 struct _FolderItemComposePage
94 {
95         PrefsPage page;
96
97         FolderItem *item;
98
99         GtkWidget *window;
100         GtkWidget *table;
101         GtkWidget *checkbtn_request_return_receipt;
102         GtkWidget *checkbtn_save_copy_to_folder;
103         GtkWidget *checkbtn_default_to;
104         GtkWidget *entry_default_to;
105         GtkWidget *checkbtn_default_reply_to;
106         GtkWidget *entry_default_reply_to;
107         GtkWidget *checkbtn_enable_default_account;
108         GtkWidget *optmenu_default_account;
109 #if USE_ASPELL
110         GtkWidget *checkbtn_enable_default_dictionary;
111         GtkWidget *optmenu_default_dictionary;
112 #endif
113
114         /* apply to sub folders */
115         GtkWidget *request_return_receipt_rec_checkbtn;
116         GtkWidget *save_copy_to_folder_rec_checkbtn;
117         GtkWidget *default_to_rec_checkbtn;
118         GtkWidget *default_reply_to_rec_checkbtn;
119         GtkWidget *default_account_rec_checkbtn;
120 #if USE_ASPELL
121         GtkWidget *default_dictionary_rec_checkbtn;
122 #endif
123 };
124
125
126 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page);
127 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page);
128
129 static gboolean general_save_recurse_func(GNode *node, gpointer data);
130 static gboolean compose_save_recurse_func(GNode *node, gpointer data);
131
132 gint prefs_folder_item_chmod_mode               (gchar *folder_chmod);
133
134 static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
135 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data);
136 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data);
137
138 #define SAFE_STRING(str) \
139         (str) ? (str) : ""
140
141 void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
142                                                    GtkWindow * window,
143                                                    gpointer data)
144 {
145         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
146         FolderItem *item = (FolderItem *) data;
147         guint rowcount;
148
149
150         GtkWidget *table;
151         GtkWidget *hbox;
152         GtkWidget *label;
153         
154         GtkWidget *folder_type_menu;
155         GtkWidget *folder_type;
156         GtkWidget *dummy_chkbtn;
157         GtkWidget *menuitem;
158         SpecialFolderItemType type;
159         
160         GtkWidget *checkbtn_simplify_subject;
161         GtkWidget *entry_simplify_subject;
162         GtkWidget *hbox_regexp;
163         GtkWidget *label_regexp_test;
164         GtkWidget *entry_regexp_test_string;
165         GtkWidget *left_arrow;
166         GtkWidget *entry_regexp_test_result;
167
168         GtkWidget *checkbtn_folder_chmod;
169         GtkWidget *entry_folder_chmod;
170         GtkWidget *folder_color;
171         GtkWidget *folder_color_btn;
172         GtkWidget *checkbtn_enable_processing;
173         GtkWidget *checkbtn_newmailcheck;
174         GtkWidget *checkbtn_offlinesync;
175
176         GtkWidget *simplify_subject_rec_checkbtn;
177         GtkWidget *folder_chmod_rec_checkbtn;
178         GtkWidget *folder_color_rec_checkbtn;
179         GtkWidget *enable_processing_rec_checkbtn;
180         GtkWidget *newmailcheck_rec_checkbtn;
181         GtkWidget *offlinesync_rec_checkbtn;
182         GtkTooltips *tooltips;
183
184         page->item         = item;
185
186         /* Table */
187         table = gtk_table_new(6, 2, FALSE);
188         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
189         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
190         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
191         rowcount = 0;
192
193         /* Apply to subfolders */
194         label = gtk_label_new(_("Apply to\nsubfolders"));
195         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
196         gtk_table_attach(GTK_TABLE(table), label, 3, 4,
197                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
198         rowcount++;
199
200         /* folder_type */
201         folder_type = gtk_option_menu_new ();
202         gtk_widget_show (folder_type);
203
204         type = F_NORMAL;
205         if (item->stype == F_INBOX)
206                 type = F_INBOX;
207         else if (folder_has_parent_of_type(item, F_OUTBOX))
208                 type = F_OUTBOX;
209         else if (folder_has_parent_of_type(item, F_DRAFT))
210                 type = F_DRAFT;
211         else if (folder_has_parent_of_type(item, F_QUEUE))
212                 type = F_QUEUE;
213         else if (folder_has_parent_of_type(item, F_TRASH))
214                 type = F_TRASH;
215
216         folder_type_menu = gtk_menu_new ();
217
218         MENUITEM_ADD (folder_type_menu, menuitem, _("Normal"),  F_NORMAL);
219         MENUITEM_ADD (folder_type_menu, menuitem, _("Inbox"),  F_INBOX);
220         MENUITEM_ADD (folder_type_menu, menuitem, _("Outbox"),  F_OUTBOX);
221         MENUITEM_ADD (folder_type_menu, menuitem, _("Drafts"),  F_DRAFT);
222         MENUITEM_ADD (folder_type_menu, menuitem, _("Queue"),  F_QUEUE);
223         MENUITEM_ADD (folder_type_menu, menuitem, _("Trash"),  F_TRASH);
224         gtk_option_menu_set_menu (GTK_OPTION_MENU (folder_type), folder_type_menu);
225
226         gtk_option_menu_set_history(GTK_OPTION_MENU(folder_type), type);
227
228         dummy_chkbtn = gtk_check_button_new();
229         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy_chkbtn), type != F_INBOX);
230         gtk_widget_set_sensitive(dummy_chkbtn, FALSE);
231
232         if (type == item->stype && type == F_NORMAL)
233                 gtk_widget_set_sensitive(folder_type, TRUE);
234         else
235                 gtk_widget_set_sensitive(folder_type, FALSE);
236
237         label = gtk_label_new(_("Folder type"));
238         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
239         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 
240                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
241         gtk_table_attach(GTK_TABLE(table), folder_type, 1, 2, 
242                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
243         gtk_table_attach(GTK_TABLE(table), dummy_chkbtn, 3, 4, 
244                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
245
246         rowcount++;
247
248         /* Simplify Subject */
249         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp"));
250         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
251                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
252         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
253                                      item->prefs->enable_simplify_subject);
254
255         g_signal_connect(G_OBJECT(checkbtn_simplify_subject), "toggled",
256                         G_CALLBACK(folder_regexp_set_subject_example_cb), page);
257
258         entry_simplify_subject = gtk_entry_new();
259         gtk_table_attach(GTK_TABLE(table), entry_simplify_subject, 1, 3, 
260                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
261         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
262         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
263                            SAFE_STRING(item->prefs->simplify_subject_regexp));
264
265         g_signal_connect(G_OBJECT(entry_simplify_subject), "changed",
266                         G_CALLBACK(folder_regexp_test_cb), page);
267
268         simplify_subject_rec_checkbtn = gtk_check_button_new();
269         gtk_table_attach(GTK_TABLE(table), simplify_subject_rec_checkbtn, 3, 4, 
270                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
271
272         rowcount++;
273
274         /* Test RegExp */
275         label_regexp_test = gtk_label_new(_("Test RegExp"));
276         gtk_misc_set_alignment(GTK_MISC(label_regexp_test), 0, 0.5);
277         gtk_table_attach(GTK_TABLE(table), label_regexp_test, 0, 1, 
278                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
279         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, label_regexp_test);
280
281         entry_regexp_test_string = gtk_entry_new();
282         gtk_table_attach(GTK_TABLE(table), entry_regexp_test_string, 1, 2, 
283                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
284         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_string);
285
286         g_signal_connect(G_OBJECT(entry_regexp_test_string), "changed",
287                         G_CALLBACK(folder_regexp_test_cb), page);
288
289         hbox_regexp = gtk_hbox_new (FALSE, 4);
290         gtk_widget_show (hbox_regexp);
291         gtk_table_attach(GTK_TABLE(table), hbox_regexp, 2, 3, 
292                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
293
294         left_arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
295         gtk_widget_show(left_arrow);
296         gtk_box_pack_start (GTK_BOX(hbox_regexp), left_arrow, FALSE, FALSE, 0);
297         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, left_arrow);
298
299         entry_regexp_test_result = gtk_entry_new();
300         gtk_box_pack_end (GTK_BOX(hbox_regexp), entry_regexp_test_result, TRUE, TRUE, 0);
301         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_result);
302         gtk_entry_set_editable(GTK_ENTRY(entry_regexp_test_result), FALSE);
303
304         rowcount++;
305
306         /* Folder chmod */
307         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod"));
308         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
309                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
310
311         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
312                                      item->prefs->enable_folder_chmod);
313
314         entry_folder_chmod = gtk_entry_new();
315         gtk_table_attach(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
316                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
317         SET_TOGGLE_SENSITIVITY(checkbtn_folder_chmod, entry_folder_chmod);
318         if (item->prefs->folder_chmod) {
319                 gchar *buf;
320
321                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
322                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
323                 g_free(buf);
324         }
325         
326         folder_chmod_rec_checkbtn = gtk_check_button_new();
327         gtk_table_attach(GTK_TABLE(table), folder_chmod_rec_checkbtn, 3, 4, 
328                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
329
330         rowcount++;
331         
332         /* Folder color */
333         folder_color = gtk_label_new(_("Folder color"));
334         gtk_misc_set_alignment(GTK_MISC(folder_color), 0, 0.5);
335         gtk_table_attach(GTK_TABLE(table), folder_color, 0, 1, 
336                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
337
338         hbox = gtk_hbox_new(FALSE, 0);
339         gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 
340                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
341
342         folder_color_btn = gtk_button_new_with_label("");
343         gtk_widget_set_size_request(folder_color_btn, 36, 26);
344         gtk_box_pack_start (GTK_BOX(hbox), folder_color_btn, FALSE, FALSE, 0);
345         tooltips = gtk_tooltips_new();
346         gtk_tooltips_set_tip(tooltips, folder_color_btn,
347                              _("Pick color for folder"), NULL);
348
349         page->folder_color = item->prefs->color;
350
351         g_signal_connect(G_OBJECT(folder_color_btn), "clicked",
352                          G_CALLBACK(folder_color_set_dialog),
353                          page);
354
355         gtkut_set_widget_bgcolor_rgb(folder_color_btn, item->prefs->color);
356
357         folder_color_rec_checkbtn = gtk_check_button_new();
358         gtk_table_attach(GTK_TABLE(table), folder_color_rec_checkbtn, 3, 4, 
359                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
360
361         rowcount++;
362
363         /* Enable processing at startup */
364         checkbtn_enable_processing = gtk_check_button_new_with_label(_("Process at startup"));
365         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_processing, 0, 2, 
366                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
367
368         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_processing), 
369                                      item->prefs->enable_processing);
370
371         enable_processing_rec_checkbtn = gtk_check_button_new();
372         gtk_table_attach(GTK_TABLE(table), enable_processing_rec_checkbtn, 3, 4, 
373                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
374         
375         rowcount++;
376
377         /* Check folder for new mail */
378         checkbtn_newmailcheck = gtk_check_button_new_with_label(_("Scan for new mail"));
379         gtk_table_attach(GTK_TABLE(table), checkbtn_newmailcheck, 0, 2,
380                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
381         
382         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmailcheck),
383                                                                  item->prefs->newmailcheck);
384         newmailcheck_rec_checkbtn = gtk_check_button_new();
385         gtk_table_attach(GTK_TABLE(table), newmailcheck_rec_checkbtn, 3, 4, 
386                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
387
388         rowcount++;
389
390         /* Synchronise folder for offline use */
391         checkbtn_offlinesync = gtk_check_button_new_with_label(_("Synchronise for offline use"));
392         gtk_table_attach(GTK_TABLE(table), checkbtn_offlinesync, 0, 2,
393                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
394         
395         offlinesync_rec_checkbtn = gtk_check_button_new();
396         gtk_table_attach(GTK_TABLE(table), offlinesync_rec_checkbtn, 3, 4, 
397                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
398
399         if (item->folder && (item->folder->klass->type != F_IMAP && 
400             item->folder->klass->type != F_NEWS)) {
401                  item->prefs->offlinesync = TRUE;
402                 gtk_widget_set_sensitive(GTK_WIDGET(checkbtn_offlinesync),
403                                                                  FALSE);
404                 gtk_widget_set_sensitive(GTK_WIDGET(offlinesync_rec_checkbtn),
405                                                                  FALSE);
406         
407         }
408         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_offlinesync),
409                                                                  item->prefs->offlinesync);
410         rowcount++;
411
412         gtk_widget_show_all(table);
413
414         page->table = table;
415         page->folder_type = folder_type;
416         page->checkbtn_simplify_subject = checkbtn_simplify_subject;
417         page->entry_simplify_subject = entry_simplify_subject;
418         page->entry_regexp_test_string = entry_regexp_test_string;
419         page->entry_regexp_test_result = entry_regexp_test_result;
420         page->checkbtn_folder_chmod = checkbtn_folder_chmod;
421         page->entry_folder_chmod = entry_folder_chmod;
422         page->folder_color_btn = folder_color_btn;
423         page->checkbtn_enable_processing = checkbtn_enable_processing;
424         page->checkbtn_newmailcheck = checkbtn_newmailcheck;
425         page->checkbtn_offlinesync = checkbtn_offlinesync;
426
427         page->simplify_subject_rec_checkbtn  = simplify_subject_rec_checkbtn;
428         page->folder_chmod_rec_checkbtn      = folder_chmod_rec_checkbtn;
429         page->folder_color_rec_checkbtn      = folder_color_rec_checkbtn;
430         page->enable_processing_rec_checkbtn = enable_processing_rec_checkbtn;
431         page->newmailcheck_rec_checkbtn      = newmailcheck_rec_checkbtn;
432         page->offlinesync_rec_checkbtn       = offlinesync_rec_checkbtn;
433
434         page->page.widget = table;
435
436         folder_regexp_set_subject_example_cb(NULL, page);
437 }
438
439 void prefs_folder_item_general_destroy_widget_func(PrefsPage *page_) 
440 {
441         /* FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_; */
442 }
443
444 /** \brief  Save the prefs in page to folder.
445  *
446  *  If the folder is not the one  specified in page->item, then only those properties 
447  *  that have the relevant 'apply to sub folders' button checked are saved
448  */
449 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page)
450 {
451         FolderItemPrefs *prefs = folder->prefs;
452         gchar *buf;
453         gboolean all = FALSE;
454         SpecialFolderItemType type = F_NORMAL;
455         GtkWidget *menu;
456         GtkWidget *menuitem;
457
458         if (folder->path == NULL)
459                 return;
460
461         g_return_if_fail(prefs != NULL);
462
463         if (page->item == folder) 
464                 all = TRUE;
465
466         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->folder_type));
467         menuitem = gtk_menu_get_active(GTK_MENU(menu));
468         type = GPOINTER_TO_INT
469                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
470         if (all && folder->stype != type) {
471                 folder_item_change_type(folder, type);
472         }
473
474         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn))) {
475                 prefs->enable_simplify_subject =
476                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
477                 ASSIGN_STRING(prefs->simplify_subject_regexp,
478                               gtk_editable_get_chars(GTK_EDITABLE(page->entry_simplify_subject), 0, -1));
479         }
480         
481         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn))) {
482                 prefs->enable_folder_chmod = 
483                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_folder_chmod));
484                 buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_folder_chmod), 0, -1);
485                 prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
486                 g_free(buf);
487         }
488
489         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn))) {
490                 int old_color = prefs->color;
491                 prefs->color = page->folder_color;
492         
493                 /* update folder view */
494                 if (prefs->color != old_color)
495                         folder_item_update(folder, F_ITEM_UPDATE_MSGCNT);
496         }
497
498         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn))) {
499                 prefs->enable_processing = 
500                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_processing));
501         }
502
503         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn))) {
504                 prefs->newmailcheck = 
505                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_newmailcheck));
506         }
507
508         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))) {
509                 prefs->offlinesync = 
510                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_offlinesync));
511         }
512
513         folder_item_prefs_save_config(folder);
514 }       
515
516 static gboolean general_save_recurse_func(GNode *node, gpointer data)
517 {
518         FolderItem *item = (FolderItem *) node->data;
519         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
520
521         g_return_val_if_fail(item != NULL, TRUE);
522         g_return_val_if_fail(page != NULL, TRUE);
523
524         general_save_folder_prefs(item, page);
525
526         /* optimise by not continuing if none of the 'apply to sub folders'
527            check boxes are selected - and optimise the checking by only doing
528            it once */
529         if ((node == page->item->node) &&
530             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn)) ||
531               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn)) ||
532               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn)) ||
533               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn)) ||
534               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn)) ||
535               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))))
536                 return TRUE;
537         else 
538                 return FALSE;
539 }
540
541 void prefs_folder_item_general_save_func(PrefsPage *page_) 
542 {
543         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
544
545         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
546                         -1, general_save_recurse_func, page);
547
548 }
549
550 static RecvProtocol item_protocol(FolderItem *item)
551 {
552         if (!item)
553                 return A_NONE;
554         if (!item->folder)
555                 return A_NONE;
556         if (!item->folder->account)
557                 return A_NONE;
558         return item->folder->account->protocol;
559 }
560 void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
561                                                    GtkWindow * window,
562                                                    gpointer data)
563 {
564         FolderItemComposePage *page = (FolderItemComposePage *) page_;
565         FolderItem *item = (FolderItem *) data;
566         guint rowcount;
567
568         GtkWidget *table;
569         GtkWidget *label;
570         
571         GtkWidget *checkbtn_request_return_receipt = NULL;
572         GtkWidget *checkbtn_save_copy_to_folder = NULL;
573         GtkWidget *checkbtn_default_to = NULL;
574         GtkWidget *entry_default_to = NULL;
575         GtkWidget *checkbtn_default_reply_to = NULL;
576         GtkWidget *entry_default_reply_to = NULL;
577         GtkWidget *checkbtn_enable_default_account = NULL;
578         GtkWidget *optmenu_default_account = NULL;
579         GtkWidget *optmenu_default_account_menu = NULL;
580         GtkWidget *optmenu_default_account_menuitem = NULL;
581 #if USE_ASPELL
582         GtkWidget *checkbtn_enable_default_dictionary = NULL;
583         GtkWidget *optmenu_default_dictionary = NULL;
584 #endif
585         GtkWidget *request_return_receipt_rec_checkbtn = NULL;
586         GtkWidget *save_copy_to_folder_rec_checkbtn = NULL;
587         GtkWidget *default_to_rec_checkbtn = NULL;
588         GtkWidget *default_reply_to_rec_checkbtn = NULL;
589         GtkWidget *default_account_rec_checkbtn = NULL;
590 #if USE_ASPELL
591         GtkWidget *default_dictionary_rec_checkbtn = NULL;
592 #endif
593
594         GList *cur_ac;
595         GList *account_list;
596 #if USE_ASPELL
597         gchar *dictionary;
598 #endif
599         PrefsAccount *ac_prefs;
600         GtkOptionMenu *optmenu;
601         GtkWidget *menu;
602         GtkWidget *menuitem;
603         gint account_index, index;
604
605         page->item         = item;
606
607         /* Table */
608 #if USE_ASPELL
609 # define TABLEHEIGHT 6
610 #else
611 # define TABLEHEIGHT 5
612 #endif
613         table = gtk_table_new(TABLEHEIGHT, 2, FALSE);
614         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
615         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
616         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
617         rowcount = 0;
618
619         /* Apply to subfolders */
620         label = gtk_label_new(_("Apply to\nsubfolders"));
621         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
622         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
623                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
624         rowcount++;
625
626         if (item_protocol(item) != A_NNTP) {
627                 /* Request Return Receipt */
628                 checkbtn_request_return_receipt = gtk_check_button_new_with_label
629                         (_("Request Return Receipt"));
630                 gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
631                                  0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
632                                  GTK_FILL, 0, 0);
633                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
634                                              item->ret_rcpt ? TRUE : FALSE);
635
636                 request_return_receipt_rec_checkbtn = gtk_check_button_new();
637                 gtk_table_attach(GTK_TABLE(table), request_return_receipt_rec_checkbtn, 2, 3, 
638                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
639
640                 rowcount++;
641
642                 /* Save Copy to Folder */
643                 checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
644                         (_("Save copy of outgoing messages to this folder instead of Sent"));
645                 gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
646                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
647                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
648                                              item->prefs->save_copy_to_folder ? TRUE : FALSE);
649
650                 save_copy_to_folder_rec_checkbtn = gtk_check_button_new();
651                 gtk_table_attach(GTK_TABLE(table), save_copy_to_folder_rec_checkbtn, 2, 3, 
652                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
653
654                 rowcount++;
655
656                 /* Default To */
657                 checkbtn_default_to = gtk_check_button_new_with_label(_("Default To: "));
658                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
659                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
660                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
661                                              item->prefs->enable_default_to);
662
663                 entry_default_to = gtk_entry_new();
664                 gtk_table_attach(GTK_TABLE(table), entry_default_to, 1, 2,
665                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
666                 SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
667                 gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
668                 address_completion_register_entry(GTK_ENTRY(entry_default_to),
669                                 TRUE);
670
671                 default_to_rec_checkbtn = gtk_check_button_new();
672                 gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3, 
673                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
674
675                 rowcount++;
676
677                 /* Default address to reply to */
678                 checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Default To for replies: "));
679                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
680                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
681                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
682                                              item->prefs->enable_default_reply_to);
683
684                 entry_default_reply_to = gtk_entry_new();
685                 gtk_table_attach(GTK_TABLE(table), entry_default_reply_to, 1, 2,
686                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
687                 SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
688                 gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
689                 address_completion_register_entry(
690                                 GTK_ENTRY(entry_default_reply_to), TRUE);
691
692                 default_reply_to_rec_checkbtn = gtk_check_button_new();
693                 gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3, 
694                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
695
696                 rowcount++;
697         }
698         /* Default account */
699         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account: "));
700         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
701                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
702         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
703                                      item->prefs->enable_default_account);
704
705         optmenu_default_account = gtk_option_menu_new ();
706         gtk_table_attach(GTK_TABLE(table), optmenu_default_account, 1, 2, 
707                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
708         optmenu_default_account_menu = gtk_menu_new ();
709
710         account_list = account_get_list();
711         account_index = 0;
712         index = 0;
713         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
714                 ac_prefs = (PrefsAccount *)cur_ac->data;
715                 if (item->folder->account &&
716                     ( (item_protocol(item) == A_NNTP && ac_prefs->protocol != A_NNTP)
717                     ||(item_protocol(item) != A_NNTP && ac_prefs->protocol == A_NNTP))) 
718                         continue;
719
720                 if (item->folder->klass->type != F_NEWS && ac_prefs->protocol == A_NNTP)
721                         continue;
722
723                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
724                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
725                                         ac_prefs->account_id);
726                 /* get the index for menu's set_history (sad method?) */
727                 if (ac_prefs->account_id == item->prefs->default_account)
728                         account_index = index;
729                 index++;                        
730         }
731
732         optmenu = GTK_OPTION_MENU(optmenu_default_account);
733         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
734
735         gtk_option_menu_set_history(optmenu, account_index);
736
737         menu = gtk_option_menu_get_menu(optmenu);
738         menuitem = gtk_menu_get_active(GTK_MENU(menu));
739         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
740
741         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
742
743         default_account_rec_checkbtn = gtk_check_button_new();
744         gtk_table_attach(GTK_TABLE(table), default_account_rec_checkbtn, 2, 3, 
745                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
746         rowcount++;
747
748 #if USE_ASPELL
749         /* Default dictionary */
750         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary: "));
751         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_dictionary, 0, 1,
752                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
753         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
754                                      item->prefs->enable_default_dictionary);
755
756         optmenu_default_dictionary = gtk_option_menu_new();
757         gtk_table_attach(GTK_TABLE(table), optmenu_default_dictionary, 1, 2,
758                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
759
760         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_dictionary), 
761                                  gtkaspell_dictionary_option_menu_new(
762                                          prefs_common.aspell_path));
763
764         dictionary = item->prefs->default_dictionary;
765
766         optmenu = GTK_OPTION_MENU(optmenu_default_dictionary);
767
768         menu = gtk_option_menu_get_menu(optmenu);
769         if (dictionary)
770                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_dictionary, dictionary);
771         menuitem = gtk_menu_get_active(GTK_MENU(menu));
772         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
773
774         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, optmenu_default_dictionary);
775
776         default_dictionary_rec_checkbtn = gtk_check_button_new();
777         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
778                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
779         
780         rowcount++;
781 #endif
782
783         gtk_widget_show_all(table);
784
785         page->window = GTK_WIDGET(window);
786         page->table = table;
787         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
788         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
789         page->checkbtn_default_to = checkbtn_default_to;
790         page->entry_default_to = entry_default_to;
791         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
792         page->entry_default_reply_to = entry_default_reply_to;
793         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
794         page->optmenu_default_account = optmenu_default_account;
795 #ifdef USE_ASPELL
796         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
797         page->optmenu_default_dictionary = optmenu_default_dictionary;
798 #endif
799
800         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
801         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
802         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
803         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
804         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
805 #if USE_ASPELL
806         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
807 #endif
808
809         address_completion_start(page->window);
810
811         page->page.widget = table;
812 }
813
814 void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
815 {
816         FolderItemComposePage *page = (FolderItemComposePage *) page_;
817
818         if (page->entry_default_to)
819                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
820         if (page->entry_default_reply_to)
821                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
822         address_completion_end(page->window);
823 }
824
825 /** \brief  Save the prefs in page to folder.
826  *
827  *  If the folder is not the one  specified in page->item, then only those properties 
828  *  that have the relevant 'apply to sub folders' button checked are saved
829  */
830 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
831 {
832         FolderItemPrefs *prefs = folder->prefs;
833         GtkWidget *menu;
834         GtkWidget *menuitem;
835         gboolean all = FALSE;
836
837         if (folder->path == NULL)
838                 return;
839
840         if (page->item == folder) 
841                 all = TRUE;
842
843         g_return_if_fail(prefs != NULL);
844
845         if (item_protocol(folder) != A_NNTP) {
846                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
847                         prefs->request_return_receipt = 
848                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
849                         /* MIGRATION */    
850                         folder->ret_rcpt = prefs->request_return_receipt;
851                 }
852
853                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
854                         prefs->save_copy_to_folder = 
855                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
856                 }
857
858                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
859
860                         prefs->enable_default_to = 
861                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
862                         ASSIGN_STRING(prefs->default_to,
863                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
864                 }
865
866                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
867                         prefs->enable_default_reply_to = 
868                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
869                         ASSIGN_STRING(prefs->default_reply_to,
870                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
871                 }
872         } else {
873                 prefs->request_return_receipt = FALSE;
874                 prefs->save_copy_to_folder = FALSE;
875                 prefs->enable_default_to = FALSE;
876                 prefs->enable_default_reply_to = FALSE;
877         }
878         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
879                 prefs->enable_default_account = 
880                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
881                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_account));
882                 menuitem = gtk_menu_get_active(GTK_MENU(menu));
883                 prefs->default_account = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
884         }
885
886 #if USE_ASPELL
887         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
888                 prefs->enable_default_dictionary =
889                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
890                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_dictionary));
891                 ASSIGN_STRING(prefs->default_dictionary,
892                               gtkaspell_get_dictionary_menu_active_item(menu));
893         }
894 #endif
895
896         folder_item_prefs_save_config(folder);
897 }       
898
899 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
900 {
901         FolderItem *item = (FolderItem *) node->data;
902         FolderItemComposePage *page = (FolderItemComposePage *) data;
903
904         g_return_val_if_fail(item != NULL, TRUE);
905         g_return_val_if_fail(page != NULL, TRUE);
906
907         compose_save_folder_prefs(item, page);
908
909         /* optimise by not continuing if none of the 'apply to sub folders'
910            check boxes are selected - and optimise the checking by only doing
911            it once */
912         if ((node == page->item->node) && item_protocol(item) != A_NNTP &&
913             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
914               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
915               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
916               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) ||
917 #if USE_ASPELL
918               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn)) ||
919 #endif
920               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))))
921                 return TRUE;
922
923         if ((node == page->item->node) &&
924             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
925 #if USE_ASPELL
926               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
927 #endif
928                     ))
929                 return TRUE;
930         else 
931                 return FALSE;
932 }
933
934 void prefs_folder_item_compose_save_func(PrefsPage *page_) 
935 {
936         FolderItemComposePage *page = (FolderItemComposePage *) page_;
937
938         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
939                         -1, compose_save_recurse_func, page);
940
941 }
942
943 gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
944 {
945         gint newmode = 0;
946         gchar *tmp;
947
948         if (folder_chmod) {
949                 newmode = strtol(folder_chmod, &tmp, 8);
950                 if (!(*(folder_chmod) && !(*tmp)))
951                         newmode = 0;
952         }
953
954         return newmode;
955 }
956
957 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
958 {
959         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
960         gint rgbcolor;
961
962         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
963                                              page->folder_color);
964         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
965         page->folder_color = rgbcolor;
966 }
967
968 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
969 {
970         int err;
971         gchar buf[BUFFSIZE];
972         regex_t *preg = NULL;
973
974         preg = g_new0(regex_t, 1);
975
976         err = string_match_precompile(simplify_subject_regexp, 
977                                       preg, REG_EXTENDED);
978         if (err) {
979                 regerror(err, preg, buf, BUFFSIZE);
980                 g_free(preg);
981                 preg = NULL;
982         }
983
984         return preg;
985 }
986
987 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data)
988 {
989         static GdkColor red;
990         static gboolean colors_initialised = FALSE;
991         static gchar buf[BUFFSIZE];
992         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
993         gchar *test_string, *regexp;
994         regex_t *preg;
995
996         regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_simplify_subject)));
997         test_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_regexp_test_string)));
998
999         if (!regexp || !regexp[0]) {
1000                 if (test_string) {
1001                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), test_string);
1002                         g_free(test_string);
1003                 }
1004                 return;
1005         }
1006
1007         if (!test_string || !test_string[0]) {
1008                 g_free(regexp);
1009                 return;
1010         }
1011
1012         if (!colors_initialised) {
1013                 gdk_color_parse("#ff7070", &red);
1014                 colors_initialised = gdk_colormap_alloc_color(
1015                         gdk_colormap_get_system(), &red, FALSE, TRUE);
1016         }
1017
1018         preg = summary_compile_simplify_regexp(regexp);
1019         if (colors_initialised) {
1020                 gtk_widget_modify_base(page->entry_simplify_subject,
1021                                 GTK_STATE_NORMAL, preg ? NULL : &red);
1022         }
1023
1024         if (preg != NULL) {
1025                 string_remove_match(buf, BUFFSIZE, test_string, preg);
1026
1027                 gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), buf);
1028
1029                 regfree(preg);
1030                 g_free(preg);
1031         }
1032
1033         g_free(test_string);
1034         g_free(regexp);
1035 }
1036
1037 static gchar *folder_regexp_get_subject_example(void)
1038 {
1039         MsgInfo *msginfo_selected;
1040         SummaryView *summaryview = NULL;
1041
1042         if (!mainwindow_get_mainwindow())
1043                 return NULL;
1044         summaryview = mainwindow_get_mainwindow()->summaryview;
1045
1046         msginfo_selected = summary_get_selected_msg(summaryview);
1047         return msginfo_selected ? g_strdup(msginfo_selected->subject) : NULL;
1048 }
1049
1050 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data)
1051 {
1052         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1053
1054         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject))) {
1055                 gchar *subject = folder_regexp_get_subject_example();
1056                 if (subject) {
1057                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_string), subject);
1058                         g_free(subject);
1059                 }
1060         }
1061 }
1062
1063 static void register_general_page()
1064 {
1065         static gchar *pfi_general_path[2];
1066         static FolderItemGeneralPage folder_item_general_page;
1067
1068         pfi_general_path[0] = _("General");
1069         pfi_general_path[1] = NULL;
1070
1071         folder_item_general_page.page.path = pfi_general_path;
1072         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
1073         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
1074         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
1075         
1076         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
1077 }
1078
1079
1080 static void register_compose_page(void)
1081 {
1082         static gchar *pfi_compose_path[2];
1083         static FolderItemComposePage folder_item_compose_page;
1084
1085         pfi_compose_path[0] = _("Compose");
1086         pfi_compose_path[1] = NULL;
1087
1088         folder_item_compose_page.page.path = pfi_compose_path;
1089         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
1090         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
1091         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
1092         
1093         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
1094 }
1095
1096 static GSList *prefs_pages = NULL;
1097
1098 void prefs_folder_item_open(FolderItem *item)
1099 {
1100         gchar *id, *title;
1101
1102         if (prefs_pages == NULL) {
1103                 register_general_page();
1104                 register_compose_page();
1105         }
1106
1107         if (item->path)
1108                 id = folder_item_get_identifier (item);
1109         else 
1110                 id = g_strdup(item->name);
1111         title = g_strdup_printf (_("Properties for folder %s"), id);
1112         g_free (id);
1113         prefswindow_open(title, prefs_pages, item,
1114                         &prefs_common.folderitemwin_width, &prefs_common.folderitemwin_height);
1115         g_free (title);
1116 }
1117
1118 void prefs_folder_item_register_page(PrefsPage *page)
1119 {
1120         prefs_pages = g_slist_append(prefs_pages, page);
1121 }
1122
1123 void prefs_folder_item_unregister_page(PrefsPage *page)
1124 {
1125         prefs_pages = g_slist_remove(prefs_pages, page);
1126 }