Reenabled regexps on Windows.
[claws.git] / src / folder_item_prefs.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 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 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include <glib.h>
26 #include <glib/gi18n.h>
27
28 #include "defs.h"
29 #include "folder.h"
30 #include "utils.h"
31 #include "prefs_gtk.h"
32 #include "filtering.h"
33 #include "folder_item_prefs.h"
34
35 FolderItemPrefs tmp_prefs;
36
37 static PrefParam param[] = {
38         {"enable_default_to", "", &tmp_prefs.enable_default_to, P_BOOL,
39          NULL, NULL, NULL},
40         {"default_to", "", &tmp_prefs.default_to, P_STRING,
41          NULL, NULL, NULL},
42         {"enable_default_reply_to", "", &tmp_prefs.enable_default_reply_to, P_BOOL,
43          NULL, NULL, NULL},
44         {"default_reply_to", "", &tmp_prefs.default_reply_to, P_STRING,
45          NULL, NULL, NULL},
46         {"enable_default_cc", "", &tmp_prefs.enable_default_cc, P_BOOL,
47          NULL, NULL, NULL},
48         {"default_cc", "", &tmp_prefs.default_cc, P_STRING,
49          NULL, NULL, NULL},
50         {"enable_default_bcc", "", &tmp_prefs.enable_default_bcc, P_BOOL,
51          NULL, NULL, NULL},
52         {"default_bcc", "", &tmp_prefs.default_bcc, P_STRING,
53          NULL, NULL, NULL},
54         {"enable_default_replyto", "", &tmp_prefs.enable_default_replyto, P_BOOL,
55          NULL, NULL, NULL},
56         {"default_replyto", "", &tmp_prefs.default_replyto, P_STRING,
57          NULL, NULL, NULL},
58         {"enable_simplify_subject", "", &tmp_prefs.enable_simplify_subject, P_BOOL,
59          NULL, NULL, NULL},
60         {"simplify_subject_regexp", "", &tmp_prefs.simplify_subject_regexp, P_STRING,
61          NULL, NULL, NULL},
62         {"enable_folder_chmod", "", &tmp_prefs.enable_folder_chmod, P_BOOL,
63          NULL, NULL, NULL},
64         {"folder_chmod", "", &tmp_prefs.folder_chmod, P_INT,
65          NULL, NULL, NULL},
66         {"enable_default_account", "", &tmp_prefs.enable_default_account, P_BOOL,
67          NULL, NULL, NULL},
68         {"default_account", NULL, &tmp_prefs.default_account, P_INT,
69          NULL, NULL, NULL},
70 #if USE_ENCHANT
71         {"enable_default_dictionary", "", &tmp_prefs.enable_default_dictionary, P_BOOL,
72          NULL, NULL, NULL},
73         {"default_dictionary", NULL, &tmp_prefs.default_dictionary, P_STRING,
74          NULL, NULL, NULL},
75         {"enable_default_alt_dictionary", "", &tmp_prefs.enable_default_alt_dictionary, P_BOOL,
76          NULL, NULL, NULL},
77         {"default_alt_dictionary", NULL, &tmp_prefs.default_alt_dictionary, P_STRING,
78          NULL, NULL, NULL},
79 #endif   
80         {"save_copy_to_folder", NULL, &tmp_prefs.save_copy_to_folder, P_BOOL,
81          NULL, NULL, NULL},
82         {"folder_color", "", &tmp_prefs.color, P_INT,
83          NULL, NULL, NULL},
84         {"enable_processing", "FALSE", &tmp_prefs.enable_processing, P_BOOL,
85          NULL, NULL, NULL},
86         {"enable_processing_when_opening", "TRUE", &tmp_prefs.enable_processing_when_opening, P_BOOL,
87          NULL, NULL, NULL},
88         {"newmailcheck", "TRUE", &tmp_prefs.newmailcheck, P_BOOL,
89          NULL, NULL, NULL},
90         {"offlinesync", "FALSE", &tmp_prefs.offlinesync, P_BOOL,
91          NULL, NULL, NULL},
92         {"offlinesync_days", "0", &tmp_prefs.offlinesync_days, P_INT,
93          NULL, NULL, NULL},
94         {"remove_old_bodies", "FALSE", &tmp_prefs.remove_old_bodies, P_BOOL,
95          NULL, NULL, NULL},
96         {"promote_html_part", "0", &tmp_prefs.promote_html_part, P_ENUM,
97          NULL, NULL, NULL},
98
99         {"compose_with_format", "FALSE", &tmp_prefs.compose_with_format, P_BOOL,
100          NULL, NULL, NULL},
101         {"compose_override_from_format", NULL, &tmp_prefs.compose_override_from_format, P_STRING,
102          NULL, NULL, NULL},
103         {"compose_subject_format", NULL, &tmp_prefs.compose_subject_format, P_STRING,
104          NULL, NULL, NULL},
105         {"compose_body_format", NULL, &tmp_prefs.compose_body_format, P_STRING,
106          NULL, NULL, NULL},
107         {"reply_with_format", "FALSE", &tmp_prefs.reply_with_format, P_BOOL,
108          NULL, NULL, NULL},
109         {"reply_override_from_format", NULL, &tmp_prefs.reply_override_from_format, P_STRING,
110          NULL, NULL, NULL},
111         {"reply_quotemark", NULL, &tmp_prefs.reply_quotemark, P_STRING,
112          NULL, NULL, NULL},
113         {"reply_body_format", NULL, &tmp_prefs.reply_body_format, P_STRING,
114          NULL, NULL, NULL},
115         {"forward_with_format", "FALSE", &tmp_prefs.forward_with_format, P_BOOL,
116          NULL, NULL, NULL},
117         {"forward_override_from_format", NULL, &tmp_prefs.forward_override_from_format, P_STRING,
118          NULL, NULL, NULL},
119         {"forward_quotemark", NULL, &tmp_prefs.forward_quotemark, P_STRING,
120          NULL, NULL, NULL},
121         {"forward_body_format", NULL, &tmp_prefs.forward_body_format, P_STRING,
122          NULL, NULL, NULL},
123         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
124 };
125
126 static FolderItemPrefs *folder_item_prefs_clear(FolderItemPrefs *prefs);
127
128 void folder_item_prefs_read_config(FolderItem * item)
129 {
130         gchar * id;
131         gchar *rcpath;
132
133         id = folder_item_get_identifier(item);
134         folder_item_prefs_clear(&tmp_prefs);
135         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FOLDERITEM_RC, NULL);
136         prefs_read_config(param, id, rcpath, NULL);
137         g_free(id);
138         g_free(rcpath);
139
140         *item->prefs = tmp_prefs;
141 }
142
143 void folder_item_prefs_save_config(FolderItem * item)
144 {       
145         gchar * id;
146
147         tmp_prefs = * item->prefs;
148
149         id = folder_item_get_identifier(item);
150         if (id == NULL)
151                 return;
152
153         debug_print("saving prefs for %s\n", id);
154         prefs_write_config(param, id, FOLDERITEM_RC);
155         g_free(id);
156 }
157
158 static gboolean folder_item_prefs_save_config_func(GNode *node, gpointer data)
159 {
160         FolderItem *item = (FolderItem *) node->data;
161         folder_item_prefs_save_config(item);
162         return FALSE;
163 }
164
165 void folder_item_prefs_save_config_recursive(FolderItem * item)
166 {       
167         g_node_traverse(item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
168                         -1, folder_item_prefs_save_config_func, NULL);
169 }
170
171 void folder_prefs_save_config_recursive(Folder *folder)
172 {       
173         g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL,
174                         -1, folder_item_prefs_save_config_func, NULL);
175 }
176
177 static FolderItemPrefs *folder_item_prefs_clear(FolderItemPrefs *prefs)
178 {
179         prefs->enable_default_to = FALSE;
180         prefs->default_to = NULL;
181         prefs->enable_default_reply_to = FALSE;
182         prefs->default_reply_to = NULL;
183         prefs->enable_default_cc = FALSE;
184         prefs->default_cc = NULL;
185         prefs->enable_default_bcc = FALSE;
186         prefs->default_bcc = NULL;
187         prefs->enable_default_replyto = FALSE;
188         prefs->default_replyto = NULL;
189         prefs->enable_simplify_subject = FALSE;
190         prefs->simplify_subject_regexp = NULL;
191         prefs->enable_folder_chmod = FALSE;
192         prefs->folder_chmod = 0;
193         prefs->enable_default_account = FALSE;
194         prefs->default_account = 0;
195 #if USE_ENCHANT
196         prefs->enable_default_dictionary = FALSE;
197         prefs->default_dictionary = NULL;
198         prefs->enable_default_alt_dictionary = FALSE;
199         prefs->default_alt_dictionary = NULL;
200 #endif
201         prefs->save_copy_to_folder = FALSE;
202         prefs->color = 0;
203
204         prefs->enable_processing = TRUE;
205         prefs->enable_processing_when_opening = TRUE;
206         prefs->processing = NULL;
207
208         prefs->newmailcheck = TRUE;
209         prefs->offlinesync = FALSE;
210         prefs->offlinesync_days = 0;
211         prefs->remove_old_bodies = FALSE;
212         prefs->promote_html_part = HTML_PROMOTE_DEFAULT;
213
214         prefs->compose_with_format = FALSE;
215         prefs->compose_subject_format = NULL;
216         prefs->compose_body_format = NULL;
217         prefs->compose_override_from_format = NULL;
218         prefs->reply_with_format = FALSE;
219         prefs->reply_quotemark = NULL;
220         prefs->reply_body_format = NULL;
221         prefs->reply_override_from_format = NULL;
222         prefs->forward_with_format = FALSE;
223         prefs->forward_quotemark = NULL;
224         prefs->forward_body_format = NULL;
225         prefs->forward_override_from_format = NULL;
226         return prefs;
227 }
228
229 FolderItemPrefs * folder_item_prefs_new(void)
230 {
231         FolderItemPrefs * prefs;
232
233         prefs = g_new0(FolderItemPrefs, 1);
234
235         return folder_item_prefs_clear(prefs);
236 }
237
238 void folder_item_prefs_free(FolderItemPrefs * prefs)
239 {
240         g_free(prefs->default_to);
241         g_free(prefs->default_reply_to);
242         g_free(prefs->default_cc);
243         g_free(prefs->default_bcc);
244         g_free(prefs->default_replyto);
245         g_free(prefs->compose_subject_format);
246         g_free(prefs->compose_body_format);
247         g_free(prefs->compose_override_from_format);
248         g_free(prefs->reply_quotemark);
249         g_free(prefs->reply_body_format);
250         g_free(prefs->reply_override_from_format);
251         g_free(prefs->forward_quotemark);
252         g_free(prefs->forward_body_format);
253         g_free(prefs->forward_override_from_format);
254         g_free(prefs);
255 }
256
257 #define SAFE_STRING(str) \
258         (str) ? (str) : ""
259
260 void folder_item_prefs_copy_prefs(FolderItem * src, FolderItem * dest)
261 {
262         GSList *tmp_prop_list = NULL, *tmp;
263         folder_item_prefs_read_config(src);
264
265         tmp_prefs.directory                     = g_strdup(src->prefs->directory);
266         tmp_prefs.enable_processing             = src->prefs->enable_processing;
267         tmp_prefs.enable_processing_when_opening = src->prefs->enable_processing_when_opening;
268         tmp_prefs.newmailcheck                  = src->prefs->newmailcheck;
269         tmp_prefs.offlinesync                   = src->prefs->offlinesync;
270         tmp_prefs.offlinesync_days              = src->prefs->offlinesync_days;
271         tmp_prefs.remove_old_bodies             = src->prefs->remove_old_bodies;
272         tmp_prefs.promote_html_part             = src->prefs->promote_html_part;
273
274         prefs_matcher_read_config();
275
276         for (tmp = src->prefs->processing; tmp != NULL && tmp->data != NULL;) {
277                 FilteringProp *prop = (FilteringProp *)tmp->data;
278                 
279                 tmp_prop_list = g_slist_append(tmp_prop_list,
280                                            filteringprop_copy(prop));
281                 tmp = tmp->next;
282         }
283         tmp_prefs.processing                    = tmp_prop_list;
284         
285         tmp_prefs.request_return_receipt        = src->prefs->request_return_receipt;
286         tmp_prefs.enable_default_to             = src->prefs->enable_default_to;
287         tmp_prefs.default_to                    = g_strdup(src->prefs->default_to);
288         tmp_prefs.enable_default_reply_to       = src->prefs->enable_default_reply_to;
289         tmp_prefs.default_reply_to              = g_strdup(src->prefs->default_reply_to);
290         tmp_prefs.enable_default_cc             = src->prefs->enable_default_cc;
291         tmp_prefs.default_cc                    = g_strdup(src->prefs->default_cc);
292         tmp_prefs.enable_default_bcc            = src->prefs->enable_default_bcc;
293         tmp_prefs.default_bcc                   = g_strdup(src->prefs->default_bcc);
294         tmp_prefs.enable_default_replyto                = src->prefs->enable_default_replyto;
295         tmp_prefs.default_replyto                       = g_strdup(src->prefs->default_replyto);
296         tmp_prefs.enable_simplify_subject       = src->prefs->enable_simplify_subject;
297         tmp_prefs.simplify_subject_regexp       = g_strdup(src->prefs->simplify_subject_regexp);
298         tmp_prefs.enable_folder_chmod           = src->prefs->enable_folder_chmod;
299         tmp_prefs.folder_chmod                  = src->prefs->folder_chmod;
300         tmp_prefs.enable_default_account        = src->prefs->enable_default_account;
301         tmp_prefs.default_account               = src->prefs->default_account;
302 #if USE_ENCHANT
303         tmp_prefs.enable_default_dictionary     = src->prefs->enable_default_dictionary;
304         tmp_prefs.default_dictionary            = g_strdup(src->prefs->default_dictionary);
305         tmp_prefs.enable_default_alt_dictionary = src->prefs->enable_default_alt_dictionary;
306         tmp_prefs.default_alt_dictionary        = g_strdup(src->prefs->default_alt_dictionary);
307 #endif
308         tmp_prefs.save_copy_to_folder           = src->prefs->save_copy_to_folder;
309         tmp_prefs.color                         = src->prefs->color;
310
311         tmp_prefs.compose_with_format = src->prefs->compose_with_format;
312         tmp_prefs.compose_subject_format = g_strdup(src->prefs->compose_subject_format);
313         tmp_prefs.compose_body_format = g_strdup(src->prefs->compose_body_format);
314         tmp_prefs.compose_override_from_format = g_strdup(src->prefs->compose_override_from_format);
315         tmp_prefs.reply_with_format = src->prefs->reply_with_format;
316         tmp_prefs.reply_quotemark = g_strdup(src->prefs->reply_quotemark);
317         tmp_prefs.reply_body_format = g_strdup(src->prefs->reply_body_format);
318         tmp_prefs.reply_override_from_format = g_strdup(src->prefs->reply_override_from_format);
319         tmp_prefs.forward_with_format = src->prefs->forward_with_format;
320         tmp_prefs.forward_quotemark = g_strdup(src->prefs->forward_quotemark);
321         tmp_prefs.forward_body_format = g_strdup(src->prefs->forward_body_format);
322         tmp_prefs.forward_override_from_format = g_strdup(src->prefs->forward_override_from_format);
323
324         *dest->prefs = tmp_prefs;
325         folder_item_prefs_save_config(dest);
326
327         dest->collapsed = src->collapsed;
328         dest->thread_collapsed = src->thread_collapsed;
329         dest->threaded  = src->threaded;
330         dest->ret_rcpt  = src->ret_rcpt;
331         dest->hide_read_msgs = src->hide_read_msgs;
332         dest->hide_del_msgs = src->hide_del_msgs;
333         dest->hide_read_threads = src->hide_read_threads;
334         dest->sort_key  = src->sort_key;
335         dest->sort_type = src->sort_type;
336
337 }