From: Timo Sirainen Date: Wed, 7 May 2003 12:06:47 +0000 (+0300) Subject: cleanup: message saving code isn't index-specific X-Git-Tag: 1.1.alpha1~4677 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0376ad840fce4b7cef75a5a73f8fb527258a7ca8;p=thirdparty%2Fdovecot%2Fcore.git cleanup: message saving code isn't index-specific --HG-- branch : HEAD --- diff --git a/src/lib-storage/Makefile.am b/src/lib-storage/Makefile.am index 0183a87d83..56049bc4e0 100644 --- a/src/lib-storage/Makefile.am +++ b/src/lib-storage/Makefile.am @@ -8,9 +8,11 @@ INCLUDES = \ -I$(top_srcdir)/src/lib-imap libstorage_a_SOURCES = \ + mail-save.c \ mail-search.c \ mail-storage.c noinst_HEADERS = \ + mail-save.h \ mail-search.h \ mail-storage.h diff --git a/src/lib-storage/index/Makefile.am b/src/lib-storage/index/Makefile.am index 22fda89bc6..ba465a91da 100644 --- a/src/lib-storage/index/Makefile.am +++ b/src/lib-storage/index/Makefile.am @@ -16,7 +16,6 @@ libstorage_index_a_SOURCES = \ index-mail.c \ index-mailbox-check.c \ index-messageset.c \ - index-save.c \ index-search.c \ index-status.c \ index-storage.c \ diff --git a/src/lib-storage/index/index-storage.h b/src/lib-storage/index/index-storage.h index b4d37a0c92..10fd8277d2 100644 --- a/src/lib-storage/index/index-storage.h +++ b/src/lib-storage/index/index-storage.h @@ -5,12 +5,6 @@ #include "mail-index.h" #include "index-mail.h" -typedef int write_func_t(struct ostream *, const void *, size_t); - -/* Return -1 = failure, 0 = don't write the header, 1 = write it */ -typedef int header_callback_t(const char *name, - write_func_t *write_func, void *context); - struct index_autosync_file { struct index_autosync_file *next; @@ -74,10 +68,6 @@ int index_expunge_mail(struct index_mailbox *ibox, struct mail_index_record *rec, unsigned int seq, int notify); -int index_storage_save(struct mail_storage *storage, const char *path, - struct istream *input, struct ostream *output, - header_callback_t *header_callback, void *context); - void index_mailbox_check_add(struct index_mailbox *ibox, const char *path); void index_mailbox_check_remove_all(struct index_mailbox *ibox); diff --git a/src/lib-storage/index/maildir/maildir-save.c b/src/lib-storage/index/maildir/maildir-save.c index a9fcdf28ea..1f517bade7 100644 --- a/src/lib-storage/index/maildir/maildir-save.c +++ b/src/lib-storage/index/maildir/maildir-save.c @@ -5,8 +5,10 @@ #include "ostream.h" #include "maildir-index.h" #include "maildir-storage.h" +#include "mail-save.h" #include +#include #include #include #include @@ -48,8 +50,8 @@ maildir_read_into_tmp(struct index_mailbox *ibox, const char *dir, IO_PRIORITY_DEFAULT, FALSE); o_stream_set_blocking(output, 60000, NULL, NULL); - if (!index_storage_save(ibox->box.storage, path, input, output, - NULL, NULL)) + if (!mail_storage_save(ibox->box.storage, path, input, output, + getenv("MAIL_SAVE_CRLF") != NULL, NULL, NULL)) fname = NULL; o_stream_unref(output); diff --git a/src/lib-storage/index/mbox/mbox-save.c b/src/lib-storage/index/mbox/mbox-save.c index f1a1494134..3804301b0c 100644 --- a/src/lib-storage/index/mbox/mbox-save.c +++ b/src/lib-storage/index/mbox/mbox-save.c @@ -8,6 +8,7 @@ #include "mbox-index.h" #include "mbox-lock.h" #include "mbox-storage.h" +#include "mail-save.h" #include #include @@ -286,9 +287,11 @@ int mbox_storage_save_next(struct mail_save_context *ctx, t_push(); if (!write_from_line(ctx, received_date) || - !index_storage_save(ctx->ibox->box.storage, - ctx->ibox->index->mailbox_path, - data, ctx->output, save_header_callback, ctx) || + !mail_storage_save(ctx->ibox->box.storage, + ctx->ibox->index->mailbox_path, + data, ctx->output, + getenv("MAIL_SAVE_CRLF") != NULL, + save_header_callback, ctx) || !mbox_fix_header(ctx) || !mbox_append_lf(ctx)) { /* failed, truncate file back to original size. diff --git a/src/lib-storage/index/index-save.c b/src/lib-storage/mail-save.c similarity index 91% rename from src/lib-storage/index/index-save.c rename to src/lib-storage/mail-save.c index 3806d4297d..b3199555fd 100644 --- a/src/lib-storage/index/index-save.c +++ b/src/lib-storage/mail-save.c @@ -3,11 +3,9 @@ #include "lib.h" #include "istream.h" #include "ostream.h" -#include "write-full.h" -#include "index-storage.h" - -#include -#include +#include "message-parser.h" +#include "mail-storage.h" +#include "mail-save.h" static int write_with_crlf(struct ostream *output, const void *v_data, size_t size) @@ -132,9 +130,9 @@ static int save_headers(struct istream *input, struct ostream *output, return !failed; } -int index_storage_save(struct mail_storage *storage, const char *path, - struct istream *input, struct ostream *output, - header_callback_t *header_callback, void *context) +int mail_storage_save(struct mail_storage *storage, const char *path, + struct istream *input, struct ostream *output, int crlf, + header_callback_t *header_callback, void *context) { write_func_t *write_func; const unsigned char *data; @@ -142,7 +140,7 @@ int index_storage_save(struct mail_storage *storage, const char *path, ssize_t ret; int failed; - write_func = getenv("MAIL_SAVE_CRLF") ? write_with_crlf : write_with_lf; + write_func = crlf ? write_with_crlf : write_with_lf; if (header_callback != NULL) { if (!save_headers(input, output, header_callback, diff --git a/src/lib-storage/mail-save.h b/src/lib-storage/mail-save.h new file mode 100644 index 0000000000..91a46ec3be --- /dev/null +++ b/src/lib-storage/mail-save.h @@ -0,0 +1,14 @@ +#ifndef __MAIL_SAVE_H +#define __MAIL_SAVE_H + +typedef int write_func_t(struct ostream *, const void *, size_t); + +/* Return -1 = failure, 0 = don't write the header, 1 = write it */ +typedef int header_callback_t(const char *name, + write_func_t *write_func, void *context); + +int mail_storage_save(struct mail_storage *storage, const char *path, + struct istream *input, struct ostream *output, int crlf, + header_callback_t *header_callback, void *context); + +#endif