[balsa/autocrypt] make IMAP messages translatable



commit 01c508601a01971e1ab6ab4e634a42bf7f4fd457
Author: Albrecht Dreß <albrecht dress arcor de>
Date:   Sat Jan 5 14:42:34 2019 -0500

    make IMAP messages translatable
    
    * libbalsa/imap/auth-cram.c, libbalsa/imap/auth-gssapi.c,
    libbalsa/imap/imap-commands.c, libbalsa/imap/imap-handle.c:
      make message strings translatable
    * libbalsa/imap/imap-handle.c, libbalsa/imap/imap_private.h:
      implement imap_mbox_handle_set_msg() as function
    * libbalsa/imap/imap-commands.h, libbalsa/imap/imap-tls.c:
      add GError to imap_handle_starttls() api
    
    Signed-off-by: Peter Bloomfield <PeterBloomfield bellsouth net>

 ChangeLog                     | 12 ++++++++++++
 libbalsa/imap/auth-cram.c     |  3 ++-
 libbalsa/imap/auth-gssapi.c   |  9 +++------
 libbalsa/imap/imap-auth.c     |  9 +++++----
 libbalsa/imap/imap-commands.c |  7 ++++---
 libbalsa/imap/imap-commands.h |  2 +-
 libbalsa/imap/imap-handle.c   | 32 +++++++++++++++++++++++---------
 libbalsa/imap/imap-tls.c      |  4 ++--
 libbalsa/imap/imap_private.h  |  4 ++--
 po/ChangeLog                  |  6 ++++++
 po/POTFILES.in                |  6 ++++++
 11 files changed, 66 insertions(+), 28 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 52d87a214..f852ce015 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2018-01-05  Albrecht Dreß  <albrecht dress arcor de>
+
+       make IMAP messages translatable
+
+       * libbalsa/imap/auth-cram.c, libbalsa/imap/auth-gssapi.c,
+       libbalsa/imap/imap-commands.c, libbalsa/imap/imap-handle.c:
+         make message strings translatable
+       * libbalsa/imap/imap-handle.c, libbalsa/imap/imap_private.h:
+         implement imap_mbox_handle_set_msg() as function
+       * libbalsa/imap/imap-commands.h, libbalsa/imap/imap-tls.c:
+         add GError to imap_handle_starttls() api
+
 2019-01-05  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Fix the meson build
diff --git a/libbalsa/imap/auth-cram.c b/libbalsa/imap/auth-cram.c
index 980662a6f..5fe1599d5 100644
--- a/libbalsa/imap/auth-cram.c
+++ b/libbalsa/imap/auth-cram.c
@@ -22,6 +22,7 @@
 /* IMAP login/authentication code */
 
 #include <string.h>
+#include <glib/gi18n.h>
 
 #include "imap-auth.h"
 #include "net-client-utils.h"
@@ -43,7 +44,7 @@ imap_auth_cram(ImapMboxHandle* handle)
 
   g_signal_emit_by_name(handle->sio, "auth", TRUE, &auth_data);
   if((auth_data == NULL) || (auth_data[0] == NULL) || (auth_data[1] == NULL)) {
-    imap_mbox_handle_set_msg(handle, "Authentication cancelled");
+    imap_mbox_handle_set_msg(handle, _("Authentication cancelled"));
        g_strfreev(auth_data);
     return IMAP_AUTH_CANCELLED;
   }
diff --git a/libbalsa/imap/auth-gssapi.c b/libbalsa/imap/auth-gssapi.c
index e70d560a2..93206961e 100644
--- a/libbalsa/imap/auth-gssapi.c
+++ b/libbalsa/imap/auth-gssapi.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 #include "imap-auth.h"
+#include <glib/gi18n.h>
 
 #if defined(HAVE_GSSAPI)
 #if defined(HAVE_HEIMDAL)
@@ -126,7 +127,7 @@ imap_auth_gssapi(ImapMboxHandle* handle)
 
     g_signal_emit_by_name(handle->sio, "auth", FALSE, &auth_data);
     if((auth_data == NULL) || (auth_data[0] == NULL)) {
-       imap_mbox_handle_set_msg(handle, "User name required, authentication cancelled");
+       imap_mbox_handle_set_msg(handle, _("User name required, authentication cancelled"));
        g_strfreev(auth_data);
        return IMAP_AUTH_CANCELLED;
     }
