maildir-index.c revision db1ee4a91a6572602302115e02146b29adea3a54
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
f0d93763f210ecdb85a115fdd0210a16cfc5ff5cTimo Sirainenstatic int maildir_index_open(struct mail_index *index,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen maildir_clean_tmp(t_strconcat(index->mailbox_path, "/tmp", NULL));
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenconst char *maildir_get_location(struct mail_index *index,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen fname = index->lookup_field(index, rec, DATA_FIELD_LOCATION);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Missing location field for record %u", rec->uid);
660b99a7059824676b2b8d6f79b8e15d47df25a2Timo Sirainen new_fname = hash_lookup(index->new_filenames, fname);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenconst char *maildir_generate_tmp_filename(const struct timeval *tv)
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen static unsigned int create_count = 0;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenint maildir_create_tmp(struct mail_index *index, const char *dir,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const char **fname)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen pool = pool_alloconly_create("maildir_tmp", 4096);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen tmp_fname = maildir_generate_tmp_filename(tv);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen path = p_strconcat(pool, dir, "/", tmp_fname, NULL);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* doesn't exist */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* wait and try again - very unlikely */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen index_file_set_syscall_error(index, path, "open()");
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenenum mail_flags maildir_filename_get_flags(const char *fname,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (info == NULL || info[1] != '2' || info[2] != ',')
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen for (info += 3; *info != '\0' && *info != ','; info++) {
1bf5c6c20f3d51f13d3240cfb46e471074c86276Timo Sirainen /* custom flag */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* unknown flag - ignore */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenconst char *maildir_filename_set_flags(const char *fname, enum mail_flags flags)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* remove the old :info from file name, and get the old flags */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (info != NULL && strrchr(fname, '/') > info)
b8afdaa1bffe2f27cd4b02bf3bfbd2d297c8e648Timo Sirainen /* insert the new flags between old flags. flags must be sorted by
b8afdaa1bffe2f27cd4b02bf3bfbd2d297c8e648Timo Sirainen their ASCII code. unknown flags are kept. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* skip all known flags */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen while (*oldflags == 'D' || *oldflags == 'F' ||
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen nextflag = *oldflags == '\0' || *oldflags == ',' ? 256 :
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen (unsigned char) *oldflags;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if ((flags & MAIL_FLAGGED) && nextflag > 'F') {
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen if ((flags & MAIL_ANSWERED) && nextflag > 'R') {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if ((flags & MAIL_DELETED) && nextflag > 'T') {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if ((flags & MAIL_CUSTOM_FLAGS_MASK) && nextflag > 'a') {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (flags & (1 << (i + MAIL_CUSTOM_FLAG_1_BIT)))
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainen /* another flagset, we don't know about these, just keep them */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmaildir_index_alloc(const char *maildir, const char *index_dir,
75e46142d8fbac811df8f2ca58d9a2f48a75d65fTimo Sirainen memcpy(index, &maildir_index, sizeof(struct mail_index));
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstatic void maildir_index_free(struct mail_index *index)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstatic time_t maildir_get_internal_date(struct mail_index *index,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* try getting it from cache */
75e46142d8fbac811df8f2ca58d9a2f48a75d65fTimo Sirainen /* stat() gives it */