diff --git a/gtk/regex.h b/gtk/regex.h index 308320278..f291eceda 100644 --- a/gtk/regex.h +++ b/gtk/regex.h @@ -39,9 +39,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define BC_REGEX_URI_FRAGMENT "(" "(" BC_REGEX_URI_PCHAR "|" "[/?]" ")*" ")" #define BC_REGEX_URI "(" BC_REGEX_URI_SCHEME ":" BC_REGEX_URI_HIER_PART "(" "\\?" BC_REGEX_URI_QUERY ")?" "(" "#" BC_REGEX_URI_FRAGMENT ")?" ")" +/* + * Regex matching with any domain name (RFC 1034) + */ +#define BC_REGEX_DOMAIN_LDH "[[:alnum:]-]" +#define BC_REGEX_DOMAIN_LABEL "(" "[[:alpha:]]" "(" BC_REGEX_DOMAIN_LDH "*" "[[:alnum:]]" ")?" ")" +#define BC_REGEX_DOMAIN "(" BC_REGEX_DOMAIN_LABEL "(" "\\." BC_REGEX_DOMAIN_LABEL ")*" ")" /* - * Regex matching with email addresses. + * Regex matching with email addresses (RFC 5322) */ #define BC_REGEX_EMAIL_ATEXT "[[:alnum:]!#$%&'*+\\-/=?\\^_`{}|~]" #define BC_REGEX_EMAIL_DOT_ATOM_TEXT "(" BC_REGEX_EMAIL_ATEXT "+" "(" "." BC_REGEX_EMAIL_ATEXT "+" ")*" ")" @@ -49,3 +55,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define BC_REGEX_EMAIL_DTEXT_NO_OBS "[!-Z\\^-~]" #define BC_REGEX_EMAIL_DOMAIN "(" BC_REGEX_EMAIL_DOT_ATOM_TEXT "|" "\\[" BC_REGEX_EMAIL_DTEXT_NO_OBS "*" "\\]" ")" #define BC_REGEX_EMAIL_ADDR_SPEC "(" BC_REGEX_EMAIL_LOCAL_PART "@" BC_REGEX_EMAIL_DOMAIN ")" + +/* + * Regex matching with email addresses but with more constraints than RFC 5322. + * The additionnal constraints are the folowings: + * + the domain part is a domain name as describe in RFC 1034 + * + the domain part must have two label at least + * + the last label of the domain part must have two letter (without digit and hyphen) at least. + */ +#define BC_REGEX_RESTRICTIVE_EMAIL_TLD "(" "[[:alpha:]]" BC_REGEX_DOMAIN_LDH "*" "[[:alnum:]]" ")" +#define BC_REGEX_RESTRICTIVE_EMAIL_ADDR "(" BC_REGEX_EMAIL_LOCAL_PART "@" "(" BC_REGEX_DOMAIN_LABEL "\\." ")+" BC_REGEX_RESTRICTIVE_EMAIL_TLD ")" \ No newline at end of file diff --git a/gtk/setupwizard.c b/gtk/setupwizard.c index cb14d8eed..08dc06bee 100644 --- a/gtk/setupwizard.c +++ b/gtk/setupwizard.c @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "linphone.h" +#include "regex.h" #include #include @@ -372,7 +373,7 @@ static void linphone_account_creation_email_changed(GtkEntry *entry, GtkWidget * GtkImage* isEmailOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w), "emailOk")); GtkWidget *assistant = gtk_widget_get_toplevel(w); - if (g_regex_match_simple("^[a-z0-9]([a-z0-9_\\+\\.-]+)@[a-z0-9]([a-z0-9\\.-]+)\\.[a-z]{2,}$", gtk_entry_get_text(email), 0, 0)) { + if (g_regex_match_simple("^" BC_REGEX_RESTRICTIVE_EMAIL_ADDR "$", gtk_entry_get_text(email), 0, 0)) { g_object_set_data(G_OBJECT(w), "is_email_correct", GINT_TO_POINTER(1)); gtk_image_set_from_stock(isEmailOk, GTK_STOCK_OK, GTK_ICON_SIZE_LARGE_TOOLBAR); } else {