[gnome-online-accounts] imap-auth-login: Use CAPABILITY to check if a server supports STARTTLS



commit d49ec85d28eabae087fc9d7dff5120fcdfe66908
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Apr 22 15:18:30 2013 +0200

    imap-auth-login: Use CAPABILITY to check if a server supports STARTTLS

 src/goabackend/goaimapauthlogin.c | 41 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
---
diff --git a/src/goabackend/goaimapauthlogin.c b/src/goabackend/goaimapauthlogin.c
index 5019480..e1fe2aa 100644
--- a/src/goabackend/goaimapauthlogin.c
+++ b/src/goabackend/goaimapauthlogin.c
@@ -164,6 +164,21 @@ imap_auth_login_check_not_OK (const gchar *response, gboolean tagged, GError **e
   return ret;
 }
 
+static gboolean
+imap_auth_login_check_not_STARTTLS (const gchar *response, GError **error)
+{
+  if (strstr (response, "STARTTLS") == NULL)
+    {
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_NOT_SUPPORTED,
+                   _("Server does not support STARTTLS"));
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gchar *
@@ -544,6 +559,32 @@ goa_imap_auth_login_starttls_sync (GoaMailAuth         *_auth,
     goto out;
   g_clear_pointer (&response, g_free);
 
+  /* Send CAPABILITY */
+
+  request = g_strdup_printf ("%s CAPABILITY\r\n", IMAP_TAG);
+  g_debug ("> %s", request);
+  if (!g_data_output_stream_put_string (output, request, cancellable, error))
+    goto out;
+  g_clear_pointer (&request, g_free);
+
+  /* Check if STARTTLS is supported or not */
+
+  response = g_data_input_stream_read_line (input, NULL, cancellable, error);
+  if (response == NULL)
+    goto out;
+  g_debug ("< %s", response);
+  if (imap_auth_login_check_not_STARTTLS (response, error))
+    goto out;
+  g_clear_pointer (&response, g_free);
+
+  response = g_data_input_stream_read_line (input, NULL, cancellable, error);
+  if (response == NULL)
+    goto out;
+  g_debug ("< %s", response);
+  if (imap_auth_login_check_not_OK (response, TRUE, error))
+    goto out;
+  g_clear_pointer (&response, g_free);
+
   /* Send STARTTLS */
 
   request = g_strdup_printf ("%s STARTTLS\r\n", IMAP_TAG);


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