diff options
author | Dan Winship <danw@src.gnome.org> | 2001-05-01 02:13:45 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2001-05-01 02:13:45 +0800 |
commit | 8ad89adf8ca7d1208473a8028036d270b6ad0b30 (patch) | |
tree | 3d7718059c99a55bac407e49852bb38c9b26eb5a | |
parent | 155fcd81538ef9aa63e6e6d4b585d5dd528b4e47 (diff) | |
download | gsoc2013-evolution-8ad89adf8ca7d1208473a8028036d270b6ad0b30.tar gsoc2013-evolution-8ad89adf8ca7d1208473a8028036d270b6ad0b30.tar.gz gsoc2013-evolution-8ad89adf8ca7d1208473a8028036d270b6ad0b30.tar.bz2 gsoc2013-evolution-8ad89adf8ca7d1208473a8028036d270b6ad0b30.tar.lz gsoc2013-evolution-8ad89adf8ca7d1208473a8028036d270b6ad0b30.tar.xz gsoc2013-evolution-8ad89adf8ca7d1208473a8028036d270b6ad0b30.tar.zst gsoc2013-evolution-8ad89adf8ca7d1208473a8028036d270b6ad0b30.zip |
New-and-improved version of get_uid_set() from camel-imap-folder.c. Looks
* providers/imap/camel-imap-utils.c (imap_uid_array_to_set):
New-and-improved version of get_uid_set() from
camel-imap-folder.c. Looks at the summary as it goes so that if
you ask for messages 5, 6, 8, and 9, and there is no message 7,
then you get "5:9" instead of "5:6,8:9"
* providers/imap/camel-imap-folder.c (imap_copy_messages_to): Use
imap_uid_array_to_set() rather than get_uid_set().
(get_uid_set): Gone
svn path=/trunk/; revision=9632
-rw-r--r-- | camel/ChangeLog | 12 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-folder.c | 39 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-utils.c | 74 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-utils.h | 2 |
4 files changed, 89 insertions, 38 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 2a5d9a0149..30b479a59f 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,15 @@ +2001-04-30 Dan Winship <danw@ximian.com> + + * providers/imap/camel-imap-utils.c (imap_uid_array_to_set): + New-and-improved version of get_uid_set() from + camel-imap-folder.c. Looks at the summary as it goes so that if + you ask for messages 5, 6, 8, and 9, and there is no message 7, + then you get "5:9" instead of "5:6,8:9" + + * providers/imap/camel-imap-folder.c (imap_copy_messages_to): Use + imap_uid_array_to_set() rather than get_uid_set(). + (get_uid_set): Gone + 2001-04-27 Dan Winship <danw@ximian.com> * camel-session.c: Redo this a lot so that instead of having a diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c index 9f325aae56..89ac95fea5 100644 --- a/camel/providers/imap/camel-imap-folder.c +++ b/camel/providers/imap/camel-imap-folder.c @@ -698,43 +698,6 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, camel_imap_response_free (response); } -static char * -get_uid_set (GPtrArray *uids) -{ - /* Note: the only thing that might be good to do here is to - not use atoi() and use strtoul() or something */ - int i, last_uid, this_uid; - gboolean range = FALSE; - GString *gset; - char *set; - - gset = g_string_new (uids->pdata[0]); - last_uid = atoi (uids->pdata[0]); - for (i = 1; i < uids->len; i++) { - this_uid = atoi (uids->pdata[i]); - if (this_uid != last_uid + 1) { - if (range) { - g_string_sprintfa (gset, ":%d", last_uid); - range = FALSE; - } - - g_string_sprintfa (gset, ",%d", this_uid); - } else { - range = TRUE; - } - - last_uid = this_uid; - } - - if (range) - g_string_sprintfa (gset, ":%d", this_uid); - - set = gset->str; - g_string_free (gset, FALSE); - - return set; -} - static void imap_copy_messages_to (CamelFolder *source, GPtrArray *uids, CamelFolder *destination, CamelException *ex) @@ -753,7 +716,7 @@ imap_copy_messages_to (CamelFolder *source, GPtrArray *uids, /* Now copy the messages */ CAMEL_IMAP_STORE_LOCK(store, command_lock); - set = get_uid_set (uids); + set = imap_uid_array_to_set (source->summary, uids); response = camel_imap_command (store, source, ex, "UID COPY %s %S", set, destination->full_name); diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c index acbfe46b23..22f3c95b50 100644 --- a/camel/providers/imap/camel-imap-utils.c +++ b/camel/providers/imap/camel-imap-utils.c @@ -566,3 +566,77 @@ imap_quote_string (const char *str) return quoted; } + + +static inline unsigned long +get_summary_uid_numeric (CamelFolderSummary *summary, int index) +{ + CamelMessageInfo *info; + unsigned long uid; + + info = camel_folder_summary_index (summary, index); + uid = strtoul (camel_message_info_uid (info), NULL, 10); + camel_folder_summary_info_free (summary, info); + return uid; +} + +/** + * imap_uid_array_to_set: + * @summary: summary for the folder the UIDs come from + * @uids: a (sorted) array of UIDs + * + * Return value: an IMAP "set" covering the listed UIDs, which the + * caller must free with g_free(). + **/ +char * +imap_uid_array_to_set (CamelFolderSummary *summary, GPtrArray *uids) +{ + int ui, si, scount; + unsigned long last_uid, next_summary_uid, this_uid; + gboolean range = FALSE; + GString *gset; + char *set; + + gset = g_string_new (uids->pdata[0]); + last_uid = strtoul (uids->pdata[0], NULL, 10); + scount = camel_folder_summary_count (summary); + + for (ui = 1, si = 0; ui < uids->len; ui++) { + /* Find the next UID in the summary */ + for (; si < scount; si++) { + next_summary_uid = get_summary_uid_numeric (summary, si); + if (next_summary_uid == last_uid) + break; + } + if (++si < scount) + next_summary_uid = get_summary_uid_numeric (summary, si); + else + next_summary_uid = (guint32) -1; + + /* Now get the next UID from @uids */ + this_uid = strtoul (uids->pdata[ui], NULL, 10); + if (this_uid == next_summary_uid) { + range = TRUE; + if (++si < scount) + next_summary_uid = get_summary_uid_numeric (summary, si); + else + next_summary_uid = (guint32) -1; + } else { + if (range) { + g_string_sprintfa (gset, ":%lu", last_uid); + range = FALSE; + } + g_string_sprintfa (gset, ",%lu", this_uid); + } + + last_uid = this_uid; + } + + if (range) + g_string_sprintfa (gset, ":%lu", last_uid); + + set = gset->str; + g_string_free (gset, FALSE); + + return set; +} diff --git a/camel/providers/imap/camel-imap-utils.h b/camel/providers/imap/camel-imap-utils.h index 77bc51f9bc..937bec02d1 100644 --- a/camel/providers/imap/camel-imap-utils.h +++ b/camel/providers/imap/camel-imap-utils.h @@ -57,6 +57,8 @@ char *imap_quote_string (const char *str); void imap_skip_list (char **str_p); +char * imap_uid_array_to_set (CamelFolderSummary *summary, GPtrArray *uids); + #ifdef __cplusplus } #endif /* __cplusplus */ |