]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Aggiunta la funzione SolipaMail::check_email_address (e il test).
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 29 Dec 2011 11:47:13 +0000 (12:47 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 29 Dec 2011 11:47:13 +0000 (12:47 +0100)
.cproject
.project
src/mail.c
src/mail.h
src/utils.c
tests/Makefile.am
tests/mail_check_address.c [new file with mode: 0644]
tests/mail_get_addresses_from_string.c

index 6f6b7fc15beb2dae9b835215cc2398dcf003b7ba..d6f39d16f6df3fdabdc4feac42744c6200af702e 100644 (file)
--- a/.cproject
+++ b/.cproject
@@ -26,6 +26,7 @@
                                                        <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.1060880142" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base"/>
                                                        <tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.2108842943" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base">
                                                                <option id="gnu.c.compiler.option.include.paths.783512568" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;C:\mingw\include&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\glib-2.0&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\gtk-2.0&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\evolution-data-server-2.32&quot;"/>
index 16520551d727251901084930f718b59c56573f5c..20175df2c2017c392d8846065f5fbe9d49fb98cc 100644 (file)
--- a/.project
+++ b/.project
@@ -69,7 +69,7 @@
        </natures>
        <filteredResources>
                <filter>
-                       <id>1321292489312</id>
+                       <id>1325156677028</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -78,7 +78,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489312</id>
+                       <id>1325156677034</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -87,7 +87,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489312</id>
+                       <id>1325156677038</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -96,7 +96,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489328</id>
+                       <id>1325156677042</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489328</id>
+                       <id>1325156677046</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489328</id>
+                       <id>1325156677050</id>
                        <name></name>
                        <type>30</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489328</id>
+                       <id>1325156677053</id>
                        <name></name>
                        <type>30</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489328</id>
+                       <id>1325156677056</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489328</id>
+                       <id>1325156677059</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489328</id>
+                       <id>1325156677062</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489343</id>
+                       <id>1325156677066</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489343</id>
+                       <id>1325156677069</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489343</id>
+                       <id>1325156677073</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489343</id>
+                       <id>1325156677076</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489343</id>
+                       <id>1325156677079</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489343</id>
+                       <id>1325156677083</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489343</id>
+                       <id>1325156677086</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489359</id>
+                       <id>1325156677094</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489359</id>
+                       <id>1325156677099</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489359</id>
+                       <id>1325156677103</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489359</id>
+                       <id>1325156677107</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489359</id>
+                       <id>1325156677111</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489359</id>
+                       <id>1325156677114</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1321292489375</id>
+                       <id>1325156677119</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
index f208844813927506be2e155c6d21ca9b717d0a4d..6680f2369177e2df05ca765f1300d43d4e8b8c44 100644 (file)
@@ -644,6 +644,39 @@ noconnect:
 #endif
 }
 
+/**
+ * solipa_mail_check_email_address:
+ * @address:
+ *
+ * Returns: #TRUE if the email address is valid.
+ */
+gboolean
+solipa_mail_check_email_address (const gchar *address)
+{
+       gboolean ret;
+
+       GError *error;
+       GRegex *regex;
+
+       ret = FALSE;
+
+       error = NULL;
+       regex = g_regex_new ("^[[:alnum:]._%+-]+@(?:[[:alnum:]-]+\\.)+[[:alpha:]]{2,4}$", 0, 0, &error);
+
+       if (regex == NULL || error != NULL)
+               {
+                       g_warning ("Error on creating regex: %s.",
+                                  error->message != NULL ? error->message : "no details");
+                       return ret;
+               }
+
+       ret = g_regex_match ((const GRegex *)regex, address, 0, NULL);
+
+       g_regex_unref (regex);
+
+       return ret;
+}
+
 GSList
 *solipa_mail_get_addresses_from_string (const gchar *addresses)
 {
index f3c40aa2a6751a656de293193e052c248793316c..7942ca370dc1914a76417774f5afa58cb7869277 100644 (file)
@@ -76,6 +76,8 @@ gchar *solipa_mail_get_as_string (SolipaMail *mail);
 
 void solipa_mail_send (SolipaMail *mail, const gchar *url);
 
+gboolean solipa_mail_check_email_address (const gchar *address);
+
 GSList *solipa_mail_get_addresses_from_string (const gchar *addresses);
 
 
index 95fecd38a51a0161e181542eed84af0773216d2a..7d6d09002a544294eadba0d23912e5011eddadb7 100644 (file)
@@ -750,7 +750,7 @@ gchar
 
        error = NULL;
        regex = g_regex_new ("(^[-\\d]?\\d+)(\\d\\d\\d)", 0, 0, &error);
-       if (error != NULL)
+       if (regex == NULL || error != NULL)
                {
                        g_warning ("Error on creating regex: %s.",
                                   error->message != NULL ? error->message : "no details");
index 864b442325ea6bf761c22f631f812e7bb03b5064..f6f009d206f813123d43355b681bd213e71663f2 100644 (file)
@@ -15,6 +15,7 @@ ooo_LDADD = $(top_builddir)/src/libsolipaooo.la
 
 noinst_PROGRAMS = allegato \
                   mail \
+                  mail_check_address \
                   mail_get_addresses_from_string \
                   mailui \
                   ooo \
diff --git a/tests/mail_check_address.c b/tests/mail_check_address.c
new file mode 100644 (file)
index 0000000..0f9de80
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <libsolipa/mail.h>
+
+int
+main (int argc, char **argv)
+{
+       g_type_init ();
+
+       if (argc != 2) return 0;
+
+       if (!solipa_mail_check_email_address (argv[1]))
+               {
+                       g_warning ("The email address isn't valid (%s).", argv[1]);
+               }
+
+       return 0;
+}
index d94f19dd44dcd17d2fd44e5f57447c49cf854994..509d96193b3cc79a3f336b2c8f698b21fd4c0332 100644 (file)
@@ -16,7 +16,7 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#include <mail.h>
+#include <libsolipa/mail.h>
 
 int
 main (int argc, char **argv)