@@ -158,12 +159,8 @@ imap_auth_gssapi(ImapMboxHandle* handle)
        g_strfreev(auth_data);
 
     if (error != NULL) {
-        gchar *err_msg;
-
        g_message("%s: %s", __func__, error->message);
-       err_msg = g_strdup_printf("GSSAPI auth failed: %s", error->message);
-       imap_mbox_handle_set_msg(handle, err_msg);
-       g_free(err_msg);
+       imap_mbox_handle_set_msg(handle, _("GSSAPI authentication failed: %s"), error->message);
        g_error_free(error);
     }
 
diff --git a/libbalsa/imap/imap-auth.c b/libbalsa/imap/imap-auth.c
index 91335bd50..42b8f6238 100644
--- a/libbalsa/imap/imap-auth.c
+++ b/libbalsa/imap/imap-auth.c
@@ -22,6 +22,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <glib/gi18n.h>
 
 #include "imap-handle.h"
 #include "imap-auth.h"
@@ -67,7 +68,7 @@ imap_authenticate(ImapMboxHandle* handle)
       return r;
     }
   }
-  imap_mbox_handle_set_msg(handle, "No way to authenticate is known");
+  imap_mbox_handle_set_msg(handle, _("No way to authenticate is known"));
   return r;
 }
 
@@ -86,14 +87,14 @@ imap_auth_login(ImapMboxHandle* handle)
   
   g_signal_emit_by_name(handle->sio, "auth", TRUE, &auth_data);
   if((auth_data == NULL) || (auth_data[0] == NULL) || (auth_data[1] == NULL)) {
-    imap_mbox_handle_set_msg(handle, "Authentication cancelled");
+    imap_mbox_handle_set_msg(handle, _("Authentication cancelled"));
        g_strfreev(auth_data);
     return IMAP_AUTH_CANCELLED;
   }
 
   /* RFC 6855, Sect. 5, explicitly forbids UTF-8 usernames or passwords */
   if (!g_str_is_ascii(auth_data[0]) || !g_str_is_ascii(auth_data[1])) {
-         imap_mbox_handle_set_msg(handle, "Cannot LOGIN with UTF-8 username or password");
+         imap_mbox_handle_set_msg(handle, _("Cannot LOGIN with UTF-8 username or password"));
          result = IMAP_AUTH_CANCELLED;
   } else {
          gchar *q_user;
@@ -137,7 +138,7 @@ imap_auth_sasl(ImapMboxHandle* handle, ImapCapability cap,
   sasl_ir = imap_mbox_handle_can_do(handle, IMCAP_SASLIR);
   
   if(!getmsg(handle, &msg64, &msglen)) {
-    imap_mbox_handle_set_msg(handle, "Authentication cancelled");
+    imap_mbox_handle_set_msg(handle, _("Authentication cancelled"));
     return IMAP_AUTH_CANCELLED;
   }
   
diff --git a/libbalsa/imap/imap-commands.c b/libbalsa/imap/imap-commands.c
index d4080aad7..5d96d817d 100644
--- a/libbalsa/imap/imap-commands.c
+++ b/libbalsa/imap/imap-commands.c
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <glib/gi18n.h>
 
 #include "imap-handle.h"
 #include "imap-commands.h"
@@ -1213,7 +1214,7 @@ imap_mbox_handle_fetch_rfc822(ImapMboxHandle* handle,
     g_free(seq);
     if(passthrough_data.pipeline_error){
       rc = IMR_NO;
-      imap_mbox_handle_set_msg(handle, "Unordered data received from server");
+      imap_mbox_handle_set_msg(handle, _("Unordered data received from server"));
     }
   }
   g_mutex_unlock(&handle->mutex);
@@ -1746,8 +1747,8 @@ imap_mbox_sort_msgno_srv(ImapMboxHandle *handle, ImapSortKey key,
       for(i=0; i<cnt; i++)
         msgno[i] = i + 1;
       imap_mbox_handle_set_msg(handle,
-                               "bug in implementation of SORT command on "
-                               "IMAP server exposed.");
+                               _("Bug in implementation of SORT command on "
+                               "IMAP server exposed."));
       rc = IMR_NO;
     }
   }
diff --git a/libbalsa/imap/imap-commands.h b/libbalsa/imap/imap-commands.h
index 9b8a85c7a..1cb0066c1 100644
--- a/libbalsa/imap/imap-commands.h
+++ b/libbalsa/imap/imap-commands.h
@@ -134,7 +134,7 @@ ImapResponse imap_mbox_handle_fetch_body(ImapMboxHandle* handle,
                                          void *arg);
 
 /* Experimental/Expansion */
-ImapResponse imap_handle_starttls(ImapMboxHandle *handle);
+ImapResponse imap_handle_starttls(ImapMboxHandle *handle, GError **error);
 ImapResponse imap_mbox_scan(ImapMboxHandle *r, const char*what,
                             const char*str);
 ImapResponse imap_mbox_unselect(ImapMboxHandle *h);
