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/>.
22 #include "claws-features.h"
27 #include <glib/gi18n.h>
29 #include <gtk/filesel.h>
32 #include "gtk/gtkutils.h"
35 #include "prefs_common.h"
36 #include "prefs_gtk.h"
37 #include "prefs_gpg.h"
40 struct GPGConfig prefs_gpg;
42 static PrefParam param[] = {
44 {"auto_check_signatures", "FALSE",
45 &prefs_gpg.auto_check_signatures, P_BOOL,
47 {"autocompletion", "FALSE",
48 &prefs_gpg.autocompletion, P_BOOL,
50 {"autocompletion_limit", "0",
51 &prefs_gpg.autocompletion_limit, P_INT,
53 {"use_gpg_agent", "TRUE", &prefs_gpg.use_gpg_agent, P_BOOL,
55 {"store_passphrase", "FALSE", &prefs_gpg.store_passphrase, P_BOOL,
57 {"store_passphrase_timeout", "0",
58 &prefs_gpg.store_passphrase_timeout, P_INT,
60 {"passphrase_grab", "FALSE", &prefs_gpg.passphrase_grab, P_BOOL,
62 {"gpg_warning", "TRUE", &prefs_gpg.gpg_warning, P_BOOL,
64 {"gpg_ask_create_key", "TRUE", &prefs_gpg.gpg_ask_create_key, P_BOOL,
66 {"skip_encryption_warning", "", &prefs_gpg.skip_encryption_warning, P_STRING,
68 {"gpg_path", "", &prefs_gpg.gpg_path, P_STRING,
71 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
74 static gchar *saved_gpg_agent_info = NULL;
75 static void gpg_path_browse_cb(GtkWidget *widget, gpointer data);
81 GtkWidget *checkbtn_auto_check_signatures;
82 GtkWidget *checkbtn_autocompletion;
83 GtkWidget *checkbtn_use_gpg_agent;
84 GtkWidget *checkbtn_store_passphrase;
85 GtkWidget *spinbtn_store_passphrase;
86 GtkWidget *checkbtn_passphrase_grab;
87 GtkWidget *checkbtn_gpg_warning;
91 static void prefs_gpg_create_widget_func(PrefsPage *_page,
95 struct GPGPage *page = (struct GPGPage *) _page;
96 struct GPGConfig *config;
98 GtkWidget *checkbtn_use_gpg_agent;
99 GtkWidget *checkbtn_passphrase_grab;
100 GtkWidget *checkbtn_store_passphrase;
101 GtkWidget *checkbtn_auto_check_signatures;
102 GtkWidget *checkbtn_autocompletion;
103 GtkWidget *checkbtn_gpg_warning;
104 GtkWidget *hbox1, *hbox2;
105 GtkWidget *vbox1, *vbox2;
106 GtkWidget *label_gpg_path;
107 GtkWidget *label_expire1;
108 GtkAdjustment *spinbtn_store_passphrase_adj;
109 GtkWidget *spinbtn_store_passphrase;
110 GtkWidget *label_expire2;
111 GtkWidget *frame_passphrase;
112 GtkWidget *gpg_path, *gpg_path_btn;
114 vbox1 = gtk_vbox_new (FALSE, VSPACING);
115 gtk_widget_show (vbox1);
116 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
118 vbox2 = gtk_vbox_new (FALSE, 0);
119 gtk_widget_show (vbox2);
120 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
122 PACK_CHECK_BUTTON (vbox2, checkbtn_auto_check_signatures,
123 _("Automatically check signatures"));
125 PACK_CHECK_BUTTON (vbox2, checkbtn_autocompletion,
126 _("Use keyring for address autocompletion"));
128 vbox2 = gtkut_get_options_frame(vbox1, &frame_passphrase, _("Passphrase"));
130 PACK_CHECK_BUTTON (vbox2, checkbtn_use_gpg_agent,
131 _("Use gpg-agent to manage passwords"));
132 if (saved_gpg_agent_info == NULL)
133 gtk_widget_set_sensitive(checkbtn_use_gpg_agent, FALSE);
135 PACK_CHECK_BUTTON (vbox2, checkbtn_store_passphrase,
136 _("Store passphrase in memory"));
138 SET_TOGGLE_SENSITIVITY_REVERSE(checkbtn_use_gpg_agent, checkbtn_store_passphrase);
140 hbox1 = gtk_hbox_new (FALSE, 8);
141 gtk_widget_show (hbox1);
142 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
144 SET_TOGGLE_SENSITIVITY_REVERSE(checkbtn_use_gpg_agent, hbox1);
146 label_expire1 = gtk_label_new(_("Expire after"));
147 gtk_widget_show (label_expire1);
148 gtk_box_pack_start (GTK_BOX (hbox1), label_expire1, FALSE, FALSE, 0);
150 spinbtn_store_passphrase_adj =
151 GTK_ADJUSTMENT(gtk_adjustment_new(1, 0, 1440, 1, 10, 0));
152 spinbtn_store_passphrase =
153 gtk_spin_button_new(GTK_ADJUSTMENT
154 (spinbtn_store_passphrase_adj), 1, 0);
155 gtk_widget_show(spinbtn_store_passphrase);
156 gtk_box_pack_start(GTK_BOX(hbox1), spinbtn_store_passphrase, FALSE,
158 gtk_widget_set_size_request(spinbtn_store_passphrase, 64, -1);
159 CLAWS_SET_TIP(spinbtn_store_passphrase,
160 _("Setting to '0' will store the passphrase for the whole session"));
161 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON
162 (spinbtn_store_passphrase), TRUE);
164 label_expire2 = gtk_label_new(_("minute(s)"));
165 gtk_widget_show(label_expire2);
166 gtk_box_pack_start(GTK_BOX(hbox1), label_expire2, FALSE, FALSE, 0);
167 gtk_misc_set_alignment(GTK_MISC(label_expire2), 0.0, 0.5);
169 SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, label_expire1);
170 SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, spinbtn_store_passphrase);
171 SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, label_expire2);
173 PACK_CHECK_BUTTON (vbox2, checkbtn_passphrase_grab,
174 _("Grab input while entering a passphrase"));
176 vbox2 = gtk_vbox_new (FALSE, 0);
177 gtk_widget_show (vbox2);
178 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
180 PACK_CHECK_BUTTON (vbox2, checkbtn_gpg_warning,
181 _("Display warning on start-up if GnuPG doesn't work"));
183 hbox2 = gtk_hbox_new(FALSE, 6);
184 label_gpg_path = gtk_label_new(_("Path to GnuPG executable"));
185 gtk_box_pack_start(GTK_BOX(hbox2), label_gpg_path, FALSE, FALSE, 0);
186 gpg_path = gtk_entry_new();
187 gtk_box_pack_start(GTK_BOX(hbox2), gpg_path, TRUE, TRUE, 0);
188 CLAWS_SET_TIP(gpg_path,
189 _("If left blank the location of the GnuPG executable will be automatically determined."));
190 gpg_path_btn = gtkut_get_browse_file_btn(_("Bro_wse"));
191 gtk_box_pack_start(GTK_BOX(hbox2), gpg_path_btn, FALSE, FALSE, 0);
192 g_signal_connect(G_OBJECT(gpg_path_btn), "clicked",
193 G_CALLBACK(gpg_path_browse_cb), gpg_path);
194 pref_set_entry_from_pref(GTK_ENTRY(gpg_path), prefs_gpg.gpg_path);
196 gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
197 gtk_widget_show_all(vbox1);
199 config = prefs_gpg_get_config();
201 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_auto_check_signatures), config->auto_check_signatures);
202 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_autocompletion), config->autocompletion);
203 if (!getenv("GPG_AGENT_INFO"))
204 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_gpg_agent), FALSE);
206 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_gpg_agent), config->use_gpg_agent);
207 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbtn_use_gpg_agent)))
208 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_store_passphrase), config->store_passphrase);
209 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_store_passphrase), (float) config->store_passphrase_timeout);
210 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_passphrase_grab), config->passphrase_grab);
211 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_gpg_warning), config->gpg_warning);
212 gtk_entry_set_text(GTK_ENTRY(gpg_path), config->gpg_path);
214 page->checkbtn_auto_check_signatures = checkbtn_auto_check_signatures;
215 page->checkbtn_autocompletion = checkbtn_autocompletion;
216 page->checkbtn_store_passphrase = checkbtn_store_passphrase;
217 page->spinbtn_store_passphrase = spinbtn_store_passphrase;
218 page->checkbtn_passphrase_grab = checkbtn_passphrase_grab;
219 page->checkbtn_gpg_warning = checkbtn_gpg_warning;
220 page->checkbtn_use_gpg_agent = checkbtn_use_gpg_agent;
221 page->gpg_path = gpg_path;
222 page->page.widget = vbox1;
225 static void gpg_path_browse_cb(GtkWidget* widget, gpointer data)
228 GtkEntry *dest = GTK_ENTRY(data);
230 filename = filesel_select_file_open(_("Select GnuPG executable"), NULL);
234 gtk_entry_set_text(GTK_ENTRY(dest), filename);
238 static void prefs_gpg_destroy_widget_func(PrefsPage *_page)
242 static void prefs_gpg_save_func(PrefsPage *_page)
244 struct GPGPage *page = (struct GPGPage *) _page;
245 GPGConfig *config = prefs_gpg_get_config();
247 config->auto_check_signatures =
248 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_auto_check_signatures));
249 config->autocompletion =
250 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autocompletion));
251 config->use_gpg_agent =
252 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_use_gpg_agent));
253 config->store_passphrase =
254 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_store_passphrase));
255 config->store_passphrase_timeout =
256 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_store_passphrase));
257 config->passphrase_grab =
258 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_passphrase_grab));
259 config->gpg_warning =
260 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_gpg_warning));
261 g_free(config->gpg_path);
262 config->gpg_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->gpg_path)));
263 if (strcmp(config->gpg_path, "") != 0 && access(config->gpg_path, X_OK) != -1)
264 gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, config->gpg_path, NULL);
266 prefs_gpg_enable_agent(config->use_gpg_agent);
268 prefs_gpg_save_config();
271 struct GPGAccountPage
275 GtkWidget *key_default;
276 GtkWidget *key_by_from;
277 GtkWidget *key_custom;
279 GtkWidget *keyid_label;
280 GtkWidget *new_key_label;
281 GtkWidget *new_key_btn;
282 GtkWidget *new_key_box;
284 PrefsAccount *account;
287 void key_custom_toggled(GtkToggleButton *togglebutton, gpointer user_data)
289 struct GPGAccountPage *page = (struct GPGAccountPage *) user_data;
292 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_custom));
293 gtk_widget_set_sensitive(GTK_WIDGET(page->keyid_label), active);
294 gtk_widget_set_sensitive(GTK_WIDGET(page->keyid), active);
296 gtk_editable_delete_text(GTK_EDITABLE(page->keyid), 0, -1);
299 static void prefs_gpg_update_sens(struct GPGAccountPage *page)
302 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_custom));
303 if (sgpgme_has_secret_key()) {
304 gtk_widget_hide(page->new_key_box);
305 gtk_widget_set_sensitive(page->key_default, TRUE);
306 gtk_widget_set_sensitive(page->key_by_from, TRUE);
307 gtk_widget_set_sensitive(page->key_custom, TRUE);
308 gtk_widget_set_sensitive(page->keyid, active);
309 gtk_widget_set_sensitive(page->keyid_label, active);
311 gtk_widget_show(page->new_key_box);
312 gtk_widget_set_sensitive(page->key_default, FALSE);
313 gtk_widget_set_sensitive(page->key_by_from, FALSE);
314 gtk_widget_set_sensitive(page->key_custom, FALSE);
315 gtk_widget_set_sensitive(page->keyid, FALSE);
316 gtk_widget_set_sensitive(page->keyid_label, FALSE);
320 static void new_key_clicked(GtkWidget *widget, gpointer user_data)
322 struct GPGAccountPage *page = (struct GPGAccountPage *) user_data;
323 sgpgme_create_secret_key(page->account, FALSE);
324 prefs_gpg_update_sens(page);
327 static void prefs_gpg_account_create_widget_func(PrefsPage *_page,
331 struct GPGAccountPage *page = (struct GPGAccountPage *) _page;
332 PrefsAccount *account = (PrefsAccount *) data;
333 GPGAccountConfig *config;
339 GSList *key_group = NULL;
340 GtkWidget *key_default;
341 GtkWidget *key_by_from;
342 GtkWidget *key_custom;
343 GtkWidget *keyid_label;
346 GtkWidget *new_key_label;
347 GtkWidget *new_key_btn;
348 GtkWidget *new_key_box;
350 vbox = gtk_vbox_new(FALSE, VSPACING);
351 gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
352 gtk_widget_show(vbox);
354 vbox2 = gtkut_get_options_frame(vbox, &frame1, _("Sign key"));
356 hbox = gtk_hbox_new (FALSE, 5);
357 gtk_widget_show (hbox);
358 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
359 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
361 key_default = gtk_radio_button_new_with_label(key_group,
362 _("Use default GnuPG key"));
363 key_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(key_default));
364 gtk_widget_show(key_default);
365 gtk_box_pack_start(GTK_BOX(hbox), key_default, FALSE, FALSE, 0);
367 hbox = gtk_hbox_new (FALSE, 5);
368 gtk_widget_show (hbox);
369 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
370 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
372 key_by_from = gtk_radio_button_new_with_label(key_group,
373 _("Select key by your email address"));
374 key_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(key_by_from));
375 gtk_widget_show(key_by_from);
376 gtk_box_pack_start(GTK_BOX(hbox), key_by_from, FALSE, FALSE, 0);
378 hbox = gtk_hbox_new (FALSE, 5);
379 gtk_widget_show (hbox);
380 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
381 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
383 key_custom = gtk_radio_button_new_with_label(key_group,
384 _("Specify key manually"));
385 key_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(key_custom));
386 gtk_widget_show(key_custom);
387 gtk_box_pack_start(GTK_BOX(hbox), key_custom, FALSE, FALSE, 0);
389 hbox = gtk_hbox_new (FALSE, 5);
390 gtk_widget_show (hbox);
391 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
392 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
394 keyid_label = gtk_label_new(_("User or key ID:"));
395 gtk_widget_show(keyid_label);
396 gtk_label_set_justify(GTK_LABEL(keyid_label), GTK_JUSTIFY_LEFT);
397 gtk_box_pack_start(GTK_BOX(hbox), keyid_label, FALSE, FALSE, 0);
399 keyid = gtk_entry_new();
400 gtk_widget_show(keyid);
401 gtk_box_pack_start(GTK_BOX(hbox), keyid, FALSE, FALSE, 0);
403 config = prefs_gpg_account_get_config(account);
404 switch (config->sign_key) {
405 case SIGN_KEY_DEFAULT:
406 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(key_default), TRUE);
407 gtk_widget_set_sensitive(GTK_WIDGET(keyid_label), FALSE);
408 gtk_widget_set_sensitive(GTK_WIDGET(keyid), FALSE);
410 case SIGN_KEY_BY_FROM:
411 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(key_by_from), TRUE);
412 gtk_widget_set_sensitive(GTK_WIDGET(keyid_label), FALSE);
413 gtk_widget_set_sensitive(GTK_WIDGET(keyid), FALSE);
415 case SIGN_KEY_CUSTOM:
416 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(key_custom), TRUE);
417 gtk_widget_set_sensitive(GTK_WIDGET(keyid_label), TRUE);
418 gtk_widget_set_sensitive(GTK_WIDGET(keyid), TRUE);
422 hbox = gtk_hbox_new (FALSE, 5);
423 gtk_widget_show (hbox);
424 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
426 new_key_box = gtk_hbox_new(FALSE, 6);
427 gtk_widget_show(new_key_box);
428 gtk_box_pack_start(GTK_BOX(hbox), new_key_box, FALSE, FALSE, 0);
430 image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
431 GTK_ICON_SIZE_SMALL_TOOLBAR);
433 gtk_box_pack_start(GTK_BOX(new_key_box), image, FALSE, FALSE, 0);
434 new_key_label = gtk_label_new(
435 _("No secret key found."));
436 gtk_box_pack_start(GTK_BOX(new_key_box), new_key_label, FALSE, FALSE, 0);
438 new_key_btn = gtk_button_new_with_label(_("Generate a new key pair"));
439 gtk_widget_show(new_key_btn);
440 gtk_box_pack_start(GTK_BOX(hbox), new_key_btn, FALSE, FALSE, 0);
442 if (config->sign_key_id != NULL)
443 gtk_entry_set_text(GTK_ENTRY(keyid), config->sign_key_id);
445 g_signal_connect(G_OBJECT(key_custom), "toggled", G_CALLBACK(key_custom_toggled), page);
446 g_signal_connect(G_OBJECT(new_key_btn), "clicked", G_CALLBACK(new_key_clicked), page);
448 page->key_default = key_default;
449 page->key_by_from = key_by_from;
450 page->key_custom = key_custom;
452 page->keyid_label = keyid_label;
453 page->new_key_box = new_key_box;
455 page->page.widget = vbox;
456 page->account = account;
457 prefs_gpg_update_sens(page);
460 static void prefs_gpg_account_destroy_widget_func(PrefsPage *_page)
462 /* nothing to do here */
465 static void prefs_gpg_account_save_func(PrefsPage *_page)
467 struct GPGAccountPage *page = (struct GPGAccountPage *) _page;
468 GPGAccountConfig *config;
470 config = prefs_gpg_account_get_config(page->account);
472 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_default)))
473 config->sign_key = SIGN_KEY_DEFAULT;
474 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_by_from)))
475 config->sign_key = SIGN_KEY_BY_FROM;
476 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_custom))) {
477 config->sign_key = SIGN_KEY_CUSTOM;
478 g_free(config->sign_key_id);
479 config->sign_key_id = gtk_editable_get_chars(GTK_EDITABLE(page->keyid), 0, -1);
482 prefs_gpg_account_set_config(page->account, config);
483 prefs_gpg_account_free_config(config);
486 GPGConfig *prefs_gpg_get_config(void)
491 void prefs_gpg_save_config(void)
496 debug_print("Saving GPG config\n");
498 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
499 pfile = prefs_write_open(rcpath);
501 if (!pfile || (prefs_set_block_label(pfile, "GPG") < 0))
504 if (prefs_write_param(param, pfile->fp) < 0) {
505 g_warning("failed to write GPG configuration to file");
506 prefs_file_close_revert(pfile);
509 if (fprintf(pfile->fp, "\n") < 0) {
510 FILE_OP_ERROR(rcpath, "fprintf");
511 prefs_file_close_revert(pfile);
513 prefs_file_close(pfile);
516 struct GPGAccountConfig *prefs_gpg_account_get_config(PrefsAccount *account)
518 GPGAccountConfig *config;
519 const gchar *confstr;
522 config = g_new0(GPGAccountConfig, 1);
523 config->sign_key = SIGN_KEY_DEFAULT;
524 config->sign_key_id = NULL;
526 confstr = prefs_account_get_privacy_prefs(account, "gpg");
530 strv = g_strsplit(confstr, ";", 0);
531 if (strv[0] != NULL) {
532 if (!strcmp(strv[0], "DEFAULT"))
533 config->sign_key = SIGN_KEY_DEFAULT;
534 if (!strcmp(strv[0], "BY_FROM"))
535 config->sign_key = SIGN_KEY_BY_FROM;
536 if (!strcmp(strv[0], "CUSTOM")) {
537 if (strv[1] != NULL) {
538 config->sign_key = SIGN_KEY_CUSTOM;
539 config->sign_key_id = g_strdup(strv[1]);
541 config->sign_key = SIGN_KEY_DEFAULT;
549 void prefs_gpg_account_set_config(PrefsAccount *account, GPGAccountConfig *config)
551 gchar *confstr = NULL;
553 switch (config->sign_key) {
554 case SIGN_KEY_DEFAULT:
555 confstr = g_strdup("DEFAULT");
557 case SIGN_KEY_BY_FROM:
558 confstr = g_strdup("BY_FROM");
560 case SIGN_KEY_CUSTOM:
561 confstr = g_strdup_printf("CUSTOM;%s", config->sign_key_id);
564 confstr = g_strdup("");
565 g_warning("prefs_gpg_account_set_config: bad sign_key val");
568 prefs_account_set_privacy_prefs(account, "gpg", confstr);
573 void prefs_gpg_account_free_config(GPGAccountConfig *config)
575 g_free(config->sign_key_id);
579 static struct GPGPage gpg_page;
580 static struct GPGAccountPage gpg_account_page;
582 void prefs_gpg_enable_agent(gboolean enable)
585 if (saved_gpg_agent_info) {
586 g_setenv("GPG_AGENT_INFO",
587 saved_gpg_agent_info, TRUE);
588 debug_print("set GPG_AGENT_INFO=%s\n",
589 saved_gpg_agent_info);
591 debug_print("Can't enable gpg agent (no GPG_AGENT_INFO)\n");
594 if (saved_gpg_agent_info) {
595 g_unsetenv("GPG_AGENT_INFO");
596 debug_print("unset GPG_AGENT_INFO=%s\n",
597 saved_gpg_agent_info);
599 debug_print("Can't disable gpg agent (no GPG_AGENT_INFO)\n");
604 void prefs_gpg_init()
606 static gchar *path[3];
608 const gchar *tmp = NULL;
610 prefs_set_default(param);
611 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
612 prefs_read_config(param, "GPG", rcpath, NULL);
615 path[0] = _("Plugins");
619 gpg_page.page.path = path;
620 gpg_page.page.create_widget = prefs_gpg_create_widget_func;
621 gpg_page.page.destroy_widget = prefs_gpg_destroy_widget_func;
622 gpg_page.page.save_page = prefs_gpg_save_func;
623 gpg_page.page.weight = 30.0;
625 prefs_gtk_register_page((PrefsPage *) &gpg_page);
627 gpg_account_page.page.path = path;
628 gpg_account_page.page.create_widget = prefs_gpg_account_create_widget_func;
629 gpg_account_page.page.destroy_widget = prefs_gpg_account_destroy_widget_func;
630 gpg_account_page.page.save_page = prefs_gpg_account_save_func;
631 gpg_account_page.page.weight = 30.0;
633 prefs_account_register_page((PrefsPage *) &gpg_account_page);
635 tmp = g_getenv("GPG_AGENT_INFO");
637 saved_gpg_agent_info = g_strdup(tmp);
639 prefs_gpg_enable_agent(prefs_gpg_get_config()->use_gpg_agent);
642 void prefs_gpg_done()
644 prefs_gtk_unregister_page((PrefsPage *) &gpg_page);
645 prefs_account_unregister_page((PrefsPage *) &gpg_account_page);
646 prefs_gpg_enable_agent(TRUE);
649 gboolean prefs_gpg_should_skip_encryption_warning(const gchar *systemid)
651 gchar **systems = NULL;
653 if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
655 systems = g_strsplit(prefs_gpg_get_config()->skip_encryption_warning,
657 while (systems && systems[i]) {
658 debug_print(" cmp %s %s\n", systems[i], systemid);
659 if (!strcmp(systems[i],systemid)) {
669 void prefs_gpg_add_skip_encryption_warning(const gchar *systemid)
672 if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
673 prefs_gpg_get_config()->skip_encryption_warning =
674 g_strdup_printf("%s,", systemid);
675 else if (!prefs_gpg_should_skip_encryption_warning(systemid)) {
676 tmp = g_strdup_printf("%s%s,",
677 prefs_gpg_get_config()->skip_encryption_warning,
679 g_free(prefs_gpg_get_config()->skip_encryption_warning);
680 prefs_gpg_get_config()->skip_encryption_warning = tmp;
682 prefs_gpg_save_config();
685 void prefs_gpg_remove_skip_encryption_warning(const gchar *systemid)
687 gchar **systems = NULL;
689 if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
692 if (prefs_gpg_should_skip_encryption_warning(systemid)) {
693 systems = g_strsplit(prefs_gpg_get_config()->skip_encryption_warning,
695 g_free(prefs_gpg_get_config()->skip_encryption_warning);
696 prefs_gpg_get_config()->skip_encryption_warning = NULL;
698 while (systems && systems[i]) {
699 if (!strcmp(systems[i],systemid)) {
703 prefs_gpg_add_skip_encryption_warning(systems[i]);
709 prefs_gpg_save_config();
712 gboolean prefs_gpg_auto_check_signatures(void)
714 return prefs_gpg_get_config()->auto_check_signatures;