]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Controllo degli indirizzi mail in SolipaMail e SolipaMailUI (closes #208, #209).
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 29 Dec 2011 12:31:34 +0000 (13:31 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 29 Dec 2011 12:31:34 +0000 (13:31 +0100)
src/mail.c
src/mailui.c

index 6680f2369177e2df05ca765f1300d43d4e8b8c44..0517758fa278913fd147eba335b5ee324fb36c0f 100644 (file)
@@ -207,7 +207,10 @@ solipa_mail_add_recipient (SolipaMail *mail, CamelInternetAddress *recipient, So
                        addressp = g_strdup ("");
                        camel_internet_address_get (recipient, i,
                                                    &namep, &addressp);
-                       camel_internet_address_add (rcpt, namep, addressp);
+                       if (solipa_mail_check_email_address (addressp))
+                               {
+                                       camel_internet_address_add (rcpt, namep, addressp);
+                               }
                }
 }
 
index 94e14174a6724922a62a115df9921d2c6728ae79..401cacdb25be68122f1d482fe8b5f1344c8ec8bb 100644 (file)
@@ -407,6 +407,8 @@ solipa_mail_ui_send (SolipaMailUI *mailui)
        gchar *subject;
        gchar *body;
 
+       gchar *email;
+
        GSList *lst_addrs;
 
        CamelInternetAddress *addr;
@@ -414,6 +416,8 @@ solipa_mail_ui_send (SolipaMailUI *mailui)
        GtkTreeIter iter;
        gchar *filename;
 
+       GtkWidget *transient;
+
        g_return_val_if_fail (IS_SOLIPA_MAIL_UI (mailui), FALSE);
 
        SolipaMailUIPrivate *priv = SOLIPA_MAIL_UI_GET_PRIVATE (mailui);
@@ -421,10 +425,22 @@ solipa_mail_ui_send (SolipaMailUI *mailui)
        SolipaMail *smail = solipa_mail_new (priv->solipa);
        if (smail == NULL)
                {
-                       g_warning ("Impossibile creare l'oggetto SolipaMail.");
+                       solipa_message_dialog (transient,
+                                              GTK_MESSAGE_WARNING,
+                                              GTK_BUTTONS_OK,
+                                              "Impossibile creare l'oggetto SolipaMail.");
                        return FALSE;
                }
 
+       if (gtk_widget_get_parent (priv->widget) == NULL)
+               {
+                       transient = priv->dialog;
+               }
+       else
+               {
+                       transient = gtk_widget_get_toplevel (priv->widget);
+               }
+
        g_object_get (G_OBJECT (mailui),
                      "smtp-uri", &smtpuri,
                      "from", &from,
@@ -442,16 +458,29 @@ solipa_mail_ui_send (SolipaMailUI *mailui)
                        lst_addrs = solipa_mail_get_addresses_from_string (from);
                        if (lst_addrs != NULL)
                                {
+                                       email = g_hash_table_lookup ((GHashTable *)lst_addrs->data, "address");
+                                       if (!solipa_mail_check_email_address (email))
+                                               {
+                                                       solipa_message_dialog (transient,
+                                                                              GTK_MESSAGE_WARNING,
+                                                                              GTK_BUTTONS_OK,
+                                                                              "Indirizzo nel campo Da: non valido.");
+                                                       return FALSE;
+                                               }
+
                                        addr = camel_internet_address_new ();
                                        camel_internet_address_add (addr,
                                                                    g_hash_table_lookup ((GHashTable *)lst_addrs->data, "name"),
-                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "address"));
+                                                                   email);
                                        solipa_mail_set_from (smail, addr);
                                        camel_address_remove (CAMEL_ADDRESS (addr), -1);
                                }
                        else
                                {
-                                       g_warning ("Campo Da: mancante.");
+                                       solipa_message_dialog (transient,
+                                                              GTK_MESSAGE_WARNING,
+                                                              GTK_BUTTONS_OK,
+                                                              "Campo Da: mancante.");
                                        return FALSE;
                                }
                }
@@ -463,29 +492,66 @@ solipa_mail_ui_send (SolipaMailUI *mailui)
 
        if (g_strcmp0 (g_strstrip (to), "") != 0)
                {
+                       gboolean one;
+
+                       one = FALSE;
                        lst_addrs = solipa_mail_get_addresses_from_string (to);
                        if (lst_addrs != NULL)
                                {
                                        while (lst_addrs != NULL)
                                                {
-                                                       camel_internet_address_add (addr,
-                                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "name"),
-                                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "address"));
+                                                       email = g_hash_table_lookup ((GHashTable *)lst_addrs->data, "address");
+                                                       if (!solipa_mail_check_email_address (email))
+                                                               {
+                                                                       if (solipa_message_dialog (transient,
+                                                                                                  GTK_MESSAGE_QUESTION,
+                                                                                                  GTK_BUTTONS_YES_NO,
+                                                                                                  g_strdup_printf ("L'indirizzo «%s» non è valido.\n"
+                                                                                                                   "Si vuole continuare? (se sì, l'indirizzo non verrà utilizzato)",
+                                                                                                                   email)) == GTK_RESPONSE_NO)
+                                                                               {
+                                                                                       return FALSE;
+                                                                               }
+                                                               }
+                                                       else
+                                                               {
+                                                                       one = TRUE;
+                                                                       camel_internet_address_add (addr,
+                                                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "name"),
+                                                                                                   email);
+                                                               }
                                                        lst_addrs = g_slist_next (lst_addrs);
                                                }
 
