2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2021 the Claws Mail team and Hiroyuki Yamamoto
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.
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.
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/>.
22 #include "claws-features.h"
26 #include <glib/gi18n.h>
31 #include "prefs_gtk.h"
32 #include "filtering.h"
33 #include "folder_item_prefs.h"
34 #include "prefs_migration.h"
36 FolderItemPrefs tmp_prefs
;
38 static PrefParam param
[] = {
39 {"enable_default_from", "", &tmp_prefs
.enable_default_from
, P_BOOL
,
41 {"default_from", "", &tmp_prefs
.default_from
, P_STRING
,
43 {"enable_default_to", "", &tmp_prefs
.enable_default_to
, P_BOOL
,
45 {"default_to", "", &tmp_prefs
.default_to
, P_STRING
,
47 {"enable_default_reply_to", "", &tmp_prefs
.enable_default_reply_to
, P_BOOL
,
49 {"default_reply_to", "", &tmp_prefs
.default_reply_to
, P_STRING
,
51 {"enable_default_cc", "", &tmp_prefs
.enable_default_cc
, P_BOOL
,
53 {"default_cc", "", &tmp_prefs
.default_cc
, P_STRING
,
55 {"enable_default_bcc", "", &tmp_prefs
.enable_default_bcc
, P_BOOL
,
57 {"default_bcc", "", &tmp_prefs
.default_bcc
, P_STRING
,
59 {"enable_default_replyto", "", &tmp_prefs
.enable_default_replyto
, P_BOOL
,
61 {"default_replyto", "", &tmp_prefs
.default_replyto
, P_STRING
,
63 {"enable_simplify_subject", "", &tmp_prefs
.enable_simplify_subject
, P_BOOL
,
65 {"simplify_subject_regexp", "", &tmp_prefs
.simplify_subject_regexp
, P_STRING
,
67 {"enable_folder_chmod", "", &tmp_prefs
.enable_folder_chmod
, P_BOOL
,
69 {"folder_chmod", "", &tmp_prefs
.folder_chmod
, P_INT
,
71 {"enable_default_account", "", &tmp_prefs
.enable_default_account
, P_BOOL
,
73 {"default_account", NULL
, &tmp_prefs
.default_account
, P_INT
,
76 {"enable_default_dictionary", "", &tmp_prefs
.enable_default_dictionary
, P_BOOL
,
78 {"default_dictionary", NULL
, &tmp_prefs
.default_dictionary
, P_STRING
,
80 {"enable_default_alt_dictionary", "", &tmp_prefs
.enable_default_alt_dictionary
, P_BOOL
,
82 {"default_alt_dictionary", NULL
, &tmp_prefs
.default_alt_dictionary
, P_STRING
,
85 {"always_sign", "0", &tmp_prefs
.always_sign
, P_ENUM
,
87 {"always_encrypt", "0", &tmp_prefs
.always_encrypt
, P_ENUM
,
89 {"save_copy_to_folder", NULL
, &tmp_prefs
.save_copy_to_folder
, P_BOOL
,
91 {"folder_color", "#000000", &tmp_prefs
.color
, P_COLOR
,
93 {"enable_processing", "FALSE", &tmp_prefs
.enable_processing
, P_BOOL
,
95 {"enable_processing_when_opening", "TRUE", &tmp_prefs
.enable_processing_when_opening
, P_BOOL
,
97 {"newmailcheck", "TRUE", &tmp_prefs
.newmailcheck
, P_BOOL
,
99 {"offlinesync", "FALSE", &tmp_prefs
.offlinesync
, P_BOOL
,
101 {"offlinesync_days", "0", &tmp_prefs
.offlinesync_days
, P_INT
,
103 {"remove_old_bodies", "FALSE", &tmp_prefs
.remove_old_bodies
, P_BOOL
,
105 {"promote_html_part", "0", &tmp_prefs
.promote_html_part
, P_ENUM
,
107 {"skip_on_goto_unread_or_new", "FALSE", &tmp_prefs
.skip_on_goto_unread_or_new
, P_BOOL
,
110 {"compose_with_format", "FALSE", &tmp_prefs
.compose_with_format
, P_BOOL
,
112 {"compose_override_from_format", NULL
, &tmp_prefs
.compose_override_from_format
, P_STRING
,
114 {"compose_subject_format", NULL
, &tmp_prefs
.compose_subject_format
, P_STRING
,
116 {"compose_body_format", NULL
, &tmp_prefs
.compose_body_format
, P_STRING
,
118 {"reply_with_format", "FALSE", &tmp_prefs
.reply_with_format
, P_BOOL
,
120 {"reply_override_from_format", NULL
, &tmp_prefs
.reply_override_from_format
, P_STRING
,
122 {"reply_quotemark", NULL
, &tmp_prefs
.reply_quotemark
, P_STRING
,
124 {"reply_body_format", NULL
, &tmp_prefs
.reply_body_format
, P_STRING
,
126 {"forward_with_format", "FALSE", &tmp_prefs
.forward_with_format
, P_BOOL
,
128 {"forward_override_from_format", NULL
, &tmp_prefs
.forward_override_from_format
, P_STRING
,
130 {"forward_quotemark", NULL
, &tmp_prefs
.forward_quotemark
, P_STRING
,
132 {"forward_body_format", NULL
, &tmp_prefs
.forward_body_format
, P_STRING
,
134 {"config_version", "-1", &tmp_prefs
.config_version
, P_INT
,
136 {NULL
, NULL
, NULL
, P_OTHER
, NULL
, NULL
, NULL
}
139 static FolderItemPrefs
*folder_item_prefs_clear(FolderItemPrefs
*prefs
);
141 void folder_item_prefs_read_config(FolderItem
* item
)
146 id
= folder_item_get_identifier(item
);
147 folder_item_prefs_clear(&tmp_prefs
);
148 rcpath
= g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S
, FOLDERITEM_RC
, NULL
);
149 prefs_read_config(param
, id
, rcpath
, NULL
);
153 *item
->prefs
= tmp_prefs
;
155 prefs_update_config_version_folder_item(item
);
158 void folder_item_prefs_save_config(FolderItem
* item
)
162 tmp_prefs
= * item
->prefs
;
164 id
= folder_item_get_identifier(item
);
168 debug_print("saving prefs for %s\n", id
);
169 prefs_write_config(param
, id
, FOLDERITEM_RC
);
173 static gboolean
folder_item_prefs_save_config_func(GNode
*node
, gpointer data
)
175 FolderItem
*item
= (FolderItem
*) node
->data
;
176 folder_item_prefs_save_config(item
);
180 void folder_item_prefs_save_config_recursive(FolderItem
* item
)
182 g_node_traverse(item
->node
, G_PRE_ORDER
, G_TRAVERSE_ALL
,
183 -1, folder_item_prefs_save_config_func
, NULL
);
186 void folder_prefs_save_config_recursive(Folder
*folder
)
188 g_node_traverse(folder
->node
, G_PRE_ORDER
, G_TRAVERSE_ALL
,
189 -1, folder_item_prefs_save_config_func
, NULL
);
192 static FolderItemPrefs
*folder_item_prefs_clear(FolderItemPrefs
*prefs
)
194 prefs
->enable_default_from
= FALSE
;
195 prefs
->default_from
= NULL
;
196 prefs
->enable_default_to
= FALSE
;
197 prefs
->default_to
= NULL
;
198 prefs
->enable_default_reply_to
= FALSE
;
199 prefs
->default_reply_to
= NULL
;
200 prefs
->enable_default_cc
= FALSE
;
201 prefs
->default_cc
= NULL
;
202 prefs
->enable_default_bcc
= FALSE
;
203 prefs
->default_bcc
= NULL
;
204 prefs
->enable_default_replyto
= FALSE
;
205 prefs
->default_replyto
= NULL
;
206 prefs
->enable_simplify_subject
= FALSE
;
207 prefs
->simplify_subject_regexp
= NULL
;
208 prefs
->enable_folder_chmod
= FALSE
;
209 prefs
->folder_chmod
= 0;
210 prefs
->enable_default_account
= FALSE
;
211 prefs
->default_account
= 0;
213 prefs
->enable_default_dictionary
= FALSE
;
214 prefs
->default_dictionary
= NULL
;
215 prefs
->enable_default_alt_dictionary
= FALSE
;
216 prefs
->default_alt_dictionary
= NULL
;
218 prefs
->always_sign
= SIGN_OR_ENCRYPT_DEFAULT
;
219 prefs
->always_encrypt
= SIGN_OR_ENCRYPT_DEFAULT
;
220 prefs
->save_copy_to_folder
= FALSE
;
222 prefs
->enable_processing
= FALSE
;
223 prefs
->enable_processing_when_opening
= FALSE
;
224 prefs
->processing
= NULL
;
225 prefs
->color
.red
= 0;
226 prefs
->color
.green
= 0;
227 prefs
->color
.blue
= 0;
228 prefs
->color
.alpha
= 1;
230 prefs
->newmailcheck
= TRUE
;
231 prefs
->offlinesync
= FALSE
;
232 prefs
->offlinesync_days
= 0;
233 prefs
->remove_old_bodies
= FALSE
;
234 prefs
->promote_html_part
= HTML_PROMOTE_DEFAULT
;
235 prefs
->skip_on_goto_unread_or_new
= FALSE
;
237 prefs
->compose_with_format
= FALSE
;
238 prefs
->compose_subject_format
= NULL
;
239 prefs
->compose_body_format
= NULL
;
240 prefs
->compose_override_from_format
= NULL
;
241 prefs
->reply_with_format
= FALSE
;
242 prefs
->reply_quotemark
= NULL
;
243 prefs
->reply_body_format
= NULL
;
244 prefs
->reply_override_from_format
= NULL
;
245 prefs
->forward_with_format
= FALSE
;
246 prefs
->forward_quotemark
= NULL
;
247 prefs
->forward_body_format
= NULL
;
248 prefs
->forward_override_from_format
= NULL
;
252 FolderItemPrefs
* folder_item_prefs_new(void)
254 FolderItemPrefs
* prefs
;
256 prefs
= g_new0(FolderItemPrefs
, 1);
258 return folder_item_prefs_clear(prefs
);
261 void folder_item_prefs_free(FolderItemPrefs
* prefs
)
263 g_free(prefs
->default_from
);
264 g_free(prefs
->default_to
);
265 g_free(prefs
->default_reply_to
);
266 g_free(prefs
->default_cc
);
267 g_free(prefs
->default_bcc
);
268 g_free(prefs
->default_replyto
);
269 g_free(prefs
->compose_subject_format
);
270 g_free(prefs
->compose_body_format
);
271 g_free(prefs
->compose_override_from_format
);
272 g_free(prefs
->reply_quotemark
);
273 g_free(prefs
->reply_body_format
);
274 g_free(prefs
->reply_override_from_format
);
275 g_free(prefs
->forward_quotemark
);
276 g_free(prefs
->forward_body_format
);
277 g_free(prefs
->forward_override_from_format
);
281 #define SAFE_STRING(str) \
284 void folder_item_prefs_copy_prefs(FolderItem
* src
, FolderItem
* dest
)
286 GSList
*tmp_prop_list
= NULL
, *tmp
;
287 folder_item_prefs_read_config(src
);
289 tmp_prefs
.directory
= g_strdup(src
->prefs
->directory
);
290 tmp_prefs
.enable_processing
= src
->prefs
->enable_processing
;
291 tmp_prefs
.enable_processing_when_opening
= src
->prefs
->enable_processing_when_opening
;
292 tmp_prefs
.newmailcheck
= src
->prefs
->newmailcheck
;
293 tmp_prefs
.offlinesync
= src
->prefs
->offlinesync
;
294 tmp_prefs
.offlinesync_days
= src
->prefs
->offlinesync_days
;
295 tmp_prefs
.remove_old_bodies
= src
->prefs
->remove_old_bodies
;
296 tmp_prefs
.promote_html_part
= src
->prefs
->promote_html_part
;
297 tmp_prefs
.skip_on_goto_unread_or_new
= src
->prefs
->skip_on_goto_unread_or_new
;
299 prefs_matcher_read_config();
301 for (tmp
= src
->prefs
->processing
; tmp
!= NULL
&& tmp
->data
!= NULL
;) {
302 FilteringProp
*prop
= (FilteringProp
*)tmp
->data
;
304 tmp_prop_list
= g_slist_append(tmp_prop_list
,
305 filteringprop_copy(prop
));
308 tmp_prefs
.processing
= tmp_prop_list
;
310 tmp_prefs
.request_return_receipt
= src
->prefs
->request_return_receipt
;
311 tmp_prefs
.enable_default_from
= src
->prefs
->enable_default_from
;
312 tmp_prefs
.default_from
= g_strdup(src
->prefs
->default_from
);
313 tmp_prefs
.enable_default_to
= src
->prefs
->enable_default_to
;
314 tmp_prefs
.default_to
= g_strdup(src
->prefs
->default_to
);
315 tmp_prefs
.enable_default_reply_to
= src
->prefs
->enable_default_reply_to
;
316 tmp_prefs
.default_reply_to
= g_strdup(src
->prefs
->default_reply_to
);
317 tmp_prefs
.enable_default_cc
= src
->prefs
->enable_default_cc
;
318 tmp_prefs
.default_cc
= g_strdup(src
->prefs
->default_cc
);
319 tmp_prefs
.enable_default_bcc
= src
->prefs
->enable_default_bcc
;
320 tmp_prefs
.default_bcc
= g_strdup(src
->prefs
->default_bcc
);
321 tmp_prefs
.enable_default_replyto
= src
->prefs
->enable_default_replyto
;
322 tmp_prefs
.default_replyto
= g_strdup(src
->prefs
->default_replyto
);
323 tmp_prefs
.enable_simplify_subject
= src
->prefs
->enable_simplify_subject
;
324 tmp_prefs
.simplify_subject_regexp
= g_strdup(src
->prefs
->simplify_subject_regexp
);
325 tmp_prefs
.enable_folder_chmod
= src
->prefs
->enable_folder_chmod
;
326 tmp_prefs
.folder_chmod
= src
->prefs
->folder_chmod
;
327 tmp_prefs
.enable_default_account
= src
->prefs
->enable_default_account
;
328 tmp_prefs
.default_account
= src
->prefs
->default_account
;
330 tmp_prefs
.enable_default_dictionary
= src
->prefs
->enable_default_dictionary
;
331 tmp_prefs
.default_dictionary
= g_strdup(src
->prefs
->default_dictionary
);
332 tmp_prefs
.enable_default_alt_dictionary
= src
->prefs
->enable_default_alt_dictionary
;
333 tmp_prefs
.default_alt_dictionary
= g_strdup(src
->prefs
->default_alt_dictionary
);
335 tmp_prefs
.always_sign
= src
->prefs
->always_sign
;
336 tmp_prefs
.always_encrypt
= src
->prefs
->always_encrypt
;
337 tmp_prefs
.save_copy_to_folder
= src
->prefs
->save_copy_to_folder
;
338 tmp_prefs
.color
= src
->prefs
->color
;
340 tmp_prefs
.compose_with_format
= src
->prefs
->compose_with_format
;
341 tmp_prefs
.compose_subject_format
= g_strdup(src
->prefs
->compose_subject_format
);
342 tmp_prefs
.compose_body_format
= g_strdup(src
->prefs
->compose_body_format
);
343 tmp_prefs
.compose_override_from_format
= g_strdup(src
->prefs
->compose_override_from_format
);
344 tmp_prefs
.reply_with_format
= src
->prefs
->reply_with_format
;
345 tmp_prefs
.reply_quotemark
= g_strdup(src
->prefs
->reply_quotemark
);
346 tmp_prefs
.reply_body_format
= g_strdup(src
->prefs
->reply_body_format
);
347 tmp_prefs
.reply_override_from_format
= g_strdup(src
->prefs
->reply_override_from_format
);
348 tmp_prefs
.forward_with_format
= src
->prefs
->forward_with_format
;
349 tmp_prefs
.forward_quotemark
= g_strdup(src
->prefs
->forward_quotemark
);
350 tmp_prefs
.forward_body_format
= g_strdup(src
->prefs
->forward_body_format
);
351 tmp_prefs
.forward_override_from_format
= g_strdup(src
->prefs
->forward_override_from_format
);
353 *dest
->prefs
= tmp_prefs
;
354 folder_item_prefs_save_config(dest
);
355 prefs_matcher_write_config();
357 dest
->collapsed
= src
->collapsed
;
358 dest
->thread_collapsed
= src
->thread_collapsed
;
359 dest
->threaded
= src
->threaded
;
360 dest
->ret_rcpt
= src
->ret_rcpt
;
361 dest
->hide_read_msgs
= src
->hide_read_msgs
;
362 dest
->hide_del_msgs
= src
->hide_del_msgs
;
363 dest
->hide_read_threads
= src
->hide_read_threads
;
364 dest
->sort_key
= src
->sort_key
;
365 dest
->sort_type
= src
->sort_type
;