2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with the program; if not, see <http://www.gnu.org/licenses/>
17 * Jeffrey Stedfast <fejj@ximian.com>
18 * Radek Doulik <rodo@ximian.com>
19 * Jonathon Jongsma <jonathon.jongsma@collabora.co.uk>
21 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22 * Copyright (C) 2009 Intel Corporation
32 #include <libedataserver/e-data-server-util.h>
34 #include <libemail-utils/e-account-utils.h>
35 #include <libemail-utils/e-signature-utils.h>
37 #include "e-mail-folder-utils.h"
38 #include "mail-config.h"
39 #include "mail-tools.h"
44 gboolean address_compress
;
50 gboolean book_lookup_local_only
;
53 extern gint camel_header_param_encode_filenames_in_rfc_2047
;
55 static MailConfig
*config
= NULL
;
56 static GSettings
*mail_settings
= NULL
;
59 settings_outlook_filenames_changed (GSettings
*settings
,
63 /* pass option to the camel */
64 if (g_settings_get_boolean (settings
, key
))
65 camel_header_param_encode_filenames_in_rfc_2047
= 1;
67 camel_header_param_encode_filenames_in_rfc_2047
= 0;
71 settings_jh_headers_changed (GSettings
*settings
,
73 EMailSession
*session
)
76 GPtrArray
*name
, *value
;
80 g_slist_foreach (config
->jh_header
, (GFunc
) g_free
, NULL
);
81 g_slist_free (config
->jh_header
);
82 config
->jh_header
= NULL
;
84 strv
= g_settings_get_strv (settings
, "junk-custom-header");
85 for (i
= 0; strv
[i
] != NULL
; i
++)
86 config
->jh_header
= g_slist_append (config
->jh_header
, g_strdup (strv
[i
]));
89 node
= config
->jh_header
;
90 name
= g_ptr_array_new ();
91 value
= g_ptr_array_new ();
92 while (node
&& node
->data
) {
93 gchar
**tok
= g_strsplit (node
->data
, "=", 2);
94 g_ptr_array_add (name
, g_strdup (tok
[0]));
95 g_ptr_array_add (value
, g_strdup (tok
[1]));
99 camel_session_set_junk_headers (
100 CAMEL_SESSION (session
),
101 (const gchar
**) name
->pdata
,
102 (const gchar
**) value
->pdata
, name
->len
);
104 g_ptr_array_foreach (name
, (GFunc
) g_free
, NULL
);
105 g_ptr_array_foreach (value
, (GFunc
) g_free
, NULL
);
106 g_ptr_array_free (name
, TRUE
);
107 g_ptr_array_free (value
, TRUE
);
111 settings_jh_check_changed (GSettings
*settings
,
113 EMailSession
*session
)
115 config
->jh_check
= g_settings_get_boolean (settings
, "junk-check-custom-header");
116 if (!config
->jh_check
) {
117 camel_session_set_junk_headers (
118 CAMEL_SESSION (session
), NULL
, NULL
, 0);
120 settings_jh_headers_changed (settings
, NULL
, session
);
125 settings_bool_value_changed (GSettings
*settings
,
127 gboolean
*save_location
)
129 *save_location
= g_settings_get_boolean (settings
, key
);
133 settings_int_value_changed (GSettings
*settings
,
137 *save_location
= g_settings_get_int (settings
, key
);
141 mail_config_write (void)
143 EAccountList
*account_list
;
144 ESignatureList
*signature_list
;
149 account_list
= e_get_account_list ();
150 signature_list
= e_get_signature_list ();
152 e_account_list_save (account_list
);
153 e_signature_list_save (signature_list
);
159 mail_config_get_address_count (void)
161 if (!config
->address_compress
)
164 return config
->address_count
;
167 /* timeout interval, in seconds, when to call server update */
169 mail_config_get_sync_timeout (void)
173 res
= g_settings_get_int (mail_settings
, "sync-interval");
175 /* do not allow recheck sooner than every 30 seconds */
185 mail_config_folder_to_cachename (CamelFolder
*folder
,
188 gchar
*folder_uri
, *basename
, *filename
;
189 const gchar
*config_dir
;
191 config_dir
= mail_session_get_config_dir ();
193 basename
= g_build_filename (config_dir
, "folders", NULL
);
194 if (!g_file_test (basename
, G_FILE_TEST_EXISTS
| G_FILE_TEST_IS_DIR
)) {
195 /* create the folder if does not exist */
196 g_mkdir_with_parents (basename
, 0700);
200 folder_uri
= e_mail_folder_uri_from_folder (folder
);
201 e_filename_make_safe (folder_uri
);
202 basename
= g_strdup_printf ("%s%s", prefix
, folder_uri
);
203 filename
= g_build_filename (config_dir
, "folders", basename
, NULL
);
211 mail_config_reload_junk_headers (EMailSession
*session
)
213 g_return_if_fail (E_IS_MAIL_SESSION (session
));
215 /* It automatically sets in the session */
217 mail_config_init (session
);
219 settings_jh_check_changed (mail_settings
, NULL
, session
);
224 mail_config_get_lookup_book (void)
226 g_return_val_if_fail (config
!= NULL
, FALSE
);
228 return config
->book_lookup
;
232 mail_config_get_lookup_book_local_only (void)
234 g_return_val_if_fail (config
!= NULL
, FALSE
);
236 return config
->book_lookup_local_only
;
239 /* Config struct routines */
241 mail_config_init (EMailSession
*session
)
243 g_return_if_fail (E_IS_MAIL_SESSION (session
));
248 config
= g_new0 (MailConfig
, 1);
250 mail_settings
= g_settings_new ("org.gnome.evolution.mail");
252 /* Composer Configuration */
254 settings_outlook_filenames_changed (
255 mail_settings
, "composer-outlook-filenames", NULL
);
257 mail_settings
, "changed::composer-outlook-filenames",
258 G_CALLBACK (settings_outlook_filenames_changed
), NULL
);
260 /* Display Configuration */
263 mail_settings
, "changed::address-compress",
264 G_CALLBACK (settings_bool_value_changed
),
265 &config
->address_compress
);
266 config
->address_compress
= g_settings_get_boolean (
267 mail_settings
, "address-compress");
270 mail_settings
, "changed::address-count",
271 G_CALLBACK (settings_int_value_changed
),
272 &config
->address_count
);
273 config
->address_count
= g_settings_get_int (
274 mail_settings
, "address-count");
276 /* Junk Configuration */
279 mail_settings
, "changed::junk-check-custom-header",
280 G_CALLBACK (settings_jh_check_changed
), session
);
281 config
->jh_check
= g_settings_get_boolean (
282 mail_settings
, "junk-check-custom-header");
285 mail_settings
, "changed::junk-custom-header",
286 G_CALLBACK (settings_jh_headers_changed
), session
);
289 mail_settings
, "changed::junk-lookup-addressbook",
290 G_CALLBACK (settings_bool_value_changed
), &config
->book_lookup
);
291 config
->book_lookup
= g_settings_get_boolean (
292 mail_settings
, "junk-lookup-addressbook");
295 mail_settings
, "changed::junk-lookup-addressbook-local-only",
296 G_CALLBACK (settings_bool_value_changed
),
297 &config
->book_lookup_local_only
);
298 config
->book_lookup_local_only
= g_settings_get_boolean (
299 mail_settings
, "junk-lookup-addressbook-local-only");
301 settings_jh_check_changed (mail_settings
, NULL
, session
);