* Added an email validation function
authorSergio Villar Senin <svillar@igalia.com>
Mon, 15 Jan 2007 19:44:02 +0000 (19:44 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Mon, 15 Jan 2007 19:44:02 +0000 (19:44 +0000)
* Added some documentation
* Initialized some variables that were causing crashes
* Added some error handling code at ModestAccountAssistant

pmo-trunk-r633

src/gtk/modest-account-assistant.c
src/modest-protocol-info.c
src/modest-text-utils.c
src/modest-text-utils.h
src/modest-tny-folder.c

index ce6a295..0fbd6d5 100644 (file)
@@ -31,6 +31,7 @@
 #include "modest-account-assistant.h"
 #include "modest-store-widget.h"
 #include "modest-transport-widget.h"
 #include "modest-account-assistant.h"
 #include "modest-store-widget.h"
 #include "modest-transport-widget.h"
+#include "modest-text-utils.h"
 #include <modest-protocol-info.h>
 
 #include <string.h>
 #include <modest-protocol-info.h>
 
 #include <string.h>
@@ -149,9 +150,11 @@ set_current_page_complete (ModestAccountAssistant *self, gboolean complete)
        gint pageno;
 
        pageno = gtk_assistant_get_current_page (GTK_ASSISTANT(self));
        gint pageno;
 
        pageno = gtk_assistant_get_current_page (GTK_ASSISTANT(self));
-       page   = gtk_assistant_get_nth_page (GTK_ASSISTANT(self), pageno);
 
 
-       gtk_assistant_set_page_complete (GTK_ASSISTANT(self), page, complete);
+       if (pageno != -1) {
+               page   = gtk_assistant_get_nth_page (GTK_ASSISTANT(self), pageno);
+               gtk_assistant_set_page_complete (GTK_ASSISTANT(self), page, complete);
+       }
 }
 
 
 }
 
 
@@ -172,11 +175,10 @@ identity_page_update_completeness (GtkEditable *editable,
 
        /* FIXME: regexp check for email address */
        txt = gtk_entry_get_text (GTK_ENTRY(priv->email));
 
        /* FIXME: regexp check for email address */
        txt = gtk_entry_get_text (GTK_ENTRY(priv->email));
-       if (!txt || strlen(txt) == 0) {
+       if (!modest_text_utils_validate_email_address (txt))
                set_current_page_complete (self, FALSE);
                set_current_page_complete (self, FALSE);
-               return;
-       }
-       set_current_page_complete (self, TRUE);
+       else
+               set_current_page_complete (self, TRUE);
 }
 
 
 }
 
 
index 0508daf..4856897 100644 (file)
@@ -60,7 +60,7 @@ const guint PROTOCOL_MAP_SIZE = sizeof(ProtocolMap)/sizeof(ProtocolInfo);
 GSList*
 modest_protocol_info_get_protocol_list (ModestProtocolType type)
 {
 GSList*
 modest_protocol_info_get_protocol_list (ModestProtocolType type)
 {
-       GSList *proto_list;
+       GSList *proto_list = NULL;
        int i;
        
        g_return_val_if_fail (type > MODEST_PROTOCOL_TYPE_UNKNOWN &&
        int i;
        
        g_return_val_if_fail (type > MODEST_PROTOCOL_TYPE_UNKNOWN &&
@@ -80,7 +80,7 @@ modest_protocol_info_get_protocol_list (ModestProtocolType type)
 ModestPairList*
 modest_protocol_info_get_protocol_pair_list (ModestProtocolType type)
 {
 ModestPairList*
 modest_protocol_info_get_protocol_pair_list (ModestProtocolType type)
 {
-       ModestPairList *proto_list;
+       ModestPairList *proto_list = NULL;
        int i;
        
        g_return_val_if_fail (type > MODEST_PROTOCOL_TYPE_UNKNOWN && type < MODEST_PROTOCOL_TYPE_NUM,
        int i;
        
        g_return_val_if_fail (type > MODEST_PROTOCOL_TYPE_UNKNOWN && type < MODEST_PROTOCOL_TYPE_NUM,
index b66137a..9d26aed 100644 (file)
@@ -784,3 +784,60 @@ modest_text_utils_get_display_date (time_t date)
                
        return date_buf;
 }
                
        return date_buf;
 }
+
+gboolean 
+modest_text_utils_validate_email_address (const gchar *email_address)
+{
+       int count = 0;
+       const gchar *c, *domain;
+       static gchar *rfc822_specials = "()<>@,;:\\\"[]";
+
+       /* first we validate the name portion (name@domain) */
+       for (c = email_address;  *c;  c++) {
+               if (*c == '\"' && 
+                   (c == email_address || 
+                    *(c - 1) == '.' || 
+                    *(c - 1) == '\"')) {
+                       while (*++c) {
+                               if (*c == '\"') 
+                                       break;
+                               if (*c == '\\' && (*++c == ' ')) 
+                                       continue;
+                               if (*c <= ' ' || *c >= 127) 
+                                       return FALSE;
+                       }
+                       if (!*c++) 
+                               return FALSE;
+                       if (*c == '@') 
+                               break;
+                       if (*c != '.') 
+                               return FALSE;
+                       continue;
+               }
+               if (*c == '@') 
+                       break;
+               if (*c <= ' ' || *c >= 127) 
+                       return FALSE;
+               if (strchr(rfc822_specials, *c)) 
+                       return FALSE;
+       }
+       if (c == email_address || *(c - 1) == '.') 
+               return FALSE;
+
+       /* next we validate the domain portion (name@domain) */
+       if (!*(domain = ++c)) 
+               return FALSE;
+       do {
+               if (*c == '.') {
+                       if (c == domain || *(c - 1) == '.') 
+                               return FALSE;
+                       count++;
+               }
+               if (*c <= ' ' || *c >= 127) 
+                       return FALSE;
+               if (strchr(rfc822_specials, *c)) 
+                       return FALSE;
+       } while (*++c);
+
+       return (count >= 1) ? TRUE : FALSE;
+}
index 56c83a5..e294442 100644 (file)
@@ -200,4 +200,15 @@ gint modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean i
  */
 const gchar* modest_text_utils_get_display_date (time_t date);
 
  */
 const gchar* modest_text_utils_get_display_date (time_t date);
 
+
+/**
+ * modest_text_utils_validate_email_address:
+ * @email_address: a string
+ * 
+ * validates the email address passed as argument
+ * 
+ * Returns: TRUE if the address is valid, FALSE otherwise
+ **/
+gboolean     modest_text_utils_validate_email_address (const gchar *email_address);
+
 #endif /* __MODEST_TEXT_UTILS_H__ */
 #endif /* __MODEST_TEXT_UTILS_H__ */
index 6dc7799..8ef6a4c 100644 (file)
@@ -84,7 +84,7 @@ modest_tny_folder_guess_folder_type (const TnyFolder *folder)
 
        g_return_val_if_fail (folder, TNY_FOLDER_TYPE_UNKNOWN);
 
 
        g_return_val_if_fail (folder, TNY_FOLDER_TYPE_UNKNOWN);
 
-       type = tny_folder_get_folder_type ((TnyFolder*)folder); /* FIXME: cast tinymail */
+       type = tny_folder_get_folder_type (TNY_FOLDER (folder));
        
        if (type == TNY_FOLDER_TYPE_UNKNOWN) {
                const gchar *folder_name;
        
        if (type == TNY_FOLDER_TYPE_UNKNOWN) {
                const gchar *folder_name;