From dde2527db61f906fd40c17b588aff4be9d4fe0ce Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 12 Oct 2014 09:53:09 +0200 Subject: [PATCH] Aggiunti i parametri a riga di comando al test di SolipaMail. --- tests/mail.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/tests/mail.c b/tests/mail.c index e27aac5..47b9593 100644 --- a/tests/mail.c +++ b/tests/mail.c @@ -28,6 +28,74 @@ main (int argc, char **argv) gchar *strmail; + gchar *from; + gchar *to; + gchar *url; + + GError *error; + + GOptionEntry entries[] = + { + { "from", 'f', 0, G_OPTION_ARG_STRING, &from, "Indirizzo FROM", NULL }, + { "to", 't', 0, G_OPTION_ARG_STRING, &to, "Indirizzo TO", NULL }, + { "url", 'u', 0, G_OPTION_ARG_STRING, &url, "Url smtp server", NULL }, + { NULL } + }; + + GOptionContext *context; + + GSList *addrs_from; + GSList *addrs_to; + + from = NULL; + to = NULL; + url = NULL; + + /* gestione degli argomenti della riga di comando */ + context = g_option_context_new (""); + g_option_context_add_main_entries (context, entries, NULL); + error = NULL; + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + /* TO DO */ + g_error ("Errore argomenti riga comando.\n"); + return 0; + } + + if (from == NULL || strcmp (g_strstrip (from), "") == 0) + { + g_error ("Occorre specificare il parametro from.\n"); + return 0; + } + else + { + addrs_from = solipa_mail_get_addresses_from_string (from); + if (addrs_from == NULL || g_slist_length (addrs_from) < 1) + { + g_error ("Occorre specificare il parametro from.\n"); + return 0; + } + } + if (to == NULL || strcmp (g_strstrip (to), "") == 0) + { + g_error ("Occorre specificare il parametro to.\n"); + return 0; + } + else + { + addrs_to = solipa_mail_get_addresses_from_string (to); + if (addrs_to == NULL || g_slist_length (addrs_to) < 1) + { + g_error ("Occorre specificare il parametro to.\n"); + return 0; + } + } + if (url == NULL || strcmp (g_strstrip (url), "") == 0) + { + g_error ("Occorre specificare il parametro url.\n"); + return 0; + } + solipa = solipa_new (); smail = solipa_mail_new (solipa); @@ -35,12 +103,16 @@ main (int argc, char **argv) solipa_mail_set_subject (smail, "Trying to send an e-mail with SolipaMail."); addr = camel_internet_address_new (); - camel_internet_address_add (addr, "Andrea Zagli", "azagli@libero.it"); + camel_internet_address_add (addr, + g_hash_table_lookup ((GHashTable *)addrs_from->data, "name"), + g_hash_table_lookup ((GHashTable *)addrs_from->data, "address")); solipa_mail_set_from (smail, addr); camel_address_remove (CAMEL_ADDRESS (addr), -1); - camel_internet_address_add (addr, "pippo", "pippo@localhost"); + camel_internet_address_add (addr, + g_hash_table_lookup ((GHashTable *)addrs_to->data, "name"), + g_hash_table_lookup ((GHashTable *)addrs_to->data, "address")); solipa_mail_add_recipient (smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_TO); g_object_unref (addr); @@ -63,7 +135,7 @@ main (int argc, char **argv) strmail = solipa_mail_get_as_string (smail); g_message ("The email text:\n%s", strmail); - solipa_mail_send (smail, "smtp://localhost/"); + solipa_mail_send (smail, url); return 0; } -- 2.49.0