ca660e264c27465a46a4de0bbcb17f8a1f64f294
[claws.git] / src / prefs_folder_item.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 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 /* 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 #include "quote_fmt.h"
50 #include "combobox.h"
51
52 #if USE_ASPELL
53 #include "gtkaspell.h"
54 #endif
55
56 #define ASSIGN_STRING(string, value) \
57         { \
58                 g_free(string); \
59                 string = (value); \
60         }
61
62 typedef struct _FolderItemGeneralPage FolderItemGeneralPage;
63 typedef struct _FolderItemComposePage FolderItemComposePage;
64 typedef struct _FolderItemTemplatesPage FolderItemTemplatesPage;
65 static gboolean can_save = TRUE;
66
67 struct _FolderItemGeneralPage
68 {
69         PrefsPage page;
70
71         FolderItem *item;
72
73         GtkWidget *table;
74         GtkWidget *no_save_warning;
75         GtkWidget *folder_type;
76         GtkWidget *checkbtn_simplify_subject;
77         GtkWidget *entry_simplify_subject;
78         GtkWidget *entry_regexp_test_string;
79         GtkWidget *entry_regexp_test_result;
80         GtkWidget *checkbtn_folder_chmod;
81         GtkWidget *entry_folder_chmod;
82         GtkWidget *folder_color_btn;
83         GtkWidget *checkbtn_enable_processing;
84         GtkWidget *checkbtn_newmailcheck;
85         GtkWidget *checkbtn_offlinesync;
86         GtkWidget *label_offlinesync;
87         GtkWidget *entry_offlinesync;
88         GtkWidget *label_end_offlinesync;
89         GtkWidget *checkbtn_remove_old_offlinesync;
90         
91         /* apply to sub folders */
92         GtkWidget *simplify_subject_rec_checkbtn;
93         GtkWidget *folder_chmod_rec_checkbtn;
94         GtkWidget *folder_color_rec_checkbtn;
95         GtkWidget *enable_processing_rec_checkbtn;
96         GtkWidget *newmailcheck_rec_checkbtn;
97         GtkWidget *offlinesync_rec_checkbtn;
98
99         gint       folder_color;
100 };
101
102 struct _FolderItemComposePage
103 {
104         PrefsPage page;
105
106         FolderItem *item;
107
108         GtkWidget *window;
109         GtkWidget *table;
110         GtkWidget *no_save_warning;
111         GtkWidget *checkbtn_request_return_receipt;
112         GtkWidget *checkbtn_save_copy_to_folder;
113         GtkWidget *checkbtn_default_to;
114         GtkWidget *entry_default_to;
115         GtkWidget *checkbtn_default_reply_to;
116         GtkWidget *entry_default_reply_to;
117         GtkWidget *checkbtn_enable_default_account;
118         GtkWidget *optmenu_default_account;
119 #if USE_ASPELL
120         GtkWidget *checkbtn_enable_default_dictionary;
121         GtkWidget *checkbtn_enable_default_alt_dictionary;
122         GtkWidget *optmenu_default_dictionary;
123         GtkWidget *optmenu_default_alt_dictionary;
124 #endif
125
126         /* apply to sub folders */
127         GtkWidget *request_return_receipt_rec_checkbtn;
128         GtkWidget *save_copy_to_folder_rec_checkbtn;
129         GtkWidget *default_to_rec_checkbtn;
130         GtkWidget *default_reply_to_rec_checkbtn;
131         GtkWidget *default_account_rec_checkbtn;
132 #if USE_ASPELL
133         GtkWidget *default_dictionary_rec_checkbtn;
134         GtkWidget *default_alt_dictionary_rec_checkbtn;
135 #endif
136 };
137
138 struct _FolderItemTemplatesPage
139 {
140         PrefsPage page;
141
142         FolderItem *item;
143
144         GtkWidget *window;
145         GtkWidget *table;
146         GtkWidget *checkbtn_compose_with_format;
147         GtkWidget *compose_subject_format;
148         GtkWidget *compose_body_format;
149         GtkWidget *checkbtn_reply_with_format;
150         GtkWidget *reply_quotemark;
151         GtkWidget *reply_body_format;
152         GtkWidget *checkbtn_forward_with_format;
153         GtkWidget *forward_quotemark;
154         GtkWidget *forward_body_format;
155
156         /* apply to sub folders */
157         GtkWidget *new_msg_format_rec_checkbtn;
158         GtkWidget *reply_format_rec_checkbtn;
159         GtkWidget *forward_format_rec_checkbtn;
160 };
161
162
163 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page);
164 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page);
165 static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesPage *page);
166
167 static gboolean general_save_recurse_func(GNode *node, gpointer data);
168 static gboolean compose_save_recurse_func(GNode *node, gpointer data);
169 static gboolean templates_save_recurse_func(GNode *node, gpointer data);
170
171 static gint prefs_folder_item_chmod_mode                (gchar *folder_chmod);
172
173 static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
174 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data);
175 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data);
176
177 #define SAFE_STRING(str) \
178         (str) ? (str) : ""
179
180 static void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
181                                                    GtkWindow * window,
182                                                    gpointer data)
183 {
184         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
185         FolderItem *item = (FolderItem *) data;
186         guint rowcount;
187
188         GtkWidget *table;
189         GtkWidget *hbox, *hbox2, *hbox_spc;
190         GtkWidget *label;
191         
192         GtkListStore *folder_type_menu;
193         GtkWidget *folder_type;
194         GtkTreeIter iter;
195         GtkWidget *dummy_checkbtn;
196         SpecialFolderItemType type;
197         
198         GtkWidget *no_save_warning = NULL;
199         GtkWidget *checkbtn_simplify_subject;
200         GtkWidget *entry_simplify_subject;
201         GtkWidget *hbox_regexp;
202         GtkWidget *label_regexp_test;
203         GtkWidget *entry_regexp_test_string;
204         GtkWidget *left_arrow;
205         GtkWidget *entry_regexp_test_result;
206
207         GtkWidget *checkbtn_folder_chmod;
208         GtkWidget *entry_folder_chmod;
209         GtkWidget *folder_color;
210         GtkWidget *folder_color_btn;
211         GtkWidget *checkbtn_enable_processing;
212         GtkWidget *checkbtn_newmailcheck;
213         GtkWidget *checkbtn_offlinesync;
214         GtkWidget *label_offlinesync;
215         GtkWidget *entry_offlinesync;
216         GtkWidget *label_end_offlinesync;
217         GtkWidget *checkbtn_remove_old_offlinesync;
218
219         GtkWidget *simplify_subject_rec_checkbtn;
220         GtkWidget *folder_chmod_rec_checkbtn;
221         GtkWidget *folder_color_rec_checkbtn;
222         GtkWidget *enable_processing_rec_checkbtn;
223         GtkWidget *newmailcheck_rec_checkbtn;
224         GtkWidget *offlinesync_rec_checkbtn;
225         GtkTooltips *tooltips;
226
227         tooltips = gtk_tooltips_new();
228         page->item         = item;
229
230         /* Table */
231         table = gtk_table_new(9, 4, FALSE);
232         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
233         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
234         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
235         rowcount = 0;
236
237         if (!can_save) {
238                 no_save_warning = gtk_label_new(
239                         _("<i>These preferences will not be saved as this folder "
240                         "is a top-level one. However you can use them to set them "
241                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
242                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
243                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
244                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
245                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 4,
246                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
247                 rowcount++;
248         }
249         
250         /* Apply to subfolders */
251         label = gtk_label_new(_("Apply to\nsubfolders"));
252         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
253         gtk_table_attach(GTK_TABLE(table), label, 3, 4,
254                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
255         rowcount++;
256
257         /* folder_type */
258         folder_type = gtkut_sc_combobox_create(NULL, FALSE);
259         gtk_widget_show (folder_type);
260
261         type = F_NORMAL;
262         if (item->stype == F_INBOX)
263                 type = F_INBOX;
264         else if (folder_has_parent_of_type(item, F_OUTBOX))
265                 type = F_OUTBOX;
266         else if (folder_has_parent_of_type(item, F_DRAFT))
267                 type = F_DRAFT;
268         else if (folder_has_parent_of_type(item, F_QUEUE))
269                 type = F_QUEUE;
270         else if (folder_has_parent_of_type(item, F_TRASH))
271                 type = F_TRASH;
272
273         folder_type_menu = GTK_LIST_STORE(gtk_combo_box_get_model(
274                                 GTK_COMBO_BOX(folder_type)));
275
276         COMBOBOX_ADD (folder_type_menu, _("Normal"),  F_NORMAL);
277         COMBOBOX_ADD (folder_type_menu, _("Inbox"),  F_INBOX);
278         COMBOBOX_ADD (folder_type_menu, _("Outbox"),  F_OUTBOX);
279         COMBOBOX_ADD (folder_type_menu, _("Drafts"),  F_DRAFT);
280         COMBOBOX_ADD (folder_type_menu, _("Queue"),  F_QUEUE);
281         COMBOBOX_ADD (folder_type_menu, _("Trash"),  F_TRASH);
282
283         combobox_select_by_data(GTK_COMBO_BOX(folder_type), type);
284
285         dummy_checkbtn = gtk_check_button_new();
286         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy_checkbtn), type != F_INBOX);
287         gtk_widget_set_sensitive(dummy_checkbtn, FALSE);
288
289         if (type == item->stype && type == F_NORMAL)
290                 gtk_widget_set_sensitive(folder_type, TRUE);
291         else
292                 gtk_widget_set_sensitive(folder_type, FALSE);
293
294         label = gtk_label_new(_("Folder type"));
295         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
296         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 
297                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
298         gtk_table_attach(GTK_TABLE(table), folder_type, 1, 2, 
299                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
300         gtk_table_attach(GTK_TABLE(table), dummy_checkbtn, 3, 4, 
301                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
302
303         rowcount++;
304
305         /* Simplify Subject */
306         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp"));
307         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
308                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
309         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
310                                      item->prefs->enable_simplify_subject);
311
312         g_signal_connect(G_OBJECT(checkbtn_simplify_subject), "toggled",
313                         G_CALLBACK(folder_regexp_set_subject_example_cb), page);
314
315         entry_simplify_subject = gtk_entry_new();
316         gtk_table_attach(GTK_TABLE(table), entry_simplify_subject, 1, 3, 
317                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
318         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
319         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
320                            SAFE_STRING(item->prefs->simplify_subject_regexp));
321
322         g_signal_connect(G_OBJECT(entry_simplify_subject), "changed",
323                         G_CALLBACK(folder_regexp_test_cb), page);
324
325         simplify_subject_rec_checkbtn = gtk_check_button_new();
326         gtk_table_attach(GTK_TABLE(table), simplify_subject_rec_checkbtn, 3, 4, 
327                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
328
329         rowcount++;
330
331         /* Test RegExp */
332         label_regexp_test = gtk_label_new(_("Test RegExp"));
333         gtk_misc_set_alignment(GTK_MISC(label_regexp_test), 0, 0.5);
334         gtk_table_attach(GTK_TABLE(table), label_regexp_test, 0, 1, 
335                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
336         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, label_regexp_test);
337
338         entry_regexp_test_string = gtk_entry_new();
339         gtk_table_attach(GTK_TABLE(table), entry_regexp_test_string, 1, 2, 
340                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
341         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_string);
342
343         g_signal_connect(G_OBJECT(entry_regexp_test_string), "changed",
344                         G_CALLBACK(folder_regexp_test_cb), page);
345
346         hbox_regexp = gtk_hbox_new (FALSE, 4);
347         gtk_widget_show (hbox_regexp);
348         gtk_table_attach(GTK_TABLE(table), hbox_regexp, 2, 3, 
349                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
350
351         left_arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
352         gtk_widget_show(left_arrow);
353         gtk_box_pack_start (GTK_BOX(hbox_regexp), left_arrow, FALSE, FALSE, 0);
354         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, left_arrow);
355
356         entry_regexp_test_result = gtk_entry_new();
357         gtk_box_pack_end (GTK_BOX(hbox_regexp), entry_regexp_test_result, TRUE, TRUE, 0);
358         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_result);
359         gtk_entry_set_editable(GTK_ENTRY(entry_regexp_test_result), FALSE);
360
361         rowcount++;
362
363         /* Folder chmod */
364         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod"));
365         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
366                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
367
368         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
369                                      item->prefs->enable_folder_chmod);
370
371         entry_folder_chmod = gtk_entry_new();
372         gtk_table_attach(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
373                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
374         SET_TOGGLE_SENSITIVITY(checkbtn_folder_chmod, entry_folder_chmod);
375         if (item->prefs->folder_chmod) {
376                 gchar *buf;
377
378                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
379                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
380                 g_free(buf);
381         }
382         
383         folder_chmod_rec_checkbtn = gtk_check_button_new();
384         gtk_table_attach(GTK_TABLE(table), folder_chmod_rec_checkbtn, 3, 4, 
385                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
386
387         rowcount++;
388         
389         /* Folder color */
390         folder_color = gtk_label_new(_("Folder color"));
391         gtk_misc_set_alignment(GTK_MISC(folder_color), 0, 0.5);
392         gtk_table_attach(GTK_TABLE(table), folder_color, 0, 1, 
393                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
394
395         hbox = gtk_hbox_new(FALSE, 0);
396         gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 
397                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
398
399         folder_color_btn = gtk_button_new_with_label("");
400         gtk_widget_set_size_request(folder_color_btn, 36, 26);
401         gtk_box_pack_start (GTK_BOX(hbox), folder_color_btn, FALSE, FALSE, 0);
402         gtk_tooltips_set_tip(tooltips, folder_color_btn,
403                              _("Pick color for folder"), NULL);
404
405         page->folder_color = item->prefs->color;
406
407         g_signal_connect(G_OBJECT(folder_color_btn), "clicked",
408                          G_CALLBACK(folder_color_set_dialog),
409                          page);
410
411         gtkut_set_widget_bgcolor_rgb(folder_color_btn, item->prefs->color);
412
413         folder_color_rec_checkbtn = gtk_check_button_new();
414         gtk_table_attach(GTK_TABLE(table), folder_color_rec_checkbtn, 3, 4, 
415                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
416
417         rowcount++;
418
419         /* Enable processing at startup */
420         checkbtn_enable_processing = gtk_check_button_new_with_label(_("Process at start-up"));
421         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_processing, 0, 2, 
422                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
423
424         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_processing), 
425                                      item->prefs->enable_processing);
426
427         enable_processing_rec_checkbtn = gtk_check_button_new();
428         gtk_table_attach(GTK_TABLE(table), enable_processing_rec_checkbtn, 3, 4, 
429                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
430         
431         rowcount++;
432
433         /* Check folder for new mail */
434         checkbtn_newmailcheck = gtk_check_button_new_with_label(_("Scan for new mail"));
435         gtk_tooltips_set_tip(tooltips, checkbtn_newmailcheck,
436                              _("Turn this option on if mail is delivered directly "
437                                "to this folder by server side filtering on IMAP or "
438                                "by an external application"), NULL);
439         gtk_table_attach(GTK_TABLE(table), checkbtn_newmailcheck, 0, 2,
440                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
441         
442         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmailcheck),
443                                                                  item->prefs->newmailcheck);
444         newmailcheck_rec_checkbtn = gtk_check_button_new();
445         gtk_table_attach(GTK_TABLE(table), newmailcheck_rec_checkbtn, 3, 4, 
446                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
447
448         rowcount++;
449
450         /* Synchronise folder for offline use */
451         checkbtn_offlinesync = gtk_check_button_new_with_label(_("Synchronise for offline use"));
452         gtk_table_attach(GTK_TABLE(table), checkbtn_offlinesync, 0, 2,
453                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
454         
455         offlinesync_rec_checkbtn = gtk_check_button_new();
456         gtk_table_attach(GTK_TABLE(table), offlinesync_rec_checkbtn, 3, 4, 
457                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
458
459         rowcount++;
460
461         hbox = gtk_hbox_new (FALSE, 8);
462         gtk_widget_show (hbox);
463         gtk_table_attach(GTK_TABLE(table), hbox, 0, 4,
464                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
465         rowcount++;
466
467         hbox_spc = gtk_hbox_new (FALSE, 0);
468         gtk_widget_show (hbox_spc);
469         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
470         gtk_widget_set_size_request (hbox_spc, 12, -1);
471
472         label_offlinesync = gtk_label_new(_("Fetch message bodies from the last"));
473         gtk_widget_show (label_offlinesync);
474         gtk_box_pack_start (GTK_BOX (hbox), label_offlinesync, FALSE, FALSE, 0);
475
476         entry_offlinesync = gtk_entry_new();
477         gtk_widget_set_size_request (entry_offlinesync, 64, -1);
478         gtk_widget_show (entry_offlinesync);
479         gtk_tooltips_set_tip(tooltips, entry_offlinesync, _("0: all bodies"), NULL);
480         gtk_box_pack_start (GTK_BOX (hbox), entry_offlinesync, FALSE, FALSE, 0);
481
482         label_end_offlinesync = gtk_label_new(_("days"));
483         gtk_widget_show (label_end_offlinesync);
484         gtk_box_pack_start (GTK_BOX (hbox), label_end_offlinesync, FALSE, FALSE, 0);
485
486         checkbtn_remove_old_offlinesync = gtk_check_button_new_with_label(
487                                                 _("Remove older messages bodies"));
488
489         hbox2 = gtk_hbox_new (FALSE, 8);
490         gtk_widget_show (hbox2);
491         gtk_table_attach(GTK_TABLE(table), hbox2, 0, 4,
492                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
493         rowcount++;
494
495         hbox_spc = gtk_hbox_new (FALSE, 0);
496         gtk_widget_show (hbox_spc);
497         gtk_box_pack_start (GTK_BOX (hbox2), hbox_spc, FALSE, FALSE, 0);
498         gtk_widget_set_size_request (hbox_spc, 12, -1);
499         gtk_box_pack_start (GTK_BOX (hbox2), checkbtn_remove_old_offlinesync, FALSE, FALSE, 0);
500
501         SET_TOGGLE_SENSITIVITY (checkbtn_offlinesync, hbox);
502         SET_TOGGLE_SENSITIVITY (checkbtn_offlinesync, hbox2);
503         
504         gtk_widget_show_all(table);
505
506         if (item->folder && (item->folder->klass->type != F_IMAP && 
507             item->folder->klass->type != F_NEWS)) {
508                 item->prefs->offlinesync = TRUE;
509                 item->prefs->offlinesync_days = 0;
510                 item->prefs->remove_old_bodies = FALSE;
511
512                 gtk_widget_set_sensitive(GTK_WIDGET(checkbtn_offlinesync),
513                                                                  FALSE);
514                 gtk_widget_set_sensitive(GTK_WIDGET(offlinesync_rec_checkbtn),
515                                                                  FALSE);
516                 gtk_widget_hide(GTK_WIDGET(checkbtn_offlinesync));
517                 gtk_widget_hide(GTK_WIDGET(hbox));
518                 gtk_widget_hide(GTK_WIDGET(hbox2));
519                 gtk_widget_hide(GTK_WIDGET(offlinesync_rec_checkbtn));
520         
521         }
522         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_offlinesync),
523                                                                  item->prefs->offlinesync);
524         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_remove_old_offlinesync),
525                                                                  item->prefs->remove_old_bodies);
526         gtk_entry_set_text(GTK_ENTRY(entry_offlinesync), itos(item->prefs->offlinesync_days));
527
528         page->table = table;
529         page->folder_type = folder_type;
530         page->no_save_warning = no_save_warning;
531         page->checkbtn_simplify_subject = checkbtn_simplify_subject;
532         page->entry_simplify_subject = entry_simplify_subject;
533         page->entry_regexp_test_string = entry_regexp_test_string;
534         page->entry_regexp_test_result = entry_regexp_test_result;
535         page->checkbtn_folder_chmod = checkbtn_folder_chmod;
536         page->entry_folder_chmod = entry_folder_chmod;
537         page->folder_color_btn = folder_color_btn;
538         page->checkbtn_enable_processing = checkbtn_enable_processing;
539         page->checkbtn_newmailcheck = checkbtn_newmailcheck;
540         page->checkbtn_offlinesync = checkbtn_offlinesync;
541         page->label_offlinesync = label_offlinesync;
542         page->entry_offlinesync = entry_offlinesync;
543         page->label_end_offlinesync = label_end_offlinesync;
544         page->checkbtn_remove_old_offlinesync = checkbtn_remove_old_offlinesync;
545
546         page->simplify_subject_rec_checkbtn  = simplify_subject_rec_checkbtn;
547         page->folder_chmod_rec_checkbtn      = folder_chmod_rec_checkbtn;
548         page->folder_color_rec_checkbtn      = folder_color_rec_checkbtn;
549         page->enable_processing_rec_checkbtn = enable_processing_rec_checkbtn;
550         page->newmailcheck_rec_checkbtn      = newmailcheck_rec_checkbtn;
551         page->offlinesync_rec_checkbtn       = offlinesync_rec_checkbtn;
552
553         page->page.widget = table;
554
555         folder_regexp_set_subject_example_cb(NULL, page);
556 }
557
558 static void prefs_folder_item_general_destroy_widget_func(PrefsPage *page_) 
559 {
560         /* FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_; */
561 }
562
563 /** \brief  Save the prefs in page to folder.
564  *
565  *  If the folder is not the one  specified in page->item, then only those properties 
566  *  that have the relevant 'apply to sub folders' button checked are saved
567  */
568 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page)
569 {
570         FolderItemPrefs *prefs = folder->prefs;
571         gchar *buf;
572         gboolean all = FALSE;
573         SpecialFolderItemType type = F_NORMAL;
574
575         if (folder->path == NULL)
576                 return;
577
578         g_return_if_fail(prefs != NULL);
579
580         if (page->item == folder) 
581                 all = TRUE;
582
583         type = combobox_get_active_data(GTK_COMBO_BOX(page->folder_type));
584         if (all && folder->stype != type) {
585                 folder_item_change_type(folder, type);
586         }
587
588         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn))) {
589                 prefs->enable_simplify_subject =
590                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
591                 ASSIGN_STRING(prefs->simplify_subject_regexp,
592                               gtk_editable_get_chars(GTK_EDITABLE(page->entry_simplify_subject), 0, -1));
593         }
594         
595         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn))) {
596                 prefs->enable_folder_chmod = 
597                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_folder_chmod));
598                 buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_folder_chmod), 0, -1);
599                 prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
600                 g_free(buf);
601         }
602
603         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn))) {
604                 int old_color = prefs->color;
605                 prefs->color = page->folder_color;
606         
607                 /* update folder view */
608                 if (prefs->color != old_color)
609                         folder_item_update(folder, F_ITEM_UPDATE_MSGCNT);
610         }
611
612         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn))) {
613                 prefs->enable_processing = 
614                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_processing));
615         }
616
617         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn))) {
618                 prefs->newmailcheck = 
619                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_newmailcheck));
620         }
621
622         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))) {
623                 prefs->offlinesync = 
624                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_offlinesync));
625                 prefs->offlinesync_days = 
626                         atoi(gtk_entry_get_text(GTK_ENTRY(page->entry_offlinesync)));
627                 prefs->remove_old_bodies =
628                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_remove_old_offlinesync));
629         }
630
631         folder_item_prefs_save_config(folder);
632 }       
633
634 static gboolean general_save_recurse_func(GNode *node, gpointer data)
635 {
636         FolderItem *item = (FolderItem *) node->data;
637         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
638
639         g_return_val_if_fail(item != NULL, TRUE);
640         g_return_val_if_fail(page != NULL, TRUE);
641
642         general_save_folder_prefs(item, page);
643
644         /* optimise by not continuing if none of the 'apply to sub folders'
645            check boxes are selected - and optimise the checking by only doing
646            it once */
647         if ((node == page->item->node) &&
648             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn)) ||
649               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn)) ||
650               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn)) ||
651               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn)) ||
652               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn)) ||
653               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))))
654                 return TRUE;
655         else 
656                 return FALSE;
657 }
658
659 static void prefs_folder_item_general_save_func(PrefsPage *page_) 
660 {
661         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
662
663         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
664                         -1, general_save_recurse_func, page);
665         
666         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
667
668 }
669
670 static RecvProtocol item_protocol(FolderItem *item)
671 {
672         if (!item)
673                 return A_NONE;
674         if (!item->folder)
675                 return A_NONE;
676         if (!item->folder->account)
677                 return A_NONE;
678         return item->folder->account->protocol;
679 }
680
681 static void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
682                                                    GtkWindow * window,
683                                                    gpointer data)
684 {
685         FolderItemComposePage *page = (FolderItemComposePage *) page_;
686         FolderItem *item = (FolderItem *) data;
687         guint rowcount;
688
689         GtkWidget *table;
690         GtkWidget *label;
691         
692         GtkWidget *no_save_warning = NULL;
693         GtkWidget *checkbtn_request_return_receipt = NULL;
694         GtkWidget *checkbtn_save_copy_to_folder = NULL;
695         GtkWidget *checkbtn_default_to = NULL;
696         GtkWidget *entry_default_to = NULL;
697         GtkWidget *checkbtn_default_reply_to = NULL;
698         GtkWidget *entry_default_reply_to = NULL;
699         GtkWidget *checkbtn_enable_default_account = NULL;
700         GtkWidget *optmenu_default_account = NULL;
701         GtkListStore *optmenu_default_account_menu = NULL;
702         GtkTreeIter iter;
703 #if USE_ASPELL
704         GtkWidget *checkbtn_enable_default_dictionary = NULL;
705         GtkWidget *optmenu_default_dictionary = NULL;
706         GtkWidget *checkbtn_enable_default_alt_dictionary = NULL;
707         GtkWidget *optmenu_default_alt_dictionary = NULL;
708         GtkWidget *default_dictionary_rec_checkbtn = NULL;
709         GtkWidget *default_alt_dictionary_rec_checkbtn = NULL;
710         gchar *dictionary;
711         GtkOptionMenu *optmenu;
712         GtkWidget *menu;
713         GtkWidget *menuitem;
714 #endif
715         GtkWidget *request_return_receipt_rec_checkbtn = NULL;
716         GtkWidget *save_copy_to_folder_rec_checkbtn = NULL;
717         GtkWidget *default_to_rec_checkbtn = NULL;
718         GtkWidget *default_reply_to_rec_checkbtn = NULL;
719         GtkWidget *default_account_rec_checkbtn = NULL;
720
721         GList *cur_ac;
722         GList *account_list;
723         PrefsAccount *ac_prefs;
724         gboolean default_account_set = FALSE;
725
726         page->item         = item;
727
728         /* Table */
729 #if USE_ASPELL
730 # define TABLEHEIGHT 7
731 #else
732 # define TABLEHEIGHT 6
733 #endif
734         table = gtk_table_new(TABLEHEIGHT, 3, FALSE);
735         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
736         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
737         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
738         rowcount = 0;
739
740         if (!can_save) {
741                 no_save_warning = gtk_label_new(
742                         _("<i>These preferences will not be saved as this folder "
743                         "is a top-level one. However you can use them to set them "
744                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
745                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
746                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
747                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
748                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 3,
749                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
750                 rowcount++;
751         }
752         
753         /* Apply to subfolders */
754         label = gtk_label_new(_("Apply to\nsubfolders"));
755         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
756         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
757                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
758         rowcount++;
759
760         if (item_protocol(item) != A_NNTP) {
761                 /* Request Return Receipt */
762                 checkbtn_request_return_receipt = gtk_check_button_new_with_label
763                         (_("Request Return Receipt"));
764                 gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
765                                  0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
766                                  GTK_FILL, 0, 0);
767                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
768                                              item->ret_rcpt ? TRUE : FALSE);
769
770                 request_return_receipt_rec_checkbtn = gtk_check_button_new();
771                 gtk_table_attach(GTK_TABLE(table), request_return_receipt_rec_checkbtn, 2, 3, 
772                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
773
774                 rowcount++;
775
776                 /* Save Copy to Folder */
777                 checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
778                         (_("Save copy of outgoing messages to this folder instead of Sent"));
779                 gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
780                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
781                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
782                                              item->prefs->save_copy_to_folder ? TRUE : FALSE);
783
784                 save_copy_to_folder_rec_checkbtn = gtk_check_button_new();
785                 gtk_table_attach(GTK_TABLE(table), save_copy_to_folder_rec_checkbtn, 2, 3, 
786                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
787
788                 rowcount++;
789
790                 /* Default To */
791                 checkbtn_default_to = gtk_check_button_new_with_label(_("Default To:"));
792                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
793                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
794                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
795                                              item->prefs->enable_default_to);
796
797                 entry_default_to = gtk_entry_new();
798                 gtk_table_attach(GTK_TABLE(table), entry_default_to, 1, 2,
799                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
800                 SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
801                 gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
802                 address_completion_register_entry(GTK_ENTRY(entry_default_to),
803                                 TRUE);
804
805                 default_to_rec_checkbtn = gtk_check_button_new();
806                 gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3, 
807                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
808
809                 rowcount++;
810
811                 /* Default address to reply to */
812                 checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Default To: for replies"));
813                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
814                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
815                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
816                                              item->prefs->enable_default_reply_to);
817
818                 entry_default_reply_to = gtk_entry_new();
819                 gtk_table_attach(GTK_TABLE(table), entry_default_reply_to, 1, 2,
820                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
821                 SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
822                 gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
823                 address_completion_register_entry(
824                                 GTK_ENTRY(entry_default_reply_to), TRUE);
825
826                 default_reply_to_rec_checkbtn = gtk_check_button_new();
827                 gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3, 
828                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
829
830                 rowcount++;
831         }
832         /* Default account */
833         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account"));
834         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
835                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
836         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
837                                      item->prefs->enable_default_account);
838
839         optmenu_default_account = gtkut_sc_combobox_create(NULL, FALSE);
840         gtk_table_attach(GTK_TABLE(table), optmenu_default_account, 1, 2, 
841                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
842         optmenu_default_account_menu = GTK_LIST_STORE(
843                         gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu_default_account)));
844
845         account_list = account_get_list();
846         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
847                 ac_prefs = (PrefsAccount *)cur_ac->data;
848                 if (item->folder->account &&
849                     ( (item_protocol(item) == A_NNTP && ac_prefs->protocol != A_NNTP)
850                     ||(item_protocol(item) != A_NNTP && ac_prefs->protocol == A_NNTP))) 
851                         continue;
852
853                 if (item->folder->klass->type != F_NEWS && ac_prefs->protocol == A_NNTP)
854                         continue;
855
856                 COMBOBOX_ADD (optmenu_default_account_menu,
857                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
858                                         ac_prefs->account_id);
859
860                 /* Set combobox to current default account id */
861                 if (ac_prefs->account_id == item->prefs->default_account) {
862                         combobox_select_by_data(GTK_COMBO_BOX(optmenu_default_account),
863                                         ac_prefs->account_id);
864                         default_account_set = TRUE;
865                 }
866         }
867
868         /* If nothing has been set (folder doesn't have a default account set),
869          * pre-select global default account, since that's what actually used
870          * anyway. We don't want nothing selected in combobox. */
871         if( !default_account_set )
872                 combobox_select_by_data(GTK_COMBO_BOX(optmenu_default_account),
873                                 account_get_default()->account_id);
874
875         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
876
877         default_account_rec_checkbtn = gtk_check_button_new();
878         gtk_table_attach(GTK_TABLE(table), default_account_rec_checkbtn, 2, 3, 
879                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
880         rowcount++;
881
882 #if USE_ASPELL
883         /* Default dictionary */
884         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary"));
885         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_dictionary, 0, 1,
886                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
887         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
888                                      item->prefs->enable_default_dictionary);
889
890         optmenu_default_dictionary = gtk_option_menu_new();
891         gtk_table_attach(GTK_TABLE(table), optmenu_default_dictionary, 1, 2,
892                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
893
894         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_dictionary), 
895                                  gtkaspell_dictionary_option_menu_new(
896                                          prefs_common.aspell_path));
897
898         dictionary = item->prefs->default_dictionary;
899
900         optmenu = GTK_OPTION_MENU(optmenu_default_dictionary);
901
902         menu = gtk_option_menu_get_menu(optmenu);
903         if (dictionary)
904                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_dictionary, dictionary);
905         menuitem = gtk_menu_get_active(GTK_MENU(menu));
906         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
907
908         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, optmenu_default_dictionary);
909
910         default_dictionary_rec_checkbtn = gtk_check_button_new();
911         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
912                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
913         
914         rowcount++;
915
916         /* Default dictionary */
917         checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
918         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_alt_dictionary, 0, 1,
919                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
920         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
921                                      item->prefs->enable_default_alt_dictionary);
922
923         optmenu_default_alt_dictionary = gtk_option_menu_new();
924         gtk_table_attach(GTK_TABLE(table), optmenu_default_alt_dictionary, 1, 2,
925                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
926
927         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_alt_dictionary), 
928                                  gtkaspell_dictionary_option_menu_new_with_refresh(
929                                          prefs_common.aspell_path, FALSE));
930
931         dictionary = item->prefs->default_alt_dictionary;
932
933         optmenu = GTK_OPTION_MENU(optmenu_default_alt_dictionary);
934
935         menu = gtk_option_menu_get_menu(optmenu);
936         if (dictionary)
937                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_alt_dictionary, dictionary);
938         menuitem = gtk_menu_get_active(GTK_MENU(menu));
939         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
940
941         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, optmenu_default_alt_dictionary);
942
943         default_alt_dictionary_rec_checkbtn = gtk_check_button_new();
944         gtk_table_attach(GTK_TABLE(table), default_alt_dictionary_rec_checkbtn, 2, 3, 
945                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
946         
947         rowcount++;
948 #endif
949
950         gtk_widget_show_all(table);
951
952         page->window = GTK_WIDGET(window);
953         page->table = table;
954         page->no_save_warning = no_save_warning;
955         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
956         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
957         page->checkbtn_default_to = checkbtn_default_to;
958         page->entry_default_to = entry_default_to;
959         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
960         page->entry_default_reply_to = entry_default_reply_to;
961         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
962         page->optmenu_default_account = optmenu_default_account;
963 #ifdef USE_ASPELL
964         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
965         page->optmenu_default_dictionary = optmenu_default_dictionary;
966         page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
967         page->optmenu_default_alt_dictionary = optmenu_default_alt_dictionary;
968 #endif
969
970         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
971         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
972         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
973         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
974         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
975 #if USE_ASPELL
976         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
977         page->default_alt_dictionary_rec_checkbtn = default_alt_dictionary_rec_checkbtn;
978 #endif
979
980         address_completion_start(page->window);
981
982         page->page.widget = table;
983 }
984
985 static void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
986 {
987         FolderItemComposePage *page = (FolderItemComposePage *) page_;
988
989         if (page->entry_default_to)
990                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
991         if (page->entry_default_reply_to)
992                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
993         address_completion_end(page->window);
994 }
995
996 /** \brief  Save the prefs in page to folder.
997  *
998  *  If the folder is not the one  specified in page->item, then only those properties 
999  *  that have the relevant 'apply to sub folders' button checked are saved
1000  */
1001 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
1002 {
1003         FolderItemPrefs *prefs = folder->prefs;
1004 #if USE_ASPELL
1005         GtkWidget *menu;
1006 #endif
1007         gboolean all = FALSE;
1008
1009         if (folder->path == NULL)
1010                 return;
1011
1012         if (page->item == folder) 
1013                 all = TRUE;
1014
1015         g_return_if_fail(prefs != NULL);
1016
1017         if (item_protocol(folder) != A_NNTP) {
1018                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
1019                         prefs->request_return_receipt = 
1020                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
1021                         /* MIGRATION */    
1022                         folder->ret_rcpt = prefs->request_return_receipt;
1023                 }
1024
1025                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
1026                         prefs->save_copy_to_folder = 
1027                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
1028                 }
1029
1030                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
1031
1032                         prefs->enable_default_to = 
1033                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
1034                         ASSIGN_STRING(prefs->default_to,
1035                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
1036                 }
1037
1038                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
1039                         prefs->enable_default_reply_to = 
1040                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
1041                         ASSIGN_STRING(prefs->default_reply_to,
1042                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
1043                 }
1044         } else {
1045                 prefs->request_return_receipt = FALSE;
1046                 prefs->save_copy_to_folder = FALSE;
1047                 prefs->enable_default_to = FALSE;
1048                 prefs->enable_default_reply_to = FALSE;
1049         }
1050
1051         if (all || gtk_toggle_button_get_active(
1052                                 GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
1053                 prefs->enable_default_account = 
1054                         gtk_toggle_button_get_active(
1055                                         GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
1056                 prefs->default_account = combobox_get_active_data(
1057                                 GTK_COMBO_BOX(page->optmenu_default_account));
1058         }
1059
1060 #if USE_ASPELL
1061         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
1062                 prefs->enable_default_dictionary =
1063                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
1064                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_dictionary));
1065                 ASSIGN_STRING(prefs->default_dictionary,
1066                               gtkaspell_get_dictionary_menu_active_item(menu));
1067         }
1068         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))) {
1069                 prefs->enable_default_alt_dictionary =
1070                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_alt_dictionary));
1071                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_alt_dictionary));
1072                 ASSIGN_STRING(prefs->default_alt_dictionary,
1073                               gtkaspell_get_dictionary_menu_active_item(menu));
1074         }
1075 #endif
1076
1077         folder_item_prefs_save_config(folder);
1078 }       
1079
1080 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
1081 {
1082         FolderItem *item = (FolderItem *) node->data;
1083         FolderItemComposePage *page = (FolderItemComposePage *) data;
1084
1085         g_return_val_if_fail(item != NULL, TRUE);
1086         g_return_val_if_fail(page != NULL, TRUE);
1087
1088         compose_save_folder_prefs(item, page);
1089
1090         /* optimise by not continuing if none of the 'apply to sub folders'
1091            check boxes are selected - and optimise the checking by only doing
1092            it once */
1093         if ((node == page->item->node) && item_protocol(item) != A_NNTP &&
1094             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
1095               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
1096               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
1097               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) ||
1098 #if USE_ASPELL
1099               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn)) ||
1100               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn)) ||
1101 #endif
1102               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))))
1103                 return TRUE;
1104         else if ((node == page->item->node) && item_protocol(item) == A_NNTP &&
1105             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
1106 #if USE_ASPELL
1107               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
1108               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))
1109 #endif
1110                     ))
1111                 return TRUE;
1112         else 
1113                 return FALSE;
1114 }
1115
1116 static void prefs_folder_item_compose_save_func(PrefsPage *page_) 
1117 {
1118         FolderItemComposePage *page = (FolderItemComposePage *) page_;
1119
1120         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1121                         -1, compose_save_recurse_func, page);
1122
1123 }
1124
1125 static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
1126                                                    GtkWindow * window,
1127                                                    gpointer data)
1128 {
1129         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1130         FolderItem *item = (FolderItem *) data;
1131
1132         GtkWidget *table;
1133         GtkWidget *label;
1134         guint rowcount;
1135         GtkWidget *vbox;
1136         GtkWidget *alignment;
1137         GtkWidget *new_msg_format_rec_checkbtn;
1138         GtkWidget *reply_format_rec_checkbtn;
1139         GtkWidget *forward_format_rec_checkbtn;
1140
1141         page->item         = item;
1142
1143         /* Table */
1144         table = gtk_table_new(5, 3, FALSE);
1145         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
1146         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1147         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
1148         rowcount = 0;
1149
1150         /* Apply to subfolders */
1151         label = gtk_label_new(_("Apply to\nsubfolders"));
1152         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
1153         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
1154                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
1155         rowcount++;
1156
1157         /* compose format */
1158         vbox = gtk_vbox_new (FALSE, VSPACING);
1159         gtk_widget_show (vbox);
1160         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1161         gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
1162                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1163
1164         quotefmt_create_new_msg_fmt_widgets(
1165                                 window,
1166                                 vbox,
1167                                 &page->checkbtn_compose_with_format,
1168                                 _("Use a specific format for new messages"),
1169                                 &page->compose_subject_format,
1170                                 &page->compose_body_format,
1171                                 FALSE);
1172
1173         vbox = gtk_vbox_new (FALSE, VSPACING);
1174         gtk_widget_show (vbox);
1175         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1176         gtk_table_attach(GTK_TABLE(table), vbox, 2, 3, 
1177                          rowcount, rowcount + 1, GTK_SHRINK, GTK_FILL, 0, 0);
1178
1179         new_msg_format_rec_checkbtn = gtk_check_button_new();
1180         gtk_box_pack_start (GTK_BOX(vbox), new_msg_format_rec_checkbtn, FALSE, FALSE, 0);
1181         alignment = gtk_alignment_new(0, 1, 0, 0);      
1182         gtk_box_pack_start (GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
1183
1184         rowcount++;
1185
1186         /* reply format */
1187         vbox = gtk_vbox_new (FALSE, VSPACING);
1188         gtk_widget_show (vbox);
1189         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1190         gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
1191                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1192
1193         quotefmt_create_reply_fmt_widgets(
1194                                 window,
1195                                 vbox,
1196                                 &page->checkbtn_reply_with_format,
1197                                 _("Use a specific reply quote format"),
1198                                 &page->reply_quotemark,
1199                                 &page->reply_body_format,
1200                                 FALSE);
1201
1202         vbox = gtk_vbox_new (FALSE, VSPACING);
1203         gtk_widget_show (vbox);
1204         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1205         gtk_table_attach(GTK_TABLE(table), vbox, 2, 3, 
1206                          rowcount, rowcount + 1, GTK_SHRINK, GTK_FILL, 0, 0);
1207
1208         reply_format_rec_checkbtn = gtk_check_button_new();
1209         gtk_box_pack_start (GTK_BOX(vbox), reply_format_rec_checkbtn, FALSE, FALSE, 0);
1210         alignment = gtk_alignment_new(0, 1, 0, 0);      
1211         gtk_box_pack_start (GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
1212
1213         rowcount++;
1214
1215         /* forward format */
1216         vbox = gtk_vbox_new (FALSE, VSPACING);
1217         gtk_widget_show (vbox);
1218         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1219         gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
1220                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1221
1222         quotefmt_create_forward_fmt_widgets(
1223                                 window,
1224                                 vbox,
1225                                 &page->checkbtn_forward_with_format,
1226                                 _("Use a specific forward quote format"),
1227                                 &page->forward_quotemark,
1228                                 &page->forward_body_format,
1229                                 FALSE);
1230
1231         vbox = gtk_vbox_new (FALSE, VSPACING);
1232         gtk_widget_show (vbox);
1233         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1234         gtk_table_attach(GTK_TABLE(table), vbox, 2, 3, 
1235                          rowcount, rowcount + 1, GTK_SHRINK, GTK_FILL, 0, 0);
1236
1237         forward_format_rec_checkbtn = gtk_check_button_new();
1238         gtk_box_pack_start (GTK_BOX(vbox), forward_format_rec_checkbtn, FALSE, FALSE, 0);
1239         alignment = gtk_alignment_new(0, 1, 0, 0);      
1240         gtk_box_pack_start (GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
1241
1242         rowcount++;
1243
1244         /* information button */
1245         vbox = gtk_vbox_new (FALSE, VSPACING);
1246         gtk_widget_show (vbox);
1247         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1248         gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
1249                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1250         rowcount++;
1251         quotefmt_add_info_button(window, vbox);
1252
1253
1254         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format),
1255                         item->prefs->compose_with_format);
1256         pref_set_entry_from_pref(GTK_ENTRY(page->compose_subject_format),
1257                         item->prefs->compose_subject_format);
1258         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->compose_body_format),
1259                         item->prefs->compose_body_format);
1260
1261         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format),
1262                         item->prefs->reply_with_format);
1263         pref_set_entry_from_pref(GTK_ENTRY(page->reply_quotemark),
1264                         item->prefs->reply_quotemark);
1265         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->reply_body_format),
1266                         item->prefs->reply_body_format);
1267
1268         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format),
1269                         item->prefs->forward_with_format);
1270         pref_set_entry_from_pref(GTK_ENTRY(page->forward_quotemark),
1271                         item->prefs->forward_quotemark);
1272         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->forward_body_format),
1273                         item->prefs->forward_body_format);
1274
1275         gtk_widget_show_all(table);
1276
1277         page->window = GTK_WIDGET(window);
1278         page->table = table;
1279
1280         page->new_msg_format_rec_checkbtn = new_msg_format_rec_checkbtn;
1281         page->reply_format_rec_checkbtn = reply_format_rec_checkbtn;
1282         page->forward_format_rec_checkbtn = forward_format_rec_checkbtn;
1283
1284         page->page.widget = table;
1285 }
1286
1287 static void prefs_folder_item_templates_destroy_widget_func(PrefsPage *page_) 
1288 {
1289         /* FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_; */
1290 }
1291
1292 /** \brief  Save the prefs in page to folder.
1293  *
1294  *  If the folder is not the one  specified in page->item, then only those properties 
1295  *  that have the relevant 'apply to sub folders' button checked are saved
1296  */
1297 static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesPage *page)
1298 {
1299         FolderItemPrefs *prefs = folder->prefs;
1300         gboolean all = FALSE;
1301
1302         if (folder->path == NULL)
1303                 return;
1304
1305         if (page->item == folder) 
1306                 all = TRUE;
1307
1308         g_return_if_fail(prefs != NULL);
1309
1310         /* save and check formats */
1311
1312         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn))) {
1313                 prefs->compose_with_format =
1314                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format));
1315                 prefs->compose_subject_format = pref_get_pref_from_entry(
1316                                 GTK_ENTRY(page->compose_subject_format));
1317                 prefs->compose_body_format = pref_get_pref_from_textview(
1318                                 GTK_TEXT_VIEW(page->compose_body_format));
1319                 quotefmt_check_new_msg_formats(prefs->compose_with_format,
1320                                                                                 prefs->compose_subject_format,
1321                                                                                 prefs->compose_body_format);
1322         }
1323
1324         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn))) {
1325                 prefs->reply_with_format =
1326                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format));
1327                 prefs->reply_quotemark = gtk_editable_get_chars(
1328                                 GTK_EDITABLE(page->reply_quotemark), 0, -1);
1329                 prefs->reply_body_format = pref_get_pref_from_textview(
1330                                 GTK_TEXT_VIEW(page->reply_body_format));
1331                 quotefmt_check_reply_formats(prefs->reply_with_format,
1332                                                                                 prefs->reply_quotemark,
1333                                                                                 prefs->reply_body_format);
1334         }
1335
1336         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))) {
1337                 prefs->forward_with_format =
1338                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format));
1339                 prefs->forward_quotemark = gtk_editable_get_chars(
1340                                 GTK_EDITABLE(page->forward_quotemark), 0, -1);
1341                 prefs->forward_body_format = pref_get_pref_from_textview(
1342                                 GTK_TEXT_VIEW(page->forward_body_format));
1343                 quotefmt_check_forward_formats(prefs->forward_with_format,
1344                                                                                 prefs->forward_quotemark,
1345                                                                                 prefs->forward_body_format);
1346         }
1347
1348         folder_item_prefs_save_config(folder);
1349 }       
1350
1351 static gboolean templates_save_recurse_func(GNode *node, gpointer data)
1352 {
1353         FolderItem *item = (FolderItem *) node->data;
1354         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) data;
1355
1356         g_return_val_if_fail(item != NULL, TRUE);
1357         g_return_val_if_fail(page != NULL, TRUE);
1358
1359         templates_save_folder_prefs(item, page);
1360
1361         /* optimise by not continuing if none of the 'apply to sub folders'
1362            check boxes are selected - and optimise the checking by only doing
1363            it once */
1364         if ((node == page->item->node) &&
1365             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn)) ||
1366               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn)) ||
1367               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))))
1368                 return TRUE;
1369         else 
1370                 return FALSE;
1371
1372         return FALSE;
1373 }
1374
1375 static void prefs_folder_item_templates_save_func(PrefsPage *page_) 
1376 {
1377         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1378
1379         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1380                         -1, templates_save_recurse_func, page);
1381
1382 }
1383
1384 static gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
1385 {
1386         gint newmode = 0;
1387         gchar *tmp;
1388
1389         if (folder_chmod) {
1390                 newmode = strtol(folder_chmod, &tmp, 8);
1391                 if (!(*(folder_chmod) && !(*tmp)))
1392                         newmode = 0;
1393         }
1394
1395         return newmode;
1396 }
1397
1398 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
1399 {
1400         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1401         gint rgbcolor;
1402
1403         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
1404                                              page->folder_color);
1405         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
1406         page->folder_color = rgbcolor;
1407 }
1408
1409 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
1410 {
1411         int err;
1412         gchar buf[BUFFSIZE];
1413         regex_t *preg = NULL;
1414
1415         preg = g_new0(regex_t, 1);
1416
1417         err = string_match_precompile(simplify_subject_regexp, 
1418                                       preg, REG_EXTENDED);
1419         if (err) {
1420                 regerror(err, preg, buf, BUFFSIZE);
1421                 g_free(preg);
1422                 preg = NULL;
1423         }
1424
1425         return preg;
1426 }
1427
1428 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data)
1429 {
1430         static GdkColor red;
1431         static gboolean colors_initialised = FALSE;
1432         static gchar buf[BUFFSIZE];
1433         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1434         gchar *test_string, *regexp;
1435         regex_t *preg;
1436
1437         regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_simplify_subject)));
1438         test_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_regexp_test_string)));
1439
1440         if (!regexp || !regexp[0]) {
1441                 gtk_widget_modify_base(page->entry_simplify_subject,
1442                                 GTK_STATE_NORMAL, NULL);
1443                 if (test_string) {
1444                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), test_string);
1445                         g_free(test_string);
1446                 }
1447                 return;
1448         }
1449
1450         if (!test_string || !test_string[0]) {
1451                 g_free(regexp);
1452                 return;
1453         }
1454
1455         if (!colors_initialised) {
1456                 gdk_color_parse("#ff7070", &red);
1457                 colors_initialised = gdk_colormap_alloc_color(
1458                         gdk_colormap_get_system(), &red, FALSE, TRUE);
1459         }
1460
1461         preg = summary_compile_simplify_regexp(regexp);
1462         if (colors_initialised) {
1463                 gtk_widget_modify_base(page->entry_simplify_subject,
1464                                 GTK_STATE_NORMAL, preg ? NULL : &red);
1465         }
1466
1467         if (preg != NULL) {
1468                 string_remove_match(buf, BUFFSIZE, test_string, preg);
1469
1470                 gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), buf);
1471
1472                 regfree(preg);
1473                 g_free(preg);
1474         }
1475
1476         g_free(test_string);
1477         g_free(regexp);
1478 }
1479
1480 static gchar *folder_regexp_get_subject_example(void)
1481 {
1482         MsgInfo *msginfo_selected;
1483         SummaryView *summaryview = NULL;
1484
1485         if (!mainwindow_get_mainwindow())
1486                 return NULL;
1487         summaryview = mainwindow_get_mainwindow()->summaryview;
1488
1489         msginfo_selected = summary_get_selected_msg(summaryview);
1490         return msginfo_selected ? g_strdup(msginfo_selected->subject) : NULL;
1491 }
1492
1493 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data)
1494 {
1495         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1496
1497         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject))) {
1498                 gchar *subject = folder_regexp_get_subject_example();
1499                 if (subject) {
1500                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_string), subject);
1501                         g_free(subject);
1502                 }
1503         }
1504 }
1505
1506 static void register_general_page()
1507 {
1508         static gchar *pfi_general_path[2];
1509         static FolderItemGeneralPage folder_item_general_page;
1510
1511         pfi_general_path[0] = _("General");
1512         pfi_general_path[1] = NULL;
1513
1514         folder_item_general_page.page.path = pfi_general_path;
1515         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
1516         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
1517         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
1518         
1519         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
1520 }
1521
1522
1523 static void register_compose_page(void)
1524 {
1525         static gchar *pfi_compose_path[2];
1526         static FolderItemComposePage folder_item_compose_page;
1527
1528         pfi_compose_path[0] = _("Compose");
1529         pfi_compose_path[1] = NULL;
1530
1531         folder_item_compose_page.page.path = pfi_compose_path;
1532         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
1533         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
1534         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
1535         
1536         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
1537 }
1538
1539 static void register_templates_page(void)
1540 {
1541         static gchar *pfi_templates_path[2];
1542         static FolderItemTemplatesPage folder_item_templates_page;
1543
1544         pfi_templates_path[0] = _("Templates");
1545         pfi_templates_path[1] = NULL;
1546
1547         folder_item_templates_page.page.path = pfi_templates_path;
1548         folder_item_templates_page.page.create_widget = prefs_folder_item_templates_create_widget_func;
1549         folder_item_templates_page.page.destroy_widget = prefs_folder_item_templates_destroy_widget_func;
1550         folder_item_templates_page.page.save_page = prefs_folder_item_templates_save_func;
1551         
1552         prefs_folder_item_register_page((PrefsPage *) &folder_item_templates_page);
1553 }
1554
1555 static GSList *prefs_pages = NULL;
1556
1557 void prefs_folder_item_open(FolderItem *item)
1558 {
1559         gchar *id, *title;
1560         if (prefs_pages == NULL) {
1561                 register_general_page();
1562                 register_compose_page();
1563                 register_templates_page();
1564         }
1565
1566         if (item->path) {
1567                 id = folder_item_get_identifier (item);
1568                 can_save = TRUE;
1569         } else {
1570                 id = g_strdup(item->name);
1571                 can_save = FALSE;
1572         }
1573         title = g_strdup_printf (_("Properties for folder %s"), id);
1574         g_free (id);
1575         prefswindow_open(title, prefs_pages, item,
1576                         &prefs_common.folderitemwin_width, &prefs_common.folderitemwin_height);
1577         
1578         g_free (title);
1579 }
1580
1581 void prefs_folder_item_register_page(PrefsPage *page)
1582 {
1583         prefs_pages = g_slist_append(prefs_pages, page);
1584 }
1585
1586 void prefs_folder_item_unregister_page(PrefsPage *page)
1587 {
1588         prefs_pages = g_slist_remove(prefs_pages, page);
1589 }