aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-05-04 04:52:59 +0800
committerDan Winship <danw@src.gnome.org>2001-05-04 04:52:59 +0800
commit7c553e6e5bb47c7b4b26f9bed147e7b7df234f96 (patch)
tree75b27df033aa84aa60eeea841fd8341ff6c415e4 /camel
parent57546880c8e3470834bb7012aee9d892e3ac6708 (diff)
downloadgsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar
gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.gz
gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.bz2
gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.lz
gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.xz
gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.zst
gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.zip
new abstract class for disconnectable remote stores
* camel-disco-store.c: new abstract class for disconnectable remote stores * camel-disco-folder.c: new abstract class for folders on disconnectable stores. * Makefile.am: Add camel-disco-folder.[ch] and camel-disco-store.[ch]. * providers/imap/camel-imap-store.c: Make this a subclass of CamelDiscoStore, and fix up the offline interfaces for the changes since they were first written (particularly the fact that some IMAP stores don't just use subscribed folders). * providers/imap/camel-imap-folder.c: Make this a subclass of CamelDiscoFolder, although most ops still fail in disconnected mode. * camel-store.c (camel_store_get_folder_info): Change gboolean, gboolean, gboolean to guint32 in the prototype for this function. * providers/local/camel-local-store.c (get_folder_info): Update for prototype change. svn path=/trunk/; revision=9659
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog26
-rw-r--r--camel/Makefile.am5
-rw-r--r--camel/camel-disco-folder.c243
-rw-r--r--camel/camel-disco-folder.h94
-rw-r--r--camel/camel-disco-store.c194
-rw-r--r--camel/camel-disco-store.h105
-rw-r--r--camel/camel-store.c39
-rw-r--r--camel/camel-store.h13
-rw-r--r--camel/camel-types.h2
-rw-r--r--camel/providers/imap/camel-imap-folder.c240
-rw-r--r--camel/providers/imap/camel-imap-folder.h16
-rw-r--r--camel/providers/imap/camel-imap-store.c717
-rw-r--r--camel/providers/imap/camel-imap-store.h8
-rw-r--r--camel/providers/local/camel-local-store.c8
14 files changed, 1174 insertions, 536 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 4903f69e6a..ecad1c19d2 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,29 @@
+2001-05-03 Dan Winship <danw@ximian.com>
+
+ * camel-disco-store.c: new abstract class for disconnectable
+ remote stores
+
+ * camel-disco-folder.c: new abstract class for folders on
+ disconnectable stores.
+
+ * Makefile.am: Add camel-disco-folder.[ch] and
+ camel-disco-store.[ch].
+
+ * providers/imap/camel-imap-store.c: Make this a subclass of
+ CamelDiscoStore, and fix up the offline interfaces for the changes
+ since they were first written (particularly the fact that some
+ IMAP stores don't just use subscribed folders).
+
+ * providers/imap/camel-imap-folder.c: Make this a subclass of
+ CamelDiscoFolder, although most ops still fail in disconnected
+ mode.
+
+ * camel-store.c (camel_store_get_folder_info): Change gboolean,
+ gboolean, gboolean to guint32 in the prototype for this function.
+
+ * providers/local/camel-local-store.c (get_folder_info): Update
+ for prototype change.
+
2001-05-02 Dan Winship <danw@ximian.com>
* providers/imap/camel-imap-store.h: Clean this up a bit. Add a
diff --git a/camel/Makefile.am b/camel/Makefile.am
index 53f7befbfe..8145b960ae 100644
--- a/camel/Makefile.am
+++ b/camel/Makefile.am
@@ -24,6 +24,8 @@ libcamel_la_SOURCES = \
camel-cipher-context.c \
camel-data-wrapper.c \
camel-digest-folder.c \
+ camel-disco-folder.c \
+ camel-disco-store.c \
camel-exception.c \
camel-file-utils.c \
camel-filter-driver.c \
@@ -100,6 +102,9 @@ libcamelinclude_HEADERS = \
camel-cipher-context.h \
camel-data-wrapper.h \
camel-digest-folder.h \
+ camel-disco-diary.h \
+ camel-disco-folder.h \
+ camel-disco-store.h \
camel-exception-list.def \
camel-exception.h \
camel-file-utils.h \
diff --git a/camel/camel-disco-folder.c b/camel/camel-disco-folder.c
new file mode 100644
index 0000000000..bce6eaef06
--- /dev/null
+++ b/camel/camel-disco-folder.c
@@ -0,0 +1,243 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-disco-folder.c: abstract class for a disconnectable folder */
+
+/*
+ * Authors: Dan Winship <danw@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * 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 the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "camel-disco-diary.h"
+#include "camel-disco-folder.h"
+#include "camel-disco-store.h"
+#include "camel-exception.h"
+
+#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS (o)))
+#define CDF_CLASS(o) (CAMEL_DISCO_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS (o)))
+
+static CamelFolderClass *parent_class = NULL;
+
+static void disco_refresh_info (CamelFolder *folder, CamelException *ex);
+static void disco_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
+static void disco_expunge (CamelFolder *folder, CamelException *ex);
+
+static void disco_append_message (CamelFolder *folder, CamelMimeMessage *message,
+ const CamelMessageInfo *info, CamelException *ex);
+static void disco_copy_messages_to (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex);
+static void disco_move_messages_to (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex);
+
+
+static void
+camel_disco_folder_class_init (CamelDiscoFolderClass *camel_disco_folder_class)
+{
+ CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_disco_folder_class);
+
+ parent_class = CAMEL_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_folder_get_type ()));
+
+ /* virtual method overload */
+ camel_folder_class->refresh_info = disco_refresh_info;
+ camel_folder_class->sync = disco_sync;
+ camel_folder_class->expunge = disco_expunge;
+
+ camel_folder_class->append_message = disco_append_message;
+ camel_folder_class->copy_messages_to = disco_copy_messages_to;
+ camel_folder_class->move_messages_to = disco_move_messages_to;
+}
+
+CamelType
+camel_disco_folder_get_type (void)
+{
+ static CamelType camel_disco_folder_type = CAMEL_INVALID_TYPE;
+
+ if (camel_disco_folder_type == CAMEL_INVALID_TYPE) {
+ camel_disco_folder_type = camel_type_register (
+ CAMEL_FOLDER_TYPE, "CamelDiscoFolder",
+ sizeof (CamelDiscoFolder),
+ sizeof (CamelDiscoFolderClass),
+ (CamelObjectClassInitFunc) camel_disco_folder_class_init,
+ NULL, NULL, NULL);
+ }
+
+ return camel_disco_folder_type;
+}
+
+
+static void
+disco_refresh_info (CamelFolder *folder, CamelException *ex)
+{
+ if (camel_disco_store_status (CAMEL_DISCO_STORE (folder->parent_store)) != CAMEL_DISCO_STORE_ONLINE)
+ return;
+ CDF_CLASS (folder)->refresh_info_online (folder, ex);
+}
+
+static void
+disco_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
+{
+ if (expunge) {
+ disco_expunge (folder, ex);
+ if (camel_exception_is_set (ex))
+ return;
+ }
+
+ switch (camel_disco_store_status (CAMEL_DISCO_STORE (folder->parent_store))) {
+ case CAMEL_DISCO_STORE_ONLINE:
+ CDF_CLASS (folder)->sync_online (folder, ex);
+ break;
+
+ case CAMEL_DISCO_STORE_OFFLINE:
+ CDF_CLASS (folder)->sync_offline (folder, ex);
+ break;
+ }
+}
+
+static void
+disco_expunge_uids (CamelFolder *folder, GPtrArray *uids, CamelException *ex)
+{
+ CamelDiscoStore *disco = CAMEL_DISCO_STORE (folder->parent_store);
+
+ if (uids->len == 0)
+ return;
+
+ switch (camel_disco_store_status (disco)) {
+ case CAMEL_DISCO_STORE_ONLINE:
+ CDF_CLASS (folder)->expunge_uids_online (folder, uids, ex);
+ break;
+
+ case CAMEL_DISCO_STORE_OFFLINE:
+ CDF_CLASS (folder)->expunge_uids_offline (folder, uids, ex);
+#ifdef NOTYET
+ if (!camel_exception_is_set (ex))
+ camel_disco_diary_log (disco->diary, CAMEL_DISCO_DIARY_FOLDER_EXPUNGE, folder, uids);
+#endif
+ break;
+ }
+}
+
+static void
+disco_expunge (CamelFolder *folder, CamelException *ex)
+{
+ GPtrArray *uids;
+ int i, count;
+ CamelMessageInfo *info;
+
+ uids = g_ptr_array_new ();
+ count = camel_folder_summary_count (folder->summary);
+ for (i = 0; i < count; i++) {
+ info = camel_folder_summary_index (folder->summary, i);
+ if (info->flags & CAMEL_MESSAGE_DELETED)
+ g_ptr_array_add (uids, g_strdup (camel_message_info_uid (info)));
+ camel_folder_summary_info_free (folder->summary, info);
+ }
+
+ disco_expunge_uids (folder, uids, ex);
+
+ for (i = 0; i < uids->len; i++)
+ g_free (uids->pdata[i]);
+ g_ptr_array_free (uids, TRUE);
+}
+
+static void
+disco_append_message (CamelFolder *folder, CamelMimeMessage *message,
+ const CamelMessageInfo *info, CamelException *ex)
+{
+ CamelDiscoStore *disco = CAMEL_DISCO_STORE (folder->parent_store);
+ char *uid;
+
+ switch (camel_disco_store_status (disco)) {
+ case CAMEL_DISCO_STORE_ONLINE:
+ uid = CDF_CLASS (folder)->append_online (folder, message, info, ex);
+ break;
+
+ case CAMEL_DISCO_STORE_OFFLINE:
+ uid = CDF_CLASS (folder)->append_offline (folder, message, info, ex);
+#ifdef NOTYET
+ if (uid)
+ camel_disco_diary_log (disco->diary, CAMEL_DISCO_DIARY_FOLDER_APPEND, folder, uid);
+#endif
+ break;
+ }
+ g_free (uid);
+}
+
+static void
+disco_copy_messages_to (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex)
+{
+ CamelDiscoStore *disco = CAMEL_DISCO_STORE (source->parent_store);
+
+ switch (camel_disco_store_status (disco)) {
+ case CAMEL_DISCO_STORE_ONLINE:
+ CDF_CLASS (source)->copy_online (source, uids, destination, ex);
+ break;
+
+ case CAMEL_DISCO_STORE_OFFLINE:
+ CDF_CLASS (source)->copy_offline (source, uids, destination, ex);
+#ifdef NOTYET
+ if (!camel_exception_is_set (ex))
+ camel_disco_diary_log (disco->diary, CAMEL_DISCO_DIARY_FOLDER_COPY, source, destination, uids);
+#endif
+ break;
+ }
+}
+
+static void
+disco_move_messages_to (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex)
+{
+ CamelDiscoStore *disco = CAMEL_DISCO_STORE (source->parent_store);
+
+ switch (camel_disco_store_status (disco)) {
+ case CAMEL_DISCO_STORE_ONLINE:
+ CDF_CLASS (source)->move_online (source, uids, destination, ex);
+ break;
+
+ case CAMEL_DISCO_STORE_OFFLINE:
+ CDF_CLASS (source)->move_offline (source, uids, destination, ex);
+#ifdef NOTYET
+ if (!camel_exception_is_set (ex))
+ camel_disco_diary_log (disco->diary, CAMEL_DISCO_DIARY_FOLDER_MOVE, source, destination, uids);
+#endif
+ break;
+ }
+}
+
+
+/**
+ * camel_disco_folder_expunge_uids:
+ * @folder: a (disconnectable) folder
+ * @uids: array of UIDs to expunge
+ * @ex: a CamelException
+ *
+ * This expunges the messages in @uids from @folder. It should take
+ * whatever steps are needed to avoid expunging any other messages,
+ * although in some cases it may not be possible to avoid expunging
+ * messages that are marked deleted by another client at the same time
+ * as the expunge_uids call is running.
+ **/
+void
+camel_disco_folder_expunge_uids (CamelFolder *folder, GPtrArray *uids,
+ CamelException *ex)
+{
+ disco_expunge_uids (folder, uids, ex);
+}
diff --git a/camel/camel-disco-folder.h b/camel/camel-disco-folder.h
new file mode 100644
index 0000000000..23e9d24923
--- /dev/null
+++ b/camel/camel-disco-folder.h
@@ -0,0 +1,94 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * camel-disco-folder.h: Abstract class for a disconnectable folder
+ *
+ * Authors: Dan Winship <danw@ximian.com>
+ *
+ * Copyright 2001 Ximian, Inc.
+ *
+ * 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 the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef CAMEL_DISCO_FOLDER_H
+#define CAMEL_DISCO_FOLDER_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus }*/
+
+#include "camel-folder.h"
+
+#define CAMEL_DISCO_FOLDER_TYPE (camel_disco_folder_get_type ())
+#define CAMEL_DISCO_FOLDER(obj) (CAMEL_CHECK_CAST((obj), CAMEL_DISCO_FOLDER_TYPE, CamelDiscoFolder))
+#define CAMEL_DISCO_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_DISCO_FOLDER_TYPE, CamelDiscoFolderClass))
+#define CAMEL_IS_DISCO_FOLDER(o) (CAMEL_CHECK_TYPE((o), CAMEL_DISCO_FOLDER_TYPE))
+
+struct _CamelDiscoFolder {
+ CamelFolder parent_object;
+
+};
+
+typedef struct {
+ CamelFolderClass parent_class;
+
+ void (*refresh_info_online) (CamelFolder *folder, CamelException *ex);
+
+ void (*sync_online) (CamelFolder *folder, CamelException *ex);
+ void (*sync_offline) (CamelFolder *folder, CamelException *ex);
+
+ void (*expunge_uids_online) (CamelFolder *folder, GPtrArray *uids,
+ CamelException *ex);
+ void (*expunge_uids_offline) (CamelFolder *folder, GPtrArray *uids,
+ CamelException *ex);
+
+ char * (*append_online) (CamelFolder *folder,
+ CamelMimeMessage *message,
+ const CamelMessageInfo *info,
+ CamelException *ex);
+ char * (*append_offline) (CamelFolder *folder,
+ CamelMimeMessage *message,
+ const CamelMessageInfo *info,
+ CamelException *ex);
+
+ void (*copy_online) (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex);
+ void (*copy_offline) (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex);
+
+ void (*move_online) (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex);
+ void (*move_offline) (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex);
+
+ void (*update_uid) (CamelFolder *folder, const char *old_uid,
+ const char *new_uid);
+} CamelDiscoFolderClass;
+
+
+/* public methods */
+void camel_disco_folder_expunge_uids (CamelFolder *folder, GPtrArray *uids,
+ CamelException *ex);
+
+
+/* Standard Camel function */
+CamelType camel_disco_folder_get_type (void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CAMEL_DISCO_FOLDER_H */
diff --git a/camel/camel-disco-store.c b/camel/camel-disco-store.c
new file mode 100644
index 0000000000..10d3ae78b3
--- /dev/null
+++ b/camel/camel-disco-store.c
@@ -0,0 +1,194 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-disco-store.c: abstract class for a disconnectable remote store */
+
+/*
+ * Authors: Dan Winship <danw@ximian.com>
+ *
+ * Copyright 2001 Ximian, Inc.
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "camel-disco-store.h"
+#include "camel-exception.h"
+
+#define CDS_CLASS(o) (CAMEL_DISCO_STORE_CLASS (CAMEL_OBJECT_GET_CLASS (o)))
+
+static CamelRemoteStoreClass *remote_store_class = NULL;
+
+static gboolean disco_connect (CamelService *service, CamelException *ex);
+static gboolean disco_disconnect (CamelService *service, gboolean clean, CamelException *ex);
+static CamelFolder *disco_get_folder (CamelStore *store, const char *name,
+ guint32 flags, CamelException *ex);
+static CamelFolderInfo *disco_get_folder_info (CamelStore *store,
+ const char *top, guint32 flags,
+ CamelException *ex);
+
+static void
+camel_disco_store_class_init (CamelDiscoStoreClass *camel_disco_store_class)
+{
+ CamelServiceClass *camel_service_class =
+ CAMEL_SERVICE_CLASS (camel_disco_store_class);
+ CamelStoreClass *camel_store_class =
+ CAMEL_STORE_CLASS (camel_disco_store_class);
+
+ remote_store_class = CAMEL_REMOTE_STORE_CLASS (camel_type_get_global_classfuncs (camel_remote_store_get_type ()));
+
+ /* virtual method overload */
+ camel_service_class->connect = disco_connect;
+ camel_service_class->disconnect = disco_disconnect;
+
+ camel_store_class->get_folder = disco_get_folder;
+ camel_store_class->get_folder_info = disco_get_folder_info;
+}
+
+static void
+camel_disco_store_init (CamelDiscoStore *store)
+{
+ /* Hack */
+ if (getenv ("CAMEL_OFFLINE"))
+ store->status = CAMEL_DISCO_STORE_OFFLINE;
+ else
+ store->status = CAMEL_DISCO_STORE_ONLINE;
+}
+
+CamelType
+camel_disco_store_get_type (void)
+{
+ static CamelType camel_disco_store_type = CAMEL_INVALID_TYPE;
+
+ if (camel_disco_store_type == CAMEL_INVALID_TYPE) {
+ camel_disco_store_type = camel_type_register (
+ CAMEL_REMOTE_STORE_TYPE, "CamelDiscoStore",
+ sizeof (CamelDiscoStore),
+ sizeof (CamelDiscoStoreClass),
+ (CamelObjectClassInitFunc) camel_disco_store_class_init,
+ NULL,
+ (CamelObjectInitFunc) camel_disco_store_init,
+ NULL);
+ }
+
+ return camel_disco_store_type;
+}
+
+static gboolean
+disco_connect (CamelService *service, CamelException *ex)
+{
+ CamelDiscoStore *store = CAMEL_DISCO_STORE (service);
+
+ if (!CAMEL_SERVICE_CLASS (remote_store_class)->connect (service, ex))
+ return FALSE;
+
+ switch (camel_disco_store_status (store)) {
+ case CAMEL_DISCO_STORE_ONLINE:
+ return CDS_CLASS (service)->connect_online (service, ex);
+
+ case CAMEL_DISCO_STORE_OFFLINE:
+ return CDS_CLASS (service)->connect_offline (service, ex);
+ }
+
+ /* Not reached */
+ return TRUE;
+}
+
+static gboolean
+disco_disconnect (CamelService *service, gboolean clean, CamelException *ex)
+{
+ CamelDiscoStore *store = CAMEL_DISCO_STORE (service);
+
+ switch (camel_disco_store_status (store)) {
+ case CAMEL_DISCO_STORE_ONLINE:
+ if (!CDS_CLASS (service)->disconnect_online (service, clean, ex))
+ return FALSE;
+ break;
+
+ case CAMEL_DISCO_STORE_OFFLINE:
+ if (!CDS_CLASS (service)->disconnect_offline (service, clean, ex))
+ return FALSE;
+ break;
+ }
+
+ return CAMEL_SERVICE_CLASS (remote_store_class)->disconnect (service, clean, ex);
+}
+
+static CamelFolder *
+disco_get_folder (CamelStore *store, const char *name,
+ guint32 flags, CamelException *ex)
+{
+ CamelDiscoStore *disco_store = CAMEL_DISCO_STORE (store);
+
+ switch (camel_disco_store_status (disco_store)) {
+ case CAMEL_DISCO_STORE_ONLINE:
+ return CDS_CLASS (store)->get_folder_online (store, name, flags, ex);
+
+ case CAMEL_DISCO_STORE_OFFLINE:
+ return CDS_CLASS (store)->get_folder_offline (store, name, flags, ex);
+ }
+
+ /* Not reached */
+ return NULL;
+}
+
+static CamelFolderInfo *
+disco_get_folder_info (CamelStore *store, const char *top,
+ guint32 flags, CamelException *ex)
+{
+ CamelDiscoStore *disco_store = CAMEL_DISCO_STORE (store);
+
+ switch (camel_disco_store_status (disco_store)) {
+ case CAMEL_DISCO_STORE_ONLINE:
+ return CDS_CLASS (store)->get_folder_info_online (store, top, flags, ex);
+
+ case CAMEL_DISCO_STORE_OFFLINE:
+ /* Can't edit subscriptions while offline */
+ if ((store->flags & CAMEL_STORE_SUBSCRIPTIONS) &&
+ !(flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED)) {
+ camel_disco_store_check_online (disco_store, ex);
+ return NULL;
+ }
+
+ return CDS_CLASS (store)->get_folder_info_offline (store, top, flags, ex);
+ }
+
+ /* Not reached */
+ return NULL;
+}
+
+
+CamelDiscoStoreStatus
+camel_disco_store_status (CamelDiscoStore *store)
+{
+ g_return_val_if_fail (CAMEL_IS_DISCO_STORE (store), CAMEL_DISCO_STORE_ONLINE);
+
+ return store->status;
+}
+
+gboolean
+camel_disco_store_check_online (CamelDiscoStore *store, CamelException *ex)
+{
+ if (camel_disco_store_status (store) != CAMEL_DISCO_STORE_ONLINE) {
+ camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+ _("You must be working online to "
+ "complete this operation"));
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/camel/camel-disco-store.h b/camel/camel-disco-store.h
new file mode 100644
index 0000000000..3bba4e8a2b
--- /dev/null
+++ b/camel/camel-disco-store.h
@@ -0,0 +1,105 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-disco-store.h: abstruct class for a disconnectable store */
+
+/*
+ * Authors: Dan Winship <danw@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * 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 the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+
+#ifndef CAMEL_DISCO_STORE_H
+#define CAMEL_DISCO_STORE_H 1
+
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus }*/
+
+#include "camel-remote-store.h"
+
+#define CAMEL_DISCO_STORE_TYPE (camel_disco_store_get_type ())
+#define CAMEL_DISCO_STORE(obj) (CAMEL_CHECK_CAST((obj), CAMEL_DISCO_STORE_TYPE, CamelDiscoStore))
+#define CAMEL_DISCO_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_DISCO_STORE_TYPE, CamelDiscoStoreClass))
+#define CAMEL_IS_DISCO_STORE(o) (CAMEL_CHECK_TYPE((o), CAMEL_DISCO_STORE_TYPE))
+
+typedef enum {
+ CAMEL_DISCO_STORE_ONLINE,
+ CAMEL_DISCO_STORE_OFFLINE,
+#ifdef NOTYET
+ CAMEL_DISCO_STORE_RESYNCING
+#endif
+} CamelDiscoStoreStatus;
+
+struct _CamelDiscoStore {
+ CamelRemoteStore parent_object;
+
+ CamelDiscoStoreStatus status;
+ CamelDiscoDiary *diary;
+};
+
+
+typedef struct {
+ CamelRemoteStoreClass parent_class;
+
+ gboolean (*connect_online) (CamelService *,
+ CamelException *);
+ gboolean (*connect_offline) (CamelService *,
+ CamelException *);
+
+ gboolean (*disconnect_online) (CamelService *, gboolean,
+ CamelException *);
+ gboolean (*disconnect_offline) (CamelService *, gboolean,
+ CamelException *);
+
+ CamelFolder * (*get_folder_online) (CamelStore *store,
+ const char *name,
+ guint32 flags,
+ CamelException *ex);
+ CamelFolder * (*get_folder_offline) (CamelStore *store,
+ const char *name,
+ guint32 flags,
+ CamelException *ex);
+
+ CamelFolderInfo * (*get_folder_info_online) (CamelStore *store,
+ const char *top,
+ guint32 flags,
+ CamelException *ex);
+ CamelFolderInfo * (*get_folder_info_offline) (CamelStore *store,
+ const char *top,
+ guint32 flags,
+ CamelException *ex);
+
+} CamelDiscoStoreClass;
+
+
+/* Standard Camel function */
+CamelType camel_disco_store_get_type (void);
+
+/* Public methods */
+CamelDiscoStoreStatus camel_disco_store_status (CamelDiscoStore *store);
+
+/* Convenience functions */
+gboolean camel_disco_store_check_online (CamelDiscoStore *store, CamelException *ex);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CAMEL_DISCO_STORE_H */
diff --git a/camel/camel-store.c b/camel/camel-store.c
index 3314b710d8..3418bd9a56 100644
--- a/camel/camel-store.c
+++ b/camel/camel-store.c
@@ -60,9 +60,7 @@ static void rename_folder (CamelStore *store, const char *old_name,
static void store_sync (CamelStore *store, CamelException *ex);
static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top,
- gboolean fast, gboolean recursive,
- gboolean subscribed_only,
- CamelException *ex);
+ guint32 flags, CamelException *ex);
static void free_folder_info (CamelStore *store, CamelFolderInfo *tree);
static gboolean folder_subscribed (CamelStore *store, const char *folder_name);
@@ -471,9 +469,7 @@ camel_store_sync (CamelStore *store, CamelException *ex)
static CamelFolderInfo *
get_folder_info (CamelStore *store, const char *top,
- gboolean fast, gboolean recursive,
- gboolean subscribed_only,
- CamelException *ex)
+ guint32 flags, CamelException *ex)
{
g_warning ("CamelStore::get_folder_info not implemented for `%s'",
camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store)));
@@ -484,36 +480,37 @@ get_folder_info (CamelStore *store, const char *top,
* camel_store_get_folder_info:
* @store: a CamelStore
* @top: the name of the folder to start from
- * @fast: whether or not to do a "fast" scan.
- * @recursive: whether to include information for subfolders
+ * @flags: various CAMEL_STORE_FOLDER_INFO_* flags to control behavior
* @ex: a CamelException
*
* This fetches information about the folder structure of @store,
* starting with @top, and returns a tree of CamelFolderInfo
- * structures. If @fast is %TRUE, the message_count or
- * unread_message_count fields of some or all of the structures may be
- * set to -1, if the store cannot determine that information quickly.
- * If @recursive is %TRUE, the returned tree will include all levels of
- * hierarchy below @top. If it is %FALSE, it will only include the
- * immediate subfolders of @top.
- *
+ * structures. If @flags includes %CAMEL_STORE_FOLDER_INFO_SUBSCRIBED,
+ * only subscribed folders will be listed. (This flag can only be used
+ * for stores that support subscriptions.) If @flags includes
+ * %CAMEL_STORE_FOLDER_INFO_RECURSIVE, the returned tree will include
+ * all levels of hierarchy below @top. If not, it will only include
+ * the immediate subfolders of @top. If @flags includes
+ * %CAMEL_STORE_FOLDER_INFO_FAST, the unread_message_count fields of
+ * some or all of the structures may be set to -1, if the store cannot
+ * determine that information quickly.
+ *
* Return value: a CamelFolderInfo tree, which must be freed with
* camel_store_free_folder_info.
**/
CamelFolderInfo *
camel_store_get_folder_info (CamelStore *store, const char *top,
- gboolean fast, gboolean recursive,
- gboolean subscribed_only,
- CamelException *ex)
+ guint32 flags, CamelException *ex)
{
CamelFolderInfo *ret;
g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
+ g_return_val_if_fail ((store->flags & CAMEL_STORE_SUBSCRIPTIONS) ||
+ !(flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED),
+ NULL);
CAMEL_STORE_LOCK(store, folder_lock);
-
- ret = CS_CLASS (store)->get_folder_info (store, top, fast, recursive, subscribed_only, ex);
-
+ ret = CS_CLASS (store)->get_folder_info (store, top, flags, ex);
CAMEL_STORE_UNLOCK(store, folder_lock);
return ret;
diff --git a/camel/camel-store.h b/camel/camel-store.h
index 51d6570348..d81f08e914 100644
--- a/camel/camel-store.h
+++ b/camel/camel-store.h
@@ -72,6 +72,10 @@ struct _CamelStore
#define CAMEL_STORE_FOLDER_BODY_INDEX (1<<1)
#define CAMEL_STORE_FOLDER_PRIVATE (1<<2) /* a private folder, that shouldn't show up in unmatched/folder info's, etc */
+#define CAMEL_STORE_FOLDER_INFO_FAST (1 << 0)
+#define CAMEL_STORE_FOLDER_INFO_RECURSIVE (1 << 1)
+#define CAMEL_STORE_FOLDER_INFO_SUBSCRIBED (1 << 2)
+
typedef struct {
CamelServiceClass parent_class;
@@ -104,12 +108,9 @@ typedef struct {
void (*sync) (CamelStore *store,
CamelException *ex);
- /* this should take flags instead, so its more futureproof */
CamelFolderInfo *(*get_folder_info) (CamelStore *store,
const char *top,
- gboolean fast,
- gboolean recursive,
- gboolean subscribed_only,
+ guint32 flags,
CamelException *ex);
void (*free_folder_info) (CamelStore *store,
CamelFolderInfo *fi);
@@ -155,9 +156,7 @@ void camel_store_sync (CamelStore *store,
CamelFolderInfo *camel_store_get_folder_info (CamelStore *store,
const char *top,
- gboolean fast,
- gboolean recursive,
- gboolean subscribed_only,
+ guint32 flags,
CamelException *ex);
void camel_store_free_folder_info (CamelStore *store,
CamelFolderInfo *fi);
diff --git a/camel/camel-types.h b/camel/camel-types.h
index 727c0a266c..dbcce56550 100644
--- a/camel/camel-types.h
+++ b/camel/camel-types.h
@@ -29,6 +29,8 @@ extern "C" {
typedef struct _CamelAddress CamelAddress;
typedef struct _header_content_type CamelContentType;
+typedef struct _CamelDiscoFolder CamelDiscoFolder;
+typedef struct _CamelDiscoStore CamelDiscoStore;
typedef struct _CamelDataWrapper CamelDataWrapper;
typedef struct _CamelException CamelException;
typedef struct _CamelFolder CamelFolder;
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
index 4ee65371fd..d0828ccac9 100644
--- a/camel/providers/imap/camel-imap-folder.c
+++ b/camel/providers/imap/camel-imap-folder.c
@@ -2,9 +2,11 @@
/* camel-imap-folder.c: class for an imap folder */
/*
- * Authors: Jeffrey Stedfast <fejj@helixcode.com>
+ * Authors:
+ * Dan Winship <danw@ximian.com>
+ * Jeffrey Stedfast <fejj@ximian.com>
*
- * Copyright (C) 2000 Helix Code, Inc.
+ * Copyright (C) 2000, 2001 Ximian, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -60,26 +62,29 @@
#include "camel-multipart.h"
#include "camel-operation.h"
-#define d(x) x
-
#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(o)))
-
-static CamelFolderClass *parent_class = NULL;
+static CamelDiscoFolderClass *disco_folder_class = NULL;
static void imap_finalize (CamelObject *object);
static void imap_rescan (CamelFolder *folder, int exists, CamelException *ex);
static void imap_refresh_info (CamelFolder *folder, CamelException *ex);
-static void imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
+static void imap_sync_online (CamelFolder *folder, CamelException *ex);
+static void imap_sync_offline (CamelFolder *folder, CamelException *ex);
static const char *imap_get_full_name (CamelFolder *folder);
-static void imap_expunge (CamelFolder *folder, CamelException *ex);
+static void imap_expunge_uids_online (CamelFolder *folder, GPtrArray *uids, CamelException *ex);
+static void imap_expunge_uids_offline (CamelFolder *folder, GPtrArray *uids, CamelException *ex);
/* message manipulation */
static CamelMimeMessage *imap_get_message (CamelFolder *folder, const gchar *uid,
CamelException *ex);
-static void imap_append_message (CamelFolder *folder, CamelMimeMessage *message,
+static char *imap_append_online (CamelFolder *folder, CamelMimeMessage *message,
const CamelMessageInfo *info, CamelException *ex);
-static void imap_copy_messages_to (CamelFolder *source, GPtrArray *uids,
- CamelFolder *destination, CamelException *ex);
+static char *imap_append_offline (CamelFolder *folder, CamelMimeMessage *message,
+ const CamelMessageInfo *info, CamelException *ex);
+static void imap_copy_online (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex);
+static void imap_copy_offline (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex);
static void imap_move_messages_to (CamelFolder *source, GPtrArray *uids,
CamelFolder *destination, CamelException *ex);
@@ -93,24 +98,26 @@ static void
camel_imap_folder_class_init (CamelImapFolderClass *camel_imap_folder_class)
{
CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_imap_folder_class);
+ CamelDiscoFolderClass *camel_disco_folder_class = CAMEL_DISCO_FOLDER_CLASS (camel_imap_folder_class);
+
+ disco_folder_class = CAMEL_DISCO_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_disco_folder_get_type ()));
- parent_class = CAMEL_FOLDER_CLASS(camel_type_get_global_classfuncs (camel_folder_get_type ()));
-
- /* virtual method definition */
-
/* virtual method overload */
- camel_folder_class->refresh_info = imap_refresh_info;
- camel_folder_class->sync = imap_sync;
- camel_folder_class->expunge = imap_expunge;
camel_folder_class->get_full_name = imap_get_full_name;
-
camel_folder_class->get_message = imap_get_message;
- camel_folder_class->append_message = imap_append_message;
- camel_folder_class->copy_messages_to = imap_copy_messages_to;
camel_folder_class->move_messages_to = imap_move_messages_to;
-
camel_folder_class->search_by_expression = imap_search_by_expression;
camel_folder_class->search_free = imap_search_free;
+
+ camel_disco_folder_class->refresh_info_online = imap_refresh_info;
+ camel_disco_folder_class->sync_online = imap_sync_online;
+ camel_disco_folder_class->sync_offline = imap_sync_offline;
+ camel_disco_folder_class->expunge_uids_online = imap_expunge_uids_online;
+ camel_disco_folder_class->expunge_uids_offline = imap_expunge_uids_offline;
+ camel_disco_folder_class->append_online = imap_append_online;
+ camel_disco_folder_class->append_offline = imap_append_offline;
+ camel_disco_folder_class->copy_online = imap_copy_online;
+ camel_disco_folder_class->copy_offline = imap_copy_offline;
}
static void
@@ -136,7 +143,7 @@ camel_imap_folder_get_type (void)
if (camel_imap_folder_type == CAMEL_INVALID_TYPE) {
camel_imap_folder_type =
- camel_type_register (CAMEL_FOLDER_TYPE, "CamelImapFolder",
+ camel_type_register (CAMEL_DISCO_FOLDER_TYPE, "CamelImapFolder",
sizeof (CamelImapFolder),
sizeof (CamelImapFolderClass),
(CamelObjectClassInitFunc) camel_imap_folder_class_init,
@@ -150,15 +157,27 @@ camel_imap_folder_get_type (void)
CamelFolder *
camel_imap_folder_new (CamelStore *parent, const char *folder_name,
- const char *short_name, const char *folder_dir,
- CamelException *ex)
+ const char *folder_dir, CamelException *ex)
{
CamelImapStore *imap_store = CAMEL_IMAP_STORE (parent);
- CamelFolder *folder = CAMEL_FOLDER (camel_object_new (camel_imap_folder_get_type ()));
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- CamelImapResponse *response;
+ CamelFolder *folder;
+ CamelImapFolder *imap_folder;
+ const char *short_name;
char *summary_file;
+ if (camel_mkdir_hier (folder_dir, S_IRWXU) != 0) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Could not create directory %s: %s"),
+ folder_dir, g_strerror (errno));
+ return NULL;
+ }
+
+ folder = CAMEL_FOLDER (camel_object_new (camel_imap_folder_get_type ()));
+ short_name = strrchr (folder_name, imap_store->dir_sep);
+ if (short_name)
+ short_name++;
+ else
+ short_name = folder_name;
camel_folder_construct (folder, parent, folder_name, short_name);
summary_file = g_strdup_printf ("%s/summary", folder_dir);
@@ -172,22 +191,13 @@ camel_imap_folder_new (CamelStore *parent, const char *folder_name,
return NULL;
}
+ imap_folder = CAMEL_IMAP_FOLDER (folder);
imap_folder->cache = camel_imap_message_cache_new (folder_dir, folder->summary, ex);
if (!imap_folder->cache) {
camel_object_unref (CAMEL_OBJECT (folder));
return NULL;
}
- if (camel_imap_store_check_online (imap_store, NULL)) {
- response = camel_imap_command (imap_store, folder, ex, NULL);
- if (response)
- camel_imap_response_free (imap_store, response);
- else {
- camel_object_unref (CAMEL_OBJECT (folder));
- return NULL;
- }
- }
-
return folder;
}
@@ -321,7 +331,7 @@ imap_finalize (CamelObject *object)
static void
imap_refresh_info (CamelFolder *folder, CamelException *ex)
{
- if (!camel_imap_store_check_online (CAMEL_IMAP_STORE (folder->parent_store), NULL))
+ if (camel_disco_store_status (CAMEL_DISCO_STORE (folder->parent_store)) == CAMEL_DISCO_STORE_OFFLINE)
return;
CAMEL_IMAP_STORE_LOCK (folder->parent_store, command_lock);
@@ -499,7 +509,13 @@ get_matching (CamelFolder *folder, guint32 flags, guint32 mask, char **set)
}
static void
-imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
+imap_sync_offline (CamelFolder *folder, CamelException *ex)
+{
+ camel_folder_summary_save (folder->summary);
+}
+
+static void
+imap_sync_online (CamelFolder *folder, CamelException *ex)
{
CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
CamelImapResponse *response = NULL;
@@ -508,43 +524,13 @@ imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
char *set, *flaglist;
int i, j, max;
- if (!camel_imap_store_check_online (store, NULL))
- return;
-
- max = camel_folder_summary_count (folder->summary);
-
CAMEL_IMAP_STORE_LOCK (store, command_lock);
- /* If we're expunging then we don't need to be precise about the
- * flags of deleted messages. Just add \Deleted to anything that
- * should have it.
- */
- if (expunge && (matches = get_matching (folder, CAMEL_MESSAGE_DELETED,
- CAMEL_MESSAGE_DELETED, &set))) {
- for (i = 0; i < matches->len; i++) {
- info = matches->pdata[i];
- info->flags &= ~CAMEL_MESSAGE_FOLDER_FLAGGED;
- camel_folder_summary_info_free (folder->summary, info);
- }
- g_ptr_array_free (matches, TRUE);
- camel_folder_summary_touch (folder->summary);
-
- response = camel_imap_command (store, folder, ex,
- "UID STORE %s +FLAGS.SILENT \\Deleted",
- set);
- g_free (set);
- if (response)
- camel_imap_response_free (store, response);
- if (camel_exception_is_set (ex)) {
- CAMEL_IMAP_STORE_UNLOCK (store, command_lock);
- return;
- }
- }
-
- /* OK, now, find a message with changed flags, find all of the
- * other messages like it, sync them as a group, mark them as
+ /* Find a message with changed flags, find all of the other
+ * messages like it, sync them as a group, mark them as
* updated, and continue.
*/
+ max = camel_folder_summary_count (folder->summary);
for (i = 0; i < max; i++) {
info = camel_folder_summary_index (folder->summary, i);
if (!info)
@@ -587,32 +573,55 @@ imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
}
}
- if (expunge) {
- response = camel_imap_command (store, folder, ex, "EXPUNGE");
- camel_imap_response_free (store, response);
- }
-
if (!response) {
- /* We didn't sync or expunge anything... Do a noop so
- * the server gets a chance to tell us any news it has.
+ /* We didn't sync anything... Do a noop so the server
+ * gets a chance to tell us any news it has.
*/
response = camel_imap_command (store, folder, ex, "NOOP");
camel_imap_response_free (store, response);
}
- camel_folder_summary_save (folder->summary);
+ /* Save the summary */
+ imap_sync_offline (folder, ex);
+
CAMEL_IMAP_STORE_UNLOCK (store, command_lock);
+}
- camel_operation_end(NULL);
+static void
+imap_expunge_uids_offline (CamelFolder *folder, GPtrArray *uids, CamelException *ex)
+{
+ /* Fail */
+ camel_disco_store_check_online (CAMEL_DISCO_STORE (folder->parent_store), ex);
}
static void
-imap_expunge (CamelFolder *folder, CamelException *ex)
+imap_expunge_uids_online (CamelFolder *folder, GPtrArray *uids, CamelException *ex)
{
- if (!camel_imap_store_check_online (CAMEL_IMAP_STORE (folder->parent_store), ex))
+ CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
+ CamelImapResponse *response;
+ char *set;
+
+ set = imap_uid_array_to_set (folder->summary, uids);
+ CAMEL_IMAP_STORE_LOCK (store, command_lock);
+ response = camel_imap_command (store, folder, ex,
+ "UID STORE %s +FLAGS.SILENT \\Deleted",
+ set);
+ if (response)
+ camel_imap_response_free (store, response);
+ if (camel_exception_is_set (ex)) {
+ CAMEL_IMAP_STORE_UNLOCK (store, command_lock);
+ g_free (set);
return;
+ }
- imap_sync (folder, TRUE, ex);
+ if (store->capabilities & IMAP_CAPABILITY_UIDPLUS) {
+ response = camel_imap_command (store, folder, ex,
+ "UID EXPUNGE %s", set);
+ } else
+ response = camel_imap_command (store, folder, ex, "EXPUNGE");
+ if (response)
+ camel_imap_response_free (store, response);
+ CAMEL_IMAP_STORE_UNLOCK (store, command_lock);
}
static const char *
@@ -634,20 +643,26 @@ imap_get_full_name (CamelFolder *folder)
return name;
}
-static void
-imap_append_message (CamelFolder *folder, CamelMimeMessage *message,
+static char *
+imap_append_offline (CamelFolder *folder, CamelMimeMessage *message,
const CamelMessageInfo *info, CamelException *ex)
{
+ /* Fail */
+ camel_disco_store_check_online (CAMEL_DISCO_STORE (folder->parent_store), ex);
+ return NULL;
+}
+
+static char *
+imap_append_online (CamelFolder *folder, CamelMimeMessage *message,
+ const CamelMessageInfo *info, CamelException *ex)
+{
CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
CamelImapResponse *response;
CamelStream *memstream;
CamelMimeFilter *crlf_filter;
CamelStreamFilter *streamfilter;
GByteArray *ba;
- char *flagstr, *result, *uid;
-
- if (!camel_imap_store_check_online (store, ex))
- return;
+ char *flagstr, *result, *uid = NULL;
/* create flag string param */
if (info && info->flags)
@@ -678,12 +693,12 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message,
if (!response) {
g_byte_array_free (ba, TRUE);
- return;
+ return NULL;
}
result = camel_imap_response_extract_continuation (store, response, ex);
if (!result) {
g_byte_array_free (ba, TRUE);
- return;
+ return NULL;
}
g_free (result);
@@ -692,7 +707,7 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message,
response = camel_imap_command_continuation (store, ex, ba->data);
g_byte_array_free (ba, TRUE);
if (!response)
- return;
+ return NULL;
if (store->capabilities & IMAP_CAPABILITY_UIDPLUS) {
uid = strstrcase (response->status, "[APPENDUID ");
@@ -707,15 +722,26 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message,
camel_imap_message_cache_insert_wrapper (
CAMEL_IMAP_FOLDER (folder)->cache,
uid, "", CAMEL_DATA_WRAPPER (message));
+ } else {
+ g_free (uid);
+ uid = NULL;
}
- g_free (uid);
}
}
camel_imap_response_free (store, response);
+ return uid;
}
static void
+imap_copy_offline (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex)
+{
+ /* Fail */
+ camel_disco_store_check_online (CAMEL_DISCO_STORE (source->parent_store), ex);
+}
+
+static void
handle_copyuid (CamelImapResponse *response, CamelFolder *source,
CamelFolder *destination)
{
@@ -769,18 +795,15 @@ handle_copyuid (CamelImapResponse *response, CamelFolder *source,
}
static void
-imap_copy_messages_to (CamelFolder *source, GPtrArray *uids,
- CamelFolder *destination, CamelException *ex)
+imap_copy_online (CamelFolder *source, GPtrArray *uids,
+ CamelFolder *destination, CamelException *ex)
{
CamelImapStore *store = CAMEL_IMAP_STORE (source->parent_store);
CamelImapResponse *response;
char *set;
- if (!camel_imap_store_check_online (store, ex))
- return;
-
/* Sync message flags if needed. */
- imap_sync (source, FALSE, ex);
+ imap_sync_online (source, ex);
if (camel_exception_is_set (ex))
return;
@@ -807,11 +830,11 @@ imap_move_messages_to (CamelFolder *source, GPtrArray *uids,
CamelFolder *destination, CamelException *ex)
{
int i;
-
- imap_copy_messages_to (source, uids, destination, ex);
+
+ CF_CLASS (disco_folder_class)->copy_messages_to (source, uids, destination, ex);
if (camel_exception_is_set (ex))
return;
-
+
for (i = 0; i < uids->len; i++)
camel_folder_delete_message (source, uids->pdata[i]);
}
@@ -822,7 +845,7 @@ imap_search_by_expression (CamelFolder *folder, const char *expression, CamelExc
CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
GPtrArray *matches, *summary;
- if (!camel_imap_store_check_online (CAMEL_IMAP_STORE (folder->parent_store), ex))
+ if (!camel_disco_store_check_online (CAMEL_DISCO_STORE (folder->parent_store), ex))
return NULL;
/* we could get around this by creating a new search object each time,
@@ -1015,7 +1038,7 @@ imap_get_message (CamelFolder *folder, const char *uid, CamelException *ex)
char *body, *found_uid;
int i;
- if (!camel_imap_store_check_online (store, NULL)) {
+ if (camel_disco_store_status (CAMEL_DISCO_STORE (store)) == CAMEL_DISCO_STORE_OFFLINE) {
camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
_("This message is not currently available"));
return NULL;
@@ -1212,6 +1235,8 @@ camel_imap_folder_changed (CamelFolder *folder, int exists,
"folder_changed", changes);
}
camel_folder_change_info_free (changes);
+
+ camel_folder_summary_save (folder->summary);
}
@@ -1235,9 +1260,10 @@ camel_imap_folder_fetch_data (CamelImapFolder *imap_folder, const char *uid,
return stream;
}
- if (!camel_imap_store_check_online (store, NULL)) {
+ if (camel_disco_store_status (CAMEL_DISCO_STORE (store)) == CAMEL_DISCO_STORE_OFFLINE) {
camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
_("This message is not currently available"));
+ CAMEL_IMAP_FOLDER_UNLOCK (imap_folder, cache_lock);
return NULL;
}
diff --git a/camel/providers/imap/camel-imap-folder.h b/camel/providers/imap/camel-imap-folder.h
index 6d969bf752..96b33c0400 100644
--- a/camel/providers/imap/camel-imap-folder.h
+++ b/camel/providers/imap/camel-imap-folder.h
@@ -1,11 +1,12 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-folder.h : Abstract class for an imap folder */
+/* camel-imap-folder.h: class for an imap folder */
/*
- * Author:
- * Jeffrey Stedfast <fejj@helixcode.com>
+ * Authors:
+ * Dan Winship <danw@ximian.com>
+ * Jeffrey Stedfast <fejj@ximian.com>
*
- * Copyright (C) 2000 Helix Code, Inc. (www.helixcode.com)
+ * Copyright (C) 2000, 2001 Ximian, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -34,7 +35,7 @@ extern "C" {
#endif /* __cplusplus }*/
#include "camel-imap-types.h"
-#include "camel-folder.h"
+#include "camel-disco-folder.h"
#include <camel/camel-folder-search.h>
#define CAMEL_IMAP_FOLDER_TYPE (camel_imap_folder_get_type ())
@@ -43,7 +44,7 @@ extern "C" {
#define CAMEL_IS_IMAP_FOLDER(o) (CAMEL_CHECK_TYPE((o), CAMEL_IMAP_FOLDER_TYPE))
struct _CamelImapFolder {
- CamelFolder parent_object;
+ CamelDiscoFolder parent_object;
struct _CamelImapFolderPrivate *priv;
@@ -53,7 +54,7 @@ struct _CamelImapFolder {
typedef struct {
- CamelFolderClass parent_class;
+ CamelDiscoFolderClass parent_class;
/* Virtual methods */
@@ -63,7 +64,6 @@ typedef struct {
/* public methods */
CamelFolder *camel_imap_folder_new (CamelStore *parent,
const char *folder_name,
- const char *short_name,
const char *folder_dir,
CamelException *ex);
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index 42c2f12cde..0a5c4425ac 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -57,23 +57,30 @@
/* Specified in RFC 2060 */
#define IMAP_PORT 143
-static CamelRemoteStoreClass *remote_store_class = NULL;
+static CamelDiscoStoreClass *disco_store_class = NULL;
static char imap_tag_prefix = 'A';
static void construct (CamelService *service, CamelSession *session,
CamelProvider *provider, CamelURL *url,
CamelException *ex);
-static gboolean imap_connect (CamelService *service, CamelException *ex);
-static gboolean imap_disconnect (CamelService *service, gboolean clean, CamelException *ex);
+static gboolean imap_connect_online (CamelService *service, CamelException *ex);
+static gboolean imap_connect_offline (CamelService *service, CamelException *ex);
+static gboolean imap_disconnect_online (CamelService *service, gboolean clean, CamelException *ex);
+static gboolean imap_disconnect_offline (CamelService *service, gboolean clean, CamelException *ex);
static GList *query_auth_types (CamelService *service, CamelException *ex);
static guint hash_folder_name (gconstpointer key);
static gint compare_folder_name (gconstpointer a, gconstpointer b);
-static CamelFolder *get_folder (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex);
+static CamelFolder *get_folder_online (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex);
+static CamelFolder *get_folder_offline (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex);
static CamelFolderInfo *create_folder (CamelStore *store, const char *parent_name, const char *folder_name, CamelException *ex);
-static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top,
- gboolean fast, gboolean recursive,
- gboolean subscribed_only,
- CamelException *ex);
+static CamelFolderInfo *get_folder_info_online (CamelStore *store,
+ const char *top,
+ guint32 flags,
+ CamelException *ex);
+static CamelFolderInfo *get_folder_info_offline (CamelStore *store,
+ const char *top,
+ guint32 flags,
+ CamelException *ex);
static gboolean folder_subscribed (CamelStore *store, const char *folder_name);
static void subscribe_folder (CamelStore *store, const char *folder_name,
CamelException *ex);
@@ -81,44 +88,43 @@ static void unsubscribe_folder (CamelStore *store, const char *folder_name,
CamelException *ex);
static void imap_keepalive (CamelRemoteStore *store);
-static gboolean imap_store_setup_online (CamelImapStore *store,
- CamelException *ex);
-static gboolean imap_store_setup_offline (CamelImapStore *store,
- CamelException *ex);
-
static void
camel_imap_store_class_init (CamelImapStoreClass *camel_imap_store_class)
{
- /* virtual method overload */
CamelServiceClass *camel_service_class =
CAMEL_SERVICE_CLASS (camel_imap_store_class);
CamelStoreClass *camel_store_class =
CAMEL_STORE_CLASS (camel_imap_store_class);
CamelRemoteStoreClass *camel_remote_store_class =
CAMEL_REMOTE_STORE_CLASS (camel_imap_store_class);
-
- remote_store_class = CAMEL_REMOTE_STORE_CLASS(camel_type_get_global_classfuncs
- (camel_remote_store_get_type ()));
-
+ CamelDiscoStoreClass *camel_disco_store_class =
+ CAMEL_DISCO_STORE_CLASS (camel_imap_store_class);
+
+ disco_store_class = CAMEL_DISCO_STORE_CLASS (camel_type_get_global_classfuncs (camel_disco_store_get_type ()));
+
/* virtual method overload */
camel_service_class->construct = construct;
camel_service_class->query_auth_types = query_auth_types;
- camel_service_class->connect = imap_connect;
- camel_service_class->disconnect = imap_disconnect;
-
+
camel_store_class->hash_folder_name = hash_folder_name;
camel_store_class->compare_folder_name = compare_folder_name;
- camel_store_class->get_folder = get_folder;
camel_store_class->create_folder = create_folder;
- camel_store_class->get_folder_info = get_folder_info;
camel_store_class->free_folder_info = camel_store_free_folder_info_full;
-
camel_store_class->folder_subscribed = folder_subscribed;
camel_store_class->subscribe_folder = subscribe_folder;
camel_store_class->unsubscribe_folder = unsubscribe_folder;
camel_remote_store_class->keepalive = imap_keepalive;
+
+ camel_disco_store_class->connect_online = imap_connect_online;
+ camel_disco_store_class->connect_offline = imap_connect_offline;
+ camel_disco_store_class->disconnect_online = imap_disconnect_online;
+ camel_disco_store_class->disconnect_offline = imap_disconnect_offline;
+ camel_disco_store_class->get_folder_online = get_folder_online;
+ camel_disco_store_class->get_folder_offline = get_folder_offline;
+ camel_disco_store_class->get_folder_info_online = get_folder_info_online;
+ camel_disco_store_class->get_folder_info_offline = get_folder_info_offline;
}
static gboolean
@@ -133,24 +139,14 @@ camel_imap_store_finalize (CamelObject *object)
{
CamelImapStore *imap_store = CAMEL_IMAP_STORE (object);
- if (imap_store->subscribed_folders) {
- g_hash_table_foreach_remove (imap_store->subscribed_folders,
- free_key, NULL);
- g_hash_table_destroy (imap_store->subscribed_folders);
- }
- if (imap_store->authtypes) {
- g_hash_table_foreach_remove (imap_store->authtypes,
- free_key, NULL);
- g_hash_table_destroy (imap_store->authtypes);
- }
- if (imap_store->namespace)
- g_free (imap_store->namespace);
+ /* This frees current_folder, folders, authtypes, and namespace. */
+ imap_disconnect_offline (CAMEL_SERVICE (object), FALSE, NULL);
+
if (imap_store->base_url)
g_free (imap_store->base_url);
if (imap_store->storage_path)
g_free (imap_store->storage_path);
- if (imap_store->current_folder)
- camel_object_unref (CAMEL_OBJECT (imap_store->current_folder));
+
#ifdef ENABLE_THREADS
e_mutex_destroy(imap_store->priv->command_lock);
#endif
@@ -188,7 +184,7 @@ camel_imap_store_get_type (void)
if (camel_imap_store_type == CAMEL_INVALID_TYPE) {
camel_imap_store_type =
- camel_type_register (CAMEL_REMOTE_STORE_TYPE, "CamelImapStore",
+ camel_type_register (CAMEL_DISCO_STORE_TYPE, "CamelImapStore",
sizeof (CamelImapStore),
sizeof (CamelImapStoreClass),
(CamelObjectClassInitFunc) camel_imap_store_class_init,
@@ -208,7 +204,7 @@ construct (CamelService *service, CamelSession *session,
CamelImapStore *imap_store = CAMEL_IMAP_STORE (service);
CamelStore *store = CAMEL_STORE (service);
- CAMEL_SERVICE_CLASS (remote_store_class)->construct (service, session, provider, url, ex);
+ CAMEL_SERVICE_CLASS (disco_store_class)->construct (service, session, provider, url, ex);
if (camel_exception_is_set (ex))
return;
@@ -216,6 +212,7 @@ construct (CamelService *service, CamelSession *session,
if (camel_exception_is_set (ex))
return;
+ /* FIXME */
imap_store->base_url = camel_url_to_string (service->url, (CAMEL_URL_HIDE_PASSWORD |
CAMEL_URL_HIDE_PARAMS |
CAMEL_URL_HIDE_AUTH));
@@ -233,6 +230,18 @@ construct (CamelService *service, CamelSession *session,
imap_store->parameters |= IMAP_PARAM_FILTER_INBOX;
}
+static void
+imap_set_server_level (CamelImapStore *store)
+{
+ if (store->capabilities & IMAP_CAPABILITY_IMAP4REV1) {
+ store->server_level = IMAP_LEVEL_IMAP4REV1;
+ store->capabilities |= IMAP_CAPABILITY_STATUS;
+ } else if (store->capabilities & IMAP_CAPABILITY_IMAP4)
+ store->server_level = IMAP_LEVEL_IMAP4;
+ else
+ store->server_level = IMAP_LEVEL_UNKNOWN;
+}
+
static struct {
const char *name;
guint32 flag;
@@ -257,9 +266,6 @@ connect_to_server (CamelService *service, CamelException *ex)
CAMEL_IMAP_STORE_ASSERT_LOCKED (store, command_lock);
- if (!CAMEL_SERVICE_CLASS (remote_store_class)->connect (service, ex))
- return FALSE;
-
store->command = 0;
/* Read the greeting, if any. FIXME: deal with PREAUTH */
@@ -299,13 +305,7 @@ connect_to_server (CamelService *service, CamelException *ex)
}
g_free (result);
- if (store->capabilities & IMAP_CAPABILITY_IMAP4REV1) {
- store->server_level = IMAP_LEVEL_IMAP4REV1;
- store->capabilities |= IMAP_CAPABILITY_STATUS;
- } else if (store->capabilities & IMAP_CAPABILITY_IMAP4)
- store->server_level = IMAP_LEVEL_IMAP4;
- else
- store->server_level = IMAP_LEVEL_UNKNOWN;
+ imap_set_server_level (store);
return TRUE;
}
@@ -326,7 +326,7 @@ query_auth_types (CamelService *service, CamelException *ex)
if (!connected)
return NULL;
- types = CAMEL_SERVICE_CLASS (remote_store_class)->query_auth_types (service, ex);
+ types = CAMEL_SERVICE_CLASS (disco_store_class)->query_auth_types (service, ex);
if (camel_exception_is_set (ex))
return types;
@@ -536,39 +536,25 @@ imap_auth_loop (CamelService *service, CamelException *ex)
return TRUE;
}
-static gboolean
-imap_connect (CamelService *service, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (service);
-
- if (camel_imap_store_check_online (store, NULL)) {
- CAMEL_IMAP_STORE_LOCK (store, command_lock);
- if (!connect_to_server (service, ex) ||
- !imap_auth_loop (service, ex) ||
- !imap_store_setup_online (store, ex)) {
- CAMEL_IMAP_STORE_UNLOCK (store, command_lock);
- camel_service_disconnect (service, TRUE, NULL);
- return FALSE;
- }
- CAMEL_IMAP_STORE_UNLOCK (store, command_lock);
- } else
- imap_store_setup_offline (store, ex);
-
- imap_store_refresh_folders (CAMEL_REMOTE_STORE (store), ex);
- return !camel_exception_is_set (ex);
-}
-
#define IMAP_STOREINFO_VERSION 1
static gboolean
-imap_store_setup_online (CamelImapStore *store, CamelException *ex)
+imap_connect_online (CamelService *service, CamelException *ex)
{
+ CamelImapStore *store = CAMEL_IMAP_STORE (service);
CamelImapResponse *response;
int i, flags, len;
char *result, *name, *path;
FILE *storeinfo;
- CAMEL_IMAP_STORE_ASSERT_LOCKED (store, command_lock);
+
+ CAMEL_IMAP_STORE_LOCK (store, command_lock);
+ if (!connect_to_server (service, ex) ||
+ !imap_auth_loop (service, ex)) {
+ CAMEL_IMAP_STORE_UNLOCK (store, command_lock);
+ camel_service_disconnect (service, TRUE, NULL);
+ return FALSE;
+ }
path = g_strdup_printf ("%s/storeinfo", store->storage_path);
storeinfo = fopen (path, "w");
@@ -585,16 +571,16 @@ imap_store_setup_online (CamelImapStore *store, CamelException *ex)
!(store->parameters & IMAP_PARAM_OVERRIDE_NAMESPACE)) {
response = camel_imap_command (store, NULL, ex, "NAMESPACE");
if (!response)
- return FALSE;
+ goto done;
result = camel_imap_response_extract (store, response, "NAMESPACE", ex);
if (!result)
- return FALSE;
-
+ goto done;
+
name = strstrcase (result, "NAMESPACE ((");
if (name) {
char *sep;
-
+
name += 12;
store->namespace = imap_parse_string (&name, &len);
if (name && *name++ == ' ') {
@@ -627,9 +613,8 @@ imap_store_setup_online (CamelImapStore *store, CamelException *ex)
"LIST \"\" %S",
store->namespace);
}
-
if (!response)
- return FALSE;
+ goto done;
result = camel_imap_response_extract (store, response, "LIST", NULL);
if (result) {
@@ -648,7 +633,7 @@ imap_store_setup_online (CamelImapStore *store, CamelException *ex)
/* Get subscribed folders */
response = camel_imap_command (store, NULL, ex, "LSUB \"\" \"*\"");
if (!response)
- return FALSE;
+ goto done;
store->subscribed_folders = g_hash_table_new (g_str_hash, g_str_equal);
for (i = 0; i < response->untagged->len; i++) {
result = response->untagged->pdata[i];
@@ -667,13 +652,21 @@ imap_store_setup_online (CamelImapStore *store, CamelException *ex)
camel_imap_response_free (store, response);
}
+ done:
fclose (storeinfo);
- return TRUE;
+ CAMEL_IMAP_STORE_UNLOCK (store, command_lock);
+
+ if (camel_exception_is_set (ex))
+ camel_service_disconnect (service, TRUE, NULL);
+ else
+ imap_store_refresh_folders (CAMEL_REMOTE_STORE (store), ex);
+ return !camel_exception_is_set (ex);
}
static gboolean
-imap_store_setup_offline (CamelImapStore *store, CamelException *ex)
+imap_connect_offline (CamelService *service, CamelException *ex)
{
+ CamelImapStore *store = CAMEL_IMAP_STORE (service);
char *buf, *name, *path;
FILE *storeinfo;
guint32 tmp;
@@ -685,11 +678,17 @@ imap_store_setup_offline (CamelImapStore *store, CamelException *ex)
if (storeinfo)
camel_file_util_decode_uint32 (storeinfo, &tmp);
if (tmp != IMAP_STOREINFO_VERSION) {
- /* This must set ex and return FALSE if we're here... */
- return camel_imap_store_check_online (store, ex);
+ if (storeinfo)
+ fclose (storeinfo);
+
+ /* We know we're offline, so this will have to set ex
+ * and return FALSE.
+ */
+ return camel_disco_store_check_online (CAMEL_DISCO_STORE (store), ex);
}
camel_file_util_decode_uint32 (storeinfo, &store->capabilities);
+ imap_set_server_level (store);
camel_file_util_decode_string (storeinfo, &store->namespace);
camel_file_util_decode_uint32 (storeinfo, &tmp);
store->dir_sep = tmp;
@@ -707,21 +706,17 @@ imap_store_setup_offline (CamelImapStore *store, CamelException *ex)
}
fclose (storeinfo);
- return TRUE;
-}
-
+ imap_store_refresh_folders (CAMEL_REMOTE_STORE (store), ex);
+ store->connected = !camel_exception_is_set (ex);
+ return store->connected;
+}
static gboolean
-imap_disconnect (CamelService *service, gboolean clean, CamelException *ex)
+imap_disconnect_offline (CamelService *service, gboolean clean, CamelException *ex)
{
CamelImapStore *store = CAMEL_IMAP_STORE (service);
- CamelImapResponse *response;
-
- if (store->connected && clean) {
- response = camel_imap_command (store, NULL, ex, "LOGOUT");
- camel_imap_response_free (store, response);
- }
+
store->connected = FALSE;
if (store->current_folder) {
camel_object_unref (CAMEL_OBJECT (store->current_folder));
@@ -747,63 +742,24 @@ imap_disconnect (CamelService *service, gboolean clean, CamelException *ex)
store->namespace = NULL;
}
- return CAMEL_SERVICE_CLASS (remote_store_class)->disconnect (service, clean, ex);
+ return TRUE;
}
static gboolean
-imap_folder_exists (CamelImapStore *store, const char *folder_name,
- gboolean *selectable, char **short_name,
- CamelException *ex)
+imap_disconnect_online (CamelService *service, gboolean clean, CamelException *ex)
{
+ CamelImapStore *store = CAMEL_IMAP_STORE (service);
CamelImapResponse *response;
- char *result, sep;
- int flags;
-
- if (!g_strcasecmp (folder_name, "INBOX")) {
- if (selectable)
- *selectable = TRUE;
- if (short_name)
- *short_name = g_strdup ("INBOX");
- return TRUE;
- }
-
- response = camel_imap_command (store, NULL, ex, "LIST \"\" %S",
- folder_name);
- if (!response)
- return FALSE;
- result = camel_imap_response_extract (store, response, "LIST", ex);
- if (!result)
- return FALSE;
-
- if (!imap_parse_list_response (result, &flags, &sep, NULL))
- return FALSE;
-
- if (selectable)
- *selectable = !(flags & IMAP_LIST_FLAG_NOSELECT);
- if (short_name) {
- *short_name = strrchr (folder_name, sep);
- if (*short_name)
- *short_name = g_strdup (*short_name + 1);
- else
- *short_name = g_strdup (folder_name);
+
+ imap_disconnect_offline (service, clean, ex);
+ if (store->connected && clean) {
+ response = camel_imap_command (store, NULL, ex, "LOGOUT");
+ camel_imap_response_free (store, response);
}
return TRUE;
}
-static gboolean
-imap_create (CamelImapStore *store, const char *folder_name,
- CamelException *ex)
-{
- CamelImapResponse *response;
-
- response = camel_imap_command (store, NULL, ex, "CREATE %S",
- folder_name);
- camel_imap_response_free (store, response);
-
- return !camel_exception_is_set (ex);
-}
-
static guint
hash_folder_name (gconstpointer key)
{
@@ -826,68 +782,85 @@ compare_folder_name (gconstpointer a, gconstpointer b)
}
static CamelFolder *
-get_folder (CamelStore *store, const char *folder_name, guint32 flags,
- CamelException *ex)
+no_such_folder (const char *name, CamelException *ex)
+{
+ camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
+ _("No such folder %s"), name);
+ return NULL;
+}
+
+static CamelFolder *
+get_folder_online (CamelStore *store, const char *folder_name,
+ guint32 flags, CamelException *ex)
{
CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
- CamelFolder *new_folder = NULL;
- char *short_name, *folder_dir;
- gboolean selectable;
+ CamelImapResponse *response;
+ CamelFolder *new_folder;
+ char *folder_dir;
- if (camel_imap_store_check_online (imap_store, NULL)) {
- if (!camel_remote_store_connected (CAMEL_REMOTE_STORE (store), ex))
- return NULL;
+ if (!camel_remote_store_connected (CAMEL_REMOTE_STORE (store), ex))
+ return NULL;
- /* lock around the whole lot to check/create atomically */
- CAMEL_IMAP_STORE_LOCK(imap_store, command_lock);
- if (!imap_folder_exists (imap_store, folder_name,
- &selectable, &short_name, ex) &&
- ((flags & CAMEL_STORE_FOLDER_CREATE) == 0
- || (!imap_create (imap_store, folder_name, ex))
- || (!imap_folder_exists (imap_store, folder_name,
- &selectable, &short_name, ex)))) {
- CAMEL_IMAP_STORE_UNLOCK(imap_store, command_lock);
+ /* Lock around the whole lot to check/create atomically */
+ CAMEL_IMAP_STORE_LOCK (imap_store, command_lock);
+ imap_store->current_folder = NULL;
+ response = camel_imap_command (imap_store, NULL, NULL,
+ "SELECT %S", folder_name);
+ if (!response) {
+ if (!flags & CAMEL_STORE_FOLDER_CREATE)
+ return no_such_folder (folder_name, ex);
+
+ response = camel_imap_command (imap_store, NULL, ex,
+ "CREATE %S", folder_name);
+ if (response) {
+ camel_imap_response_free (imap_store, response);
+
+ response = camel_imap_command (imap_store, NULL, NULL,
+ "SELECT %S", folder_name);
+ }
+ if (!response) {
+ CAMEL_IMAP_STORE_UNLOCK (imap_store, command_lock);
return NULL;
}
- } else {
- selectable = g_hash_table_lookup (imap_store->subscribed_folders, folder_name) != NULL;
- short_name = strrchr (folder_name, imap_store->dir_sep);
- if (short_name)
- short_name = g_strdup (short_name + 1);
- else
- short_name = g_strdup (folder_name);
-
- /* Need to lock here for parallelism with the online case */
- CAMEL_IMAP_STORE_LOCK(imap_store, command_lock);
}
- if (!selectable) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
- _("%s is not a selectable folder"),
- folder_name);
- g_free (short_name);
- CAMEL_IMAP_STORE_UNLOCK(imap_store, command_lock);
- return NULL;
+ folder_dir = e_path_to_physical (imap_store->storage_path, folder_name);
+ new_folder = camel_imap_folder_new (store, folder_name, folder_dir, ex);
+ g_free (folder_dir);
+ if (new_folder) {
+ imap_store->current_folder = new_folder;
+ camel_imap_folder_selected (new_folder, response, ex);
+ if (camel_exception_is_set (ex)) {
+ camel_object_unref (CAMEL_OBJECT (new_folder));
+ new_folder = imap_store->current_folder = NULL;
+ }
}
+ camel_imap_response_free_without_processing (imap_store, response);
- folder_dir = e_path_to_physical (imap_store->storage_path,
- folder_name);
- if (camel_mkdir_hier (folder_dir, S_IRWXU) == 0) {
- new_folder = camel_imap_folder_new (store, folder_name,
- short_name, folder_dir,
- ex);
- } else {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Could not create directory %s: %s"),
- folder_dir, g_strerror (errno));
- }
- CAMEL_IMAP_STORE_UNLOCK(imap_store, command_lock);
- g_free (folder_dir);
- g_free (short_name);
+ CAMEL_IMAP_STORE_UNLOCK (imap_store, command_lock);
- if (camel_exception_is_set (ex))
+ return new_folder;
+}
+
+static CamelFolder *
+get_folder_offline (CamelStore *store, const char *folder_name,
+ guint32 flags, CamelException *ex)
+{
+ CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
+ CamelFolder *new_folder;
+ char *folder_dir;
+
+ if (!imap_store->connected &&
+ !camel_service_connect (CAMEL_SERVICE (store), ex))
return NULL;
+ folder_dir = e_path_to_physical (imap_store->storage_path, folder_name);
+ if (access (folder_dir, F_OK) != 0)
+ return no_such_folder (folder_name, ex);
+
+ new_folder = camel_imap_folder_new (store, folder_name, folder_dir, ex);
+ g_free (folder_dir);
+
return new_folder;
}
@@ -908,24 +881,25 @@ create_folder (CamelStore *store, const char *parent_name,
const char *folder_name, CamelException *ex)
{
CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
+ CamelImapResponse *response;
CamelFolderInfo *fi;
char *full_name;
- if (!camel_imap_store_check_online (imap_store, ex))
+ if (!camel_disco_store_check_online (CAMEL_DISCO_STORE (store), ex))
return NULL;
if (!parent_name)
parent_name = imap_store->namespace;
full_name = imap_concat (imap_store, parent_name, folder_name);
- imap_create (imap_store, full_name, ex);
- if (camel_exception_is_set (ex)) {
- g_free (full_name);
- return NULL;
- }
+ response = camel_imap_command (imap_store, NULL, ex, "CREATE %S",
+ full_name);
+ if (response) {
+ camel_imap_response_free (imap_store, response);
+ fi = get_folder_info_online (store, full_name, 0, ex);
+ } else
+ fi = NULL;
- fi = get_folder_info (store, full_name, FALSE, FALSE, FALSE, ex);
g_free (full_name);
-
return fi;
}
@@ -1029,9 +1003,6 @@ get_folders_online (CamelImapStore *imap_store, const char *pattern,
char *list;
int i;
- if (!camel_remote_store_connected (CAMEL_REMOTE_STORE (imap_store), ex))
- return;
-
response = camel_imap_command (imap_store, NULL, ex,
"%s \"\" %S", lsub ? "LSUB" : "LIST",
pattern);
@@ -1047,92 +1018,19 @@ get_folders_online (CamelImapStore *imap_store, const char *pattern,
camel_imap_response_free (imap_store, response);
}
-static void
-get_unread_online (CamelImapStore *imap_store, CamelFolderInfo *fi)
-{
- CamelImapResponse *response;
- char *status, *p;
-
- response = camel_imap_command (imap_store, NULL, NULL,
- "STATUS %S (UNSEEN)", fi->full_name);
- if (!response)
- return;
- status = camel_imap_response_extract (imap_store, response, "STATUS", NULL);
- if (!status)
- return;
-
- p = strstrcase (status, "UNSEEN");
- if (p)
- fi->unread_message_count = strtoul (p + 6, NULL, 10);
- g_free (status);
-}
-
-static void
-add_folder (gpointer key, gpointer value, gpointer data)
-{
- g_ptr_array_add (data, key);
-}
-
-static void
-get_folders_offline (CamelImapStore *imap_store, GPtrArray *folders,
- CamelException *ex)
-{
- CamelFolderInfo *fi;
- CamelURL *url;
- int i;
-
- i = folders->len;
- g_hash_table_foreach (imap_store->subscribed_folders,
- add_folder, folders);
-
- url = camel_url_new (imap_store->base_url, NULL);
-
- while (i < folders->len) {
- fi = g_new0 (CamelFolderInfo, 1);
- fi->full_name = g_strdup (folders->pdata[i]);
- fi->name = strchr (fi->full_name, imap_store->dir_sep);
- if (fi->name)
- fi->name = g_strdup (fi->name + 1);
- else
- fi->name = g_strdup (fi->full_name);
-
- g_free (url->path);
- url->path = g_strdup_printf ("/%s", fi->full_name);
- fi->url = camel_url_to_string (url, 0);
-
- fi->unread_message_count = -1;
- folders->pdata[i++] = fi;
- }
-
- camel_url_free (url);
-}
-
-static void
-get_unread_offline (CamelImapStore *imap_store, CamelFolderInfo *fi)
-{
- /* FIXME */
-}
-
static CamelFolderInfo *
-get_folder_info (CamelStore *store, const char *top, gboolean fast,
- gboolean recursive, gboolean subscribed_only,
- CamelException *ex)
+get_folder_info_online (CamelStore *store, const char *top,
+ guint32 flags, CamelException *ex)
{
CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
- gboolean need_inbox = FALSE, online;
+ CamelImapResponse *response;
+ gboolean need_inbox = FALSE;
GPtrArray *folders;
const char *name;
- char *pattern;
+ char *pattern, *status, *p;
CamelFolderInfo *fi;
int i;
- if (!subscribed_only || !recursive || top) {
- if (!camel_imap_store_check_online (imap_store, ex))
- return NULL;
- online = TRUE;
- } else
- online = camel_imap_store_check_online (imap_store, NULL);
-
if (!camel_remote_store_connected (CAMEL_REMOTE_STORE (store), ex))
return NULL;
@@ -1144,41 +1042,35 @@ get_folder_info (CamelStore *store, const char *top, gboolean fast,
folders = g_ptr_array_new ();
- if (online) {
- /* Get top-level */
- get_folders_online (imap_store, name, folders, FALSE, ex);
- if (camel_exception_is_set (ex))
- return NULL;
- if (folders->len) {
- fi = folders->pdata[0];
- if (!fi->url) {
- camel_folder_info_free (fi);
- g_ptr_array_remove_index (folders, 0);
- }
- }
-
- /* If we want to look at only subscribed folders AND
- * check if any of them have new mail, AND the server
- * doesn't return Marked/UnMarked with LSUB, then
- * use get_subscribed_folders_by_hand. In all other
- * cases, use a single LIST or LSUB command.
- */
- if (subscribed_only &&
- !(imap_store->capabilities & IMAP_CAPABILITY_useful_lsub) &&
- (imap_store->parameters & IMAP_PARAM_CHECK_ALL)) {
- get_subscribed_folders_by_hand (imap_store, name,
- folders, ex);
- } else {
- pattern = imap_concat (imap_store, name,
- recursive ? "*" : "%");
- get_folders_online (imap_store, pattern, folders,
- subscribed_only, ex);
- g_free (pattern);
+ /* Get top-level */
+ get_folders_online (imap_store, name, folders, FALSE, ex);
+ if (camel_exception_is_set (ex))
+ goto lose;
+ if (folders->len) {
+ fi = folders->pdata[0];
+ if (!fi->url) {
+ camel_folder_info_free (fi);
+ g_ptr_array_remove_index (folders, 0);
}
- } else
- get_folders_offline (imap_store, folders, ex);
+ }
+ /* If we want to look at only subscribed folders AND check if
+ * any of them have new mail, AND the server doesn't return
+ * Marked/UnMarked with LSUB, then use
+ * get_subscribed_folders_by_hand. In all other cases, use a
+ * single LIST or LSUB command.
+ */
+ if ((flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED) &&
+ !(imap_store->capabilities & IMAP_CAPABILITY_useful_lsub) &&
+ (imap_store->parameters & IMAP_PARAM_CHECK_ALL)) {
+ get_subscribed_folders_by_hand (imap_store, name, folders, ex);
+ } else {
+ pattern = imap_concat (imap_store, name, (flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) ? "*" : "%");
+ get_folders_online (imap_store, pattern, folders, (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED), ex);
+ g_free (pattern);
+ }
if (camel_exception_is_set (ex)) {
+ lose:
for (i = 0; i < folders->len; i++)
camel_folder_info_free (folders->pdata[i]);
g_ptr_array_free (folders, TRUE);
@@ -1194,68 +1086,143 @@ get_folder_info (CamelStore *store, const char *top, gboolean fast,
break;
}
}
+
+ if (need_inbox) {
+ CamelURL *url;
+ char *uri;
+
+ url = camel_url_new (imap_store->base_url, NULL);
+ g_free (url->path);
+ url->path = g_strdup ("/INBOX");
+ uri = camel_url_to_string (url, 0);
+ camel_url_free (url);
+
+ fi = g_new0 (CamelFolderInfo, 1);
+ fi->full_name = g_strdup ("INBOX");
+ fi->name = g_strdup ("INBOX");
+ fi->url = uri;
+ fi->unread_message_count = -1;
+
+ g_ptr_array_add (folders, fi);
+ }
}
-
- if (need_inbox) {
- CamelURL *url;
- char *uri;
-
- url = camel_url_new (imap_store->base_url, NULL);
- g_free (url->path);
- url->path = g_strdup ("/INBOX");
- uri = camel_url_to_string (url, 0);
- camel_url_free (url);
-
- fi = g_new0 (CamelFolderInfo, 1);
- fi->full_name = g_strdup ("INBOX");
- fi->name = g_strdup ("INBOX");
- fi->url = uri;
- fi->unread_message_count = -1;
-
- g_ptr_array_add (folders, fi);
+
+ /* Assemble. */
+ fi = camel_folder_info_build (folders, name, imap_store->dir_sep, TRUE);
+ if (flags & CAMEL_STORE_FOLDER_INFO_FAST) {
+ g_ptr_array_free (folders, TRUE);
+ return fi;
}
- if (!fast) {
- /* Get unread counts. Sync flag changes to the server
- * first so it has the same ideas about read/unread as
- * we do.
+ /* Get unread counts. Sync flag changes to the server first so
+ * it has the same ideas about read/unread as we do.
+ */
+ camel_store_sync (store, NULL);
+ for (i = 0; i < folders->len; i++) {
+ fi = folders->pdata[i];
+
+ /* Don't check if it doesn't contain messages or if it
+ * was \UnMarked.
*/
- camel_store_sync (store, NULL);
- for (i = 0; i < folders->len; i++) {
- fi = folders->pdata[i];
+ if (!fi->url || fi->unread_message_count != -1)
+ continue;
+ /* Don't check if it's not INBOX and we're only
+ * checking INBOX.
+ */
+ if ((!(imap_store->parameters & IMAP_PARAM_CHECK_ALL))
+ && (g_strcasecmp (fi->name, "INBOX") != 0))
+ continue;
- /* Don't check if it doesn't contain messages
- * or if it was \UnMarked.
- */
- if (!fi->url || fi->unread_message_count != -1)
- continue;
- /* Don't check if it's not INBOX and we're only
- * checking INBOX.
- */
- if ((!(imap_store->parameters & IMAP_PARAM_CHECK_ALL))
- && (g_strcasecmp (fi->name, "INBOX") != 0))
- continue;
+ /* UW will give cached data for the currently selected
+ * folder. Grr. Well, I guess this also potentially
+ * saves us one IMAP command.
+ */
+ if (imap_store->current_folder &&
+ !strcmp (imap_store->current_folder->full_name, fi->full_name)) {
+ fi->unread_message_count = camel_folder_get_unread_message_count (imap_store->current_folder);
+ continue;
+ }
- /* UW will give cached data for the currently
- * selected folder. Grr. Well, I guess this
- * also potentially saves us one IMAP command.
- */
- if (imap_store->current_folder &&
- !strcmp (imap_store->current_folder->full_name,
- fi->full_name)) {
- fi->unread_message_count = camel_folder_get_unread_message_count (imap_store->current_folder);
- continue;
- }
+ response = camel_imap_command (imap_store, NULL, NULL,
+ "STATUS %S (UNSEEN)",
+ fi->full_name);
+ if (!response)
+ continue;
+ status = camel_imap_response_extract (imap_store, response,
+ "STATUS", NULL);
+ if (!status)
+ continue;
- if (online)
- get_unread_online (imap_store, fi);
- else
- get_unread_offline (imap_store, fi);
- }
+ p = strstrcase (status, "UNSEEN");
+ if (p)
+ fi->unread_message_count = strtoul (p + 6, NULL, 10);
+ g_free (status);
+ }
+
+ g_ptr_array_free (folders, TRUE);
+ return fi;
+}
+
+static gboolean
+get_one_folder_offline (const char *physical_path, const char *path, gpointer data)
+{
+ GPtrArray *folders = data;
+ CamelImapStore *imap_store = folders->pdata[0];
+ CamelFolderInfo *fi;
+
+ if (*path++ != '/')
+ return TRUE;
+
+ fi = g_new0 (CamelFolderInfo, 1);
+ fi->full_name = g_strdup (path);
+ fi->name = strrchr (fi->full_name, imap_store->dir_sep);
+ if (fi->name)
+ fi->name = g_strdup (fi->name + 1);
+ else
+ fi->name = g_strdup (fi->full_name);
+
+ fi->url = g_strdup_printf ("%s/%s", imap_store->base_url, path);
+
+ /* FIXME: check summary */
+ fi->unread_message_count = -1;
+
+ g_ptr_array_add (folders, fi);
+ return TRUE;
+}
+
+static CamelFolderInfo *
+get_folder_info_offline (CamelStore *store, const char *top,
+ guint32 flags, CamelException *ex)
+{
+ CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
+ CamelFolderInfo *fi;
+ GPtrArray *folders;
+
+ if (!imap_store->connected &&
+ !camel_service_connect (CAMEL_SERVICE (store), ex))
+ return NULL;
+
+ if ((store->flags & CAMEL_STORE_SUBSCRIPTIONS) &&
+ !(flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED)) {
+ camel_disco_store_check_online (CAMEL_DISCO_STORE (store), ex);
+ return NULL;
+ }
+
+ /* FIXME: obey other flags */
+
+ folders = g_ptr_array_new ();
+
+ /* A kludge to avoid having to pass a struct to the callback */
+ g_ptr_array_add (folders, imap_store);
+ if (!e_path_find_folders (imap_store->storage_path, get_one_folder_offline, folders)) {
+ camel_disco_store_check_online (CAMEL_DISCO_STORE (imap_store), ex);
+ fi = NULL;
+ } else {
+ g_ptr_array_remove_index_fast (folders, 0);
+ fi = camel_folder_info_build (folders, imap_store->namespace,
+ imap_store->dir_sep, TRUE);
}
- /* And assemble. */
- fi = camel_folder_info_build (folders, name, imap_store->dir_sep, TRUE);
g_ptr_array_free (folders, TRUE);
return fi;
}
@@ -1280,7 +1247,7 @@ subscribe_folder (CamelStore *store, const char *folder_name,
CamelFolderInfo *fi;
char *name;
- if (!camel_imap_store_check_online (imap_store, ex))
+ if (!camel_disco_store_check_online (CAMEL_DISCO_STORE (store), ex))
return;
if (!camel_remote_store_connected (CAMEL_REMOTE_STORE (store), ex))
return;
@@ -1318,7 +1285,7 @@ unsubscribe_folder (CamelStore *store, const char *folder_name,
CamelFolderInfo *fi;
char *name;
- if (!camel_imap_store_check_online (imap_store, ex))
+ if (!camel_disco_store_check_online (CAMEL_DISCO_STORE (store), ex))
return;
if (!camel_remote_store_connected (CAMEL_REMOTE_STORE (store), ex))
return;
@@ -1357,17 +1324,3 @@ imap_keepalive (CamelRemoteStore *store)
response = camel_imap_command (imap_store, NULL, NULL, "NOOP");
camel_imap_response_free (imap_store, response);
}
-
-gboolean
-camel_imap_store_check_online (CamelImapStore *store, CamelException *ex)
-{
- /* Hack */
- if (getenv ("CAMEL_OFFLINE")) {
- camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("You must be working online to "
- "complete this operation"));
- return FALSE;
- }
-
- return TRUE;
-}
diff --git a/camel/providers/imap/camel-imap-store.h b/camel/providers/imap/camel-imap-store.h
index b05e525845..8c0453cb53 100644
--- a/camel/providers/imap/camel-imap-store.h
+++ b/camel/providers/imap/camel-imap-store.h
@@ -33,7 +33,7 @@ extern "C" {
#endif /* __cplusplus }*/
#include "camel-imap-types.h"
-#include "camel-remote-store.h"
+#include "camel-disco-store.h"
#define CAMEL_IMAP_STORE_TYPE (camel_imap_store_get_type ())
#define CAMEL_IMAP_STORE(obj) (CAMEL_CHECK_CAST((obj), CAMEL_IMAP_STORE_TYPE, CamelImapStore))
@@ -59,7 +59,7 @@ typedef enum {
#define IMAP_PARAM_FILTER_INBOX (1 << 2)
struct _CamelImapStore {
- CamelRemoteStore parent_object;
+ CamelDiscoStore parent_object;
struct _CamelImapStorePrivate *priv;
/* Information about the command channel / connection status */
@@ -77,7 +77,7 @@ struct _CamelImapStore {
typedef struct {
- CamelRemoteStoreClass parent_class;
+ CamelDiscoStoreClass parent_class;
} CamelImapStoreClass;
@@ -85,8 +85,6 @@ typedef struct {
/* Standard Camel function */
CamelType camel_imap_store_get_type (void);
-gboolean camel_imap_store_check_online (CamelImapStore *store, CamelException *ex);
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/camel/providers/local/camel-local-store.c b/camel/providers/local/camel-local-store.c
index d0ce48ce98..4b948ab96a 100644
--- a/camel/providers/local/camel-local-store.c
+++ b/camel/providers/local/camel-local-store.c
@@ -46,9 +46,7 @@ static char *get_name(CamelService *service, gboolean brief);
static CamelFolder *get_inbox (CamelStore *store, CamelException *ex);
static void rename_folder(CamelStore *store, const char *old_name, const char *new_name, CamelException *ex);
static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top,
- gboolean fast, gboolean recursive,
- gboolean subscribed_only,
- CamelException *ex);
+ guint32 flags, CamelException *ex);
static void delete_folder(CamelStore *store, const char *folder_name, CamelException *ex);
static void rename_folder(CamelStore *store, const char *old, const char *new, CamelException *ex);
@@ -187,9 +185,7 @@ get_name (CamelService *service, gboolean brief)
static CamelFolderInfo *
get_folder_info (CamelStore *store, const char *top,
- gboolean fast, gboolean recursive,
- gboolean subscribed_only,
- CamelException *ex)
+ guint32 flags, CamelException *ex)
{
/* FIXME: This is broken, but it corresponds to what was
* there before.