if (ctx->fd != -1) {
_ctx->data.output =
o_stream_create_fd_file(ctx->fd, 0, FALSE);
+ o_stream_set_name(_ctx->data.output, path);
o_stream_cork(_ctx->data.output);
} else {
mail_storage_set_critical(trans->box->storage,
int cydir_save_continue(struct mail_save_context *_ctx)
{
struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
- struct mail_storage *storage = &ctx->mbox->storage->storage;
if (ctx->failed)
return -1;
- do {
- if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
- if (!mail_storage_set_error_from_errno(storage)) {
- mail_storage_set_critical(storage,
- "write(%s) failed: %m",
- cydir_get_save_path(ctx, ctx->mail_count));
- }
- ctx->failed = TRUE;
- return -1;
- }
- index_mail_cache_parse_continue(_ctx->dest_mail);
-
- /* both tee input readers may consume data from our primary
- input stream. we'll have to make sure we don't return with
- one of the streams still having data in them. */
- } while (i_stream_read(ctx->input) > 0);
+ if (index_storage_save_continue(_ctx, ctx->input,
+ _ctx->dest_mail) < 0) {
+ ctx->failed = TRUE;
+ return -1;
+ }
return 0;
}
#include "str.h"
#include "hex-binary.h"
#include "index-mail.h"
+#include "index-storage.h"
#include "dbox-attachment.h"
#include "dbox-file.h"
#include "dbox-save.h"
int dbox_save_continue(struct mail_save_context *_ctx)
{
struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
- struct mail_storage *storage = _ctx->transaction->box->storage;
if (ctx->failed)
return -1;
if (_ctx->data.attach != NULL)
return index_attachment_save_continue(_ctx);
- do {
- if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
- if (!mail_storage_set_error_from_errno(storage)) {
- mail_storage_set_critical(storage,
- "write(%s) failed: %m",
- o_stream_get_name(_ctx->data.output));
- }
- ctx->failed = TRUE;
- return -1;
- }
- index_mail_cache_parse_continue(_ctx->dest_mail);
-
- /* both tee input readers may consume data from our primary
- input stream. we'll have to make sure we don't return with
- one of the streams still having data in them. */
- } while (i_stream_read(ctx->input) > 0);
+ if (index_storage_save_continue(_ctx, ctx->input,
+ _ctx->dest_mail) < 0) {
+ ctx->failed = TRUE;
+ return -1;
+ }
return 0;
}
int imapc_save_continue(struct mail_save_context *_ctx)
{
struct imapc_save_context *ctx = (struct imapc_save_context *)_ctx;
- struct mail_storage *storage = _ctx->transaction->box->storage;
if (ctx->failed)
return -1;
- if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
- if (!mail_storage_set_error_from_errno(storage)) {
- mail_storage_set_critical(storage,
- "o_stream_send_istream(%s) failed: %m",
- ctx->temp_path);
- }
+ if (index_storage_save_continue(_ctx, ctx->input, NULL) < 0) {
ctx->failed = TRUE;
return -1;
}
#include "lib.h"
#include "array.h"
#include "istream.h"
+#include "ostream.h"
#include "ioloop.h"
#include "str.h"
#include "mkdir-parents.h"
}
return 1;
}
+
+int index_storage_save_continue(struct mail_save_context *ctx,
+ struct istream *input,
+ struct mail *cache_dest_mail)
+{
+ struct mail_storage *storage = ctx->transaction->box->storage;
+
+ do {
+ if (o_stream_send_istream(ctx->data.output, input) < 0) {
+ if (!mail_storage_set_error_from_errno(storage)) {
+ mail_storage_set_critical(storage,
+ "write(%s) failed: %m",
+ o_stream_get_name(ctx->data.output));
+ }
+ return -1;
+ }
+ if (cache_dest_mail != NULL)
+ index_mail_cache_parse_continue(cache_dest_mail);
+
+ /* both tee input readers may consume data from our primary
+ input stream. we'll have to make sure we don't return with
+ one of the streams still having data in them. */
+ } while (i_stream_read(input) > 0);
+ return 0;
+}
enum mail_index_sync_flags flags);
void index_storage_expunging_deinit(struct mailbox *box);
+int index_storage_save_continue(struct mail_save_context *ctx,
+ struct istream *input,
+ struct mail *cache_dest_mail);
+
#endif
if (!ctx->failed) {
_ctx->data.output = o_stream_create_fd_file(ctx->fd, 0, FALSE);
+ o_stream_set_name(_ctx->data.output, t_strdup_printf(
+ "%s/%s", ctx->tmpdir, ctx->file_last->tmp_name));
o_stream_cork(_ctx->data.output);
ctx->last_save_finished = FALSE;
}
int maildir_save_continue(struct mail_save_context *_ctx)
{
struct maildir_save_context *ctx = (struct maildir_save_context *)_ctx;
- struct mail_storage *storage = &ctx->mbox->storage->storage;
if (ctx->failed)
return -1;
- do {
- if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
- if (!mail_storage_set_error_from_errno(storage)) {
- mail_storage_set_critical(storage,
- "o_stream_send_istream(%s/%s) "
- "failed: %m",
- ctx->tmpdir, ctx->file_last->tmp_name);
- }
- ctx->failed = TRUE;
- return -1;
- }
- if (ctx->cur_dest_mail != NULL)
- index_mail_cache_parse_continue(ctx->cur_dest_mail);
-
- /* both tee input readers may consume data from our primary
- input stream. we'll have to make sure we don't return with
- one of the streams still having data in them. */
- } while (i_stream_read(ctx->input) > 0);
+ if (index_storage_save_continue(_ctx, ctx->input,
+ ctx->cur_dest_mail) < 0) {
+ ctx->failed = TRUE;
+ return -1;
+ }
return 0;
}