maildir-util.c revision ca98d6a1bbe73499da758a36bfab2963375c8d06
/* Copyright (c) 2004-2010 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "str.h"
#include "mkdir-parents.h"
#include "maildir-storage.h"
#include "maildir-uidlist.h"
#include "maildir-keywords.h"
#include "maildir-filename.h"
#include "maildir-sync.h"
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <utime.h>
#define MAILDIR_RESYNC_RETRY_COUNT 10
static const char *
const char *fname, bool *have_flags_r)
{
struct maildir_keywords_sync_ctx *kw_ctx;
enum mail_flags flags;
*have_flags_r = FALSE;
return fname;
}
if (array_count(&keywords) == 0) {
} else {
*have_flags_r = TRUE;
}
return fname;
}
{
bool have_flags;
int ret;
if (ret <= 0)
if ((flags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) {
/* let's see if we can guess the filename based on index */
if (have_flags) {
/* don't even bother looking into new/ dir */
}
}
if ((flags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) != 0) {
/* probably in new/ dir */
if (ret != 0)
return ret;
}
return ret;
}
void *context ATTR_UNUSED)
{
/* most likely a symlink pointing to a non-existing file */
"Maildir: Symlink destination doesn't exist: %s", path);
return -2;
} else {
"maildir_file_do(%s): Filename keeps changing", path);
return -1;
}
}
{
int i, ret;
T_BEGIN {
} T_END;
for (i = 0; i < MAILDIR_RESYNC_RETRY_COUNT && 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. */
return -1;
T_BEGIN {
} T_END;
}
if (i == MAILDIR_RESYNC_RETRY_COUNT) T_BEGIN {
} T_END;
}
bool is_mail_dir)
{
box->file_create_gid_origin) == 0)
return 0;
switch (errno) {
case EEXIST:
return 0;
case ENOENT:
if (is_mail_dir || p == NULL) {
/* mailbox was being deleted just now */
return -1;
}
&parent_gid, &origin);
origin) == 0 ||
/* should work now, try again */
}
/* fall through */
default:
"mkdir(%s) failed: %m", path);
return -1;
}
}
{
const char *path;
unsigned int i;
bool is_mail_dir;
/* @UNSAFE: get a list of directories we want to create */
for (i = 0; i < N_ELEMENTS(subdirs); i++)
for (i = 0; i < N_ELEMENTS(dirs); i++) {
continue;
"stat(%s) failed: %m", path);
break;
}
break;
}
}
{
int ret;
else {
}
return FALSE;
}
/* maildir itself exists. create all of its subdirectories in case
they got lost. */
T_BEGIN {
} T_END;
}