aboutsummaryrefslogtreecommitdiffstats
path: root/capplet/settings/mail-guess-servers.c
diff options
context:
space:
mode:
Diffstat (limited to 'capplet/settings/mail-guess-servers.c')
-rw-r--r--capplet/settings/mail-guess-servers.c88
1 files changed, 78 insertions, 10 deletions
diff --git a/capplet/settings/mail-guess-servers.c b/capplet/settings/mail-guess-servers.c
index 388f894e72..a9e477abd7 100644
--- a/capplet/settings/mail-guess-servers.c
+++ b/capplet/settings/mail-guess-servers.c
@@ -42,6 +42,8 @@
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
+#include <shell/e-shell.h>
+
#include "mail-guess-servers.h"
static gchar *
@@ -158,13 +160,13 @@ handle_outgoing (xmlNodePtr head, EmailProvider *provider)
}
}
-static void
-parse_msg (SoupMessage *msg, EmailProvider *provider)
+static gboolean
+parse_message (const gchar *msg, gint length, EmailProvider *provider)
{
xmlDocPtr doc;
xmlNodePtr node, top;
- doc = xmlReadMemory (msg->response_body->data, msg->response_body->length, "file.xml", NULL, 0);
+ doc = xmlReadMemory (msg, length, "file.xml", NULL, 0);
node = doc->children;
while (node) {
@@ -176,7 +178,7 @@ parse_msg (SoupMessage *msg, EmailProvider *provider)
if (!node) {
g_warning ("Incorrect data: ClientConfig not found ... Quitting\n");
- return;
+ return FALSE;
}
node = node->children;
@@ -189,7 +191,7 @@ parse_msg (SoupMessage *msg, EmailProvider *provider)
if (!node) {
g_warning ("Incorrect data: ClientConfig not found ... Quitting\n");
- return;
+ return FALSE;
}
top = node;
@@ -207,10 +209,36 @@ parse_msg (SoupMessage *msg, EmailProvider *provider)
}
xmlFreeDoc(doc);
+
+ return TRUE;
}
-gboolean
-mail_guess_servers(EmailProvider *provider)
+static gboolean
+parse_soup_message (SoupMessage *msg, EmailProvider *provider)
+{
+ return parse_message (msg->response_body->data, msg->response_body->length, provider);
+}
+
+static gboolean
+is_online (void)
+{
+ EShell *shell;
+
+ shell = e_shell_get_default ();
+ if (!shell) {
+ /* FIXME: do we always have a shell? What do we do if one
+ * hasn't been created yet? e_shell_get_default() won't create
+ * a shell; it will just return one that has been created
+ * before.
+ */
+ return FALSE;
+ }
+
+ return e_shell_get_online (shell);
+}
+
+static gboolean
+guess_when_online (EmailProvider *provider)
{
const gchar *cafile = NULL;
gchar *url;
@@ -222,7 +250,6 @@ mail_guess_servers(EmailProvider *provider)
parsed = soup_uri_new (url);
soup_uri_free (parsed);
-
session = soup_session_sync_new_with_options (
SOUP_SESSION_SSL_CA_FILE, cafile,
SOUP_SESSION_USER_AGENT, "get ",
@@ -238,8 +265,8 @@ mail_guess_servers(EmailProvider *provider)
if (!msg)
return FALSE;
- parse_msg(msg, provider);
-
+ parse_soup_message (msg, provider);
+
g_object_unref (msg);
g_object_unref(session);
g_free(url);
@@ -248,6 +275,47 @@ mail_guess_servers(EmailProvider *provider)
}
+static gchar *
+get_filename_for_offline_autoconfig (const gchar *domain)
+{
+ return g_build_filename (EVOLUTION_PRIVDATADIR, "mail-autoconfig", domain, NULL);
+}
+
+static gboolean
+guess_when_offline (EmailProvider *provider)
+{
+ gchar *filename;
+ gchar *contents;
+ gsize length;
+ gboolean success;
+
+ if (!provider->domain || provider->domain[0] == 0)
+ return FALSE;
+
+ success = FALSE;
+
+ filename = get_filename_for_offline_autoconfig (provider->domain);
+ if (!g_file_get_contents (filename, &contents, &length, NULL)) /* NULL-GError */
+ goto out;
+
+ success = parse_message (contents, (gint) length, provider);
+
+out:
+ g_free (filename);
+ g_free (contents);
+
+ return success;
+}
+
+gboolean
+mail_guess_servers(EmailProvider *provider)
+{
+ if (is_online () && guess_when_online (provider))
+ return TRUE;
+ else
+ return guess_when_offline (provider);
+}
+
#ifdef TEST
gint
main (gint argc, gchar **argv)