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

« back to all changes in this revision

Viewing changes to src/lib-storage/index/imapc/imapc-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) 2011-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2011-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "str.h"
66
66
 
67
67
        i_assert(ctx->fd == -1);
68
68
 
69
 
        ctx->fd = imapc_client_create_temp_fd(ctx->mbox->storage->client, &path);
 
69
        ctx->fd = imapc_client_create_temp_fd(ctx->mbox->storage->client->client,
 
70
                                              &path);
70
71
        if (ctx->fd == -1) {
71
72
                mail_storage_set_critical(storage,
72
73
                                          "Couldn't create temp file %s", path);
79
80
        ctx->finished = FALSE;
80
81
        ctx->temp_path = i_strdup(path);
81
82
        ctx->input = i_stream_create_crlf(input);
82
 
        _ctx->output = o_stream_create_fd_file(ctx->fd, 0, FALSE);
83
 
        o_stream_cork(_ctx->output);
 
83
        _ctx->data.output = o_stream_create_fd_file(ctx->fd, 0, FALSE);
 
84
        o_stream_cork(_ctx->data.output);
84
85
        return 0;
85
86
}
86
87
 
92
93
        if (ctx->failed)
93
94
                return -1;
94
95
 
95
 
        if (o_stream_send_istream(_ctx->output, ctx->input) < 0) {
 
96
        if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
96
97
                if (!mail_storage_set_error_from_errno(storage)) {
97
98
                        mail_storage_set_critical(storage,
98
99
                                "o_stream_send_istream(%s) failed: %m",
126
127
                return;
127
128
 
128
129
        if (str_to_uint32(args[1], &dest_uid) == 0) {
129
 
                seq_range_array_add(&ctx->dest_saved_uids, 0, dest_uid);
 
130
                seq_range_array_add_with_init(&ctx->dest_saved_uids,
 
131
                                              32, dest_uid);
130
132
                *uid_r = dest_uid;
131
133
        }
132
134
}
165
167
        uint32_t uid = 0;
166
168
 
167
169
        if (reply->state == IMAPC_COMMAND_STATE_OK) {
168
 
                if (strcasecmp(reply->resp_text_key, "APPENDUID") == 0)
 
170
                if (reply->resp_text_key != NULL &&
 
171
                    strcasecmp(reply->resp_text_key, "APPENDUID") == 0)
169
172
                        imapc_save_appenduid(ctx->ctx, reply, &uid);
170
173
                imapc_save_add_to_index(ctx->ctx, uid);
171
174
                ctx->ret = 0;
178
181
                        "imapc: COPY failed: %s", reply->text_full);
179
182
                ctx->ret = -1;
180
183
        }
181
 
        imapc_client_stop(ctx->ctx->mbox->storage->client);
 
184
        imapc_client_stop(ctx->ctx->mbox->storage->client->client);
 
185
}
 
186
 
 
187
static void
 
188
imapc_save_noop_callback(const struct imapc_command_reply *reply ATTR_UNUSED,
 
189
                         void *context)
 
190
{
 
191
        struct imapc_save_cmd_context *ctx = context;
 
192
 
 
193
        /* we don't really care about the reply */
 
194
        ctx->ret = 0;
 
195
        imapc_client_stop(ctx->ctx->mbox->storage->client->client);
182
196
}
183
197
 
