aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers
diff options
context:
space:
mode:
Diffstat (limited to 'camel/providers')
-rw-r--r--camel/providers/imap/camel-imap-folder.c68
-rw-r--r--camel/providers/imap/camel-imap-folder.h6
-rw-r--r--camel/providers/imap/camel-imap-store.c66
-rw-r--r--camel/providers/imap/camel-imap-store.h6
-rw-r--r--camel/providers/imap/camel-imap-stream.c1
-rw-r--r--camel/providers/imap/camel-imap-stream.h5
6 files changed, 69 insertions, 83 deletions
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
index 3e60478783..722b6bbd9e 100644
--- a/camel/providers/imap/camel-imap-folder.c
+++ b/camel/providers/imap/camel-imap-folder.c
@@ -36,6 +36,7 @@
#include "camel-imap-folder.h"
#include "camel-imap-store.h"
+#include "camel-imap-stream.h"
#include "string-utils.h"
#include "camel-stream.h"
#include "camel-stream-fs.h"
@@ -178,11 +179,6 @@ camel_imap_folder_new (CamelStore *parent, CamelException *ex)
static void
imap_finalize (GtkObject *object)
{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (object);
-
- g_free (imap_folder->folder_file_path);
- g_free (imap_folder->folder_dir_path);
-
GTK_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -191,7 +187,6 @@ imap_init (CamelFolder *folder, CamelStore *parent_store, CamelFolder *parent_fo
const gchar *name, gchar separator, CamelException *ex)
{
CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- const gchar *root_dir_path;
/* call parent method */
parent_class->init (folder, parent_store, parent_folder, name, separator, ex);
@@ -219,25 +214,11 @@ imap_init (CamelFolder *folder, CamelStore *parent_store, CamelFolder *parent_fo
imap_folder->summary = NULL;
imap_folder->search = NULL;
-
- /* now set the name info */
- g_free (imap_folder->folder_file_path);
- g_free (imap_folder->folder_dir_path);
- g_free (imap_folder->index_file_path);
-
- root_dir_path = camel_imap_store_get_toplevel_dir (CAMEL_IMAP_STORE(folder->parent_store));
-
- imap_folder->folder_file_path = g_strdup_printf ("%s/%s", root_dir_path, folder->full_name);
-#if 0
- imap_folder->folder_dir_path = g_strdup_printf ("%s/%s.sdb", root_dir_path, folder->full_name);
- imap_folder->index_file_path = g_strdup_printf ("%s/%s.ibex", root_dir_path, folder->full_name);
-#endif
}
static void
imap_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex)
{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
gchar *result;
gint status;
@@ -247,14 +228,14 @@ imap_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex)
parent_class->open (folder, mode, ex);
/* SELECT the IMAP mail spool */
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), &result,
- "SELECT %s", imap_folder->folder_file_path);
+ status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder,
+ &result, "SELECT %s", folder->full_name);
if (status != CAMEL_IMAP_OK) {
CamelService *service = CAMEL_SERVICE (folder->parent_store);
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
"Could not SELECT %s on IMAP server %s: %s.",
- imap_folder->folder_file_path,
+ folder->full_name,
service->url->host,
status == CAMEL_IMAP_ERR ? result :
"Unknown error");
@@ -274,20 +255,18 @@ imap_close (CamelFolder *folder, gboolean expunge, CamelException *ex)
if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_NONE)
parent_class->close (folder, expunge, ex);
-
}
static void
imap_expunge (CamelFolder *folder, CamelException *ex)
{
- /*CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);*/
gchar *result;
gint status;
g_return_if_fail (folder != NULL);
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), &result,
- "EXPUNGE");
+ status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder,
+ &result, "EXPUNGE");
if (status != CAMEL_IMAP_OK) {
CamelService *service = CAMEL_SERVICE (folder->parent_store);
@@ -308,24 +287,21 @@ static gboolean
imap_exists (CamelFolder *folder, CamelException *ex)
{
/* make sure the folder exists */
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
GPtrArray *lsub;
gboolean exists = FALSE;
int i, max;
g_return_val_if_fail (folder != NULL, FALSE);
- imap_folder = CAMEL_IMAP_FOLDER (folder);
-
/* check if the imap file path is determined */
- if (!imap_folder->folder_file_path) {
+ if (!folder->full_name) {
camel_exception_set (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
"undetermined folder file path. Maybe use set_name ?");
return FALSE;
}
/* check if the imap dir path is determined */
- if (!imap_folder->folder_dir_path) {
+ if (!folder->full_name) {
camel_exception_set (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
"undetermined folder directory path. Maybe use set_name ?");
return FALSE;
@@ -337,7 +313,7 @@ imap_exists (CamelFolder *folder, CamelException *ex)
/* look to see if any of those subfolders match... */
max = lsub->len;
for (i = 0; i < max; i++)
- if (!strcmp(g_ptr_array_index(lsub, i), imap_folder->folder_file_path))
+ if (!strcmp(g_ptr_array_index(lsub, i), folder->full_name))
{
exists = TRUE;
break;
@@ -348,13 +324,13 @@ imap_exists (CamelFolder *folder, CamelException *ex)
return exists;
}
#endif
+
#if 0
static gboolean
imap_delete (CamelFolder *folder, gboolean recurse, CamelException *ex)
{
/* TODO: code this & what should this do? delete messages or the folder? */
CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- const gchar *folder_file_path, *folder_dir_path;
gboolean folder_already_exists;
g_return_val_if_fail (folder != NULL, FALSE);
@@ -378,11 +354,7 @@ imap_delete (CamelFolder *folder, gboolean recurse, CamelException *ex)
if (camel_exception_get_id (ex))
return FALSE;
- /* get the paths of what we need to be deleted */
- folder_file_path = imap_folder->folder_file_path;
- folder_dir_path = imap_folder->folder_file_path;
-
- if (!(folder_file_path || folder_dir_path)) {
+ if (!(folder->full_name || folder->name)) {
camel_exception_set (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
"invalid folder path. Use set_name ?");
return FALSE;
@@ -410,8 +382,8 @@ imap_get_message_count (CamelFolder *folder, CamelException *ex)
if (imap_folder->count != -1)
return imap_folder->count;
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), &result,
- "STATUS %s (MESSAGES)", imap_folder->folder_file_path);
+ status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder,
+ &result, "STATUS %s (MESSAGES)", folder->full_name);
if (status != CAMEL_IMAP_OK) {
CamelService *service = CAMEL_SERVICE (folder->parent_store);
@@ -445,7 +417,6 @@ imap_get_message_count (CamelFolder *folder, CamelException *ex)
static void
imap_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex)
{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
CamelStreamMem *mem;
gchar *result;
gint status;
@@ -467,9 +438,9 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelExcept
mem->buffer = g_byte_array_append(mem->buffer, g_strdup("\n"), 2);
status = camel_imap_command(CAMEL_IMAP_STORE (folder->parent_store),
- &result,
+ folder, &result,
"APPEND %s (\\Seen) {%d}\r\n%s",
- imap_folder->folder_file_path,
+ folder->full_name,
mem->buffer->len,
mem->buffer->data);
@@ -520,8 +491,8 @@ imap_get_subfolder_names (CamelFolder *folder, CamelException *ex)
if (imap_folder->count != -1)
return g_ptr_array_new ();
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), &result,
- "LSUB \"\" \"%s\"", imap_folder->folder_file_path);
+ status = camel_imap_command_extended(CAMEL_IMAP_STORE (folder->parent_store), folder,
+ &result, "LSUB \"\" \"%s\"", folder->full_name);
if (status != CAMEL_IMAP_OK) {
CamelService *service = CAMEL_SERVICE (folder->parent_store);
@@ -580,11 +551,10 @@ imap_get_subfolder_names (CamelFolder *folder, CamelException *ex)
static void
imap_delete_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex)
{
- /*CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);*/
gchar *result;
gint status;
- status = camel_imap_command_extended(CAMEL_IMAP_STORE (folder->parent_store),
+ status = camel_imap_command_extended(CAMEL_IMAP_STORE (folder->parent_store), folder,
&result, "UID STORE %s +FLAGS.SILENT (\\Deleted)", uid);
if (status != CAMEL_IMAP_OK) {
@@ -670,7 +640,7 @@ imap_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *
g_assert(info->frompos != -1);
/* get our message buffer */
- status = camel_imap_command_extended(CAMEL_IMAP_STORE (folder->parent_store),
+ status = camel_imap_command_extended(CAMEL_IMAP_STORE (folder->parent_store), folder,
&result, "UID FETCH %s (FLAGS BODY[])", uid);
if (status != CAMEL_IMAP_OK) {
diff --git a/camel/providers/imap/camel-imap-folder.h b/camel/providers/imap/camel-imap-folder.h
index 479a43c45c..1b7676b4f8 100644
--- a/camel/providers/imap/camel-imap-folder.h
+++ b/camel/providers/imap/camel-imap-folder.h
@@ -47,10 +47,6 @@ extern "C" {
typedef struct {
CamelFolder parent_object;
- gchar *folder_file_path; /* contains the messages */
- gchar *folder_dir_path; /* contains the subfolders */
- gchar *index_file_path; /* index of body contents */
-
ibex *index; /* index for this folder */
CamelImapSummary *summary;
CamelFolderSearch *search; /* used to run searches, we just use the real thing (tm) */
@@ -78,3 +74,5 @@ GtkType camel_imap_folder_get_type (void);
#endif /* __cplusplus */
#endif /* CAMEL_IMAP_FOLDER_H */
+
+
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index 5c57a8911d..0bf8dd52e8 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -39,6 +39,7 @@
#include "camel-imap-store.h"
#include "camel-imap-folder.h"
+#include "camel-folder.h"
#include "camel-exception.h"
#include "camel-session.h"
#include "camel-stream.h"
@@ -272,9 +273,9 @@ imap_connect (CamelService *service, CamelException *ex)
}
g_free (buf);
- status = camel_imap_command (store, &msg, "LOGIN \"%s\" \"%s\"",
- service->url->user,
- service->url->passwd);
+ status = camel_imap_command(store, NULL, &msg, "LOGIN \"%s\" \"%s\"",
+ service->url->user,
+ service->url->passwd);
if (status != CAMEL_IMAP_OK) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
@@ -322,42 +323,29 @@ camel_imap_store_get_toplevel_dir (CamelImapStore *store)
static gboolean
imap_create (CamelFolder *folder, CamelException *ex)
{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- const gchar *folder_file_path, *folder_dir_path;
- gboolean folder_already_exists;
gchar *result;
gint status;
g_return_val_if_fail (folder != NULL, FALSE);
- /* get the paths of what we need to create */
- folder_file_path = imap_folder->folder_file_path;
- folder_dir_path = imap_folder->folder_dir_path;
-
- if (!(folder_file_path || folder_dir_path)) {
+ if (!(folder->full_name || folder->name)) {
camel_exception_set (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
"invalid folder path. Use set_name ?");
return FALSE;
}
- /* if the folder already exists, simply return */
- folder_already_exists = camel_folder_exists (folder, ex);
- if (camel_exception_get_id (ex))
- return FALSE;
-
- if (folder_already_exists)
+ if (camel_folder_get_subfolder(folder->parent_folder, folder->name, FALSE, ex))
return TRUE;
- /* create the directory for the subfolder */
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), &result,
- "CREATE %s", imap_folder->folder_file_path);
+ /* create the directory for the subfolder */
+ status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), NULL,
+ &result, "CREATE %s", folder->full_name);
if (status != CAMEL_IMAP_OK) {
CamelService *service = CAMEL_SERVICE (folder->parent_store);
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
"Could not CREATE %s on IMAP server %s: %s.",
- imap_folder->folder_file_path,
- service->url->host,
+ folder->full_name, service->url->host,
status == CAMEL_IMAP_ERR ? result :
"Unknown error");
g_free (result);
@@ -414,13 +402,28 @@ get_folder_name (CamelStore *store, const char *folder_name,
* result of the command.)
**/
gint
-camel_imap_command (CamelImapStore *store, char **ret, char *fmt, ...)
+camel_imap_command (CamelImapStore *store, CamelFolder *folder, char **ret, char *fmt, ...)
{
gchar *cmdbuf, *respbuf;
gchar *cmdid, *code;
va_list ap;
gint status;
+ if (folder && store->current_folder != folder && strncmp(fmt, "SELECT", 6) &&
+ strncmp(fmt, "STATUS", 6) && strncmp(fmt, "CREATE", 5)) {
+ /* We need to select the correct mailbox first */
+ char *r;
+ int s;
+
+ s = camel_imap_command(store, folder, &r, "SELECT %s", folder->full_name);
+ if (s != CAMEL_IMAP_OK) {
+ *ret = r;
+ return s;
+ }
+
+ store->current_folder = folder;
+ }
+
/* create the command */
cmdid = g_strdup_printf("A%.5d", store->command++);
va_start (ap, fmt);
@@ -500,7 +503,7 @@ camel_imap_command (CamelImapStore *store, char **ret, char *fmt, ...)
**/
gint
-camel_imap_command_extended (CamelImapStore *store, char **ret, char *fmt, ...)
+camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **ret, char *fmt, ...)
{
CamelStreamBuffer *stream = CAMEL_STREAM_BUFFER (store->istream);
GPtrArray *data;
@@ -508,6 +511,21 @@ camel_imap_command_extended (CamelImapStore *store, char **ret, char *fmt, ...)
va_list app;
gint i, status = CAMEL_IMAP_OK;
+ if (folder && store->current_folder != folder && strncmp(fmt, "SELECT", 6) &&
+ strncmp(fmt, "STATUS", 6) && strncmp(fmt, "CREATE", 5)) {
+ /* We need to select the correct mailbox first */
+ char *r;
+ int s;
+
+ s = camel_imap_command(store, folder, &r, "SELECT %s", folder->full_name);
+ if (s != CAMEL_IMAP_OK) {
+ *ret = r;
+ return s;
+ }
+
+ store->current_folder = folder;
+ }
+
/* Create the command */
cmdid = g_strdup_printf("A%.5d", store->command++);
va_start (app, fmt);
diff --git a/camel/providers/imap/camel-imap-store.h b/camel/providers/imap/camel-imap-store.h
index 5ea6eca09e..587415b153 100644
--- a/camel/providers/imap/camel-imap-store.h
+++ b/camel/providers/imap/camel-imap-store.h
@@ -3,7 +3,6 @@
/*
* Authors: Jeffrey Stedfast <fejj@helixcode.com>
- * Ross Golder <ross@golder.org>
*
* Copyright (C) 2000 Helix Code, Inc.
*
@@ -45,6 +44,7 @@ extern "C" {
typedef struct {
CamelStore parent_object;
+ CamelFolder *current_folder;
CamelStream *istream, *ostream;
guint32 command;
@@ -67,8 +67,8 @@ void camel_imap_store_close (CamelImapStore *store, gboolean expunge,
enum { CAMEL_IMAP_OK, CAMEL_IMAP_ERR, CAMEL_IMAP_FAIL };
-gint camel_imap_command (CamelImapStore *store, char **ret, char *fmt, ...);
-gint camel_imap_command_extended (CamelImapStore *store, char **ret, char *fmt, ...);
+gint camel_imap_command (CamelImapStore *store, CamelFolder *folder, char **ret, char *fmt, ...);
+gint camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **ret, char *fmt, ...);
/* Standard Gtk function */
GtkType camel_imap_store_get_type (void);
diff --git a/camel/providers/imap/camel-imap-stream.c b/camel/providers/imap/camel-imap-stream.c
index f2400f4ce8..43b1afb61a 100644
--- a/camel/providers/imap/camel-imap-stream.c
+++ b/camel/providers/imap/camel-imap-stream.c
@@ -131,6 +131,7 @@ stream_read (CamelStream *stream, char *buffer, size_t n)
gint status;
status = camel_imap_command_extended(CAMEL_IMAP_STORE (folder->parent_store),
+ CAMEL_FOLDER (imap_stream->folder),
&imap_stream->cache, "%s",
imap_stream->command);
diff --git a/camel/providers/imap/camel-imap-stream.h b/camel/providers/imap/camel-imap-stream.h
index 6cb96e8cc5..2a6e2fc723 100644
--- a/camel/providers/imap/camel-imap-stream.h
+++ b/camel/providers/imap/camel-imap-stream.h
@@ -21,7 +21,6 @@
*/
-
#ifndef CAMEL_IMAP_STREAM_H
#define CAMEL_IMAP_STREAM_H
@@ -32,8 +31,8 @@ extern "C" {
#endif /* __cplusplus }*/
#include <camel/camel-stream.h>
-#include <camel/providers/imap/camel-imap-folder.h>
-#include <camel/providers/imap/camel-imap-store.h>
+#include "camel-imap-folder.h"
+#include "camel-imap-store.h"
#include <sys/types.h>
#define CAMEL_IMAP_STREAM_TYPE (camel_imap_stream_get_type ())