Hi all,

attached is a trivial patch for the autocrypt branch, addressing the following 
Autocrypt-related issues:
* If Autocrypt is activated for an identity, but no gpg private key fingerprint 
is given (the usual case), and no usable private key exists, calling 
libbalsa_gpgme_export_autocrypt_key() via autocrypt_header() triggers a 
CRITICAL.  The patch fills in a proper error message in this case.
* An Autocrypt header is added even if the message is only postponed, which is 
useless.
* Remember the size of the Autocrypt database window.

Cheers,
Albrecht.

---
Patch details:
- libbalsa/autocrypt.c: set a proper error message if no fingerprint of a 
usable private key can be identified for a mailbox; fix memory leak; attach 
Autocrypt database window to geometry manager
- libbalsa/send.c: do not add Autocrypt header when postponing; propagate error 
from creating Autocrypt header
- src/save-restore.c: restore Autocrypt database window geometry
diff --git a/libbalsa/autocrypt.c b/libbalsa/autocrypt.c
index cfcb6aae5..6c6c5f5a7 100644
--- a/libbalsa/autocrypt.c
+++ b/libbalsa/autocrypt.c
@@ -32,6 +32,7 @@
 #include "libbalsa-gpgme-keys.h"
 #include "libbalsa-gpgme-widgets.h"
 #include "identity.h"
+#include "geometry-manager.h"
 #include "autocrypt.h"
 
 
@@ -297,7 +298,6 @@ autocrypt_header(const LibBalsaIdentity *identity, GError **error)
 	const gchar *mailbox;
 	gchar *use_fpr = NULL;
 	gchar *result = NULL;
-	gchar *keydata;
 
 	g_return_val_if_fail((identity != NULL) && (identity->autocrypt_mode != AUTOCRYPT_DISABLE), NULL);
 	mailbox = internet_address_mailbox_get_addr(INTERNET_ADDRESS_MAILBOX(identity->ia));
@@ -321,27 +321,38 @@ autocrypt_header(const LibBalsaIdentity *identity, GError **error)
 			}
 			gpgme_release(ctx);
 		}
-		g_debug("found fingerprint %s for '%s'", use_fpr, mailbox);
+
+		if (use_fpr == NULL) {
+			g_set_error(error, AUTOCRYPT_ERROR_QUARK, -1,
+				_("No usable private key for “%s” found! Please create a key or disable Autocrypt."), mailbox);
+		} else {
+			g_debug("found fingerprint %s for '%s'", use_fpr, mailbox);
+		}
 	} else {
 		use_fpr = g_strdup(identity->force_gpg_key_id);
 	}
 
-	keydata = libbalsa_gpgme_export_autocrypt_key(use_fpr, mailbox, error);
-	g_free(use_fpr);
-	if (keydata != NULL) {
-		GString *buffer;
-		gssize ins_fws;
+	if (use_fpr != NULL) {
+		gchar *keydata;
 
-		buffer = g_string_new(NULL);
-		g_string_append_printf(buffer, "addr=%s;", mailbox);
-		if (identity->autocrypt_mode == AUTOCRYPT_PREFER_ENCRYPT) {
-			g_string_append(buffer, "prefer-encrypt=mutual;");
-		}
-		g_string_append_printf(buffer, "keydata=%s", keydata);
-		for (ins_fws = 66U; ins_fws < (gssize) buffer->len; ins_fws += 78) {
-			g_string_insert(buffer, ins_fws, "\n\t");
+		keydata = libbalsa_gpgme_export_autocrypt_key(use_fpr, mailbox, error);
+		g_free(use_fpr);
+		if (keydata != NULL) {
+			GString *buffer;
+			gssize ins_fws;
+
+			buffer = g_string_new(NULL);
+			g_string_append_printf(buffer, "addr=%s;", mailbox);
+			if (identity->autocrypt_mode == AUTOCRYPT_PREFER_ENCRYPT) {
+				g_string_append(buffer, "prefer-encrypt=mutual;");
+			}
+			g_string_append_printf(buffer, "keydata=%s", keydata);
+			for (ins_fws = 66; ins_fws < (gssize) buffer->len; ins_fws += 78) {
+				g_string_insert(buffer, ins_fws, "\n\t");
+			}
+			result = g_string_free(buffer, FALSE);
+			g_free(keydata);
 		}
-		result = g_string_free(buffer, FALSE);
 	}
 
 	return result;
@@ -444,6 +455,7 @@ autocrypt_db_dialog_run(const gchar *date_string, GtkWindow *parent)
 
 	dialog = gtk_dialog_new_with_buttons(_("Autocrypt database"), parent,
 		GTK_DIALOG_DESTROY_WITH_PARENT | libbalsa_dialog_flags(), _("_Close"), GTK_RESPONSE_CLOSE, NULL);
+	geometry_manager_attach(GTK_WINDOW(dialog), "AutocryptDB");
 
     vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
     gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox);
diff --git a/libbalsa/send.c b/libbalsa/send.c
index 33ed67fed..38947d2af 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -1511,9 +1511,9 @@ libbalsa_message_create_mime_message(LibBalsaMessage *message,
 
 #ifdef ENABLE_AUTOCRYPT
     /* add Autocrypt header if requested */
-    if ((message->ident != NULL) && (message->ident->autocrypt_mode != AUTOCRYPT_DISABLE) &&
+    if (!postponing && (message->ident != NULL) && (message->ident->autocrypt_mode != AUTOCRYPT_DISABLE) &&
     	!autocrypt_ignore(g_mime_object_get_content_type(mime_root))) {
-    	tmp = autocrypt_header(message->ident, NULL);
+    	tmp = autocrypt_header(message->ident, error);
     	if (tmp == NULL) {
     		g_object_unref(G_OBJECT(mime_message));
     		return LIBBALSA_MESSAGE_CREATE_ERROR;
diff --git a/src/save-restore.c b/src/save-restore.c
index 4c96754c3..23313fb9c 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -695,7 +695,10 @@ config_global_load(void)
 #ifdef HAVE_GPGME
     geometry_manager_init("KeyDialog", 400, 200, FALSE);
     geometry_manager_init("KeyList", 300, 200, FALSE);
-#endif
+#ifdef ENABLE_AUTOCRYPT
+    geometry_manager_init("AutocryptDB", 300, 200, FALSE);
+#endif  /* ENABLE_AUTOCRYPT */
+#endif  /* HAVE_GPGME */
 
     /* FIXME: PKGW: why comment this out? Breaks my Transfer context menu. */
     if (balsa_app.mblist_width < 100)

Attachment: pgpnCBPbeLQ6Y.pgp
Description: PGP signature

_______________________________________________
balsa-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/balsa-list

Reply via email to