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