[gnome-online-accounts] utils: Add goa_utils_parse_email_address



commit a05a4e89feb0178c2df55c967599c04689f8ae78
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Feb 12 22:12:31 2013 +0100

    utils: Add goa_utils_parse_email_address
    
    ... by renaming the function that was used to check the validity of
    email addresses in the Exchange provider.

 src/goabackend/goaexchangeprovider.c |   31 +------------------------------
 src/goabackend/goautils.c            |   29 +++++++++++++++++++++++++++++
 src/goabackend/goautils.h            |    2 ++
 3 files changed, 32 insertions(+), 30 deletions(-)
---
diff --git a/src/goabackend/goaexchangeprovider.c b/src/goabackend/goaexchangeprovider.c
index 931eafe..4a03fd0 100644
--- a/src/goabackend/goaexchangeprovider.c
+++ b/src/goabackend/goaexchangeprovider.c
@@ -416,35 +416,6 @@ typedef struct
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static gboolean
-is_valid_email_address (const gchar *email, gchar **out_username, gchar **out_domain)
-{
-  gchar *at;
-  gchar *dot;
-
-  if (email == NULL || email[0] == '\0')
-    return FALSE;
-
-  at = strchr (email, '@');
-  if (at == NULL || *(at + 1) == '\0')
-    return FALSE;
-
-  dot = strchr (at + 1, '.');
-  if (dot == NULL || *(dot + 1) == '\0')
-    return FALSE;
-
-  if (out_username != NULL)
-    {
-      *out_username = g_strdup (email);
-      (*out_username)[at - email] = '\0';
-    }
-
-  if (out_domain != NULL)
-    *out_domain = g_strdup (at + 1);
-
-  return TRUE;
-}
-
 static void
 on_email_address_or_password_changed (GtkEditable *editable, gpointer user_data)
 {
@@ -461,7 +432,7 @@ on_email_address_or_password_changed (GtkEditable *editable, gpointer user_data)
   username = NULL;
 
   email = gtk_entry_get_text (GTK_ENTRY (data->email_address));
-  if (!is_valid_email_address (email, &username, &domain))
+  if (!goa_utils_parse_email_address (email, &username, &domain))
     goto out;
 
   if (data->username != NULL)
diff --git a/src/goabackend/goautils.c b/src/goabackend/goautils.c
index 2a3260f..c6dffbb 100644
--- a/src/goabackend/goautils.c
+++ b/src/goabackend/goautils.c
@@ -466,6 +466,35 @@ goa_utils_keyfile_set_string (GoaAccount *account, const gchar *key, const gchar
   g_free (path);
 }
 
+gboolean
+goa_utils_parse_email_address (const gchar *email, gchar **out_username, gchar **out_domain)
+{
+  gchar *at;
+  gchar *dot;
+
+  if (email == NULL || email[0] == '\0')
+    return FALSE;
+
+  at = strchr (email, '@');
+  if (at == NULL || *(at + 1) == '\0')
+    return FALSE;
+
+  dot = strchr (at + 1, '.');
+  if (dot == NULL || *(dot + 1) == '\0')
+    return FALSE;
+
+  if (out_username != NULL)
+    {
+      *out_username = g_strdup (email);
+      (*out_username)[at - email] = '\0';
+    }
+
+  if (out_domain != NULL)
+    *out_domain = g_strdup (at + 1);
+
+  return TRUE;
+}
+
 void
 goa_utils_set_error_ssl (GError **err, GTlsCertificateFlags flags)
 {
diff --git a/src/goabackend/goautils.h b/src/goabackend/goautils.h
index fdce9cd..3c6b5af 100644
--- a/src/goabackend/goautils.h
+++ b/src/goabackend/goautils.h
@@ -72,6 +72,8 @@ void             goa_utils_keyfile_set_boolean (GoaAccount *account, const gchar
 
 void             goa_utils_keyfile_set_string (GoaAccount *account, const gchar *key, const gchar *value);
 
+gboolean         goa_utils_parse_email_address (const gchar *email, gchar **out_username, gchar **out_domain);
+
 void             goa_utils_set_error_ssl (GError **err, GTlsCertificateFlags flags);
 
 G_END_DECLS


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