/* select-keys.c - GTK+ based key selection
- * Copyright (C) 2001-2006 Werner Koch (dd9jn) and the Sylpheed-Claws team
+ * Copyright (C) 2001-2007 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 set_row (GtkCList *clist, gpgme_key_t key);
+static void set_row (GtkCList *clist, gpgme_key_t key, gpgme_protocol_t proto);
static gpgme_key_t fill_clist (struct select_keys_s *sk, const char *pattern,
gpgme_protocol_t proto);
static void create_dialog (struct select_keys_s *sk);
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);
+static gboolean use_untrusted (gpgme_key_t, gpgme_protocol_t proto);
static void
update_progress (struct select_keys_s *sk, int running, const char *pattern)
sk.result = KEY_SELECTION_OK;
gpgme_release (sk.select_ctx);
sk.select_ctx = NULL;
- printf("used %s\n", key->uids->email);
+ debug_print("used %s\n", key->uids->email);
}
key = NULL;
if (recp_names)
}
static void
-set_row (GtkCList *clist, gpgme_key_t key)
+set_row (GtkCList *clist, gpgme_key_t key, gpgme_protocol_t proto)
{
const char *s;
const char *text[N_COL_TITLES];
char *algo_buf;
int row;
gsize by_read = 0, by_written = 0;
- gchar *ret_str;
+ gchar *ret_str = NULL;
/* first check whether the key is capable of encryption which is not
* the case for revoked, expired or sign-only keys */
s += 8; /* show only the short keyID */
text[COL_KEYID] = s;
+
s = key->uids->name;
- if (!s || !strlen(s))
+ if (!s || !*s)
s = key->uids->uid;
- ret_str = g_locale_to_utf8 (s, strlen(s), &by_read, &by_written, NULL);
+ if (proto == GPGME_PROTOCOL_CMS) {
+ if (strstr(s, ",CN="))
+ s = strstr(s, ",CN=")+4;
+ else if (strstr(s, "CN="))
+ s = strstr(s, "CN=")+3;
+ }
+
+ ret_str = NULL;
+ if (!g_utf8_validate(s, -1, NULL))
+ ret_str = g_locale_to_utf8 (s, strlen(s), &by_read, &by_written, NULL);
if (ret_str && by_written) {
s = ret_str;
}
text[COL_NAME] = s;
- s = key->uids->email;
- ret_str = g_locale_to_utf8 (s, strlen(s), &by_read, &by_written, NULL);
+ if (proto == GPGME_PROTOCOL_CMS && (!key->uids->email || !*key->uids->email)) {
+ gpgme_user_id_t uid = key->uids->next;
+ if (uid)
+ s = uid->email;
+ else
+ s = key->uids->email;
+ } else {
+ s = key->uids->email;
+ }
+
+ ret_str = NULL;
+ if (!g_utf8_validate(s, -1, NULL))
+ ret_str = g_locale_to_utf8 (s, strlen(s), &by_read, &by_written, NULL);
if (ret_str && by_written) {
s = ret_str;
}
pattern, gpgme_strerror (err));
sk->select_ctx = NULL;
gpgme_release(ctx);
- return FALSE;
+ return NULL;
}
update_progress (sk, ++running, pattern);
while ( !(err = gpgme_op_keylist_next ( ctx, &key )) ) {
gpgme_user_id_t uid = key->uids;
debug_print ("%% %s:%d: insert\n", __FILE__ ,__LINE__ );
- set_row (clist, key );
+ set_row (clist, key, proto );
for (; uid; uid = uid->next) {
- if (!strcmp(pattern, uid->email)) {
+ gchar *raw_mail = NULL;
+ if (!uid->email)
+ continue;
+ raw_mail = g_strdup(uid->email);
+ extract_address(raw_mail);
+ if (!strcmp(pattern, raw_mail)) {
exact_match = TRUE;
+ g_free(raw_mail);
break;
}
+ g_free(raw_mail);
}
num_results++;
last_key = key;
if (exact_match == TRUE && num_results == 1) {
if (last_key->uids->validity < GPGME_VALIDITY_FULL &&
- !use_untrusted(last_key))
+ !use_untrusted(last_key, proto))
exact_match = FALSE;
}
key = gtk_clist_get_row_data(sk->clist, row);
if (key) {
if ( key->uids->validity < GPGME_VALIDITY_FULL ) {
- use_key = use_untrusted(key);
+ use_key = use_untrusted(key, sk->proto);
if (!use_key) {
debug_print ("** Key untrusted, will not encrypt");
return;
static gboolean
-use_untrusted (gpgme_key_t key)
+use_untrusted (gpgme_key_t key, gpgme_protocol_t proto)
{
AlertValue aval;
- gchar *buf = g_strdup_printf(_("The key of '%s' is not fully trusted.\n"
+ gchar *buf = 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);