to sync back flags to the server. currently can sync only read messages.
authorParthasarathi Susarla <sparthasarathi@novell.com>
Tue, 11 Jan 2005 09:45:29 +0000 (09:45 +0000)
committerParthasarathi Susarla <saps@src.gnome.org>
Tue, 11 Jan 2005 09:45:29 +0000 (09:45 +0000)
2005-01-11  Parthasarathi Susarla <sparthasarathi@novell.com>

* providers/groupwise/camel-groupwise-folder.c
  (groupwise_sync): to sync back flags to the server. currently
  can sync only read messages.
  (groupwise_append_message): set source based on folder
* providers/groupwise/camel-groupwise-utils.[ch]
  (do_flags_diff): finds the difference between flags. Based on the
  imap4 code by fejj

camel/ChangeLog
camel/providers/groupwise/camel-groupwise-folder.c
camel/providers/groupwise/camel-groupwise-utils.c
camel/providers/groupwise/camel-groupwise-utils.h

index 2b78634..702a392 100644 (file)
@@ -1,3 +1,13 @@
+2005-01-11  Parthasarathi Susarla <sparthasarathi@novell.com>
+       
+       * providers/groupwise/camel-groupwise-folder.c
+         (groupwise_sync): to sync back flags to the server. currently
+         can sync only read messages.
+         (groupwise_append_message): set source based on folder 
+       * providers/groupwise/camel-groupwise-utils.[ch]
+         (do_flags_diff): finds the difference between flags. Based on the
+         imap4 code by fejj
+
 2005-01-11  JP Rosevear  <jpr@novell.com>
 
        * providers/groupwise/camel-groupwise-transport.h: remove defines
index b8f6ddb..a4d710c 100644 (file)
@@ -397,7 +397,47 @@ groupwise_folder_search_free (CamelFolder *folder, GPtrArray *uids)
 static void
 groupwise_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 {
+       CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE (folder->parent_store) ;
+       CamelGroupwiseStorePrivate *priv = gw_store->priv ;
+       CamelMessageInfo *info ;
+       CamelGroupwiseMessageInfo *gw_info ;
+       GList *items ;
+       flags_diff_t diff ;
+       EGwConnection *cnc  = cnc_lookup (priv) ;
+       int count, i ;
+
+       if (((CamelOfflineStore *) gw_store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) 
+               return ;
+       
+       CAMEL_SERVICE_LOCK (folder->parent_store, connect_lock);
+
+       count = camel_folder_summary_count (folder->summary) ;
+       for (i=0 ; i <count ; i++) {
+               info = camel_folder_summary_index (folder->summary, i) ;
+               gw_info = (CamelGroupwiseMessageInfo *) info ;
+
+               if (gw_info->info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED) {
+                       do_flags_diff (&diff, gw_info->server_flags, gw_info->info.flags) ;
+                       diff.changed &= folder->permanent_flags;
+
+                       /* weed out flag changes that we can't sync to the server */
+                       if (!diff.changed)
+                               camel_message_info_free(info);
+                       else {
+                               if (diff.changed & CAMEL_MESSAGE_SEEN)
+                                       items = g_list_append (items, (char *)camel_message_info_uid(info));
+                       }
+               }
+               
+       }
+
+       e_gw_connection_mark_unread (cnc, items) ;
+       
        camel_folder_summary_save (folder->summary);
+
+done:
+       CAMEL_SERVICE_UNLOCK (folder->parent_store, connect_lock);
+
 }
 
 
@@ -628,7 +668,18 @@ groupwise_append_message (CamelFolder *folder, CamelMimeMessage *message,
        camel_address_cat (recipients, CAMEL_ADDRESS (camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_BCC)));
 
        item = camel_groupwise_util_item_from_message (message, CAMEL_ADDRESS (message->from), recipients);
+       /*Set the source*/
+       if (!strcmp (folder->name, RECEIVED))
+                       e_gw_item_set_source (item, "received") ;
+       if (!strcmp (folder->name, SENT))
+                       e_gw_item_set_source (item, "sent") ;
+       if (!strcmp (folder->name, DRAFT))
+                       e_gw_item_set_source (item, "draft") ;
+       if (!strcmp (folder->name, PERSONAL))
+                       e_gw_item_set_source (item, "personal") ;
+       /*set container id*/
        e_gw_item_set_container_id (item, container_id) ;
+
        status = e_gw_connection_create_item (cnc, item, &id);
        if (status != E_GW_CONNECTION_STATUS_OK) {
                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot create message: %s"),
index 5b0329d..04a50b7 100644 (file)
@@ -440,3 +440,11 @@ camel_groupwise_util_item_from_message (CamelMimeMessage *message, CamelAddress
 
        return item;
 }
+
+void
+do_flags_diff (flags_diff_t *diff, guint32 old, guint32 _new)
+{
+       diff->changed = old ^ _new;
+       diff->bits = _new & diff->changed;
+}
+
index 4cf0fba..cbe8cb1 100644 (file)
 #define X_RETURN_NOTIFY_OPEN    "X-return-notify-open"
 #define X_RETURN_NOTIFY_DECLINE "X-return-notify-decline"
 
+/* Folder types for source */
+#define RECEIVED  "Mailbox"
+#define SENT     "Sent Items"
+#define DRAFT    ""
+#define PERSONAL  "Cabinet"
+
+/*for syncing flags back to server*/
+typedef struct {
+       guint32 changed;
+       guint32 bits;
+} flags_diff_t;
+
 
 /* FIXME: deprecated
    This is used exclusively for the legacy imap cache code.  DO NOT use this in any new code */
@@ -59,5 +71,5 @@ int      e_path_rmdir        (const char *prefix, const char *vpath);
 
 
 EGwItem *camel_groupwise_util_item_from_message (CamelMimeMessage *message, CamelAddress *from, CamelAddress *recipients);
-
+void do_flags_diff (flags_diff_t *diff, guint32 old, guint32 _new) ;
 #endif