aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-09-26 08:42:38 +0800
committerMatthew Barnes <mbarnes@redhat.com>2011-09-26 21:45:55 +0800
commit9773f0a3b8ed4a058d4cd28d0bc4060dbe43da19 (patch)
treea7c2a01bbf11bce97cde8d5fdc0ecf518f67e4b2
parente384255d8f999bd77fb7ccee5e57c30b54ea5a56 (diff)
downloadgsoc2013-evolution-9773f0a3b8ed4a058d4cd28d0bc4060dbe43da19.tar
gsoc2013-evolution-9773f0a3b8ed4a058d4cd28d0bc4060dbe43da19.tar.gz
gsoc2013-evolution-9773f0a3b8ed4a058d4cd28d0bc4060dbe43da19.tar.bz2
gsoc2013-evolution-9773f0a3b8ed4a058d4cd28d0bc4060dbe43da19.tar.lz
gsoc2013-evolution-9773f0a3b8ed4a058d4cd28d0bc4060dbe43da19.tar.xz
gsoc2013-evolution-9773f0a3b8ed4a058d4cd28d0bc4060dbe43da19.tar.zst
gsoc2013-evolution-9773f0a3b8ed4a058d4cd28d0bc4060dbe43da19.zip
EMFormatHTML: Configure CamelHttpStreams with proxy authpass.
Base64-encode the "USER:PASS" authentication string ourselves and hand it to camel_http_stream_set_proxy_authpass(). This is so I can kill camel_http_stream_set_proxy().
-rw-r--r--mail/em-format-html.c47
-rw-r--r--mail/em-utils.c81
-rw-r--r--mail/em-utils.h3
3 files changed, 45 insertions, 86 deletions
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index a1be319390..e41455e294 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -1511,6 +1511,43 @@ emfh_getpuri (struct _EMFormatHTMLJob *job,
}
static void
+emfh_configure_stream_for_proxy (CamelHttpStream *stream,
+ const gchar *uri)
+{
+ EProxy *proxy;
+ SoupURI *proxy_uri;
+ gchar *basic;
+ gchar *basic64;
+ const gchar *user = "";
+ const gchar *password = "";
+
+ proxy = em_utils_get_proxy ();
+
+ if (!e_proxy_require_proxy_for_uri (proxy, uri))
+ return;
+
+ proxy_uri = e_proxy_peek_uri_for (proxy, uri);
+
+ if (proxy_uri == NULL)
+ return;
+
+ if (proxy_uri->user != NULL)
+ user = proxy_uri->user;
+
+ if (proxy_uri->password != NULL)
+ password = proxy_uri->password;
+
+ if (*user == '\0' && *password == '\0')
+ return;
+
+ basic = g_strdup_printf ("%s:%s", user, password);
+ basic64 = g_base64_encode ((guchar *) basic, strlen (basic));
+ camel_http_stream_set_proxy_authpass (stream, basic64);
+ g_free (basic64);
+ g_free (basic);
+}
+
+static void
emfh_gethttp (struct _EMFormatHTMLJob *job,
GCancellable *cancellable)
{
@@ -1533,7 +1570,6 @@ emfh_gethttp (struct _EMFormatHTMLJob *job,
if (instream == NULL) {
EMailImageLoadingPolicy policy;
- gchar *proxy;
policy = em_format_html_get_image_loading_policy (job->format);
@@ -1552,12 +1588,9 @@ emfh_gethttp (struct _EMFormatHTMLJob *job,
}
instream = camel_http_stream_new (CAMEL_HTTP_METHOD_GET, ((EMFormat *) job->format)->session, url);
- camel_http_stream_set_user_agent((CamelHttpStream *)instream, "CamelHttpStream/1.0 Evolution/" VERSION);
- proxy = em_utils_get_proxy_uri (job->u.uri);
- if (proxy) {
- camel_http_stream_set_proxy ((CamelHttpStream *) instream, proxy);
- g_free (proxy);
- }
+ camel_http_stream_set_user_agent((CamelHttpStream *) instream, "CamelHttpStream/1.0 Evolution/" VERSION);
+ emfh_configure_stream_for_proxy ((CamelHttpStream *) instream, job->u.uri);
+
camel_operation_push_message (
cancellable, _("Retrieving '%s'"), job->u.uri);
tmp_stream = (CamelHttpStream *) instream;
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 5ff93887a2..4a74a80fc2 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -1194,69 +1194,6 @@ em_utils_folder_is_outbox (CamelFolder *folder)
static EProxy *emu_proxy = NULL;
static GStaticMutex emu_proxy_lock = G_STATIC_MUTEX_INIT;
-/* encode to string this way, because soup_uri_to_string doesn't include passwords */
-static gchar *
-suri_to_string (SoupURI *suri)
-{
- GString *uri;
- gchar *tmp;
-
- if (!suri)
- return NULL;
-
- uri = g_string_sized_new (20);
-
- if (suri->scheme)
- g_string_append_printf (uri, "%s:", suri->scheme);
- if (suri->host) {
- g_string_append (uri, "//");
- if (suri->user) {
- tmp = soup_uri_encode (suri->user, ":/;#@?\\");
- g_string_append (uri, tmp);
- g_free (tmp);
- }
-
- if (suri->password) {
- g_string_append_c (uri, ':');
- tmp = soup_uri_encode (suri->password, ":/;#@?\\");
- g_string_append (uri, tmp);
- g_free (tmp);
- }
-
- if (suri->user || suri->password)
- g_string_append_c (uri, '@');
-
- if (strchr (suri->host, ':')) {
- g_string_append_c (uri, '[');
- g_string_append (uri, suri->host);
- g_string_append_c (uri, ']');
- } else {
- tmp = soup_uri_encode (suri->host, ":/");
- g_string_append (uri, tmp);
- g_free (tmp);
- }
-
- if (suri->port && !soup_uri_uses_default_port (suri))
- g_string_append_printf (uri, ":%d", suri->port);
- if (!suri->path && (suri->query || suri->fragment))
- g_string_append_c (uri, '/');
- }
-
- if (suri->path && *suri->path)
- g_string_append (uri, suri->path);
-
- if (suri->query) {
- g_string_append_c (uri, '?');
- g_string_append (uri, suri->query);
- }
- if (suri->fragment) {
- g_string_append_c (uri, '#');
- g_string_append (uri, suri->fragment);
- }
-
- return g_string_free (uri, FALSE);
-}
-
static gpointer
emu_proxy_setup (gpointer data)
{
@@ -1269,30 +1206,18 @@ emu_proxy_setup (gpointer data)
return NULL;
}
-/**
- * em_utils_get_proxy_uri:
- *
- * Get the system proxy uri for 'pUri'.
- *
- * Return value: Must be freed when finished with.
- **/
-gchar *
-em_utils_get_proxy_uri (const gchar *pUri)
+EProxy *
+em_utils_get_proxy (void)
{
- gchar *uri = NULL;
-
g_static_mutex_lock (&emu_proxy_lock);
if (!emu_proxy) {
mail_call_main (MAIL_CALL_p_p, (MailMainFunc) emu_proxy_setup, NULL);
}
- if (e_proxy_require_proxy_for_uri (emu_proxy, pUri))
- uri = suri_to_string (e_proxy_peek_uri_for (emu_proxy, pUri));
-
g_static_mutex_unlock (&emu_proxy_lock);
- return uri;
+ return emu_proxy;
}
/**
diff --git a/mail/em-utils.h b/mail/em-utils.h
index e6ebe8ca4b..b07b74b186 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -26,6 +26,7 @@
#include <gtk/gtk.h>
#include <sys/types.h>
#include <camel/camel.h>
+#include <libedataserver/e-proxy.h>
#include <mail/e-mail-reader.h>
#include <mail/e-mail-session.h>
@@ -66,7 +67,7 @@ gboolean em_utils_folder_is_templates (CamelFolder *folder);
gboolean em_utils_folder_is_sent (CamelFolder *folder);
gboolean em_utils_folder_is_outbox (CamelFolder *folder);
-gchar *em_utils_get_proxy_uri (const gchar *uri);
+EProxy * em_utils_get_proxy (void);
/* FIXME: should this have an override charset? */
gchar *em_utils_message_to_html (CamelMimeMessage *msg, const gchar *credits, guint32 flags, struct _EMFormat *source, const gchar *append, guint32 *validity_found);