aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2014-03-18 09:37:28 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2014-03-18 09:37:28 +0000
commita80079c9ef5b0a1d8736bb1442a88d1bf0a10fea (patch)
tree57efcaac1b5cd37237aa3b341ab15e0daec4fa70
parent445477bf9edea510634eefd9db694c6ca459fdeb (diff)
added PGP encrypt-to-self feature.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3348 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog7
-rw-r--r--libsylph/prefs_account.c3
-rw-r--r--libsylph/prefs_account.h5
-rw-r--r--src/compose.c72
-rw-r--r--src/prefs_account_dialog.c11
-rw-r--r--src/select-keys.c12
6 files changed, 87 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 89c284c4..f1442dee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-03-18
+
+ * libsylph/prefs_account.[ch]
+ src/compose.c
+ src/select-keys.c
+ src/prefs_account_dialog.c: added PGP encrypt-to-self feature.
+
2014-03-17
* src/setup.c: allow resize of setup dialog (workaround for #166).
diff --git a/libsylph/prefs_account.c b/libsylph/prefs_account.c
index 8dd9a664..eeeef5b9 100644
--- a/libsylph/prefs_account.c
+++ b/libsylph/prefs_account.c
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2010 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -97,6 +97,7 @@ static PrefParam param[] = {
{"default_sign", "FALSE", &tmp_ac_prefs.default_sign, P_BOOL},
{"default_encrypt", "FALSE", &tmp_ac_prefs.default_encrypt, P_BOOL},
{"encrypt_reply", "TRUE", &tmp_ac_prefs.encrypt_reply, P_BOOL},
+ {"encrypt_to_self", "TRUE", &tmp_ac_prefs.encrypt_to_self, P_BOOL},
{"ascii_armored", "FALSE", &tmp_ac_prefs.ascii_armored, P_BOOL},
{"clearsign", "FALSE", &tmp_ac_prefs.clearsign, P_BOOL},
{"sign_key", NULL, &tmp_ac_prefs.sign_key, P_ENUM},
diff --git a/libsylph/prefs_account.h b/libsylph/prefs_account.h
index df012c98..c8e37803 100644
--- a/libsylph/prefs_account.h
+++ b/libsylph/prefs_account.h
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2010 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -180,6 +180,9 @@ struct _PrefsAccount
gboolean use_proxy_auth;
gchar *proxy_name;
gchar *proxy_pass;
+
+ /* Privacy */
+ gboolean encrypt_to_self;
};
PrefsAccount *prefs_account_new (void);
diff --git a/src/compose.c b/src/compose.c
index 257cea3f..a0cfb510 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2013 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -3635,17 +3635,13 @@ static gint compose_send(Compose *compose)
}
#if USE_GPGME
-/* interfaces to rfc2015 to keep out the prefs stuff there.
- * returns 0 on success and -1 on error. */
-static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
+static const gchar *compose_get_self_key_id(Compose *compose)
{
const gchar *key_id = NULL;
- GSList *key_list;
switch (compose->account->sign_key) {
case SIGN_KEY_DEFAULT:
- *pkey_list = NULL;
- return 0;
+ break;
case SIGN_KEY_BY_FROM:
key_id = compose->account->address;
break;
@@ -3656,8 +3652,23 @@ static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
break;
}
- key_list = rfc2015_create_signers_list(key_id);
+ return key_id;
+}
+/* interfaces to rfc2015 to keep out the prefs stuff there.
+ * returns 0 on success and -1 on error. */
+static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
+{
+ const gchar *key_id = NULL;
+ GSList *key_list;
+
+ key_id = compose_get_self_key_id(compose);
+ if (!key_id) {
+ *pkey_list = NULL;
+ return 0;
+ }
+
+ key_list = rfc2015_create_signers_list(key_id);
if (!key_list) {
alertpanel_error(_("Could not find any key associated with "
"currently selected key id `%s'."), key_id);
@@ -3668,6 +3679,22 @@ static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
return 0;
}
+static GSList *compose_create_encrypt_recipients_list(Compose *compose)
+{
+ GSList *recp_list = NULL;
+ const gchar *key_id = NULL;
+
+ g_return_val_if_fail(compose->to_list != NULL, NULL);
+
+ recp_list = g_slist_copy(compose->to_list);
+ if (compose->account->encrypt_to_self) {
+ key_id = compose_get_self_key_id(compose);
+ recp_list = g_slist_append(recp_list, (gpointer)key_id);
+ }
+
+ return recp_list;
+}
+
/* clearsign message body text */
static gint compose_clearsign_text(Compose *compose, gchar **text)
{
@@ -3705,6 +3732,7 @@ static gint compose_clearsign_text(Compose *compose, gchar **text)
static gint compose_encrypt_armored(Compose *compose, gchar **text)
{
gchar *tmp_file;
+ GSList *recp_list;
tmp_file = get_tmp_file();
if (str_write_to_file(*text, tmp_file) < 0) {
@@ -3712,13 +3740,17 @@ static gint compose_encrypt_armored(Compose *compose, gchar **text)
return -1;
}
- if (rfc2015_encrypt_armored(tmp_file, compose->to_list) < 0) {
+ recp_list = compose_create_encrypt_recipients_list(compose);
+
+ if (rfc2015_encrypt_armored(tmp_file, recp_list) < 0) {
alertpanel_error(_("Can't encrypt the message."));
+ g_slist_free(recp_list);
g_unlink(tmp_file);
g_free(tmp_file);
return -1;
}
+ g_slist_free(recp_list);
g_free(*text);
*text = file_read_to_str(tmp_file);
g_unlink(tmp_file);
@@ -3732,6 +3764,7 @@ static gint compose_encrypt_armored(Compose *compose, gchar **text)
static gint compose_encrypt_sign_armored(Compose *compose, gchar **text)
{
GSList *key_list;
+ GSList *recp_list;
gchar *tmp_file;
tmp_file = get_tmp_file();
@@ -3746,14 +3779,17 @@ static gint compose_encrypt_sign_armored(Compose *compose, gchar **text)
return -1;
}
- if (rfc2015_encrypt_sign_armored
- (tmp_file, compose->to_list, key_list) < 0) {
+ recp_list = compose_create_encrypt_recipients_list(compose);
+
+ if (rfc2015_encrypt_sign_armored(tmp_file, recp_list, key_list) < 0) {
alertpanel_error(_("Can't encrypt or sign the message."));
+ g_slist_free(recp_list);
g_unlink(tmp_file);
g_free(tmp_file);
return -1;
}
+ g_slist_free(recp_list);
g_free(*text);
*text = file_read_to_str(tmp_file);
g_unlink(tmp_file);
@@ -4077,6 +4113,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
}
} else if (use_pgpmime_encryption) {
GSList *key_list;
+ GSList *recp_list;
if (compose->use_bcc) {
const gchar *text;
@@ -4104,23 +4141,30 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
g_free(bcc);
}
}
+
+ recp_list = compose_create_encrypt_recipients_list(compose);
+
if (use_pgpmime_signing) {
if (compose_create_signers_list
(compose, &key_list) < 0) {
g_unlink(file);
return -1;
}
- if (rfc2015_encrypt_sign(file, compose->to_list,
- key_list) < 0) {
+
+ if (rfc2015_encrypt_sign(file, recp_list, key_list) < 0) {
alertpanel_error(_("Can't encrypt or sign the message."));
+ g_slist_free(recp_list);
g_unlink(file);
return -1;
}
- } else if (rfc2015_encrypt(file, compose->to_list) < 0) {
+ } else if (rfc2015_encrypt(file, recp_list) < 0) {
alertpanel_error(_("Can't encrypt the message."));
+ g_slist_free(recp_list);
g_unlink(file);
return -1;
}
+
+ g_slist_free(recp_list);
}
#endif /* USE_GPGME */
diff --git a/src/prefs_account_dialog.c b/src/prefs_account_dialog.c
index faf77734..6f56515e 100644
--- a/src/prefs_account_dialog.c
+++ b/src/prefs_account_dialog.c
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -142,6 +142,7 @@ static struct Privacy {
GtkWidget *default_sign_chkbtn;
GtkWidget *default_encrypt_chkbtn;
GtkWidget *encrypt_reply_chkbtn;
+ GtkWidget *encrypt_to_self_chkbtn;
GtkWidget *ascii_armored_chkbtn;
GtkWidget *clearsign_chkbtn;
GtkWidget *defaultkey_radiobtn;
@@ -343,6 +344,8 @@ static PrefsUIData ui_data[] = {
prefs_set_data_from_toggle, prefs_set_toggle},
{"encrypt_reply", &privacy.encrypt_reply_chkbtn,
prefs_set_data_from_toggle, prefs_set_toggle},
+ {"encrypt_to_self", &privacy.encrypt_to_self_chkbtn,
+ prefs_set_data_from_toggle, prefs_set_toggle},
{"ascii_armored", &privacy.ascii_armored_chkbtn,
prefs_set_data_from_toggle, prefs_set_toggle},
{"clearsign", &privacy.clearsign_chkbtn,
@@ -1432,6 +1435,7 @@ static void prefs_account_privacy_create(void)
GtkWidget *default_sign_chkbtn;
GtkWidget *default_encrypt_chkbtn;
GtkWidget *encrypt_reply_chkbtn;
+ GtkWidget *encrypt_to_self_chkbtn;
GtkWidget *ascii_armored_chkbtn;
GtkWidget *clearsign_chkbtn;
GtkWidget *defaultkey_radiobtn;
@@ -1454,6 +1458,8 @@ static void prefs_account_privacy_create(void)
_("PGP encrypt message by default"));
PACK_CHECK_BUTTON (vbox2, encrypt_reply_chkbtn,
_("Encrypt when replying to encrypted message"));
+ PACK_CHECK_BUTTON (vbox2, encrypt_to_self_chkbtn,
+ _("Add my own key to the recipients list"));
PACK_CHECK_BUTTON (vbox2, ascii_armored_chkbtn,
_("Use ASCII-armored format for encryption"));
PACK_CHECK_BUTTON (vbox2, clearsign_chkbtn,
@@ -1462,7 +1468,7 @@ static void prefs_account_privacy_create(void)
G_CALLBACK (prefs_account_ascii_armored_warning),
NULL);
- PACK_FRAME (vbox1, frame1, _("Sign key"));
+ PACK_FRAME (vbox1, frame1, _("Sign / Encryption key"));
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox2);
@@ -1518,6 +1524,7 @@ static void prefs_account_privacy_create(void)
privacy.default_sign_chkbtn = default_sign_chkbtn;
privacy.default_encrypt_chkbtn = default_encrypt_chkbtn;
privacy.encrypt_reply_chkbtn = encrypt_reply_chkbtn;
+ privacy.encrypt_to_self_chkbtn = encrypt_to_self_chkbtn;
privacy.ascii_armored_chkbtn = ascii_armored_chkbtn;
privacy.clearsign_chkbtn = clearsign_chkbtn;
privacy.defaultkey_radiobtn = defaultkey_radiobtn;
diff --git a/src/select-keys.c b/src/select-keys.c
index 5ee703f5..d441094d 100644
--- a/src/select-keys.c
+++ b/src/select-keys.c
@@ -1,5 +1,6 @@
/* select-keys.c - GTK+ based key selection
* Copyright (C) 2001 Werner Koch (dd9jn)
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -93,10 +94,10 @@ update_progress (struct select_keys_s *sk, int running, const char *pattern)
if (!pattern)
pattern = "";
if (!running)
- buf = g_strdup_printf (_("Please select key for `%s'"),
+ buf = g_strdup_printf (_("Please select key for \"%s\""),
pattern);
else
- buf = g_strdup_printf (_("Collecting info for `%s' ... %c"),
+ buf = g_strdup_printf (_("Collecting info for \"%s\" ... %c"),
pattern,
windmill[running%DIM(windmill)]);
gtk_label_set_text (sk->toplabel, buf);
@@ -124,7 +125,7 @@ gpgmegtk_recipient_selection (GSList *recp_names)
open_dialog (&sk);
do {
- sk.pattern = recp_names? recp_names->data:NULL;
+ sk.pattern = recp_names ? recp_names->data : NULL;
gtk_clist_clear (sk.clist);
fill_clist (&sk, sk.pattern);
update_progress (&sk, 0, sk.pattern);
@@ -223,7 +224,8 @@ fill_clist (struct select_keys_s *sk, const char *pattern)
clist = sk->clist;
g_return_if_fail (clist);
- debug_print ("select_keys:fill_clist: pattern `%s'\n", pattern);
+ debug_print ("select_keys:fill_clist: pattern '%s'\n",
+ pattern ? pattern : "");
/*gtk_clist_freeze (select_keys.clist);*/
err = gpgme_new (&ctx);
@@ -238,7 +240,7 @@ fill_clist (struct select_keys_s *sk, const char *pattern)
err = gpgme_op_keylist_start (ctx, pattern, 0);
if (err) {
debug_print ("** gpgme_op_keylist_start(%s) failed: %s",
- pattern, gpgme_strerror (err));
+ pattern ? pattern : "", gpgme_strerror (err));
sk->select_ctx = NULL;
gpgme_release(ctx);
return;