maildir-index.c revision 934d42dec29def3fc2b070932f2a7247ec2eea8a
76b43e4417bab52e913da39b5f5bc2a130d3f149Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainenstatic int maildir_index_open(struct mail_index *index,
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen maildir_clean_tmp(t_strconcat(index->mailbox_path, "/tmp", NULL));
c8b5a21a139992e66b4ad02adb69eaf929b3d024Timo Sirainenconst char *maildir_get_location(struct mail_index *index,
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen fname = index->lookup_field(index, rec, DATA_FIELD_LOCATION);
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen "Missing location field for record %u", rec->uid);
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainenconst char *maildir_generate_tmp_filename(const struct timeval *tv)
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen static unsigned int create_count = 0;
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainenint maildir_create_tmp(struct mail_index *index, const char *dir,
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen const char **fname)
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen pool = pool_alloconly_create("maildir_tmp", 4096);
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen tmp_fname = maildir_generate_tmp_filename(tv);
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen path = p_strconcat(pool, dir, "/", tmp_fname, NULL);
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen /* doesn't exist */
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen /* wait and try again - very unlikely */
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen index_file_set_syscall_error(index, path, "open()");
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainenenum mail_flags maildir_filename_get_flags(const char *fname,
f2f86ec77d1e4986e95990976447c2d1520a8357Timo Sirainen if (info == NULL || info[1] != '2' || info[2] != ',')
f2f86ec77d1e4986e95990976447c2d1520a8357Timo Sirainen for (info += 3; *info != '\0' && *info != ','; info++) {
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen /* custom flag */
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen /* unknown flag - ignore */
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainenconst char *maildir_filename_set_flags(const char *fname, enum mail_flags flags)
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen /* remove the old :info from file name, and get the old flags */
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen if (info != NULL && strrchr(fname, '/') > info)
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen /* insert the new flags between old flags. flags must be sorted by
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen their ASCII code. unknown flags are kept. */
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen /* skip all known flags */
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen while (*oldflags == 'D' || *oldflags == 'F' ||
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen nextflag = *oldflags == '\0' || *oldflags == ',' ? 256 :
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen (unsigned char) *oldflags;
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen if ((flags & MAIL_FLAGGED) && nextflag > 'F') {
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen if ((flags & MAIL_ANSWERED) && nextflag > 'R') {
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen if ((flags & MAIL_DELETED) && nextflag > 'T') {
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen if ((flags & MAIL_CUSTOM_FLAGS_MASK) && nextflag > 'a') {
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen if (flags & (1 << (i + MAIL_CUSTOM_FLAG_1_BIT)))
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainen /* another flagset, we don't know about these, just keep them */
67f1723e1685b4bf73c1cca0a1e08a0a87ffd410Timo Sirainenmaildir_index_alloc(const char *maildir, const char *index_dir,
return index;
const char *fname;
return date;
int external_change)
return FALSE;
return FALSE;
return FALSE;
return FALSE;
return TRUE;