14
14
void dbox_save_add_to_index(struct dbox_save_context *ctx)
16
struct mail_save_data *mdata = &ctx->ctx.data;
16
17
enum mail_flags save_flags;
18
save_flags = ctx->ctx.flags & ~MAIL_RECENT;
19
mail_index_append(ctx->trans, ctx->ctx.uid, &ctx->seq);
19
save_flags = mdata->flags & ~MAIL_RECENT;
20
mail_index_append(ctx->trans, mdata->uid, &ctx->seq);
20
21
mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_REPLACE,
22
if (ctx->ctx.keywords != NULL) {
23
if (mdata->keywords != NULL) {
23
24
mail_index_update_keywords(ctx->trans, ctx->seq,
24
MODIFY_REPLACE, ctx->ctx.keywords);
25
MODIFY_REPLACE, mdata->keywords);
26
if (ctx->ctx.min_modseq != 0) {
27
if (mdata->min_modseq != 0) {
27
28
mail_index_update_modseq(ctx->trans, ctx->seq,
55
56
o_stream_cork(ctx->dbox_output);
56
57
if (o_stream_send(ctx->dbox_output, &dbox_msg_hdr,
57
58
sizeof(dbox_msg_hdr)) < 0) {
58
mail_storage_set_critical(_storage,
59
"o_stream_send(%s) failed: %m",
60
ctx->cur_file->cur_path);
59
mail_storage_set_critical(_storage, "write(%s) failed: %m",
60
o_stream_get_name(ctx->dbox_output));
61
61
ctx->failed = TRUE;
63
_ctx->output = ctx->dbox_output;
63
_ctx->data.output = ctx->dbox_output;
65
if (_ctx->received_date == (time_t)-1)
66
_ctx->received_date = ioloop_time;
65
if (_ctx->data.received_date == (time_t)-1)
66
_ctx->data.received_date = ioloop_time;
67
67
index_attachment_save_begin(_ctx, storage->attachment_fs, ctx->input);
78
if (_ctx->attach != NULL)
78
if (_ctx->data.attach != NULL)
79
79
return index_attachment_save_continue(_ctx);
82
if (o_stream_send_istream(_ctx->output, ctx->input) < 0) {
82
if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
83
83
if (!mail_storage_set_error_from_errno(storage)) {
84
84
mail_storage_set_critical(storage,
85
"o_stream_send_istream(%s) failed: %m",
86
ctx->cur_file->cur_path);
85
"write(%s) failed: %m",
86
o_stream_get_name(_ctx->data.output));
88
88
ctx->failed = TRUE;
100
100
void dbox_save_end(struct dbox_save_context *ctx)
102
struct mail_save_data *mdata = &ctx->ctx.data;
102
103
struct ostream *dbox_output = ctx->dbox_output;
104
if (ctx->ctx.attach != NULL) {
105
if (mdata->attach != NULL && !ctx->failed) {
105
106
if (index_attachment_save_finish(&ctx->ctx) < 0)
106
107
ctx->failed = TRUE;
108
if (ctx->ctx.output == dbox_output)
111
/* e.g. zlib plugin had changed this */
112
o_stream_ref(dbox_output);
113
o_stream_destroy(&ctx->ctx.output);
114
ctx->ctx.output = dbox_output;
109
if (o_stream_nfinish(mdata->output) < 0) {
110
mail_storage_set_critical(ctx->ctx.transaction->box->storage,
111
"write(%s) failed: %m",
112
o_stream_get_name(mdata->output));
115
if (mdata->output != dbox_output) {
116
if (mdata->output != NULL) {
117
/* e.g. zlib plugin had changed this */
118
o_stream_ref(dbox_output);
119
o_stream_destroy(&mdata->output);
120
mdata->output = dbox_output;
122
i_assert(ctx->failed);
125
index_mail_cache_parse_deinit(ctx->ctx.dest_mail,
126
ctx->ctx.data.received_date,
117
130
void dbox_save_write_metadata(struct mail_save_context *_ctx,
128
142
memset(&metadata_hdr, 0, sizeof(metadata_hdr));
129
143
memcpy(metadata_hdr.magic_post, DBOX_MAGIC_POST,
130
144
sizeof(metadata_hdr.magic_post));
131
o_stream_send(output, &metadata_hdr, sizeof(metadata_hdr));
145
o_stream_nsend(output, &metadata_hdr, sizeof(metadata_hdr));
133
147
str = t_str_new(256);
134
148
if (output_msg_size != ctx->input->v_offset) {
140
154
(unsigned long long)ctx->input->v_offset);
142
156
str_printfa(str, "%c%lx\n", DBOX_METADATA_RECEIVED_TIME,
143
(unsigned long)_ctx->received_date);
157
(unsigned long)mdata->received_date);
144
158
if (mail_get_virtual_size(_ctx->dest_mail, &vsize) < 0)
146
160
str_printfa(str, "%c%llx\n", DBOX_METADATA_VIRTUAL_SIZE,
147
161
(unsigned long long)vsize);
148
if (_ctx->pop3_uidl != NULL) {
149
i_assert(strchr(_ctx->pop3_uidl, '\n') == NULL);
162
if (mdata->pop3_uidl != NULL) {
163
i_assert(strchr(mdata->pop3_uidl, '\n') == NULL);
150
164
str_printfa(str, "%c%s\n", DBOX_METADATA_POP3_UIDL,
166
ctx->have_pop3_uidls = TRUE;
168
if (mdata->pop3_order != 0) {
169
str_printfa(str, "%c%u\n", DBOX_METADATA_POP3_ORDER,
171
ctx->have_pop3_orders = TRUE;
155
175
if (guid != NULL)
156
176
mail_generate_guid_128_hash(guid, guid_128);
173
193
dbox_attachment_save_write_metadata(_ctx, str);
175
195
str_append_c(str, '\n');
176
o_stream_send(output, str_data(str), str_len(str));
196
o_stream_nsend(output, str_data(str), str_len(str));
199
void dbox_save_update_header_flags(struct dbox_save_context *ctx,
200
struct mail_index_view *sync_view,
202
unsigned int flags_offset)
206
uint8_t old_flags = 0, flags;
208
mail_index_get_header_ext(sync_view, ext_id, &data, &data_size);
209
if (flags_offset < data_size)
210
old_flags = *((const uint8_t *)data + flags_offset);
212
/* grow old dbox header */
213
mail_index_ext_resize_hdr(ctx->trans, ext_id, flags_offset+1);
217
if (ctx->have_pop3_uidls)
218
flags |= DBOX_INDEX_HEADER_FLAG_HAVE_POP3_UIDLS;
219
if (ctx->have_pop3_orders)
220
flags |= DBOX_INDEX_HEADER_FLAG_HAVE_POP3_ORDERS;
221
if (flags != old_flags) {
222
/* flags changed, update them */
223
mail_index_update_header_ext(ctx->trans, ext_id,
224
flags_offset, &flags, 1);