[evolution-data-server/imap-notify: 14/23] CamelIMAPXServer: Convert API to CamelIMAPXMailbox.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/imap-notify: 14/23] CamelIMAPXServer: Convert API to CamelIMAPXMailbox.
- Date: Tue, 10 Sep 2013 14:06:41 +0000 (UTC)
commit 357ef7e08039982f6c70080c8423a199b6f2818b
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Sep 3 07:05:22 2013 -0400
CamelIMAPXServer: Convert API to CamelIMAPXMailbox.
Convert CamelIMAPXServer to primarily use CamelIMAPXMailbox instead of
CamelIMAPXFolder, the idea being to keep all the Camel-specific policy
and limitations relegated to CamelIMAPXStore and CamelIMAPXFolder, and
just have CamelIMAPXServer be a pure IMAP client implementation.
This is a huge commit which I don't like doing, but CamelIMAPXServer,
CamelIMAPXCommand and CamelIMAPXJob are so tightly intertwined that I
was unable to split this into smaller steps.
Added functions:
camel_imapx_command_ref_mailbox()
camel_imapx_job_has_mailbox()
camel_imapx_job_ref_mailbox()
camel_imapx_job_set_mailbox()
camel_imapx_server_create_mailbox()
camel_imapx_server_delete_mailbox()
camel_imapx_server_rename_mailbox()
Removed functions:
camel_imapx_job_has_folder()
camel_imapx_job_ref_folder()
camel_imapx_job_set_mailbox()
camel_imapx_server_create_folder()
camel_imapx_server_delete_folder()
camel_imapx_server_rename_folder()
Modified function signatures:
camel_imapx_command_new()
camel_imapx_job_matches()
camel_imapx_server_refresh_info()
camel_imapx_server_sync_changes()
camel_imapx_server_expunge()
camel_imapx_server_fetch_messages()
camel_imapx_server_noop()
camel_imapx_server_get_message()
camel_imapx_server_copy_message()
camel_imapx_server_append_message()
camel_imapx_server_sync_message()
camel_imapx_server_manage_subscription()
camel_imapx_server_update_quota_info()
camel_imapx_server_uid_search()
imapx_parse_status()
camel/camel-imapx-command.c | 21 +-
camel/camel-imapx-command.h | 10 +-
camel/camel-imapx-folder.c | 338 +++++--
camel/camel-imapx-folder.h | 3 -
camel/camel-imapx-job.c | 71 +-
camel/camel-imapx-job.h | 15 +-
camel/camel-imapx-search.c | 18 +-
camel/camel-imapx-server.c | 1524 +++++++++++++++++--------------
camel/camel-imapx-server.h | 51 +-
camel/camel-imapx-store.c | 230 +++--
camel/camel-imapx-utils.c | 65 +-
camel/camel-imapx-utils.h | 8 +-
docs/reference/camel/camel-sections.txt | 1 -
13 files changed, 1374 insertions(+), 981 deletions(-)
---
diff --git a/camel/camel-imapx-command.c b/camel/camel-imapx-command.c
index 4fabc47..7c80aab 100644
--- a/camel/camel-imapx-command.c
+++ b/camel/camel-imapx-command.c
@@ -42,6 +42,9 @@ struct _CamelIMAPXRealCommand {
/* For building the part. */
GString *buffer;
+ /* Mailbox to select before running command. */
+ GWeakRef mailbox;
+
/* For network/parse errors. */
GError *error;
@@ -59,7 +62,7 @@ struct _CamelIMAPXCommandQueue {
CamelIMAPXCommand *
camel_imapx_command_new (CamelIMAPXServer *is,
const gchar *name,
- CamelFolder *select,
+ CamelIMAPXMailbox *mailbox,
const gchar *format,
...)
{
@@ -72,6 +75,7 @@ camel_imapx_command_new (CamelIMAPXServer *is,
/* Initialize private bits. */
real_ic->ref_count = 1;
real_ic->buffer = g_string_sized_new (512);
+ g_weak_ref_set (&real_ic->mailbox, mailbox);
g_cond_init (&real_ic->done_sync_cond);
g_mutex_init (&real_ic->done_sync_mutex);
@@ -79,7 +83,6 @@ camel_imapx_command_new (CamelIMAPXServer *is,
real_ic->public.is = is;
real_ic->public.tag = tag++;
real_ic->public.name = name;
- real_ic->public.select = select;
g_queue_init (&real_ic->public.parts);
if (format != NULL && *format != '\0') {
@@ -144,6 +147,8 @@ camel_imapx_command_unref (CamelIMAPXCommand *ic)
g_string_free (real_ic->buffer, TRUE);
+ g_weak_ref_set (&real_ic->mailbox, NULL);
+
g_clear_error (&real_ic->error);
g_cond_clear (&real_ic->done_sync_cond);
@@ -222,6 +227,18 @@ camel_imapx_command_set_job (CamelIMAPXCommand *ic,
real_ic->job = job;
}
+CamelIMAPXMailbox *
+camel_imapx_command_ref_mailbox (CamelIMAPXCommand *ic)
+{
+ CamelIMAPXRealCommand *real_ic;
+
+ g_return_val_if_fail (CAMEL_IS_IMAPX_COMMAND (ic), NULL);
+
+ real_ic = (CamelIMAPXRealCommand *) ic;
+
+ return g_weak_ref_get (&real_ic->mailbox);
+}
+
void
camel_imapx_command_add (CamelIMAPXCommand *ic,
const gchar *format,
diff --git a/camel/camel-imapx-command.h b/camel/camel-imapx-command.h
index 1094985..ed2c480 100644
--- a/camel/camel-imapx-command.h
+++ b/camel/camel-imapx-command.h
@@ -23,7 +23,8 @@
#ifndef CAMEL_IMAPX_COMMAND_H
#define CAMEL_IMAPX_COMMAND_H
-#include "camel-imapx-utils.h"
+#include <camel/camel-imapx-mailbox.h>
+#include <camel/camel-imapx-utils.h>
#define CAMEL_IS_IMAPX_COMMAND(command) \
(camel_imapx_command_check (command))
@@ -74,9 +75,6 @@ struct _CamelIMAPXCommand {
/* Command name/type (e.g. FETCH) */
const gchar *name;
- /* Folder to select */
- CamelFolder *select;
-
/* Status for command, indicates it is complete if != NULL. */
struct _status_info *status;
@@ -92,7 +90,7 @@ struct _CamelIMAPXCommand {
CamelIMAPXCommand *
camel_imapx_command_new (struct _CamelIMAPXServer *is,
const gchar *name,
- CamelFolder *select,
+ CamelIMAPXMailbox *mailbox,
const gchar *format,
...);
CamelIMAPXCommand *
@@ -105,6 +103,8 @@ struct _CamelIMAPXJob *
camel_imapx_command_get_job (CamelIMAPXCommand *ic);
void camel_imapx_command_set_job (CamelIMAPXCommand *ic,
struct _CamelIMAPXJob *job);
+CamelIMAPXMailbox *
+ camel_imapx_command_ref_mailbox (CamelIMAPXCommand *ic);
void camel_imapx_command_add (CamelIMAPXCommand *ic,
const gchar *format,
...);
diff --git a/camel/camel-imapx-folder.c b/camel/camel-imapx-folder.c
index 643d711..23b8286 100644
--- a/camel/camel-imapx-folder.c
+++ b/camel/camel-imapx-folder.c
@@ -223,9 +223,6 @@ imapx_folder_finalize (GObject *object)
{
CamelIMAPXFolder *folder = CAMEL_IMAPX_FOLDER (object);
- if (folder->ignore_recent != NULL)
- g_hash_table_unref (folder->ignore_recent);
-
g_mutex_clear (&folder->search_lock);
g_mutex_clear (&folder->stream_lock);
@@ -455,22 +452,33 @@ imapx_append_message_sync (CamelFolder *folder,
CamelStore *store;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
gboolean success = FALSE;
+ if (appended_uid != NULL)
+ *appended_uid = NULL;
+
store = camel_folder_get_parent_store (folder);
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (appended_uid != NULL)
- *appended_uid = NULL;
+ if (imapx_server == NULL)
+ goto exit;
- if (imapx_server != NULL) {
- success = camel_imapx_server_append_message (
- imapx_server, folder, message, info,
- appended_uid, cancellable, error);
- }
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+
+ if (mailbox == NULL)
+ goto exit;
+ success = camel_imapx_server_append_message (
+ imapx_server, mailbox, folder->summary,
+ CAMEL_IMAPX_FOLDER (folder)->cache, message,
+ info, appended_uid, cancellable, error);
+
+exit:
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
return success;
@@ -484,6 +492,7 @@ imapx_expunge_sync (CamelFolder *folder,
CamelStore *store;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
gboolean success = FALSE;
store = camel_folder_get_parent_store (folder);
@@ -491,11 +500,20 @@ imapx_expunge_sync (CamelFolder *folder,
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (imapx_server != NULL) {
- success = camel_imapx_server_expunge (
- imapx_server, folder, cancellable, error);
- }
+ if (imapx_server == NULL)
+ goto exit;
+
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+
+ if (mailbox == NULL)
+ goto exit;
+
+ success = camel_imapx_server_expunge (
+ imapx_server, mailbox, cancellable, error);
+exit:
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
return success;
@@ -511,6 +529,8 @@ imapx_fetch_messages_sync (CamelFolder *folder,
CamelStore *store;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
+ CamelFolderChangeInfo *changes;
gboolean success = FALSE;
store = camel_folder_get_parent_store (folder);
@@ -518,11 +538,27 @@ imapx_fetch_messages_sync (CamelFolder *folder,
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (imapx_server != NULL) {
- success = camel_imapx_server_fetch_messages (
- imapx_server, folder, type, limit, cancellable, error);
+ if (imapx_server == NULL)
+ goto exit;
+
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+
+ if (mailbox == NULL)
+ goto exit;
+
+ changes = camel_imapx_server_fetch_messages (
+ imapx_server, mailbox, type, limit, cancellable, error);
+
+ if (changes != NULL) {
+ if (camel_folder_change_info_changed (changes))
+ camel_folder_changed (folder, changes);
+ camel_folder_change_info_free (changes);
+ success = TRUE;
}
+exit:
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
return success;
@@ -554,6 +590,7 @@ imapx_get_message_sync (CamelFolder *folder,
stream = camel_data_cache_get (imapx_folder->cache, path, uid, NULL);
if (stream == NULL) {
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox;
if (offline_message) {
g_set_error (
@@ -566,11 +603,23 @@ imapx_get_message_sync (CamelFolder *folder,
imapx_server = camel_imapx_store_ref_server (
CAMEL_IMAPX_STORE (store), error);
- if (imapx_server != NULL) {
- stream = camel_imapx_server_get_message (
- imapx_server, folder, uid, cancellable, error);
+ if (imapx_server == NULL)
+ return NULL;
+
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+
+ if (mailbox == NULL) {
+ g_object_unref (imapx_server);
+ return NULL;
}
+ stream = camel_imapx_server_get_message (
+ imapx_server, mailbox, folder->summary,
+ CAMEL_IMAPX_FOLDER (folder)->cache, uid,
+ cancellable, error);
+
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
}
@@ -622,43 +671,50 @@ imapx_get_quota_info_sync (CamelFolder *folder,
CamelStore *store;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
CamelFolderQuotaInfo *quota_info = NULL;
- const gchar *folder_name;
- gchar **quota_root_names;
+ gchar **quota_roots;
gboolean success = FALSE;
store = camel_folder_get_parent_store (folder);
- folder_name = camel_folder_get_full_name (folder);
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (imapx_server != NULL) {
- success = camel_imapx_server_update_quota_info (
- imapx_server, folder_name, cancellable, error);
- }
+ if (imapx_server == NULL)
+ goto exit;
- g_clear_object (&imapx_server);
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+ if (mailbox == NULL)
+ goto exit;
+
+ success = camel_imapx_server_update_quota_info (
+ imapx_server, mailbox, cancellable, error);
if (!success)
- return NULL;
+ goto exit;
- quota_root_names = camel_imapx_folder_dup_quota_root_names (
+ quota_roots = camel_imapx_folder_dup_quota_root_names (
CAMEL_IMAPX_FOLDER (folder));
- /* XXX Just return info for the first quota root name, I guess. */
- if (quota_root_names != NULL && quota_root_names[0] != NULL)
+ /* XXX Just return info for the first quota root, I guess. */
+ if (quota_roots != NULL && quota_roots[0] != NULL) {
quota_info = camel_imapx_store_dup_quota_info (
- CAMEL_IMAPX_STORE (store),
- quota_root_names[0]);
+ CAMEL_IMAPX_STORE (store), quota_roots[0]);
+ }
- g_strfreev (quota_root_names);
+ g_strfreev (quota_roots);
if (quota_info == NULL)
g_set_error (
error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
_("No quota information available for folder '%s'"),
- folder_name);
+ camel_folder_get_full_name (folder));
+
+exit:
+ g_clear_object (&mailbox);
+ g_clear_object (&imapx_server);
return quota_info;
}
@@ -682,6 +738,8 @@ imapx_refresh_info_sync (CamelFolder *folder,
CamelStore *store;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
+ CamelFolderChangeInfo *changes;
gboolean success = FALSE;
store = camel_folder_get_parent_store (folder);
@@ -689,11 +747,27 @@ imapx_refresh_info_sync (CamelFolder *folder,
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (imapx_server != NULL) {
- success = camel_imapx_server_refresh_info (
- imapx_server, folder, cancellable, error);
+ if (imapx_server == NULL)
+ goto exit;
+
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+
+ if (mailbox == NULL)
+ goto exit;
+
+ changes = camel_imapx_server_refresh_info (
+ imapx_server, mailbox, cancellable, error);
+
+ if (changes != NULL) {
+ if (camel_folder_change_info_changed (changes))
+ camel_folder_changed (folder, changes);
+ camel_folder_change_info_free (changes);
+ success = TRUE;
}
+exit:
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
return success;
@@ -707,6 +781,8 @@ imapx_move_to_real_junk (CamelIMAPXServer *imapx_server,
gboolean *out_need_to_expunge,
GError **error)
{
+ CamelIMAPXFolder *imapx_folder;
+ CamelIMAPXMailbox *mailbox;
CamelIMAPXSettings *settings;
GPtrArray *uids_to_copy;
gchar *real_junk_path = NULL;
@@ -714,6 +790,12 @@ imapx_move_to_real_junk (CamelIMAPXServer *imapx_server,
*out_need_to_expunge = FALSE;
+ /* Caller already obtained the mailbox from the folder,
+ * so the folder should still have it readily available. */
+ imapx_folder = CAMEL_IMAPX_FOLDER (folder);
+ mailbox = camel_imapx_folder_ref_mailbox (imapx_folder);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
+
uids_to_copy = g_ptr_array_new_with_free_func (
(GDestroyNotify) camel_pstring_free);
@@ -722,19 +804,19 @@ imapx_move_to_real_junk (CamelIMAPXServer *imapx_server,
real_junk_path =
camel_imapx_settings_dup_real_junk_path (settings);
imapx_folder_claim_move_to_real_junk_uids (
- CAMEL_IMAPX_FOLDER (folder), uids_to_copy);
+ imapx_folder, uids_to_copy);
}
g_object_unref (settings);
if (uids_to_copy->len > 0) {
- CamelFolder *destination = NULL;
- CamelIMAPXStore *store;
+ CamelIMAPXStore *imapx_store;
+ CamelIMAPXMailbox *destination = NULL;
- store = camel_imapx_server_ref_store (imapx_server);
+ imapx_store = camel_imapx_server_ref_store (imapx_server);
if (real_junk_path != NULL) {
- destination = camel_store_get_folder_sync (
- CAMEL_STORE (store),
+ folder = camel_store_get_folder_sync (
+ CAMEL_STORE (imapx_store),
real_junk_path, 0,
cancellable, error);
} else {
@@ -742,15 +824,23 @@ imapx_move_to_real_junk (CamelIMAPXServer *imapx_server,
error, CAMEL_FOLDER_ERROR,
CAMEL_FOLDER_ERROR_INVALID_PATH,
_("No destination folder specified"));
+ folder = NULL;
+ }
+
+ if (folder != NULL) {
+ destination = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder),
+ cancellable, error);
+ g_object_unref (folder);
}
/* Avoid duplicating messages in the Junk folder. */
- if (destination == folder) {
+ if (destination == mailbox) {
success = TRUE;
} else if (destination != NULL) {
success = camel_imapx_server_copy_message (
imapx_server,
- folder, destination,
+ mailbox, destination,
uids_to_copy, TRUE,
cancellable, error);
*out_need_to_expunge = success;
@@ -764,12 +854,15 @@ imapx_move_to_real_junk (CamelIMAPXServer *imapx_server,
_("Unable to move junk messages"));
}
- g_object_unref (store);
+ g_clear_object (&destination);
+ g_clear_object (&imapx_store);
}
g_ptr_array_unref (uids_to_copy);
g_free (real_junk_path);
+ g_clear_object (&mailbox);
+
return success;
}
@@ -781,6 +874,8 @@ imapx_move_to_real_trash (CamelIMAPXServer *imapx_server,
gboolean *out_need_to_expunge,
GError **error)
{
+ CamelIMAPXFolder *imapx_folder;
+ CamelIMAPXMailbox *mailbox;
CamelIMAPXSettings *settings;
GPtrArray *uids_to_copy;
gchar *real_trash_path = NULL;
@@ -788,6 +883,12 @@ imapx_move_to_real_trash (CamelIMAPXServer *imapx_server,
*out_need_to_expunge = FALSE;
+ /* Caller already obtained the mailbox from the folder,
+ * so the folder should still have it readily available. */
+ imapx_folder = CAMEL_IMAPX_FOLDER (folder);
+ mailbox = camel_imapx_folder_ref_mailbox (imapx_folder);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
+
uids_to_copy = g_ptr_array_new_with_free_func (
(GDestroyNotify) camel_pstring_free);
@@ -801,14 +902,14 @@ imapx_move_to_real_trash (CamelIMAPXServer *imapx_server,
g_object_unref (settings);
if (uids_to_copy->len > 0) {
- CamelFolder *destination = NULL;
- CamelIMAPXStore *store;
+ CamelIMAPXStore *imapx_store;
+ CamelIMAPXMailbox *destination = NULL;
- store = camel_imapx_server_ref_store (imapx_server);
+ imapx_store = camel_imapx_server_ref_store (imapx_server);
if (real_trash_path != NULL) {
- destination = camel_store_get_folder_sync (
- CAMEL_STORE (store),
+ folder = camel_store_get_folder_sync (
+ CAMEL_STORE (imapx_store),
real_trash_path, 0,
cancellable, error);
} else {
@@ -816,15 +917,23 @@ imapx_move_to_real_trash (CamelIMAPXServer *imapx_server,
error, CAMEL_FOLDER_ERROR,
CAMEL_FOLDER_ERROR_INVALID_PATH,
_("No destination folder specified"));
+ folder = NULL;
+ }
+
+ if (folder != NULL) {
+ destination = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder),
+ cancellable, error);
+ g_object_unref (folder);
}
/* Avoid duplicating messages in the Trash folder. */
- if (destination == folder) {
+ if (destination == mailbox) {
success = TRUE;
} else if (destination != NULL) {
success = camel_imapx_server_copy_message (
imapx_server,
- folder, destination,
+ mailbox, destination,
uids_to_copy, TRUE,
cancellable, error);
*out_need_to_expunge = success;
@@ -838,12 +947,15 @@ imapx_move_to_real_trash (CamelIMAPXServer *imapx_server,
_("Unable to move deleted messages"));
}
- g_object_unref (store);
+ g_clear_object (&destination);
+ g_clear_object (&imapx_store);
}
g_ptr_array_unref (uids_to_copy);
g_free (real_trash_path);
+ g_clear_object (&mailbox);
+
return success;
}
@@ -856,6 +968,8 @@ imapx_synchronize_sync (CamelFolder *folder,
CamelStore *store;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
+ gboolean need_to_expunge;
gboolean success = FALSE;
store = camel_folder_get_parent_store (folder);
@@ -863,34 +977,41 @@ imapx_synchronize_sync (CamelFolder *folder,
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (imapx_server != NULL) {
- gboolean need_to_expunge;
+ if (imapx_server == NULL)
+ goto exit;
- success = camel_imapx_server_sync_changes (
- imapx_server, folder, cancellable, error);
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+ if (mailbox == NULL)
+ goto exit;
- if (success) {
- success = imapx_move_to_real_junk (
- imapx_server, folder, cancellable,
- &need_to_expunge, error);
- expunge |= need_to_expunge;
- }
+ success = camel_imapx_server_sync_changes (
+ imapx_server, mailbox, cancellable, error);
- if (success) {
- success = imapx_move_to_real_trash (
- imapx_server, folder, cancellable,
- &need_to_expunge, error);
- expunge |= need_to_expunge;
- }
+ if (success) {
+ success = imapx_move_to_real_junk (
+ imapx_server, folder, cancellable,
+ &need_to_expunge, error);
+ expunge |= need_to_expunge;
+ }
+
+ if (success) {
+ success = imapx_move_to_real_trash (
+ imapx_server, folder, cancellable,
+ &need_to_expunge, error);
+ expunge |= need_to_expunge;
+ }
- /* Sync twice - make sure deleted flags are written out,
- * then sync again incase expunge changed anything */
+ /* Sync twice - make sure deleted flags are written out,
+ * then sync again incase expunge changed anything */
- if (success && expunge)
- success = camel_imapx_server_expunge (
- imapx_server, folder, cancellable, error);
+ if (success && expunge) {
+ success = camel_imapx_server_expunge (
+ imapx_server, mailbox, cancellable, error);
}
+exit:
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
return success;
@@ -905,6 +1026,7 @@ imapx_synchronize_message_sync (CamelFolder *folder,
CamelStore *store;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
gboolean success = FALSE;
store = camel_folder_get_parent_store (folder);
@@ -912,11 +1034,22 @@ imapx_synchronize_message_sync (CamelFolder *folder,
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (imapx_server != NULL) {
- success = camel_imapx_server_sync_message (
- imapx_server, folder, uid, cancellable, error);
- }
+ if (imapx_server == NULL)
+ goto exit;
+
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+
+ if (mailbox == NULL)
+ goto exit;
+
+ success = camel_imapx_server_sync_message (
+ imapx_server, mailbox, folder->summary,
+ CAMEL_IMAPX_FOLDER (folder)->cache, uid,
+ cancellable, error);
+exit:
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
return success;
@@ -934,6 +1067,8 @@ imapx_transfer_messages_to_sync (CamelFolder *source,
CamelStore *store;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *src_mailbox = NULL;
+ CamelIMAPXMailbox *dst_mailbox = NULL;
gboolean success = FALSE;
store = camel_folder_get_parent_store (source);
@@ -941,18 +1076,34 @@ imapx_transfer_messages_to_sync (CamelFolder *source,
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (imapx_server != NULL) {
- success = camel_imapx_server_copy_message (
- imapx_server, source, dest, uids,
- delete_originals, cancellable, error);
+ if (imapx_server == NULL)
+ goto exit;
- /* Update destination folder only if it's not frozen,
- * to avoid updating for each "move" action on a single
- * message while filtering. */
- if (!camel_folder_is_frozen (dest))
- imapx_refresh_info_sync (dest, cancellable, NULL);
- }
+ src_mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (source), cancellable, error);
+
+ if (src_mailbox == NULL)
+ goto exit;
+
+ dst_mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (dest), cancellable, error);
+ if (dst_mailbox == NULL)
+ goto exit;
+
+ success = camel_imapx_server_copy_message (
+ imapx_server, src_mailbox, dst_mailbox, uids,
+ delete_originals, cancellable, error);
+
+ /* Update destination folder only if it's not frozen,
+ * to avoid updating for each "move" action on a single
+ * message while filtering. */
+ if (!camel_folder_is_frozen (dest))
+ imapx_refresh_info_sync (dest, cancellable, NULL);
+
+exit:
+ g_clear_object (&src_mailbox);
+ g_clear_object (&dst_mailbox);
g_clear_object (&imapx_server);
return success;
@@ -1161,11 +1312,6 @@ camel_imapx_folder_new (CamelStore *store,
imapx_folder->search = camel_imapx_search_new ();
g_mutex_init (&imapx_folder->search_lock);
g_mutex_init (&imapx_folder->stream_lock);
- imapx_folder->ignore_recent = g_hash_table_new_full (
- (GHashFunc) g_str_hash,
- (GEqualFunc) g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) NULL);
imapx_folder->exists_on_server = 0;
imapx_folder->unread_on_server = 0;
imapx_folder->modseq_on_server = 0;
diff --git a/camel/camel-imapx-folder.h b/camel/camel-imapx-folder.h
index f2120f0..48e4870 100644
--- a/camel/camel-imapx-folder.h
+++ b/camel/camel-imapx-folder.h
@@ -74,9 +74,6 @@ struct _CamelIMAPXFolder {
guint64 uidvalidity_on_server;
guint32 uidnext_on_server;
- /* hash table of UIDs to ignore as recent when updating folder */
- GHashTable *ignore_recent;
-
GMutex search_lock;
GMutex stream_lock;
diff --git a/camel/camel-imapx-job.c b/camel/camel-imapx-job.c
index 49c3988..07e09a3 100644
--- a/camel/camel-imapx-job.c
+++ b/camel/camel-imapx-job.c
@@ -20,6 +20,8 @@
#include <string.h>
+#include <camel/camel-imapx-folder.h>
+
typedef struct _CamelIMAPXRealJob CamelIMAPXRealJob;
/* CamelIMAPXJob + some private bits */
@@ -43,8 +45,8 @@ struct _CamelIMAPXRealJob {
gpointer data;
GDestroyNotify destroy_data;
- CamelFolder *folder;
- GMutex folder_lock;
+ CamelIMAPXMailbox *mailbox;
+ GMutex mailbox_lock;
};
static void
@@ -75,7 +77,7 @@ camel_imapx_job_new (GCancellable *cancellable)
g_object_ref (cancellable);
real_job->cancellable = cancellable;
- g_mutex_init (&real_job->folder_lock);
+ g_mutex_init (&real_job->mailbox_lock);
return (CamelIMAPXJob *) real_job;
}
@@ -123,9 +125,8 @@ camel_imapx_job_unref (CamelIMAPXJob *job)
if (real_job->destroy_data != NULL)
real_job->destroy_data (real_job->data);
- if (real_job->folder != NULL)
- g_object_unref (real_job->folder);
- g_mutex_clear (&real_job->folder_lock);
+ g_clear_object (&real_job->mailbox);
+ g_mutex_clear (&real_job->mailbox_lock);
/* Fill the memory with a bit pattern before releasing
* it back to the slab allocator, so we can more easily
@@ -265,21 +266,21 @@ camel_imapx_job_run (CamelIMAPXJob *job,
gboolean
camel_imapx_job_matches (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid)
{
- /* XXX CamelFolder can be NULL. I'm less sure about the
- * message UID but let's assume that can be NULL too. */
+ /* XXX CamelIMAPXMailbox can be NULL. I'm less sure about
+ * the message UID but let's assume that can be NULL too. */
g_return_val_if_fail (CAMEL_IS_IMAPX_JOB (job), FALSE);
- if (folder != NULL)
- g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+ if (mailbox != NULL)
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
if (job->matches == NULL)
return FALSE;
- return job->matches (job, folder, uid);
+ return job->matches (job, mailbox, uid);
}
gpointer
@@ -313,47 +314,47 @@ camel_imapx_job_set_data (CamelIMAPXJob *job,
}
gboolean
-camel_imapx_job_has_folder (CamelIMAPXJob *job,
- CamelFolder *folder)
+camel_imapx_job_has_mailbox (CamelIMAPXJob *job,
+ CamelIMAPXMailbox *mailbox)
{
CamelIMAPXRealJob *real_job;
g_return_val_if_fail (CAMEL_IS_IMAPX_JOB (job), FALSE);
- if (folder != NULL)
- g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+ if (mailbox != NULL)
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
real_job = (CamelIMAPXRealJob *) job;
/* Not necessary to lock the mutex since
* we're just comparing memory addresses. */
- return (folder == real_job->folder);
+ return (mailbox == real_job->mailbox);
}
-CamelFolder *
-camel_imapx_job_ref_folder (CamelIMAPXJob *job)
+CamelIMAPXMailbox *
+camel_imapx_job_ref_mailbox (CamelIMAPXJob *job)
{
CamelIMAPXRealJob *real_job;
- CamelFolder *folder = NULL;
+ CamelIMAPXMailbox *mailbox = NULL;
g_return_val_if_fail (CAMEL_IS_IMAPX_JOB (job), NULL);
real_job = (CamelIMAPXRealJob *) job;
- g_mutex_lock (&real_job->folder_lock);
+ g_mutex_lock (&real_job->mailbox_lock);
- if (real_job->folder != NULL)
- folder = g_object_ref (real_job->folder);
+ if (real_job->mailbox != NULL)
+ mailbox = g_object_ref (real_job->mailbox);
- g_mutex_unlock (&real_job->folder_lock);
+ g_mutex_unlock (&real_job->mailbox_lock);
- return folder;
+ return mailbox;
}
void
-camel_imapx_job_set_folder (CamelIMAPXJob *job,
- CamelFolder *folder)
+camel_imapx_job_set_mailbox (CamelIMAPXJob *job,
+ CamelIMAPXMailbox *mailbox)
{
CamelIMAPXRealJob *real_job;
@@ -361,19 +362,17 @@ camel_imapx_job_set_folder (CamelIMAPXJob *job,
real_job = (CamelIMAPXRealJob *) job;
- if (folder != NULL) {
- g_return_if_fail (CAMEL_IS_FOLDER (folder));
- g_object_ref (folder);
+ if (mailbox != NULL) {
+ g_return_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox));
+ g_object_ref (mailbox);
}
- g_mutex_lock (&real_job->folder_lock);
-
- if (real_job->folder != NULL)
- g_object_unref (real_job->folder);
+ g_mutex_lock (&real_job->mailbox_lock);
- real_job->folder = folder;
+ g_clear_object (&real_job->mailbox);
+ real_job->mailbox = mailbox;
- g_mutex_unlock (&real_job->folder_lock);
+ g_mutex_unlock (&real_job->mailbox_lock);
}
GCancellable *
diff --git a/camel/camel-imapx-job.h b/camel/camel-imapx-job.h
index 4b57864..840385b 100644
--- a/camel/camel-imapx-job.h
+++ b/camel/camel-imapx-job.h
@@ -49,7 +49,7 @@ struct _CamelIMAPXJob {
GCancellable *cancellable,
GError **error);
gboolean (*matches) (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid);
guint noreply:1; /* dont wait for reply */
@@ -70,17 +70,18 @@ gboolean camel_imapx_job_run (CamelIMAPXJob *job,
CamelIMAPXServer *is,
GError **error);
gboolean camel_imapx_job_matches (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid);
gpointer camel_imapx_job_get_data (CamelIMAPXJob *job);
void camel_imapx_job_set_data (CamelIMAPXJob *job,
gpointer data,
GDestroyNotify destroy_data);
-gboolean camel_imapx_job_has_folder (CamelIMAPXJob *job,
- CamelFolder *folder);
-CamelFolder * camel_imapx_job_ref_folder (CamelIMAPXJob *job);
-void camel_imapx_job_set_folder (CamelIMAPXJob *job,
- CamelFolder *folder);
+gboolean camel_imapx_job_has_mailbox (CamelIMAPXJob *job,
+ CamelIMAPXMailbox *mailbox);
+CamelIMAPXMailbox *
+ camel_imapx_job_ref_mailbox (CamelIMAPXJob *job);
+void camel_imapx_job_set_mailbox (CamelIMAPXJob *job,
+ CamelIMAPXMailbox *mailbox);
GCancellable * camel_imapx_job_get_cancellable (CamelIMAPXJob *job);
void camel_imapx_job_take_error (CamelIMAPXJob *job,
GError *error);
diff --git a/camel/camel-imapx-search.c b/camel/camel-imapx-search.c
index cae7792..8b46de4 100644
--- a/camel/camel-imapx-search.c
+++ b/camel/camel-imapx-search.c
@@ -94,10 +94,11 @@ imapx_search_body_contains (CamelSExp *sexp,
CamelFolderSearch *search)
{
CamelIMAPXServer *server;
+ CamelIMAPXMailbox *mailbox;
CamelSExpResult *result;
CamelSExpResultType type;
GString *criteria;
- GPtrArray *uids;
+ GPtrArray *uids = NULL;
gint ii, jj;
GError *error = NULL;
@@ -157,8 +158,19 @@ imapx_search_body_contains (CamelSExp *sexp,
}
}
- uids = camel_imapx_server_uid_search (
- server, search->folder, criteria->str, NULL, &error);
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (search->folder), NULL, &error);
+
+ /* Sanity check. */
+ g_return_val_if_fail (
+ ((mailbox != NULL) && (error == NULL)) ||
+ ((mailbox == NULL) && (error != NULL)), NULL);
+
+ if (mailbox != NULL) {
+ uids = camel_imapx_server_uid_search (
+ server, mailbox, criteria->str, NULL, &error);
+ g_object_unref (mailbox);
+ }
/* Sanity check. */
g_return_val_if_fail (
diff --git a/camel/camel-imapx-server.c b/camel/camel-imapx-server.c
index 731e613..0b5bc32 100644
--- a/camel/camel-imapx-server.c
+++ b/camel/camel-imapx-server.c
@@ -71,14 +71,13 @@ typedef struct _CopyMessagesData CopyMessagesData;
typedef struct _ListData ListData;
typedef struct _ManageSubscriptionsData ManageSubscriptionsData;
typedef struct _RenameFolderData RenameFolderData;
-typedef struct _CreateFolderData CreateFolderData;
-typedef struct _DeleteFolderData DeleteFolderData;
-typedef struct _QuotaData QuotaData;
+typedef struct _CreateMailboxData CreateMailboxData;
typedef struct _SearchData SearchData;
struct _GetMessageData {
/* in: uid requested */
gchar *uid;
+ CamelDataCache *message_cache;
/* in/out: message content stream output */
CamelStream *stream;
/* working variables */
@@ -126,7 +125,7 @@ struct _AppendMessageData {
};
struct _CopyMessagesData {
- CamelFolder *dest;
+ CamelIMAPXMailbox *destination;
GPtrArray *uids;
gboolean delete_originals;
gboolean use_move_command;
@@ -143,7 +142,6 @@ struct _ListData {
};
struct _ManageSubscriptionsData {
- gchar *folder_name;
gboolean subscribe;
};
@@ -152,12 +150,8 @@ struct _RenameFolderData {
gchar *new_folder_name;
};
-struct _CreateFolderData {
- gchar *folder_name;
-};
-
-struct _DeleteFolderData {
- gchar *folder_name;
+struct _CreateMailboxData {
+ gchar *utf7_mailbox_name;
};
struct _SearchData {
@@ -165,10 +159,6 @@ struct _SearchData {
GArray *results;
};
-struct _QuotaData {
- gchar *folder_name;
-};
-
/* untagged response handling */
/* May need to turn this into separate,
@@ -334,16 +324,10 @@ struct _CamelIMAPXServerPrivate {
/* Info on currently selected folder. */
GMutex select_lock;
- GWeakRef select_folder;
+ GWeakRef select_mailbox;
GWeakRef select_pending;
CamelFolderChangeInfo *changes;
guint32 permanentflags;
- guint32 unseen;
- guint64 uidvalidity;
- guint64 highestmodseq;
- guint32 uidnext;
- guint32 exists;
- guint32 recent;
/* Data items to request in STATUS commands:
* STATUS $mailbox_name ($status_data_items) */
@@ -483,7 +467,7 @@ static gint imapx_refresh_info_uid_cmp (gconstpointer ap,
static gint imapx_uids_array_cmp (gconstpointer ap,
gconstpointer bp);
static gboolean imapx_server_sync_changes (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
guint32 job_type,
gint pri,
GCancellable *cancellable,
@@ -538,13 +522,13 @@ static CamelIMAPXIdleStopResult
CamelIMAPXStream *stream,
GError **error);
static gboolean camel_imapx_server_idle (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error);
static void imapx_maybe_select (CamelIMAPXServer *is,
CamelIMAPXJob *job,
- CamelFolder *folder);
+ CamelIMAPXMailbox *mailbox);
G_DEFINE_TYPE (CamelIMAPXServer, camel_imapx_server, CAMEL_TYPE_OBJECT)
@@ -610,8 +594,8 @@ get_message_data_free (GetMessageData *data)
{
g_free (data->uid);
- if (data->stream != NULL)
- g_object_unref (data->stream);
+ g_clear_object (&data->message_cache);
+ g_clear_object (&data->stream);
g_slice_free (GetMessageData, data);
}
@@ -638,7 +622,9 @@ refresh_info_data_infos_free (RefreshInfoData *data)
static void
refresh_info_data_free (RefreshInfoData *data)
{
- camel_folder_change_info_free (data->changes);
+ if (data->changes != NULL)
+ camel_folder_change_info_free (data->changes);
+
refresh_info_data_infos_free (data);
g_slice_free (RefreshInfoData, data);
@@ -672,8 +658,7 @@ append_message_data_free (AppendMessageData *data)
static void
copy_messages_data_free (CopyMessagesData *data)
{
- if (data->dest != NULL)
- g_object_unref (data->dest);
+ g_clear_object (&data->destination);
if (data->uids != NULL) {
g_ptr_array_foreach (data->uids, (GFunc) g_free, NULL);
@@ -697,8 +682,6 @@ list_data_free (ListData *data)
static void
manage_subscriptions_data_free (ManageSubscriptionsData *data)
{
- g_free (data->folder_name);
-
g_slice_free (ManageSubscriptionsData, data);
}
@@ -712,19 +695,11 @@ rename_folder_data_free (RenameFolderData *data)
}
static void
-create_folder_data_free (CreateFolderData *data)
-{
- g_free (data->folder_name);
-
- g_slice_free (CreateFolderData, data);
-}
-
-static void
-delete_folder_data_free (DeleteFolderData *data)
+create_mailbox_data_free (CreateMailboxData *data)
{
- g_free (data->folder_name);
+ g_free (data->utf7_mailbox_name);
- g_slice_free (DeleteFolderData, data);
+ g_slice_free (CreateMailboxData, data);
}
static void
@@ -738,14 +713,6 @@ search_data_free (SearchData *data)
g_slice_free (SearchData, data);
}
-static void
-quota_data_free (QuotaData *data)
-{
- g_free (data->folder_name);
-
- g_slice_free (QuotaData, data);
-}
-
/*
this creates a uid (or sequence number) set directly into a command,
if total is set, then we break it up into total uids. (i.e. command time)
@@ -832,6 +799,47 @@ imapx_uidset_add (struct _uidset_state *ss,
return 0;
}
+static CamelFolder *
+imapx_server_ref_folder (CamelIMAPXServer *is,
+ CamelIMAPXMailbox *mailbox)
+{
+ CamelFolder *folder;
+ CamelIMAPXStore *store;
+ const gchar *mailbox_name;
+ gchar *folder_path;
+ gchar separator;
+ GError *local_error = NULL;
+
+ mailbox_name = camel_imapx_mailbox_get_name (mailbox);
+ separator = camel_imapx_mailbox_get_separator (mailbox);
+
+ store = camel_imapx_server_ref_store (is);
+
+ folder_path = camel_imapx_mailbox_to_folder_path (
+ mailbox_name, separator);
+
+ folder = camel_store_get_folder_sync (
+ CAMEL_STORE (store), folder_path, 0, NULL, &local_error);
+
+ g_free (folder_path);
+
+ g_object_unref (store);
+
+ /* Sanity check. */
+ g_warn_if_fail (
+ ((folder != NULL) && (local_error == NULL)) ||
+ ((folder == NULL) && (local_error != NULL)));
+
+ if (local_error != NULL) {
+ g_warning (
+ "%s: Failed to get folder for '%s': %s",
+ G_STRFUNC, mailbox_name, local_error->message);
+ g_error_free (local_error);
+ }
+
+ return folder;
+}
+
static void
imapx_server_stash_command_arguments (CamelIMAPXServer *is)
{
@@ -1202,7 +1210,7 @@ static void
imapx_command_start_next (CamelIMAPXServer *is)
{
CamelIMAPXCommand *first_ic;
- CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
gint min_pri = -128;
c (is->tagprefix, "** Starting next command\n");
@@ -1214,20 +1222,21 @@ imapx_command_start_next (CamelIMAPXServer *is)
return;
}
- folder = g_weak_ref_get (&is->priv->select_pending);
- if (folder != NULL) {
+ mailbox = g_weak_ref_get (&is->priv->select_pending);
+ if (mailbox != NULL) {
GQueue start = G_QUEUE_INIT;
GList *head, *link;
c (
is->tagprefix,
- "-- Checking job queue for non-folder jobs\n");
+ "-- Checking job queue for non-mailbox jobs\n");
head = camel_imapx_command_queue_peek_head_link (is->queue);
/* Tag which commands in the queue to start. */
for (link = head; link != NULL; link = g_list_next (link)) {
CamelIMAPXCommand *ic = link->data;
+ CamelIMAPXMailbox *ic_mailbox;
if (ic->pri < min_pri)
break;
@@ -1236,7 +1245,10 @@ imapx_command_start_next (CamelIMAPXServer *is)
is->tagprefix,
"-- %3d '%s'?\n",
(gint) ic->pri, ic->name);
- if (!ic->select) {
+
+ ic_mailbox = camel_imapx_command_ref_mailbox (ic);
+
+ if (ic_mailbox == NULL) {
c (
is->tagprefix,
"--> starting '%s'\n",
@@ -1245,6 +1257,8 @@ imapx_command_start_next (CamelIMAPXServer *is)
g_queue_push_tail (&start, link);
}
+ g_clear_object (&ic_mailbox);
+
if (g_queue_get_length (&start) == MAX_COMMANDS)
break;
}
@@ -1253,7 +1267,7 @@ imapx_command_start_next (CamelIMAPXServer *is)
c (
is->tagprefix,
"* no, waiting for pending select '%s'\n",
- camel_folder_get_full_name (folder));
+ camel_imapx_mailbox_get_name (mailbox));
/* Start the tagged commands.
*
@@ -1273,7 +1287,7 @@ imapx_command_start_next (CamelIMAPXServer *is)
g_queue_clear (&start);
}
- g_clear_object (&folder);
+ g_clear_object (&mailbox);
return;
}
@@ -1334,8 +1348,8 @@ imapx_command_start_next (CamelIMAPXServer *is)
}
/* See if any queued jobs on this select first */
- folder = g_weak_ref_get (&is->priv->select_folder);
- if (folder != NULL) {
+ mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+ if (mailbox != NULL) {
GQueue start = G_QUEUE_INIT;
GList *head, *link;
gboolean commands_started = FALSE;
@@ -1343,7 +1357,7 @@ imapx_command_start_next (CamelIMAPXServer *is)
c (
is->tagprefix,
"- we're selected on '%s', current jobs?\n",
- camel_folder_get_full_name (folder));
+ camel_imapx_mailbox_get_name (mailbox));
head = camel_imapx_command_queue_peek_head_link (is->active);
@@ -1363,7 +1377,7 @@ imapx_command_start_next (CamelIMAPXServer *is)
is->tagprefix,
"** too many jobs busy, "
"waiting for results for now\n");
- g_object_unref (folder);
+ g_object_unref (mailbox);
return;
}
@@ -1374,6 +1388,7 @@ imapx_command_start_next (CamelIMAPXServer *is)
/* Tag which commands in the queue to start. */
for (link = head; link != NULL; link = g_list_next (link)) {
CamelIMAPXCommand *ic = link->data;
+ CamelIMAPXMailbox *ic_mailbox;
gboolean okay_to_start;
if (is->literal != NULL)
@@ -1387,9 +1402,11 @@ imapx_command_start_next (CamelIMAPXServer *is)
"-- %3d '%s'?\n",
(gint) ic->pri, ic->name);
+ ic_mailbox = camel_imapx_command_ref_mailbox (ic);
+
okay_to_start =
- (ic->select == NULL) ||
- (ic->select == folder &&
+ (ic_mailbox == NULL) ||
+ (ic_mailbox == mailbox &&
!imapx_is_duplicate_fetch_or_refresh (is, ic));
if (okay_to_start) {
@@ -1400,18 +1417,20 @@ imapx_command_start_next (CamelIMAPXServer *is)
min_pri = ic->pri;
g_queue_push_tail (&start, link);
} else {
- /* This job isn't for the selected folder,
+ /* This job isn't for the selected mailbox,
* but we don't want to consider jobs with
* lower priority than this, even if they
- * are for the selected folder. */
+ * are for the selected mailbox. */
min_pri = ic->pri;
}
+ g_clear_object (&ic_mailbox);
+
if (g_queue_get_length (&start) == MAX_COMMANDS)
break;
}
- g_clear_object (&folder);
+ g_clear_object (&mailbox);
/* Start the tagged commands.
*
@@ -1441,22 +1460,25 @@ imapx_command_start_next (CamelIMAPXServer *is)
/* This won't be NULL because we checked for an empty queue above. */
first_ic = camel_imapx_command_queue_peek_head (is->queue);
- /* If we need to select a folder for the first command, do
+ /* If we need to select a mailbox for the first command, do
* so now. It will re-call us if it completes successfully. */
- if (first_ic->select) {
+ mailbox = camel_imapx_command_ref_mailbox (first_ic);
+ if (mailbox != NULL) {
CamelIMAPXJob *job;
c (
is->tagprefix,
- "Selecting folder '%s' for command '%s'(%p)\n",
- camel_folder_get_full_name (first_ic->select),
+ "Selecting mailbox '%s' for command '%s'(%p)\n",
+ camel_imapx_mailbox_get_name (mailbox),
first_ic->name, first_ic);
/* Associate the SELECT command with the CamelIMAPXJob
* that triggered it. Then if the SELECT command fails
* we have some destination to propagate the GError to. */
job = camel_imapx_command_get_job (first_ic);
- imapx_maybe_select (is, job, first_ic->select);
+ imapx_maybe_select (is, job, mailbox);
+
+ g_clear_object (&mailbox);
} else {
GQueue start = G_QUEUE_INIT;
@@ -1464,13 +1486,14 @@ imapx_command_start_next (CamelIMAPXServer *is)
min_pri = first_ic->pri;
- folder = g_weak_ref_get (&is->priv->select_folder);
+ mailbox = g_weak_ref_get (&is->priv->select_mailbox);
head = camel_imapx_command_queue_peek_head_link (is->queue);
/* Tag which commands in the queue to start. */
for (link = head; link != NULL; link = g_list_next (link)) {
CamelIMAPXCommand *ic = link->data;
+ CamelIMAPXMailbox *ic_mailbox;
gboolean okay_to_start;
if (is->literal != NULL)
@@ -1479,9 +1502,11 @@ imapx_command_start_next (CamelIMAPXServer *is)
if (ic->pri < min_pri)
break;
+ ic_mailbox = camel_imapx_command_ref_mailbox (ic);
+
okay_to_start =
- (ic->select == NULL) ||
- (ic->select == folder &&
+ (ic_mailbox == NULL) ||
+ (ic_mailbox == mailbox &&
!imapx_is_duplicate_fetch_or_refresh (is, ic));
if (okay_to_start) {
@@ -1493,11 +1518,13 @@ imapx_command_start_next (CamelIMAPXServer *is)
g_queue_push_tail (&start, link);
}
+ g_clear_object (&ic_mailbox);
+
if (g_queue_get_length (&start) == MAX_COMMANDS)
break;
}
- g_clear_object (&folder);
+ g_clear_object (&mailbox);
/* Start the tagged commands.
*
@@ -1594,7 +1621,7 @@ imapx_match_active_job (CamelIMAPXServer *is,
for (link = head; link != NULL; link = g_list_next (link)) {
CamelIMAPXCommand *ic = link->data;
- CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
CamelIMAPXJob *job;
gboolean job_matches;
@@ -1606,9 +1633,9 @@ imapx_match_active_job (CamelIMAPXServer *is,
if (!(job->type & type))
continue;
- folder = g_weak_ref_get (&is->priv->select_folder);
- job_matches = camel_imapx_job_matches (job, folder, uid);
- g_clear_object (&folder);
+ mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+ job_matches = camel_imapx_job_matches (job, mailbox, uid);
+ g_clear_object (&mailbox);
if (job_matches) {
match = job;
@@ -1623,7 +1650,7 @@ imapx_match_active_job (CamelIMAPXServer *is,
static CamelIMAPXJob *
imapx_is_job_in_queue (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
guint32 type,
const gchar *uid)
{
@@ -1641,7 +1668,7 @@ imapx_is_job_in_queue (CamelIMAPXServer *is,
if (!job || !(job->type & type))
continue;
- if (camel_imapx_job_matches (job, folder, uid)) {
+ if (camel_imapx_job_matches (job, mailbox, uid)) {
found = TRUE;
break;
}
@@ -1658,16 +1685,20 @@ imapx_expunge_uid_from_summary (CamelIMAPXServer *is,
gboolean unsolicited)
{
CamelFolder *folder;
- CamelIMAPXFolder *ifolder;
+ CamelIMAPXMailbox *mailbox;
CamelMessageInfo *mi;
+ guint32 messages;
+
+ mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+ g_return_if_fail (mailbox != NULL);
- folder = g_weak_ref_get (&is->priv->select_folder);
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_if_fail (folder != NULL);
- ifolder = CAMEL_IMAPX_FOLDER (folder);
+ messages = camel_imapx_mailbox_get_messages (mailbox);
- if (unsolicited && ifolder->exists_on_server)
- ifolder->exists_on_server--;
+ if (unsolicited && messages > 0)
+ camel_imapx_mailbox_set_messages (mailbox, messages - 1);
if (is->priv->changes == NULL)
is->priv->changes = camel_folder_change_info_new ();
@@ -1691,6 +1722,7 @@ imapx_expunge_uid_from_summary (CamelIMAPXServer *is,
}
g_object_unref (folder);
+ g_object_unref (mailbox);
}
/* untagged response handler functions */
@@ -1723,7 +1755,7 @@ imapx_untagged_expunge (CamelIMAPXServer *is,
GCancellable *cancellable,
GError **error)
{
- CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
CamelIMAPXJob *job = NULL;
guint32 expunge = 0;
@@ -1738,17 +1770,23 @@ imapx_untagged_expunge (CamelIMAPXServer *is,
c (is->tagprefix, "expunged: %lu\n", is->priv->context->id);
- folder = g_weak_ref_get (&is->priv->select_folder);
+ mailbox = g_weak_ref_get (&is->priv->select_mailbox);
- if (folder != NULL) {
+ if (mailbox != NULL) {
+ CamelFolder *folder;
gchar *uid;
- uid = camel_imapx_dup_uid_from_summary_index (folder, expunge - 1);
+ folder = imapx_server_ref_folder (is, mailbox);
+ g_return_val_if_fail (folder != NULL, FALSE);
+
+ uid = camel_imapx_dup_uid_from_summary_index (
+ folder, expunge - 1);
if (uid != NULL)
imapx_expunge_uid_from_summary (is, uid, TRUE);
g_object_unref (folder);
+ g_object_unref (mailbox);
}
return TRUE;
@@ -1761,6 +1799,7 @@ imapx_untagged_vanished (CamelIMAPXServer *is,
GError **error)
{
CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
GPtrArray *uids = NULL;
GList *uid_list = NULL;
gboolean unsolicited = TRUE;
@@ -1792,23 +1831,31 @@ imapx_untagged_vanished (CamelIMAPXServer *is,
if (uids == NULL)
return FALSE;
- folder = g_weak_ref_get (&is->priv->select_folder);
+ mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_val_if_fail (folder != NULL, FALSE);
if (unsolicited) {
- CamelIMAPXFolder *ifolder = CAMEL_IMAPX_FOLDER (folder);
+ guint32 messages;
- if (ifolder->exists_on_server < uids->len) {
+ messages = camel_imapx_mailbox_get_messages (mailbox);
+
+ if (messages < uids->len) {
c (
is->tagprefix,
- "Error: exists_on_folder %d is "
- "fewer than vanished %d\n",
- ifolder->exists_on_server,
- uids->len);
- ifolder->exists_on_server = 0;
- } else
- ifolder->exists_on_server -= uids->len;
+ "Error: mailbox messages (%u) is "
+ "fewer than vanished %u\n",
+ messages, uids->len);
+ messages = 0;
+ } else {
+ messages -= uids->len;
+ }
+
+ camel_imapx_mailbox_set_messages (mailbox, messages);
}
+
if (is->priv->changes == NULL)
is->priv->changes = camel_folder_change_info_new ();
@@ -1841,6 +1888,7 @@ imapx_untagged_vanished (CamelIMAPXServer *is,
g_ptr_array_free (uids, TRUE);
g_object_unref (folder);
+ g_object_unref (mailbox);
return TRUE;
}
@@ -1961,35 +2009,42 @@ imapx_untagged_exists (CamelIMAPXServer *is,
GError **error)
{
CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
+ guint32 exists;
gboolean success = TRUE;
g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
- c (is->tagprefix, "exists: %lu\n", is->priv->context->id);
- is->priv->exists = is->priv->context->id;
+ mailbox = camel_imapx_server_ref_selected (is);
- folder = g_weak_ref_get (&is->priv->select_folder);
+ if (mailbox == NULL) {
+ g_warning ("%s: No mailbox available", G_STRFUNC);
+ return TRUE;
+ }
- if (folder != NULL) {
- CAMEL_IMAPX_FOLDER (folder)->exists_on_server =
- is->priv->context->id;
+ exists = (guint32) is->priv->context->id;
- if (imapx_in_idle (is)) {
- guint count;
+ camel_imapx_mailbox_set_messages (mailbox, exists);
- count = camel_folder_summary_count (folder->summary);
- if (count < is->priv->context->id) {
- CamelIMAPXIdleStopResult stop_result;
+ folder = imapx_server_ref_folder (is, mailbox);
+ g_return_val_if_fail (folder != NULL, FALSE);
- stop_result =
- imapx_stop_idle (is, stream, error);
- success = (stop_result != IMAPX_IDLE_STOP_ERROR);
- }
- }
+ if (imapx_in_idle (is)) {
+ guint count;
- g_object_unref (folder);
+ count = camel_folder_summary_count (folder->summary);
+ if (count < exists) {
+ CamelIMAPXIdleStopResult stop_result;
+
+ stop_result =
+ imapx_stop_idle (is, stream, error);
+ success = (stop_result != IMAPX_IDLE_STOP_ERROR);
+ }
}
+ g_object_unref (folder);
+ g_object_unref (mailbox);
+
return success;
}
@@ -2064,8 +2119,8 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
if ((finfo->got & FETCH_FLAGS) && !(finfo->got & FETCH_HEADER)) {
CamelIMAPXJob *job;
- CamelFolder *select_folder;
- CamelFolder *select_pending;
+ CamelIMAPXMailbox *select_mailbox;
+ CamelIMAPXMailbox *select_pending;
RefreshInfoData *data = NULL;
job = imapx_match_active_job (
@@ -2079,7 +2134,7 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
}
g_mutex_lock (&is->priv->select_lock);
- select_folder = g_weak_ref_get (&is->priv->select_folder);
+ select_mailbox = g_weak_ref_get (&is->priv->select_mailbox);
select_pending = g_weak_ref_get (&is->priv->select_pending);
g_mutex_unlock (&is->priv->select_lock);
@@ -2097,13 +2152,18 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
r.exists = FALSE;
g_array_append_val (data->infos, r);
- } else if (select_folder != NULL) {
+ } else if (select_mailbox != NULL) {
+ CamelFolder *select_folder;
CamelMessageInfo *mi = NULL;
gboolean changed = FALSE;
gchar *uid = NULL;
c (is->tagprefix, "flag changed: %lu\n", is->priv->context->id);
+ select_folder =
+ imapx_server_ref_folder (is, select_mailbox);
+ g_return_val_if_fail (select_folder != NULL, FALSE);
+
if (finfo->got & FETCH_UID) {
uid = finfo->uid;
finfo->uid = NULL;
@@ -2155,9 +2215,11 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
if (mi)
camel_message_info_free (mi);
+
+ g_object_unref (select_folder);
}
- g_clear_object (&select_folder);
+ g_clear_object (&select_mailbox);
g_clear_object (&select_pending);
}
@@ -2173,13 +2235,24 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
IMAPX_JOB_FETCH_MESSAGES, NULL);
if (job != NULL) {
+ CamelIMAPXMailbox *mailbox;
CamelFolder *folder;
CamelMimeParser *mp;
CamelMessageInfo *mi;
+ guint32 messages;
+ guint32 unseen;
+ guint32 uidnext;
+
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_val_if_fail (folder != NULL, FALSE);
+ messages = camel_imapx_mailbox_get_messages (mailbox);
+ unseen = camel_imapx_mailbox_get_unseen (mailbox);
+ uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
+
/* Do we want to save these headers for later too? Do we care? */
mp = camel_mime_parser_new ();
@@ -2245,14 +2318,15 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
* command completion, but update UNREAD count now according to the
* message SEEN flag */
if (!(server_flags & CAMEL_MESSAGE_SEEN)) {
- CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) folder;
- guint64 uidl = strtoull (mi->uid, NULL, 10);
+ guint64 uidl;
+
+ uidl = strtoull (mi->uid, NULL, 10);
- if (uidl >= ifolder->uidnext_on_server) {
- c (is->tagprefix, "Updating unread count for new message
%s\n", mi->uid);
- ((CamelIMAPXFolder *) folder)->unread_on_server++;
+ if (uidl >= uidnext) {
+ c (is->tagprefix, "Updating unseen count for new message
%s\n", mi->uid);
+ camel_imapx_mailbox_set_unseen (mailbox, unseen + 1);
} else {
- c (is->tagprefix, "Not updating unread count for new message
%s\n", mi->uid);
+ c (is->tagprefix, "Not updating unseen count for new message
%s\n", mi->uid);
}
}
@@ -2261,7 +2335,6 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
if (!camel_folder_summary_check_uid (folder->summary, mi->uid)) {
RefreshInfoData *data;
- CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) folder;
gint cnt;
data = camel_imapx_job_get_data (job);
@@ -2271,12 +2344,9 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
camel_folder_summary_add (folder->summary, mi);
camel_folder_change_info_add_uid (data->changes, mi->uid);
- if (!g_hash_table_lookup (ifolder->ignore_recent, mi->uid)) {
- camel_folder_change_info_recent_uid (data->changes, mi->uid);
- g_hash_table_remove (ifolder->ignore_recent, mi->uid);
- }
+ camel_folder_change_info_recent_uid (data->changes, mi->uid);
- cnt = (camel_folder_summary_count (folder->summary) * 100 ) /
ifolder->exists_on_server;
+ cnt = (camel_folder_summary_count (folder->summary) * 100 ) /
messages;
camel_operation_progress (cancellable, cnt ? cnt : 1);
} else {
camel_message_info_free (mi);
@@ -2288,6 +2358,7 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
}
g_object_unref (folder);
+ g_object_unref (mailbox);
}
}
@@ -2508,12 +2579,12 @@ imapx_untagged_quotaroot (CamelIMAPXServer *is,
CamelIMAPXStoreNamespace *ns;
CamelFolder *folder = NULL;
gchar *mailbox_name = NULL;
- gchar **quota_root_names = NULL;
+ gchar **quota_roots = NULL;
gboolean success;
GError *local_error = NULL;
success = camel_imapx_parse_quotaroot (
- stream, cancellable, &mailbox_name, "a_root_names, error);
+ stream, cancellable, &mailbox_name, "a_roots, error);
/* Sanity check */
g_return_val_if_fail (
@@ -2543,7 +2614,7 @@ imapx_untagged_quotaroot (CamelIMAPXServer *is,
if (folder != NULL) {
camel_imapx_folder_set_quota_root_names (
CAMEL_IMAPX_FOLDER (folder),
- (const gchar **) quota_root_names);
+ (const gchar **) quota_roots);
g_object_unref (folder);
}
@@ -2555,7 +2626,7 @@ imapx_untagged_quotaroot (CamelIMAPXServer *is,
}
g_free (mailbox_name);
- g_strfreev (quota_root_names);
+ g_strfreev (quota_roots);
return TRUE;
}
@@ -2566,10 +2637,23 @@ imapx_untagged_recent (CamelIMAPXServer *is,
GCancellable *cancellable,
GError **error)
{
+ CamelIMAPXMailbox *mailbox;
+ guint32 recent;
+
g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
- c (is->tagprefix, "recent: %lu\n", is->priv->context->id);
- is->priv->recent = is->priv->context->id;
+ mailbox = camel_imapx_server_ref_selected (is);
+
+ if (mailbox == NULL) {
+ g_warning ("%s: No mailbox available", G_STRFUNC);
+ return TRUE;
+ }
+
+ recent = (guint32) is->priv->context->id;
+
+ camel_imapx_mailbox_set_recent (mailbox, recent);
+
+ g_object_unref (mailbox);
return TRUE;
}
@@ -2717,6 +2801,8 @@ imapx_untagged_ok_no_bad (CamelIMAPXServer *is,
GCancellable *cancellable,
GError **error)
{
+ CamelIMAPXMailbox *mailbox;
+
g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
/* TODO: validate which ones of these can happen as unsolicited responses */
@@ -2727,8 +2813,13 @@ imapx_untagged_ok_no_bad (CamelIMAPXServer *is,
is->priv->context->token,
is->priv->context->len);
+ mailbox = camel_imapx_server_ref_selected (is);
+
is->priv->context->sinfo =
- imapx_parse_status (stream, cancellable, error);
+ imapx_parse_status (stream, mailbox, cancellable, error);
+
+ g_clear_object (&mailbox);
+
if (is->priv->context->sinfo == NULL)
return FALSE;
@@ -2736,48 +2827,33 @@ imapx_untagged_ok_no_bad (CamelIMAPXServer *is,
case IMAPX_CLOSED:
c (
is->tagprefix,
- "previously selected folder is now closed\n");
+ "previously selected mailbox is now closed\n");
{
- CamelFolder *select_folder;
- CamelFolder *select_pending;
+ CamelIMAPXMailbox *select_mailbox;
+ CamelIMAPXMailbox *select_pending;
g_mutex_lock (&is->priv->select_lock);
- select_folder =
- g_weak_ref_get (&is->priv->select_folder);
+ select_mailbox =
+ g_weak_ref_get (&is->priv->select_mailbox);
select_pending =
g_weak_ref_get (&is->priv->select_pending);
- if (select_folder == NULL)
+ if (select_mailbox == NULL)
g_weak_ref_set (
- &is->priv->select_folder,
+ &is->priv->select_mailbox,
select_pending);
- g_clear_object (&select_folder);
+ g_clear_object (&select_mailbox);
g_clear_object (&select_pending);
g_mutex_unlock (&is->priv->select_lock);
}
break;
- case IMAPX_UIDVALIDITY:
- is->priv->uidvalidity =
- is->priv->context->sinfo->u.uidvalidity;
- break;
- case IMAPX_UNSEEN:
- is->priv->unseen =
- is->priv->context->sinfo->u.unseen;
- break;
- case IMAPX_HIGHESTMODSEQ:
- is->priv->highestmodseq =
- is->priv->context->sinfo->u.highestmodseq;
- break;
case IMAPX_PERMANENTFLAGS:
is->priv->permanentflags =
is->priv->context->sinfo->u.permanentflags;
break;
- case IMAPX_UIDNEXT:
- is->priv->uidnext = is->priv->context->sinfo->u.uidnext;
- break;
case IMAPX_ALERT:
c (is->tagprefix, "ALERT!: %s\n", is->priv->context->sinfo->text);
g_mutex_lock (&is->priv->known_alerts_lock);
@@ -3150,6 +3226,7 @@ imapx_completion (CamelIMAPXServer *is,
GError **error)
{
CamelIMAPXCommand *ic;
+ CamelIMAPXMailbox *mailbox;
gboolean success = FALSE;
guint tag;
@@ -3184,8 +3261,12 @@ imapx_completion (CamelIMAPXServer *is,
if (camel_folder_change_info_changed (is->priv->changes)) {
CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
+
+ mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
- folder = g_weak_ref_get (&is->priv->select_folder);
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_val_if_fail (folder != NULL, FALSE);
camel_folder_summary_save_to_db (folder->summary, NULL);
@@ -3195,6 +3276,7 @@ imapx_completion (CamelIMAPXServer *is,
camel_folder_change_info_clear (is->priv->changes);
g_object_unref (folder);
+ g_object_unref (mailbox);
}
QUEUE_LOCK (is);
@@ -3220,7 +3302,11 @@ imapx_completion (CamelIMAPXServer *is,
QUEUE_UNLOCK (is);
- ic->status = imapx_parse_status (stream, cancellable, error);
+ mailbox = camel_imapx_server_ref_selected (is);
+
+ ic->status = imapx_parse_status (stream, mailbox, cancellable, error);
+
+ g_clear_object (&mailbox);
if (ic->status == NULL)
goto exit;
@@ -3490,16 +3576,16 @@ imapx_job_idle_start (CamelIMAPXJob *job,
GCancellable *cancellable,
GError **error)
{
- CamelFolder *folder;
CamelIMAPXCommand *ic;
CamelIMAPXCommandPart *cp;
+ CamelIMAPXMailbox *mailbox;
gboolean success = TRUE;
- folder = camel_imapx_job_ref_folder (job);
- g_return_val_if_fail (folder != NULL, FALSE);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
ic = camel_imapx_command_new (
- is, "IDLE", folder, "IDLE");
+ is, "IDLE", mailbox, "IDLE");
camel_imapx_command_set_job (ic, job);
ic->pri = job->pri;
ic->complete = imapx_command_idle_done;
@@ -3522,14 +3608,14 @@ imapx_job_idle_start (CamelIMAPXJob *job,
camel_imapx_command_unref (ic);
- g_object_unref (folder);
+ g_object_unref (mailbox);
return success;
}
static gboolean
camel_imapx_server_idle (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
@@ -3540,7 +3626,7 @@ camel_imapx_server_idle (CamelIMAPXServer *is,
job->type = IMAPX_JOB_IDLE;
job->start = imapx_job_idle_start;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
success = imapx_submit_job (is, job, error);
@@ -3551,15 +3637,15 @@ camel_imapx_server_idle (CamelIMAPXServer *is,
static gboolean
imapx_job_fetch_new_messages_matches (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid)
{
- return camel_imapx_job_has_folder (job, folder);
+ return camel_imapx_job_has_mailbox (job, mailbox);
}
static gboolean
imapx_server_fetch_new_messages (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
gboolean async,
gboolean update_unseen,
GCancellable *cancellable,
@@ -3580,7 +3666,7 @@ imapx_server_fetch_new_messages (CamelIMAPXServer *is,
job->matches = imapx_job_fetch_new_messages_matches;
job->noreply = async;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
camel_imapx_job_set_data (
job, data, (GDestroyNotify) refresh_info_data_free);
@@ -3610,6 +3696,7 @@ imapx_idle_thread (gpointer data)
while (TRUE) {
CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
gboolean new_messages_on_server;
time_t dwelled;
@@ -3619,15 +3706,15 @@ imapx_idle_thread (gpointer data)
if (is->idle->idle_exit)
break;
- folder = g_weak_ref_get (&is->priv->select_folder);
- if (folder == NULL)
+ mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+ if (mailbox == NULL)
break;
dwelled = time (NULL) - is->idle->started;
if (dwelled < IMAPX_IDLE_DWELL_TIME) {
gulong seconds;
- g_object_unref (folder);
+ g_object_unref (mailbox);
IDLE_UNLOCK (is->idle);
seconds = IMAPX_IDLE_DWELL_TIME - dwelled;
@@ -3639,18 +3726,20 @@ imapx_idle_thread (gpointer data)
IDLE_UNLOCK (is->idle);
+ folder = imapx_server_ref_folder (is, mailbox);
+
camel_imapx_server_idle (
- is, folder, cancellable, &local_error);
+ is, mailbox, cancellable, &local_error);
new_messages_on_server =
- CAMEL_IMAPX_FOLDER (folder)->exists_on_server >
+ camel_imapx_mailbox_get_messages (mailbox) >
camel_folder_summary_count (folder->summary);
if (local_error == NULL &&
new_messages_on_server &&
imapx_is_command_queue_empty (is)) {
imapx_server_fetch_new_messages (
- is, folder, TRUE, TRUE,
+ is, mailbox, TRUE, TRUE,
cancellable, &local_error);
}
@@ -3660,7 +3749,8 @@ imapx_idle_thread (gpointer data)
g_clear_error (&local_error);
}
- g_object_unref (folder);
+ g_clear_object (&folder);
+ g_clear_object (&mailbox);
IDLE_LOCK (is->idle);
}
@@ -3863,38 +3953,43 @@ imapx_command_select_done (CamelIMAPXServer *is,
if (camel_imapx_command_set_error_if_failed (ic, &local_error)) {
GQueue failed = G_QUEUE_INIT;
GQueue trash = G_QUEUE_INIT;
- CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
GList *link;
c (is->tagprefix, "Select failed\n");
g_mutex_lock (&is->priv->select_lock);
- folder = g_weak_ref_get (&is->priv->select_pending);
- g_weak_ref_set (&is->priv->select_folder, NULL);
+ mailbox = g_weak_ref_get (&is->priv->select_pending);
+ g_weak_ref_set (&is->priv->select_mailbox, NULL);
g_weak_ref_set (&is->priv->select_pending, NULL);
is->state = IMAPX_INITIALISED;
g_mutex_unlock (&is->priv->select_lock);
QUEUE_LOCK (is);
- if (folder != NULL) {
+ if (mailbox != NULL) {
GList *head = camel_imapx_command_queue_peek_head_link (is->queue);
for (link = head; link != NULL; link = g_list_next (link)) {
CamelIMAPXCommand *cw = link->data;
+ CamelIMAPXMailbox *cw_mailbox;
+
+ cw_mailbox = camel_imapx_command_ref_mailbox (cw);
- if (cw->select && cw->select == folder) {
+ if (cw_mailbox == mailbox) {
c (
is->tagprefix,
"Cancelling command '%s'(%p) "
- "for folder '%s'\n",
+ "for mailbox '%s'\n",
cw->name, cw,
- camel_folder_get_full_name (cw->select));
+ camel_imapx_mailbox_get_name (cw_mailbox));
g_queue_push_tail (&trash, link);
}
+
+ g_clear_object (&cw_mailbox);
}
- g_object_unref (folder);
+ g_object_unref (mailbox);
}
while ((link = g_queue_pop_head (&trash)) != NULL) {
@@ -3930,30 +4025,33 @@ imapx_command_select_done (CamelIMAPXServer *is,
} else {
CamelFolder *folder;
- CamelIMAPXFolder *ifolder;
+ CamelIMAPXMailbox *mailbox;
+ CamelIMAPXSummary *imapx_summary;
+ guint32 uidnext;
c (is->tagprefix, "Select ok!\n");
g_mutex_lock (&is->priv->select_lock);
- folder = g_weak_ref_get (&is->priv->select_pending);
- g_weak_ref_set (&is->priv->select_folder, folder);
+ mailbox = g_weak_ref_get (&is->priv->select_pending);
+ g_weak_ref_set (&is->priv->select_mailbox, mailbox);
g_weak_ref_set (&is->priv->select_pending, NULL);
is->state = IMAPX_SELECTED;
g_mutex_unlock (&is->priv->select_lock);
/* We should have a strong reference
* on the newly-selected CamelFolder. */
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_if_fail (folder != NULL);
- ifolder = CAMEL_IMAPX_FOLDER (folder);
- ifolder->exists_on_server = is->priv->exists;
- ifolder->modseq_on_server = is->priv->highestmodseq;
- if (ifolder->uidnext_on_server < is->priv->uidnext) {
+ uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
+ imapx_summary = CAMEL_IMAPX_SUMMARY (folder->summary);
+
+ if (imapx_summary->uidnext < uidnext) {
/* We don't want to fetch new messages if the command we selected this
* folder for is *already* fetching all messages (i.e. scan_changes).
* Bug #667725. */
CamelIMAPXJob *job = imapx_is_job_in_queue (
- is, folder, IMAPX_JOB_REFRESH_INFO, NULL);
+ is, mailbox, IMAPX_JOB_REFRESH_INFO, NULL);
if (job) {
RefreshInfoData *data = camel_imapx_job_get_data (job);
@@ -3965,16 +4063,11 @@ imapx_command_select_done (CamelIMAPXServer *is,
goto no_fetch_new;
}
}
- imapx_server_fetch_new_messages (is, folder, TRUE, TRUE, NULL, NULL);
+ imapx_server_fetch_new_messages (
+ is, mailbox, TRUE, TRUE, NULL, NULL);
no_fetch_new:
;
}
- ifolder->uidvalidity_on_server = is->priv->uidvalidity;
-
- if (is->priv->uidvalidity > 0 &&
- is->priv->uidvalidity != ((CamelIMAPXSummary *) folder->summary)->validity)
- camel_imapx_folder_invalidate_local_cache (
- ifolder, is->priv->uidvalidity);
#if 0 /* see comment for disabled bits in imapx_job_refresh_info_start() */
/* This should trigger a new messages scan */
@@ -3985,7 +4078,8 @@ imapx_command_select_done (CamelIMAPXServer *is,
((CamelIMAPXSummary *) folder->summary)->exists);
#endif
- g_object_unref (folder);
+ g_clear_object (&mailbox);
+ g_clear_object (&folder);
}
}
@@ -3993,58 +4087,51 @@ imapx_command_select_done (CamelIMAPXServer *is,
static void
imapx_maybe_select (CamelIMAPXServer *is,
CamelIMAPXJob *job,
- CamelFolder *folder)
+ CamelIMAPXMailbox *mailbox)
{
CamelIMAPXCommand *ic;
- CamelIMAPXMailbox *mailbox;
- CamelFolder *select_folder;
- CamelFolder *select_pending;
+ CamelIMAPXMailbox *select_mailbox;
+ CamelIMAPXMailbox *select_pending;
gboolean nothing_to_do = FALSE;
/* Select is complicated by the fact we may have commands
* active on the server for a different selection.
*
* So this waits for any commands to complete, selects the
- * new folder, and halts the queuing of any new commands.
- * It is assumed whomever called is us about to issue a
- * high-priority command anyway */
+ * new mailbox, and halts the queuing of any new commands.
+ * It is assumed whomever called us is about to issue a
+ * high-priority command anyway. */
g_mutex_lock (&is->priv->select_lock);
- select_folder = g_weak_ref_get (&is->priv->select_folder);
+ select_mailbox = g_weak_ref_get (&is->priv->select_mailbox);
select_pending = g_weak_ref_get (&is->priv->select_pending);
if (select_pending != NULL) {
nothing_to_do = TRUE;
- } else if (select_folder == folder) {
+ } else if (select_mailbox == mailbox) {
nothing_to_do = TRUE;
} else if (!camel_imapx_command_queue_is_empty (is->active)) {
nothing_to_do = TRUE;
} else {
- g_weak_ref_set (&is->priv->select_pending, folder);
+ g_weak_ref_set (&is->priv->select_pending, mailbox);
- if (select_folder != NULL) {
- g_weak_ref_set (&is->priv->select_folder, NULL);
+ if (select_mailbox != NULL) {
+ g_weak_ref_set (&is->priv->select_mailbox, NULL);
} else {
- /* If no folder was selected, we won't get a
- * [CLOSED] status so just point select_folder
- * at the newly-selected folder immediately. */
- g_weak_ref_set (&is->priv->select_folder, folder);
+ /* If no mailbox was selected, we won't get a
+ * [CLOSED] status so just point select_mailbox
+ * at the newly-selected mailbox immediately. */
+ g_weak_ref_set (&is->priv->select_mailbox, mailbox);
}
- is->priv->uidvalidity = 0;
- is->priv->unseen = 0;
- is->priv->highestmodseq = 0;
is->priv->permanentflags = 0;
- is->priv->exists = 0;
- is->priv->recent = 0;
- is->priv->uidnext = 0;
/* Hrm, what about reconnecting? */
is->state = IMAPX_INITIALISED;
}
- g_clear_object (&select_folder);
+ g_clear_object (&select_mailbox);
g_clear_object (&select_pending);
g_mutex_unlock (&is->priv->select_lock);
@@ -4052,16 +4139,16 @@ imapx_maybe_select (CamelIMAPXServer *is,
if (nothing_to_do)
return;
- mailbox = camel_imapx_folder_ref_mailbox (CAMEL_IMAPX_FOLDER (folder));
- g_warn_if_fail (mailbox != NULL);
-
ic = camel_imapx_command_new (
is, "SELECT", NULL, "SELECT %m", mailbox);
- g_object_unref (mailbox);
+ if (is->use_qresync) {
+ CamelFolder *folder;
- if (is->use_qresync)
+ folder = imapx_server_ref_folder (is, mailbox);
camel_imapx_command_add_qresync_parameter (ic, folder);
+ g_clear_object (&folder);
+ }
ic->complete = imapx_command_select_done;
camel_imapx_command_set_job (ic, job);
@@ -4745,9 +4832,8 @@ imapx_command_fetch_message_done (CamelIMAPXServer *is,
CamelIMAPXCommand *ic)
{
CamelIMAPXJob *job;
- CamelFolder *folder;
GetMessageData *data;
- CamelIMAPXFolder *ifolder;
+ CamelIMAPXMailbox *mailbox;
GCancellable *cancellable;
GError *local_error = NULL;
@@ -4760,8 +4846,8 @@ imapx_command_fetch_message_done (CamelIMAPXServer *is,
data = camel_imapx_job_get_data (job);
g_return_if_fail (data != NULL);
- folder = camel_imapx_job_ref_folder (job);
- g_return_if_fail (folder != NULL);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_if_fail (mailbox != NULL);
/* We either have more to fetch (partial mode?), we are complete,
* or we failed. Failure is handled in the fetch code, so
@@ -4791,7 +4877,7 @@ imapx_command_fetch_message_done (CamelIMAPXServer *is,
(data->fetch_offset *100) / data->size);
new_ic = camel_imapx_command_new (
- is, "FETCH", folder,
+ is, "FETCH", mailbox,
"UID FETCH %t (BODY.PEEK[]",
data->uid);
camel_imapx_command_add (new_ic, "<%u.%u>", data->fetch_offset, MULTI_SIZE);
@@ -4816,8 +4902,6 @@ imapx_command_fetch_message_done (CamelIMAPXServer *is,
/* No more messages to fetch, let's wrap things up. */
- ifolder = CAMEL_IMAPX_FOLDER (folder);
-
if (local_error == NULL) {
camel_stream_flush (data->stream, cancellable, &local_error);
g_prefix_error (
@@ -4838,10 +4922,10 @@ imapx_command_fetch_message_done (CamelIMAPXServer *is,
gchar *dirname;
cur_filename = camel_data_cache_get_filename (
- ifolder->cache, "cur", data->uid);
+ data->message_cache, "cur", data->uid);
tmp_filename = camel_data_cache_get_filename (
- ifolder->cache, "tmp", data->uid);
+ data->message_cache, "tmp", data->uid);
dirname = g_path_get_dirname (cur_filename);
g_mkdir_with_parents (dirname, 0700);
@@ -4851,7 +4935,7 @@ imapx_command_fetch_message_done (CamelIMAPXServer *is,
/* Exchange the "tmp" stream for the "cur" stream. */
g_clear_object (&data->stream);
data->stream = camel_data_cache_get (
- ifolder->cache, "cur",
+ data->message_cache, "cur",
data->uid, &local_error);
} else {
g_set_error (
@@ -4869,11 +4953,11 @@ imapx_command_fetch_message_done (CamelIMAPXServer *is,
if (local_error != NULL)
camel_imapx_job_take_error (job, local_error);
- camel_data_cache_remove (ifolder->cache, "tmp", data->uid, NULL);
+ camel_data_cache_remove (data->message_cache, "tmp", data->uid, NULL);
imapx_unregister_job (is, job);
exit:
- g_object_unref (folder);
+ g_object_unref (mailbox);
}
static gboolean
@@ -4882,8 +4966,8 @@ imapx_job_get_message_start (CamelIMAPXJob *job,
GCancellable *cancellable,
GError **error)
{
- CamelFolder *folder;
CamelIMAPXCommand *ic;
+ CamelIMAPXMailbox *mailbox;
GetMessageData *data;
gint i;
gboolean success = TRUE;
@@ -4891,13 +4975,13 @@ imapx_job_get_message_start (CamelIMAPXJob *job,
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
- g_return_val_if_fail (folder != NULL, FALSE);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
if (data->use_multi_fetch) {
for (i = 0; i < 3 && data->fetch_offset < data->size; i++) {
ic = camel_imapx_command_new (
- is, "FETCH", folder,
+ is, "FETCH", mailbox,
"UID FETCH %t (BODY.PEEK[]",
data->uid);
camel_imapx_command_add (ic, "<%u.%u>", data->fetch_offset, MULTI_SIZE);
@@ -4917,7 +5001,7 @@ imapx_job_get_message_start (CamelIMAPXJob *job,
}
} else {
ic = camel_imapx_command_new (
- is, "FETCH", folder,
+ is, "FETCH", mailbox,
"UID FETCH %t (BODY.PEEK[])",
data->uid);
ic->complete = imapx_command_fetch_message_done;
@@ -4930,14 +5014,14 @@ imapx_job_get_message_start (CamelIMAPXJob *job,
camel_imapx_command_unref (ic);
}
- g_object_unref (folder);
+ g_object_unref (mailbox);
return success;
}
static gboolean
imapx_job_get_message_matches (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid)
{
GetMessageData *data;
@@ -4945,7 +5029,7 @@ imapx_job_get_message_matches (CamelIMAPXJob *job,
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- if (!camel_imapx_job_has_folder (job, folder))
+ if (!camel_imapx_job_has_mailbox (job, mailbox))
return FALSE;
if (g_strcmp0 (uid, data->uid) != 0)
@@ -4962,6 +5046,7 @@ imapx_command_copy_messages_step_done (CamelIMAPXServer *is,
{
CamelIMAPXJob *job;
CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
CopyMessagesData *data;
GPtrArray *uids;
gint i;
@@ -4973,7 +5058,10 @@ imapx_command_copy_messages_step_done (CamelIMAPXServer *is,
data = camel_imapx_job_get_data (job);
g_return_if_fail (data != NULL);
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_if_fail (mailbox != NULL);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_if_fail (folder != NULL);
uids = data->uids;
@@ -4999,22 +5087,6 @@ imapx_command_copy_messages_step_done (CamelIMAPXServer *is,
camel_folder_delete_message (folder, uids->pdata[j]);
}
- /* TODO Copy the summary and cached messages to the new folder.
- * We might need a sorted insert to avoid refreshing the dest
- * folder. */
- if (ic->status && ic->status->condition == IMAPX_COPYUID) {
- gint i;
-
- for (i = 0; i < ic->status->u.copyuid.copied_uids->len; i++) {
- guint32 uid = GPOINTER_TO_UINT (g_ptr_array_index (ic->status->u.copyuid.copied_uids,
i));
- gchar *str = g_strdup_printf ("%d",uid);
- CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) data->dest;
-
- g_hash_table_insert (ifolder->ignore_recent, str, GINT_TO_POINTER (1));
- }
-
- }
-
if (i < uids->len) {
imapx_command_copy_messages_step_start (
is, job, i, &local_error);
@@ -5025,6 +5097,7 @@ imapx_command_copy_messages_step_done (CamelIMAPXServer *is,
exit:
g_object_unref (folder);
+ g_object_unref (mailbox);
imapx_unregister_job (is, job);
}
@@ -5035,8 +5108,7 @@ imapx_command_copy_messages_step_start (CamelIMAPXServer *is,
gint index,
GError **error)
{
- CamelFolder *folder;
- CamelIMAPXMailbox *dest_mailbox;
+ CamelIMAPXMailbox *mailbox;
CamelIMAPXCommand *ic;
CopyMessagesData *data;
GPtrArray *uids;
@@ -5046,24 +5118,21 @@ imapx_command_copy_messages_step_start (CamelIMAPXServer *is,
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
- g_return_val_if_fail (folder != NULL, FALSE);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
uids = data->uids;
if (data->use_move_command)
- ic = camel_imapx_command_new (is, "MOVE", folder, "UID MOVE ");
+ ic = camel_imapx_command_new (is, "MOVE", mailbox, "UID MOVE ");
else
- ic = camel_imapx_command_new (is, "COPY", folder, "UID COPY ");
+ ic = camel_imapx_command_new (is, "COPY", mailbox, "UID COPY ");
ic->complete = imapx_command_copy_messages_step_done;
camel_imapx_command_set_job (ic, job);
ic->pri = job->pri;
data->last_index = i;
- g_object_unref (folder);
-
- dest_mailbox = camel_imapx_folder_ref_mailbox (
- CAMEL_IMAPX_FOLDER (data->dest));
+ g_object_unref (mailbox);
for (; i < uids->len; i++) {
gint res;
@@ -5071,7 +5140,7 @@ imapx_command_copy_messages_step_start (CamelIMAPXServer *is,
res = imapx_uidset_add (&data->uidset, ic, uid);
if (res == 1) {
- camel_imapx_command_add (ic, " %m", dest_mailbox);
+ camel_imapx_command_add (ic, " %m", data->destination);
data->index = i + 1;
imapx_command_queue (is, ic);
goto exit;
@@ -5080,14 +5149,12 @@ imapx_command_copy_messages_step_start (CamelIMAPXServer *is,
data->index = i;
if (imapx_uidset_done (&data->uidset, ic)) {
- camel_imapx_command_add (ic, " %m", dest_mailbox);
+ camel_imapx_command_add (ic, " %m", data->destination);
imapx_command_queue (is, ic);
goto exit;
}
exit:
- g_object_unref (dest_mailbox);
-
camel_imapx_command_unref (ic);
return success;
@@ -5099,18 +5166,18 @@ imapx_job_copy_messages_start (CamelIMAPXJob *job,
GCancellable *cancellable,
GError **error)
{
- CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
CopyMessagesData *data;
gboolean success;
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
- g_return_val_if_fail (folder != NULL, FALSE);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
success = imapx_server_sync_changes (
- is, folder, job->type, job->pri, cancellable, error);
+ is, mailbox, job->type, job->pri, cancellable, error);
if (!success)
imapx_unregister_job (is, job);
@@ -5118,7 +5185,7 @@ imapx_job_copy_messages_start (CamelIMAPXJob *job,
g_ptr_array_sort (data->uids, (GCompareFunc) imapx_uids_array_cmp);
imapx_uidset_init (&data->uidset, 0, MAX_COMMAND_LEN);
- g_object_unref (folder);
+ g_object_unref (mailbox);
return imapx_command_copy_messages_step_start (is, job, 0, error);
}
@@ -5131,10 +5198,12 @@ imapx_command_append_message_done (CamelIMAPXServer *is,
{
CamelIMAPXJob *job;
CamelIMAPXFolder *ifolder;
+ CamelIMAPXMailbox *mailbox;
CamelFolder *folder;
CamelMessageInfo *mi;
AppendMessageData *data;
gchar *cur, *old_uid;
+ guint32 uidvalidity;
GError *local_error = NULL;
job = camel_imapx_command_get_job (ic);
@@ -5143,9 +5212,14 @@ imapx_command_append_message_done (CamelIMAPXServer *is,
data = camel_imapx_job_get_data (job);
g_return_if_fail (data != NULL);
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_if_fail (mailbox != NULL);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_if_fail (folder != NULL);
+ uidvalidity = camel_imapx_mailbox_get_uidvalidity (mailbox);
+
ifolder = CAMEL_IMAPX_FOLDER (folder);
/* Append done. If we the server supports UIDPLUS we will get
@@ -5165,7 +5239,7 @@ imapx_command_append_message_done (CamelIMAPXServer *is,
} else if (ic->status && ic->status->condition == IMAPX_APPENDUID) {
c (is->tagprefix, "Got appenduid %d %d\n", (gint) ic->status->u.appenduid.uidvalidity, (gint)
ic->status->u.appenduid.uid);
- if (ic->status->u.appenduid.uidvalidity == ifolder->uidvalidity_on_server) {
+ if (ic->status->u.appenduid.uidvalidity == uidvalidity) {
CamelFolderChangeInfo *changes;
data->appended_uid = g_strdup_printf ("%u", (guint) ic->status->u.appenduid.uid);
@@ -5196,6 +5270,7 @@ imapx_command_append_message_done (CamelIMAPXServer *is,
g_free (old_uid);
g_object_unref (folder);
+ g_object_unref (mailbox);
imapx_unregister_job (is, job);
}
@@ -5206,7 +5281,6 @@ imapx_job_append_message_start (CamelIMAPXJob *job,
GCancellable *cancellable,
GError **error)
{
- CamelFolder *folder;
CamelIMAPXMailbox *mailbox;
CamelIMAPXCommand *ic;
AppendMessageData *data;
@@ -5214,11 +5288,8 @@ imapx_job_append_message_start (CamelIMAPXJob *job,
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
- g_return_val_if_fail (folder != NULL, FALSE);
-
- mailbox = camel_imapx_folder_ref_mailbox (CAMEL_IMAPX_FOLDER (folder));
- g_warn_if_fail (mailbox != NULL);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
/* TODO: we could supply the original append date from the file timestamp */
ic = camel_imapx_command_new (
@@ -5237,7 +5308,6 @@ imapx_job_append_message_start (CamelIMAPXJob *job,
camel_imapx_command_unref (ic);
g_object_unref (mailbox);
- g_object_unref (folder);
return TRUE;
}
@@ -5327,7 +5397,7 @@ static void
imapx_command_step_fetch_done (CamelIMAPXServer *is,
CamelIMAPXCommand *ic)
{
- CamelIMAPXFolder *ifolder;
+ CamelIMAPXMailbox *mailbox;
CamelIMAPXSummary *isum;
CamelIMAPXJob *job;
CamelFolder *folder;
@@ -5344,12 +5414,14 @@ imapx_command_step_fetch_done (CamelIMAPXServer *is,
data = camel_imapx_job_get_data (job);
g_return_if_fail (data != NULL);
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_if_fail (mailbox != NULL);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_if_fail (folder != NULL);
data->scan_changes = FALSE;
- ifolder = CAMEL_IMAPX_FOLDER (folder);
isum = CAMEL_IMAPX_SUMMARY (folder->summary);
settings = camel_imapx_server_ref_settings (is);
@@ -5380,18 +5452,16 @@ imapx_command_step_fetch_done (CamelIMAPXServer *is,
gint fetch_limit = data->fetch_msg_limit;
ic = camel_imapx_command_new (
- is, "FETCH", folder, "UID FETCH ");
+ is, "FETCH", mailbox, "UID FETCH ");
ic->complete = imapx_command_step_fetch_done;
camel_imapx_command_set_job (ic, job);
ic->pri = job->pri - 1;
- //printf ("Total: %d: %d, %d, %d\n", total, fetch_limit, i, data->last_index);
data->last_index = i;
/* If its mobile client and when total=0 (new account setup)
* fetch only one batch of mails, on futher attempts download
* all new mails as per the limit. */
- //printf ("Total: %d: %d\n", total, fetch_limit);
for (; i < data->infos->len &&
(!mobile_mode || (total && i == 0) ||
((fetch_limit != -1 && i < fetch_limit) ||
@@ -5411,13 +5481,13 @@ imapx_command_step_fetch_done (CamelIMAPXServer *is,
camel_imapx_command_unref (ic);
g_object_unref (folder);
+ g_object_unref (mailbox);
return;
}
}
}
- //printf ("Existing : %d Gonna fetch in %s for %d/%d\n", total, camel_folder_get_full_name
(folder), i, data->infos->len);
data->index = data->infos->len;
if (imapx_uidset_done (&data->uidset, ic)) {
camel_imapx_command_add (ic, " (RFC822.SIZE RFC822.HEADER)");
@@ -5427,6 +5497,7 @@ imapx_command_step_fetch_done (CamelIMAPXServer *is,
camel_imapx_command_unref (ic);
g_object_unref (folder);
+ g_object_unref (mailbox);
return;
}
@@ -5440,27 +5511,37 @@ imapx_command_step_fetch_done (CamelIMAPXServer *is,
}
if (camel_folder_summary_count (folder->summary)) {
- gchar *uid = camel_imapx_dup_uid_from_summary_index (
+ gchar *uid;
+ guint32 uidl;
+ guint32 uidnext;
+
+ uid = camel_imapx_dup_uid_from_summary_index (
folder,
camel_folder_summary_count (folder->summary) - 1);
- guint64 uidl = strtoull (uid, NULL, 10);
+ uidl = (guint32) strtoull (uid, NULL, 10);
g_free (uid);
uidl++;
- if (uidl > ifolder->uidnext_on_server) {
+ uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
+
+ if (uidl > uidnext) {
c (
- is->tagprefix, "Updating uidnext_on_server for '%s' to %" G_GUINT64_FORMAT
"\n",
- camel_folder_get_full_name (folder), uidl);
- ifolder->uidnext_on_server = uidl;
+ is->tagprefix,
+ "Updating uidnext for '%s' to %ul\n",
+ camel_imapx_mailbox_get_name (mailbox),
+ uidl);
+ camel_imapx_mailbox_set_uidnext (mailbox, uidl);
}
}
- isum->uidnext = ifolder->uidnext_on_server;
+
+ isum->uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
exit:
refresh_info_data_infos_free (data);
g_object_unref (folder);
+ g_object_unref (mailbox);
imapx_unregister_job (is, job);
}
@@ -5495,6 +5576,7 @@ imapx_job_scan_changes_done (CamelIMAPXServer *is,
CamelIMAPXCommand *ic)
{
CamelIMAPXJob *job;
+ CamelIMAPXMailbox *mailbox;
CamelIMAPXSettings *settings;
CamelFolder *folder;
RefreshInfoData *data;
@@ -5512,7 +5594,10 @@ imapx_job_scan_changes_done (CamelIMAPXServer *is,
data = camel_imapx_job_get_data (job);
g_return_if_fail (data != NULL);
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_if_fail (mailbox != NULL);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_if_fail (folder != NULL);
data->scan_changes = FALSE;
@@ -5533,19 +5618,18 @@ imapx_job_scan_changes_done (CamelIMAPXServer *is,
CamelMessageInfo *s_minfo = NULL;
CamelIMAPXMessageInfo *info;
CamelFolderSummary *s = folder->summary;
- CamelIMAPXFolder *ifolder;
GList *removed = NULL, *l;
gboolean fetch_new = FALSE;
gint i;
guint j = 0;
GPtrArray *uids;
- ifolder = CAMEL_IMAPX_FOLDER (folder);
-
/* Actually we wanted to do this after the SELECT but before the
* FETCH command was issued. But this should suffice. */
- ((CamelIMAPXSummary *) s)->uidnext = ifolder->uidnext_on_server;
- ((CamelIMAPXSummary *) s)->modseq = ifolder->modseq_on_server;
+ ((CamelIMAPXSummary *) s)->uidnext =
+ camel_imapx_mailbox_get_uidnext (mailbox);
+ ((CamelIMAPXSummary *) s)->modseq =
+ camel_imapx_mailbox_get_highestmodseq (mailbox);
/* Here we do the typical sort/iterate/merge loop.
* If the server flags dont match what we had, we modify our
@@ -5665,6 +5749,7 @@ imapx_job_scan_changes_done (CamelIMAPXServer *is,
data->update_unseen = TRUE;
g_object_unref (folder);
+ g_object_unref (mailbox);
return imapx_command_step_fetch_done (is, ic);
}
@@ -5677,11 +5762,15 @@ imapx_job_scan_changes_done (CamelIMAPXServer *is,
* mobile mode. In mobile mode we would have this filled up already
* with a STATUS command.
**/
- if (!mobile_mode)
- ((CamelIMAPXFolder *) folder)->unread_on_server =
- camel_folder_summary_get_unread_count (folder->summary);
+ if (!mobile_mode) {
+ guint32 unseen;
+
+ unseen = camel_folder_summary_get_unread_count (folder->summary);
+ camel_imapx_mailbox_set_unseen (mailbox, unseen);
+ }
g_object_unref (folder);
+ g_object_unref (mailbox);
imapx_unregister_job (is, job);
}
@@ -5694,6 +5783,7 @@ imapx_job_scan_changes_start (CamelIMAPXJob *job,
{
CamelFolder *folder;
CamelIMAPXCommand *ic;
+ CamelIMAPXMailbox *mailbox;
RefreshInfoData *data;
CamelIMAPXSettings *settings;
gboolean mobile_mode;
@@ -5702,7 +5792,10 @@ imapx_job_scan_changes_start (CamelIMAPXJob *job,
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_val_if_fail (folder != NULL, FALSE);
settings = camel_imapx_server_ref_settings (is);
@@ -5720,11 +5813,12 @@ imapx_job_scan_changes_start (CamelIMAPXJob *job,
camel_folder_get_display_name (folder));
e (
- 'E', "Scanning from %s in %s\n", uid ? uid : "start",
- camel_folder_get_full_name (folder));
+ 'E', "Scanning from %s in %s\n",
+ uid ? uid : "start",
+ camel_imapx_mailbox_get_name (mailbox));
ic = camel_imapx_command_new (
- is, "FETCH", folder,
+ is, "FETCH", mailbox,
"UID FETCH %s:* (UID FLAGS)", uid ? uid : "1");
camel_imapx_command_set_job (ic, job);
ic->complete = imapx_job_scan_changes_done;
@@ -5741,6 +5835,7 @@ imapx_job_scan_changes_start (CamelIMAPXJob *job,
g_free (uid);
g_object_unref (folder);
+ g_object_unref (mailbox);
return TRUE;
}
@@ -5751,7 +5846,7 @@ imapx_command_fetch_new_messages_done (CamelIMAPXServer *is,
{
CamelIMAPXJob *job;
CamelIMAPXSummary *isum;
- CamelIMAPXFolder *ifolder;
+ CamelIMAPXMailbox *mailbox;
CamelFolder *folder;
RefreshInfoData *data;
GError *local_error = NULL;
@@ -5762,10 +5857,12 @@ imapx_command_fetch_new_messages_done (CamelIMAPXServer *is,
data = camel_imapx_job_get_data (job);
g_return_if_fail (data != NULL);
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_if_fail (mailbox != NULL);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_if_fail (folder != NULL);
- ifolder = CAMEL_IMAPX_FOLDER (folder);
isum = CAMEL_IMAPX_SUMMARY (folder->summary);
if (camel_imapx_command_set_error_if_failed (ic, &local_error)) {
@@ -5784,26 +5881,35 @@ imapx_command_fetch_new_messages_done (CamelIMAPXServer *is,
}
if (camel_folder_summary_count (folder->summary)) {
- gchar *uid = camel_imapx_dup_uid_from_summary_index (
+ gchar *uid;
+ guint32 uidl;
+ guint32 uidnext;
+
+ uid = camel_imapx_dup_uid_from_summary_index (
folder,
camel_folder_summary_count (folder->summary) - 1);
- guint64 uidl = strtoull (uid, NULL, 10);
+ uidl = (guint32) strtoull (uid, NULL, 10);
g_free (uid);
uidl++;
- if (uidl > ifolder->uidnext_on_server) {
+ uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
+
+ if (uidl > uidnext) {
c (
- is->tagprefix, "Updating uidnext_on_server for '%s' to %" G_GUINT64_FORMAT
"\n",
- camel_folder_get_full_name (folder), uidl);
- ifolder->uidnext_on_server = uidl;
+ is->tagprefix,
+ "Updating uidnext for '%s' to %ul\n",
+ camel_imapx_mailbox_get_name (mailbox),
+ uidl);
+ camel_imapx_mailbox_set_uidnext (mailbox, uidl);
}
}
- isum->uidnext = ifolder->uidnext_on_server;
+ isum->uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
exit:
g_object_unref (folder);
+ g_object_unref (mailbox);
imapx_unregister_job (is, job);
}
@@ -5840,18 +5946,22 @@ imapx_job_fetch_new_messages_start (CamelIMAPXJob *job,
{
CamelIMAPXCommand *ic;
CamelFolder *folder;
- CamelIMAPXFolder *ifolder;
+ CamelIMAPXMailbox *mailbox;
CamelIMAPXSettings *settings;
CamelSortType fetch_order;
RefreshInfoData *data;
guint32 total, diff;
+ guint32 messages;
guint uidset_size;
gchar *uid = NULL;
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_val_if_fail (folder != NULL, FALSE);
settings = camel_imapx_server_ref_settings (is);
@@ -5859,10 +5969,10 @@ imapx_job_fetch_new_messages_start (CamelIMAPXJob *job,
uidset_size = camel_imapx_settings_get_batch_fetch_count (settings);
g_object_unref (settings);
- ifolder = CAMEL_IMAPX_FOLDER (folder);
+ messages = camel_imapx_mailbox_get_messages (mailbox);
total = camel_folder_summary_count (folder->summary);
- diff = ifolder->exists_on_server - total;
+ diff = messages - total;
if (total > 0) {
guint64 uidl;
@@ -5883,7 +5993,7 @@ imapx_job_fetch_new_messages_start (CamelIMAPXJob *job,
//printf ("Fetch order: %d/%d\n", fetch_order, CAMEL_SORT_DESCENDING);
if (diff > uidset_size || fetch_order == CAMEL_SORT_DESCENDING) {
ic = camel_imapx_command_new (
- is, "FETCH", folder,
+ is, "FETCH", mailbox,
"UID FETCH %s:* (UID FLAGS)", uid);
imapx_uidset_init (&data->uidset, uidset_size, 0);
refresh_info_data_infos_free (data);
@@ -5898,7 +6008,7 @@ imapx_job_fetch_new_messages_start (CamelIMAPXJob *job,
ic->complete = imapx_command_step_fetch_done;
} else {
ic = camel_imapx_command_new (
- is, "FETCH", folder,
+ is, "FETCH", mailbox,
"UID FETCH %s:* (RFC822.SIZE RFC822.HEADER FLAGS)", uid);
ic->pri = job->pri;
ic->complete = imapx_command_fetch_new_messages_done;
@@ -5913,6 +6023,7 @@ imapx_job_fetch_new_messages_start (CamelIMAPXJob *job,
g_free (uid);
g_object_unref (folder);
+ g_object_unref (mailbox);
return TRUE;
}
@@ -5938,11 +6049,11 @@ imapx_job_fetch_messages_start (CamelIMAPXJob *job,
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
- g_return_val_if_fail (folder != NULL, FALSE);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
- mailbox = camel_imapx_folder_ref_mailbox (CAMEL_IMAPX_FOLDER (folder));
- g_warn_if_fail (mailbox != NULL);
+ folder = imapx_server_ref_folder (is, mailbox);
+ g_return_val_if_fail (folder != NULL, FALSE);
settings = camel_imapx_server_ref_settings (is);
fetch_order = camel_imapx_settings_get_fetch_order (settings);
@@ -6003,7 +6114,7 @@ imapx_job_fetch_messages_start (CamelIMAPXJob *job,
/* New account and fetching old messages, we would return just the limited number of newest
messages */
ic = camel_imapx_command_new (
- is, "FETCH", folder,
+ is, "FETCH", mailbox,
"UID FETCH %s:* (UID FLAGS)", uid);
imapx_uidset_init (&data->uidset, uidset_size, 0);
@@ -6035,8 +6146,9 @@ imapx_job_fetch_messages_start (CamelIMAPXJob *job,
camel_folder_get_display_name (folder));
ic = camel_imapx_command_new (
- is, "FETCH", folder,
- "UID FETCH %s:%s (RFC822.SIZE RFC822.HEADER FLAGS)", start_uid, end_uid);
+ is, "FETCH", mailbox,
+ "UID FETCH %s:%s (RFC822.SIZE RFC822.HEADER FLAGS)",
+ start_uid, end_uid);
ic->pri = job->pri;
ic->complete = imapx_command_fetch_new_messages_done;
@@ -6053,8 +6165,8 @@ imapx_job_fetch_messages_start (CamelIMAPXJob *job,
camel_imapx_command_unref (ic);
- g_object_unref (mailbox);
g_object_unref (folder);
+ g_object_unref (mailbox);
return TRUE;
}
@@ -6065,7 +6177,6 @@ imapx_job_refresh_info_start (CamelIMAPXJob *job,
GCancellable *cancellable,
GError **error)
{
- CamelIMAPXFolder *ifolder;
CamelIMAPXSettings *settings;
CamelIMAPXSummary *isum;
CamelFolder *folder;
@@ -6076,19 +6187,23 @@ imapx_job_refresh_info_start (CamelIMAPXJob *job,
gboolean can_qresync = FALSE;
gboolean mobile_mode;
gboolean success;
+ guint32 messages;
+ guint32 unseen;
+ guint32 uidnext;
+ guint32 uidvalidity;
+ guint64 highestmodseq;
guint32 total;
- folder = camel_imapx_job_ref_folder (job);
- g_return_val_if_fail (folder != NULL, FALSE);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
- mailbox = camel_imapx_folder_ref_mailbox (CAMEL_IMAPX_FOLDER (folder));
- g_warn_if_fail (mailbox != NULL);
+ folder = imapx_server_ref_folder (is, mailbox);
+ g_return_val_if_fail (folder != NULL, FALSE);
settings = camel_imapx_server_ref_settings (is);
mobile_mode = camel_imapx_settings_get_mobile_mode (settings);
g_object_unref (settings);
- ifolder = CAMEL_IMAPX_FOLDER (folder);
isum = CAMEL_IMAPX_SUMMARY (folder->summary);
full_name = camel_folder_get_full_name (folder);
@@ -6096,10 +6211,16 @@ imapx_job_refresh_info_start (CamelIMAPXJob *job,
/* Sync changes first, else unread count will not
* match. Need to think about better ways for this */
success = imapx_server_sync_changes (
- is, folder, job->type, job->pri, cancellable, error);
+ is, mailbox, job->type, job->pri, cancellable, error);
if (!success)
goto done;
+ messages = camel_imapx_mailbox_get_messages (mailbox);
+ unseen = camel_imapx_mailbox_get_unseen (mailbox);
+ uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
+ uidvalidity = camel_imapx_mailbox_get_uidvalidity (mailbox);
+ highestmodseq = camel_imapx_mailbox_get_highestmodseq (mailbox);
+
#if 0 /* There are issues with this still; continue with the buggy
* behaviour where we issue STATUS on the current folder, for now. */
if (is->priv->select_folder == folder)
@@ -6107,26 +6228,23 @@ imapx_job_refresh_info_start (CamelIMAPXJob *job,
#endif
total = camel_folder_summary_count (folder->summary);
- if (ifolder->uidvalidity_on_server && isum->validity && isum->validity !=
ifolder->uidvalidity_on_server) {
- camel_imapx_folder_invalidate_local_cache (
- ifolder, ifolder->uidvalidity_on_server);
+ if (uidvalidity > 0 && uidvalidity != isum->validity)
need_rescan = TRUE;
- }
/* We don't have valid unread count or modseq for currently-selected server
* (unless we want to re-SELECT it). We fake unread count when fetching
* message flags, but don't depend on modseq for the selected folder */
- if (total != ifolder->exists_on_server ||
- isum->uidnext != ifolder->uidnext_on_server ||
- camel_folder_summary_get_unread_count (folder->summary) != ifolder->unread_on_server ||
- (!is_selected && isum->modseq != ifolder->modseq_on_server))
+ if (total != messages ||
+ isum->uidnext != uidnext ||
+ camel_folder_summary_get_unread_count (folder->summary) != unseen ||
+ (!is_selected && isum->modseq != highestmodseq))
need_rescan = TRUE;
/* This is probably the first check of this folder after startup;
* use STATUS to check whether the cached summary is valid, rather
* than blindly updating. Only for servers which support CONDSTORE
* though. */
- if ((isum->modseq && !ifolder->modseq_on_server))
+ if (isum->modseq > 0 && highestmodseq == 0)
need_rescan = FALSE;
/* If we don't think there's anything to do, poke it to check */
@@ -6173,10 +6291,16 @@ imapx_job_refresh_info_start (CamelIMAPXJob *job,
}
/* Recalulate need_rescan */
- if (total != ifolder->exists_on_server ||
- isum->uidnext != ifolder->uidnext_on_server ||
- camel_folder_summary_get_unread_count (folder->summary) != ifolder->unread_on_server ||
- (!is_selected && isum->modseq != ifolder->modseq_on_server))
+
+ messages = camel_imapx_mailbox_get_messages (mailbox);
+ unseen = camel_imapx_mailbox_get_unseen (mailbox);
+ uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
+ highestmodseq = camel_imapx_mailbox_get_highestmodseq (mailbox);
+
+ if (total != messages ||
+ isum->uidnext != uidnext ||
+ camel_folder_summary_get_unread_count (folder->summary) != unseen ||
+ (!is_selected && isum->modseq != highestmodseq))
need_rescan = TRUE;
} else if (mobile_mode) {
@@ -6202,7 +6326,13 @@ imapx_job_refresh_info_start (CamelIMAPXJob *job,
}
}
- if (is->use_qresync && isum->modseq && ifolder->uidvalidity_on_server)
+ messages = camel_imapx_mailbox_get_messages (mailbox);
+ unseen = camel_imapx_mailbox_get_unseen (mailbox);
+ uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
+ uidvalidity = camel_imapx_mailbox_get_uidvalidity (mailbox);
+ highestmodseq = camel_imapx_mailbox_get_highestmodseq (mailbox);
+
+ if (is->use_qresync && isum->modseq > 0 && uidvalidity > 0)
can_qresync = TRUE;
e (
@@ -6214,24 +6344,22 @@ imapx_job_refresh_info_start (CamelIMAPXJob *job,
full_name,
is_selected ? "" : "not ",
total,
- ifolder->exists_on_server,
+ messages,
camel_folder_summary_get_unread_count (folder->summary),
- ifolder->unread_on_server,
- (guint64) isum->modseq,
- (guint64) ifolder->modseq_on_server,
+ unseen,
+ isum->modseq,
+ highestmodseq,
isum->uidnext,
- ifolder->uidnext_on_server,
+ uidnext,
need_rescan ? "" : "not ");
/* Fetch new messages first, so that they appear to the user ASAP */
- if (ifolder->exists_on_server > total ||
- ifolder->uidnext_on_server > isum->uidnext)
- {
+ if (messages > total || uidnext > isum->uidnext) {
if (!total)
need_rescan = FALSE;
success = imapx_server_fetch_new_messages (
- is, folder, FALSE, FALSE, cancellable, error);
+ is, mailbox, FALSE, FALSE, cancellable, error);
if (!success)
goto done;
@@ -6246,48 +6374,52 @@ imapx_job_refresh_info_start (CamelIMAPXJob *job,
if (can_qresync) {
/* Actually we only want to select it; no need for the NOOP */
success = camel_imapx_server_noop (
- is, folder, cancellable, error);
+ is, mailbox, cancellable, error);
if (!success)
goto done;
qresync_done:
- isum->modseq = ifolder->modseq_on_server;
+ messages = camel_imapx_mailbox_get_messages (mailbox);
+ unseen = camel_imapx_mailbox_get_unseen (mailbox);
+ highestmodseq = camel_imapx_mailbox_get_highestmodseq (mailbox);
+
+ isum->modseq = highestmodseq;
total = camel_folder_summary_count (folder->summary);
- if (total != ifolder->exists_on_server ||
- camel_folder_summary_get_unread_count (folder->summary) != ifolder->unread_on_server ||
- (isum->modseq != ifolder->modseq_on_server)) {
+ if (total != messages ||
+ camel_folder_summary_get_unread_count (folder->summary) != unseen ||
+ (isum->modseq != highestmodseq)) {
c (
is->tagprefix,
"Eep, after QRESYNC we're out of sync. "
"total %u / %u, unread %u / %u, modseq %"
G_GUINT64_FORMAT " / %" G_GUINT64_FORMAT "\n",
- total, ifolder->exists_on_server,
+ total, messages,
camel_folder_summary_get_unread_count (folder->summary),
- ifolder->unread_on_server,
+ unseen,
isum->modseq,
- ifolder->modseq_on_server);
+ highestmodseq);
} else {
c (
is->tagprefix,
"OK, after QRESYNC we're still in sync. "
"total %u / %u, unread %u / %u, modseq %"
G_GUINT64_FORMAT " / %" G_GUINT64_FORMAT "\n",
- total, ifolder->exists_on_server,
+ total, messages,
camel_folder_summary_get_unread_count (folder->summary),
- ifolder->unread_on_server,
+ unseen,
isum->modseq,
- ifolder->modseq_on_server);
+ highestmodseq);
goto done;
}
}
- g_object_unref (mailbox);
g_object_unref (folder);
+ g_object_unref (mailbox);
return imapx_job_scan_changes_start (job, is, cancellable, error);
done:
- g_object_unref (mailbox);
g_object_unref (folder);
+ g_object_unref (mailbox);
imapx_unregister_job (is, job);
@@ -6296,10 +6428,10 @@ done:
static gboolean
imapx_job_refresh_info_matches (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid)
{
- return camel_imapx_job_has_folder (job, folder);
+ return camel_imapx_job_has_mailbox (job, mailbox);
}
/* ********************************************************************** */
@@ -6309,13 +6441,17 @@ imapx_command_expunge_done (CamelIMAPXServer *is,
CamelIMAPXCommand *ic)
{
CamelIMAPXJob *job;
+ CamelIMAPXMailbox *mailbox;
CamelFolder *folder;
GError *local_error = NULL;
job = camel_imapx_command_get_job (ic);
g_return_if_fail (CAMEL_IS_IMAPX_JOB (job));
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_if_fail (mailbox != NULL);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_if_fail (folder != NULL);
if (camel_imapx_command_set_error_if_failed (ic, &local_error)) {
@@ -6368,6 +6504,7 @@ imapx_command_expunge_done (CamelIMAPXServer *is,
}
g_object_unref (folder);
+ g_object_unref (mailbox);
imapx_unregister_job (is, job);
}
@@ -6379,19 +6516,19 @@ imapx_job_expunge_start (CamelIMAPXJob *job,
GError **error)
{
CamelIMAPXCommand *ic;
- CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
gboolean success;
- folder = camel_imapx_job_ref_folder (job);
- g_return_val_if_fail (folder != NULL, FALSE);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
success = imapx_server_sync_changes (
- is, folder, job->type, job->pri, cancellable, error);
+ is, mailbox, job->type, job->pri, cancellable, error);
if (success) {
/* TODO handle UIDPLUS capability */
ic = camel_imapx_command_new (
- is, "EXPUNGE", folder, "EXPUNGE");
+ is, "EXPUNGE", mailbox, "EXPUNGE");
camel_imapx_command_set_job (ic, job);
ic->pri = job->pri;
ic->complete = imapx_command_expunge_done;
@@ -6401,17 +6538,17 @@ imapx_job_expunge_start (CamelIMAPXJob *job,
camel_imapx_command_unref (ic);
}
- g_object_unref (folder);
+ g_object_unref (mailbox);
return success;
}
static gboolean
imapx_job_expunge_matches (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid)
{
- return camel_imapx_job_has_folder (job, folder);
+ return camel_imapx_job_has_mailbox (job, mailbox);
}
/* ********************************************************************** */
@@ -6473,7 +6610,7 @@ imapx_job_list_start (CamelIMAPXJob *job,
static gboolean
imapx_job_list_matches (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid)
{
return TRUE; /* matches everything */
@@ -6526,24 +6663,23 @@ imapx_job_manage_subscription_start (CamelIMAPXJob *job,
GError **error)
{
CamelIMAPXCommand *ic;
- CamelIMAPXStore *store;
+ CamelIMAPXMailbox *mailbox;
ManageSubscriptionsData *data;
- gchar *encoded_fname = NULL;
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- store = camel_imapx_server_ref_store (is);
- encoded_fname = imapx_encode_folder_name (store, data->folder_name);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
if (data->subscribe)
ic = camel_imapx_command_new (
is, "SUBSCRIBE", NULL,
- "SUBSCRIBE %s", encoded_fname);
+ "SUBSCRIBE %m", mailbox);
else
ic = camel_imapx_command_new (
is, "UNSUBSCRIBE", NULL,
- "UNSUBSCRIBE %s", encoded_fname);
+ "UNSUBSCRIBE %m", mailbox);
ic->pri = job->pri;
camel_imapx_command_set_job (ic, job);
@@ -6553,8 +6689,7 @@ imapx_job_manage_subscription_start (CamelIMAPXJob *job,
camel_imapx_command_unref (ic);
- g_free (encoded_fname);
- g_object_unref (store);
+ g_clear_object (&mailbox);
return TRUE;
}
@@ -6562,8 +6697,8 @@ imapx_job_manage_subscription_start (CamelIMAPXJob *job,
/* ********************************************************************** */
static void
-imapx_command_create_folder_done (CamelIMAPXServer *is,
- CamelIMAPXCommand *ic)
+imapx_command_create_mailbox_done (CamelIMAPXServer *is,
+ CamelIMAPXCommand *ic)
{
CamelIMAPXJob *job;
GError *local_error = NULL;
@@ -6582,41 +6717,36 @@ imapx_command_create_folder_done (CamelIMAPXServer *is,
}
static gboolean
-imapx_job_create_folder_start (CamelIMAPXJob *job,
- CamelIMAPXServer *is,
- GCancellable *cancellable,
- GError **error)
+imapx_job_create_mailbox_start (CamelIMAPXJob *job,
+ CamelIMAPXServer *is,
+ GCancellable *cancellable,
+ GError **error)
{
CamelIMAPXCommand *ic;
- CreateFolderData *data;
- gchar *encoded_fname = NULL;
+ CreateMailboxData *data;
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- encoded_fname = camel_utf8_utf7 (data->folder_name);
-
ic = camel_imapx_command_new (
- is, "CREATE", NULL,
- "CREATE %s", encoded_fname);
+ is, "CREATE", NULL, "CREATE %s",
+ data->utf7_mailbox_name);
ic->pri = job->pri;
camel_imapx_command_set_job (ic, job);
- ic->complete = imapx_command_create_folder_done;
+ ic->complete = imapx_command_create_mailbox_done;
imapx_command_queue (is, ic);
camel_imapx_command_unref (ic);
- g_free (encoded_fname);
-
return TRUE;
}
/* ********************************************************************** */
static void
-imapx_command_delete_folder_done (CamelIMAPXServer *is,
- CamelIMAPXCommand *ic)
+imapx_command_delete_mailbox_done (CamelIMAPXServer *is,
+ CamelIMAPXCommand *ic)
{
CamelIMAPXJob *job;
GError *local_error = NULL;
@@ -6635,52 +6765,38 @@ imapx_command_delete_folder_done (CamelIMAPXServer *is,
}
static gboolean
-imapx_job_delete_folder_start (CamelIMAPXJob *job,
- CamelIMAPXServer *is,
- GCancellable *cancellable,
- GError **error)
+imapx_job_delete_mailbox_start (CamelIMAPXJob *job,
+ CamelIMAPXServer *is,
+ GCancellable *cancellable,
+ GError **error)
{
CamelIMAPXCommand *ic;
- CamelIMAPXStore *store;
- CamelFolder *folder;
- DeleteFolderData *data;
- gchar *encoded_fname = NULL;
- gboolean success = FALSE;
-
- data = camel_imapx_job_get_data (job);
- g_return_val_if_fail (data != NULL, FALSE);
-
- store = camel_imapx_server_ref_store (is);
- encoded_fname = imapx_encode_folder_name (store, data->folder_name);
-
- folder = camel_store_get_folder_sync (
- CAMEL_STORE (store), "INBOX", 0, cancellable, error);
-
- if (folder != NULL) {
- camel_imapx_job_set_folder (job, folder);
+ CamelIMAPXMailbox *inbox;
+ CamelIMAPXMailbox *mailbox;
- /* Make sure the to-be-deleted folder is not
- * selected by selecting INBOX for this operation. */
- ic = camel_imapx_command_new (
- is, "DELETE", folder,
- "DELETE %s", encoded_fname);
- ic->pri = job->pri;
- camel_imapx_command_set_job (ic, job);
- ic->complete = imapx_command_delete_folder_done;
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
- imapx_command_queue (is, ic);
+ /* Keep going, even if this returns NULL. */
+ inbox = camel_imapx_server_ref_mailbox (is, "INBOX");
- camel_imapx_command_unref (ic);
+ /* Make sure the to-be-deleted folder is not
+ * selected by selecting INBOX for this operation. */
+ ic = camel_imapx_command_new (
+ is, "DELETE", inbox,
+ "DELETE %m", mailbox);
+ ic->pri = job->pri;
+ camel_imapx_command_set_job (ic, job);
+ ic->complete = imapx_command_delete_mailbox_done;
- g_object_unref (folder);
+ imapx_command_queue (is, ic);
- success = TRUE;
- }
+ camel_imapx_command_unref (ic);
- g_free (encoded_fname);
- g_object_unref (store);
+ g_clear_object (&inbox);
+ g_clear_object (&mailbox);
- return success;
+ return TRUE;
}
/* ********************************************************************** */
@@ -6712,12 +6828,11 @@ imapx_job_rename_folder_start (CamelIMAPXJob *job,
GError **error)
{
CamelIMAPXCommand *ic;
+ CamelIMAPXMailbox *mailbox;
CamelIMAPXStore *store;
RenameFolderData *data;
- CamelFolder *folder;
gchar *en_ofname = NULL;
gchar *en_nfname = NULL;
- gboolean success = FALSE;
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
@@ -6727,34 +6842,29 @@ imapx_job_rename_folder_start (CamelIMAPXJob *job,
en_ofname = imapx_encode_folder_name (store, data->old_folder_name);
en_nfname = imapx_encode_folder_name (store, data->new_folder_name);
- folder = camel_store_get_folder_sync (
- CAMEL_STORE (store), "INBOX", 0, cancellable, error);
-
- if (folder != NULL) {
- camel_imapx_job_set_folder (job, folder);
+ mailbox = camel_imapx_server_ref_mailbox (is, "INBOX");
+ g_return_val_if_fail (mailbox != NULL, FALSE);
- ic = camel_imapx_command_new (
- is, "RENAME", folder,
- "RENAME %s %s", en_ofname, en_nfname);
- ic->pri = job->pri;
- camel_imapx_command_set_job (ic, job);
- ic->complete = imapx_command_rename_folder_done;
+ camel_imapx_job_set_mailbox (job, mailbox);
- imapx_command_queue (is, ic);
-
- camel_imapx_command_unref (ic);
+ ic = camel_imapx_command_new (
+ is, "RENAME", mailbox,
+ "RENAME %s %s", en_ofname, en_nfname);
+ ic->pri = job->pri;
+ camel_imapx_command_set_job (ic, job);
+ ic->complete = imapx_command_rename_folder_done;
- g_object_unref (folder);
+ imapx_command_queue (is, ic);
- success = TRUE;
- }
+ camel_imapx_command_unref (ic);
g_free (en_ofname);
g_free (en_nfname);
+ g_object_unref (mailbox);
g_object_unref (store);
- return success;
+ return TRUE;
}
/* ********************************************************************** */
@@ -6786,19 +6896,14 @@ imapx_job_update_quota_info_start (CamelIMAPXJob *job,
GError **error)
{
CamelIMAPXCommand *ic;
- CamelIMAPXStore *store;
- QuotaData *data;
- gchar *encoded_fname;
-
- data = camel_imapx_job_get_data (job);
- g_return_val_if_fail (data != NULL, FALSE);
+ CamelIMAPXMailbox *mailbox;
- store = camel_imapx_server_ref_store (is);
- encoded_fname = imapx_encode_folder_name (store, data->folder_name);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
ic = camel_imapx_command_new (
is, "GETQUOTAROOT", NULL,
- "GETQUOTAROOT %s", encoded_fname);
+ "GETQUOTAROOT %m", mailbox);
ic->pri = job->pri;
camel_imapx_command_set_job (ic, job);
ic->complete = imapx_command_update_quota_info_done;
@@ -6807,8 +6912,7 @@ imapx_job_update_quota_info_start (CamelIMAPXJob *job,
camel_imapx_command_unref (ic);
- g_free (encoded_fname);
- g_object_unref (store);
+ g_clear_object (&mailbox);
return TRUE;
}
@@ -6851,18 +6955,18 @@ imapx_job_uid_search_start (CamelIMAPXJob *job,
GCancellable *cancellable,
GError **error)
{
- CamelFolder *folder;
CamelIMAPXCommand *ic;
+ CamelIMAPXMailbox *mailbox;
SearchData *data;
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
- g_return_val_if_fail (folder != NULL, FALSE);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
ic = camel_imapx_command_new (
- is, "UID SEARCH", folder,
+ is, "UID SEARCH", mailbox,
"UID SEARCH %t", data->criteria);
ic->pri = job->pri;
camel_imapx_command_set_job (ic, job);
@@ -6872,7 +6976,7 @@ imapx_job_uid_search_start (CamelIMAPXJob *job,
camel_imapx_command_unref (ic);
- g_object_unref (folder);
+ g_object_unref (mailbox);
return TRUE;
}
@@ -6906,26 +7010,27 @@ imapx_job_noop_start (CamelIMAPXJob *job,
GError **error)
{
CamelIMAPXCommand *ic;
- CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
- folder = camel_imapx_job_ref_folder (job);
+ /* This may be NULL. */
+ mailbox = camel_imapx_job_ref_mailbox (job);
ic = camel_imapx_command_new (
- is, "NOOP", folder, "NOOP");
+ is, "NOOP", mailbox, "NOOP");
camel_imapx_command_set_job (ic, job);
ic->complete = imapx_command_noop_done;
- if (folder != NULL) {
+ if (mailbox != NULL)
ic->pri = IMAPX_PRIORITY_REFRESH_INFO;
- g_object_unref (folder);
- } else {
+ else
ic->pri = IMAPX_PRIORITY_NOOP;
- }
imapx_command_queue (is, ic);
camel_imapx_command_unref (ic);
+ g_clear_object (&mailbox);
+
return TRUE;
}
@@ -6961,6 +7066,7 @@ imapx_command_sync_changes_done (CamelIMAPXServer *is,
CamelIMAPXCommand *ic)
{
CamelIMAPXJob *job;
+ CamelIMAPXMailbox *mailbox;
CamelFolder *folder;
CamelStore *parent_store;
SyncChangesData *data;
@@ -6975,7 +7081,10 @@ imapx_command_sync_changes_done (CamelIMAPXServer *is,
data = camel_imapx_job_get_data (job);
g_return_if_fail (data != NULL);
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_if_fail (mailbox != NULL);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_if_fail (folder != NULL);
settings = camel_imapx_server_ref_settings (is);
@@ -7007,6 +7116,7 @@ imapx_command_sync_changes_done (CamelIMAPXServer *is,
/* lock cache ? */
} else {
+ guint32 unseen;
gint i;
for (i = 0; i < data->changed_uids->len; i++) {
@@ -7031,9 +7141,12 @@ imapx_command_sync_changes_done (CamelIMAPXServer *is,
camel_folder_summary_touch (folder->summary);
camel_message_info_free (xinfo);
}
+
/* Apply the changes to server-side unread count; it won't tell
* us of these changes, of course. */
- ((CamelIMAPXFolder *) folder)->unread_on_server += data->unread_change;
+ unseen = camel_imapx_mailbox_get_unseen (mailbox);
+ unseen += data->unread_change;
+ camel_imapx_mailbox_set_unseen (mailbox, unseen);
}
if (job->commands == 0) {
@@ -7066,6 +7179,7 @@ imapx_command_sync_changes_done (CamelIMAPXServer *is,
exit:
g_object_unref (folder);
+ g_object_unref (mailbox);
}
static gboolean
@@ -7076,6 +7190,7 @@ imapx_job_sync_changes_start (CamelIMAPXJob *job,
{
SyncChangesData *data;
CamelFolder *folder;
+ CamelIMAPXMailbox *mailbox;
guint32 i, j;
struct _uidset_state ss;
GPtrArray *uids;
@@ -7084,7 +7199,10 @@ imapx_job_sync_changes_start (CamelIMAPXJob *job,
data = camel_imapx_job_get_data (job);
g_return_val_if_fail (data != NULL, FALSE);
- folder = camel_imapx_job_ref_folder (job);
+ mailbox = camel_imapx_job_ref_mailbox (job);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
+
+ folder = imapx_server_ref_folder (is, mailbox);
g_return_val_if_fail (folder != NULL, FALSE);
uids = data->changed_uids;
@@ -7136,7 +7254,7 @@ imapx_job_sync_changes_start (CamelIMAPXJob *job,
|| (!on && (((flags ^ sflags) & ~flags) & flag))) {
if (ic == NULL) {
ic = camel_imapx_command_new (
- is, "STORE", folder,
+ is, "STORE", mailbox,
"UID STORE ");
ic->complete = imapx_command_sync_changes_done;
camel_imapx_command_set_job (ic, job);
@@ -7175,7 +7293,7 @@ imapx_job_sync_changes_start (CamelIMAPXJob *job,
if (ic == NULL) {
ic = camel_imapx_command_new (
- is, "STORE", folder,
+ is, "STORE", mailbox,
"UID STORE ");
ic->complete = imapx_command_sync_changes_done;
camel_imapx_command_set_job (ic, job);
@@ -7196,6 +7314,7 @@ imapx_job_sync_changes_start (CamelIMAPXJob *job,
}
g_object_unref (folder);
+ g_object_unref (mailbox);
/* Since this may start in another thread ... we need to
* lock the commands count, ho hum */
@@ -7208,10 +7327,10 @@ imapx_job_sync_changes_start (CamelIMAPXJob *job,
static gboolean
imapx_job_sync_changes_matches (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid)
{
- return camel_imapx_job_has_folder (job, folder);
+ return camel_imapx_job_has_mailbox (job, mailbox);
}
static void
@@ -7829,24 +7948,18 @@ camel_imapx_server_ref_mailbox (CamelIMAPXServer *is,
CamelIMAPXMailbox *
camel_imapx_server_ref_selected (CamelIMAPXServer *is)
{
- CamelIMAPXFolder *folder;
- CamelIMAPXMailbox *mailbox = NULL;
+ CamelIMAPXMailbox *mailbox;
g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), NULL);
g_mutex_lock (&is->priv->select_lock);
- folder = g_weak_ref_get (&is->priv->select_folder);
- if (folder == NULL)
- folder = g_weak_ref_get (&is->priv->select_pending);
+ mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+ if (mailbox == NULL)
+ mailbox = g_weak_ref_get (&is->priv->select_pending);
g_mutex_unlock (&is->priv->select_lock);
- if (folder != NULL) {
- mailbox = camel_imapx_folder_ref_mailbox (folder);
- g_object_unref (folder);
- }
-
return mailbox;
}
@@ -7914,7 +8027,7 @@ imapx_disconnect (CamelIMAPXServer *is)
g_mutex_unlock (&is->priv->stream_lock);
g_mutex_lock (&is->priv->select_lock);
- g_weak_ref_set (&is->priv->select_folder, NULL);
+ g_weak_ref_set (&is->priv->select_mailbox, NULL);
g_weak_ref_set (&is->priv->select_pending, NULL);
g_mutex_unlock (&is->priv->select_lock);
@@ -7958,23 +8071,25 @@ camel_imapx_server_connect (CamelIMAPXServer *is,
static CamelStream *
imapx_server_get_message (CamelIMAPXServer *is,
- CamelFolder *folder,
- const gchar *uid,
+ CamelIMAPXMailbox *mailbox,
+ CamelFolderSummary *summary,
+ CamelDataCache *message_cache,
+ const gchar *message_uid,
gint pri,
GCancellable *cancellable,
GError **error)
{
CamelStream *stream = NULL;
- CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) folder;
CamelIMAPXJob *job;
CamelMessageInfo *mi;
GetMessageData *data;
gboolean registered;
- gboolean success;
QUEUE_LOCK (is);
- job = imapx_is_job_in_queue (is, folder, IMAPX_JOB_GET_MESSAGE, uid);
+ job = imapx_is_job_in_queue (
+ is, mailbox, IMAPX_JOB_GET_MESSAGE, message_uid);
+
if (job != NULL) {
/* Promote the existing GET_MESSAGE
* job's priority if ours is higher. */
@@ -7990,27 +8105,29 @@ imapx_server_get_message (CamelIMAPXServer *is,
* message from cache (implying the job we were waiting
* on failed or got cancelled), we'll just re-fetch it. */
stream = camel_data_cache_get (
- ifolder->cache, "cur", uid, NULL);
+ message_cache, "cur", message_uid, NULL);
if (stream != NULL)
return stream;
QUEUE_LOCK (is);
}
- mi = camel_folder_summary_get (folder->summary, uid);
- if (!mi) {
+ mi = camel_folder_summary_get (summary, message_uid);
+ if (mi == NULL) {
g_set_error (
error, CAMEL_FOLDER_ERROR,
CAMEL_FOLDER_ERROR_INVALID_UID,
_("Cannot get message with message ID %s: %s"),
- uid, _("No such message available."));
+ message_uid, _("No such message available."));
QUEUE_UNLOCK (is);
return NULL;
}
data = g_slice_new0 (GetMessageData);
- data->uid = g_strdup (uid);
- data->stream = camel_data_cache_add (ifolder->cache, "tmp", uid, NULL);
+ data->uid = g_strdup (message_uid);
+ data->message_cache = g_object_ref (message_cache);
+ data->stream = camel_data_cache_add (
+ message_cache, "tmp", message_uid, NULL);
data->size = ((CamelMessageInfoBase *) mi)->size;
if (data->size > MULTI_SIZE)
data->use_multi_fetch = TRUE;
@@ -8021,7 +8138,7 @@ imapx_server_get_message (CamelIMAPXServer *is,
job->start = imapx_job_get_message_start;
job->matches = imapx_job_get_message_matches;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
camel_imapx_job_set_data (
job, data, (GDestroyNotify) get_message_data_free);
@@ -8031,9 +8148,7 @@ imapx_server_get_message (CamelIMAPXServer *is,
QUEUE_UNLOCK (is);
- success = registered && camel_imapx_job_run (job, is, error);
-
- if (success)
+ if (registered && camel_imapx_job_run (job, is, error))
stream = g_object_ref (data->stream);
camel_imapx_job_unref (job);
@@ -8043,60 +8158,73 @@ imapx_server_get_message (CamelIMAPXServer *is,
CamelStream *
camel_imapx_server_get_message (CamelIMAPXServer *is,
- CamelFolder *folder,
- const gchar *uid,
+ CamelIMAPXMailbox *mailbox,
+ CamelFolderSummary *summary,
+ CamelDataCache *message_cache,
+ const gchar *message_uid,
GCancellable *cancellable,
GError **error)
{
- CamelStream *stream;
-
- stream = imapx_server_get_message (
- is, folder, uid,
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), NULL);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), NULL);
+ g_return_val_if_fail (CAMEL_IS_FOLDER_SUMMARY (summary), NULL);
+ g_return_val_if_fail (CAMEL_IS_DATA_CACHE (message_cache), NULL);
+ g_return_val_if_fail (message_uid != NULL, NULL);
+
+ return imapx_server_get_message (
+ is, mailbox, summary,
+ message_cache, message_uid,
IMAPX_PRIORITY_GET_MESSAGE,
cancellable, error);
-
- return stream;
}
gboolean
camel_imapx_server_sync_message (CamelIMAPXServer *is,
- CamelFolder *folder,
- const gchar *uid,
+ CamelIMAPXMailbox *mailbox,
+ CamelFolderSummary *summary,
+ CamelDataCache *message_cache,
+ const gchar *message_uid,
GCancellable *cancellable,
GError **error)
{
gchar *cache_file = NULL;
- CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) folder;
- CamelStream *stream;
gboolean is_cached;
struct stat st;
+ gboolean success = TRUE;
+
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
+ g_return_val_if_fail (CAMEL_IS_FOLDER_SUMMARY (summary), FALSE);
+ g_return_val_if_fail (CAMEL_IS_DATA_CACHE (message_cache), FALSE);
+ g_return_val_if_fail (message_uid != NULL, FALSE);
/* Check if the cache file already exists and is non-empty. */
cache_file = camel_data_cache_get_filename (
- ifolder->cache, "cur", uid);
+ message_cache, "cur", message_uid);
is_cached = (g_stat (cache_file, &st) == 0 && st.st_size > 0);
g_free (cache_file);
- if (is_cached)
- return TRUE;
+ if (!is_cached) {
+ CamelStream *stream;
- stream = imapx_server_get_message (
- is, folder, uid,
- IMAPX_PRIORITY_SYNC_MESSAGE,
- cancellable, error);
+ stream = imapx_server_get_message (
+ is, mailbox, summary,
+ message_cache, message_uid,
+ IMAPX_PRIORITY_SYNC_MESSAGE,
+ cancellable, error);
- if (stream == NULL)
- return FALSE;
+ success = (stream != NULL);
- g_object_unref (stream);
+ g_clear_object (&stream);
+ }
- return TRUE;
+ return success;
}
gboolean
camel_imapx_server_copy_message (CamelIMAPXServer *is,
- CamelFolder *source,
- CamelFolder *dest,
+ CamelIMAPXMailbox *mailbox,
+ CamelIMAPXMailbox *destination,
GPtrArray *uids,
gboolean delete_originals,
GCancellable *cancellable,
@@ -8106,8 +8234,13 @@ camel_imapx_server_copy_message (CamelIMAPXServer *is,
CopyMessagesData *data;
gint ii;
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (destination), FALSE);
+ g_return_val_if_fail (uids != NULL, FALSE);
+
data = g_slice_new0 (CopyMessagesData);
- data->dest = g_object_ref (dest);
+ data->destination = g_object_ref (destination);
data->uids = g_ptr_array_new ();
data->delete_originals = delete_originals;
@@ -8127,7 +8260,7 @@ camel_imapx_server_copy_message (CamelIMAPXServer *is,
job->type = IMAPX_JOB_COPY_MESSAGE;
job->start = imapx_job_copy_messages_start;
- camel_imapx_job_set_folder (job, source);
+ camel_imapx_job_set_mailbox (job, mailbox);
camel_imapx_job_set_data (
job, data, (GDestroyNotify) copy_messages_data_free);
@@ -8137,7 +8270,9 @@ camel_imapx_server_copy_message (CamelIMAPXServer *is,
gboolean
camel_imapx_server_append_message (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
+ CamelFolderSummary *summary,
+ CamelDataCache *message_cache,
CamelMimeMessage *message,
const CamelMessageInfo *mi,
gchar **appended_uid,
@@ -8146,7 +8281,6 @@ camel_imapx_server_append_message (CamelIMAPXServer *is,
{
gchar *uid = NULL, *path = NULL;
CamelStream *stream, *filter;
- CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) folder;
CamelMimeFilter *canon;
CamelIMAPXJob *job;
CamelMessageInfo *info;
@@ -8154,6 +8288,13 @@ camel_imapx_server_append_message (CamelIMAPXServer *is,
gint res;
gboolean success;
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
+ g_return_val_if_fail (CAMEL_IS_FOLDER_SUMMARY (summary), FALSE);
+ g_return_val_if_fail (CAMEL_IS_DATA_CACHE (message_cache), FALSE);
+ g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE);
+ /* CamelMessageInfo can be NULL. */
+
/* Append just assumes we have no/a dodgy connection. We dump
* stuff into the 'new' directory, and let the summary know it's
* there. Then we fire off a no-reply job which will asynchronously
@@ -8162,7 +8303,7 @@ camel_imapx_server_append_message (CamelIMAPXServer *is,
/* chen cleanup this later */
uid = imapx_get_temp_uid ();
- stream = camel_data_cache_add (ifolder->cache, "new", uid, error);
+ stream = camel_data_cache_add (message_cache, "new", uid, error);
if (stream == NULL) {
g_prefix_error (error, _("Cannot create spool file: "));
g_free (uid);
@@ -8180,15 +8321,16 @@ camel_imapx_server_append_message (CamelIMAPXServer *is,
if (res == -1) {
g_prefix_error (error, _("Cannot create spool file: "));
- camel_data_cache_remove (ifolder->cache, "new", uid, NULL);
+ camel_data_cache_remove (message_cache, "new", uid, NULL);
g_free (uid);
return FALSE;
}
- path = camel_data_cache_get_filename (ifolder->cache, "new", uid);
- info = camel_folder_summary_info_new_from_message ((CamelFolderSummary *) folder->summary, message,
NULL);
+ path = camel_data_cache_get_filename (message_cache, "new", uid);
+ info = camel_folder_summary_info_new_from_message (
+ summary, message, NULL);
info->uid = camel_pstring_strdup (uid);
- if (mi) {
+ if (mi != NULL) {
CamelMessageInfoBase *base_info = (CamelMessageInfoBase *) info;
base_info->flags = camel_message_info_flags (mi);
@@ -8199,16 +8341,20 @@ camel_imapx_server_append_message (CamelIMAPXServer *is,
const CamelTag *tag;
flag = camel_message_info_user_flags (mi);
- while (flag) {
- if (flag->name && *flag->name)
- camel_flag_set (&base_info->user_flags, flag->name, TRUE);
+ while (flag != NULL) {
+ if (flag->name != NULL && *flag->name != '\0')
+ camel_flag_set (
+ &base_info->user_flags,
+ flag->name, TRUE);
flag = flag->next;
}
tag = camel_message_info_user_tags (mi);
- while (tag) {
- if (tag->name && *tag->name)
- camel_tag_set (&base_info->user_tags, tag->name, tag->value);
+ while (tag != NULL) {
+ if (tag->name != NULL && *tag->name != '\0')
+ camel_tag_set (
+ &base_info->user_tags,
+ tag->name, tag->value);
tag = tag->next;
}
}
@@ -8232,7 +8378,7 @@ camel_imapx_server_append_message (CamelIMAPXServer *is,
job->start = imapx_job_append_message_start;
job->noreply = FALSE;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
camel_imapx_job_set_data (
job, data, (GDestroyNotify) append_message_data_free);
@@ -8251,19 +8397,22 @@ camel_imapx_server_append_message (CamelIMAPXServer *is,
gboolean
camel_imapx_server_noop (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
CamelIMAPXJob *job;
gboolean success;
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ /* Mailbox may be NULL. */
+
job = camel_imapx_job_new (cancellable);
job->type = IMAPX_JOB_NOOP;
job->start = imapx_job_noop_start;
job->pri = IMAPX_PRIORITY_NOOP;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
success = imapx_submit_job (is, job, error);
@@ -8272,27 +8421,33 @@ camel_imapx_server_noop (CamelIMAPXServer *is,
return success;
}
-gboolean
+CamelFolderChangeInfo *
camel_imapx_server_refresh_info (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
CamelIMAPXJob *job;
RefreshInfoData *data;
+ CamelFolderChangeInfo *changes = NULL;
gboolean registered = TRUE;
- const gchar *full_name;
- gboolean success = TRUE;
+ const gchar *mailbox_name;
- full_name = camel_folder_get_full_name (folder);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
QUEUE_LOCK (is);
/* Both RefreshInfo and Fetch messages can't operate simultaneously */
- if (imapx_is_job_in_queue (is, folder, IMAPX_JOB_REFRESH_INFO, NULL) ||
- imapx_is_job_in_queue (is, folder, IMAPX_JOB_FETCH_MESSAGES, NULL)) {
+ job = imapx_is_job_in_queue (
+ is, mailbox, IMAPX_JOB_REFRESH_INFO, NULL);
+ if (job == NULL)
+ job = imapx_is_job_in_queue (
+ is, mailbox, IMAPX_JOB_FETCH_MESSAGES, NULL);
+
+ if (job != NULL) {
QUEUE_UNLOCK (is);
- return TRUE;
+ return camel_folder_change_info_new ();
}
data = g_slice_new0 (RefreshInfoData);
@@ -8304,9 +8459,11 @@ camel_imapx_server_refresh_info (CamelIMAPXServer *is,
job->matches = imapx_job_refresh_info_matches;
job->pri = IMAPX_PRIORITY_REFRESH_INFO;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
- if (g_ascii_strcasecmp (full_name, "INBOX") == 0)
+ mailbox_name = camel_imapx_mailbox_get_name (mailbox);
+
+ if (camel_imapx_mailbox_is_inbox (mailbox_name))
job->pri += 10;
camel_imapx_job_set_data (
@@ -8316,14 +8473,14 @@ camel_imapx_server_refresh_info (CamelIMAPXServer *is,
QUEUE_UNLOCK (is);
- success = registered && camel_imapx_job_run (job, is, error);
-
- if (success && camel_folder_change_info_changed (data->changes))
- camel_folder_changed (folder, data->changes);
+ if (registered && camel_imapx_job_run (job, is, error)) {
+ changes = data->changes;
+ data->changes = NULL;
+ }
camel_imapx_job_unref (job);
- return success;
+ return changes;
}
static void
@@ -8352,7 +8509,7 @@ imapx_sync_free_user (GArray *user_set)
static gboolean
imapx_server_sync_changes (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
guint32 job_type,
gint pri,
GCancellable *cancellable,
@@ -8361,6 +8518,7 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
guint i, on_orset, off_orset;
GPtrArray *changed_uids;
GArray *on_user = NULL, *off_user = NULL;
+ CamelFolder *folder;
CamelIMAPXMessageInfo *info;
CamelIMAPXJob *job;
CamelIMAPXSettings *settings;
@@ -8371,6 +8529,9 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
gboolean registered;
gboolean success = TRUE;
+ folder = imapx_server_ref_folder (is, mailbox);
+ g_return_val_if_fail (folder != NULL, FALSE);
+
/* We calculate two masks, a mask of all flags which have been
* turned off and a mask of all flags which have been turned
* on. If either of these aren't 0, then we have work to do,
@@ -8385,6 +8546,7 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
if (changed_uids->len == 0) {
camel_folder_free_uids (folder, changed_uids);
+ g_object_unref (folder);
return TRUE;
}
@@ -8509,6 +8671,7 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
imapx_sync_free_user (on_user);
imapx_sync_free_user (off_user);
camel_folder_free_uids (folder, changed_uids);
+ g_object_unref (folder);
return TRUE;
}
@@ -8516,7 +8679,9 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
QUEUE_LOCK (is);
- if ((job = imapx_is_job_in_queue (is, folder, IMAPX_JOB_SYNC_CHANGES, NULL))) {
+ job = imapx_is_job_in_queue (is, mailbox, IMAPX_JOB_SYNC_CHANGES, NULL);
+
+ if (job != NULL) {
if (pri > job->pri)
job->pri = pri;
@@ -8525,6 +8690,7 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
imapx_sync_free_user (on_user);
imapx_sync_free_user (off_user);
camel_folder_free_uids (folder, changed_uids);
+ g_object_unref (folder);
return TRUE;
}
@@ -8546,7 +8712,7 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
job->matches = imapx_job_sync_changes_matches;
job->pri = pri;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
camel_imapx_job_set_data (
job, data, (GDestroyNotify) sync_changes_data_free);
@@ -8559,17 +8725,22 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
camel_imapx_job_unref (job);
+ g_object_unref (folder);
+
return success;
}
gboolean
camel_imapx_server_sync_changes (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
+
return imapx_server_sync_changes (
- is, folder,
+ is, mailbox,
IMAPX_JOB_SYNC_CHANGES,
IMAPX_PRIORITY_SYNC_CHANGES,
cancellable, error);
@@ -8578,7 +8749,7 @@ camel_imapx_server_sync_changes (CamelIMAPXServer *is,
/* expunge-uids? */
gboolean
camel_imapx_server_expunge (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
@@ -8586,10 +8757,15 @@ camel_imapx_server_expunge (CamelIMAPXServer *is,
gboolean registered;
gboolean success;
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
+
/* Do we really care to wait for this one to finish? */
QUEUE_LOCK (is);
- if (imapx_is_job_in_queue (is, folder, IMAPX_JOB_EXPUNGE, NULL)) {
+ job = imapx_is_job_in_queue (is, mailbox, IMAPX_JOB_EXPUNGE, NULL);
+
+ if (job != NULL) {
QUEUE_UNLOCK (is);
return TRUE;
}
@@ -8600,7 +8776,7 @@ camel_imapx_server_expunge (CamelIMAPXServer *is,
job->matches = imapx_job_expunge_matches;
job->pri = IMAPX_PRIORITY_EXPUNGE;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
registered = imapx_register_job (is, job, error);
@@ -8670,7 +8846,7 @@ camel_imapx_server_list (CamelIMAPXServer *is,
gboolean
camel_imapx_server_manage_subscription (CamelIMAPXServer *is,
- const gchar *folder_name,
+ CamelIMAPXMailbox *mailbox,
gboolean subscribe,
GCancellable *cancellable,
GError **error)
@@ -8679,8 +8855,10 @@ camel_imapx_server_manage_subscription (CamelIMAPXServer *is,
ManageSubscriptionsData *data;
gboolean success;
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
+
data = g_slice_new0 (ManageSubscriptionsData);
- data->folder_name = g_strdup (folder_name);
data->subscribe = subscribe;
job = camel_imapx_job_new (cancellable);
@@ -8688,6 +8866,8 @@ camel_imapx_server_manage_subscription (CamelIMAPXServer *is,
job->start = imapx_job_manage_subscription_start;
job->pri = IMAPX_PRIORITY_MANAGE_SUBSCRIPTION;
+ camel_imapx_job_set_mailbox (job, mailbox);
+
camel_imapx_job_set_data (
job, data, (GDestroyNotify) manage_subscriptions_data_free);
@@ -8699,25 +8879,28 @@ camel_imapx_server_manage_subscription (CamelIMAPXServer *is,
}
gboolean
-camel_imapx_server_create_folder (CamelIMAPXServer *is,
- const gchar *folder_name,
- GCancellable *cancellable,
- GError **error)
+camel_imapx_server_create_mailbox (CamelIMAPXServer *is,
+ const gchar *mailbox_name,
+ GCancellable *cancellable,
+ GError **error)
{
CamelIMAPXJob *job;
- CreateFolderData *data;
+ CreateMailboxData *data;
gboolean success;
- data = g_slice_new0 (CreateFolderData);
- data->folder_name = g_strdup (folder_name);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ g_return_val_if_fail (mailbox_name != NULL, FALSE);
+
+ data = g_slice_new0 (CreateMailboxData);
+ data->utf7_mailbox_name = camel_utf8_utf7 (mailbox_name);
job = camel_imapx_job_new (cancellable);
job->type = IMAPX_JOB_CREATE_FOLDER;
- job->start = imapx_job_create_folder_start;
+ job->start = imapx_job_create_mailbox_start;
job->pri = IMAPX_PRIORITY_CREATE_FOLDER;
camel_imapx_job_set_data (
- job, data, (GDestroyNotify) create_folder_data_free);
+ job, data, (GDestroyNotify) create_mailbox_data_free);
success = imapx_submit_job (is, job, error);
@@ -8727,25 +8910,23 @@ camel_imapx_server_create_folder (CamelIMAPXServer *is,
}
gboolean
-camel_imapx_server_delete_folder (CamelIMAPXServer *is,
- const gchar *folder_name,
- GCancellable *cancellable,
- GError **error)
+camel_imapx_server_delete_mailbox (CamelIMAPXServer *is,
+ CamelIMAPXMailbox *mailbox,
+ GCancellable *cancellable,
+ GError **error)
{
CamelIMAPXJob *job;
- DeleteFolderData *data;
gboolean success;
- data = g_slice_new0 (DeleteFolderData);
- data->folder_name = g_strdup (folder_name);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
job = camel_imapx_job_new (cancellable);
job->type = IMAPX_JOB_DELETE_FOLDER;
- job->start = imapx_job_delete_folder_start;
+ job->start = imapx_job_delete_mailbox_start;
job->pri = IMAPX_PRIORITY_DELETE_FOLDER;
- camel_imapx_job_set_data (
- job, data, (GDestroyNotify) delete_folder_data_free);
+ camel_imapx_job_set_mailbox (job, mailbox);
success = imapx_submit_job (is, job, error);
@@ -8756,15 +8937,15 @@ camel_imapx_server_delete_folder (CamelIMAPXServer *is,
static gboolean
imapx_job_fetch_messages_matches (CamelIMAPXJob *job,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *uid)
{
- return camel_imapx_job_has_folder (job, folder);
+ return camel_imapx_job_has_mailbox (job, mailbox);
}
-gboolean
+CamelFolderChangeInfo *
camel_imapx_server_fetch_messages (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
CamelFetchType type,
gint limit,
GCancellable *cancellable,
@@ -8772,25 +8953,25 @@ camel_imapx_server_fetch_messages (CamelIMAPXServer *is,
{
CamelIMAPXJob *job;
RefreshInfoData *data;
+ CamelFolderChangeInfo *changes = NULL;
gboolean registered = TRUE;
- const gchar *full_name;
- gboolean success = TRUE;
- guint64 firstuid, newfirstuid;
- gchar *uid;
- gint old_len;
+ const gchar *mailbox_name;
- old_len = camel_folder_summary_count (folder->summary);
- uid = camel_imapx_dup_uid_from_summary_index (folder, 0);
- firstuid = strtoull (uid, NULL, 10);
- g_free (uid);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), NULL);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), NULL);
QUEUE_LOCK (is);
/* Both RefreshInfo and Fetch messages can't operate simultaneously */
- if (imapx_is_job_in_queue (is, folder, IMAPX_JOB_REFRESH_INFO, NULL) ||
- imapx_is_job_in_queue (is, folder, IMAPX_JOB_FETCH_MESSAGES, NULL)) {
+ job = imapx_is_job_in_queue (
+ is, mailbox, IMAPX_JOB_REFRESH_INFO, NULL);
+ if (job == NULL)
+ job = imapx_is_job_in_queue (
+ is, mailbox, IMAPX_JOB_FETCH_MESSAGES, NULL);
+
+ if (job != NULL) {
QUEUE_UNLOCK (is);
- return TRUE;
+ return camel_folder_change_info_new ();
}
data = g_slice_new0 (RefreshInfoData);
@@ -8804,11 +8985,11 @@ camel_imapx_server_fetch_messages (CamelIMAPXServer *is,
job->matches = imapx_job_fetch_messages_matches;
job->pri = IMAPX_PRIORITY_NEW_MESSAGES;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
- full_name = camel_folder_get_full_name (folder);
+ mailbox_name = camel_imapx_mailbox_get_name (mailbox);
- if (g_ascii_strcasecmp (full_name, "INBOX") == 0)
+ if (camel_imapx_mailbox_is_inbox (mailbox_name))
job->pri += 10;
camel_imapx_job_set_data (
@@ -8818,24 +8999,14 @@ camel_imapx_server_fetch_messages (CamelIMAPXServer *is,
QUEUE_UNLOCK (is);
- success = registered && camel_imapx_job_run (job, is, error);
-
- if (success && camel_folder_change_info_changed (data->changes))
- camel_folder_changed (folder, data->changes);
-
- uid = camel_imapx_dup_uid_from_summary_index (folder, 0);
- newfirstuid = strtoull (uid, NULL, 10);
- g_free (uid);
+ if (registered && camel_imapx_job_run (job, is, error)) {
+ changes = data->changes;
+ data->changes = NULL;
+ }
camel_imapx_job_unref (job);
- if (type == CAMEL_FETCH_OLD_MESSAGES && firstuid == newfirstuid)
- return FALSE; /* No more old messages */
- else if (type == CAMEL_FETCH_NEW_MESSAGES &&
- old_len == camel_folder_summary_count (folder->summary))
- return FALSE; /* No more new messages */
-
- return TRUE;
+ return changes;
}
gboolean
@@ -8870,16 +9041,15 @@ camel_imapx_server_rename_folder (CamelIMAPXServer *is,
gboolean
camel_imapx_server_update_quota_info (CamelIMAPXServer *is,
- const gchar *folder_name,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
CamelIMAPXJob *job;
- QuotaData *data;
gboolean success;
g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
- g_return_val_if_fail (folder_name != NULL, FALSE);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), FALSE);
if (CAMEL_IMAPX_LACK_CAPABILITY (is->cinfo, QUOTA)) {
g_set_error_literal (
@@ -8888,16 +9058,12 @@ camel_imapx_server_update_quota_info (CamelIMAPXServer *is,
return FALSE;
}
- data = g_slice_new0 (QuotaData);
- data->folder_name = g_strdup (folder_name);
-
job = camel_imapx_job_new (cancellable);
job->type = IMAPX_JOB_UPDATE_QUOTA_INFO;
job->start = imapx_job_update_quota_info_start;
job->pri = IMAPX_PRIORITY_UPDATE_QUOTA_INFO;
- camel_imapx_job_set_data (
- job, data, (GDestroyNotify) quota_data_free);
+ camel_imapx_job_set_mailbox (job, mailbox);
success = imapx_submit_job (is, job, error);
@@ -8908,7 +9074,7 @@ camel_imapx_server_update_quota_info (CamelIMAPXServer *is,
GPtrArray *
camel_imapx_server_uid_search (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *criteria,
GCancellable *cancellable,
GError **error)
@@ -8918,7 +9084,7 @@ camel_imapx_server_uid_search (CamelIMAPXServer *is,
GPtrArray *results = NULL;
g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), NULL);
- g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
+ g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), NULL);
g_return_val_if_fail (criteria != NULL, NULL);
data = g_slice_new0 (SearchData);
@@ -8929,7 +9095,7 @@ camel_imapx_server_uid_search (CamelIMAPXServer *is,
job->start = imapx_job_uid_search_start;
job->pri = IMAPX_PRIORITY_SEARCH;
- camel_imapx_job_set_folder (job, folder);
+ camel_imapx_job_set_mailbox (job, mailbox);
camel_imapx_job_set_data (
job, data, (GDestroyNotify) search_data_free);
diff --git a/camel/camel-imapx-server.h b/camel/camel-imapx-server.h
index c56896f..d14faab 100644
--- a/camel/camel-imapx-server.h
+++ b/camel/camel-imapx-server.h
@@ -24,6 +24,7 @@
#ifndef CAMEL_IMAPX_SERVER_H
#define CAMEL_IMAPX_SERVER_H
+#include <camel/camel-data-cache.h>
#include <camel/camel-session.h>
#include <camel/camel-store.h>
@@ -183,68 +184,76 @@ GPtrArray * camel_imapx_server_list (CamelIMAPXServer *is,
const gchar *ext,
GCancellable *cancellable,
GError **error);
-gboolean camel_imapx_server_refresh_info (CamelIMAPXServer *is,
- CamelFolder *folder,
+CamelFolderChangeInfo *
+ camel_imapx_server_refresh_info (CamelIMAPXServer *is,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error);
gboolean camel_imapx_server_sync_changes (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error);
gboolean camel_imapx_server_expunge (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error);
-gboolean camel_imapx_server_fetch_messages
+CamelFolderChangeInfo *
+ camel_imapx_server_fetch_messages
(CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
CamelFetchType type,
gint limit,
GCancellable *cancellable,
GError **error);
gboolean camel_imapx_server_noop (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error);
CamelStream * camel_imapx_server_get_message (CamelIMAPXServer *is,
- CamelFolder *folder,
- const gchar *uid,
+ CamelIMAPXMailbox *mailbox,
+ CamelFolderSummary *summary,
+ CamelDataCache *message_cache,
+ const gchar *message_uid,
GCancellable *cancellable,
GError **error);
gboolean camel_imapx_server_copy_message (CamelIMAPXServer *is,
- CamelFolder *source,
- CamelFolder *dest,
+ CamelIMAPXMailbox *mailbox,
+ CamelIMAPXMailbox *destination,
GPtrArray *uids,
gboolean delete_originals,
GCancellable *cancellable,
GError **error);
gboolean camel_imapx_server_append_message
(CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
+ CamelFolderSummary *summary,
+ CamelDataCache *message_cache,
CamelMimeMessage *message,
const CamelMessageInfo *mi,
gchar **append_uid,
GCancellable *cancellable,
GError **error);
gboolean camel_imapx_server_sync_message (CamelIMAPXServer *is,
- CamelFolder *folder,
- const gchar *uid,
+ CamelIMAPXMailbox *mailbox,
+ CamelFolderSummary *summary,
+ CamelDataCache *message_cache,
+ const gchar *message_uid,
GCancellable *cancellable,
GError **error);
gboolean camel_imapx_server_manage_subscription
(CamelIMAPXServer *is,
- const gchar *folder_name,
+ CamelIMAPXMailbox *mailbox,
gboolean subscribe,
GCancellable *cancellable,
GError **error);
-gboolean camel_imapx_server_create_folder
+gboolean camel_imapx_server_create_mailbox
(CamelIMAPXServer *is,
- const gchar *folder_name,
+ const gchar *mailbox_name,
GCancellable *cancellable,
GError **error);
-gboolean camel_imapx_server_delete_folder
+gboolean camel_imapx_server_delete_mailbox
(CamelIMAPXServer *is,
- const gchar *folder_name,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error);
gboolean camel_imapx_server_rename_folder
@@ -255,11 +264,11 @@ gboolean camel_imapx_server_rename_folder
GError **error);
gboolean camel_imapx_server_update_quota_info
(CamelIMAPXServer *is,
- const gchar *folder_name,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error);
GPtrArray * camel_imapx_server_uid_search (CamelIMAPXServer *is,
- CamelFolder *folder,
+ CamelIMAPXMailbox *mailbox,
const gchar *criteria,
GCancellable *cancellable,
GError **error);
diff --git a/camel/camel-imapx-store.c b/camel/camel-imapx-store.c
index ad29a12..bd48180 100644
--- a/camel/camel-imapx-store.c
+++ b/camel/camel-imapx-store.c
@@ -523,11 +523,6 @@ imapx_store_process_mailbox_status (CamelIMAPXStore *store,
{
CamelFolder *folder = NULL;
const gchar *mailbox_name;
- guint32 messages;
- guint32 unseen;
- guint32 uidnext;
- guint32 uidvalidity;
- guint64 highestmodseq;
gchar *folder_path;
gchar separator;
GError *local_error = NULL;
@@ -535,12 +530,6 @@ imapx_store_process_mailbox_status (CamelIMAPXStore *store,
mailbox_name = camel_imapx_mailbox_get_name (mailbox);
separator = camel_imapx_mailbox_get_separator (mailbox);
- messages = camel_imapx_mailbox_get_messages (mailbox);
- unseen = camel_imapx_mailbox_get_unseen (mailbox);
- uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
- uidvalidity = camel_imapx_mailbox_get_uidvalidity (mailbox);
- highestmodseq = camel_imapx_mailbox_get_highestmodseq (mailbox);
-
folder_path = camel_imapx_mailbox_to_folder_path (
mailbox_name, separator);
@@ -555,15 +544,12 @@ imapx_store_process_mailbox_status (CamelIMAPXStore *store,
if (folder != NULL) {
CamelIMAPXFolder *imapx_folder;
CamelIMAPXSummary *imapx_summary;
+ guint32 uidvalidity;
imapx_folder = CAMEL_IMAPX_FOLDER (folder);
imapx_summary = CAMEL_IMAPX_SUMMARY (folder->summary);
- imapx_folder->exists_on_server = messages;
- imapx_folder->unread_on_server = unseen;
- imapx_folder->uidnext_on_server = uidnext;
- imapx_folder->uidvalidity_on_server = uidvalidity;
- imapx_folder->modseq_on_server = highestmodseq;
+ uidvalidity = camel_imapx_mailbox_get_uidvalidity (mailbox);
if (uidvalidity > 0 && uidvalidity != imapx_summary->validity)
camel_imapx_folder_invalidate_local_cache (
@@ -1076,22 +1062,29 @@ fill_fi (CamelStore *store,
folder = camel_object_bag_peek (store->folders, fi->full_name);
if (folder) {
+ CamelIMAPXFolder *imapx_folder;
CamelIMAPXSummary *ims;
+ CamelIMAPXMailbox *mailbox;
if (folder->summary)
ims = (CamelIMAPXSummary *) folder->summary;
else
ims = (CamelIMAPXSummary *) camel_imapx_summary_new (folder);
+ imapx_folder = CAMEL_IMAPX_FOLDER (folder);
+ mailbox = camel_imapx_folder_ref_mailbox (imapx_folder);
+
/* Mobile clients would still love to see the total unread of actual mails
* than what they just have downloaded. So we override that information by giving
* what the server has instead of what we have downloaded. */
- if (mobile_mode)
- fi->unread = ((CamelIMAPXFolder *) folder)->unread_on_server;
+ if (mobile_mode && mailbox != NULL)
+ fi->unread = camel_imapx_mailbox_get_unseen (mailbox);
else
fi->unread = camel_folder_summary_get_unread_count ((CamelFolderSummary *) ims);
fi->total = camel_folder_summary_get_saved_count ((CamelFolderSummary *) ims);
+ g_clear_object (&mailbox);
+
if (!folder->summary)
g_object_unref (ims);
g_object_unref (folder);
@@ -1201,26 +1194,40 @@ imapx_subscribe_folder (CamelStore *store,
GCancellable *cancellable,
GError **error)
{
+ CamelFolder *folder;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
gboolean success = FALSE;
+ folder = camel_store_get_folder_sync (
+ store, folder_path, 0, cancellable, error);
+
+ if (folder == NULL)
+ return FALSE;
+
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (folder_path != NULL && *folder_path == '/')
- folder_path++;
+ if (imapx_server == NULL)
+ goto exit;
+
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
- if (imapx_server != NULL) {
- success = camel_imapx_server_manage_subscription (
- imapx_server, folder_path, TRUE, cancellable, error);
- }
+ if (mailbox == NULL)
+ goto exit;
+
+ success = camel_imapx_server_manage_subscription (
+ imapx_server, mailbox, TRUE, cancellable, error);
if (success) {
imapx_mark_folder_subscribed (
imapx_store, folder_path, emit_signal);
}
+exit:
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
return success;
@@ -1233,26 +1240,40 @@ imapx_unsubscribe_folder (CamelStore *store,
GCancellable *cancellable,
GError **error)
{
+ CamelFolder *folder;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
gboolean success = FALSE;
+ folder = camel_store_get_folder_sync (
+ store, folder_path, 0, cancellable, error);
+
+ if (folder == NULL)
+ return FALSE;
+
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (folder_path != NULL && *folder_path == '/')
- folder_path++;
+ if (imapx_server == NULL)
+ goto exit;
- if (imapx_server != NULL) {
- success = camel_imapx_server_manage_subscription (
- imapx_server, folder_path, FALSE, cancellable, error);
- }
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+
+ if (mailbox == NULL)
+ goto exit;
+
+ success = camel_imapx_server_manage_subscription (
+ imapx_server, mailbox, FALSE, cancellable, error);
if (success) {
imapx_unmark_folder_subscribed (
imapx_store, folder_path, emit_signal);
}
+exit:
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
return success;
@@ -1861,6 +1882,10 @@ imapx_store_get_folder_sync (CamelStore *store,
gboolean use_real_junk_path = FALSE;
gboolean use_real_trash_path = FALSE;
+ /* XXX This should be taken care of before we get this far. */
+ if (*folder_name == '/')
+ folder_name++;
+
folder = get_folder_offline (store, folder_name, flags, error);
/* Configure the folder flags according to IMAPX settings.
@@ -2106,15 +2131,18 @@ imapx_store_create_folder_sync (CamelStore *store,
GCancellable *cancellable,
GError **error)
{
- CamelStoreInfo *si;
- CamelIMAPXStoreNamespace *ns;
+ CamelIMAPXNamespaceResponse *namespace_response;
+ CamelIMAPXNamespace *namespace;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
- gchar *mailbox;
- gchar *child_mailbox;
- gchar *parent_mailbox;
+ CamelFolder *folder;
+ CamelIMAPXMailbox *parent_mailbox = NULL;
CamelFolderInfo *fi = NULL;
- gchar dir_sep = 0;
+ GList *list;
+ const gchar *namespace_prefix;
+ const gchar *parent_mailbox_name;
+ gchar *mailbox_name = NULL;
+ gchar separator;
gboolean success;
imapx_store = CAMEL_IMAPX_STORE (store);
@@ -2123,57 +2151,74 @@ imapx_store_create_folder_sync (CamelStore *store,
if (imapx_server == NULL)
return NULL;
- if (parent_name == NULL)
- parent_name = "";
+ if (parent_name == NULL || *parent_name == '\0')
+ goto check_namespace;
- ns = camel_imapx_store_summary_namespace_find_by_path (
- imapx_store->summary, parent_name);
- if (ns)
- dir_sep = ns->sep;
+ /* Obtain the separator from the parent CamelIMAPXMailbox. */
- if (!dir_sep)
- dir_sep = '/';
+ folder = camel_store_get_folder_sync (
+ store, parent_name, 0, cancellable, error);
- if (strchr (folder_name, dir_sep)) {
- g_set_error (
- error, CAMEL_FOLDER_ERROR,
- CAMEL_FOLDER_ERROR_INVALID_PATH,
- _("The folder name \"%s\" is invalid because it contains the character \"%c\""),
- folder_name, dir_sep);
- goto exit;
+ if (folder != NULL) {
+ parent_mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+ g_object_unref (folder);
}
- parent_mailbox = camel_imapx_store_summary_mailbox_from_path (
- imapx_store->summary, parent_name);
- if (parent_mailbox == NULL) {
- g_set_error (
- error, CAMEL_FOLDER_ERROR,
- CAMEL_FOLDER_ERROR_INVALID_STATE,
- _("Unknown parent folder: %s"), parent_name);
+ if (parent_mailbox == NULL)
goto exit;
- }
- si = camel_store_summary_path (
- (CamelStoreSummary *) imapx_store->summary, parent_name);
- if (si && si->flags & CAMEL_STORE_INFO_FOLDER_NOINFERIORS) {
+ separator = camel_imapx_mailbox_get_separator (parent_mailbox);
+ parent_mailbox_name = camel_imapx_mailbox_get_name (parent_mailbox);
+
+ mailbox_name = g_strdup_printf (
+ "%s%c%s", parent_mailbox_name, separator, folder_name);
+
+ g_object_unref (parent_mailbox);
+
+ goto check_separator;
+
+check_namespace:
+
+ /* Obtain the separator from the first personal namespace.
+ *
+ * FIXME The CamelFolder API provides no way to specify a
+ * namespace prefix when creating a top-level mailbox,
+ * This needs fixed to properly support IMAP namespaces.
+ */
+
+ namespace_response = camel_imapx_server_ref_namespaces (imapx_server);
+ g_return_val_if_fail (namespace_response != NULL, NULL);
+
+ list = camel_imapx_namespace_response_list (namespace_response);
+ g_return_val_if_fail (list != NULL, NULL);
+
+ /* The namespace list is in the order received in the NAMESPACE
+ * response so the first element should be a personal namespace. */
+ namespace = CAMEL_IMAPX_NAMESPACE (list->data);
+
+ separator = camel_imapx_namespace_get_separator (namespace);
+ namespace_prefix = camel_imapx_namespace_get_prefix (namespace);
+
+ mailbox_name = g_strconcat (namespace_prefix, folder_name, NULL);
+
+ g_list_free_full (list, (GDestroyNotify) g_object_unref);
+ g_object_unref (namespace_response);
+
+check_separator:
+
+ if (strchr (folder_name, separator) != NULL) {
g_set_error (
error, CAMEL_FOLDER_ERROR,
- CAMEL_FOLDER_ERROR_INVALID_STATE,
- _("The parent folder is not allowed to contain subfolders"));
+ CAMEL_FOLDER_ERROR_INVALID_PATH,
+ _("The folder name \"%s\" is invalid "
+ "because it contains the character \"%c\""),
+ folder_name, separator);
goto exit;
}
- if (si)
- camel_store_summary_info_unref (
- (CamelStoreSummary *) imapx_store->summary, si);
-
- child_mailbox = camel_imapx_store_summary_path_to_mailbox (
- imapx_store->summary, folder_name, dir_sep);
- mailbox = imapx_concat (imapx_store, parent_mailbox, child_mailbox);
- g_free (child_mailbox);
-
- success = camel_imapx_server_create_folder (
- imapx_server, mailbox, cancellable, error);
+ success = camel_imapx_server_create_mailbox (
+ imapx_server, mailbox_name, cancellable, error);
if (success) {
CamelStoreSummary *summary;
@@ -2183,7 +2228,7 @@ imapx_store_create_folder_sync (CamelStore *store,
summary = CAMEL_STORE_SUMMARY (imapx_store->summary);
si = camel_imapx_store_summary_add_from_mailbox (
- imapx_store->summary, mailbox, dir_sep);
+ imapx_store->summary, mailbox_name, separator);
camel_store_summary_save (summary);
folder_path = camel_store_info_path (
summary, (CamelStoreInfo *) si);
@@ -2193,10 +2238,9 @@ imapx_store_create_folder_sync (CamelStore *store,
camel_store_folder_created (store, fi);
}
- g_free (mailbox);
- g_free (parent_mailbox);
-
exit:
+ g_free (mailbox_name);
+
g_clear_object (&imapx_server);
return fi;
@@ -2208,22 +2252,38 @@ imapx_store_delete_folder_sync (CamelStore *store,
GCancellable *cancellable,
GError **error)
{
+ CamelFolder *folder;
CamelIMAPXStore *imapx_store;
CamelIMAPXServer *imapx_server;
+ CamelIMAPXMailbox *mailbox = NULL;
gboolean success = FALSE;
+ folder = camel_store_get_folder_sync (
+ store, folder_name, 0, cancellable, error);
+
+ if (folder == NULL)
+ return FALSE;
+
imapx_store = CAMEL_IMAPX_STORE (store);
imapx_server = camel_imapx_store_ref_server (imapx_store, error);
- if (imapx_server != NULL) {
- success = camel_imapx_server_delete_folder (
- imapx_server, folder_name, cancellable, error);
- }
+ if (imapx_server == NULL)
+ goto exit;
- if (success) {
+ mailbox = camel_imapx_folder_list_mailbox (
+ CAMEL_IMAPX_FOLDER (folder), cancellable, error);
+ if (mailbox == NULL)
+ goto exit;
+
+ success = camel_imapx_server_delete_mailbox (
+ imapx_server, mailbox, cancellable, error);
+
+ if (success)
imapx_delete_folder_from_cache (imapx_store, folder_name);
- }
+exit:
+ g_clear_object (&folder);
+ g_clear_object (&mailbox);
g_clear_object (&imapx_server);
return success;
diff --git a/camel/camel-imapx-utils.c b/camel/camel-imapx-utils.c
index 4666003..2a05832 100644
--- a/camel/camel-imapx-utils.c
+++ b/camel/camel-imapx-utils.c
@@ -339,14 +339,10 @@ void
imapx_update_store_summary (CamelFolder *folder)
{
CamelStoreInfo *si;
- CamelService *service;
CamelStore *parent_store;
CamelStoreSummary *store_summary;
- CamelSettings *settings;
CamelIMAPXStore *imapx_store;
- CamelIMAPXFolder *imapx_folder;
const gchar *full_name;
- gboolean mobile_mode;
guint32 total;
guint32 unread;
@@ -354,16 +350,8 @@ imapx_update_store_summary (CamelFolder *folder)
full_name = camel_folder_get_full_name (folder);
parent_store = camel_folder_get_parent_store (folder);
- service = CAMEL_SERVICE (parent_store);
-
- settings = camel_service_ref_settings (service);
- mobile_mode = camel_imapx_settings_get_mobile_mode (
- CAMEL_IMAPX_SETTINGS (settings));
- g_object_unref (settings);
- imapx_folder = CAMEL_IMAPX_FOLDER (folder);
imapx_store = CAMEL_IMAPX_STORE (parent_store);
-
store_summary = CAMEL_STORE_SUMMARY (imapx_store->summary);
si = camel_store_summary_path (store_summary, full_name);
@@ -374,12 +362,7 @@ imapx_update_store_summary (CamelFolder *folder)
unread = camel_folder_summary_get_unread_count (folder->summary);
if (si->unread != unread || si->total != total) {
-
- /* XXX Why is this different for mobile mode? */
- if (mobile_mode)
- si->unread = imapx_folder->unread_on_server;
- else
- si->unread = unread;
+ si->unread = unread;
si->total = total;
camel_store_summary_touch (store_summary);
@@ -1969,7 +1952,7 @@ imapx_parse_status_copyuid (CamelIMAPXStream *is,
static gboolean
imapx_parse_status_highestmodseq (CamelIMAPXStream *is,
- struct _status_info *sinfo,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
@@ -1978,7 +1961,7 @@ imapx_parse_status_highestmodseq (CamelIMAPXStream *is,
if (!camel_imapx_stream_number (is, &number, cancellable, error))
return FALSE;
- sinfo->u.highestmodseq = number;
+ camel_imapx_mailbox_set_highestmodseq (mailbox, number);
return TRUE;
}
@@ -2025,7 +2008,7 @@ imapx_parse_status_permanentflags (CamelIMAPXStream *is,
static gboolean
imapx_parse_status_uidnext (CamelIMAPXStream *is,
- struct _status_info *sinfo,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
@@ -2034,14 +2017,14 @@ imapx_parse_status_uidnext (CamelIMAPXStream *is,
if (!camel_imapx_stream_number (is, &number, cancellable, error))
return FALSE;
- sinfo->u.uidnext = (guint32) number;
+ camel_imapx_mailbox_set_uidnext (mailbox, (guint32) number);
return TRUE;
}
static gboolean
imapx_parse_status_uidvalidity (CamelIMAPXStream *is,
- struct _status_info *sinfo,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
@@ -2050,14 +2033,14 @@ imapx_parse_status_uidvalidity (CamelIMAPXStream *is,
if (!camel_imapx_stream_number (is, &number, cancellable, error))
return FALSE;
- sinfo->u.uidvalidity = number;
+ camel_imapx_mailbox_set_uidvalidity (mailbox, (guint32) number);
return TRUE;
}
static gboolean
imapx_parse_status_unseen (CamelIMAPXStream *is,
- struct _status_info *sinfo,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
@@ -2066,7 +2049,7 @@ imapx_parse_status_unseen (CamelIMAPXStream *is,
if (!camel_imapx_stream_number (is, &number, cancellable, error))
return FALSE;
- sinfo->u.unseen = (guint32) number;
+ camel_imapx_mailbox_set_unseen (mailbox, (guint32) number);
return TRUE;
}
@@ -2075,6 +2058,7 @@ imapx_parse_status_unseen (CamelIMAPXStream *is,
/* should this start after [ or before the [? token_unget anyone? */
struct _status_info *
imapx_parse_status (CamelIMAPXStream *is,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error)
{
@@ -2154,7 +2138,7 @@ imapx_parse_status (CamelIMAPXStream *is,
case IMAPX_HIGHESTMODSEQ:
success = imapx_parse_status_highestmodseq (
- is, sinfo, cancellable, error);
+ is, mailbox, cancellable, error);
break;
case IMAPX_NEWNAME:
@@ -2169,17 +2153,17 @@ imapx_parse_status (CamelIMAPXStream *is,
case IMAPX_UIDNEXT:
success = imapx_parse_status_uidnext (
- is, sinfo, cancellable, error);
+ is, mailbox, cancellable, error);
break;
case IMAPX_UIDVALIDITY:
success = imapx_parse_status_uidvalidity (
- is, sinfo, cancellable, error);
+ is, mailbox, cancellable, error);
break;
case IMAPX_UNSEEN:
success = imapx_parse_status_unseen (
- is, sinfo, cancellable, error);
+ is, mailbox, cancellable, error);
break;
/* RFC 5530 Response Codes */
@@ -2290,6 +2274,7 @@ camel_imapx_command_add_qresync_parameter (CamelIMAPXCommand *ic,
CamelIMAPXFolder *imapx_folder;
CamelIMAPXSummary *imapx_summary;
+ CamelIMAPXMailbox *mailbox;
guint64 last_known_uidvalidity;
guint64 last_known_modsequence;
guint32 last_known_message_cnt;
@@ -2304,9 +2289,11 @@ camel_imapx_command_add_qresync_parameter (CamelIMAPXCommand *ic,
imapx_folder = CAMEL_IMAPX_FOLDER (folder);
imapx_summary = CAMEL_IMAPX_SUMMARY (folder->summary);
- last_known_uidvalidity = imapx_folder->uidvalidity_on_server;
+ mailbox = camel_imapx_folder_ref_mailbox (imapx_folder);
+
+ last_known_uidvalidity = camel_imapx_mailbox_get_uidvalidity (mailbox);
last_known_modsequence = imapx_summary->modseq;
- last_known_message_cnt = imapx_folder->exists_on_server;
+ last_known_message_cnt = camel_imapx_mailbox_get_messages (mailbox);
/* XXX This should return an unsigned integer to
* avoid the possibility of a negative count. */
@@ -2407,6 +2394,8 @@ camel_imapx_command_add_qresync_parameter (CamelIMAPXCommand *ic,
exit:
g_free (known_uid_set);
+ g_object_unref (mailbox);
+
return parameter_added;
}
@@ -2667,7 +2656,7 @@ gboolean
camel_imapx_parse_quotaroot (CamelIMAPXStream *is,
GCancellable *cancellable,
gchar **out_mailbox_name,
- gchar ***out_quota_root_names,
+ gchar ***out_quota_roots,
GError **error)
{
GQueue queue = G_QUEUE_INIT;
@@ -2675,12 +2664,12 @@ camel_imapx_parse_quotaroot (CamelIMAPXStream *is,
guint len;
guchar *token;
gchar *mailbox_name = NULL;
- gchar **quota_root_names = NULL;
+ gchar **quota_roots = NULL;
gint ii = 0;
g_return_val_if_fail (CAMEL_IS_IMAPX_STREAM (is), FALSE);
g_return_val_if_fail (out_mailbox_name != NULL, FALSE);
- g_return_val_if_fail (out_quota_root_names != NULL, FALSE);
+ g_return_val_if_fail (out_quota_roots != NULL, FALSE);
/* quotaroot_response ::= "QUOTAROOT" SP astring *(SP astring) */
@@ -2707,12 +2696,12 @@ camel_imapx_parse_quotaroot (CamelIMAPXStream *is,
g_queue_push_tail (&queue, g_strdup ((gchar *) token));
}
- quota_root_names = g_new0 (gchar *, queue.length + 1);
+ quota_roots = g_new0 (gchar *, queue.length + 1);
while (!g_queue_is_empty (&queue))
- quota_root_names[ii++] = g_queue_pop_head (&queue);
+ quota_roots[ii++] = g_queue_pop_head (&queue);
*out_mailbox_name = mailbox_name;
- *out_quota_root_names = quota_root_names;
+ *out_quota_roots = quota_roots;
return TRUE;
diff --git a/camel/camel-imapx-utils.h b/camel/camel-imapx-utils.h
index 9d172d1..faf7f3a 100644
--- a/camel/camel-imapx-utils.h
+++ b/camel/camel-imapx-utils.h
@@ -25,6 +25,7 @@
#define CAMEL_IMAPX_UTILS_H
#include <camel/camel-store.h>
+#include <camel/camel-imapx-mailbox.h>
G_BEGIN_DECLS
@@ -284,10 +285,6 @@ struct _status_info {
gchar *newname;
} newname;
guint32 permanentflags;
- guint64 uidvalidity;
- guint32 uidnext;
- guint32 unseen;
- guint64 highestmodseq;
struct {
guint64 uidvalidity;
guint32 uid;
@@ -305,6 +302,7 @@ struct _status_info {
struct _status_info *
imapx_parse_status (struct _CamelIMAPXStream *is,
+ CamelIMAPXMailbox *mailbox,
GCancellable *cancellable,
GError **error);
struct _status_info *
@@ -340,7 +338,7 @@ gboolean camel_imapx_parse_quota (struct _CamelIMAPXStream *is,
gboolean camel_imapx_parse_quotaroot (struct _CamelIMAPXStream *is,
GCancellable *cancellable,
gchar **out_mailbox_name,
- gchar ***out_quota_root_names,
+ gchar ***out_quota_roots,
GError **error);
/* ********************************************************************** */
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index f1f9b5a..a00f0bc 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -816,7 +816,6 @@ camel_imapx_job_get_data
camel_imapx_job_set_data
camel_imapx_job_has_folder
camel_imapx_job_ref_folder
-camel_imapx_job_set_folder
camel_imapx_job_get_cancellable
camel_imapx_job_take_error
<SUBSECTION Private>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]