2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2016 the Claws Mail team
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/>.
21 #include "claws-features.h"
25 #include <glib/gi18n.h>
33 #include "folder_item_prefs.h"
34 #include "prefs_account.h"
35 #include "prefs_common.h"
36 #include "alertpanel.h"
38 static gint starting_config_version = 0;
40 gboolean _version_check(gint ver)
42 if (ver > CLAWS_CONFIG_VERSION) {
47 markup = g_strdup_printf(
48 "<a href=\"%s\"><span underline=\"none\">",
50 msg = g_strdup_printf(
51 _("Your Claws Mail configuration is from a newer "
52 "version than the version which you are currently "
54 "This is not recommended.\n\n"
55 "For further information see the %sClaws Mail "
57 "Do you want to exit now?"),
58 markup, "</span></a>");
60 av = alertpanel_full(_("Configuration warning"), msg,
61 GTK_STOCK_NO, GTK_STOCK_YES, NULL, ALERTFOCUS_SECOND,
62 FALSE, NULL, ALERT_ERROR);
65 if (av != G_ALERTDEFAULT)
66 return FALSE; /* abort startup */
68 return TRUE; /* hic sunt dracones */
74 static void _update_config_common(gint version)
76 debug_print("Updating config version %d to %d.\n", version, version + 1);
81 /* The autochk_interval preference is now
82 * interpreted as seconds instead of minutes */
83 prefs_common.autochk_itv *= 60;
95 static void _update_config_account(PrefsAccount *ac_prefs, gint version)
97 debug_print("Account '%s': Updating config version from %d to %d.\n",
98 ac_prefs->account_name, version, version + 1);
103 /* Removing A_APOP and A_RPOP from RecvProtocol enum,
104 * protocol numbers above A_POP3 need to be adjusted.
106 * In config_version=0:
110 * A_IMAP and the rest are from 3 up.
111 * We can't use the macros, since they may change in the
112 * future. Numbers do not change. :) */
113 if (ac_prefs->protocol == 1) {
114 ac_prefs->protocol = 0;
115 } else if (ac_prefs->protocol > 2) {
116 /* A_IMAP and above gets bumped down by 2. */
117 ac_prefs->protocol -= 2;
124 /* Introducing per-account mail check intervals, and separating
125 * recv_at_getall from autocheck function.
127 * If recv_at_getall is TRUE, the account's autocheck will be
128 * enabled, following global autocheck interval.
130 * The account's own autocheck interval will be set to the
131 * same value as the global interval, but will not be used.
133 * recv_at_getall will remain enabled, but will only be used
134 * to determine whether or not to include this account for
135 * manual 'Get all' check. */
136 ac_prefs->autochk_itv = prefs_common_get_prefs()->autochk_itv;
137 ac_prefs->autochk_use_custom = FALSE;
138 if (ac_prefs->recv_at_getall) {
139 ac_prefs->autochk_use_default = TRUE;
141 ac_prefs->autochk_use_default = FALSE;
153 ac_prefs->config_version = version + 1;
156 static void _update_config_password_store(gint version)
158 debug_print("Password store: Updating config version from %d to %d.\n",
159 version, version + 1);
162 /* nothing here yet */
172 static void _update_config_folderlist(gint version)
174 debug_print("Folderlist: Updating config version from %d to %d.\n",
175 version, version + 1);
178 /* nothing here yet */
188 static void _update_config_folder_item(FolderItem *item,
191 debug_print("Updating config_version from %d to %d.\n",
192 version, version + 1);
195 /* nothing here yet */
205 int prefs_update_config_version_common()
207 gint ver = prefs_common_get_prefs()->config_version;
209 /* Store the starting version number for other components'
210 * migration functions. */
211 starting_config_version = ver;
213 if (!_version_check(ver))
216 debug_print("Starting config update at config_version %d.\n", ver);
217 if (ver == CLAWS_CONFIG_VERSION) {
218 debug_print("No update necessary, already at latest config_version.\n");
219 return 0; /* nothing to do */
222 while (ver < CLAWS_CONFIG_VERSION) {
223 _update_config_common(ver++);
224 prefs_common_get_prefs()->config_version = ver;
227 debug_print("Config update done.\n");
228 return 1; /* update done */
231 int prefs_update_config_version_accounts()
234 PrefsAccount *ac_prefs;
236 for (cur = account_get_list(); cur != NULL; cur = cur->next) {
237 ac_prefs = (PrefsAccount *)cur->data;
239 if (ac_prefs->config_version == -1) {
240 /* There was no config_version stored in the config, let's
241 * assume config_version same as what clawsrc started at
242 * this session, to avoid breaking the configuration by
243 * "upgrading" it unnecessarily. */
244 debug_print("Account '%s': config_version not saved, using one from clawsrc: %d\n", ac_prefs->account_name, starting_config_version);
245 ac_prefs->config_version = starting_config_version;
248 gint ver = ac_prefs->config_version;
250 debug_print("Account '%s': Starting config update at config_version %d.\n", ac_prefs->account_name, ver);
252 if (!_version_check(ver))
255 if (ver == CLAWS_CONFIG_VERSION) {
256 debug_print("Account '%s': No update necessary, already at latest config_version.\n", ac_prefs->account_name);
260 while (ver < CLAWS_CONFIG_VERSION) {
261 _update_config_account(ac_prefs, ver++);
265 debug_print("Accounts config update done.\n");
269 int prefs_update_config_version_password_store(gint from_version)
271 gint ver = from_version;
274 /* There was no config_version stored in the config, let's assume
275 * config_version same as what clawsrc started at this session,
276 * to avoid breaking the configuration by "upgrading" it unnecessarily. */
277 debug_print("Password store: config_version not saved, using one from clawsrc: %d\n", starting_config_version);
278 ver = starting_config_version;
281 debug_print("Starting config update at config_version %d.\n", ver);
283 if (!_version_check(ver))
286 if (ver == CLAWS_CONFIG_VERSION) {
287 debug_print("No update necessary, already at latest config_version.\n");
288 return 0; /* nothing to do */
291 while (ver < CLAWS_CONFIG_VERSION) {
292 _update_config_password_store(ver++);
295 debug_print("Passwordstore config update done.\n");
299 int prefs_update_config_version_folderlist(gint from_version)
301 gint ver = from_version;
304 /* There was no config_version stored in the config, let's assume
305 * config_version same as what clawsrc started at this session,
306 * to avoid breaking the configuration by "upgrading" it unnecessarily. */
307 debug_print("Folderlist: config_version not saved, using one from clawsrc: %d\n", starting_config_version);
308 ver = starting_config_version;
311 debug_print("Starting config_update at config_version %d,\n", ver);
313 if (!_version_check(ver))
316 if (ver == CLAWS_CONFIG_VERSION) {
317 debug_print("No update necessary, already at latest config_version.\n");
318 return 0; /* nothing to do */
321 while (ver < CLAWS_CONFIG_VERSION) {
322 _update_config_folderlist(ver++);
325 debug_print("Folderlist config update done.\n");
329 int prefs_update_config_version_folder_item(FolderItem *item)
334 cm_return_val_if_fail(item != NULL, 0);
336 id = folder_item_get_identifier(item);
338 if (item->prefs->config_version == -1) {
339 /* There was no config_version stored in the config, let's assume
340 * config_version same as what clawsrc started at this session,
341 * to avoid breaking the configuration by "upgrading" it unnecessarily. */
342 debug_print("Folder item '%s': config_version not saved, using one from clawsrc: %d\n", id, starting_config_version);
343 item->prefs->config_version = starting_config_version;
346 ver = item->prefs->config_version;
348 if (!_version_check(ver)) {
353 if (ver == CLAWS_CONFIG_VERSION) {
354 debug_print("Folder item '%s': No update necessary, already at latest config_version %d.\n", id, ver);
356 return 0; /* nothing to do */
359 debug_print("Folder item '%s': starting config_update at version %d.\n",
363 while (ver < CLAWS_CONFIG_VERSION) {
364 _update_config_folder_item(item, ver++);
367 debug_print("Folder item config update done.\n");