/* select-keys.c - GTK+ based key selection
- * Copyright (C) 2001-2007 Werner Koch (dd9jn) and the Claws Mail team
+ * Copyright (C) 2001-2012 Werner Koch (dd9jn) and the Claws Mail team
*
* 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
static void sort_keys_name (GtkWidget *widget, gpointer data);
static void sort_keys_email (GtkWidget *widget, gpointer data);
-static gboolean use_untrusted (gpgme_key_t, gpgme_protocol_t proto);
+static gboolean use_untrusted (gpgme_key_t, gpgme_user_id_t uid, gpgme_protocol_t proto);
static void
update_progress (struct select_keys_s *sk, int running, const char *pattern)
sk.proto = proto;
gtk_cmclist_clear (sk.clist);
key = fill_clist (&sk, sk.pattern, proto);
- update_progress (&sk, 0, sk.pattern);
+ update_progress (&sk, 0, sk.pattern ? sk.pattern : "NULL");
if (!key) {
gtk_widget_show_all (sk.window);
gtk_main ();
/* first check whether the key is capable of encryption which is not
* the case for revoked, expired or sign-only keys */
- if (!key->can_encrypt || key->revoked || key->expired)
+ if (!key->can_encrypt || key->revoked || key->expired || key->disabled)
return;
algo_buf = g_strdup_printf ("%du/%s",
gpgme_pubkey_algo_name(key->subkeys->pubkey_algo) );
text[COL_ALGO] = algo_buf;
- s = key->subkeys->keyid;
- if (strlen (s) == 16)
- s += 8; /* show only the short keyID */
- text[COL_KEYID] = s;
-
+ text[COL_KEYID] = key->subkeys->keyid;
s = key->uids->name;
if (!s || !*s)
int num_results = 0;
gboolean exact_match = FALSE;
gpgme_key_t last_key = NULL;
- g_return_val_if_fail (sk, NULL);
+ gpgme_user_id_t last_uid = NULL;
+ cm_return_val_if_fail (sk, NULL);
clist = sk->clist;
- g_return_val_if_fail (clist, NULL);
+ cm_return_val_if_fail (clist, NULL);
debug_print ("select_keys:fill_clist: pattern '%s' proto %d\n", pattern, proto);
update_progress (sk, ++running, pattern);
while ( !(err = gpgme_op_keylist_next ( ctx, &key )) ) {
gpgme_user_id_t uid = key->uids;
- if (!key->can_encrypt || key->revoked || key->expired)
+ if (!key->can_encrypt || key->revoked || key->expired || key->disabled)
continue;
debug_print ("%% %s:%d: insert\n", __FILE__ ,__LINE__ );
set_row (clist, key, proto );
if (!uid->email)
continue;
+ if (uid->revoked || uid->invalid)
+ continue;
raw_mail = g_strdup(uid->email);
extract_address(raw_mail);
if (!strcasecmp(pattern, raw_mail)) {
exact_match = TRUE;
+ last_uid = uid;
g_free(raw_mail);
break;
}
if (exact_match == TRUE && num_results == 1) {
if (last_key->uids->validity < GPGME_VALIDITY_FULL &&
- !use_untrusted(last_key, proto))
+ !use_untrusted(last_key, last_uid, proto))
exact_match = FALSE;
}
g_assert (!sk->window);
window = gtkut_window_new (GTK_WINDOW_TOPLEVEL, "select-keys");
- gtk_widget_set_size_request (window, 520, 280);
+ gtk_widget_set_size_request (window, 560, 280);
gtk_container_set_border_width (GTK_CONTAINER (window), 8);
gtk_window_set_title (GTK_WINDOW (window), _("Select Keys"));
gtk_window_set_modal (GTK_WINDOW (window), TRUE);
clist = gtk_cmclist_new_with_titles (N_COL_TITLES, (char**)titles);
gtk_container_add (GTK_CONTAINER (scrolledwin), clist);
- gtk_cmclist_set_column_width (GTK_CMCLIST(clist), COL_ALGO, 72);
- gtk_cmclist_set_column_width (GTK_CMCLIST(clist), COL_KEYID, 76);
- gtk_cmclist_set_column_width (GTK_CMCLIST(clist), COL_NAME, 130);
- gtk_cmclist_set_column_width (GTK_CMCLIST(clist), COL_EMAIL, 130);
+ gtk_cmclist_set_column_width (GTK_CMCLIST(clist), COL_ALGO, 70);
+ gtk_cmclist_set_column_width (GTK_CMCLIST(clist), COL_KEYID, 120);
+ gtk_cmclist_set_column_width (GTK_CMCLIST(clist), COL_NAME, 115);
+ gtk_cmclist_set_column_width (GTK_CMCLIST(clist), COL_EMAIL, 140);
gtk_cmclist_set_column_width (GTK_CMCLIST(clist), COL_VALIDITY, 20);
gtk_cmclist_set_selection_mode (GTK_CMCLIST(clist), GTK_SELECTION_BROWSE);
g_signal_connect (G_OBJECT(GTK_CMCLIST(clist)->column[COL_NAME].button),
hbox = gtk_hbox_new (FALSE, 8);
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+ /* TRANSLATORS: check that the accelerators in _Select, _Other and
+ * Do_n't encrypt are different than the one in the stock Cancel
+ * button */
gtkut_stock_button_set_create (&bbox,
- &select_btn, _("Select"),
- &other_btn, _("Other"),
- &dont_encrypt_btn, _("Don't encrypt"));
+ &select_btn, _("_Select"),
+ &other_btn, _("_Other"),
+ &dont_encrypt_btn, _("Do_n't encrypt"));
cancel_btn = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
- GTK_WIDGET_SET_FLAGS(cancel_btn, GTK_CAN_DEFAULT);
+ gtkut_widget_set_can_default(cancel_btn, TRUE);
gtk_box_pack_start(GTK_BOX(bbox), cancel_btn, TRUE, TRUE, 0);
gtk_widget_show(cancel_btn);
gtk_box_pack_end (GTK_BOX (hbox), bbox, FALSE, FALSE, 0);
static void
close_dialog (struct select_keys_s *sk)
{
- g_return_if_fail (sk);
+ cm_return_if_fail (sk);
gtk_widget_destroy (sk->window);
sk->window = NULL;
}
{
struct select_keys_s *sk = data;
- g_return_val_if_fail (sk, FALSE);
- if (event && event->keyval == GDK_Escape) {
+ cm_return_val_if_fail (sk, FALSE);
+ if (event && event->keyval == GDK_KEY_Escape) {
sk->okay = 0;
gtk_main_quit ();
}
gboolean use_key;
gpgme_key_t key;
- g_return_if_fail (sk);
+ cm_return_if_fail (sk);
if (!sk->clist->selection) {
debug_print ("** nothing selected");
return;
row = GPOINTER_TO_INT(sk->clist->selection->data);
key = gtk_cmclist_get_row_data(sk->clist, row);
if (key) {
- if ( key->uids->validity < GPGME_VALIDITY_FULL ) {
- use_key = use_untrusted(key, sk->proto);
+ gpgme_user_id_t uid;
+ for (uid = key->uids; uid; uid = uid->next) {
+ gchar *raw_mail = NULL;
+
+ if (!uid->email)
+ continue;
+ raw_mail = g_strdup(uid->email);
+ extract_address(raw_mail);
+ if (sk->pattern && !strcasecmp(sk->pattern, raw_mail)) {
+ g_free(raw_mail);
+ break;
+ }
+ g_free(raw_mail);
+ }
+ if (!uid)
+ uid = key->uids;
+
+ if ( uid->validity < GPGME_VALIDITY_FULL ) {
+ use_key = use_untrusted(key, uid, sk->proto);
if (!use_key) {
debug_print ("** Key untrusted, will not encrypt");
return;
{
struct select_keys_s *sk = data;
- g_return_if_fail (sk);
+ cm_return_if_fail (sk);
sk->okay = 0;
sk->result = KEY_SELECTION_CANCEL;
if (sk->select_ctx)
{
struct select_keys_s *sk = data;
- g_return_if_fail (sk);
+ cm_return_if_fail (sk);
sk->okay = 0;
sk->result = KEY_SELECTION_DONT;
if (sk->select_ctx)
struct select_keys_s *sk = data;
char *uid;
- g_return_if_fail (sk);
+ cm_return_if_fail (sk);
uid = input_dialog ( _("Add key"),
_("Enter another user or key ID:"),
NULL );
static gboolean
-use_untrusted (gpgme_key_t key, gpgme_protocol_t proto)
+use_untrusted (gpgme_key_t key, gpgme_user_id_t uid, gpgme_protocol_t proto)
{
AlertValue aval;
gchar *buf = NULL;
-
+ gchar *title = NULL;
if (proto != GPGME_PROTOCOL_OpenPGP)
return TRUE;
- buf = g_strdup_printf(_("The key of '%s' is not fully trusted.\n"
- "If you choose to encrypt the message with this key you don't\n"
- "know for sure that it will go to the person you mean it to.\n"
- "Do you trust it enough to use it anyway?"), key->uids->email);
+ title = g_strdup_printf(_("Encrypt to %s <%s>"), uid->name, uid->email);
+ buf = g_strdup_printf(_("This encryption key is not fully trusted.\n"
+ "If you choose to encrypt the message with this key, you don't\n"
+ "know for sure that it will go to the person you mean it to.\n\n"
+ "Key details: ID %s, primary identity %s <%s>\n\n"
+ "Do you trust this key enough to use it anyway?"),
+ key->subkeys->keyid, key->uids->name, key->uids->email);
aval = alertpanel
- (_("Trust key"),
- buf,
+ (title, buf,
GTK_STOCK_NO, GTK_STOCK_YES, NULL);
g_free(buf);
+ g_free(title);
if (aval == G_ALERTALTERNATE)
return TRUE;
else