aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap/camel-imap-wrapper.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-03-16 04:50:59 +0800
committerDan Winship <danw@src.gnome.org>2001-03-16 04:50:59 +0800
commit1f9d06c2aac1805bbd3922991d8332b44f16ad3e (patch)
tree0b363d1cb7795c0c20f4f734541b70291d09c213 /camel/providers/imap/camel-imap-wrapper.c
parent892997d8c0f0cc6105ca8b0a8a369b97aab45dcb (diff)
downloadgsoc2013-evolution-1f9d06c2aac1805bbd3922991d8332b44f16ad3e.tar
gsoc2013-evolution-1f9d06c2aac1805bbd3922991d8332b44f16ad3e.tar.gz
gsoc2013-evolution-1f9d06c2aac1805bbd3922991d8332b44f16ad3e.tar.bz2
gsoc2013-evolution-1f9d06c2aac1805bbd3922991d8332b44f16ad3e.tar.lz
gsoc2013-evolution-1f9d06c2aac1805bbd3922991d8332b44f16ad3e.tar.xz
gsoc2013-evolution-1f9d06c2aac1805bbd3922991d8332b44f16ad3e.tar.zst
gsoc2013-evolution-1f9d06c2aac1805bbd3922991d8332b44f16ad3e.zip
First batch of disconnected IMAP-related stuff. This adds local
caching of message parts, but NOT any actual disconnected support. (But it should speed up IMAP use.) * providers/imap/camel-imap-message-cache.c: New class for caching message data to disk, and removing it when it's no longer relevant. Will eventually also support merging message parts together to save on files. Or maybe using a db instead of files? * providers/imap/camel-imap-private.h: Add a cache_lock to CamelImapFolderPrivate. This lock must be recursive, so make both locks EMutexes rather than GMutex. * providers/imap/camel-imap-folder.c (parse_fetch_response): "The only FETCH response parser you need!" Replaces the various almost-correct bits of code formerly scattered throughout this file with a single fully-correct function that can handle any FETCH response at any time, so we don't get confused by seeing a flags update when we were only expecting a message body, etc. (camel_imap_folder_fetch_data): FETCH a message body part either from the cache or the server (camel_imap_folder_changed): Remove expunged messages from the message cache. (camel_imap_folder_new): Change to take a directory instead of a summary file name. Create a CamelImapMessageCache for the folder. (imap_finalize): Unref the message cache. (camel_imap_folder_selected, imap_rescan, get_content, get_message, imap_get_message, imap_update_summary): Redone a bunch to use parse_fetch_data, CamelImapMessageCache, etc. * providers/imap/camel-imap-store.c (get_folder): Pass directory name to camel_imap_folder_new, not summary filename. Use e_path_to_physical to generate a path with /subfolders/ inserted between directory components. * providers/imap/camel-imap-wrapper.c (camel_imap_wrapper_new): Call camel_imap_folder_fetch_data (with cache_only TRUE) and if the data is cached, return an online datawrapper rather than an offline one. (write_to_stream): Use camel_imap_folder_fetch_data (with cache_only FALSE) here too * providers/imap/camel-imap-utils.c (imap_skip_list): Renamed from skip_list and made non-static. svn path=/trunk/; revision=8743
Diffstat (limited to 'camel/providers/imap/camel-imap-wrapper.c')
-rw-r--r--camel/providers/imap/camel-imap-wrapper.c96
1 files changed, 40 insertions, 56 deletions
diff --git a/camel/providers/imap/camel-imap-wrapper.c b/camel/providers/imap/camel-imap-wrapper.c
index e4d06a009b..a0e8b963fc 100644
--- a/camel/providers/imap/camel-imap-wrapper.c
+++ b/camel/providers/imap/camel-imap-wrapper.c
@@ -24,14 +24,10 @@
#include <config.h>
+#include "camel-imap-folder.h"
#include "camel-imap-wrapper.h"
-#include "camel-imap-command.h"
-#include "camel-imap-store.h"
-#include "camel-imap-utils.h"
#include "camel-imap-private.h"
#include "camel-exception.h"
-#include "camel-folder.h"
-#include "camel-stream-mem.h"
#include "camel-stream-filter.h"
#include "camel-mime-filter-basic.h"
#include "camel-mime-filter-crlf.h"
@@ -109,54 +105,15 @@ camel_imap_wrapper_get_type (void)
}
-static int
-write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+static void
+imap_wrapper_hydrate (CamelImapWrapper *imap_wrapper, CamelStream *stream)
{
- CamelImapWrapper *imap_wrapper = CAMEL_IMAP_WRAPPER (data_wrapper);
- CamelImapStore *store;
- CamelImapResponse *response;
- CamelStream *memstream;
+ CamelDataWrapper *data_wrapper = CAMEL_DATA_WRAPPER (imap_wrapper);
CamelStreamFilter *filterstream;
CamelMimeFilter *filter;
CamelContentType *ct;
- char *result, *p, *body;
- int len;
- CAMEL_IMAP_WRAPPER_LOCK (imap_wrapper, lock);
- if (!data_wrapper->offline) {
- CAMEL_IMAP_WRAPPER_UNLOCK (imap_wrapper, lock);
- return parent_class->write_to_stream (data_wrapper, stream);
- }
-
- store = CAMEL_IMAP_STORE (imap_wrapper->folder->parent_store);
- CAMEL_IMAP_STORE_LOCK (store, command_lock);
- response = camel_imap_command (store, imap_wrapper->folder, NULL,
- "UID FETCH %s BODY.PEEK[%s]",
- imap_wrapper->uid,
- imap_wrapper->part_spec);
- CAMEL_IMAP_STORE_UNLOCK (store, command_lock);
- if (!response)
- goto lose;
-
- result = camel_imap_response_extract (response, "FETCH", NULL);
- if (!result)
- goto lose;
-
- p = strchr (result, ']');
- if (!p) {
- g_free (result);
- goto lose;
- }
- p += 2;
-
- body = imap_parse_nstring (&p, &len);
- g_free (result);
- if (!body)
- goto lose;
-
- memstream = camel_stream_mem_new_with_buffer (body, len);
- g_free (body);
- filterstream = camel_stream_filter_new_with_stream (memstream);
+ filterstream = camel_stream_filter_new_with_stream (stream);
if (camel_mime_part_get_encoding (imap_wrapper->part) ==
CAMEL_MIME_PART_ENCODING_BASE64) {
@@ -198,37 +155,64 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
imap_wrapper->uid = NULL;
g_free (imap_wrapper->part_spec);
imap_wrapper->part = NULL;
+}
- CAMEL_IMAP_WRAPPER_UNLOCK (imap_wrapper, lock);
- return parent_class->write_to_stream (data_wrapper, stream);
+static int
+write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+{
+ CamelImapWrapper *imap_wrapper = CAMEL_IMAP_WRAPPER (data_wrapper);
+
+ CAMEL_IMAP_WRAPPER_LOCK (imap_wrapper, lock);
+ if (data_wrapper->offline) {
+ CamelStream *datastream;
+
+ datastream = camel_imap_folder_fetch_data (
+ imap_wrapper->folder, imap_wrapper->uid,
+ imap_wrapper->part_spec, FALSE, NULL);
+ if (!datastream) {
+ CAMEL_IMAP_WRAPPER_UNLOCK (imap_wrapper, lock);
+ errno = ENETUNREACH;
+ return -1;
+ }
- lose:
+ imap_wrapper_hydrate (imap_wrapper, datastream);
+ camel_object_unref (CAMEL_OBJECT (datastream));
+ }
CAMEL_IMAP_WRAPPER_UNLOCK (imap_wrapper, lock);
- errno = ENETUNREACH;
- return -1;
+
+ return parent_class->write_to_stream (data_wrapper, stream);
}
CamelDataWrapper *
-camel_imap_wrapper_new (CamelFolder *folder, CamelContentType *type,
+camel_imap_wrapper_new (CamelImapFolder *imap_folder, CamelContentType *type,
const char *uid, const char *part_spec,
CamelMimePart *part)
{
CamelImapWrapper *imap_wrapper;
+ CamelStream *stream;
imap_wrapper = (CamelImapWrapper *)camel_object_new(camel_imap_wrapper_get_type());
camel_data_wrapper_set_mime_type_field (CAMEL_DATA_WRAPPER (imap_wrapper), type);
((CamelDataWrapper *)imap_wrapper)->offline = TRUE;
- imap_wrapper->folder = folder;
- camel_object_ref (CAMEL_OBJECT (folder));
+ imap_wrapper->folder = imap_folder;
+ camel_object_ref (CAMEL_OBJECT (imap_folder));
imap_wrapper->uid = g_strdup (uid);
imap_wrapper->part_spec = g_strdup (part_spec);
/* Don't ref this, it's our parent. */
imap_wrapper->part = part;
+ /* Try the cache. */
+ stream = camel_imap_folder_fetch_data (imap_folder, uid, part_spec,
+ TRUE, NULL);
+ if (stream) {
+ imap_wrapper_hydrate (imap_wrapper, stream);
+ camel_object_unref (CAMEL_OBJECT (stream));
+ }
+
return (CamelDataWrapper *)imap_wrapper;
}