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 {"use_gpg_agent", "TRUE", &prefs_gpg.use_gpg_agent, P_BOOL,
52 {"store_passphrase", "FALSE", &prefs_gpg.store_passphrase, P_BOOL,
54 {"store_passphrase_timeout", "0",
55 &prefs_gpg.store_passphrase_timeout, P_INT,
57 {"passphrase_grab", "FALSE", &prefs_gpg.passphrase_grab, P_BOOL,
59 {"gpg_warning", "TRUE", &prefs_gpg.gpg_warning, P_BOOL,
61 {"gpg_ask_create_key", "TRUE", &prefs_gpg.gpg_ask_create_key, P_BOOL,
63 {"skip_encryption_warning", "", &prefs_gpg.skip_encryption_warning, P_STRING,
65 {"gpg_path", "", &prefs_gpg.gpg_path, P_STRING,
68 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
71 static gchar *saved_gpg_agent_info = NULL;
72 static void gpg_path_browse_cb(GtkWidget *widget, gpointer data);
78 GtkWidget *checkbtn_auto_check_signatures;
79 GtkWidget *checkbtn_autocompletion;
80 GtkWidget *checkbtn_use_gpg_agent;
81 GtkWidget *checkbtn_store_passphrase;
82 GtkWidget *spinbtn_store_passphrase;
83 GtkWidget *checkbtn_passphrase_grab;
84 GtkWidget *checkbtn_gpg_warning;
88 static void prefs_gpg_create_widget_func(PrefsPage *_page,
92 struct GPGPage *page = (struct GPGPage *) _page;
93 struct GPGConfig *config;
95 GtkWidget *checkbtn_use_gpg_agent;
96 GtkWidget *checkbtn_passphrase_grab;
97 GtkWidget *checkbtn_store_passphrase;
98 GtkWidget *checkbtn_auto_check_signatures;
99 GtkWidget *checkbtn_autocompletion;
100 GtkWidget *checkbtn_gpg_warning;
101 GtkWidget *hbox1, *hbox2;
102 GtkWidget *vbox1, *vbox2;
103 GtkWidget *label_gpg_path;
104 GtkWidget *label_expire1;
105 GtkAdjustment *spinbtn_store_passphrase_adj;
106 GtkWidget *spinbtn_store_passphrase;
107 GtkWidget *label_expire2;
108 GtkWidget *frame_passphrase;
109 GtkWidget *gpg_path, *gpg_path_btn;
111 vbox1 = gtk_vbox_new (FALSE, VSPACING);
112 gtk_widget_show (vbox1);
113 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
115 vbox2 = gtk_vbox_new (FALSE, 0);
116 gtk_widget_show (vbox2);
117 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
119 PACK_CHECK_BUTTON (vbox2, checkbtn_auto_check_signatures,
120 _("Automatically check signatures"));
122 PACK_CHECK_BUTTON (vbox2, checkbtn_autocompletion,
123 _("Use keyring for address autocompletion"));
125 vbox2 = gtkut_get_options_frame(vbox1, &frame_passphrase, _("Passphrase"));
127 PACK_CHECK_BUTTON (vbox2, checkbtn_use_gpg_agent,
128 _("Use gpg-agent to manage passwords"));
129 if (saved_gpg_agent_info == NULL)
130 gtk_widget_set_sensitive(checkbtn_use_gpg_agent, FALSE);
132 PACK_CHECK_BUTTON (vbox2, checkbtn_store_passphrase,
133 _("Store passphrase in memory"));
135 SET_TOGGLE_SENSITIVITY_REVERSE(checkbtn_use_gpg_agent, checkbtn_store_passphrase);
137 hbox1 = gtk_hbox_new (FALSE, 8);
138 gtk_widget_show (hbox1);
139 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
141 SET_TOGGLE_SENSITIVITY_REVERSE(checkbtn_use_gpg_agent, hbox1);
143 label_expire1 = gtk_label_new(_("Expire after"));
144 gtk_widget_show (label_expire1);
145 gtk_box_pack_start (GTK_BOX (hbox1), label_expire1, FALSE, FALSE, 0);
147 spinbtn_store_passphrase_adj =
148 GTK_ADJUSTMENT(gtk_adjustment_new(1, 0, 1440, 1, 10, 0));
149 spinbtn_store_passphrase =
150 gtk_spin_button_new(GTK_ADJUSTMENT
151 (spinbtn_store_passphrase_adj), 1, 0);
152 gtk_widget_show(spinbtn_store_passphrase);
153 gtk_box_pack_start(GTK_BOX(hbox1), spinbtn_store_passphrase, FALSE,
155 gtk_widget_set_size_request(spinbtn_store_passphrase, 64, -1);
156 CLAWS_SET_TIP(spinbtn_store_passphrase,
157 _("Setting to '0' will store the passphrase for the whole session"));
158 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON
159 (spinbtn_store_passphrase), TRUE);
161 label_expire2 = gtk_label_new(_("minute(s)"));
162 gtk_widget_show(label_expire2);
163 gtk_box_pack_start(GTK_BOX(hbox1), label_expire2, FALSE, FALSE, 0);
164 gtk_misc_set_alignment(GTK_MISC(label_expire2), 0.0, 0.5);
166 SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, label_expire1);
167 SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, spinbtn_store_passphrase);
168 SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, label_expire2);
170 PACK_CHECK_BUTTON (vbox2, checkbtn_passphrase_grab,
171 _("Grab input while entering a passphrase"));
173 vbox2 = gtk_vbox_new (FALSE, 0);
174 gtk_widget_show (vbox2);
175 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
177 PACK_CHECK_BUTTON (vbox2, checkbtn_gpg_warning,
178 _("Display warning on start-up if GnuPG doesn't work"));
180 hbox2 = gtk_hbox_new(FALSE, 6);
181 label_gpg_path = gtk_label_new(_("Path to GnuPG executable"));
182 gtk_box_pack_start(GTK_BOX(hbox2), label_gpg_path, FALSE, FALSE, 0);
183 gpg_path = gtk_entry_new();
184 gtk_box_pack_start(GTK_BOX(hbox2), gpg_path, TRUE, TRUE, 0);
185 CLAWS_SET_TIP(gpg_path,
186 _("If left blank the location of the GnuPG executable will be automatically determined."));
187 gpg_path_btn = gtkut_get_browse_file_btn(_("Bro_wse"));
188 gtk_box_pack_start(GTK_BOX(hbox2), gpg_path_btn, FALSE, FALSE, 0);
189 g_signal_connect(G_OBJECT(gpg_path_btn), "clicked",
190 G_CALLBACK(gpg_path_browse_cb), gpg_path);
191 pref_set_entry_from_pref(GTK_ENTRY(gpg_path), prefs_gpg.gpg_path);
193 gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
194 gtk_widget_show_all(vbox1);
196 config = prefs_gpg_get_config();
198 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_auto_check_signatures), config->auto_check_signatures);
199 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_autocompletion), config->autocompletion);
200 if (!getenv("GPG_AGENT_INFO"))
201 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_gpg_agent), FALSE);
203 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_gpg_agent), config->use_gpg_agent);
204 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbtn_use_gpg_agent)))
205 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_store_passphrase), config->store_passphrase);
206 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_store_passphrase), (float) config->store_passphrase_timeout);
207 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_passphrase_grab), config->passphrase_grab);
208 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_gpg_warning), config->gpg_warning);
209 gtk_entry_set_text(GTK_ENTRY(gpg_path), config->gpg_path);
211 page->checkbtn_auto_check_signatures = checkbtn_auto_check_signatures;
212 page->checkbtn_autocompletion = checkbtn_autocompletion;
213 page->checkbtn_store_passphrase = checkbtn_store_passphrase;
214 page->spinbtn_store_passphrase = spinbtn_store_passphrase;
215 page->checkbtn_passphrase_grab = checkbtn_passphrase_grab;
216 page->checkbtn_gpg_warning = checkbtn_gpg_warning;
217 page->checkbtn_use_gpg_agent = checkbtn_use_gpg_agent;
218 page->gpg_path = gpg_path;
219 page->page.widget = vbox1;
222 static void gpg_path_browse_cb(GtkWidget* widget, gpointer data)
225 GtkEntry *dest = GTK_ENTRY(data);
227 filename = filesel_select_file_open(_("Select GnuPG executable"), NULL);
231 gtk_entry_set_text(GTK_ENTRY(dest), filename);
235 static void prefs_gpg_destroy_widget_func(PrefsPage *_page)
239 static void prefs_gpg_save_func(PrefsPage *_page)
241 struct GPGPage *page = (struct GPGPage *) _page;
242 GPGConfig *config = prefs_gpg_get_config();
244 config->auto_check_signatures =
245 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_auto_check_signatures));
246 config->autocompletion =
247 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autocompletion));
248 config->use_gpg_agent =
249 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_use_gpg_agent));
250 config->store_passphrase =
251 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_store_passphrase));
252 config->store_passphrase_timeout =
253 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_store_passphrase));
254 config->passphrase_grab =
255 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_passphrase_grab));
256 config->gpg_warning =
257 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_gpg_warning));
258 g_free(config->gpg_path);
259 config->gpg_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->gpg_path)));
260 if (strcmp(config->gpg_path, "") != 0 && access(config->gpg_path, X_OK) != -1)
261 gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, config->gpg_path, NULL);
263 prefs_gpg_enable_agent(config->use_gpg_agent);
265 prefs_gpg_save_config();
268 struct GPGAccountPage
272 GtkWidget *key_default;
273 GtkWidget *key_by_from;
274 GtkWidget *key_custom;
276 GtkWidget *keyid_label;
277 GtkWidget *new_key_label;
278 GtkWidget *new_key_btn;
279 GtkWidget *new_key_box;
281 PrefsAccount *account;
284 void key_custom_toggled(GtkToggleButton *togglebutton, gpointer user_data)
286 struct GPGAccountPage *page = (struct GPGAccountPage *) user_data;
289 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_custom));
290 gtk_widget_set_sensitive(GTK_WIDGET(page->keyid_label), active);
291 gtk_widget_set_sensitive(GTK_WIDGET(page->keyid), active);
293 gtk_editable_delete_text(GTK_EDITABLE(page->keyid), 0, -1);
296 static void prefs_gpg_update_sens(struct GPGAccountPage *page)
299 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_custom));
300 if (sgpgme_has_secret_key()) {
301 gtk_widget_hide(page->new_key_box);
302 gtk_widget_set_sensitive(page->key_default, TRUE);
303 gtk_widget_set_sensitive(page->key_by_from, TRUE);
304 gtk_widget_set_sensitive(page->key_custom, TRUE);
305 gtk_widget_set_sensitive(page->keyid, active);
306 gtk_widget_set_sensitive(page->keyid_label, active);
308 gtk_widget_show(page->new_key_box);
309 gtk_widget_set_sensitive(page->key_default, FALSE);
310 gtk_widget_set_sensitive(page->key_by_from, FALSE);
311 gtk_widget_set_sensitive(page->key_custom, FALSE);
312 gtk_widget_set_sensitive(page->keyid, FALSE);
313 gtk_widget_set_sensitive(page->keyid_label, FALSE);
317 static void new_key_clicked(GtkWidget *widget, gpointer user_data)
319 struct GPGAccountPage *page = (struct GPGAccountPage *) user_data;
320 sgpgme_create_secret_key(page->account, FALSE);
321 prefs_gpg_update_sens(page);
324 static void prefs_gpg_account_create_widget_func(PrefsPage *_page,
328 struct GPGAccountPage *page = (struct GPGAccountPage *) _page;
329 PrefsAccount *account = (PrefsAccount *) data;
330 GPGAccountConfig *config;
336 GSList *key_group = NULL;
337 GtkWidget *key_default;
338 GtkWidget *key_by_from;
339 GtkWidget *key_custom;
340 GtkWidget *keyid_label;
343 GtkWidget *new_key_label;
344 GtkWidget *new_key_btn;
345 GtkWidget *new_key_box;
347 vbox = gtk_vbox_new(FALSE, VSPACING);
348 gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
349 gtk_widget_show(vbox);
351 vbox2 = gtkut_get_options_frame(vbox, &frame1, _("Sign key"));
353 hbox = gtk_hbox_new (FALSE, 5);
354 gtk_widget_show (hbox);
355 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
356 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
358 key_default = gtk_radio_button_new_with_label(key_group,
359 _("Use default GnuPG key"));
360 key_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(key_default));
361 gtk_widget_show(key_default);
362 gtk_box_pack_start(GTK_BOX(hbox), key_default, FALSE, FALSE, 0);
364 hbox = gtk_hbox_new (FALSE, 5);
365 gtk_widget_show (hbox);
366 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
367 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
369 key_by_from = gtk_radio_button_new_with_label(key_group,
370 _("Select key by your email address"));
371 key_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(key_by_from));
372 gtk_widget_show(key_by_from);
373 gtk_box_pack_start(GTK_BOX(hbox), key_by_from, FALSE, FALSE, 0);
375 hbox = gtk_hbox_new (FALSE, 5);
376 gtk_widget_show (hbox);
377 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
378 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
380 key_custom = gtk_radio_button_new_with_label(key_group,
381 _("Specify key manually"));
382 key_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(key_custom));
383 gtk_widget_show(key_custom);
384 gtk_box_pack_start(GTK_BOX(hbox), key_custom, FALSE, FALSE, 0);
386 hbox = gtk_hbox_new (FALSE, 5);
387 gtk_widget_show (hbox);
388 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
389 gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
391 keyid_label = gtk_label_new(_("User or key ID:"));
392 gtk_widget_show(keyid_label);
393 gtk_label_set_justify(GTK_LABEL(keyid_label), GTK_JUSTIFY_LEFT);
394 gtk_box_pack_start(GTK_BOX(hbox), keyid_label, FALSE, FALSE, 0);
396 keyid = gtk_entry_new();
397 gtk_widget_show(keyid);
398 gtk_box_pack_start(GTK_BOX(hbox), keyid, FALSE, FALSE, 0);
400 config = prefs_gpg_account_get_config(account);
401 switch (config->sign_key) {
402 case SIGN_KEY_DEFAULT:
403 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(key_default), TRUE);
404 gtk_widget_set_sensitive(GTK_WIDGET(keyid_label), FALSE);
405 gtk_widget_set_sensitive(GTK_WIDGET(keyid), FALSE);
407 case SIGN_KEY_BY_FROM:
408 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(key_by_from), TRUE);
409 gtk_widget_set_sensitive(GTK_WIDGET(keyid_label), FALSE);
410 gtk_widget_set_sensitive(GTK_WIDGET(keyid), FALSE);
412 case SIGN_KEY_CUSTOM:
413 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(key_custom), TRUE);
414 gtk_widget_set_sensitive(GTK_WIDGET(keyid_label), TRUE);
415 gtk_widget_set_sensitive(GTK_WIDGET(keyid), TRUE);
419 hbox = gtk_hbox_new (FALSE, 5);
420 gtk_widget_show (hbox);
421 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
423 new_key_box = gtk_hbox_new(FALSE, 6);
424 gtk_widget_show(new_key_box);
425 gtk_box_pack_start(GTK_BOX(hbox), new_key_box, FALSE, FALSE, 0);
427 image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
428 GTK_ICON_SIZE_SMALL_TOOLBAR);
430 gtk_box_pack_start(GTK_BOX(new_key_box), image, FALSE, FALSE, 0);
431 new_key_label = gtk_label_new(
432 _("No secret key found."));
433 gtk_box_pack_start(GTK_BOX(new_key_box), new_key_label, FALSE, FALSE, 0);
435 new_key_btn = gtk_button_new_with_label(_("Generate a new key pair"));
436 gtk_widget_show(new_key_btn);
437 gtk_box_pack_start(GTK_BOX(hbox), new_key_btn, FALSE, FALSE, 0);
439 if (config->sign_key_id != NULL)
440 gtk_entry_set_text(GTK_ENTRY(keyid), config->sign_key_id);
442 g_signal_connect(G_OBJECT(key_custom), "toggled", G_CALLBACK(key_custom_toggled), page);
443 g_signal_connect(G_OBJECT(new_key_btn), "clicked", G_CALLBACK(new_key_clicked), page);
445 page->key_default = key_default;
446 page->key_by_from = key_by_from;
447 page->key_custom = key_custom;
449 page->keyid_label = keyid_label;
450 page->new_key_box = new_key_box;
452 page->page.widget = vbox;
453 page->account = account;
454 prefs_gpg_update_sens(page);
457 static void prefs_gpg_account_destroy_widget_func(PrefsPage *_page)
459 /* nothing to do here */
462 static void prefs_gpg_account_save_func(PrefsPage *_page)
464 struct GPGAccountPage *page = (struct GPGAccountPage *) _page;
465 GPGAccountConfig *config;
467 config = prefs_gpg_account_get_config(page->account);
469 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_default)))
470 config->sign_key = SIGN_KEY_DEFAULT;
471 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_by_from)))
472 config->sign_key = SIGN_KEY_BY_FROM;
473 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->key_custom))) {
474 config->sign_key = SIGN_KEY_CUSTOM;
475 g_free(config->sign_key_id);
476 config->sign_key_id = gtk_editable_get_chars(GTK_EDITABLE(page->keyid), 0, -1);
479 prefs_gpg_account_set_config(page->account, config);
480 prefs_gpg_account_free_config(config);
483 GPGConfig *prefs_gpg_get_config(void)
488 void prefs_gpg_save_config(void)
493 debug_print("Saving GPG config\n");
495 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
496 pfile = prefs_write_open(rcpath);
498 if (!pfile || (prefs_set_block_label(pfile, "GPG") < 0))
501 if (prefs_write_param(param, pfile->fp) < 0) {
502 g_warning("failed to write GPG configuration to file\n");
503 prefs_file_close_revert(pfile);
506 if (fprintf(pfile->fp, "\n") < 0) {
507 FILE_OP_ERROR(rcpath, "fprintf");
508 prefs_file_close_revert(pfile);
510 prefs_file_close(pfile);
513 struct GPGAccountConfig *prefs_gpg_account_get_config(PrefsAccount *account)
515 GPGAccountConfig *config;
516 const gchar *confstr;
519 config = g_new0(GPGAccountConfig, 1);
520 config->sign_key = SIGN_KEY_DEFAULT;
521 config->sign_key_id = NULL;
523 confstr = prefs_account_get_privacy_prefs(account, "gpg");
527 strv = g_strsplit(confstr, ";", 0);
528 if (strv[0] != NULL) {
529 if (!strcmp(strv[0], "DEFAULT"))
530 config->sign_key = SIGN_KEY_DEFAULT;
531 if (!strcmp(strv[0], "BY_FROM"))
532 config->sign_key = SIGN_KEY_BY_FROM;
533 if (!strcmp(strv[0], "CUSTOM")) {
534 if (strv[1] != NULL) {
535 config->sign_key = SIGN_KEY_CUSTOM;
536 config->sign_key_id = g_strdup(strv[1]);
538 config->sign_key = SIGN_KEY_DEFAULT;
546 void prefs_gpg_account_set_config(PrefsAccount *account, GPGAccountConfig *config)
548 gchar *confstr = NULL;
550 switch (config->sign_key) {
551 case SIGN_KEY_DEFAULT:
552 confstr = g_strdup("DEFAULT");
554 case SIGN_KEY_BY_FROM:
555 confstr = g_strdup("BY_FROM");
557 case SIGN_KEY_CUSTOM:
558 confstr = g_strdup_printf("CUSTOM;%s", config->sign_key_id);
561 confstr = g_strdup("");
562 g_warning("prefs_gpg_account_set_config: bad sign_key val\n");
565 prefs_account_set_privacy_prefs(account, "gpg", confstr);
570 void prefs_gpg_account_free_config(GPGAccountConfig *config)
572 g_free(config->sign_key_id);
576 static struct GPGPage gpg_page;
577 static struct GPGAccountPage gpg_account_page;
579 void prefs_gpg_enable_agent(gboolean enable)
582 if (saved_gpg_agent_info) {
583 g_setenv("GPG_AGENT_INFO",
584 saved_gpg_agent_info, TRUE);
585 debug_print("set GPG_AGENT_INFO=%s\n",
586 saved_gpg_agent_info);
588 debug_print("Can't enable gpg agent (no GPG_AGENT_INFO)\n");
591 if (saved_gpg_agent_info) {
592 g_unsetenv("GPG_AGENT_INFO");
593 debug_print("unset GPG_AGENT_INFO=%s\n",
594 saved_gpg_agent_info);
596 debug_print("Can't disable gpg agent (no GPG_AGENT_INFO)\n");
601 void prefs_gpg_init()
603 static gchar *path[3];
605 const gchar *tmp = NULL;
607 prefs_set_default(param);
608 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
609 prefs_read_config(param, "GPG", rcpath, NULL);
612 path[0] = _("Plugins");
616 gpg_page.page.path = path;
617 gpg_page.page.create_widget = prefs_gpg_create_widget_func;
618 gpg_page.page.destroy_widget = prefs_gpg_destroy_widget_func;
619 gpg_page.page.save_page = prefs_gpg_save_func;
620 gpg_page.page.weight = 30.0;
622 prefs_gtk_register_page((PrefsPage *) &gpg_page);
624 gpg_account_page.page.path = path;
625 gpg_account_page.page.create_widget = prefs_gpg_account_create_widget_func;
626 gpg_account_page.page.destroy_widget = prefs_gpg_account_destroy_widget_func;
627 gpg_account_page.page.save_page = prefs_gpg_account_save_func;
628 gpg_account_page.page.weight = 30.0;
630 prefs_account_register_page((PrefsPage *) &gpg_account_page);
632 tmp = g_getenv("GPG_AGENT_INFO");
634 saved_gpg_agent_info = g_strdup(tmp);
636 prefs_gpg_enable_agent(prefs_gpg_get_config()->use_gpg_agent);
639 void prefs_gpg_done()
641 prefs_gtk_unregister_page((PrefsPage *) &gpg_page);
642 prefs_account_unregister_page((PrefsPage *) &gpg_account_page);
643 prefs_gpg_enable_agent(TRUE);
646 gboolean prefs_gpg_should_skip_encryption_warning(const gchar *systemid)
648 gchar **systems = NULL;
650 if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
652 systems = g_strsplit(prefs_gpg_get_config()->skip_encryption_warning,
654 while (systems && systems[i]) {
655 debug_print(" cmp %s %s\n", systems[i], systemid);
656 if (!strcmp(systems[i],systemid)) {
666 void prefs_gpg_add_skip_encryption_warning(const gchar *systemid)
669 if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
670 prefs_gpg_get_config()->skip_encryption_warning =
671 g_strdup_printf("%s,", systemid);
672 else if (!prefs_gpg_should_skip_encryption_warning(systemid)) {
673 tmp = g_strdup_printf("%s%s,",
674 prefs_gpg_get_config()->skip_encryption_warning,
676 g_free(prefs_gpg_get_config()->skip_encryption_warning);
677 prefs_gpg_get_config()->skip_encryption_warning = tmp;
679 prefs_gpg_save_config();
682 void prefs_gpg_remove_skip_encryption_warning(const gchar *systemid)
684 gchar **systems = NULL;
686 if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
689 if (prefs_gpg_should_skip_encryption_warning(systemid)) {
690 systems = g_strsplit(prefs_gpg_get_config()->skip_encryption_warning,
692 g_free(prefs_gpg_get_config()->skip_encryption_warning);
693 prefs_gpg_get_config()->skip_encryption_warning = NULL;
695 while (systems && systems[i]) {
696 if (!strcmp(systems[i],systemid)) {
700 prefs_gpg_add_skip_encryption_warning(systems[i]);
706 prefs_gpg_save_config();
709 gboolean prefs_gpg_auto_check_signatures(void)
711 return prefs_gpg_get_config()->auto_check_signatures;