view src/lib-index/maildir/maildir-open.c @ 221:ed0d5b17c7a4 HEAD

Added extra functions for easier printing of error messages. Moved file_set_size() to generic function in lib. If there's no space to build hash file, it builds itself in anon-mmaped memory and stays there.
author Timo Sirainen <tss@iki.fi>
date Fri, 13 Sep 2002 03:01:23 +0300
parents 1b34ec11fff8
children cf4d065f2f85
line wrap: on
line source

/* Copyright (C) 2002 Timo Sirainen */

#include "lib.h"
#include "iobuffer.h"
#include "maildir-index.h"
#include "mail-index-util.h"

#include <unistd.h>
#include <fcntl.h>

IOBuffer *maildir_open_mail(MailIndex *index, MailIndexRecord *rec)
{
	const char *fname, *path;
	int fd;

	fname = index->lookup_field(index, rec, FIELD_TYPE_LOCATION);
	if (fname == NULL) {
		index_data_set_corrupted(index, "Missing location field for "
					 "record %u", rec->uid);
		return NULL;
	}

	path = t_strconcat(index->dir, "/cur/", fname, NULL);

	fd = open(path, O_RDONLY);
	if (fd == -1) {
		index_set_error(index, "Error opening mail file %s: %m", path);
		return NULL;
	}

	return io_buffer_create_mmap(fd, default_pool, MAIL_MMAP_BLOCK_SIZE, 0);
}