diff --git a/libbalsa/imap/imap-handle.c b/libbalsa/imap/imap-handle.c
index 6fcc83886..e8b950f30 100644
--- a/libbalsa/imap/imap-handle.c
+++ b/libbalsa/imap/imap-handle.c
@@ -22,6 +22,7 @@
 
 #include <glib.h>
 #include <glib-object.h>
+#include <glib/gi18n.h>
 #include <ctype.h>
 
 #include <stdio.h>
@@ -54,6 +55,7 @@
 #define LIT_IS_HANDLE_CLASS(klass) \
     (G_TYPE_CHECK_CLASS_TYPE(klass, LIT_TYPE_HANDLE))
 
+#define error_safe(e)  (((e != NULL) && ((e)->message != NULL)) ? (e)->message : _("unknown"))
 
 struct _ImapMboxHandleClass {
   GObjectClass parent_class;
@@ -718,8 +720,9 @@ imap_mbox_connect(ImapMboxHandle* handle)
          handle->tls_mode == NET_CLIENT_CRYPT_ENCRYPTED ? 993 : 143);
   g_signal_connect(G_OBJECT(handle->sio), "auth", handle->auth_cb, handle->auth_arg);
   g_signal_connect(G_OBJECT(handle->sio), "cert-check", handle->cert_cb, handle->sio);
+  /* FIXME - client certificate? */
   if (!net_client_connect(NET_CLIENT(handle->sio), &error)) {
-       imap_mbox_handle_set_msg(handle, error->message);
+       imap_mbox_handle_set_msg(handle, _("Connecting %s failed: %s"), handle->host, error_safe(error));
        g_clear_error(&error);
        return IMAP_CONNECT_FAILED;
   }
