maildir-util.c revision a38ef15060e45e5060bb24c403a580b9a57a818c
/* Copyright (C) 2004 Timo Sirainen */
#include "lib.h"
#include "hostpid.h"
#include "ioloop.h"
#include "str.h"
#include "maildir-storage.h"
#include "maildir-uidlist.h"
#include <unistd.h>
#include <fcntl.h>
{
int ret;
return -2; /* expunged */
t_push();
if ((flags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) != 0) {
/* probably in new/ dir */
if (ret != 0) {
t_pop();
return ret;
}
}
t_pop();
return ret;
}
{
int i, ret;
for (i = 0; i < 10 && ret == 0; i++) {
/* file is either renamed or deleted. sync the maildir and
see which one. if file appears to be renamed constantly,
don't try to open it more than 10 times. */
if (maildir_storage_sync_force(ibox) < 0)
return -1;
}
if (i == 10) {
}
}
{
const char *info;
unsigned int num;
*flags_r = 0;
return 0;
switch (*info) {
case 'R': /* replied */
*flags_r |= MAIL_ANSWERED;
break;
case 'S': /* seen */
break;
case 'T': /* trashed */
*flags_r |= MAIL_DELETED;
break;
case 'D': /* draft */
*flags_r |= MAIL_DRAFT;
break;
case 'F': /* flagged */
*flags_r |= MAIL_FLAGGED;
break;
default:
/* keyword */
break;
}
/* unknown flag - ignore */
break;
}
}
return 1;
}
{
int i, nextflag;
/* see if any keywords are given */
for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
if (keywords[i] != 0)
break;
}
if (i == INDEX_KEYWORDS_BYTE_COUNT)
}
/* remove the old :info from file name, and get the old flags */
oldflags = "";
}
/* insert the new flags between old flags. flags must be sorted by
their ASCII code. unknown flags are kept. */
for (;;) {
/* skip all known flags */
*oldflags == 'T' ||
oldflags++;
(unsigned char) *oldflags;
flags &= ~MAIL_DRAFT;
}
flags &= ~MAIL_FLAGGED;
}
flags &= ~MAIL_ANSWERED;
}
}
flags &= ~MAIL_DELETED;
}
for (i = 0; i < INDEX_KEYWORDS_COUNT; i++) {
(1 << (i % CHAR_BIT))) != 0)
}
}
break;
oldflags++;
}
if (*oldflags == ',') {
/* another flagset, we don't know about these, just keep them */
while (*oldflags != '\0')
}
}
{
static unsigned int create_count = 0;
static time_t first_stamp = 0;
/* it's possible that within last second another process had
the same UID as us. Use usecs to make sure we don't create
duplicate base name. */
return t_strdup_printf("%s.P%sQ%uM%s.%s",
create_count++,
} else {
/* Don't bother with usecs. Saves a bit space :) */
return t_strdup_printf("%s.P%sQ%u.%s",
create_count++, my_hostname);
}
}
{
int fd;
tv = &ioloop_timeval;
for (;;) {
/* doesn't exist */
break;
}
/* wait and try again - very unlikely */
sleep(2);
i_fatal("gettimeofday(): %m");
}
if (fd == -1) {
"open(%s) failed: %m", path);
}
return fd;
}
/* a char* hash function from ASU -- from glib */
unsigned int maildir_hash(const void *p)
{
const unsigned char *s = p;
unsigned int g, h = 0;
while (*s != ':' && *s != '\0') {
h = (h << 4) + *s;
if ((g = h & 0xf0000000UL)) {
h = h ^ (g >> 24);
h = h ^ g;
}
s++;
}
return h;
}
{
}
return 0;
}