[balsa/gtk3] A few fixes and other cleanups (Albrecht Dre ß)



commit e56c50348c5b41d813eac5d71a80210ff6157260
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Mar 12 16:59:38 2016 -0500

    A few fixes and other cleanups (Albrecht Dreß)
    
        * Bug fixes: due to broken assignments in libbalsa_gpgme_init(),
          the callbacks for selecting a GnuPG key from a list
          or for accepting low-trust keys individually are never called.
          When selecting a key, only the first subkey is checked,
          instead of all potential ones.
        * Message improvements: When checking a GnuPG signed message
          where the key has expired, Balsa displays a
          "Signature could not be checked" error
          and an informational message containg the "real" result.
          The patch removes the (wrong) former message.
        * Code cleanups: change the return value of all crypto-related
          functions which return an essentially bool value to gboolean
          instead of (g)int, remove hacks for Emacs (still someone using it?)
          in header files which confuse almost all other tools,
          fix a few minor glitches, and remove a few unused statements.
    
        * libbalsa-gpgme.c: fix callback assignment bug,
        implement new function to verify all subkeys of a key
        * rfc3156.c: remove confusing error message
        * gmime-application-pkcs7.h, gmime-application-pkcs7.c,
          gmime-multipart-crypt.c, gmime-multipart-crypt.h,
          gmime-part-rfc2440.c, gmime-part-rfc2440.h, libbalsa-gpgme.c,
          libbalsa-gpgme.h: change function return types to gboolean
        * rfc3156.c: used changed api
        * gmime-gpgme-signature.h, gmime-multipart-crypt.h,
          gmime-part-rfc2440.h, libbalsa-gpgme.h: remove Emacs hack
        * gmime-multipart-crypt.c: reorder statements to avoid duplicated ones
          (g_mime_gpgme_mps_sign)
        * gmime-multipart-crypt.c, rfc3156.c: use error checking macro instead of cast
        * libbalsa-gpgme.c: remove assignments of variables which are never used
        * send.c, smtp-server.c, src/filter-edit-callbacks.c: remove unused statements

 ChangeLog                          |   34 ++++++++++
 libbalsa/gmime-application-pkcs7.c |   18 +++---
 libbalsa/gmime-application-pkcs7.h |    2 +-
 libbalsa/gmime-gpgme-signature.h   |    3 -
 libbalsa/gmime-multipart-crypt.c   |   29 ++++-----
 libbalsa/gmime-multipart-crypt.h   |    7 +--
 libbalsa/gmime-part-rfc2440.c      |   29 ++++-----
 libbalsa/gmime-part-rfc2440.h      |    6 +--
 libbalsa/libbalsa-gpgme.c          |  122 ++++++++++++++++++++----------------
 libbalsa/libbalsa-gpgme.h          |    8 +--
 libbalsa/rfc3156.c                 |   19 +++---
 libbalsa/send.c                    |    1 -
 libbalsa/smtp-server.c             |    2 -
 src/filter-edit-callbacks.c        |    1 -
 14 files changed, 156 insertions(+), 125 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f34778b..bdf4ba5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2016-03-12  Albrecht Dreß
+
+       * Bug fixes: due to broken assignments in libbalsa_gpgme_init(),
+         the callbacks for selecting a GnuPG key from a list
+         or for accepting low-trust keys individually are never called.
+         When selecting a key, only the first subkey is checked,
+         instead of all potential ones.
+       * Message improvements: When checking a GnuPG signed message
+         where the key has expired, Balsa displays a
+         "Signature could not be checked" error
+         and an informational message containg the "real" result.
+         The patch removes the (wrong) former message.
+       * Code cleanups: change the return value of all crypto-related
+         functions which return an essentially bool value to gboolean
+         instead of (g)int, remove hacks for Emacs (still someone using it?)
+         in header files which confuse almost all other tools,
+         fix a few minor glitches, and remove a few unused statements.
+
+       * libbalsa-gpgme.c: fix callback assignment bug,
+       implement new function to verify all subkeys of a key
+       * rfc3156.c: remove confusing error message
+       * gmime-application-pkcs7.h, gmime-application-pkcs7.c,
+         gmime-multipart-crypt.c, gmime-multipart-crypt.h,
+         gmime-part-rfc2440.c, gmime-part-rfc2440.h, libbalsa-gpgme.c,
+         libbalsa-gpgme.h: change function return types to gboolean
+       * rfc3156.c: used changed api
+       * gmime-gpgme-signature.h, gmime-multipart-crypt.h,
+         gmime-part-rfc2440.h, libbalsa-gpgme.h: remove Emacs hack
+       * gmime-multipart-crypt.c: reorder statements to avoid duplicated ones
+         (g_mime_gpgme_mps_sign)
+       * gmime-multipart-crypt.c, rfc3156.c: use error checking macro instead of cast
+       * libbalsa-gpgme.c: remove assignments of variables which are never used
+       * send.c, smtp-server.c, src/filter-edit-callbacks.c: remove unused statements
+
 2016-02-23  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Build without libnotify
