Mercurial > dovecot > original-hg > dovecot-1.2
changeset 171:4716cf66c2cc HEAD
Moved lib-index/mail-messageset.* to lib-storage/index/index-messageset.*.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 07 Sep 2002 04:52:21 +0300 |
parents | 00e52ea54ed4 |
children | 674d0067ea22 |
files | src/lib-index/Makefile.am src/lib-index/mail-messageset.c src/lib-index/mail-messageset.h src/lib-storage/index/Makefile.am src/lib-storage/index/index-copy.c src/lib-storage/index/index-fetch.c src/lib-storage/index/index-messageset.c src/lib-storage/index/index-messageset.h src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/index-update-flags.c src/lib-storage/index/maildir/maildir-copy.c |
diffstat | 12 files changed, 359 insertions(+), 375 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/Makefile.am Sat Sep 07 04:46:07 2002 +0300 +++ b/src/lib-index/Makefile.am Sat Sep 07 04:52:21 2002 +0300 @@ -17,7 +17,6 @@ mail-index-update-cache.c \ mail-index-util.c \ mail-lockdir.c \ - mail-messageset.c \ mail-modifylog.c noinst_HEADERS = \ @@ -26,5 +25,4 @@ mail-index-data.h \ mail-index-util.h \ mail-lockdir.h \ - mail-messageset.h \ mail-modifylog.h
--- a/src/lib-index/mail-messageset.c Sat Sep 07 04:46:07 2002 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,310 +0,0 @@ -/* Copyright (C) 2002 Timo Sirainen */ - -#include "lib.h" -#include "mail-index.h" -#include "mail-index-util.h" -#include "mail-hash.h" -#include "mail-modifylog.h" -#include "mail-messageset.h" - -static unsigned int get_next_number(const char **str) -{ - unsigned int num; - - num = 0; - while (**str != '\0') { - if (**str < '0' || **str > '9') - break; - - num = num*10 + (**str - '0'); - (*str)++; - } - - return num; -} - -static int mail_index_foreach(MailIndex *index, - unsigned int seq, unsigned int seq2, - MsgsetForeachFunc func, void *context, - const char **error) -{ - MailIndexRecord *rec; - const unsigned int *expunges; - unsigned int expunges_before; - int expunges_found; - - if (seq > seq2) { - /* Second sequence can't be smaller than first - we could swap - them but I think it's a bug in client if it does this, - and better complain about it immediately than later let - them wonder why it doesn't work with other imapds.. */ - *error = t_strdup_printf("Invalid messageset range: %u > %u", - seq, seq2); - return -2; - } - - /* get list of expunged messages in our range. the expunges_before - can be used to calculate the current real sequence position */ - expunges = mail_modifylog_seq_get_expunges(index->modifylog, seq, seq2, - &expunges_before); - i_assert(expunges_before < seq); - expunges_found = *expunges != '\0'; - - /* Reset index errors, since we later rely on it to check if failed */ - index_reset_error(index); - - /* get the first non-expunged message. note that if all messages - were expunged in the range, this points outside wanted range. */ - rec = index->lookup(index, seq - expunges_before); - for (; rec != NULL; seq++) { - /* skip expunged sequences */ - i_assert(rec->uid != 0); - - while (*expunges != 0 && *expunges < rec->uid) { - expunges++; - seq++; - } - i_assert(*expunges != rec->uid); - - if (seq > seq2) - break; - - t_push(); - if (!func(index, rec, seq, context)) { - t_pop(); - return 0; - } - t_pop(); - - rec = index->next(index, rec); - } - - if (rec == NULL && index->get_last_error(index) != NULL) { - /* error occured */ - return -1; - } - - return !expunges_found && seq > seq2 ? 1 : 2; -} - -int mail_index_messageset_foreach(MailIndex *index, const char *messageset, - unsigned int messages_count, - MsgsetForeachFunc func, void *context, - const char **error) -{ - const char *input; - unsigned int seq, seq2; - int ret, all_found; - - i_assert(index->lock_type != MAIL_LOCK_UNLOCK); - - *error = NULL; - if (messages_count == 0) { - /* no messages in mailbox */ - return 1; - } - - all_found = TRUE; - input = messageset; - while (*input != '\0') { - if (*input == '*') { - /* last message */ - seq = messages_count; - input++; - } else { - seq = get_next_number(&input); - if (seq == 0) { - *error = t_strconcat("Invalid messageset: ", - messageset, NULL); - return -2; - } - } - - if (*input != ':') - seq2 = seq; - else { - /* first:last range */ - input++; - - if (*input != '*') { - seq2 = get_next_number(&input); - if (seq2 == 0) { - *error = t_strconcat("Invalid " - "messageset: ", - messageset, NULL); - return -2; - } - - if (seq2 > messages_count) { - /* too large .. ignore silently */ - seq2 = messages_count; - } - } else { - seq2 = messages_count; - input++; - } - } - - if (*input == ',') - input++; - else if (*input != '\0') { - *error = t_strdup_printf("Unexpected char '%c' " - "with messageset: %s", - *input, messageset); - return -2; - } - - if (seq > messages_count) { - /* too large .. ignore silently */ - } else { - ret = mail_index_foreach(index, seq, seq2, - func, context, error); - if (ret <= 0) - return ret; - if (ret == 2) - all_found = FALSE; - } - } - - return all_found ? 1 : 2; -} - -static int mail_index_uid_foreach(MailIndex *index, - unsigned int uid, unsigned int uid2, - MsgsetForeachFunc func, void *context, - const char **error) -{ - MailIndexRecord *rec; - const unsigned int *expunges; - unsigned int seq; - int expunges_found; - - if (uid > uid2) { - /* not allowed - see mail_index_foreach() */ - *error = t_strdup_printf("Invalid uidset range: %u > %u", - uid, uid2); - return -2; - } - - /* get list of expunged messages in our range. */ - expunges = mail_modifylog_uid_get_expunges(index->modifylog, uid, uid2); - expunges_found = *expunges != '\0'; - - /* skip expunged messages at the beginning */ - while (*expunges == uid) { - expunges++; - - if (uid++ == uid2) { - /* all were expunged */ - return 2; - } - } - - rec = index->lookup_uid_range(index, uid, uid2); - if (rec == NULL) - return expunges_found ? 2 : 1; - - seq = index->get_sequence(index, rec); - while (rec != NULL && rec->uid <= uid2) { - uid = rec->uid; - while (*expunges != 0 && *expunges < rec->uid) { - expunges++; - seq++; - } - i_assert(*expunges != rec->uid); - - t_push(); - if (!func(index, rec, seq, context)) { - t_pop(); - return 0; - } - t_pop(); - - seq++; - rec = index->next(index, rec); - } - - if (rec == NULL && index->get_last_error(index) != NULL) { - /* error occured */ - return -1; - } - - return expunges_found ? 2 : 1; -} - -int mail_index_uidset_foreach(MailIndex *index, const char *uidset, - unsigned int messages_count, - MsgsetForeachFunc func, void *context, - const char **error) -{ - MailIndexRecord *rec; - const char *input; - unsigned int uid, uid2; - int ret, all_found; - - i_assert(index->lock_type != MAIL_LOCK_UNLOCK); - - *error = NULL; - if (messages_count == 0) { - /* no messages in mailbox */ - return 1; - } - - all_found = TRUE; - input = uidset; - while (*input != '\0') { - if (*input == '*') { - /* last message */ - rec = index->lookup(index, messages_count); - uid = rec == NULL ? 0 : rec->uid; - input++; - } else { - uid = get_next_number(&input); - if (uid == 0) { - *error = t_strconcat("Invalid uidset: ", - uidset, NULL); - return -2; - } - } - - if (*input != ':') - uid2 = uid; - else { - /* first:last range */ - input++; - - if (*input != '*') { - uid2 = get_next_number(&input); - if (uid2 == 0) { - *error = t_strconcat("Invalid uidset: ", - uidset, NULL); - return -2; - } - } else { - uid2 = index->header->next_uid-1; - input++; - } - } - - if (*input == ',') - input++; - else if (*input != '\0') { - *error = t_strdup_printf("Unexpected char '%c' with " - "uidset: %s", *input, uidset); - return -2; - } - - if (uid >= index->header->next_uid) { - /* too large .. ignore silently */ - } else { - ret = mail_index_uid_foreach(index, uid, uid2, - func, context, error); - if (ret <= 0) - return ret; - if (ret == 2) - all_found = FALSE; - } - } - - return all_found ? 1 : 2; -}
--- a/src/lib-index/mail-messageset.h Sat Sep 07 04:46:07 2002 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -#ifndef __MAIL_MESSAGESET_H -#define __MAIL_MESSAGESET_H - -#include "mail-index.h" - -/* If FALSE is returned, the loop is stopped. */ -typedef int (*MsgsetForeachFunc)(MailIndex *index, MailIndexRecord *rec, - unsigned int seq, void *context); - -/* Returns -1 if internal error occured, -2 if messageset was invalid - (sets error), 0 if foreach-func returned FALSE, 1 if everything was ok - or 2 if some of the given sequences were expunged */ -int mail_index_messageset_foreach(MailIndex *index, const char *messageset, - unsigned int messages_count, - MsgsetForeachFunc func, void *context, - const char **error); - -/* Like messageset_foreach() but for UIDs. */ -int mail_index_uidset_foreach(MailIndex *index, const char *uidset, - unsigned int messages_count, - MsgsetForeachFunc func, void *context, - const char **error); - -#endif
--- a/src/lib-storage/index/Makefile.am Sat Sep 07 04:46:07 2002 +0300 +++ b/src/lib-storage/index/Makefile.am Sat Sep 07 04:52:21 2002 +0300 @@ -14,6 +14,7 @@ index-expunge.c \ index-fetch.c \ index-fetch-section.c \ + index-messageset.c \ index-msgcache.c \ index-save.c \ index-search.c \
--- a/src/lib-storage/index/index-copy.c Sat Sep 07 04:46:07 2002 +0300 +++ b/src/lib-storage/index/index-copy.c Sat Sep 07 04:52:21 2002 +0300 @@ -3,7 +3,7 @@ #include "lib.h" #include "iobuffer.h" #include "index-storage.h" -#include "mail-messageset.h" +#include "index-messageset.h" #include <unistd.h>
--- a/src/lib-storage/index/index-fetch.c Sat Sep 07 04:46:07 2002 +0300 +++ b/src/lib-storage/index/index-fetch.c Sat Sep 07 04:52:21 2002 +0300 @@ -5,7 +5,7 @@ #include "temp-string.h" #include "index-storage.h" #include "index-fetch.h" -#include "mail-messageset.h" +#include "index-messageset.h" #include "message-send.h" #include "imap-date.h" #include "imap-util.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-storage/index/index-messageset.c Sat Sep 07 04:52:21 2002 +0300 @@ -0,0 +1,340 @@ +/* Copyright (C) 2002 Timo Sirainen */ + +#include "lib.h" +#include "mail-index.h" +#include "mail-index-util.h" +#include "mail-hash.h" +#include "mail-modifylog.h" +#include "index-messageset.h" + +static unsigned int get_next_number(const char **str) +{ + unsigned int num; + + num = 0; + while (**str != '\0') { + if (**str < '0' || **str > '9') + break; + + num = num*10 + (**str - '0'); + (*str)++; + } + + return num; +} + +static int mail_index_foreach(MailIndex *index, + unsigned int seq, unsigned int seq2, + MsgsetForeachFunc func, void *context, + const char **error) +{ + MailIndexRecord *rec; + const unsigned int *expunges; + unsigned int expunges_before; + int expunges_found; + + if (seq > seq2) { + /* Second sequence can't be smaller than first - we could swap + them but I think it's a bug in client if it does this, + and better complain about it immediately than later let + them wonder why it doesn't work with other imapds.. */ + *error = t_strdup_printf("Invalid messageset range: %u > %u", + seq, seq2); + return -2; + } + + /* get list of expunged messages in our range. the expunges_before + can be used to calculate the current real sequence position */ + expunges = mail_modifylog_seq_get_expunges(index->modifylog, seq, seq2, + &expunges_before); + i_assert(expunges_before < seq); + expunges_found = *expunges != '\0'; + + /* Reset index errors, since we later rely on it to check if failed */ + index_reset_error(index); + + /* get the first non-expunged message. note that if all messages + were expunged in the range, this points outside wanted range. */ + rec = index->lookup(index, seq - expunges_before); + for (; rec != NULL; seq++) { + /* skip expunged sequences */ + i_assert(rec->uid != 0); + + while (*expunges != 0 && *expunges < rec->uid) { + expunges++; + seq++; + } + i_assert(*expunges != rec->uid); + + if (seq > seq2) + break; + + t_push(); + if (!func(index, rec, seq, context)) { + t_pop(); + return 0; + } + t_pop(); + + rec = index->next(index, rec); + } + + if (rec == NULL && index->get_last_error(index) != NULL) { + /* error occured */ + return -1; + } + + return !expunges_found && seq > seq2 ? 1 : 2; +} + +static int mail_index_messageset_foreach(MailIndex *index, + const char *messageset, + unsigned int messages_count, + MsgsetForeachFunc func, void *context, + const char **error) +{ + const char *input; + unsigned int seq, seq2; + int ret, all_found; + + i_assert(index->lock_type != MAIL_LOCK_UNLOCK); + + *error = NULL; + if (messages_count == 0) { + /* no messages in mailbox */ + return 1; + } + + all_found = TRUE; + input = messageset; + while (*input != '\0') { + if (*input == '*') { + /* last message */ + seq = messages_count; + input++; + } else { + seq = get_next_number(&input); + if (seq == 0) { + *error = t_strconcat("Invalid messageset: ", + messageset, NULL); + return -2; + } + } + + if (*input != ':') + seq2 = seq; + else { + /* first:last range */ + input++; + + if (*input != '*') { + seq2 = get_next_number(&input); + if (seq2 == 0) { + *error = t_strconcat("Invalid " + "messageset: ", + messageset, NULL); + return -2; + } + + if (seq2 > messages_count) { + /* too large .. ignore silently */ + seq2 = messages_count; + } + } else { + seq2 = messages_count; + input++; + } + } + + if (*input == ',') + input++; + else if (*input != '\0') { + *error = t_strdup_printf("Unexpected char '%c' " + "with messageset: %s", + *input, messageset); + return -2; + } + + if (seq > messages_count) { + /* too large .. ignore silently */ + } else { + ret = mail_index_foreach(index, seq, seq2, + func, context, error); + if (ret <= 0) + return ret; + if (ret == 2) + all_found = FALSE; + } + } + + return all_found ? 1 : 2; +} + +static int mail_index_uid_foreach(MailIndex *index, + unsigned int uid, unsigned int uid2, + MsgsetForeachFunc func, void *context, + const char **error) +{ + MailIndexRecord *rec; + const unsigned int *expunges; + unsigned int seq; + int expunges_found; + + if (uid > uid2) { + /* not allowed - see mail_index_foreach() */ + *error = t_strdup_printf("Invalid uidset range: %u > %u", + uid, uid2); + return -2; + } + + /* get list of expunged messages in our range. */ + expunges = mail_modifylog_uid_get_expunges(index->modifylog, uid, uid2); + expunges_found = *expunges != '\0'; + + /* skip expunged messages at the beginning */ + while (*expunges == uid) { + expunges++; + + if (uid++ == uid2) { + /* all were expunged */ + return 2; + } + } + + rec = index->lookup_uid_range(index, uid, uid2); + if (rec == NULL) + return expunges_found ? 2 : 1; + + seq = index->get_sequence(index, rec); + while (rec != NULL && rec->uid <= uid2) { + uid = rec->uid; + while (*expunges != 0 && *expunges < rec->uid) { + expunges++; + seq++; + } + i_assert(*expunges != rec->uid); + + t_push(); + if (!func(index, rec, seq, context)) { + t_pop(); + return 0; + } + t_pop(); + + seq++; + rec = index->next(index, rec); + } + + if (rec == NULL && index->get_last_error(index) != NULL) { + /* error occured */ + return -1; + } + + return expunges_found ? 2 : 1; +} + +static int mail_index_uidset_foreach(MailIndex *index, const char *uidset, + unsigned int messages_count, + MsgsetForeachFunc func, void *context, + const char **error) +{ + MailIndexRecord *rec; + const char *input; + unsigned int uid, uid2; + int ret, all_found; + + i_assert(index->lock_type != MAIL_LOCK_UNLOCK); + + *error = NULL; + if (messages_count == 0) { + /* no messages in mailbox */ + return 1; + } + + all_found = TRUE; + input = uidset; + while (*input != '\0') { + if (*input == '*') { + /* last message */ + rec = index->lookup(index, messages_count); + uid = rec == NULL ? 0 : rec->uid; + input++; + } else { + uid = get_next_number(&input); + if (uid == 0) { + *error = t_strconcat("Invalid uidset: ", + uidset, NULL); + return -2; + } + } + + if (*input != ':') + uid2 = uid; + else { + /* first:last range */ + input++; + + if (*input != '*') { + uid2 = get_next_number(&input); + if (uid2 == 0) { + *error = t_strconcat("Invalid uidset: ", + uidset, NULL); + return -2; + } + } else { + uid2 = index->header->next_uid-1; + input++; + } + } + + if (*input == ',') + input++; + else if (*input != '\0') { + *error = t_strdup_printf("Unexpected char '%c' with " + "uidset: %s", *input, uidset); + return -2; + } + + if (uid >= index->header->next_uid) { + /* too large .. ignore silently */ + } else { + ret = mail_index_uid_foreach(index, uid, uid2, + func, context, error); + if (ret <= 0) + return ret; + if (ret == 2) + all_found = FALSE; + } + } + + return all_found ? 1 : 2; +} + +int index_messageset_foreach(IndexMailbox *ibox, + const char *messageset, int uidset, + MsgsetForeachFunc func, void *context) +{ + const char *error; + int ret; + + if (uidset) { + ret = mail_index_uidset_foreach(ibox->index, messageset, + ibox->synced_messages_count, + func, context, &error); + } else { + ret = mail_index_messageset_foreach(ibox->index, messageset, + ibox->synced_messages_count, + func, context, &error); + } + + if (ret < 0) { + if (ret == -2) { + /* user error */ + mail_storage_set_error(ibox->box.storage, "%s", error); + } else { + mail_storage_set_index_error(ibox); + } + } + + return ret; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-storage/index/index-messageset.h Sat Sep 07 04:52:21 2002 +0300 @@ -0,0 +1,14 @@ +#ifndef __INDEX_MESSAGESET_H +#define __INDEX_MESSAGESET_H + +#include "index-storage.h" + +/* If FALSE is returned, the loop is stopped. */ +typedef int (*MsgsetForeachFunc)(MailIndex *index, MailIndexRecord *rec, + unsigned int seq, void *context); + +int index_messageset_foreach(IndexMailbox *ibox, + const char *messageset, int uidset, + MsgsetForeachFunc func, void *context); + +#endif
--- a/src/lib-storage/index/index-storage.c Sat Sep 07 04:46:07 2002 +0300 +++ b/src/lib-storage/index/index-storage.c Sat Sep 07 04:52:21 2002 +0300 @@ -64,36 +64,6 @@ return FALSE; } -int index_messageset_foreach(IndexMailbox *ibox, - const char *messageset, int uidset, - MsgsetForeachFunc func, void *context) -{ - const char *error; - int ret; - - if (uidset) { - ret = mail_index_uidset_foreach(ibox->index, messageset, - ibox->synced_messages_count, - func, context, &error); - } else { - ret = mail_index_messageset_foreach(ibox->index, messageset, - ibox->synced_messages_count, - func, context, &error); - } - - if (ret < 0) { - if (ret == -2) { - /* user error */ - mail_storage_set_error(ibox->box.storage, "%s", error); - } else { - mail_storage_set_index_error(ibox); - } - } - - return ret; -} - - static MailFlags get_used_flags(void *context) { IndexMailbox *ibox = context;
--- a/src/lib-storage/index/index-storage.h Sat Sep 07 04:46:07 2002 +0300 +++ b/src/lib-storage/index/index-storage.h Sat Sep 07 04:52:21 2002 +0300 @@ -2,7 +2,6 @@ #define __INDEX_STORAGE_H #include "mail-storage.h" -#include "mail-messageset.h" #include "mail-index.h" #include "imap-message-cache.h" #include "flags-file/flags-file.h" @@ -32,10 +31,6 @@ int mail_storage_set_index_error(IndexMailbox *ibox); -int index_messageset_foreach(IndexMailbox *ibox, - const char *messageset, int uidset, - MsgsetForeachFunc func, void *context); - int index_mailbox_fix_custom_flags(IndexMailbox *ibox, MailFlags *flags, const char *custom_flags[]);
--- a/src/lib-storage/index/index-update-flags.c Sat Sep 07 04:46:07 2002 +0300 +++ b/src/lib-storage/index/index-update-flags.c Sat Sep 07 04:52:21 2002 +0300 @@ -2,7 +2,7 @@ #include "lib.h" #include "index-storage.h" -#include "mail-messageset.h" +#include "index-messageset.h" typedef struct { Mailbox *box;
--- a/src/lib-storage/index/maildir/maildir-copy.c Sat Sep 07 04:46:07 2002 +0300 +++ b/src/lib-storage/index/maildir/maildir-copy.c Sat Sep 07 04:52:21 2002 +0300 @@ -1,7 +1,7 @@ /* Copyright (C) 2002 Timo Sirainen */ #include "lib.h" -#include "mail-messageset.h" +#include "index-messageset.h" #include "maildir-storage.h" #include <stdlib.h>