[dovecot-cvs] dovecot/src/lib-storage/index index-copy.c,1.28,1.29
index-fetch.c,1.47,1.48 index-mail.c,1.10,1.11
index-storage.h,1.41,1.42
cras at procontrol.fi
cras at procontrol.fi
Wed Jul 23 04:40:52 EEST 2003
Update of /home/cvs/dovecot/src/lib-storage/index
In directory danu:/tmp/cvs-serv408/lib-storage/index
Modified Files:
index-copy.c index-fetch.c index-mail.c index-storage.h
Log Message:
API change for copying messages.
Index: index-copy.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-copy.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- index-copy.c 15 Jun 2003 03:42:29 -0000 1.28
+++ index-copy.c 23 Jul 2003 00:40:50 -0000 1.29
@@ -8,90 +8,52 @@
#include <unistd.h>
-static int copy_messageset(struct messageset_context *msgset_ctx,
- struct mail_save_context *save_ctx,
- struct index_mailbox *src,
- struct mailbox *dest)
+struct mail_copy_context {
+ struct mailbox *box;
+ struct mail_save_context *save_ctx;
+};
+
+struct mail_copy_context *index_storage_copy_init(struct mailbox *box)
{
- const struct messageset_mail *mail;
- struct mail_full_flags flags;
- struct istream *input;
- time_t received_date;
- int failed, deleted;
+ struct mail_copy_context *ctx;
+ struct mail_save_context *save_ctx;
- memset(&flags, 0, sizeof(flags));
- flags.custom_flags =
- mail_custom_flags_list_get(src->index->custom_flags);
- flags.custom_flags_count = MAIL_CUSTOM_FLAGS_COUNT;
+ save_ctx = box->save_init(box, TRUE);
+ if (save_ctx == NULL)
+ return NULL;
- while ((mail = index_messageset_next(msgset_ctx)) != NULL) {
- input = src->index->open_mail(src->index, mail->rec,
- &received_date, &deleted);
- if (input == NULL)
- return FALSE;
+ ctx = i_new(struct mail_copy_context, 1);
+ ctx->box = box;
+ ctx->save_ctx = save_ctx;
- flags.flags = mail->rec->msg_flags;
- failed = !dest->save_next(save_ctx, &flags, received_date,
- 0, input);
- i_stream_unref(input);
+ return ctx;
+}
- if (failed)
- return FALSE;
- }
+int index_storage_copy_deinit(struct mail_copy_context *ctx, int rollback)
+{
+ int ret;
- return TRUE;
+ ret = ctx->box->save_deinit(ctx->save_ctx, rollback);
+ i_free(ctx);
+ return ret;
}
-int index_storage_copy(struct mailbox *box, struct mailbox *destbox,
- const char *messageset, int uidset)
+int index_storage_copy(struct mail *mail, struct mail_copy_context *ctx)
{
- struct index_mailbox *ibox = (struct index_mailbox *) box;
- struct messageset_context *msgset_ctx;
- struct mail_save_context *save_ctx;
- int ret, ret2, copy_inside_mailbox;
+ struct index_mail *imail = (struct index_mail *) mail;
+ struct istream *input;
+ time_t received_date;
+ int ret, deleted;
- if (destbox->readonly) {
- mail_storage_set_error(box->storage,
- "Destination mailbox is read-only");
+ input = imail->ibox->index->open_mail(imail->ibox->index,
+ imail->data.rec,
+ &received_date, &deleted);
+ if (input == NULL)
return FALSE;
- }
-
- copy_inside_mailbox =
- destbox->storage == box->storage &&
- strcmp(destbox->name, box->name) == 0;
-
- if (copy_inside_mailbox) {
- if (!index_storage_lock(ibox, MAIL_LOCK_EXCLUSIVE))
- return FALSE;
- } else {
- if (!index_storage_sync_and_lock(ibox, TRUE, TRUE,
- MAIL_LOCK_SHARED))
- return FALSE;
- }
- save_ctx = destbox->save_init(destbox, TRUE);
- if (save_ctx == NULL)
- ret = FALSE;
- else {
- /* abort if any of the messages are expunged */
- msgset_ctx = index_messageset_init(ibox, messageset, uidset,
- FALSE);
- ret = copy_messageset(msgset_ctx, save_ctx, ibox, destbox);
- ret2 = index_messageset_deinit(msgset_ctx);
- if (ret2 < 0)
- ret = FALSE;
- else if (ret2 == 0) {
- mail_storage_set_error(ibox->box.storage,
- "Some of the requested messages no longer exist.");
- ret = FALSE;
- }
-
- if (!destbox->save_deinit(save_ctx, !ret))
- ret = FALSE;
- }
-
- if (!index_storage_lock(ibox, MAIL_LOCK_UNLOCK))
- ret = FALSE;
+ ret = ctx->box->save_next(ctx->save_ctx, mail->get_flags(mail),
+ received_date, 0, input);
+ i_stream_unref(input);
return ret;
}
Index: index-fetch.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-fetch.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- index-fetch.c 15 Jun 2003 03:42:29 -0000 1.47
+++ index-fetch.c 23 Jul 2003 00:40:50 -0000 1.48
@@ -18,6 +18,7 @@
struct index_mail mail;
int update_seen;
+ enum mail_lock_type old_lock;
};
struct mail_fetch_context *
@@ -30,6 +31,7 @@
int check_mail;
ctx = i_new(struct mail_fetch_context, 1);
+ ctx->old_lock = ibox->index->lock_type;
if (box->readonly && update_seen != NULL)
*update_seen = FALSE;
@@ -48,7 +50,8 @@
if (update_seen != NULL && *update_seen &&
ibox->index->header->messages_count ==
- ibox->index->header->seen_messages_count) {
+ ibox->index->header->seen_messages_count &&
+ ctx->old_lock != MAIL_LOCK_EXCLUSIVE) {
/* if all messages are already seen, there's no point in
keeping exclusive lock */
*update_seen = FALSE;
@@ -73,7 +76,7 @@
if (all_found != NULL)
*all_found = ret > 0;
- if (!index_storage_lock(ctx->ibox, MAIL_LOCK_UNLOCK))
+ if (!index_storage_lock(ctx->ibox, ctx->old_lock))
ret = -1;
if (ctx->ibox->fetch_mail.pool != NULL)
Index: index-mail.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- index-mail.c 24 Jun 2003 22:53:54 -0000 1.10
+++ index-mail.c 23 Jul 2003 00:40:50 -0000 1.11
@@ -637,7 +637,7 @@
}
static struct mail index_mail = {
- 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
get_flags,
get_parts,
@@ -648,7 +648,8 @@
get_address,
get_first_mailbox,
get_stream,
- get_special
+ get_special,
+ index_storage_copy
};
void index_mail_init(struct index_mailbox *ibox, struct index_mail *mail,
@@ -656,11 +657,15 @@
const char *const wanted_headers[])
{
mail->mail = index_mail;
- mail->pool = pool_alloconly_create("index_mail", 4096);
+ mail->mail.box = &ibox->box;
+ mail->pool = pool_alloconly_create("index_mail", 4096);
mail->ibox = ibox;
mail->wanted_fields = wanted_fields;
mail->wanted_headers = wanted_headers;
+
+ if (ibox->mail_init != NULL)
+ ibox->mail_init(mail);
}
int index_mail_next(struct index_mail *mail, struct mail_index_record *rec)
Index: index-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- index-storage.h 21 Jul 2003 14:35:39 -0000 1.41
+++ index-storage.h 23 Jul 2003 00:40:50 -0000 1.42
@@ -18,6 +18,7 @@
/* expunge messages marked as deleted, requires index to be
exclusively locked */
int (*expunge_locked)(struct index_mailbox *ibox, int notify);
+ void (*mail_init)(struct index_mail *mail);
struct mail_index *index;
@@ -82,8 +83,6 @@
void index_storage_set_callbacks(struct mail_storage *storage,
struct mail_storage_callbacks *callbacks,
void *context);
-int index_storage_copy(struct mailbox *box, struct mailbox *destbox,
- const char *messageset, int uidset);
int index_storage_expunge(struct mailbox *box, int notify);
int index_storage_get_status(struct mailbox *box,
enum mailbox_status_items items,
@@ -116,5 +115,9 @@
const char *const wanted_headers[]);
int index_storage_search_deinit(struct mail_search_context *ctx);
struct mail *index_storage_search_next(struct mail_search_context *ctx);
+
+struct mail_copy_context *index_storage_copy_init(struct mailbox *box);
+int index_storage_copy_deinit(struct mail_copy_context *ctx, int rollback);
+int index_storage_copy(struct mail *mail, struct mail_copy_context *ctx);
#endif
More information about the dovecot-cvs
mailing list