From 3c86a0c57cab32e0042cc58c347b2843274b9a03 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Fri, 11 Jun 2004 05:33:51 +0000 Subject: Don't bother scanning summary info if EXISTS was 0. 2004-06-11 Jeffrey Stedfast * providers/imap4/camel-imap4-summary.c (camel_imap4_summary_flush_updates): Don't bother scanning summary info if EXISTS was 0. (camel_imap4_summary_set_uidvalidity): Emit the folder_changed event after clearing the summary. (camel_imap4_summary_expunge): Emit the folder_changed event after removing the message from the summary. * providers/imap4/camel-imap4-folder.c (imap4_sync): Flush updates after an EXPUNGE and don't unset expunge if we didn't delete anything (the logic was wrong anyway). (imap4_refresh_info): Implemented. svn path=/trunk/; revision=26300 --- camel/providers/imap4/camel-imap4-folder.c | 28 ++++++++++++++++++++++++- camel/providers/imap4/camel-imap4-summary.c | 32 +++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 9 deletions(-) (limited to 'camel/providers') diff --git a/camel/providers/imap4/camel-imap4-folder.c b/camel/providers/imap4/camel-imap4-folder.c index a67d50f816..006b214488 100644 --- a/camel/providers/imap4/camel-imap4-folder.c +++ b/camel/providers/imap4/camel-imap4-folder.c @@ -58,6 +58,7 @@ static void camel_imap4_folder_init (CamelIMAP4Folder *folder, CamelIMAP4FolderC static void camel_imap4_folder_finalize (CamelObject *object); static void imap4_sync (CamelFolder *folder, gboolean expunge, CamelException *ex); +static void imap4_refresh_info (CamelFolder *folder, CamelException *ex); static void imap4_expunge (CamelFolder *folder, CamelException *ex); static CamelMimeMessage *imap4_get_message (CamelFolder *folder, const char *uid, CamelException *ex); static void imap4_append_message (CamelFolder *folder, CamelMimeMessage *message, @@ -96,6 +97,7 @@ camel_imap4_folder_class_init (CamelIMAP4FolderClass *klass) parent_class = (CamelFolderClass *) camel_type_get_global_classfuncs (CAMEL_FOLDER_TYPE); folder_class->sync = imap4_sync; + folder_class->refresh_info = imap4_refresh_info; folder_class->expunge = imap4_expunge; folder_class->get_message = imap4_get_message; folder_class->append_message = imap4_append_message; @@ -522,7 +524,6 @@ imap4_sync (CamelFolder *folder, gboolean expunge, CamelException *ex) max = camel_folder_summary_count (folder->summary); for (i = 0; i < max; i++) { iinfo = (CamelIMAP4MessageInfo *) info = camel_folder_summary_index (folder->summary, i); - expunge = expunge && (info->flags & CAMEL_MESSAGE_DELETED); if (info->flags & CAMEL_MESSAGE_FOLDER_FLAGGED) { camel_imap4_flags_diff (&diff, iinfo->server_flags, info->flags); diff.changed &= folder->permanent_flags; @@ -557,6 +558,9 @@ imap4_sync (CamelFolder *folder, gboolean expunge, CamelException *ex) ; switch (ic->result) { + case CAMEL_IMAP4_RESULT_OK: + camel_imap4_summary_flush_updates (folder->summary, ex); + break; case CAMEL_IMAP4_RESULT_NO: /* FIXME: would be good to save the NO reason into the err message */ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, @@ -571,6 +575,8 @@ imap4_sync (CamelFolder *folder, gboolean expunge, CamelException *ex) } camel_imap4_command_unref (ic); + } else { + camel_imap4_summary_flush_updates (folder->summary, ex); } camel_folder_summary_save (folder->summary); @@ -586,6 +592,26 @@ imap4_expunge (CamelFolder *folder, CamelException *ex) imap4_sync (folder, TRUE, ex); } +static void +imap4_refresh_info (CamelFolder *folder, CamelException *ex) +{ + CamelIMAP4Engine *engine = ((CamelIMAP4Store *) folder->parent_store)->engine; + CamelFolder *selected = (CamelFolder *) engine->folder; + + CAMEL_SERVICE_LOCK (folder->parent_store, connect_lock); + + if (folder != selected) { + if (camel_imap4_engine_select_folder (engine, folder, ex) == -1) + goto done; + } + + if (camel_imap4_summary_flush_updates (folder->summary, ex) == -1) + goto done; + + done: + + CAMEL_SERVICE_UNLOCK (folder->parent_store, connect_lock); +} static int untagged_fetch (CamelIMAP4Engine *engine, CamelIMAP4Command *ic, guint32 index, camel_imap4_token_t *token, CamelException *ex) diff --git a/camel/providers/imap4/camel-imap4-summary.c b/camel/providers/imap4/camel-imap4-summary.c index 8ef8d342fa..f68f892153 100644 --- a/camel/providers/imap4/camel-imap4-summary.c +++ b/camel/providers/imap4/camel-imap4-summary.c @@ -998,15 +998,30 @@ void camel_imap4_summary_set_uidvalidity (CamelFolderSummary *summary, guint32 uidvalidity) { CamelIMAP4Summary *imap4_summary = (CamelIMAP4Summary *) summary; + CamelFolderChangeInfo *changes; + CamelMessageInfo *info; + int i, count; g_return_if_fail (CAMEL_IS_IMAP4_SUMMARY (summary)); if (imap4_summary->uidvalidity == uidvalidity) return; - /* FIXME: emit a signal or something first? */ + changes = camel_folder_change_info_new (); + count = camel_folder_summary_count (summary); + for (i = 0; i < count; i++) { + if (!(info = camel_folder_summary_index (summary, i))) + continue; + + camel_folder_change_info_remove_uid (changes, camel_message_info_uid (info)); + camel_folder_summary_info_free (summary, info); + } + camel_folder_summary_clear (summary); + camel_object_trigger_event (imap4_summary->folder, "folder_changed", changes); + camel_folder_change_info_free (changes); + imap4_summary->uidvalidity = uidvalidity; imap4_summary->uidvalidity_changed = TRUE; @@ -1015,6 +1030,8 @@ camel_imap4_summary_set_uidvalidity (CamelFolderSummary *summary, guint32 uidval void camel_imap4_summary_expunge (CamelFolderSummary *summary, int seqid) { + CamelIMAP4Summary *imap4_summary = (CamelIMAP4Summary *) summary; + CamelFolderChangeInfo *changes; CamelMessageInfo *info; g_return_if_fail (CAMEL_IS_IMAP4_SUMMARY (summary)); @@ -1022,11 +1039,10 @@ camel_imap4_summary_expunge (CamelFolderSummary *summary, int seqid) if (!(info = camel_folder_summary_index (summary, seqid))) return; - /* FIXME: emit a signal or something that our Folder can proxy - * up to the app so that it can update its display and - * whatnot? */ - - /* emit signal */ + changes = camel_folder_change_info_new (); + camel_folder_change_info_remove_uid (changes, camel_message_info_uid (info)); + camel_object_trigger_event (imap4_summary->folder, "folder_changed", changes); + camel_folder_change_info_free (changes); camel_folder_summary_info_free (summary, info); camel_folder_summary_remove_index (summary, seqid); @@ -1062,7 +1078,7 @@ camel_imap4_summary_flush_updates (CamelFolderSummary *summary, CamelException * if (imap4_summary->uidvalidity_changed) { first = 1; - } else if (imap4_summary->exists_changed) { + } else if (imap4_summary->exists_changed && imap4_summary->exists > 0) { scount = camel_folder_summary_count (summary); ic = imap4_summary_fetch_flags (summary, 1, scount); @@ -1082,7 +1098,7 @@ camel_imap4_summary_flush_updates (CamelFolderSummary *summary, CamelException * camel_imap4_command_unref (ic); } - if (first != 0) { + if (first != 0 && imap4_summary->exists > 0) { ic = imap4_summary_fetch_all (summary, first, 0); while ((id = camel_imap4_engine_iterate (engine)) < ic->id && id != -1) -- cgit v1.2.3