diff --git a/libbalsa/gmime-application-pkcs7.c b/libbalsa/gmime-application-pkcs7.c
index cad055c..38cc3b3 100644
--- a/libbalsa/gmime-application-pkcs7.c
+++ b/libbalsa/gmime-application-pkcs7.c
@@ -130,11 +130,11 @@ g_mime_application_pkcs7_decrypt_verify(GMimePart * pkcs7,
 
 /*
  * Encrypt content for all recipients in recipients using the context ctx and
- * return the resulting application/pkcs7-mime object in pkcs7. Return 0 on
- * success and -1 on fail. In the latter case, fill err with more information
+ * return the resulting application/pkcs7-mime object in pkcs7. Return TRUE on
+ * success and FALSE on fail. In the latter case, fill err with more information
  * about the reason.
  */
-int
+gboolean
 g_mime_application_pkcs7_encrypt(GMimePart * pkcs7, GMimeObject * content,
                                 GPtrArray * recipients,
                                 gboolean trust_all, GtkWindow * parent,
@@ -145,8 +145,8 @@ g_mime_application_pkcs7_encrypt(GMimePart * pkcs7, GMimeObject * content,
     GMimeStream *stream, *ciphertext;
     GMimeFilter *crlf_filter;
        
-    g_return_val_if_fail(GMIME_IS_PART(pkcs7), -1);
-    g_return_val_if_fail(GMIME_IS_OBJECT(content), -1);
+    g_return_val_if_fail(GMIME_IS_PART(pkcs7), FALSE);
+    g_return_val_if_fail(GMIME_IS_OBJECT(content), FALSE);
        
     /* get the cleartext */
     stream = g_mime_stream_mem_new();
@@ -166,12 +166,12 @@ g_mime_application_pkcs7_encrypt(GMimePart * pkcs7, GMimeObject * content,
        
     /* encrypt the content stream */
     ciphertext = g_mime_stream_mem_new();
-    if (libbalsa_gpgme_encrypt
+    if (!libbalsa_gpgme_encrypt
        (recipients, NULL, stream, ciphertext, GPGME_PROTOCOL_CMS, TRUE,
-        trust_all, parent, err) == -1) {
+        trust_all, parent, err)) {
        g_object_unref(ciphertext);
        g_object_unref(stream);
-       return -1;
+       return FALSE;
     }
        
     g_object_unref(stream);
@@ -194,5 +194,5 @@ g_mime_application_pkcs7_encrypt(GMimePart * pkcs7, GMimeObject * content,
     g_mime_object_set_content_type_parameter(GMIME_OBJECT(pkcs7), "name",
                                             "smime.p7m");
        
-    return 0;
+    return TRUE;
 }
diff --git a/libbalsa/gmime-application-pkcs7.h b/libbalsa/gmime-application-pkcs7.h
index 6b9e0e7..6458357 100644
--- a/libbalsa/gmime-application-pkcs7.h
+++ b/libbalsa/gmime-application-pkcs7.h
@@ -36,7 +36,7 @@ extern "C" {
                                                         GtkWindow *
                                                         parent,
                                                         GError ** err);
-    int g_mime_application_pkcs7_encrypt(GMimePart * pkcs7,
+       gboolean g_mime_application_pkcs7_encrypt(GMimePart * pkcs7,
                                  GMimeObject * content,
                                         GPtrArray * recipients,
                                         gboolean trust_all,
diff --git a/libbalsa/gmime-gpgme-signature.h b/libbalsa/gmime-gpgme-signature.h
index 962f63c..948d3c7 100644
--- a/libbalsa/gmime-gpgme-signature.h
+++ b/libbalsa/gmime-gpgme-signature.h
@@ -27,9 +27,6 @@
 
 #ifdef __cplusplus
 extern "C" {
-#  ifdef MAKE_EMACS_HAPPY
-}
-#  endif
 #endif                         /* __cplusplus */
 
 
diff --git a/libbalsa/gmime-multipart-crypt.c b/libbalsa/gmime-multipart-crypt.c
index e78dbb4..ddeab55 100644
--- a/libbalsa/gmime-multipart-crypt.c
+++ b/libbalsa/gmime-multipart-crypt.c
@@ -81,7 +81,7 @@ sign_prepare(GMimeObject * mime_part)
 }
 
 
-int
+gboolean
 g_mime_gpgme_mps_sign(GMimeMultipartSigned * mps, GMimeObject * content,
                      const gchar * userid, gpgme_protocol_t protocol,
                      GtkWindow * parent, GError ** err)
@@ -97,8 +97,8 @@ g_mime_gpgme_mps_sign(GMimeMultipartSigned * mps, GMimeObject * content,
     const gchar *sig_type;
     gpgme_hash_algo_t hash_algo;
 
-    g_return_val_if_fail(GMIME_IS_MULTIPART_SIGNED(mps), -1);
-    g_return_val_if_fail(GMIME_IS_OBJECT(content), -1);
+    g_return_val_if_fail(GMIME_IS_MULTIPART_SIGNED(mps), FALSE);
+    g_return_val_if_fail(GMIME_IS_OBJECT(content), FALSE);
 
     /* Prepare all the parts for signing... */
     sign_prepare(content);
@@ -135,14 +135,13 @@ g_mime_gpgme_mps_sign(GMimeMultipartSigned * mps, GMimeObject * content,
     hash_algo =
        libbalsa_gpgme_sign(userid, filtered, sigstream, protocol, FALSE,
                            parent, err);
+    g_object_unref(filtered);
     if (hash_algo == GPGME_MD_NONE) {
        g_object_unref(sigstream);
-       g_object_unref(filtered);
        g_object_unref(stream);
-       return -1;
+       return FALSE;
     }
 
-    g_object_unref(filtered);
     g_mime_stream_reset(sigstream);
     g_mime_stream_reset(stream);
 
@@ -199,7 +198,7 @@ g_mime_gpgme_mps_sign(GMimeMultipartSigned * mps, GMimeObject * content,
     g_object_unref(signature);
     g_object_unref(content);
 
-    return 0;
+    return TRUE;
 }
 
 
@@ -220,7 +219,7 @@ g_mime_gpgme_mps_verify(GMimeMultipartSigned * mps, GError ** error)
 
     g_return_val_if_fail(GMIME_IS_MULTIPART_SIGNED(mps), NULL);
 
-    if (g_mime_multipart_get_count((GMimeMultipart *) mps) < 2) {
+    if (g_mime_multipart_get_count(GMIME_MULTIPART(mps)) < 2) {
        g_set_error(error, GMIME_ERROR, GMIME_ERROR_PARSE_ERROR, "%s",
                    _
                    ("Cannot verify multipart/signed part due to missing subparts."));
@@ -312,7 +311,7 @@ g_mime_gpgme_mps_verify(GMimeMultipartSigned * mps, GError ** error)
 }
 
 
-int
+gboolean
 g_mime_gpgme_mpe_encrypt(GMimeMultipartEncrypted * mpe,
                         GMimeObject * content, GPtrArray * recipients,
                         gboolean trust_all, GtkWindow * parent,
@@ -327,8 +326,8 @@ g_mime_gpgme_mpe_encrypt(GMimeMultipartEncrypted * mpe,
     GMimeDataWrapper *wrapper;
     GMimeFilter *crlf_filter;
 
-    g_return_val_if_fail(GMIME_IS_MULTIPART_ENCRYPTED(mpe), -1);
-    g_return_val_if_fail(GMIME_IS_OBJECT(content), -1);
+    g_return_val_if_fail(GMIME_IS_MULTIPART_ENCRYPTED(mpe), FALSE);
+    g_return_val_if_fail(GMIME_IS_OBJECT(content), FALSE);
 
     /* get the cleartext */
     stream = g_mime_stream_mem_new();
@@ -348,12 +347,12 @@ g_mime_gpgme_mpe_encrypt(GMimeMultipartEncrypted * mpe,
 
     /* encrypt the content stream */
     ciphertext = g_mime_stream_mem_new();
-    if (libbalsa_gpgme_encrypt
+    if (!libbalsa_gpgme_encrypt
        (recipients, NULL, stream, ciphertext, GPGME_PROTOCOL_OpenPGP,
-        FALSE, trust_all, parent, err) == -1) {
+        FALSE, trust_all, parent, err)) {
        g_object_unref(ciphertext);
        g_object_unref(stream);
-       return -1;
+       return FALSE;
     }
 
     g_object_unref(stream);
@@ -413,7 +412,7 @@ g_mime_gpgme_mpe_encrypt(GMimeMultipartEncrypted * mpe,
                                             "application/pgp-encrypted");
     g_mime_multipart_set_boundary(GMIME_MULTIPART(mpe), NULL);
 
-    return 0;
+    return TRUE;
 }
 
 
diff --git a/libbalsa/gmime-multipart-crypt.h b/libbalsa/gmime-multipart-crypt.h
index f7cc428..f4a633b 100644
--- a/libbalsa/gmime-multipart-crypt.h
+++ b/libbalsa/gmime-multipart-crypt.h
@@ -41,19 +41,16 @@
 
 #ifdef __cplusplus
 extern "C" {
-#ifdef MAKE_EMACS_HAPPY
-}
-#endif
 #endif                         /* __cplusplus */
 
 
 GMimeGpgmeSigstat *g_mime_gpgme_mps_verify(GMimeMultipartSigned * mps,
                                           GError ** error);
-int g_mime_gpgme_mps_sign(GMimeMultipartSigned * mps,
+gboolean g_mime_gpgme_mps_sign(GMimeMultipartSigned * mps,
                          GMimeObject * content, const gchar * userid,
                          gpgme_protocol_t protocol, GtkWindow * parent,
                          GError ** err);
-int g_mime_gpgme_mpe_encrypt(GMimeMultipartEncrypted * mpe,
+gboolean g_mime_gpgme_mpe_encrypt(GMimeMultipartEncrypted * mpe,
                             GMimeObject * content, GPtrArray * recipients,
                             gboolean trust_all, GtkWindow * parent,
                             GError ** err);
diff --git a/libbalsa/gmime-part-rfc2440.c b/libbalsa/gmime-part-rfc2440.c
index 33ace50..ca1eeab 100644
--- a/libbalsa/gmime-part-rfc2440.c
+++ b/libbalsa/gmime-part-rfc2440.c
@@ -41,7 +41,7 @@
  *
  * Check if the passed part is RFC 2440 signed or encrypted by looking for
  * the "magic" strings defined there.  Note that parts which include extra
- * data before the beginning or after the end of signed or encryped matter
+ * data before the beginning or after the end of signed or encrypted matter
  * are always classified as GMIME_PART_RFC2440_NONE.
  */
 GMimePartRfc2440Mode
@@ -115,16 +115,15 @@ g_mime_part_check_rfc2440(GMimePart * part)
  *        encryption.
  * \param parent Parent window to be passed to the callback functions.
  * \param error Filled with error information on error.
- * \return 0 on success, or -1 on error.
+ * \return TRUE on success, or FALSE on error.
  *
  * RFC2440 sign, encrypt or sign and encrypt a gmime part.  If sign_userid
  * is not NULL, part will be signed.  If recipients is not NULL, encrypt
  * part for recipients.  If both are not null, part will be both signed and
- * encrypted. Returns 0 on success or -1 on fail. If any operation
- * failed, an exception will be set on err to provide more
- * information.
+ * encrypted. Returns TRUE on success or FALSE on fail. If any operation
+ * failed, an exception will be set on err to provide more information.
  */
-int
+gboolean
 g_mime_part_rfc2440_sign_encrypt(GMimePart * part, const char *sign_userid,
                                 GPtrArray * recipients,
                                 gboolean trust_all, GtkWindow * parent,
@@ -133,14 +132,14 @@ g_mime_part_rfc2440_sign_encrypt(GMimePart * part, const char *sign_userid,
     GMimeDataWrapper *wrapper;
     GMimeStream *stream, *cipherstream;
     GByteArray *cipherdata;
-    gint result;
+    gboolean result;
 
-    g_return_val_if_fail(GMIME_IS_PART(part), -1);
-    g_return_val_if_fail(recipients != NULL || sign_userid != NULL, -1);
+    g_return_val_if_fail(GMIME_IS_PART(part), FALSE);
+    g_return_val_if_fail(recipients != NULL || sign_userid != NULL, FALSE);
 
     /* get the raw content */
     wrapper = g_mime_part_get_content_object(part);
-    g_return_val_if_fail(wrapper, -1); /* Incomplete part. */
+    g_return_val_if_fail(wrapper, FALSE); /* Incomplete part. */
     stream = g_mime_data_wrapper_get_stream(wrapper);
     g_mime_stream_reset(stream);
 
@@ -154,17 +153,17 @@ g_mime_part_rfc2440_sign_encrypt(GMimePart * part, const char *sign_userid,
        if (libbalsa_gpgme_sign
            (sign_userid, stream, cipherstream, GPGME_PROTOCOL_OpenPGP,
             TRUE, parent, err) == GPGME_MD_NONE)
-           result = -1;
+           result = FALSE;
     else
-           result = 0;
+           result = TRUE;
     } else
        result =
            libbalsa_gpgme_encrypt(recipients, sign_userid, stream,
                                   cipherstream, GPGME_PROTOCOL_OpenPGP,
                                   TRUE, trust_all, parent, err);
-    if (result == -1) {
+    if (!result) {
        g_object_unref(cipherstream);
-       return -1;
+       return result;
     }
 
     /* add the headers to encrypted ascii armor output: as there is no
@@ -217,7 +216,7 @@ g_mime_part_rfc2440_sign_encrypt(GMimePart * part, const char *sign_userid,
     g_object_unref(cipherstream);
     g_object_unref(wrapper);
 
-    return 0;
+    return result;
 }
 
 
diff --git a/libbalsa/gmime-part-rfc2440.h b/libbalsa/gmime-part-rfc2440.h
index d70466d..104404d 100644
--- a/libbalsa/gmime-part-rfc2440.h
+++ b/libbalsa/gmime-part-rfc2440.h
@@ -30,10 +30,6 @@
 
 #ifdef __cplusplus
 extern "C" {
-
-#ifdef MAKE_EMACS_HAPPY
-}
-#endif
 #endif                         /* __cplusplus */
 typedef enum _GMimePartRfc2440Mode GMimePartRfc2440Mode;
 enum _GMimePartRfc2440Mode { 
@@ -47,7 +43,7 @@ enum _GMimePartRfc2440Mode {
 GMimePartRfc2440Mode g_mime_part_check_rfc2440(GMimePart * part);
 
 /* crypto routines */
-int g_mime_part_rfc2440_sign_encrypt(GMimePart * part,
+gboolean g_mime_part_rfc2440_sign_encrypt(GMimePart * part,
                                     const char *sign_userid,
                                     GPtrArray * recipients,
                                     gboolean trust_all,
diff --git a/libbalsa/libbalsa-gpgme.c b/libbalsa/libbalsa-gpgme.c
index 4d00322..1110677 100644
--- a/libbalsa/libbalsa-gpgme.c
+++ b/libbalsa/libbalsa-gpgme.c
@@ -168,8 +168,8 @@ libbalsa_gpgme_init(gpgme_passphrase_cb_t get_passphrase,
 #endif
 
     /* remember callbacks */
-    select_key = select_key_cb;
-    accept_low_trust = accept_low_trust_cb;
+    select_key_cb = select_key;
+    accept_low_trust_cb = accept_low_trust;
 }
 
 
@@ -327,9 +327,8 @@ libbalsa_gpgme_sign(const gchar * userid, GMimeStream * istream,
                         protocol == GPGME_PROTOCOL_CMS, GPGME_MD_NONE);
 
     /* create the GpgME context */
-    if ((err =
-        gpgme_new_with_protocol(&ctx, protocol, parent,
-                                error)) != GPG_ERR_NO_ERROR)
+    if (gpgme_new_with_protocol(&ctx, protocol, parent,
+                                error) != GPG_ERR_NO_ERROR)
        return GPGME_MD_NONE;
 
     /* set the signature mode */
@@ -402,13 +401,13 @@ libbalsa_gpgme_sign(const gchar * userid, GMimeStream * istream,
  *        to ask the user whether a low-trust key shall be accepted.
  * \param parent Parent window to be passed to the callback functions.
  * \param error Filled with error information on error.
- * \return 0 on success, or -1 on error.
+ * \return TRUE on success, or FALSE on error.
  *
  * Encrypt the passed matter and write the result to the output stream.
  * Combined signing and encryption is allowed for single-part OpenPGP mode
  * only.
  */
-int
+gboolean
 libbalsa_gpgme_encrypt(GPtrArray * recipients, const char *sign_for,
                       GMimeStream * istream, GMimeStream * ostream,
                       gpgme_protocol_t protocol, gboolean singlepart_mode,
@@ -428,17 +427,16 @@ libbalsa_gpgme_encrypt(GPtrArray * recipients, const char *sign_for,
     };
 
     /* paranoia checks */
-    g_return_val_if_fail(recipients != NULL, -1);
-    g_return_val_if_fail(GMIME_IS_STREAM(istream), -1);
-    g_return_val_if_fail(GMIME_IS_STREAM(ostream), GPGME_MD_NONE);
+    g_return_val_if_fail(recipients != NULL, FALSE);
+    g_return_val_if_fail(GMIME_IS_STREAM(istream), FALSE);
+    g_return_val_if_fail(GMIME_IS_STREAM(ostream), FALSE);
     g_return_val_if_fail(protocol == GPGME_PROTOCOL_OpenPGP ||
-                        protocol == GPGME_PROTOCOL_CMS, -1);
+                        protocol == GPGME_PROTOCOL_CMS, FALSE);
 
     /* create the GpgME context */
-    if ((err =
-        gpgme_new_with_protocol(&ctx, protocol, parent,
-                                error)) != GPG_ERR_NO_ERROR)
-       return -1;
+    if (gpgme_new_with_protocol(&ctx, protocol, parent,
+                                error) != GPG_ERR_NO_ERROR)
+       return FALSE;
 
     /* sign & encrypt is valid only for single-part OpenPGP */
     if (sign_for != NULL
@@ -448,13 +446,13 @@ libbalsa_gpgme_encrypt(GPtrArray * recipients, const char *sign_for,
                        _
                        ("combined signing and encryption is defined only for RFC 2440"));
        gpgme_release(ctx);
-       return -1;
+       return FALSE;
     }
 
     /* if requested, find the secret key for "userid" */
     if (sign_for && !gpgme_add_signer(ctx, sign_for, parent, error)) {
        gpgme_release(ctx);
-       return -1;
+       return FALSE;
     }
 
     /* build the list of recipients */
@@ -463,7 +461,7 @@ libbalsa_gpgme_encrypt(GPtrArray * recipients, const char *sign_for,
         gpgme_build_recipients(ctx, recipients, trust_all_keys, parent,
                                error))) {
        gpgme_release(ctx);
-       return -1;
+       return FALSE;
     }
 
     /* create the data objects */
@@ -481,7 +479,7 @@ libbalsa_gpgme_encrypt(GPtrArray * recipients, const char *sign_for,
                               _("could not get data from stream"));
        release_keylist(rcpt_keys);
        gpgme_release(ctx);
-       return -1;
+       return FALSE;
     }
     if ((err =
         gpgme_data_new_from_cbs(&crypt, &cbs,
@@ -491,7 +489,7 @@ libbalsa_gpgme_encrypt(GPtrArray * recipients, const char *sign_for,
        release_keylist(rcpt_keys);
        gpgme_data_release(plain);
        gpgme_release(ctx);
-       return -1;
+       return FALSE;
     }
 
     /* do the encrypt or sign and encrypt operation
@@ -517,9 +515,9 @@ libbalsa_gpgme_encrypt(GPtrArray * recipients, const char *sign_for,
                                   _("signing and encryption failed"));
        else
            g_set_error_from_gpgme(error, err, _("encryption failed"));
-       return -1;
+       return FALSE;
     } else
-       return 0;
+       return TRUE;
 }
 
 
@@ -561,9 +559,8 @@ libbalsa_gpgme_decrypt(GMimeStream * crypted, GMimeStream * plain,
                         protocol == GPGME_PROTOCOL_CMS, NULL);
 
     /* create the GpgME context */
-    if ((err =
-        gpgme_new_with_protocol(&ctx, protocol, parent,
-                                error)) != GPG_ERR_NO_ERROR)
+    if (gpgme_new_with_protocol(&ctx, protocol, parent,
+                                error) != GPG_ERR_NO_ERROR)
        return NULL;
 
     /* create the data streams */
@@ -606,16 +603,23 @@ libbalsa_gpgme_decrypt(GMimeStream * crypted, GMimeStream * plain,
 
 /* ---- local stuff ---------------------------------------------------- */
 
-#define UTF8_VALID_STR(s)                                              \
-    do {                                                               \
-       if ((s) && !g_utf8_validate(s, -1, NULL)) {                     \
-           gsize bwr;                                                  \
-           gchar * newstr = g_locale_to_utf8(s, -1, NULL, &bwr, NULL); \
-                                                                       \
-           g_free(s);                                                  \
-           s = newstr;                                                 \
-       }                                                               \
-    } while (0)
+static gchar *
+utf8_valid_str(const char *gpgme_str)
+{
+       gchar *result;
+
+       if (gpgme_str != NULL) {
+               if (g_utf8_validate(gpgme_str, -1, NULL)) {
+                       result = g_strdup(gpgme_str);
+               } else {
+                       gsize bytes_written;
+                       result = g_locale_to_utf8(gpgme_str, -1, NULL, &bytes_written, NULL);
+               }
+       } else {
+               result = NULL;
+       }
+       return result;
+}
 
 
 /*
@@ -631,10 +635,8 @@ g_set_error_from_gpgme(GError ** error, gpgme_error_t gpgme_err,
     if (!error)
        return;
 
-    srcstr = g_strdup(gpgme_strsource(gpgme_err));
-    UTF8_VALID_STR(srcstr);
-    errstr = g_strdup(gpgme_strerror(gpgme_err));
-    UTF8_VALID_STR(errstr);
+    srcstr = utf8_valid_str(gpgme_strsource(gpgme_err));
+    errstr = utf8_valid_str(gpgme_strerror(gpgme_err));
     g_set_error(error, GPGME_ERROR_QUARK, gpgme_err, "%s: %s: %s", srcstr,
                message, errstr);
     g_free(srcstr);
@@ -709,6 +711,32 @@ gpgme_new_with_protocol(gpgme_ctx_t * ctx, gpgme_protocol_t protocol,
     return err;
 }
 
+/* return TRUE if the passed key is not expired, not revoked, not disabled
+ * and not invalid, and has at least one subkey which can be used for signing
+ * if secret is TRUE, or one subkey which can be used for encryption if secret
+ * is FALSE, and the particular subkey is not expired, not revoked, not
+ * disabled and not invalid */
+static gboolean
+check_key(const gpgme_key_t key, gboolean secret, time_t now)
+{
+       gboolean result = FALSE;
+
+       if (!key->expired && !key->revoked && !key->disabled && !key->invalid) {
+               gpgme_subkey_t subkey = key->subkeys;
+
+               while (!result && (subkey != NULL)) {
+                       if (((secret && subkey->can_sign) || (!secret && subkey->can_encrypt)) &&
+                               !subkey->expired && !subkey->revoked && !subkey->disabled && !subkey->invalid 
&&
+                               (subkey->expires == 0 || subkey->expires > now)) {
+                               result = TRUE;
+                       } else {
+                               subkey = subkey->next;
+                       }
+               }
+       }
+
+       return result;
+}
 
 /*
  * Get a key for name. If secret_only is set, choose only secret (private)
@@ -717,8 +745,6 @@ gpgme_new_with_protocol(gpgme_ctx_t * ctx, gpgme_protocol_t protocol,
  * no matching key could be found or if any error occurs, return NULL and
  * set error.
  */
-#define KEY_IS_OK(k)   (!((k)->expired || (k)->revoked || \
-                          (k)->disabled || (k)->invalid))
 static gpgme_key_t
 get_key_from_name(gpgme_ctx_t ctx, const gchar * name, gboolean secret,
                  gboolean accept_all, GtkWindow * parent, GError ** error)
@@ -743,18 +769,8 @@ get_key_from_name(gpgme_ctx_t ctx, const gchar * name, gboolean secret,
     found_bad = FALSE;
     while ((err = gpgme_op_keylist_next(ctx, &key)) == GPG_ERR_NO_ERROR) {
        /* check if this key and the relevant subkey are usable */
-       if (KEY_IS_OK(key)) {
-           gpgme_subkey_t subkey = key->subkeys;
-
-           while (subkey && ((secret && !subkey->can_sign) ||
-                             (!secret && !subkey->can_encrypt)))
-               subkey = subkey->next;
-
-           if (subkey && KEY_IS_OK(subkey) &&
-               (subkey->expires == 0 || subkey->expires > now))
+       if (check_key(key, secret, now)) {
                keys = g_list_append(keys, key);
-           else
-               found_bad = TRUE;
        } else
            found_bad = TRUE;
     }
@@ -877,7 +893,7 @@ static gboolean
 gpgme_add_signer(gpgme_ctx_t ctx, const gchar * signer, GtkWindow * parent,
                 GError ** error)
 {
-    gpgme_key_t key = NULL;
+    gpgme_key_t key;
 
     /* note: private (secret) key has never low trust... */
     if (!
diff --git a/libbalsa/libbalsa-gpgme.h b/libbalsa/libbalsa-gpgme.h
index 3a865f5..b58f0a2 100644
--- a/libbalsa/libbalsa-gpgme.h
+++ b/libbalsa/libbalsa-gpgme.h
@@ -36,9 +36,6 @@
 
 #ifdef __cplusplus
 extern "C" {
-#ifdef MAKE_EMACS_HAPPY
-}
-#endif
 #endif                         /* __cplusplus */
 
 
@@ -56,7 +53,8 @@ extern "C" {
  * - list of available keys (gpgme_key_t data elements)
  * - protocol
  * - parent window
- */ typedef gpgme_key_t(*lbgpgme_select_key_cb) (const gchar *,
+ */
+typedef gpgme_key_t(*lbgpgme_select_key_cb) (const gchar *,
                                                 gboolean,
                                                 GList *,
                                                 gpgme_protocol_t,
@@ -92,7 +90,7 @@ gpgme_hash_algo_t libbalsa_gpgme_sign(const gchar * userid,
                                      gboolean singlepart_mode,
                                      GtkWindow * parent, GError ** error);
 
-int libbalsa_gpgme_encrypt(GPtrArray * recipients,
+gboolean libbalsa_gpgme_encrypt(GPtrArray * recipients,
                           const char *sign_for,
                           GMimeStream * istream,
                           GMimeStream * ostream,
diff --git a/libbalsa/rfc3156.c b/libbalsa/rfc3156.c
index c9f664b..64da2dd 100644
--- a/libbalsa/rfc3156.c
+++ b/libbalsa/rfc3156.c
@@ -228,7 +228,7 @@ libbalsa_sign_mime_object(GMimeObject ** content, const gchar * rfc822_for,
        return FALSE;
     }
 
-    if (g_mime_gpgme_mps_sign(mps, *content, rfc822_for, protocol, parent, error) != 0) {
+    if (!g_mime_gpgme_mps_sign(mps, *content, rfc822_for, protocol, parent, error)) {
        g_object_unref(mps);
        return FALSE;
     }
@@ -251,7 +251,7 @@ libbalsa_encrypt_mime_object(GMimeObject ** content, GList * rfc822_for,
 {
     GMimeObject *encrypted_obj = NULL;
     GPtrArray *recipients;
-    int result = -1;
+    gboolean result = FALSE;
 
     /* paranoia checks */
     g_return_val_if_fail(rfc822_for != NULL, FALSE);
@@ -291,14 +291,13 @@ libbalsa_encrypt_mime_object(GMimeObject ** content, GList * rfc822_for,
     g_ptr_array_free(recipients, FALSE);
 
     /* error checking */
-    if (result != 0) {
+    if (!result) {
        g_object_unref(encrypted_obj);
-       return FALSE;
     } else {
     g_object_unref(G_OBJECT(*content));
     *content = GMIME_OBJECT(encrypted_obj);
-    return TRUE;
     }
+    return result;
 }
 
 
@@ -382,7 +381,7 @@ libbalsa_body_check_signature(LibBalsaMessageBody * body,
     /* check if the body is really a multipart/signed */
     if (!GMIME_IS_MULTIPART_SIGNED(body->mime_part)
         || (g_mime_multipart_get_count
-            (((GMimeMultipart *) body->mime_part))) < 2)
+            (GMIME_MULTIPART(body->mime_part)) < 2))
         return FALSE;
     if (body->parts->next->sig_info)
        g_object_unref(G_OBJECT(body->parts->next->sig_info));
@@ -390,7 +389,7 @@ libbalsa_body_check_signature(LibBalsaMessageBody * body,
     /* verify the signature */
     libbalsa_mailbox_lock_store(body->message->mailbox);
     result = g_mime_gpgme_mps_verify(GMIME_MULTIPART_SIGNED(body->mime_part), &error);
-    if (!result || result->status != GPG_ERR_NO_ERROR) {
+    if (!result) {
        if (error) {
            libbalsa_information(LIBBALSA_INFORMATION_ERROR, "%s: %s",
                                 _("signature verification failed"),
@@ -515,7 +514,7 @@ libbalsa_rfc2440_sign_encrypt(GMimePart *part, const gchar *sign_for,
                              GtkWindow *parent, GError **error)
 {
     GPtrArray *recipients;
-    gint result;
+    gboolean result;
 
     /* paranoia checks */
     g_return_val_if_fail(part != NULL, FALSE);
@@ -541,7 +540,7 @@ libbalsa_rfc2440_sign_encrypt(GMimePart *part, const gchar *sign_for,
     /* clean up */
     if (recipients)
        g_ptr_array_free(recipients, FALSE);
-    return (result == 0) ? TRUE : FALSE;
+    return result;
 }
 
 
@@ -571,7 +570,7 @@ libbalsa_rfc2440_verify(GMimePart * part, GMimeGpgmeSigstat ** sig_info)
 
     /* verify */
     result = g_mime_part_rfc2440_verify(part, &error);
-    if (!result || result->status != GPG_ERR_NO_ERROR) {
+    if (!result) {
        if (error) {
            libbalsa_information(LIBBALSA_INFORMATION_ERROR, "%s: %s",
                                 _("signature verification failed"),
diff --git a/libbalsa/send.c b/libbalsa/send.c
index 4c7ba42..ec54c8b 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -221,7 +221,6 @@ libbalsa_fill_msg_queue_item_from_queu(LibBalsaMessage * message,
                                        MessageQueueItem *mqi);
 
 #ifdef BALSA_USE_THREADS
-void balsa_send_thread(MessageQueueItem * first_message);
 
 GtkWidget *send_progress_message = NULL;
 GtkWidget *send_dialog = NULL;
diff --git a/libbalsa/smtp-server.c b/libbalsa/smtp-server.c
index f0dc3f4..36f2004 100644
--- a/libbalsa/smtp-server.c
+++ b/libbalsa/smtp-server.c
@@ -159,8 +159,6 @@ libbalsa_smtp_server_init(LibBalsaSmtpServer * smtp_server)
 #endif                          /* HAVE_SMTP_TLS_CLIENT_CERTIFICATE */
 }
 
-static void libbalsa_smtp_server_finalize(GObject * object);
-
 /* Class boilerplate */
 
 GType
diff --git a/src/filter-edit-callbacks.c b/src/filter-edit-callbacks.c
index 45bc0a5..e296c33 100644
--- a/src/filter-edit-callbacks.c
+++ b/src/filter-edit-callbacks.c
@@ -79,7 +79,6 @@ GtkWidget *fe_search_option_menu;
 extern GtkWidget *fe_op_codes_option_menu;
     
 /* Name field */
-extern GtkWidget *fe_name_label;
 extern GtkWidget *fe_name_entry;
     
 /* widgets for the matching fields */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]