~ubuntu-branches/ubuntu/trusty/dovecot/trusty-updates

« back to all changes in this revision

Viewing changes to src/lib-storage/index/dbox-common/dbox-save.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (1.15.3) (96.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140108093549-814nkqdcxfbvgktg
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2007-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2007-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "istream.h"
13
13
 
14
14
void dbox_save_add_to_index(struct dbox_save_context *ctx)
15
15
{
 
16
        struct mail_save_data *mdata = &ctx->ctx.data;
16
17
        enum mail_flags save_flags;
17
18
 
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,
21
22
                                save_flags);
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);
25
26
        }
26
 
        if (ctx->ctx.min_modseq != 0) {
 
27
        if (mdata->min_modseq != 0) {
27
28
                mail_index_update_modseq(ctx->trans, ctx->seq,
28
 
                                         ctx->ctx.min_modseq);
 
29
                                         mdata->min_modseq);
29
30
        }
30
31
}
31
32
 
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;
62
62
        }
63
 
        _ctx->output = ctx->dbox_output;
 
63
        _ctx->data.output = ctx->dbox_output;
64
64
 
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);
68
68
}
69
69
 
75
75
        if (ctx->failed)
76
76
                return -1;
77
77
 
78
 
        if (_ctx->attach != NULL)
 
78
        if (_ctx->data.attach != NULL)
79
79
                return index_attachment_save_continue(_ctx);
80
80
 
81
81
        do {
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));
87
87
                        }
88
88
                        ctx->failed = TRUE;
89
89
                        return -1;
99
99
 
100
100
void dbox_save_end(struct dbox_save_context *ctx)
101
101
{
 
102
        struct mail_save_data *mdata = &ctx->ctx.data;
102
103
        struct ostream *dbox_output = ctx->dbox_output;
103
104
 
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;
107
108
        }
108
 
        if (ctx->ctx.output == dbox_output)
109
 
                return;
110
 
 
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));
 
113
                ctx->failed = TRUE;
 
114
        }
 
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;
 
121
                } else {
 
122
                        i_assert(ctx->failed);
 
123
                }
 
124
        }
 
125
        index_mail_cache_parse_deinit(ctx->ctx.dest_mail,
 
126
                                      ctx->ctx.data.received_date,
 
127
                                      !ctx->failed);
115
128
}
116
129
 
117
130
void dbox_save_write_metadata(struct mail_save_context *_ctx,
120
133
                              guid_128_t guid_128)
121
134
{
122
135
        struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
 
136
        struct mail_save_data *mdata = &ctx->ctx.data;
123
137
        struct dbox_metadata_header metadata_hdr;
124
138
        const char *guid;
125
139
        string_t *str;
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));
132
146
 
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);
141
155
        }
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)
145
159
                i_unreached();
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,
151
 
                            _ctx->pop3_uidl);
 
165
                            mdata->pop3_uidl);
 
166
                ctx->have_pop3_uidls = TRUE;
 
167
        }
 
168
        if (mdata->pop3_order != 0) {
 
169
                str_printfa(str, "%c%u\n", DBOX_METADATA_POP3_ORDER,
 
170
                            mdata->pop3_order);
 
171
                ctx->have_pop3_orders = TRUE;
152
172
        }
153
173
 
154
 
        guid = _ctx->guid;
 
174
        guid = mdata->guid;
155
175
        if (guid != NULL)
156
176
                mail_generate_guid_128_hash(guid, guid_128);
157
177
        else {
173
193
        dbox_attachment_save_write_metadata(_ctx, str);
174
194
 
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));
 
197
}
 
198
 
 
199
void dbox_save_update_header_flags(struct dbox_save_context *ctx,
 
200
                                   struct mail_index_view *sync_view,
 
201
                                   uint32_t ext_id,
 
202
                                   unsigned int flags_offset)
 
203
{
 
204
        const void *data;
 
205
        size_t data_size;
 
206
        uint8_t old_flags = 0, flags;
 
207
 
 
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);
 
211
        else {
 
212
                /* grow old dbox header */
 
213
                mail_index_ext_resize_hdr(ctx->trans, ext_id, flags_offset+1);
 
214
        }
 
215
 
 
216
        flags = old_flags;
 
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);
 
225
        }
177
226
}