@@ -732,7 +735,7 @@ imap_mbox_connect(ImapMboxHandle* handle)
 #endif
   if (handle->tls_mode == NET_CLIENT_CRYPT_ENCRYPTED) {
     if (!net_client_start_tls(NET_CLIENT(handle->sio), &error)) {
-      imap_mbox_handle_set_msg(handle, error->message);
+      imap_mbox_handle_set_msg(handle, _("TLS negotiation failed: %s"), error_safe(error));
          g_clear_error(&error);
       return IMAP_UNSECURE;
     }
@@ -751,14 +754,14 @@ imap_mbox_connect(ImapMboxHandle* handle)
         (handle->tls_mode == NET_CLIENT_CRYPT_NONE)) {
     resp = IMAP_SUCCESS; /* secured already with SSL, or no encryption requested */
   } else if(imap_mbox_handle_can_do(handle, IMCAP_STARTTLS)) {
-    if( imap_handle_starttls(handle) != IMR_OK) {
-      imap_mbox_handle_set_msg(handle,"TLS negotiation failed");
+    if( imap_handle_starttls(handle, &error) != IMR_OK) {
+      imap_mbox_handle_set_msg(handle, _("TLS negotiation failed: %s"), error_safe(error));
       resp = IMAP_UNSECURE; /* TLS negotiation error */
     } else {
       resp = IMAP_SUCCESS; /* secured with TLS */
     }
   } else {
-       imap_mbox_handle_set_msg(handle,"TLS required but not available");
+       imap_mbox_handle_set_msg(handle, _("TLS required but not available"));
     resp = IMR_NO; /* TLS unavailable */
   }
 
@@ -887,6 +890,17 @@ imap_mbox_handle_get_delim(ImapMboxHandle* handle,
 
 }
 
+void
+imap_mbox_handle_set_msg(ImapMboxHandle *handle, const gchar *fmt, ...)
+{
+       va_list va_args;
+
+       g_free(handle->last_msg);
+    va_start(va_args, fmt);
+    handle->last_msg = g_strdup_vprintf(fmt, va_args);
+    va_end(va_args);
+}
+
 char*
 imap_mbox_handle_get_last_msg(ImapMboxHandle *handle)
 {
@@ -2340,7 +2354,7 @@ ir_ok(ImapMboxHandle *h)
     rc = IMR_OK;
   else if (rc != IMR_SEVERED && (l=strlen(line))>0 ) {
     line[l-2] = '\0'; 
-    imap_mbox_handle_set_msg(h, line);
+    imap_mbox_handle_set_msg(h, _("IMAP response: %s"), line);
     if(h->info_cb)
       h->info_cb(h, rc, line, h->info_arg);
     else
@@ -2358,7 +2372,7 @@ ir_no(ImapMboxHandle *h)
   sio_gets(h->sio, line, sizeof(line));
   /* look for information response codes here: section 7.1 of the draft */
   if( strlen(line)>2) {
-    imap_mbox_handle_set_msg(h, line);
+    imap_mbox_handle_set_msg(h, _("IMAP response: %s"), line);
     if(h->info_cb)
       h->info_cb(h, IMR_NO, line, h->info_arg);
     else
@@ -2374,7 +2388,7 @@ ir_bad(ImapMboxHandle *h)
   sio_gets(h->sio, line, sizeof(line));
   /* look for information response codes here: section 7.1 of the draft */
   if( strlen(line)>2) {
-    imap_mbox_handle_set_msg(h, line);
+    imap_mbox_handle_set_msg(h, _("IMAP response: %s"), line);
     if(h->info_cb)
       h->info_cb(h, IMR_BAD, line, h->info_arg);
     else
@@ -2401,7 +2415,7 @@ ir_bye(ImapMboxHandle *h)
   char line[LONG_STRING];
   sio_gets(h->sio, line, sizeof(line));
   if(!h->doing_logout) {/* it is not we, so it must be the server */
-    imap_mbox_handle_set_msg(h, line);
+    imap_mbox_handle_set_msg(h, _("IMAP response: %s"), line);
     imap_mbox_handle_set_state(h, IMHS_DISCONNECTED);
     /* we close the connection here unless we are doing logout. */
     if(h->sio) {
diff --git a/libbalsa/imap/imap-tls.c b/libbalsa/imap/imap-tls.c
index d07275b79..2fa197710 100644
--- a/libbalsa/imap/imap-tls.c
+++ b/libbalsa/imap/imap-tls.c
@@ -45,7 +45,7 @@
 #include "imap_private.h"
 
 ImapResponse
-imap_handle_starttls(ImapMboxHandle *handle)
+imap_handle_starttls(ImapMboxHandle *handle, GError **error)
 {
        ImapResponse rc;
 
@@ -57,7 +57,7 @@ imap_handle_starttls(ImapMboxHandle *handle)
        if (rc != IMR_OK) {
                return rc;
        }
-       if (net_client_start_tls(NET_CLIENT(handle->sio), NULL)) {
+       if (net_client_start_tls(NET_CLIENT(handle->sio), error)) {
                handle->has_capabilities = 0;
                return IMR_OK;
        } else {
diff --git a/libbalsa/imap/imap_private.h b/libbalsa/imap/imap_private.h
index e9821ead9..e3c088427 100644
--- a/libbalsa/imap/imap_private.h
+++ b/libbalsa/imap/imap_private.h
@@ -195,8 +195,8 @@ void imap_handle_disconnect(ImapMboxHandle *h);
 ImapConnectionState imap_mbox_handle_get_state(ImapMboxHandle *h);
 void imap_mbox_handle_set_state(ImapMboxHandle *h,
                                 ImapConnectionState newstate);
-#define imap_mbox_handle_set_msg(h,s) \
-  do{g_free((h)->last_msg); (h)->last_msg = g_strdup(s); }while(0)
+void imap_mbox_handle_set_msg(ImapMboxHandle *handle, const gchar *fmt, ...)
+       G_GNUC_PRINTF(2, 3);
 
 typedef unsigned (*ImapCoalesceFunc)(int, void*);
 gchar* imap_coalesce_seq_range(int lo, int hi,
diff --git a/po/ChangeLog b/po/ChangeLog
index f5f7e1ed9..d91aa787e 100644
--- a/po/ChangeLog
+++ b/po/ChangeLog
@@ -4,6 +4,12 @@
 
        * POTFILES.in:
 
+2019-01-05  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       reviewed by: <delete if not using a buddy>
+
+       * POTFILES.in:
+
 2017-09-13  Peter Bloomfield  <pbloomfield bellsouth net>
 
        reviewed by: <delete if not using a buddy>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 633e20790..f086ef1f7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -23,6 +23,12 @@ libbalsa/gmime-gpgme-signature.c
 libbalsa/gmime-multipart-crypt.c
 libbalsa/html.c
 libbalsa/identity.c
+libbalsa/imap/auth-cram.c
+libbalsa/imap/auth-gssapi.c
+libbalsa/imap/imap-auth.c
+libbalsa/imap/imap-commands.c
+libbalsa/imap/imap-handle.c
+libbalsa/imap/imap-tls.c
 libbalsa/imap-server.c
 libbalsa/libbalsa.c
 libbalsa/libbalsa-conf.c


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