index-fetch.c revision 0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834
45e9809aff7304721fddb95654901b32195c9c7avboxsync/* Copyright (C) 2002-2003 Timo Sirainen */
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#include "lib.h"
45e9809aff7304721fddb95654901b32195c9c7avboxsync#include "index-storage.h"
45e9809aff7304721fddb95654901b32195c9c7avboxsync#include "index-mail.h"
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstruct mail *
45e9809aff7304721fddb95654901b32195c9c7avboxsyncindex_storage_fetch(struct mailbox_transaction_context *_t, uint32_t seq,
45e9809aff7304721fddb95654901b32195c9c7avboxsync enum mail_fetch_field wanted_fields)
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct index_transaction_context *t =
45e9809aff7304721fddb95654901b32195c9c7avboxsync (struct index_transaction_context *)_t;
45e9809aff7304721fddb95654901b32195c9c7avboxsync const struct mail_index_record *rec;
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync if (mail_index_lookup(t->ibox->view, seq, &rec) < 0) {
45e9809aff7304721fddb95654901b32195c9c7avboxsync mail_storage_set_index_error(t->ibox);
45e9809aff7304721fddb95654901b32195c9c7avboxsync return NULL;
45e9809aff7304721fddb95654901b32195c9c7avboxsync }
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync if (rec == NULL)
45e9809aff7304721fddb95654901b32195c9c7avboxsync return NULL;
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync if (t->fetch_mail.pool != NULL)
45e9809aff7304721fddb95654901b32195c9c7avboxsync index_mail_deinit(&t->fetch_mail);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync index_mail_init(t, &t->fetch_mail, wanted_fields, NULL);
45e9809aff7304721fddb95654901b32195c9c7avboxsync if (index_mail_next(&t->fetch_mail, rec, seq, FALSE) <= 0)
45e9809aff7304721fddb95654901b32195c9c7avboxsync return NULL;
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync return &t->fetch_mail.mail;
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncint index_storage_get_uids(struct mailbox *box,
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t uid1, uint32_t uid2,
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t *seq1_r, uint32_t *seq2_r)
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct index_mailbox *ibox = (struct index_mailbox *)box;
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync if (mail_index_lookup_uid_range(ibox->view, uid1, uid2,
45e9809aff7304721fddb95654901b32195c9c7avboxsync seq1_r, seq2_r) < 0) {
45e9809aff7304721fddb95654901b32195c9c7avboxsync mail_storage_set_index_error(ibox);
45e9809aff7304721fddb95654901b32195c9c7avboxsync return -1;
45e9809aff7304721fddb95654901b32195c9c7avboxsync }
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync return 0;
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync