maildir-util.c revision b142deb9a831c89b1bb9129ada655f3e56b9d4cc
/* 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 "maildir-keywords.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(mbox) < 0)
return -1;
}
if (i == 10) {
ret = -1;
}
}
{
static unsigned int create_count = 0;
static time_t first_stamp = 0;
/* it's possible that within last second another process had
the same PID 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) {
"Not enough disk space");
} else {
"open(%s) failed: %m", path);
}
}
return fd;
}
{
fname += 3;
break;
}
}
if (*fname == '\0')
return FALSE;
fname++;
}
if (*fname != MAILDIR_INFO_SEP &&
*fname != MAILDIR_EXTRA_SEP &&
*fname != '\0')
return FALSE;
return TRUE;
}
/* 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 != MAILDIR_INFO_SEP && *s != '\0') {
i_assert(*s != '/');
h = (h << 4) + *s;
if ((g = h & 0xf0000000UL)) {
h = h ^ (g >> 24);
h = h ^ g;
}
s++;
}
return h;
}
{
}
return 0;
}