Updated to check for EXPUNGE notifications
authorJeffrey Stedfast <fejj@helixcode.com>
Tue, 29 Aug 2000 17:04:54 +0000 (17:04 +0000)
committerJeffrey Stedfast <fejj@src.gnome.org>
Tue, 29 Aug 2000 17:04:54 +0000 (17:04 +0000)
2000-08-29  Jeffrey Stedfast  <fejj@helixcode.com>

* providers/imap/camel-imap-store.c (camel_imap_command_extended):
Updated to check for EXPUNGE notifications

* providers/imap/camel-imap-folder.c (camel_imap_folder_changed):
Updated to account for messages which have been expunged (now
takes a new arg, a GPtrArray of message id's that have been
expunged)
(imap_expunge): Updated (we may want to just use the code in
folder_changed now instead of doing our own summary
expunging...but that can be fixed later)
(imap_append_message): Updated.
(imap_copy_message_to): Updated.
(imap_move_message_to): Updated.

camel/ChangeLog
camel/providers/imap/camel-imap-folder.c
camel/providers/imap/camel-imap-folder.h
camel/providers/imap/camel-imap-store.c
camel/providers/smtp/camel-smtp-transport.c

index be17adb..54c23dc 100644 (file)
@@ -1,3 +1,19 @@
+2000-08-29  Jeffrey Stedfast  <fejj@helixcode.com>
+
+       * providers/imap/camel-imap-store.c (camel_imap_command_extended):
+       Updated to check for EXPUNGE notifications
+
+       * providers/imap/camel-imap-folder.c (camel_imap_folder_changed):
+       Updated to account for messages which have been expunged (now
+       takes a new arg, a GPtrArray of message id's that have been
+       expunged)
+       (imap_expunge): Updated (we may want to just use the code in
+       folder_changed now instead of doing our own summary
+       expunging...but that can be fixed later)
+       (imap_append_message): Updated.
+       (imap_copy_message_to): Updated.
+       (imap_move_message_to): Updated.
+
 2000-08-28  Jeffrey Stedfast  <fejj@helixcode.com>
 
        * providers/imap/camel-imap-folder.c (imap_get_message): Fixed the
index 33d7d06..e3ce219 100644 (file)
@@ -439,7 +439,7 @@ imap_expunge (CamelFolder *folder, CamelException *ex)
        
        g_free (result);
        
-       camel_imap_folder_changed (folder, recent, ex);
+       camel_imap_folder_changed (folder, recent, NULL, ex);
 }
 
 static gint
@@ -620,7 +620,7 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, const Camel
        g_free (cmdid);
        g_free (result);
        
-       camel_imap_folder_changed (folder, 1, ex);
+       camel_imap_folder_changed (folder, 1, NULL, ex);
 }
 
 static void
@@ -656,7 +656,7 @@ imap_copy_message_to (CamelFolder *source, const char *uid, CamelFolder *destina
        g_free (result);
        g_free (folder_path);
        
-       camel_imap_folder_changed (destination, 1, ex);
+       camel_imap_folder_changed (destination, 1, NULL, ex);
 }
 
 /* FIXME: Duplication of code! */
@@ -705,7 +705,7 @@ imap_move_message_to (CamelFolder *source, const char *uid, CamelFolder *destina
        
        imap_set_message_flags (source, uid, CAMEL_MESSAGE_DELETED, ~(info->flags));
        
-       camel_imap_folder_changed (destination, 1, ex);
+       camel_imap_folder_changed (destination, 1, NULL, ex);
 }
 
 static GPtrArray *
@@ -1544,11 +1544,42 @@ imap_set_message_user_flag (CamelFolder *folder, const char *uid, const char *na
 }
 
 void
