# HG changeset patch # User Timo Sirainen # Date 1118327503 -10800 # Node ID b0bdf32564b71234d97cea2a758ea02c0a66be7f # Parent 27312b7941e998fb51baab1710e7cba6eb583181 Replaced ':' and ',' character usages with #defines, so they can be changed easily if needed. diff -r 27312b7941e9 -r b0bdf32564b7 src/lib-storage/index/maildir/maildir-mail.c --- a/src/lib-storage/index/maildir/maildir-mail.c Thu Jun 09 16:44:53 2005 +0300 +++ b/src/lib-storage/index/maildir/maildir-mail.c Thu Jun 09 17:31:43 2005 +0300 @@ -129,7 +129,7 @@ return (uoff_t)-1; /* size can be included in filename */ - p = strstr(fname, ",W="); + p = strstr(fname, MAILDIR_EXTRA_SEP_S"W="); if (p != NULL) { p += 3; virtual_size = 0; @@ -138,7 +138,8 @@ p++; } - if (*p == ':' || *p == ',' || *p == '\0') { + if (*p == MAILDIR_INFO_SEP || *p == MAILDIR_EXTRA_SEP || + *p == '\0') { mail_cache_add(mail->trans->cache_trans, mail->data.seq, MAIL_CACHE_VIRTUAL_FULL_SIZE, &virtual_size, sizeof(virtual_size)); @@ -160,7 +161,7 @@ if (field == MAIL_FETCH_UIDL_FILE_NAME) { fname = maildir_uidlist_lookup(mbox->uidlist, mail->mail.mail.uid, &flags); - end = strchr(fname, ':'); + end = strchr(fname, MAILDIR_INFO_SEP); return end == NULL ? fname : t_strdup_until(fname, end); } @@ -187,7 +188,7 @@ return (uoff_t)-1; /* size can be included in filename */ - p = strstr(fname, ",S="); + p = strstr(fname, MAILDIR_EXTRA_SEP_S"S="); if (p != NULL) { p += 3; size = 0; @@ -196,7 +197,8 @@ p++; } - if (*p != ':' && *p != ',' && *p != '\0') + if (*p != MAILDIR_INFO_SEP && + *p != MAILDIR_EXTRA_SEP && *p != '\0') size = (uoff_t)-1; } diff -r 27312b7941e9 -r b0bdf32564b7 src/lib-storage/index/maildir/maildir-storage.c --- a/src/lib-storage/index/maildir/maildir-storage.c Thu Jun 09 16:44:53 2005 +0300 +++ b/src/lib-storage/index/maildir/maildir-storage.c Thu Jun 09 17:31:43 2005 +0300 @@ -266,15 +266,33 @@ static const char *maildir_get_control_path(struct maildir_storage *storage, const char *name) { + const char *default_path, *path, *default_uidlist; + struct stat st; + + default_path = maildir_get_path(INDEX_STORAGE(storage), name); if (storage->control_dir == NULL) - return maildir_get_path(INDEX_STORAGE(storage), name); + return default_path; if ((STORAGE(storage)->flags & MAIL_STORAGE_FLAG_FULL_FS_ACCESS) != 0 && (*name == '/' || *name == '~')) - return maildir_get_absolute_path(name, FALSE); + path = maildir_get_absolute_path(name, FALSE); + else { + path = t_strconcat(storage->control_dir, "/"MAILDIR_FS_SEP_S, + name, NULL); + } - return t_strconcat(storage->control_dir, "/"MAILDIR_FS_SEP_S, - name, NULL); + default_uidlist = + t_strconcat(default_path, "/" MAILDIR_UIDLIST_NAME, NULL); + if (stat(default_uidlist, &st) == 0) { + const char *dest_uidlist = + t_strconcat(path, "/" MAILDIR_UIDLIST_NAME, NULL); + + if (rename(default_uidlist, dest_uidlist) < 0) { + i_error("rename(%s, %s) failed: %m", + default_uidlist, dest_uidlist); + } + } + return path; } static int mkdir_verify(struct index_storage *storage, diff -r 27312b7941e9 -r b0bdf32564b7 src/lib-storage/index/maildir/maildir-storage.h --- a/src/lib-storage/index/maildir/maildir-storage.h Thu Jun 09 16:44:53 2005 +0300 +++ b/src/lib-storage/index/maildir/maildir-storage.h Thu Jun 09 17:31:43 2005 +0300 @@ -8,6 +8,19 @@ #define SUBSCRIPTION_FILE_NAME "subscriptions" #define MAILDIR_INDEX_PREFIX "dovecot.index" +/* "base,S=123:2," means: + [ [..]] 2 */ +#define MAILDIR_INFO_SEP ':' +#define MAILDIR_EXTRA_SEP ',' +#define MAILDIR_FLAGS_SEP ',' + +#define MAILDIR_INFO_SEP_S ":" +#define MAILDIR_EXTRA_SEP_S "," +#define MAILDIR_FLAGS_SEP_S "," + +/* ":2," is the standard flags separator */ +#define MAILDIR_FLAGS_FULL_SEP MAILDIR_INFO_SEP_S "2" MAILDIR_FLAGS_SEP_S + #include "index-storage.h" #define STORAGE(maildir_storage) \ diff -r 27312b7941e9 -r b0bdf32564b7 src/lib-storage/index/maildir/maildir-sync.c --- a/src/lib-storage/index/maildir/maildir-sync.c Thu Jun 09 16:44:53 2005 +0300 +++ b/src/lib-storage/index/maildir/maildir-sync.c Thu Jun 09 17:31:43 2005 +0300 @@ -461,8 +461,9 @@ str_truncate(dest, 0); str_printfa(src, "%s/%s", ctx->new_dir, dp->d_name); str_printfa(dest, "%s/%s", ctx->cur_dir, dp->d_name); - if (strchr(dp->d_name, ':') == NULL) - str_append(dest, ":2,"); + if (strchr(dp->d_name, MAILDIR_INFO_SEP) == NULL) { + str_append(dest, MAILDIR_FLAGS_FULL_SEP); + } if (rename(str_c(src), str_c(dest)) == 0) { /* we moved it - it's \Recent for us */ ctx->mbox->dirty_cur_time = ioloop_time; diff -r 27312b7941e9 -r b0bdf32564b7 src/lib-storage/index/maildir/maildir-util.c --- a/src/lib-storage/index/maildir/maildir-util.c Thu Jun 09 16:44:53 2005 +0300 +++ b/src/lib-storage/index/maildir/maildir-util.c Thu Jun 09 17:31:43 2005 +0300 @@ -73,11 +73,11 @@ *flags_r = 0; *keywords_r = NULL; - info = strchr(fname, ':'); - if (info == NULL || info[1] != '2' || info[2] != ',') + info = strchr(fname, MAILDIR_INFO_SEP); + if (info == NULL || info[1] != '2' || info[2] != MAILDIR_FLAGS_SEP) return 0; - for (info += 3; *info != '\0' && *info != ','; info++) { + for (info += 3; *info != '\0' && *info != MAILDIR_FLAGS_SEP; info++) { switch (*info) { case 'R': /* replied */ *flags_r |= MAIL_ANSWERED; @@ -118,14 +118,14 @@ int nextflag; /* remove the old :info from file name, and get the old flags */ - info = strrchr(fname, ':'); + info = strrchr(fname, MAILDIR_INFO_SEP); if (info != NULL && strrchr(fname, '/') > info) info = NULL; oldflags = ""; if (info != NULL) { fname = t_strdup_until(fname, info); - if (info[1] == '2' && info[2] == ',') + if (info[1] == '2' && info[2] == MAILDIR_FLAGS_SEP) oldflags = info+3; } @@ -133,7 +133,7 @@ their ASCII code. unknown flags are kept. */ flags_str = t_str_new(256); str_append(flags_str, fname); - str_append(flags_str, ":2,"); + str_append(flags_str, MAILDIR_FLAGS_FULL_SEP); flags_left = flags; for (;;) { /* skip all known flags */ @@ -143,8 +143,8 @@ (*oldflags >= 'a' && *oldflags <= 'z')) oldflags++; - nextflag = *oldflags == '\0' || *oldflags == ',' ? 256 : - (unsigned char) *oldflags; + nextflag = *oldflags == '\0' || *oldflags == MAILDIR_FLAGS_SEP ? + 256 : (unsigned char) *oldflags; if ((flags_left & MAIL_DRAFT) && nextflag > 'D') { str_append_c(flags_str, 'D'); @@ -171,14 +171,14 @@ // FIXME } - if (*oldflags == '\0' || *oldflags == ',') + if (*oldflags == '\0' || *oldflags == MAILDIR_FLAGS_SEP) break; str_append_c(flags_str, *oldflags); oldflags++; } - if (*oldflags == ',') { + if (*oldflags == MAILDIR_FLAGS_SEP) { /* another flagset, we don't know about these, just keep them */ while (*oldflags != '\0') str_append_c(flags_str, *oldflags++); @@ -262,7 +262,7 @@ const unsigned char *s = p; unsigned int g, h = 0; - while (*s != ':' && *s != '\0') { + while (*s != MAILDIR_INFO_SEP && *s != '\0') { h = (h << 4) + *s; if ((g = h & 0xf0000000UL)) { h = h ^ (g >> 24); @@ -279,11 +279,11 @@ { const char *s1 = p1, *s2 = p2; - while (*s1 == *s2 && *s1 != ':' && *s1 != '\0') { + while (*s1 == *s2 && *s1 != MAILDIR_INFO_SEP && *s1 != '\0') { s1++; s2++; } - if ((*s1 == '\0' || *s1 == ':') && - (*s2 == '\0' || *s2 == ':')) + if ((*s1 == '\0' || *s1 == MAILDIR_INFO_SEP) && + (*s2 == '\0' || *s2 == MAILDIR_INFO_SEP)) return 0; return *s1 - *s2; }