aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@novell.com>2004-06-25 05:49:41 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-06-25 05:49:41 +0800
commit0ef312f45de342d9eb91bda74503497974c39084 (patch)
tree51c26409cfcfbc0e92d3e0cd626ec97c142245e0 /camel/providers
parent4110b183b7326182ef014516be7c4a53a8c1bb76 (diff)
downloadgsoc2013-evolution-0ef312f45de342d9eb91bda74503497974c39084.tar.gz
gsoc2013-evolution-0ef312f45de342d9eb91bda74503497974c39084.tar.zst
gsoc2013-evolution-0ef312f45de342d9eb91bda74503497974c39084.zip
Error out and set an exception if camel_pop3_engine_new() returns NULL
2004-06-24 Jeffrey Stedfast <fejj@novell.com> * providers/pop3/camel-pop3-store.c (connect_to_server): Error out and set an exception if camel_pop3_engine_new() returns NULL (which it can do now). * providers/pop3/camel-pop3-engine.c (get_capabilities): No longer reads the greeting. (camel_pop3_engine_new): Reads the greeting itself and returns NULL if an error occurs (like stupid braindamaged piece of shit POP servers that spew debug prinfs). svn path=/trunk/; revision=26504
Diffstat (limited to 'camel/providers')
-rw-r--r--camel/providers/pop3/camel-pop3-engine.c64
-rw-r--r--camel/providers/pop3/camel-pop3-store.c19
2 files changed, 53 insertions, 30 deletions
diff --git a/camel/providers/pop3/camel-pop3-engine.c b/camel/providers/pop3/camel-pop3-engine.c
index 2186136f95..391d5bd31b 100644
--- a/camel/providers/pop3/camel-pop3-engine.c
+++ b/camel/providers/pop3/camel-pop3-engine.c
@@ -44,7 +44,7 @@
extern int camel_verbose_debug;
#define dd(x) (camel_verbose_debug?(x):0)
-static void get_capabilities(CamelPOP3Engine *pe, int read_greeting);
+static void get_capabilities(CamelPOP3Engine *pe);
static CamelObjectClass *parent_class = NULL;
@@ -72,7 +72,7 @@ camel_pop3_engine_finalise(CamelPOP3Engine *pe)
/* FIXME: Also flush/free any outstanding requests, etc */
if (pe->stream)
- camel_object_unref((CamelObject *)pe->stream);
+ camel_object_unref(pe->stream);
}
CamelType
@@ -94,6 +94,32 @@ camel_pop3_engine_get_type (void)
return camel_pop3_engine_type;
}
+static int
+read_greeting (CamelPOP3Engine *pe)
+{
+ extern CamelServiceAuthType camel_pop3_password_authtype;
+ extern CamelServiceAuthType camel_pop3_apop_authtype;
+ unsigned char *line, *apop, *apopend;
+ unsigned int len;
+
+ /* first, read the greeting */
+ if (camel_pop3_stream_line (pe->stream, &line, &len) == -1
+ || strncmp (line, "+OK", 3) != 0)
+ return -1;
+
+ if ((apop = strchr (line + 3, '<'))
+ && (apopend = strchr (apop, '>'))) {
+ apopend[1] = 0;
+ pe->apop = g_strdup (apop);
+ pe->capa = CAMEL_POP3_CAP_APOP;
+ pe->auth = g_list_append (pe->auth, &camel_pop3_apop_authtype);
+ }
+
+ pe->auth = g_list_prepend (pe->auth, &camel_pop3_password_authtype);
+
+ return 0;
+}
+
/**
* camel_pop3_engine_new:
* @source: source stream
@@ -115,8 +141,13 @@ camel_pop3_engine_new(CamelStream *source, guint32 flags)
pe->state = CAMEL_POP3_ENGINE_AUTH;
pe->flags = flags;
- get_capabilities(pe, TRUE);
-
+ if (read_greeting (pe) == -1) {
+ camel_object_unref (pe);
+ return NULL;
+ }
+
+ get_capabilities (pe);
+
return pe;
}
@@ -132,7 +163,7 @@ camel_pop3_engine_reget_capabilities (CamelPOP3Engine *engine)
{
g_return_if_fail (CAMEL_IS_POP3_ENGINE (engine));
- get_capabilities (engine, FALSE);
+ get_capabilities (engine);
}
@@ -190,30 +221,11 @@ cmd_capa(CamelPOP3Engine *pe, CamelPOP3Stream *stream, void *data)
}
static void
-get_capabilities(CamelPOP3Engine *pe, int read_greeting)
+get_capabilities(CamelPOP3Engine *pe)
{
CamelPOP3Command *pc;
- unsigned char *line, *apop, *apopend;
+ unsigned char *line;
unsigned int len;
- extern CamelServiceAuthType camel_pop3_password_authtype;
- extern CamelServiceAuthType camel_pop3_apop_authtype;
-
- if (read_greeting) {
- /* first, read the greeting */
- if (camel_pop3_stream_line(pe->stream, &line, &len) == -1
- || strncmp(line, "+OK", 3) != 0)
- return;
-
- if ((apop = strchr(line+3, '<'))
- && (apopend = strchr(apop, '>'))) {
- apopend[1] = 0;
- pe->apop = g_strdup(apop);
- pe->capa = CAMEL_POP3_CAP_APOP;
- pe->auth = g_list_append(pe->auth, &camel_pop3_apop_authtype);
- }
-
- pe->auth = g_list_prepend(pe->auth, &camel_pop3_password_authtype);
- }
if (!(pe->flags & CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS)) {
pc = camel_pop3_engine_command_new(pe, CAMEL_POP3_COMMAND_MULTI, cmd_capa, NULL, "CAPA\r\n");
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index 685bf49f3c..96f9295b52 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -195,21 +195,26 @@ connect_to_server (CamelService *service, int ssl_mode, int try_starttls, CamelE
_("Could not connect to POP server %s (port %d): %s"),
service->url->host, port, g_strerror (errno));
- camel_object_unref (CAMEL_OBJECT (tcp_stream));
+ camel_object_unref (tcp_stream);
return FALSE;
}
/* parent class connect initialization */
if (CAMEL_SERVICE_CLASS (parent_class)->connect (service, ex) == FALSE) {
- camel_object_unref (CAMEL_OBJECT (tcp_stream));
+ camel_object_unref (tcp_stream);
return FALSE;
}
if (camel_url_get_param (service->url, "disable_extensions"))
flags |= CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS;
- store->engine = camel_pop3_engine_new (tcp_stream, flags);
+ if (!(store->engine = camel_pop3_engine_new (tcp_stream, flags))) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Failed to read a valid greeting from POP server %s (port %d)"),
+ service->url->host, port);
+ return FALSE;
+ }
#ifdef HAVE_SSL
if (store->engine) {
@@ -235,7 +240,7 @@ connect_to_server (CamelService *service, int ssl_mode, int try_starttls, CamelE
}
#endif /* HAVE_SSL */
- camel_object_unref (CAMEL_OBJECT (tcp_stream));
+ camel_object_unref (tcp_stream);
return store->engine != NULL;
@@ -537,6 +542,12 @@ pop3_try_authenticate (CamelService *service, gboolean reprompt, const char *err
CAMEL_SERVICE (store)->url->host,
errno ? g_strerror (errno) : _("Unknown error"));
}
+ } else if (pcu && pcu->state != CAMEL_POP3_COMMAND_OK) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+ _("Unable to connect to POP server %s.\n"
+ "Error sending username: %s"),
+ CAMEL_SERVICE (store)->url->host,
+ store->engine->line ? (char *)store->engine->line : _("Unknown error"));
} else if (pcp->state != CAMEL_POP3_COMMAND_OK)
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
_("Unable to connect to POP server %s.\n"