2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2004-2015 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"
26 #include <glib/gi18n.h>
28 #include <gtk/filesel.h>
31 #include "gtk/gtkutils.h"
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
36 #include "prefs_gpg.h"
39 struct GPGConfig prefs_gpg;
41 static PrefParam param[] = {
43 {"auto_check_signatures", "FALSE",
44 &prefs_gpg.auto_check_signatures, P_BOOL,
46 {"autocompletion", "FALSE",
47 &prefs_gpg.autocompletion, P_BOOL,
49 {"autocompletion_limit", "0",
50 &prefs_gpg.autocompletion_limit, P_INT,
52 {"use_gpg_agent", "TRUE", &prefs_gpg.use_gpg_agent, P_BOOL,
54 {"store_passphrase", "FALSE", &prefs_gpg.store_passphrase, P_BOOL,
56 {"store_passphrase_timeout", "0",
57 &prefs_gpg.store_passphrase_timeout, P_INT,
59 {"passphrase_grab", "FALSE", &prefs_gpg.passphrase_grab, P_BOOL,
61 {"gpg_warning", "TRUE", &prefs_gpg.gpg_warning, P_BOOL,
63 {"gpg_ask_create_key", "TRUE", &prefs_gpg.gpg_ask_create_key, P_BOOL,
65 {"skip_encryption_warning", "", &prefs_gpg.skip_encryption_warning, P_STRING,
67 {"gpg_path", "", &prefs_gpg.gpg_path, P_STRING,
70 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
73 static gchar *saved_gpg_agent_info = NULL;
74 static void gpg_path_browse_cb(GtkWidget *widget, gpointer data);
80 GtkWidget *checkbtn_auto_check_signatures;
81 GtkWidget *checkbtn_autocompletion;
82 GtkWidget *checkbtn_use_gpg_agent;
83 GtkWidget *checkbtn_store_passphrase;
84 GtkWidget *spinbtn_store_passphrase;
85 GtkWidget *checkbtn_passphrase_grab;
86 GtkWidget *checkbtn_gpg_warning;
90 static void prefs_gpg_create_widget_func(PrefsPage *_page,
94 struct GPGPage *page = (struct GPGPage *) _page;
95 struct GPGConfig *config;
97 GtkWidget *checkbtn_use_gpg_agent;
98 GtkWidget *checkbtn_passphrase_grab;
99 GtkWidget *checkbtn_store_passphrase;
100 GtkWidget *checkbtn_auto_check_signatures;
101 GtkWidget *checkbtn_autocompletion;
102 GtkWidget *checkbtn_gpg_warning;
103 GtkWidget *hbox1, *hbox2;
104 GtkWidget *vbox1, *vbox2;
105 GtkWidget *label_gpg_path;
106 GtkWidget *label_expire1;
107 GtkAdjustment *spinbtn_store_passphrase_adj;
108 GtkWidget *spinbtn_store_passphrase;
109 GtkWidget *label_expire2;
110 GtkWidget *frame_passphrase;
111 GtkWidget *gpg_path, *gpg_path_btn;
113 vbox1 = gtk_vbox_new (FALSE, VSPACING);
114 gtk_widget_show (vbox1);
115 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
117 vbox2 = gtk_vbox_new (FALSE, 0);
118 gtk_widget_show (vbox2);
119 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
121 PACK_CHECK_BUTTON (vbox2, checkbtn_auto_check_signatures,
122 _("Automatically check signatures"));
124 PACK_CHECK_BUTTON (vbox2, checkbtn_autocompletion,
125 _("Use keyring for address autocompletion"));
127 vbox2 = gtkut_get_options_frame(vbox1, &frame_passphrase, _("Passphrase"));
129 PACK_CHECK_BUTTON (vbox2, checkbtn_use_gpg_agent,
130 _("Use gpg-agent to manage passwords"));
131 if (saved_gpg_agent_info == NULL)
132 gtk_widget_set_sensitive(checkbtn_use_gpg_agent, FALSE);
134 PACK_CHECK_BUTTON (vbox2, checkbtn_store_passphrase,
135 _("Store passphrase in memory"));
137 SET_TOGGLE_SENSITIVITY_REVERSE(checkbtn_use_gpg_agent, checkbtn_store_passphrase);
139 hbox1 = gtk_hbox_new (FALSE, 8);
140 gtk_widget_show (hbox1);
141 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
143 SET_TOGGLE_SENSITIVITY_REVERSE(checkbtn_use_gpg_agent, hbox1);
145 label_expire1 = gtk_label_new(_("Expire after"));
146 gtk_widget_show (label_expire1);
147 gtk_box_pack_start (GTK_BOX (hbox1), label_expire1, FALSE, FALSE, 0);
149 spinbtn_store_passphrase_adj =
150 GTK_ADJUSTMENT(gtk_adjustment_new(1, 0, 1440, 1, 10, 0));
151 spinbtn_store_passphrase =
152 gtk_spin_button_new(GTK_ADJUSTMENT
153 (spinbtn_store_passphrase_adj), 1, 0);
154 gtk_widget_show(spinbtn_store_passphrase);
155 gtk_box_pack_start(GTK_BOX(hbox1), spinbtn_store_passphrase, FALSE,
157 gtk_widget_set_size_request(spinbtn_store_passphrase, 64, -1);
158 CLAWS_SET_TIP(spinbtn_store_passphrase,
159 _("Setting to '0' will store the passphrase for the whole session"));
160 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON
161 (spinbtn_store_passphrase), TRUE);
163 label_expire2 = gtk_label_new(_("minute(s)"));
164 gtk_widget_show(label_expire2);
165 gtk_box_pack_start(GTK_BOX(hbox1), label_expire2, FALSE, FALSE, 0);
166 gtk_misc_set_alignment(GTK_MISC(label_expire2), 0.0, 0.5);
168 SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, label_expire1);
169 SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, spinbtn_store_passphrase);
170 SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, label_expire2);
172 PACK_CHECK_BUTTON (vbox2, checkbtn_passphrase_grab,
173 _("Grab input while entering a passphrase"));
175 vbox2 = gtk_vbox_new (FALSE, 0);
176 gtk_widget_show (vbox2);
177 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
179 PACK_CHECK_BUTTON (vbox2, checkbtn_gpg_warning,
180 _("Display warning on start-up if GnuPG doesn't work"));
182 hbox2 = gtk_hbox_new(FALSE, 6);
183 label_gpg_path = gtk_label_new(_("Path to GnuPG executable"));
184 gtk_box_pack_start(GTK_BOX(hbox2), label_gpg_path, FALSE, FALSE, 0);
185 gpg_path = gtk_entry_new();
186 gtk_box_pack_start(GTK_BOX(hbox2), gpg_path, TRUE, TRUE, 0);
187 CLAWS_SET_TIP(gpg_path,
188 _("If left blank the location of the GnuPG executable will be automatically determined."));
189 gpg_path_btn = gtkut_get_browse_file_btn(_("Bro_wse"));
190 gtk_box_pack_start(GTK_BOX(hbox2), gpg_path_btn, FALSE, FALSE, 0);
191 g_signal_connect(G_OBJECT(gpg_path_btn), "clicked",
192 G_CALLBACK(gpg_path_browse_cb), gpg_path);
193 pref_set_entry_from_pref(GTK_ENTRY(gpg_path), prefs_gpg.gpg_path);
195 gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
196 gtk_widget_show_all(vbox1);
198 config = prefs_gpg_get_config();
200 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_auto_check_signatures), config->auto_check_signatures);
201 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_autocompletion), config->autocompletion);
202 if (!g_getenv("GPG_AGENT_INFO"))
203 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_gpg_agent), FALSE);
205 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_gpg_agent), config->use_gpg_agent);
206 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbtn_use_gpg_agent)))
207 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_store_passphrase), config->store_passphrase);
208 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_store_passphrase), (float) config->store_passphrase_timeout);
209 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_passphrase_grab), config->passphrase_grab);
210 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_gpg_warning), config->gpg_warning);
211 gtk_entry_set_text(GTK_ENTRY(gpg_path), config->gpg_path);
213 page->checkbtn_auto_check_signatures = checkbtn_auto_check_signatures;
214 page->checkbtn_autocompletion = checkbtn_autocompletion;
215 page->checkbtn_store_passphrase = checkbtn_store_passphrase;
216 page->spinbtn_store_passphrase = spinbtn_store_passphrase;
217 page->checkbtn_passphrase_grab = checkbtn_passphrase_grab;
218 page->checkbtn_gpg_warning = checkbtn_gpg_warning;
219 page->checkbtn_use_gpg_agent = checkbtn_use_gpg_agent;
220 page->gpg_path = gpg_path;
221 page->page.widget = vbox1;
224 static void gpg_path_browse_cb(GtkWidget* widget, gpointer data)
227 GtkEntry *dest = GTK_ENTRY(data);
229 filename = filesel_select_file_open(_("Select GnuPG executable"), NULL);
233 gtk_entry_set_text(GTK_ENTRY(dest), filename);
237 static void prefs_gpg_destroy_widget_func(PrefsPage *_page)
241 static void prefs_gpg_save_func(PrefsPage *_page)
243 struct GPGPage *page = (struct GPGPage *) _page;
244 GPGConfig *config = prefs_gpg_get_config();
246 config->auto_check_signatures =
247 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_auto_check_signatures));
248 config->autocompletion =
249 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autocompletion));
250 config->use_gpg_agent =
251 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_use_gpg_agent));
252 config->store_passphrase =
253 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_store_passphrase));
254 config->store_passphrase_timeout =
255 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_store_passphrase));
256 config->passphrase_grab =
257 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_passphrase_grab));
258 config->gpg_warning =
259 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_gpg_warning));
260 g_free(config->gpg_path);
261 config->gpg_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->gpg_path)));
262 if (strcmp(config->gpg_path, "") != 0 && access(config->gpg_path, X_OK) != -1)
263 gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, config->gpg_path, NULL);
265 prefs_gpg_enable_agent(config->use_gpg_agent);
267 prefs_gpg_save_config();
270 struct GPGAccountPage
274 GtkWidget *key_default;
275 GtkWidget *key_by_from;
276 GtkWidget *key_custom;
278 GtkWidget *keyid_label;
279 GtkWidget *new_key_label;
280 GtkWidget *new_key_btn;
281 GtkWidget *new_key_box;
283 PrefsAccount *account;
286 void key_custom_toggled(GtkToggleButton *togglebutton, gpointer user_data)
288 struct GPGAccountPage *page = (struct GPGAccountPage *) user_data;
291 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_custom));
292 gtk_widget_set_sensitive(GTK_WIDGET(page->keyid_label), active);
293 gtk_widget_set_sensitive(GTK_WIDGET(page->keyid), active);
295 gtk_editable_delete_text(GTK_EDITABLE(page->keyid), 0, -1);
298 static void prefs_gpg_update_sens(struct GPGAccountPage *page)
301 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_custom));
302 if (sgpgme_has_secret_key()) {
303 gtk_widget_hide(page->new_key_box);
304 gtk_widget_set_sensitive(page->key_default, TRUE);
305 gtk_widget_set_sensitive(page->key_by_from, TRUE);
306 gtk_widget_set_sensitive(page->key_custom, TRUE);
307 gtk_widget_set_sensitive(page->keyid, active);
308 gtk_widget_set_sensitive(page->keyid_label, active);
310 gtk_widget_show(page->new_key_box);
311 gtk_widget_set_sensitive(page->key_default, FALSE);
312 gtk_widget_set_sensitive(page->key_by_from, FALSE);
313 gtk_widget_set_sensitive(page->key_custom, FALSE);
314 gtk_widget_set_sensitive(page->keyid, FALSE);
315 gtk_widget_set_sensitive(page->keyid_label, FALSE);
319 static void new_key_clicked(GtkWidget *widget, gpointer user_data)
321 struct GPGAccountPage *page = (struct GPGAccountPage *) user_data;
322 sgpgme_create_secret_key(page->account, FALSE);
323 prefs_gpg_update_sens(page);
326 static void prefs_gpg_account_create_widget_func(PrefsPage *_page,
330 struct GPGAccountPage *page = (struct GPGAccountPage *) _page;
331 PrefsAccount *account = (PrefsAccount *) data;
332 GPGAccountConfig *config;
338 GSList *key_group = NULL;
339 GtkWidget *key_default;
340 GtkWidget *key_by_from;
341 GtkWidget *key_custom;
342 GtkWidget *keyid_label;
345 GtkWidget *new_key_label;
346 GtkWidget *new_key_btn;
347 GtkWidget *new_key_box;
349 vbox = gtk_vbox_new(FALSE, VSPACING);
350 gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
351 gtk_widget_show(vbox);
353 vbox2 = gtkut_get_options_frame(vbox, &frame1, _("Sign key"));
355 hbox = gtk_hbox_new (FALSE, 5);
356 gtk_widget_show (hbox);
357 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
358 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
360 key_default = gtk_radio_button_new_with_label(key_group,
361 _("Use default GnuPG key"));
362 key_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(key_default));
363 gtk_widget_show(key_default);
364 gtk_box_pack_start(GTK_BOX(hbox), key_default, FALSE, FALSE, 0);
366 hbox = gtk_hbox_new (FALSE, 5);
367 gtk_widget_show (hbox);
368 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
369 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
371 key_by_from = gtk_radio_button_new_with_label(key_group,
372 _("Select key by your email address"));
373 key_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(key_by_from));
374 gtk_widget_show(key_by_from);
375 gtk_box_pack_start(GTK_BOX(hbox), key_by_from, FALSE, FALSE, 0);
377 hbox = gtk_hbox_new (FALSE, 5);
378 gtk_widget_show (hbox);
379 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
380 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
382 key_custom = gtk_radio_button_new_with_label(key_group,
383 _("Specify key manually"));
384 key_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(key_custom));
385 gtk_widget_show(key_custom);
386 gtk_box_pack_start(GTK_BOX(hbox), key_custom, FALSE, FALSE, 0);
388 hbox = gtk_hbox_new (FALSE, 5);
389 gtk_widget_show (hbox);
390 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
391 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
393 keyid_label = gtk_label_new(_("User or key ID:"));
394 gtk_widget_show(keyid_label);
395 gtk_label_set_justify(GTK_LABEL(keyid_label), GTK_JUSTIFY_LEFT);
396 gtk_box_pack_start(GTK_BOX(hbox), keyid_label, FALSE, FALSE, 0);
398 keyid = gtk_entry_new();
399 gtk_widget_show(keyid);
400 gtk_box_pack_start(GTK_BOX(hbox), keyid, FALSE, FALSE, 0);
402 config = prefs_gpg_account_get_config(account);
403 switch (config->sign_key) {
404 case SIGN_KEY_DEFAULT:
405 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(key_default), TRUE);
406 gtk_widget_set_sensitive(GTK_WIDGET(keyid_label), FALSE);
407 gtk_widget_set_sensitive(GTK_WIDGET(keyid), FALSE);
409 case SIGN_KEY_BY_FROM:
410 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(key_by_from), TRUE);
411 gtk_widget_set_sensitive(GTK_WIDGET(keyid_label), FALSE);
412 gtk_widget_set_sensitive(GTK_WIDGET(keyid), FALSE);
414 case SIGN_KEY_CUSTOM:
415 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(key_custom), TRUE);
416 gtk_widget_set_sensitive(GTK_WIDGET(keyid_label), TRUE);
417 gtk_widget_set_sensitive(GTK_WIDGET(keyid), TRUE);
421 hbox = gtk_hbox_new (FALSE, 5);
422 gtk_widget_show (hbox);
423 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
425 new_key_box = gtk_hbox_new(FALSE, 6);
426 gtk_widget_show(new_key_box);
427 gtk_box_pack_start(GTK_BOX(hbox), new_key_box, FALSE, FALSE, 0);
429 image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
430 GTK_ICON_SIZE_SMALL_TOOLBAR);
432 gtk_box_pack_start(GTK_BOX(new_key_box), image, FALSE, FALSE, 0);
433 new_key_label = gtk_label_new(
434 _("No secret key found."));
435 gtk_box_pack_start(GTK_BOX(new_key_box), new_key_label, FALSE, FALSE, 0);
437 new_key_btn = gtk_button_new_with_label(_("Generate a new key pair"));
438 gtk_widget_show(new_key_btn);
439 gtk_box_pack_start(GTK_BOX(hbox), new_key_btn, FALSE, FALSE, 0);
441 if (config->sign_key_id != NULL)
442 gtk_entry_set_text(GTK_ENTRY(keyid), config->sign_key_id);
444 g_signal_connect(G_OBJECT(key_custom), "toggled", G_CALLBACK(key_custom_toggled), page);
445 g_signal_connect(G_OBJECT(new_key_btn), "clicked", G_CALLBACK(new_key_clicked), page);
447 page->key_default = key_default;
448 page->key_by_from = key_by_from;
449 page->key_custom = key_custom;
451 page->keyid_label = keyid_label;
452 page->new_key_box = new_key_box;
454 page->page.widget = vbox;
455 page->account = account;
456 prefs_gpg_update_sens(page);
459 static void prefs_gpg_account_destroy_widget_func(PrefsPage *_page)
461 /* nothing to do here */
464 static void prefs_gpg_account_save_func(PrefsPage *_page)
466 struct GPGAccountPage *page = (struct GPGAccountPage *) _page;
467 GPGAccountConfig *config;
469 config = prefs_gpg_account_get_config(page->account);
471 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_default)))
472 config->sign_key = SIGN_KEY_DEFAULT;
473 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_by_from)))
474 config->sign_key = SIGN_KEY_BY_FROM;
475 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_custom))) {
476 config->sign_key = SIGN_KEY_CUSTOM;
477 g_free(config->sign_key_id);
478 config->sign_key_id = gtk_editable_get_chars(GTK_EDITABLE(page->keyid), 0, -1);
481 prefs_gpg_account_set_config(page->account, config);
482 prefs_gpg_account_free_config(config);
485 GPGConfig *prefs_gpg_get_config(void)
490 void prefs_gpg_save_config(void)
495 debug_print("Saving GPG config\n");
497 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
498 pfile = prefs_write_open(rcpath);
500 if (!pfile || (prefs_set_block_label(pfile, "GPG") < 0))
503 if (prefs_write_param(param, pfile->fp) < 0) {
504 g_warning("failed to write GPG configuration to file");
505 prefs_file_close_revert(pfile);
508 if (fprintf(pfile->fp, "\n") < 0) {
509 FILE_OP_ERROR(rcpath, "fprintf");
510 prefs_file_close_revert(pfile);
512 prefs_file_close(pfile);
515 struct GPGAccountConfig *prefs_gpg_account_get_config(PrefsAccount *account)
517 GPGAccountConfig *config;
518 const gchar *confstr;
521 config = g_new0(GPGAccountConfig, 1);
522 config->sign_key = SIGN_KEY_DEFAULT;
523 config->sign_key_id = NULL;
525 confstr = prefs_account_get_privacy_prefs(account, "gpg");
529 strv = g_strsplit(confstr, ";", 0);
530 if (strv[0] != NULL) {
531 if (!strcmp(strv[0], "DEFAULT"))
532 config->sign_key = SIGN_KEY_DEFAULT;
533 if (!strcmp(strv[0], "BY_FROM"))
534 config->sign_key = SIGN_KEY_BY_FROM;
535 if (!strcmp(strv[0], "CUSTOM")) {
536 if (strv[1] != NULL) {
537 config->sign_key = SIGN_KEY_CUSTOM;
538 config->sign_key_id = g_strdup(strv[1]);
540 config->sign_key = SIGN_KEY_DEFAULT;
548 void prefs_gpg_account_set_config(PrefsAccount *account, GPGAccountConfig *config)
550 gchar *confstr = NULL;
552 switch (config->sign_key) {
553 case SIGN_KEY_DEFAULT:
554 confstr = g_strdup("DEFAULT");
556 case SIGN_KEY_BY_FROM:
557 confstr = g_strdup("BY_FROM");
559 case SIGN_KEY_CUSTOM:
560 confstr = g_strdup_printf("CUSTOM;%s", config->sign_key_id);
563 confstr = g_strdup("");
564 g_warning("prefs_gpg_account_set_config: bad sign_key val");
567 prefs_account_set_privacy_prefs(account, "gpg", confstr);
572 void prefs_gpg_account_free_config(GPGAccountConfig *config)
574 g_free(config->sign_key_id);
578 static struct GPGPage gpg_page;
579 static struct GPGAccountPage gpg_account_page;
581 void prefs_gpg_enable_agent(gboolean enable)
584 if (saved_gpg_agent_info) {
585 g_setenv("GPG_AGENT_INFO",
586 saved_gpg_agent_info, TRUE);
587 debug_print("set GPG_AGENT_INFO=%s\n",
588 saved_gpg_agent_info);
590 debug_print("Can't enable gpg agent (no GPG_AGENT_INFO)\n");
593 if (saved_gpg_agent_info) {
594 g_unsetenv("GPG_AGENT_INFO");
595 debug_print("unset GPG_AGENT_INFO=%s\n",
596 saved_gpg_agent_info);
598 debug_print("Can't disable gpg agent (no GPG_AGENT_INFO)\n");
603 void prefs_gpg_init()
605 static gchar *path[3];
607 const gchar *tmp = NULL;
609 prefs_set_default(param);
610 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
611 prefs_read_config(param, "GPG", rcpath, NULL);
614 path[0] = _("Plugins");
618 gpg_page.page.path = path;
619 gpg_page.page.create_widget = prefs_gpg_create_widget_func;
620 gpg_page.page.destroy_widget = prefs_gpg_destroy_widget_func;
621 gpg_page.page.save_page = prefs_gpg_save_func;
622 gpg_page.page.weight = 30.0;
624 prefs_gtk_register_page((PrefsPage *) &gpg_page);
626 gpg_account_page.page.path = path;
627 gpg_account_page.page.create_widget = prefs_gpg_account_create_widget_func;
628 gpg_account_page.page.destroy_widget = prefs_gpg_account_destroy_widget_func;
629 gpg_account_page.page.save_page = prefs_gpg_account_save_func;
630 gpg_account_page.page.weight = 30.0;
632 prefs_account_register_page((PrefsPage *) &gpg_account_page);
634 tmp = g_getenv("GPG_AGENT_INFO");
636 saved_gpg_agent_info = g_strdup(tmp);
638 prefs_gpg_enable_agent(prefs_gpg_get_config()->use_gpg_agent);
641 void prefs_gpg_done()
643 prefs_gtk_unregister_page((PrefsPage *) &gpg_page);
644 prefs_account_unregister_page((PrefsPage *) &gpg_account_page);
645 prefs_gpg_enable_agent(TRUE);
648 gboolean prefs_gpg_should_skip_encryption_warning(const gchar *systemid)
650 gchar **systems = NULL;
652 if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
654 systems = g_strsplit(prefs_gpg_get_config()->skip_encryption_warning,
656 while (systems && systems[i]) {
657 debug_print(" cmp %s %s\n", systems[i], systemid);
658 if (!strcmp(systems[i],systemid)) {
668 void prefs_gpg_add_skip_encryption_warning(const gchar *systemid)
671 if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
672 prefs_gpg_get_config()->skip_encryption_warning =
673 g_strdup_printf("%s,", systemid);
674 else if (!prefs_gpg_should_skip_encryption_warning(systemid)) {
675 tmp = g_strdup_printf("%s%s,",
676 prefs_gpg_get_config()->skip_encryption_warning,
678 g_free(prefs_gpg_get_config()->skip_encryption_warning);
679 prefs_gpg_get_config()->skip_encryption_warning = tmp;
681 prefs_gpg_save_config();
684 void prefs_gpg_remove_skip_encryption_warning(const gchar *systemid)
686 gchar **systems = NULL;
688 if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
691 if (prefs_gpg_should_skip_encryption_warning(systemid)) {
692 systems = g_strsplit(prefs_gpg_get_config()->skip_encryption_warning,
694 g_free(prefs_gpg_get_config()->skip_encryption_warning);
695 prefs_gpg_get_config()->skip_encryption_warning = NULL;
697 while (systems && systems[i]) {
698 if (!strcmp(systems[i],systemid)) {
702 prefs_gpg_add_skip_encryption_warning(systems[i]);
708 prefs_gpg_save_config();
711 gboolean prefs_gpg_auto_check_signatures(void)
713 return prefs_gpg_get_config()->auto_check_signatures;