maildir-mail.c revision e76c494ad6535d3de314cc0d3ac7a44b06e53c4b
/* Copyright (c) 2003-2008 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "istream.h"
#include "index-mail.h"
#include "maildir-storage.h"
#include "maildir-filename.h"
#include "maildir-uidlist.h"
#include "maildir-sync.h"
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
static int
{
if (*fd != -1)
return 1;
return 0;
"open(%s) failed: %m", path);
return -1;
}
static int
{
return 1;
return 0;
"stat(%s) failed: %m", path);
return -1;
}
static struct istream *
bool *deleted_r)
{
const char *path;
int fd = -1;
return NULL;
} else {
return NULL;
}
if (fd == -1) {
return NULL;
}
}
{
const char *path;
/* we're going to open the mail anyway */
}
"fstat(maildir) failed: %m");
return -1;
}
if (ret <= 0) {
if (ret == 0)
return -1;
}
} else {
"stat(%s) failed: %m", path);
return -1;
}
}
return 0;
}
{
return 0;
return -1;
return 0;
}
{
return 0;
return -1;
}
static bool
const char **fname_r)
{
struct mail_index_view *view;
bool exists;
return TRUE;
/* file exists in index file, but not in dovecot-uidlist anymore. */
/* one reason this could happen is if we delayed opening
dovecot-uidlist and we're trying to open a mail that got recently
expunged. Let's test this theory first: */
if (exists) {
/* the message still exists in index. this means there's some
kind of a desync, which doesn't get fixed if cur/ mtime is
the same as in index. fix this by forcing a resync. */
}
return FALSE;
}
{
const struct mail_cache_field *fields;
bool not_pop3_only = FALSE;
if (mail->pop3_state_set)
return mail->pop3_state;
/* if this mail itself has non-pop3 fields we know we're not
pop3-only */
/* get vsize decisions */
if (not_pop3_only) {
} else {
/* also check if there are any non-[pv]size cached fields */
&count);
for (i = 0; i < count; i++) {
else if (dec != MAIL_CACHE_DECISION_NO &&
}
}
if (!not_pop3_only) {
/* either nothing is cached, or only vsize is cached. */
} else if (vsize_dec != MAIL_CACHE_DECISION_YES) {
/* if virtual size isn't cached permanently,
POP3 isn't being used */
} else {
mail->pop3_state = 0;
}
return mail->pop3_state;
}
{
char *p;
return -1;
} else {
}
/* size can be included in filename */
size_r))
return 1;
/* size can be included in uidlist entry */
key);
if (*p == '\0') {
return 1;
}
}
}
return 0;
}
static void
bool vsize)
{
enum mail_fetch_field field;
int pop3_state;
return;
/* already in filename / uidlist. don't add it anywhere,
including to the uidlist if it's already in filename.
do some extra checks here to catch potential cache bugs. */
"Corrupted virtual size for uid=%u: "
"Corrupted physical size for uid=%u: "
}
return;
}
/* 1 = pop3-only, 0 = mixed, -1 = no pop3 */
/* if size is wanted permanently, store it to uidlist
so that in case cache file gets lost we can get it quickly */
}
}
{
return 0;
}
return -1;
return 0;
}
/* fallback to reading the file */
return -1;
return 0;
}
{
const char *path;
int ret;
return 0;
}
return -1;
return 0;
}
if (ret <= 0) {
if (ret == 0)
return -1;
}
} else {
/* saved mail which hasn't been committed yet */
"stat(%s) failed: %m", path);
return -1;
}
}
return 0;
}
static int
const char **value_r)
{
if (field == MAIL_FETCH_UIDL_FILE_NAME) {
return -1;
} else {
}
return 0;
} else if (field == MAIL_FETCH_UIDL_BACKEND) {
return 0;
} else {
return -1;
}
}
}
struct message_size *hdr_size,
struct message_size *body_size,
{
bool deleted;
if (deleted)
return -1;
}
}
}
enum mail_fetch_field field)
{
const char *fname;
if (field == MAIL_FETCH_VIRTUAL_SIZE) {
/* make sure it gets removed from uidlist.
if it's in file name, we can't really do more than log it. */
&size)) {
i_error("Maildir filename has wrong W value: %s/%s",
NULL);
}
}
}
struct mail_vfuncs maildir_mail_vfuncs = {
};