aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/pop3
diff options
context:
space:
mode:
authorPeter Williams <peterw@src.gnome.org>2000-08-30 05:28:46 +0800
committerPeter Williams <peterw@src.gnome.org>2000-08-30 05:28:46 +0800
commitda570c66609a9baea34d4899c4ca7e1f8329d471 (patch)
tree78f82074f39463fc8db0cfb92728d57fe9c2ac84 /camel/providers/pop3
parentba2eaa68b17882b0fec2eac160f674d29598795f (diff)
downloadgsoc2013-evolution-da570c66609a9baea34d4899c4ca7e1f8329d471.tar.gz
gsoc2013-evolution-da570c66609a9baea34d4899c4ca7e1f8329d471.tar.zst
gsoc2013-evolution-da570c66609a9baea34d4899c4ca7e1f8329d471.zip
CamelRemoteStore: a new generic store for stores that connect to servers. Prepare for the ability to cancel operations (much better exception handling). Clean up IMAP like nobody's business
svn path=/trunk/; revision=5103
Diffstat (limited to 'camel/providers/pop3')
-rw-r--r--camel/providers/pop3/camel-pop3-folder.c32
-rw-r--r--camel/providers/pop3/camel-pop3-store.c21
2 files changed, 43 insertions, 10 deletions
diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c
index 6dbba64c20..43c8d9a958 100644
--- a/camel/providers/pop3/camel-pop3-folder.c
+++ b/camel/providers/pop3/camel-pop3-folder.c
@@ -38,6 +38,7 @@ static CamelFolderClass *parent_class;
static void pop3_finalize (CamelObject *object);
+static void pop3_refresh_info (CamelFolder *folder, CamelException *ex);
static void pop3_sync (CamelFolder *folder, gboolean expunge,
CamelException *ex);
@@ -60,6 +61,7 @@ camel_pop3_folder_class_init (CamelPop3FolderClass *camel_pop3_folder_class)
parent_class = CAMEL_FOLDER_CLASS(camel_type_get_global_classfuncs (camel_folder_get_type ()));
/* virtual method overload */
+ camel_folder_class->refresh_info = pop3_refresh_info;
camel_folder_class->sync = pop3_sync;
camel_folder_class->get_message_count = pop3_get_message_count;
@@ -111,21 +113,36 @@ pop3_finalize (CamelObject *object)
CamelFolder *
camel_pop3_folder_new (CamelStore *parent, CamelException *ex)
{
- CamelPop3Store *pop3_store = CAMEL_POP3_STORE (parent);
CamelPop3Folder *pop3_folder;
+
+ pop3_folder = CAMEL_POP3_FOLDER(camel_object_new (CAMEL_POP3_FOLDER_TYPE));
+ CF_CLASS (pop3_folder)->init ((CamelFolder *)pop3_folder, parent,
+ NULL, "inbox", "/", TRUE, ex);
+ pop3_folder->uids = NULL;
+ pop3_folder->flags = NULL;
+ CF_CLASS (pop3_folder)->refresh_info ((CamelFolder *)pop3_folder, ex);
+
+ return (CamelFolder *)pop3_folder;
+}
+
+static void
+pop3_refresh_info (CamelFolder *folder, CamelException *ex)
+{
GPtrArray *uids;
int status, count;
char *data;
+ CamelPop3Folder *pop3_folder = (CamelPop3Folder *) folder;
+ CamelPop3Store *pop3_store = CAMEL_POP3_STORE (folder->parent_store);
status = camel_pop3_command (pop3_store, &data, "STAT");
if (status != CAMEL_POP3_OK) {
- CamelService *service = CAMEL_SERVICE (parent);
+ CamelService *service = CAMEL_SERVICE (pop3_store);
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
"Could not get message count from POP "
"server %s: %s.", service->url->host,
data ? data : "Unknown error");
g_free (data);
- return NULL;
+ return;
}
count = atoi (data);
@@ -148,7 +165,7 @@ camel_pop3_folder_new (CamelStore *parent, CamelException *ex)
} else {
data = camel_pop3_command_get_additional_data (pop3_store, ex);
if (camel_exception_is_set (ex))
- return NULL;
+ return;
uids = parse_listing (count, data);
g_free (data);
@@ -157,17 +174,12 @@ camel_pop3_folder_new (CamelStore *parent, CamelException *ex)
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
"Could not open folder: message "
"listing was incomplete.");
- return NULL;
+ return;
}
}
- pop3_folder = CAMEL_POP3_FOLDER(camel_object_new (CAMEL_POP3_FOLDER_TYPE));
- CF_CLASS (pop3_folder)->init ((CamelFolder *)pop3_folder, parent,
- NULL, "inbox", "/", TRUE, ex);
pop3_folder->uids = uids;
pop3_folder->flags = g_new0 (guint32, uids->len);
-
- return (CamelFolder *)pop3_folder;
}
static void
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index 4f618e521e..6ee7361959 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -277,6 +277,9 @@ connect_to_server (CamelService *service, gboolean real, CamelException *ex)
store->supports_uidl = -1;
store->expires = -1;
+ /* good enough for us */
+ service->connected = TRUE;
+
status = camel_pop3_command (store, NULL, "CAPA");
if (status == CAMEL_POP3_OK) {
char *p;
@@ -285,6 +288,7 @@ connect_to_server (CamelService *service, gboolean real, CamelException *ex)
buf = camel_pop3_command_get_additional_data (store, ex);
if (camel_exception_is_set (ex)) {
pop3_disconnect (service, ex);
+ service->connected = FALSE;
return FALSE;
}
@@ -534,6 +538,7 @@ pop3_connect (CamelService *service, CamelException *ex)
if (camel_exception_is_set (ex)) {
pop3_disconnect (service, NULL);
+ service->connected = FALSE;
return FALSE;
}
@@ -628,6 +633,21 @@ camel_pop3_command (CamelPop3Store *store, char **ret, char *fmt, ...)
char *cmdbuf;
va_list ap;
+ /* Check for connectedness. Failed (or cancelled) operations will
+ * close the connection. */
+ if (CAMEL_SERVICE (store)->connected == FALSE) {
+ CamelException ex;
+
+ d(g_message ("pop3: disconnected, reconnecting."));
+ camel_exception_init (&ex);
+ CAMEL_SERVICE_CLASS (CAMEL_OBJECT_GET_CLASS (store))->connect (store, &ex);
+ if (camel_exception_is_set (&ex)) {
+ camel_exception_clear (&ex);
+ return CAMEL_POP3_FAIL;
+ }
+ camel_exception_clear (&ex);
+ }
+
if (!store->ostream) {
/*CamelException ex;
*
@@ -769,3 +789,4 @@ camel_pop3_command_get_additional_data (CamelPop3Store *store, CamelException *e
return buf;
}
+