From: Andrea Zagli <azagli@libero.it>
Date: Sat, 22 Oct 2016 13:52:57 +0000 (+0200)
Subject: Aggiunta la funzione SolipaMail::set_proxy.
X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=01bac9b4f30b43421f2978016455bbc1d89a24ec;p=solipa%2Flibsolipa

Aggiunta la funzione SolipaMail::set_proxy.
---

diff --git a/src/mail.c b/src/mail.c
index 72f56c0..435046b 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2016 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -61,6 +61,9 @@ struct _SolipaMailPrivate
 		gchar *username;
 		gchar *password;
 
+		GProxyResolver *proxy_resolver;
+		gchar *proxy_uri;
+
 		gchar *body_plain;
 		gchar *body_html;
 
@@ -577,6 +580,32 @@ solipa_mail_set_username_password (SolipaMail *mail, const gchar *username, cons
 		}
 }
 
+void
+solipa_mail_set_proxy (SolipaMail *mail, GProxyResolver *resolver, const gchar *uri)
+{
+	SolipaMailPrivate *priv;
+
+	g_return_if_fail (IS_SOLIPA_MAIL (mail));
+
+	priv = SOLIPA_MAIL_GET_PRIVATE (mail);
+
+	priv->proxy_resolver = NULL;
+	if (priv->proxy_uri != NULL)
+		{
+			g_free (priv->proxy_uri);
+		}
+	priv->proxy_uri = NULL;
+
+	if (uri != NULL)
+		{
+			priv->proxy_uri = g_strdup (uri);
+		}
+	else if (G_IS_PROXY_RESOLVER (resolver))
+		{
+			priv->proxy_resolver = resolver;
+		}
+}
+
 void
 solipa_mail_send (SolipaMail *mail, const gchar *url)
 {
@@ -587,13 +616,13 @@ solipa_mail_send (SolipaMail *mail, const gchar *url)
 
 	CamelMimeMessage *msg;
 
+	GProxyResolver *proxy_resolver;
+
 	CamelInternetAddress *from;
 	CamelInternetAddress *addr;
 	CamelInternetAddress *to;
 	CamelService *trans;
 
-	CamelSession *session;
-
 	guint i;
 
 	char *types[] = { "to", "cc", "bcc" };
@@ -712,6 +741,25 @@ solipa_mail_send (SolipaMail *mail, const gchar *url)
 			return;
 		}
 
+	/* proxy */
+	if (priv->proxy_resolver != NULL
+		|| priv->proxy_uri != NULL)
+		{
+			if (priv->proxy_resolver != NULL)
+				{
+					proxy_resolver = priv->proxy_resolver;
+				}
+			else
+				{
+					proxy_resolver = g_simple_proxy_resolver_new (priv->proxy_uri, NULL);
+				}
+		}
+	else
+		{
+			proxy_resolver = g_simple_proxy_resolver_new (NULL, NULL);
+		}
+	camel_service_set_proxy_resolver (trans, proxy_resolver);
+
 	error = NULL;
 #ifdef CAMEL318
 	ret = camel_service_connect_sync (trans, NULL, &error);
diff --git a/src/mail.h b/src/mail.h
index 517dd5f..8a195da 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2016 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -80,6 +80,8 @@ void solipa_mail_set_security_method (SolipaMail *mail, CamelNetworkSecurityMeth
 
 void solipa_mail_set_username_password (SolipaMail *mail, const gchar *username, const gchar *password);
 
+void solipa_mail_set_proxy (SolipaMail *mail, GProxyResolver *resolver, const gchar *uri);
+
 void solipa_mail_send (SolipaMail *mail, const gchar *url);
 
 gboolean solipa_mail_check_email_address (const gchar *address);
diff --git a/tests/mail.c b/tests/mail.c
index f529ac6..f61ae1f 100644
--- a/tests/mail.c
+++ b/tests/mail.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2016 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
@@ -35,18 +35,20 @@ main (int argc, char **argv)
 	CamelNetworkSecurityMethod security_method;
 	gchar *username;
 	gchar *password;
+	gchar *proxy;
 
 	GError *error;
 
-	GOptionEntry entries[] = 
+	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 },
 		{ "notification", 'n', 0, G_OPTION_ARG_INT, &notification, "Richiedere notifica", NULL },
-		{ "security method", 's', 0, G_OPTION_ARG_INT, &security_method, "Metodo per connessione sicura (0 - nessuno; 1 - SSL/TLS; 2 - STARTTLS", NULL },
+		{ "security method", 's', 0, G_OPTION_ARG_INT, &security_method, "Metodo per connessione sicura (0 - nessuno; 1 - SSL/TLS; 2 - STARTTLS)", NULL },
 		{ "username", 'm', 0, G_OPTION_ARG_STRING, &username, "Nome utente", NULL },
 		{ "password", 'p', 0, G_OPTION_ARG_STRING, &password, "Password", NULL },
+		{ "proxy", 'r', 0, G_OPTION_ARG_STRING, &proxy, "Proxy URI", NULL },
 		{ NULL }
 	};
 
@@ -62,6 +64,7 @@ main (int argc, char **argv)
 	security_method = CAMEL_NETWORK_SECURITY_METHOD_NONE;
 	username = NULL;
 	password = NULL;
+	proxy = NULL;
 
 	/* gestione degli argomenti della riga di comando */
 	context = g_option_context_new ("");
@@ -157,6 +160,8 @@ main (int argc, char **argv)
 			solipa_mail_set_username_password (smail, username, password);
 		}
 
+	solipa_mail_set_proxy (smail, NULL, proxy);
+
 	solipa_mail_send (smail, url);
 
 	return 0;