maildir-save.c revision 087e7957fb95f619d86db2d3d8c0664937cea419
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "ioloop.h"
#include "hostpid.h"
#include "ostream.h"
#include "maildir-index.h"
#include "maildir-storage.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <utime.h>
#include <time.h>
struct mail_filename {
struct mail_filename *next;
};
struct mail_save_context {
struct index_mailbox *ibox;
int transaction;
struct mail_filename *files;
};
{
static unsigned int create_count = 0;
hostpid_init();
return t_strdup_printf("%s.P%sQ%uM%s.%s",
}
const char **fname)
{
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 {
"Can't create file %s: %m", path);
}
}
return fd;
}
static const char *
{
int fd;
if (fd == -1)
return NULL;
t_push();
t_pop();
return fname;
}
{
int failed;
t_push();
else {
"Not enough disk space");
} else {
"link(%s, %s) failed: %m",
}
}
t_pop();
return !failed;
}
const struct mail_full_flags *flags,
{
enum mail_flags mail_flags;
int failed;
return FALSE;
t_push();
/* create the file into tmp/ directory */
t_pop();
return FALSE;
}
/* set the received_date by modifying mtime */
"utime() failed for %s: %m",
tmp_path);
t_pop();
return FALSE;
}
/* now, if we want to be able to rollback the whole append session,
we'll just store the name of this temp file and move it later
into new/ */
if (ctx->transaction) {
struct mail_filename *mf;
} else {
}
t_pop();
return !failed;
}
struct mail_save_context *
{
struct mail_save_context *ctx;
return NULL;
}
"/tmp", NULL);
"/new", NULL);
return ctx;
}
{
const char *path;
if (rollback) {
/* clean up the temp files */
t_push();
t_pop();
}
} else {
/* move them into new/ */
break;
}
}
if (failed) {
/* failed, try to unlink the mails already moved */
t_push();
t_pop();
}
}
}
return !failed;
}