184
198
static void
200
214
static int imapc_save_append(struct imapc_save_context *ctx)
201
215
{
202
216
        struct mail_save_context *_ctx = &ctx->ctx;
 
217
        struct mail_save_data *mdata = &_ctx->data;
203
218
        struct imapc_command *cmd;
204
219
        struct imapc_save_cmd_context sctx;
205
220
        struct istream *input;
206
221
        const char *flags = "", *internaldate = "";
207
222
 
208
 
        if (_ctx->flags != 0 || _ctx->keywords != NULL) {
 
223
        if (mdata->flags != 0 || mdata->keywords != NULL) {
209
224
                string_t *str = t_str_new(64);
210
225
 
211
226
                str_append(str, " (");
212
 
                imap_write_flags(str, _ctx->flags & ~MAIL_RECENT, NULL);
213
 
                if (_ctx->keywords != NULL)
214
 
                        imapc_append_keywords(str, _ctx->keywords);
 
227
                imap_write_flags(str, mdata->flags & ~MAIL_RECENT, NULL);
 
228
                if (mdata->keywords != NULL)
 
229
                        imapc_append_keywords(str, mdata->keywords);
215
230
                str_append_c(str, ')');
216
231
                flags = str_c(str);
217
232
        }
218
 
        if (_ctx->received_date != (time_t)-1) {
 
233
        if (mdata->received_date != (time_t)-1) {
219
234
                internaldate = t_strdup_printf(" \"%s\"",
220
 
                        imap_to_datetime(_ctx->received_date));
 
235
                        imap_to_datetime(mdata->received_date));
221
236
        }
222
237
 
 
238
        ctx->mbox->exists_received = FALSE;
 
239
 
223
240
        input = i_stream_create_fd(ctx->fd, IO_BLOCK_SIZE, FALSE);
224
241
        sctx.ctx = ctx;
225
242
        sctx.ret = -2;
226
 
        cmd = imapc_client_cmd(ctx->mbox->storage->client,
 
243
        cmd = imapc_client_cmd(ctx->mbox->storage->client->client,
227
244
                               imapc_save_callback, &sctx);
228
245
        imapc_command_sendf(cmd, "APPEND %s%1s%1s %p",
229
246
                            ctx->mbox->box.name, flags, internaldate, input);
230
247
        i_stream_unref(&input);
231
248
        while (sctx.ret == -2)
232
 
                imapc_storage_run(ctx->mbox->storage);
 
249
                imapc_mailbox_run(ctx->mbox);
 
250
 
 
251
        if (sctx.ret == 0 && ctx->mbox->selected &&
 
252
            !ctx->mbox->exists_received) {
 
253
                /* e.g. Courier doesn't send EXISTS reply before the tagged
 
254
                   APPEND reply. That isn't exactly required by the IMAP RFC,
 
255
                   but it makes the behavior better. See if NOOP finds
 
256
                   the mail. */
 
257
                sctx.ret = -2;
 
258
                cmd = imapc_client_cmd(ctx->mbox->storage->client->client,
 
259
                                       imapc_save_noop_callback, &sctx);
 
260
                imapc_command_send(cmd, "NOOP");
 
261
                while (sctx.ret == -2)
 
262
                        imapc_mailbox_run(ctx->mbox);
 
263
        }
233
264
        return sctx.ret;
234
265
}
235
266
 
241
272
        ctx->finished = TRUE;
242
273
 
243
274
        if (!ctx->failed) {
244
 
                if (o_stream_flush(_ctx->output) < 0) {
 
275
                if (o_stream_nfinish(_ctx->data.output) < 0) {
245
276
                        if (!mail_storage_set_error_from_errno(storage)) {
246
277
                                mail_storage_set_critical(storage,
247
 
                                        "o_stream_flush(%s) failed: %m",
248
 
                                        ctx->temp_path);
 
278
                                        "write(%s) failed: %m", ctx->temp_path);
249
279
                        }
250
280
                        ctx->failed = TRUE;
251
281
                }
256
286
                        ctx->failed = TRUE;
257
287
        }
258
288
 
259
 
        if (_ctx->output != NULL)
260
 
                o_stream_unref(&_ctx->output);
 
289
        if (_ctx->data.output != NULL)
 
290
                o_stream_unref(&_ctx->data.output);
261
291
        if (ctx->input != NULL)
262
292
                i_stream_unref(&ctx->input);
263
293
        if (ctx->fd != -1) {
342
372
                return;
343
373
 
344
374
        if (str_to_uint32(args[2], &dest_uid) == 0) {
345
 
                seq_range_array_add(&ctx->dest_saved_uids, 0, dest_uid);
 
375
                seq_range_array_add_with_init(&ctx->dest_saved_uids,
 
376
                                              32, dest_uid);
346
377
                *uid_r = dest_uid;
347
378
        }
348
379
}
354
385
        uint32_t uid = 0;
355
386
 
356
387
        if (reply->state == IMAPC_COMMAND_STATE_OK) {
357
 
                if (strcasecmp(reply->resp_text_key, "COPYUID") == 0)
 
388
                if (reply->resp_text_key != NULL &&
 
389
                    strcasecmp(reply->resp_text_key, "COPYUID") == 0)
358
390
                        imapc_save_copyuid(ctx->ctx, reply, &uid);
359
391
                imapc_save_add_to_index(ctx->ctx, uid);
360
392
                ctx->ret = 0;
367
399
                        "imapc: COPY failed: %s", reply->text_full);
368
400
                ctx->ret = -1;
369
401
        }
370
 
        imapc_client_stop(ctx->ctx->mbox->storage->client);
 
402
        imapc_client_stop(ctx->ctx->mbox->storage->client->client);
371
403
}
372
404
 
373
405
int imapc_copy(struct mail_save_context *_ctx, struct mail *mail)
389
421
                imapc_command_sendf(cmd, "UID COPY %u %s",
390
422
                                    mail->uid, _t->box->name);
391
423
                while (sctx.ret == -2)
392
 
                        imapc_storage_run(src_mbox->storage);
 
424
                        imapc_mailbox_run(src_mbox);
393
425
                ctx->finished = TRUE;
 
426
                index_save_context_free(_ctx);
394
427
                return sctx.ret;
395
428
        }
396
429
        return mail_storage_copy(_ctx, mail);