-                                       solipa_mail_add_recipient (smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_TO);
-                                       camel_address_remove (CAMEL_ADDRESS (addr), -1);
+                                       if (one)
+                                               {
+                                                       solipa_mail_add_recipient (smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_TO);
+                                                       camel_address_remove (CAMEL_ADDRESS (addr), -1);
+                                               }
+                                       else
+                                               {
+                                                       solipa_message_dialog (transient,
+                                                                              GTK_MESSAGE_WARNING,
+                                                                              GTK_BUTTONS_OK,
+                                                                              "Campo A: mancante.");
+                                                       return FALSE;
+                                               }
                                }
                        else
                                {
-                                       g_warning ("Campo A: mancante.");
+                                       solipa_message_dialog (transient,
+                                                              GTK_MESSAGE_WARNING,
+                                                              GTK_BUTTONS_OK,
+                                                              "Campo A: mancante.");
                                        return FALSE;
                                }
                }
        else
                {
-                       g_warning ("Campo A: mancante.");
+                       solipa_message_dialog (transient,
+                                              GTK_MESSAGE_WARNING,
+                                              GTK_BUTTONS_OK,
+                                              "Campo A: mancante.");
                        return FALSE;
                }
 
@@ -496,9 +562,25 @@ solipa_mail_ui_send (SolipaMailUI *mailui)
                                {
                                        while (lst_addrs != NULL)
                                                {
-                                                       camel_internet_address_add (addr,
-                                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "name"),
-                                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "address"));
+                                                       email = g_hash_table_lookup ((GHashTable *)lst_addrs->data, "address");
+                                                       if (!solipa_mail_check_email_address (email))
+                                                               {
+                                                                       if (solipa_message_dialog (transient,
+                                                                                                  GTK_MESSAGE_QUESTION,
+                                                                                                  GTK_BUTTONS_YES_NO,
+                                                                                                  g_strdup_printf ("L'indirizzo «%s» non è valido.\n"
+                                                                                                                   "Si vuole continuare? (se sì, l'indirizzo non verrà utilizzato)",
+                                                                                                                   email)) == GTK_RESPONSE_NO)
+                                                                               {
+                                                                                       return FALSE;
+                                                                               }
+                                                               }
+                                                       else
+                                                               {
+                                                                       camel_internet_address_add (addr,
+                                                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "name"),
+                                                                                                   email);
+                                                               }
                                                        lst_addrs = g_slist_next (lst_addrs);
                                                }
 
@@ -514,9 +596,25 @@ solipa_mail_ui_send (SolipaMailUI *mailui)
                                {
                                        while (lst_addrs != NULL)
                                                {
-                                                       camel_internet_address_add (addr,
-                                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "name"),
-                                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "address"));
+                                                       email = g_hash_table_lookup ((GHashTable *)lst_addrs->data, "address");
+                                                       if (!solipa_mail_check_email_address (email))
+                                                               {
+                                                                       if (solipa_message_dialog (transient,
+                                                                                                  GTK_MESSAGE_QUESTION,
+                                                                                                  GTK_BUTTONS_YES_NO,
+                                                                                                  g_strdup_printf ("L'indirizzo «%s» non è valido.\n"
+                                                                                                                   "Si vuole continuare? (se sì, l'indirizzo non verrà utilizzato)",
+                                                                                                                   email)) == GTK_RESPONSE_NO)
+                                                                               {
+                                                                                       return FALSE;
+                                                                               }
+                                                               }
+                                                       else
+                                                               {
+                                                                       camel_internet_address_add (addr,
+                                                                                                   g_hash_table_lookup ((GHashTable *)lst_addrs->data, "name"),
+                                                                                                   email);
+                                                               }
                                                        lst_addrs = g_slist_next (lst_addrs);
                                                }
 
@@ -546,7 +644,10 @@ solipa_mail_ui_send (SolipaMailUI *mailui)
                }
        else
                {
-                       g_warning ("URI smtp mancante.");
+                       solipa_message_dialog (transient,
+                                              GTK_MESSAGE_WARNING,
+                                              GTK_BUTTONS_OK,
+                                              "URI smtp mancante.");
                        return FALSE;
                }