Mercurial > dovecot > original-hg > dovecot-1.2
changeset 180:38341ad6a9db HEAD
partial changes to add X-IMAPbase parser update custom flags
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 08 Sep 2002 15:12:41 +0300 |
parents | 0ffecd4e7e1a |
children | f1bdcf3448f6 |
files | src/lib-index/mail-custom-flags.c src/lib-index/mbox/mbox-append.c src/lib-index/mbox/mbox-fsck.c src/lib-index/mbox/mbox-index.c src/lib-index/mbox/mbox-index.h src/lib-index/mbox/mbox-rewrite.c |
diffstat | 6 files changed, 54 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-custom-flags.c Sun Sep 08 14:36:03 2002 +0300 +++ b/src/lib-index/mail-custom-flags.c Sun Sep 08 15:12:41 2002 +0300 @@ -460,8 +460,10 @@ /* unlock + write lock, don't directly change from read -> write lock to prevent deadlocking */ - if (!lock_file(mcf, F_UNLCK) || !lock_file(mcf, F_WRLCK)) - return -1; + if (mcf->lock_type != F_WRLCK) { + if (!lock_file(mcf, F_UNLCK) || !lock_file(mcf, F_WRLCK)) + return -1; + } /* new flag, add it. first find the first free flag, note that unlock+lock might have just changed it. */ @@ -490,6 +492,8 @@ MailFlags oldflags, flag; int i, idx; + i_assert(mcf->custom_flags_refcount == 0); + if ((*flags & MAIL_CUSTOM_FLAGS_MASK) == 0) return 1;
--- a/src/lib-index/mbox/mbox-append.c Sun Sep 08 14:36:03 2002 +0300 +++ b/src/lib-index/mbox/mbox-append.c Sun Sep 08 15:12:41 2002 +0300 @@ -134,7 +134,7 @@ from Status and X-Status fields. temporarily limit the buffer size so the message body is parsed properly (FIXME: does this have side effects?) */ - mbox_header_init_context(&ctx); + mbox_header_init_context(&ctx, index); old_size = inbuf->size; inbuf->size = stop_offset;
--- a/src/lib-index/mbox/mbox-fsck.c Sun Sep 08 14:36:03 2002 +0300 +++ b/src/lib-index/mbox/mbox-fsck.c Sun Sep 08 15:12:41 2002 +0300 @@ -132,7 +132,7 @@ /* get the MD5 sum of fixed headers and the current message flags in Status and X-Status fields */ - mbox_header_init_context(&ctx); + mbox_header_init_context(&ctx, index); message_parse_header(NULL, inbuf, &hdr_size, mbox_header_func, &ctx); md5_final(&ctx.md5, current_digest);
--- a/src/lib-index/mbox/mbox-index.c Sun Sep 08 14:36:03 2002 +0300 +++ b/src/lib-index/mbox/mbox-index.c Sun Sep 08 15:12:41 2002 +0300 @@ -5,13 +5,17 @@ #include "rfc822-tokenize.h" #include "mbox-index.h" #include "mail-index-util.h" +#include "mail-custom-flags.h" static MailIndex mbox_index; -void mbox_header_init_context(MboxHeaderContext *ctx) +void mbox_header_init_context(MboxHeaderContext *ctx, MailIndex *index) { memset(ctx, 0, sizeof(MboxHeaderContext)); md5_init(&ctx->md5); + + ctx->index = index; + ctx->custom_flags = mail_custom_flags_list_get(index->custom_flags); } static MailFlags mbox_get_status_flags(const char *value, unsigned int len) @@ -65,11 +69,33 @@ return flags; } -static void -mbox_get_custom_flags_list(const char *value, unsigned int len, - const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT]) +static void mbox_parse_imapbase(const char *value, unsigned int len, + MboxHeaderContext *ctx) { + unsigned int i, spaces; + + /* skip <uid validity> and <last uid> fields */ + spaces = 0; + for (i = 0; i < len; i++) { + if (value[i] == ' ' && (i == 0 || value[i-1] != ' ')) { + if (++spaces == 2) + break; + } + } + + while (i < len && value[i] == ' ') i++; + + if (i == len) + return; + + /* we're at the 3rd field now, which begins the list of custom flags */ + + /* FIXME */ + mail_custom_flags_list_unref(ctx->index->custom_flags); + + ctx->custom_flags = + mail_custom_flags_list_get(ctx->index->custom_flags); } void mbox_header_func(MessagePart *part __attr_unused__, @@ -140,8 +166,7 @@ } else if (name_len == 10 && strncasecmp(name, "X-IMAPbase", 10) == 0) { /* update list of custom message flags */ - mbox_get_custom_flags_list(value, value_len, - ctx->custom_flags); + mbox_parse_imapbase(value, value_len, ctx); } break; }
--- a/src/lib-index/mbox/mbox-index.h Sun Sep 08 14:36:03 2002 +0300 +++ b/src/lib-index/mbox/mbox-index.h Sun Sep 08 15:12:41 2002 +0300 @@ -5,15 +5,16 @@ #include "mail-index.h" typedef struct { + MailIndex *index; MailFlags flags; + const char **custom_flags; MD5Context md5; int received; - const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT]; } MboxHeaderContext; MailIndex *mbox_index_alloc(const char *dir, const char *mbox_path); -void mbox_header_init_context(MboxHeaderContext *ctx); +void mbox_header_init_context(MboxHeaderContext *ctx, MailIndex *index); void mbox_header_func(MessagePart *part __attr_unused__, const char *name, unsigned int name_len, const char *value, unsigned int value_len, @@ -36,7 +37,6 @@ time_t mbox_from_parse_date(const char *msg, unsigned int size); const char *mbox_from_create(const char *sender, time_t time); -int mbox_index_rewrite(MailIndex *index, - const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT]); +int mbox_index_rewrite(MailIndex *index); #endif
--- a/src/lib-index/mbox/mbox-rewrite.c Sun Sep 08 14:36:03 2002 +0300 +++ b/src/lib-index/mbox/mbox-rewrite.c Sun Sep 08 15:12:41 2002 +0300 @@ -6,6 +6,7 @@ #include "write-full.h" #include "mbox-index.h" #include "mail-index-util.h" +#include "mail-custom-flags.h" #include <stdio.h> #include <stdlib.h> @@ -145,8 +146,7 @@ static int mbox_write_header(MailIndex *index, MailIndexRecord *rec, unsigned int seq, IOBuffer *inbuf, IOBuffer *outbuf, - uoff_t end_offset, - const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT]) + uoff_t end_offset) { /* We need to update fields that define message flags. Standard fields are stored in Status and X-Status. For custom flags we use @@ -161,7 +161,7 @@ */ MboxRewriteContext ctx; MessageSize hdr_size; - const char *str, *flags; + const char *str, *flags, **custom_flags; unsigned int field; int i; @@ -173,6 +173,10 @@ return FALSE; } + t_push(); + + custom_flags = mail_custom_flags_list_get(index->custom_flags); + /* parse the header, write the fields we don't want to change */ memset(&ctx, 0, sizeof(ctx)); ctx.outbuf = outbuf; @@ -180,8 +184,6 @@ ctx.msg_flags = rec->msg_flags; ctx.custom_flags = custom_flags; - t_push(); - message_parse_header(NULL, inbuf, &hdr_size, header_func, &ctx); i_assert(hdr_size.physical_size == rec->header_size); @@ -250,14 +252,15 @@ } t_pop(); + mail_custom_flags_list_unref(index->custom_flags); + /* empty line ends headers */ (void)io_buffer_send(outbuf, "\n", 1); return TRUE; } -int mbox_index_rewrite(MailIndex *index, - const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT]) +int mbox_index_rewrite(MailIndex *index) { /* Write it to temp file and then rename() to real file. easier and much safer than moving data inside the file. @@ -330,7 +333,7 @@ /* write header, updating flag fields */ offset += rec->header_size; if (!mbox_write_header(index, rec, seq, inbuf, outbuf, - offset, custom_flags)) { + offset)) { failed = TRUE; break; }