-camel_imap_folder_changed (CamelFolder *folder, gint recent, CamelException *ex)
+camel_imap_folder_changed (CamelFolder *folder, gint recent, GPtrArray *expunged, CamelException *ex)
 {
-       d(fprintf (stderr, "camel_imap_folder_changed: recent = %d\n", recent));
+       CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
        
-       g_return_if_fail (recent);
+       if (expunged) {
+               gint i, id;
+               
+               for (i = 0; i < expunged->len; i++) {
+                       id = atoi (expunged->pdata[i]);
+                       d(fprintf (stderr, "Expunging message %d from the summary (i = %d)\n", id + i, i));
+                       
+                       if (id <= imap_folder->summary->len) {
+                               CamelMessageInfo *info;
+                               
+                               info = (CamelMessageInfo *) imap_folder->summary->pdata[id - 1];
+                               
+                               /* remove from the lookup table and summary */
+                               g_hash_table_remove (imap_folder->summary_hash, info->uid);
+                               g_ptr_array_remove_index (imap_folder->summary, id - 1);
+                               
+                               /* free the info data */
+                               g_free (info->subject);
+                               g_free (info->from);
+                               g_free (info->to);
+                               g_free (info->cc);
+                               g_free (info->uid);
+                               g_free (info->message_id);
+                               header_references_list_clear (&info->references);
+                               g_free (info);
+                               info = NULL;
+                       } else {
+                               /* Hopefully this should never happen */
+                               d(fprintf (stderr, "imap expunge-error: message %d is out of range\n", id));
+                       }
+               }
+       }
        
        if (recent > 0) {
                CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
index bd1647c..4df50ed 100644 (file)
@@ -65,7 +65,8 @@ typedef struct {
 CamelFolder *camel_imap_folder_new (CamelStore *parent, char *folder_name,
                                    CamelException *ex);
 
-void camel_imap_folder_changed (CamelFolder *folder, gint recent, CamelException *ex);
+void camel_imap_folder_changed (CamelFolder *folder, gint recent, GPtrArray *expunged,
+                               CamelException *ex);
 
 /* Standard Camel function */
 CamelType camel_imap_folder_get_type (void);
index f7662ad..9e57dc0 100644 (file)
@@ -824,7 +824,7 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
        CamelURL *url = service->url;
        gint len = 0, recent = 0, status = CAMEL_IMAP_OK;
        gchar *cmdid, *cmdbuf, *respbuf;
-       GPtrArray *data;
+       GPtrArray *data, *expunged = NULL;
        va_list app;
        int i;
        
@@ -893,6 +893,7 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
        g_free (cmdbuf);
        
        data = g_ptr_array_new ();
+       expunged = g_ptr_array_new ();
        
        while (1) {
                CamelStreamBuffer *stream = CAMEL_STREAM_BUFFER (store->istream);
@@ -925,14 +926,27 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
                if (recent && *respbuf != '*')
                        recent = 0;
                
-               if (*respbuf == '*' && (ptr = strstr (respbuf, "RECENT"))) {
-                       char *rcnt;
-                       
-                       d(fprintf (stderr, "*** We may have found a 'RECENT' flag: %s\n", respbuf));
-                       /* Make sure it's in the form: "* %d RECENT" */
-                       rcnt = imap_next_word (respbuf);
-                       if (*rcnt >= '0' && *rcnt <= '9' && !strncmp ("RECENT", imap_next_word (rcnt), 6))
-                               recent = atoi (rcnt);
+               if (*respbuf == '*') {
+                       if ((ptr = strstr (respbuf, "RECENT"))) {
+                               char *rcnt;
+                               
+                               d(fprintf (stderr, "*** We may have found a 'RECENT' flag: %s\n", respbuf));
+                               /* Make sure it's in the form: "* %d RECENT" */
+                               rcnt = imap_next_word (respbuf);
+                               if (*rcnt >= '0' && *rcnt <= '9' && !strncmp ("RECENT", imap_next_word (rcnt), 6))
+                                       recent = atoi (rcnt);
+                       } else if ((ptr = strstr (respbuf, "EXPUNGE"))) {
+                               char *id_str;
+                               int id;
+                               
+                               d(fprintf (stderr, "*** We may have found an 'EXPUNGE' flag: %s\n", respbuf));
+                               /* Make sure it's in the form: "* %d EXPUNGE" */
+                               id_str = imap_next_word (respbuf);
+                               if (*id_str >= '0' && *id_str <= '9' && !strncmp ("EXPUNGE", imap_next_word (id_str), 7)) {
+                                       id = atoi (id_str);
+                                       g_ptr_array_add (expunged, g_strdup_printf ("%d", id));
+                               }
+                       }
                }
        }
        
@@ -965,7 +979,7 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
        } else {
                if (status != CAMEL_IMAP_FAIL && respbuf) {
                        char *word;
-
+                       
                        word = imap_next_word (respbuf); /* word should now point to NO or BAD */
                        
                        *ret = g_strdup (imap_next_word (word));
@@ -982,7 +996,12 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
                CamelException *ex;
                
                ex = camel_exception_new ();
-               camel_imap_folder_changed (folder, recent, ex);
+               camel_imap_folder_changed (folder, recent, expunged, ex);
+               
+               for (i = 0; i < expunged->len; i++)
+                       g_free (expunged->pdata[i]);
+               g_ptr_array_free (expunged, TRUE);
+               
                camel_exception_free (ex);
        }
        
index 19668a3..ea3a60a 100644 (file)
@@ -207,11 +207,11 @@ smtp_connect (CamelService *service, CamelException *ex)
                /* not really supported yet, but we can at least show what auth types are supported */
                d(fprintf (stderr, "camel-smtp-transport::connect(): %s requires AUTH\n", service->url->host));
                num = g_list_length (transport->esmtp_supported_authtypes);
-
+               
                for (i = 0; i < num; i++)
                        d(fprintf (stderr, "\nSupported AUTH: %s\n\n", 
                                (gchar *) g_list_nth_data (transport->esmtp_supported_authtypes, i)));
-
+               
                g_list_free (transport->esmtp_supported_authtypes);
                transport->esmtp_supported_authtypes = NULL;
        } else {