From 099f2987f918a8f19c031389cd638d399278379e Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Tue, 11 Jan 2005 07:49:58 +0000 Subject: [PATCH] remove defines 2005-01-11 JP Rosevear * providers/groupwise/camel-groupwise-transport.h: remove defines * providers/groupwise/camel-groupwise-transport.c (groupwise_send_to) (groupwise_send_to): use util routine to build item * providers/groupwise/camel-groupwise-store.h: new protos * providers/groupwise/camel-groupwise-store.c (groupwise_rename_folder): use new api name and don't strdup the lookup name (camel_groupwise_store_folder_lookup): find folder from container id * providers/groupwise/camel-groupwise-journal.[hc]: implement journalling for append and transfer * providers/groupwise/camel-groupwise-folder.h: add journal member * providers/groupwise/camel-groupwise-folder.c (groupwise_folder_get_message): use new api name and don't strdup the lookup name (groupwise_refresh_info): ditto (groupwise_append_message): ditto (groupwise_expunge): ditto (groupwise_transfer_messages_to): handle being in offline mode * providers/groupwise/Makefile.am: build journal sources --- camel/providers/groupwise/Makefile.am | 2 + camel/providers/groupwise/camel-groupwise-folder.c | 55 ++- camel/providers/groupwise/camel-groupwise-folder.h | 3 + .../providers/groupwise/camel-groupwise-journal.c | 425 +++++++++++++++++++++ .../providers/groupwise/camel-groupwise-journal.h | 92 +++++ camel/providers/groupwise/camel-groupwise-store.c | 20 +- camel/providers/groupwise/camel-groupwise-store.h | 3 +- .../groupwise/camel-groupwise-transport.c | 183 +-------- .../groupwise/camel-groupwise-transport.h | 15 - camel/providers/groupwise/camel-groupwise-utils.c | 1 - 10 files changed, 588 insertions(+), 211 deletions(-) create mode 100644 camel/providers/groupwise/camel-groupwise-journal.c create mode 100644 camel/providers/groupwise/camel-groupwise-journal.h diff --git a/camel/providers/groupwise/Makefile.am b/camel/providers/groupwise/Makefile.am index e345af5..aeeca33 100644 --- a/camel/providers/groupwise/Makefile.am +++ b/camel/providers/groupwise/Makefile.am @@ -17,6 +17,7 @@ INCLUDES = -I.. \ libcamelgroupwise_la_SOURCES = \ camel-groupwise-provider.c \ camel-groupwise-folder.c \ + camel-groupwise-journal.c \ camel-groupwise-store.c \ camel-groupwise-summary.c \ camel-groupwise-store-summary.c \ @@ -25,6 +26,7 @@ libcamelgroupwise_la_SOURCES = \ noinst_HEADERS = \ camel-groupwise-folder.h \ + camel-groupwise-journal.h \ camel-groupwise-private.h \ camel-groupwise-store.h \ camel-groupwise-summary.h \ diff --git a/camel/providers/groupwise/camel-groupwise-folder.c b/camel/providers/groupwise/camel-groupwise-folder.c index 9b09583..b8f6ddb 100644 --- a/camel/providers/groupwise/camel-groupwise-folder.c +++ b/camel/providers/groupwise/camel-groupwise-folder.c @@ -150,11 +150,11 @@ groupwise_folder_get_message( CamelFolder *folder, folder_name = g_strdup(folder->name) ; temp_name = strrchr (folder_name,'/') ; if(temp_name == NULL) { - container_id = g_strdup (container_id_lookup (priv,g_strdup(folder_name))) ; + container_id = g_strdup (camel_groupwise_store_container_id_lookup (gw_store, folder_name)) ; } else { temp_name++ ; - container_id = g_strdup (container_id_lookup (priv,g_strdup(temp_name))) ; + container_id = g_strdup (camel_groupwise_store_container_id_lookup (gw_store, temp_name)) ; } @@ -473,7 +473,7 @@ groupwise_refresh_info(CamelFolder *folder, CamelException *ex) GList *list = NULL; char *container_id = NULL ; - container_id = g_strdup (container_id_lookup(priv, g_strdup (folder->name))) ; + container_id = g_strdup (camel_groupwise_store_container_id_lookup (gw_store, folder->name)) ; if (!container_id) { g_print ("\nERROR - Container id not present. Cannot refresh info\n") ; return ; @@ -605,7 +605,7 @@ groupwise_append_message (CamelFolder *folder, CamelMimeMessage *message, const CamelMessageInfo *info, char **appended_uid, CamelException *ex) { - char *container_id = NULL; + const char *container_id = NULL; CamelGroupwiseStore *gw_store= CAMEL_GROUPWISE_STORE(folder->parent_store) ; CamelGroupwiseStorePrivate *priv = gw_store->priv; CamelOfflineStore *offline = (CamelOfflineStore *) folder->parent_store; @@ -620,7 +620,7 @@ groupwise_append_message (CamelFolder *folder, CamelMimeMessage *message, return; } /*Get the container id*/ - container_id = container_id_lookup (priv, folder->name) ; + container_id = camel_groupwise_store_container_id_lookup (gw_store, folder->name) ; /* FIXME Separate To/CC/BCC? */ recipients = CAMEL_ADDRESS (camel_internet_address_new ()); camel_address_cat (recipients, CAMEL_ADDRESS (camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_TO))); @@ -682,8 +682,9 @@ groupwise_transfer_messages_to (CamelFolder *source, GPtrArray *uids, { int count, index = 0 ; GList *item_ids = NULL, *temp_list = NULL ; - char *source_container_id = NULL, *dest_container_id = NULL; + const char *source_container_id = NULL, *dest_container_id = NULL; CamelGroupwiseStore *gw_store= CAMEL_GROUPWISE_STORE(source->parent_store) ; + CamelOfflineStore *offline = (CamelOfflineStore *) destination->parent_store; CamelGroupwiseStorePrivate *priv = gw_store->priv; EGwConnectionStatus status ; EGwConnection *cnc = cnc_lookup (priv) ; @@ -696,9 +697,44 @@ groupwise_transfer_messages_to (CamelFolder *source, GPtrArray *uids, temp_list = g_list_append (temp_list, g_ptr_array_index (uids, index)); index ++; } + + source_container_id = camel_groupwise_store_container_id_lookup (gw_store, source->name) ; + dest_container_id = camel_groupwise_store_container_id_lookup (gw_store, destination->name) ; + + /* check for offline operation */ + if (offline->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) { + CamelGroupwiseJournal *journal = (CamelGroupwiseJournal *) ((CamelGroupwiseFolder *) destination)->journal; + CamelMimeMessage *message; + GList *l; + int i; + + for (l = item_ids, i = 0; l; l = l->next, i++) { + CamelMessageInfo *info; + + if (!(info = camel_folder_summary_uid (source->summary, uids->pdata[i]))) + continue; + + if (!(message = groupwise_folder_get_message (source, camel_message_info_uid (info), ex))) + break; + + camel_groupwise_journal_transfer (journal, (CamelGroupwiseFolder *)source, message, info, uids->pdata[i], NULL, ex); + camel_object_unref (message); + + if (camel_exception_is_set (ex)) + break; + + if (delete_originals) + camel_folder_set_message_flags (source, camel_message_info_uid (info), + CAMEL_MESSAGE_DELETED, CAMEL_MESSAGE_DELETED); + } + + /* FIXME Return the list of transfers */ + if (transferred_uids) + *transferred_uids = NULL ; + + return; + } - source_container_id = container_id_lookup (priv, g_strdup (source->name)) ; - dest_container_id = container_id_lookup (priv, g_strdup (destination->name)) ; status = e_gw_connection_add_items (cnc, dest_container_id, item_ids) ; if (status != E_GW_CONNECTION_STATUS_OK) { g_print ("Warning!! Could not move items\n") ; @@ -713,6 +749,7 @@ groupwise_transfer_messages_to (CamelFolder *source, GPtrArray *uids, } } + /* FIXME Return the list of transfers */ if (transferred_uids) *transferred_uids = NULL ; } @@ -746,7 +783,7 @@ groupwise_expunge (CamelFolder *folder, CamelException *ex) camel_message_info_free (info); } - container_id = g_strdup (container_id_lookup (priv,g_strdup(folder->name))) ; + container_id = g_strdup (camel_groupwise_store_container_id_lookup (groupwise_store, folder->name)) ; status = e_gw_connection_remove_items (cnc, container_id, item_ids); if (status == E_GW_CONNECTION_STATUS_OK) camel_object_trigger_event (CAMEL_OBJECT (folder), "folder_changed", changes); diff --git a/camel/providers/groupwise/camel-groupwise-folder.h b/camel/providers/groupwise/camel-groupwise-folder.h index 3eaef1a..cdd930d 100644 --- a/camel/providers/groupwise/camel-groupwise-folder.h +++ b/camel/providers/groupwise/camel-groupwise-folder.h @@ -40,6 +40,7 @@ extern "C" { #include #include #include +#include #include "camel-groupwise-summary.h" @@ -56,6 +57,8 @@ struct _CamelGroupwiseFolder { struct _CamelGroupwiseFolderPrivate *priv; CamelFolderSearch *search; + + CamelOfflineJournal *journal; CamelDataCache *cache; unsigned int need_rescan:1; diff --git a/camel/providers/groupwise/camel-groupwise-journal.c b/camel/providers/groupwise/camel-groupwise-journal.c new file mode 100644 index 0000000..17d717e --- /dev/null +++ b/camel/providers/groupwise/camel-groupwise-journal.c @@ -0,0 +1,425 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast + * + * Copyright 2004 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "camel-groupwise-folder.h" +#include "camel-groupwise-store.h" +#include "camel-groupwise-journal.h" + + +#define d(x) x + + +static void camel_groupwise_journal_class_init (CamelGroupwiseJournalClass *klass); +static void camel_groupwise_journal_init (CamelGroupwiseJournal *journal, CamelGroupwiseJournalClass *klass); +static void camel_groupwise_journal_finalize (CamelObject *object); + +static void groupwise_entry_free (CamelOfflineJournal *journal, EDListNode *entry); +static EDListNode *groupwise_entry_load (CamelOfflineJournal *journal, FILE *in); +static int groupwise_entry_write (CamelOfflineJournal *journal, EDListNode *entry, FILE *out); +static int groupwise_entry_play (CamelOfflineJournal *journal, EDListNode *entry, CamelException *ex); + + +static CamelOfflineJournalClass *parent_class = NULL; + + +CamelType +camel_groupwise_journal_get_type (void) +{ + static CamelType type = 0; + + if (!type) { + type = camel_type_register (camel_offline_journal_get_type (), + "CamelGroupwiseJournal", + sizeof (CamelGroupwiseJournal), + sizeof (CamelGroupwiseJournalClass), + (CamelObjectClassInitFunc) camel_groupwise_journal_class_init, + NULL, + (CamelObjectInitFunc) camel_groupwise_journal_init, + (CamelObjectFinalizeFunc) camel_groupwise_journal_finalize); + } + + return type; +} + +static void +camel_groupwise_journal_class_init (CamelGroupwiseJournalClass *klass) +{ + CamelOfflineJournalClass *journal_class = (CamelOfflineJournalClass *) klass; + + parent_class = (CamelOfflineJournalClass *) camel_type_get_global_classfuncs (CAMEL_TYPE_OFFLINE_JOURNAL); + + journal_class->entry_free = groupwise_entry_free; + journal_class->entry_load = groupwise_entry_load; + journal_class->entry_write = groupwise_entry_write; + journal_class->entry_play = groupwise_entry_play; +} + +static void +camel_groupwise_journal_init (CamelGroupwiseJournal *journal, CamelGroupwiseJournalClass *klass) +{ + +} + +static void +camel_groupwise_journal_finalize (CamelObject *object) +{ + +} + +static void +groupwise_entry_free (CamelOfflineJournal *journal, EDListNode *entry) +{ + CamelGroupwiseJournalEntry *groupwise_entry = (CamelGroupwiseJournalEntry *) entry; + + g_free (groupwise_entry->uid); + g_free (groupwise_entry->source_container); + g_free (groupwise_entry); +} + +static EDListNode * +groupwise_entry_load (CamelOfflineJournal *journal, FILE *in) +{ + CamelGroupwiseJournalEntry *entry; + + entry = g_malloc0 (sizeof (CamelGroupwiseJournalEntry)); + + if (camel_file_util_decode_uint32 (in, &entry->type) == -1) + goto exception; + + switch (entry->type) { + case CAMEL_GROUPWISE_JOURNAL_ENTRY_APPEND: + if (camel_file_util_decode_string (in, &entry->uid) == -1) + goto exception; + break; + case CAMEL_GROUPWISE_JOURNAL_ENTRY_TRANSFER: + if (camel_file_util_decode_string (in, &entry->uid) == -1) + goto exception; + if (camel_file_util_decode_string (in, &entry->source_container) == -1) + goto exception; + break; + default: + goto exception; + } + + return (EDListNode *) entry; + + exception: + + switch (entry->type) { + case CAMEL_GROUPWISE_JOURNAL_ENTRY_APPEND: + g_free (entry->uid); + break; + case CAMEL_GROUPWISE_JOURNAL_ENTRY_TRANSFER: + g_free (entry->uid); + g_free (entry->source_container); + break; + + default: + g_assert_not_reached (); + } + + g_free (entry); + + return NULL; +} + +static int +groupwise_entry_write (CamelOfflineJournal *journal, EDListNode *entry, FILE *out) +{ + CamelGroupwiseJournalEntry *groupwise_entry = (CamelGroupwiseJournalEntry *) entry; + + if (camel_file_util_encode_uint32 (out, groupwise_entry->type) == -1) + return -1; + + switch (groupwise_entry->type) { + case CAMEL_GROUPWISE_JOURNAL_ENTRY_APPEND: + if (camel_file_util_encode_string (out, groupwise_entry->uid)) + return -1; + break; + case CAMEL_GROUPWISE_JOURNAL_ENTRY_TRANSFER: + if (camel_file_util_encode_string (out, groupwise_entry->uid)) + return -1; + if (camel_file_util_encode_string (out, groupwise_entry->source_container)) + return -1; + break; + default: + g_assert_not_reached (); + } + + return 0; +} + +static int +play_update (CamelOfflineJournal *journal, CamelGroupwiseJournalEntry *entry, gboolean transfer, CamelException *ex) +{ + CamelGroupwiseFolder *groupwise_folder = (CamelGroupwiseFolder *) journal->folder; + CamelFolder *folder = journal->folder; + CamelMimeMessage *message; + CamelMessageInfo *info; + CamelStream *stream; + CamelException lex; + + /* if the message isn't in the cache, the user went behind our backs so "not our problem" */ + if (!groupwise_folder->cache || !(stream = camel_data_cache_get (groupwise_folder->cache, "cache", entry->uid, ex))) + goto done; + + message = camel_mime_message_new (); + if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) message, stream) == -1) { + camel_object_unref (message); + camel_object_unref (stream); + goto done; + } + + camel_object_unref (stream); + + if (!(info = camel_folder_summary_uid (folder->summary, entry->uid))) { + /* info not in the summary, either because the summary + * got corrupted or because the previous time this + * journal was replay'd, it failed [1] */ + info = camel_message_info_new (NULL); + } + + camel_exception_init (&lex); + if (transfer) { + GPtrArray *uids; + CamelFolder *source_folder; + const char *name; + + name = camel_groupwise_store_folder_lookup ((CamelGroupwiseStore *)folder->parent_store, entry->source_container); + if (name) { + source_folder = camel_store_get_folder (folder->parent_store, name, 0, &lex); + + if (source_folder) { + uids = g_ptr_array_sized_new (1); + g_ptr_array_add (uids, entry->original_uid); + + camel_folder_transfer_messages_to (source_folder, uids, folder, NULL, FALSE, &lex); + + g_ptr_array_free (uids, FALSE); + } + } else { + camel_exception_setv (&lex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get folder container %s"), + entry->source_container); + } + } else { + camel_folder_append_message (folder, message, info, NULL, &lex); + } + camel_message_info_free (info); + camel_object_unref (message); + + if (camel_exception_is_set (&lex)) { + /* [1] remove the summary even if we fail or the next + * summary downsync will break because info indexes + * will be wrong + * + * FIXME: we really need to save these info's to a + * temp location and then restore them after the + * summary downsync finishes. */ + camel_folder_summary_remove_uid (folder->summary, entry->uid); + camel_exception_xfer (ex, &lex); + return -1; + } + + done: + + camel_folder_summary_remove_uid (folder->summary, entry->uid); + camel_data_cache_remove (groupwise_folder->cache, "cache", entry->uid, NULL); + + return 0; +} + +static int +groupwise_entry_play_append (CamelOfflineJournal *journal, CamelGroupwiseJournalEntry *entry, CamelException *ex) +{ + return play_update (journal, entry, FALSE, ex); +} + +static int +groupwise_entry_play_transfer (CamelOfflineJournal *journal, CamelGroupwiseJournalEntry *entry, CamelException *ex) +{ + return play_update (journal, entry, TRUE, ex); +} + +static int +groupwise_entry_play (CamelOfflineJournal *journal, EDListNode *entry, CamelException *ex) +{ + CamelGroupwiseJournalEntry *groupwise_entry = (CamelGroupwiseJournalEntry *) entry; + + switch (groupwise_entry->type) { + case CAMEL_GROUPWISE_JOURNAL_ENTRY_APPEND: + return groupwise_entry_play_append (journal, groupwise_entry, ex); + case CAMEL_GROUPWISE_JOURNAL_ENTRY_TRANSFER: + return groupwise_entry_play_transfer (journal, groupwise_entry, ex); + default: + g_assert_not_reached (); + return -1; + } +} + + + +CamelOfflineJournal * +camel_groupwise_journal_new (CamelGroupwiseFolder *folder, const char *filename) +{ + CamelOfflineJournal *journal; + + g_return_val_if_fail (CAMEL_IS_GROUPWISE_FOLDER (folder), NULL); + + journal = (CamelOfflineJournal *) camel_object_new (camel_groupwise_journal_get_type ()); + camel_offline_journal_construct (journal, (CamelFolder *) folder, filename); + + return journal; +} + +static gboolean +update_cache (CamelGroupwiseJournal *groupwise_journal, CamelMimeMessage *message, + const CamelMessageInfo *mi, char **updated_uid, CamelException *ex) +{ + CamelOfflineJournal *journal = (CamelOfflineJournal *) groupwise_journal; + CamelGroupwiseFolder *groupwise_folder = (CamelGroupwiseFolder *) journal->folder; + CamelFolder *folder = (CamelFolder *) journal->folder; + CamelMessageInfoBase *a, *b; + CamelMessageInfo *info; + CamelStream *cache; + guint32 nextuid; + char *uid; + + if (groupwise_folder->cache == NULL) { + camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, + _("Cannot append message in offline mode: cache unavailable")); + return FALSE; + } + + nextuid = camel_folder_summary_next_uid (folder->summary); + uid = g_strdup_printf ("-%u", nextuid); + + if (!(cache = camel_data_cache_add (groupwise_folder->cache, "cache", uid, ex))) { + folder->summary->nextuid--; + g_free (uid); + return FALSE; + } + + if (camel_data_wrapper_write_to_stream ((CamelDataWrapper *) message, cache) == -1 + || camel_stream_flush (cache) == -1) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Cannot append message in offline mode: %s"), + g_strerror (errno)); + camel_data_cache_remove (groupwise_folder->cache, "cache", uid, NULL); + folder->summary->nextuid--; + camel_object_unref (cache); + g_free (uid); + return FALSE; + } + + camel_object_unref (cache); + + info = camel_folder_summary_info_new_from_message (folder->summary, message); + info->uid = g_strdup (uid); + + a = (CamelMessageInfoBase *) info; + b = (CamelMessageInfoBase *) mi; + + camel_flag_list_copy (&a->user_flags, &b->user_flags); + camel_tag_list_copy (&a->user_tags, &b->user_tags); + a->date_received = b->date_received; + a->date_sent = b->date_sent; + a->flags = b->flags; + a->size = b->size; + + camel_folder_summary_add (folder->summary, info); + + if (updated_uid) + *updated_uid = g_strdup (uid); + + g_free (uid); + + return TRUE; +} + +void +camel_groupwise_journal_append (CamelGroupwiseJournal *groupwise_journal, CamelMimeMessage *message, + const CamelMessageInfo *mi, char **appended_uid, CamelException *ex) +{ + CamelOfflineJournal *journal = (CamelOfflineJournal *) groupwise_journal; + CamelGroupwiseJournalEntry *entry; + char *uid; + + if (!update_cache (groupwise_journal, message, mi, &uid, ex)) + return; + + entry = g_new (CamelGroupwiseJournalEntry, 1); + entry->type = CAMEL_GROUPWISE_JOURNAL_ENTRY_APPEND; + entry->uid = uid; + + e_dlist_addtail (&journal->queue, (EDListNode *) entry); + + if (appended_uid) + *appended_uid = g_strdup (uid); + + g_free (uid); +} + +void +camel_groupwise_journal_transfer (CamelGroupwiseJournal *groupwise_journal, CamelGroupwiseFolder *source_folder, CamelMimeMessage *message, + const CamelMessageInfo *mi, const char *original_uid, char **transferred_uid, CamelException *ex) +{ + CamelOfflineJournal *journal = (CamelOfflineJournal *) groupwise_journal; + CamelGroupwiseStore *gw_store= CAMEL_GROUPWISE_STORE(journal->folder->parent_store) ; + CamelGroupwiseJournalEntry *entry; + char *uid; + + if (!update_cache (groupwise_journal, message, mi, &uid, ex)) + return; + + entry = g_new (CamelGroupwiseJournalEntry, 1); + entry->type = CAMEL_GROUPWISE_JOURNAL_ENTRY_APPEND; + entry->uid = uid; + entry->original_uid = g_strdup (original_uid); + entry->source_container = g_strdup (camel_groupwise_store_container_id_lookup (gw_store, ((CamelFolder *)source_folder)->name)); + + e_dlist_addtail (&journal->queue, (EDListNode *) entry); + + if (transferred_uid) + *transferred_uid = g_strdup (uid); + + g_free (uid); +} diff --git a/camel/providers/groupwise/camel-groupwise-journal.h b/camel/providers/groupwise/camel-groupwise-journal.h new file mode 100644 index 0000000..dc34699 --- /dev/null +++ b/camel/providers/groupwise/camel-groupwise-journal.h @@ -0,0 +1,92 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast + * + * Copyright 2004 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef __CAMEL_GROUPWISE_JOURNAL_H__ +#define __CAMEL_GROUPWISE_JOURNAL_H__ + +#include + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define CAMEL_TYPE_GROUPWISE_JOURNAL (camel_groupwise_journal_get_type ()) +#define CAMEL_GROUPWISE_JOURNAL(obj) (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_GROUPWISE_JOURNAL, CamelGroupwiseJournal)) +#define CAMEL_GROUPWISE_JOURNAL_CLASS(klass) (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_GROUPWISE_JOURNAL, CamelGroupwiseJournalClass)) +#define CAMEL_IS_GROUPWISE_JOURNAL(obj) (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_GROUPWISE_JOURNAL)) +#define CAMEL_IS_GROUPWISE_JOURNAL_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_GROUPWISE_JOURNAL)) +#define CAMEL_GROUPWISE_JOURNAL_GET_CLASS(obj) (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_GROUPWISE_JOURNAL, CamelGroupwiseJournalClass)) + +typedef struct _CamelGroupwiseJournal CamelGroupwiseJournal; +typedef struct _CamelGroupwiseJournalClass CamelGroupwiseJournalClass; +typedef struct _CamelGroupwiseJournalEntry CamelGroupwiseJournalEntry; + +struct _CamelGroupwiseFolder; + +enum { + CAMEL_GROUPWISE_JOURNAL_ENTRY_APPEND, + CAMEL_GROUPWISE_JOURNAL_ENTRY_TRANSFER +}; + +struct _CamelGroupwiseJournalEntry { + EDListNode node; + + int type; + + char *uid; + char *original_uid; + char *source_container; +}; + +struct _CamelGroupwiseJournal { + CamelOfflineJournal parent_object; + +}; + +struct _CamelGroupwiseJournalClass { + CamelOfflineJournalClass parent_class; + +}; + + +CamelType camel_groupwise_journal_get_type (void); + +CamelOfflineJournal *camel_groupwise_journal_new (struct _CamelGroupwiseFolder *folder, const char *filename); + +/* interfaces for adding a journal entry */ +void camel_groupwise_journal_append (CamelGroupwiseJournal *journal, CamelMimeMessage *message, const CamelMessageInfo *mi, + char **appended_uid, CamelException *ex); +void camel_groupwise_journal_transfer (CamelGroupwiseJournal *journal, CamelGroupwiseFolder *source_folder, CamelMimeMessage *message, + const CamelMessageInfo *mi, const char *orginal_uid, char **transferred_uid, CamelException *ex); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __CAMEL_GROUPWISE_JOURNAL_H__ */ diff --git a/camel/providers/groupwise/camel-groupwise-store.c b/camel/providers/groupwise/camel-groupwise-store.c index 25e9706..1b885ec 100644 --- a/camel/providers/groupwise/camel-groupwise-store.c +++ b/camel/providers/groupwise/camel-groupwise-store.c @@ -867,16 +867,15 @@ groupwise_rename_folder(CamelStore *store, CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = groupwise_store->priv; char *oldpath, *newpath, *storepath ; - char *container_id ; + const char *container_id ; if (((CamelOfflineStore *) store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) { camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot rename GroupWise folders in offline mode.")); return; } - container_id = container_id_lookup (priv,old_name) ; + container_id = camel_groupwise_store_container_id_lookup (groupwise_store, old_name) ; if (!container_id || e_gw_connection_rename_folder (priv->cnc, container_id , new_name) != E_GW_CONNECTION_STATUS_OK) { - g_free (container_id) ; camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot rename Groupwise folder `%s' to `%s'"), old_name, new_name); return ; @@ -967,12 +966,23 @@ groupwise_forget_folder (CamelGroupwiseStore *gw_store, const char *folder_name, } -char * -container_id_lookup (CamelGroupwiseStorePrivate *priv, const char *folder_name) +const char * +camel_groupwise_store_container_id_lookup (CamelGroupwiseStore *gw_store, const char *folder_name) { + CamelGroupwiseStorePrivate *priv = gw_store->priv ; + return g_hash_table_lookup (priv->name_hash,folder_name) ; } +const char * +camel_groupwise_store_folder_lookup (CamelGroupwiseStore *gw_store, const char *container_id) +{ + CamelGroupwiseStorePrivate *priv = gw_store->priv ; + + return g_hash_table_lookup (priv->id_hash, container_id) ; +} + + EGwConnection * cnc_lookup (CamelGroupwiseStorePrivate *priv) { diff --git a/camel/providers/groupwise/camel-groupwise-store.h b/camel/providers/groupwise/camel-groupwise-store.h index 18212d6..65a665a 100644 --- a/camel/providers/groupwise/camel-groupwise-store.h +++ b/camel/providers/groupwise/camel-groupwise-store.h @@ -69,7 +69,8 @@ CamelType camel_groupwise_store_get_type (void); char * groupwise_get_name(CamelService *service, gboolean brief) ; /*IMplemented*/ -char *container_id_lookup (CamelGroupwiseStorePrivate *priv, const char *folder_name) ; +const char *camel_groupwise_store_container_id_lookup (CamelGroupwiseStore *gw_store, const char *folder_name) ; +const char *camel_groupwise_store_folder_lookup (CamelGroupwiseStore *gw_store, const char *container_id) ; EGwConnection *cnc_lookup (CamelGroupwiseStorePrivate *priv) ; const char *gw_get_path (CamelGroupwiseStore *gw_store, const char *folder_name) ; char *storage_path_lookup (CamelGroupwiseStorePrivate *priv) ; diff --git a/camel/providers/groupwise/camel-groupwise-transport.c b/camel/providers/groupwise/camel-groupwise-transport.c index 0bdd106..cbb2749 100644 --- a/camel/providers/groupwise/camel-groupwise-transport.c +++ b/camel/providers/groupwise/camel-groupwise-transport.c @@ -28,6 +28,7 @@ #include "camel-groupwise-transport.h" #include "camel-groupwise-store.h" +#include "camel-groupwise-utils.h" #include "camel-i18n.h" #include "camel-session.h" @@ -141,31 +142,14 @@ groupwise_send_to (CamelTransport *transport, CamelException *ex) { CamelService *service = CAMEL_SERVICE(transport) ; - CamelStore *store = NULL ; - CamelGroupwiseStore *groupwise_store = NULL; CamelGroupwiseStorePrivate *priv = NULL; - - EGwItem *item ; EGwConnection *cnc = NULL; EGwConnectionStatus status ; - EGwItemRecipient *recipient ; - EGwItemOrganizer *org = g_new0 (EGwItemOrganizer, 1) ; - - const char *display_name = NULL, *email = NULL ; - char *send_options = NULL ; - - int total_add ; - - CamelMultipart *mp ; - - GSList *sent_item_list = NULL, *recipient_list = NULL, *attach_list = NULL ; + GSList *sent_item_list = NULL; char *url = NULL ; - int i ; - /*Egroupwise item*/ - item = e_gw_item_new_empty () ; url = camel_url_to_string (service->url, (CAMEL_URL_HIDE_PASSWORD | @@ -191,169 +175,8 @@ groupwise_send_to (CamelTransport *transport, return FALSE ; } - /*poulate recipient list*/ - total_add = camel_address_length (recipients) ; - for (i=0 ; iemail = g_strdup (addr) ; - recipient->display_name = g_strdup (name) ; - recipient->type = E_GW_ITEM_RECIPIENT_TO; - recipient->status = E_GW_ITEM_STAT_NONE ; - recipient_list= g_slist_append (recipient_list, recipient) ; - } - } - - /** Get the mime parts from CamelMimemessge **/ - mp = (CamelMultipart *)camel_medium_get_content_object (CAMEL_MEDIUM (message)); - if(!mp) { - g_print ("ERROR: Could not get content object") ; - camel_operation_end (NULL) ; - return FALSE ; - } - - if (CAMEL_IS_MULTIPART (mp)) { - /*contains multiple parts*/ - guint part_count ; - - part_count = camel_multipart_get_number (mp) ; - for ( i=0 ; ibuffer->len+1) ; - g_print (">>>>>> length:%d |||\n", content->buffer->len) ; - buffer = memcpy (buffer, content->buffer->data, content->buffer->len) ; - g_print (">>>>>> buffer: \n %s\n", buffer) ; - len = content->buffer->len ; - - filename = camel_mime_part_get_filename (part) ; - if (!filename) { - /*the message*/ - e_gw_item_set_message (item, buffer) ; - } else { - mime_type = camel_data_wrapper_get_mime_type (dw) ; - g_print (">>>>mime:%s |||\n", mime_type) ; - type = camel_mime_part_get_content_type(part) ; - disposition = camel_mime_part_get_disposition (part) ; - attachment->data = g_malloc0 (content->buffer->len+1) ; - attachment->data = memcpy (attachment->data, content->buffer->data, content->buffer->len) ; - attachment->name = g_strdup (filename) ; - attachment->contentType = g_strdup_printf ("%s/%s", type->type, type->subtype) ; - g_print (">>>>>> %s/%s <<<<<< \n", type->type, type->subtype) ; - attachment->size = content->buffer->len ; - - attach_list = g_slist_append (attach_list, attachment) ; - g_free ((char *)disposition) ; - g_free ((char *)mime_type) ; - camel_content_type_unref (type) ; - } - g_free (buffer) ; - g_free ((char *)filename) ; - camel_object_unref (content) ; - - } /*end of for*/ - - } else { - /*only message*/ - CamelStreamMem *content = (CamelStreamMem *)camel_stream_mem_new () ; - CamelDataWrapper *dw = camel_data_wrapper_new () ; - char *buffer = NULL ; - - dw = camel_medium_get_content_object (CAMEL_MEDIUM (mp)) ; - camel_data_wrapper_write_to_stream(dw, (CamelStream *)content) ; - buffer = g_malloc0 (content->buffer->len+1) ; - g_print (">>>>>> length:%d |||\n", content->buffer->len) ; - buffer = memcpy (buffer, content->buffer->data, content->buffer->len) ; - - e_gw_item_set_message (item, buffer) ; - - g_free (buffer) ; - camel_object_unref (content) ; - } - /*Populate EGwItem*/ - /*From Address*/ - camel_internet_address_get ((CamelInternetAddress *)from, 0 , &display_name, &email) ; - g_print ("from : %s : %s\n", display_name,email) ; - org->display_name = g_strdup (display_name) ; - org->email = g_strdup (email) ; - e_gw_item_set_organizer (item, org) ; - /*recipient list*/ - e_gw_item_set_recipient_list (item, recipient_list) ; - /*Item type is mail*/ - e_gw_item_set_item_type (item, E_GW_ITEM_TYPE_MAIL) ; - /*subject*/ - e_gw_item_set_subject (item, camel_mime_message_get_subject(message)) ; - /*attachmets*/ - e_gw_item_set_attach_id_list (item, attach_list) ; - - /*send options*/ - e_gw_item_set_sendoptions (item, TRUE) ; - - if ((char *)camel_medium_get_header (CAMEL_MEDIUM(message), X_REPLY_CONVENIENT)) - e_gw_item_set_reply_request (item, TRUE) ; + item = camel_groupwise_util_item_from_message (message, from, recipients); - send_options = (char *)camel_medium_get_header (CAMEL_MEDIUM(message), X_REPLY_WITHIN) ; - if (send_options) - e_gw_item_set_reply_within (item, send_options) ; - - send_options = (char *)camel_medium_get_header (CAMEL_MEDIUM(message),X_EXPIRE_AFTER) ; - if (send_options) - e_gw_item_set_expires (item, send_options) ; - - send_options = (char *)camel_medium_get_header (CAMEL_MEDIUM(message), X_DELAY_UNTIL) ; - if (send_options) - e_gw_item_set_delay_until (item, send_options) ; - - send_options = (char *)camel_medium_get_header (CAMEL_MEDIUM(message), X_TRACK_WHEN) ; - if (send_options) { - switch (atoi(send_options)) { - case 1: e_gw_item_set_track_info (item, E_GW_ITEM_DELIVERED); - break; - case 2: e_gw_item_set_track_info (item, E_GW_ITEM_DELIVERED_OPENED); - break; - case 3: e_gw_item_set_track_info (item, E_GW_ITEM_ALL); - break; - default: e_gw_item_set_track_info (item, E_GW_ITEM_NONE); - break; - } - } - - if ((char *)camel_medium_get_header (CAMEL_MEDIUM(message), X_AUTODELETE)) - e_gw_item_set_autodelete (item, TRUE) ; - - send_options = (char *)camel_medium_get_header (CAMEL_MEDIUM (message), X_RETURN_NOTIFY_OPEN) ; - if (send_options) { - switch (atoi(send_options)) { - case 0: e_gw_item_set_notify_opened (item, E_GW_ITEM_NOTIFY_NONE); - break; - case 1: e_gw_item_set_notify_opened (item, E_GW_ITEM_NOTIFY_MAIL); - } - } - send_options = (char *)camel_medium_get_header (CAMEL_MEDIUM (message), X_RETURN_NOTIFY_DECLINE) ; - if (send_options) { - switch (atoi(send_options)) { - case 0: e_gw_item_set_notify_declined (item, E_GW_ITEM_NOTIFY_NONE); - break; - case 1: e_gw_item_set_notify_declined (item, E_GW_ITEM_NOTIFY_MAIL); - } - } - /*Send item*/ status = e_gw_connection_send_item (cnc, item, &sent_item_list) ; if (status != E_GW_CONNECTION_STATUS_OK) { diff --git a/camel/providers/groupwise/camel-groupwise-transport.h b/camel/providers/groupwise/camel-groupwise-transport.h index ef47743..7d79e00 100644 --- a/camel/providers/groupwise/camel-groupwise-transport.h +++ b/camel/providers/groupwise/camel-groupwise-transport.h @@ -38,21 +38,6 @@ extern "C" { #define CAMEL_GROUPWISE_TRANSPORT_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_GROUPWISE_TRANSPORT_TYPE, CamelGroupwiseTransportClass)) #define CAMEL_IS_GROUPWISE_TRANSPORT(o) (CAMEL_CHECK_TYPE((o), CAMEL_GROUPWISE_TRANSPORT_TYPE)) -/*Headers for send options*/ -#define X_SEND_OPTIONS "X-gw-send-options" -/*General Options*/ -#define X_SEND_OPT_PRIORITY "X-gw-send-opt-priority" -#define X_REPLY_CONVENIENT "X-reply-convenient" -#define X_REPLY_WITHIN "X-reply-within" -#define X_EXPIRE_AFTER "X-expire-after" -#define X_DELAY_UNTIL "X-delay-until" - -/*Status Tracking Options*/ -#define X_TRACK_WHEN "X-track-when" -#define X_AUTODELETE "X-auto-delete" -#define X_RETURN_NOTIFY_OPEN "X-return-notify-open" -#define X_RETURN_NOTIFY_DECLINE "X-return-notify-decline" - typedef struct { CamelTransport parent_object; diff --git a/camel/providers/groupwise/camel-groupwise-utils.c b/camel/providers/groupwise/camel-groupwise-utils.c index 362a393..5b0329d 100644 --- a/camel/providers/groupwise/camel-groupwise-utils.c +++ b/camel/providers/groupwise/camel-groupwise-utils.c @@ -258,7 +258,6 @@ e_path_rmdir (const char *prefix, const char *vpath) return 0; } - EGwItem * camel_groupwise_util_item_from_message (CamelMimeMessage *message, CamelAddress *from, CamelAddress *recipients) { -- 2.7.4