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

« back to all changes in this revision

Viewing changes to src/imap/cmd-select.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) 2002-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2002-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "imap-common.h"
4
4
#include "seq-range-array.h"
 
5
#include "time-util.h"
5
6
#include "imap-commands.h"
6
7
#include "mail-search-build.h"
 
8
#include "imap-search-args.h"
7
9
#include "imap-seqset.h"
8
10
#include "imap-fetch.h"
9
11
#include "imap-sync.h"
15
17
        struct mail_namespace *ns;
16
18
        struct mailbox *box;
17
19
 
 
20
        struct timeval start_time;
18
21
        struct imap_fetch_context *fetch_ctx;
19
22
 
20
23
        uint32_t qresync_uid_validity;
197
200
 
198
201
static void cmd_select_finish(struct imap_select_context *ctx, int ret)
199
202
{
 
203
        const char *resp_code;
 
204
        struct timeval end_time;
 
205
        int time_msecs;
 
206
 
200
207
        if (ret < 0) {
201
208
                if (ctx->box != NULL)
202
209
                        mailbox_free(&ctx->box);
203
210
                ctx->cmd->client->mailbox = NULL;
204
211
        } else {
205
 
                client_send_tagline(ctx->cmd, mailbox_is_readonly(ctx->box) ?
206
 
                                    "OK [READ-ONLY] Select completed." :
207
 
                                    "OK [READ-WRITE] Select completed.");
 
212
                resp_code = mailbox_is_readonly(ctx->box) ?
 
213
                        "READ-ONLY" : "READ-WRITE";
 
214
                if (gettimeofday(&end_time, NULL) < 0)
 
215
                        memset(&end_time, 0, sizeof(end_time));
 
216
                time_msecs = timeval_diff_msecs(&end_time, &ctx->start_time);
 
217
                client_send_tagline(ctx->cmd, t_strdup_printf(
 
218
                        "OK [%s] %s completed (%d.%03d secs).", resp_code,
 
219
                        ctx->cmd->client->mailbox_examined ? "Examine" : "Select",
 
220
                        time_msecs/1000, time_msecs%1000));
208
221
        }
209
222
        select_context_free(ctx);
210
223
}
214
227
        struct imap_select_context *ctx = cmd->context;
215
228
        int ret;
216
229
 
217
 
        if (imap_fetch_more(ctx->fetch_ctx) == 0) {
 
230
        if (imap_fetch_more(ctx->fetch_ctx, cmd) == 0) {
218
231
                /* unfinished */
219
232
                return FALSE;
220
233
        }
221
234
 
222
 
        ret = imap_fetch_deinit(ctx->fetch_ctx);
 
235
        ret = imap_fetch_end(ctx->fetch_ctx);
223
236
        if (ret < 0) {
224
237
                client_send_storage_error(ctx->cmd,
225
238
                                          mailbox_get_storage(ctx->box));
226
239
        }
 
240
        imap_fetch_free(&ctx->fetch_ctx);
227
241
        cmd_select_finish(ctx, ret);
228
242
        return TRUE;
229
243
}
232
246
{
233
247
        struct imap_fetch_context *fetch_ctx;
234
248
        struct mail_search_args *search_args;
 
249
        struct imap_fetch_qresync_args qresync_args;
235
250
 
236
251
        search_args = mail_search_build_init();
237
252
        search_args->args = p_new(search_args->pool, struct mail_search_arg, 1);
238
253
        search_args->args->type = SEARCH_UIDSET;
239
254
        search_args->args->value.seqset = ctx->qresync_known_uids;
240
 
 
241
 
        fetch_ctx = imap_fetch_init(ctx->cmd, ctx->box);
242
 
        if (fetch_ctx == NULL)
243
 
                return -1;
244
 
 
245
 
        fetch_ctx->search_args = search_args;
246
 
        fetch_ctx->send_vanished = TRUE;
247
 
        fetch_ctx->qresync_sample_seqset = &ctx->qresync_sample_seqset;
248
 
        fetch_ctx->qresync_sample_uidset = &ctx->qresync_sample_uidset;
249
 
 
250
 
        if (!imap_fetch_add_changed_since(fetch_ctx, ctx->qresync_modseq) ||
251
 
            !imap_fetch_init_handler(fetch_ctx, "UID", NULL) ||
252
 
            !imap_fetch_init_handler(fetch_ctx, "FLAGS", NULL) ||
253
 
            !imap_fetch_init_handler(fetch_ctx, "MODSEQ", NULL)) {
254
 
                (void)imap_fetch_deinit(fetch_ctx);
255
 
                return -1;
256
 
        }
257
 
 
258
 
        if (imap_fetch_begin(fetch_ctx) == 0) {
259
 
                if (imap_fetch_more(fetch_ctx) == 0) {
260
 
                        /* unfinished */
261
 
                        ctx->fetch_ctx = fetch_ctx;
262
 
                        ctx->cmd->state = CLIENT_COMMAND_STATE_WAIT_OUTPUT;
263
 
 
264
 
                        ctx->cmd->func = cmd_select_continue;
265
 
                        ctx->cmd->context = ctx;
266
 
                        return 0;
267
 
                }
268
 
        }
269
 
 
270
 
        return imap_fetch_deinit(fetch_ctx) < 0 ? -1 : 1;
 
255
        imap_search_add_changed_since(search_args, ctx->qresync_modseq);
 
256
 
 
257
        memset(&qresync_args, 0, sizeof(qresync_args));
 
258
        qresync_args.qresync_sample_seqset = &ctx->qresync_sample_seqset;
 
259
        qresync_args.qresync_sample_uidset = &ctx->qresync_sample_uidset;
 
260
 
 
261
        if (imap_fetch_send_vanished(ctx->cmd->client, ctx->box,
 
262
                                     search_args, &qresync_args) < 0) {
 
263
                mail_search_args_unref(&search_args);
 
264
                return -1;
 
265
        }
 
266
 
 
267
        fetch_ctx = imap_fetch_alloc(ctx->cmd->client, ctx->cmd->pool);
 
268
 
 
269
        imap_fetch_init_nofail_handler(fetch_ctx, imap_fetch_uid_init);
 
270
        imap_fetch_init_nofail_handler(fetch_ctx, imap_fetch_flags_init);
 
271
        imap_fetch_init_nofail_handler(fetch_ctx, imap_fetch_modseq_init);
 
272
 
 
273
        imap_fetch_begin(fetch_ctx, ctx->box, search_args);
 
274
        mail_search_args_unref(&search_args);
 
275
 
 
276
        if (imap_fetch_more(fetch_ctx, ctx->cmd) == 0) {
 
277
                /* unfinished */
 
278
                ctx->fetch_ctx = fetch_ctx;
 
279
                ctx->cmd->state = CLIENT_COMMAND_STATE_WAIT_OUTPUT;
 
280
 
 
281
                ctx->cmd->func = cmd_select_continue;
 
282
                ctx->cmd->context = ctx;
 
283
                return 0;
 
284
        }
 
285
        if (imap_fetch_end(fetch_ctx) < 0)
 
286
                return -1;
 
287
        imap_fetch_free(&fetch_ctx);
 
288
        return 1;
271
289
}
272
290
 
273
291
static int
304
322
                                STATUS_HIGHESTMODSEQ, &status);
305
323
 
306
324
        client->mailbox = ctx->box;
307
 
        client->select_counter++;
308
325
        client->mailbox_examined = readonly;
309
326
        client->messages_count = status.messages;
310
327
        client->recent_count = status.recent;
311
328
        client->uidvalidity = status.uidvalidity;
 
329
        client->notify_uidnext = status.uidnext;
312
330
 
313
331
        client_update_mailbox_flags(client, status.keywords);
314
332
        client_send_mailbox_flags(client, TRUE);
376
394
        struct client *client = cmd->client;
377
395
        struct imap_select_context *ctx;
378
396
        const struct imap_arg *args, *list_args;
379
 
        const char *mailbox;
 
397
        const char *mailbox, *error;
380
398
        int ret;
381
399
 
382
400
        /* <mailbox> [(optional parameters)] */
384
402
                return FALSE;
385
403
 
386
404
        if (!imap_arg_get_astring(args, &mailbox)) {
 
405
                close_selected_mailbox(client);
387
406
                client_send_command_error(cmd, "Invalid arguments.");
388
 
                close_selected_mailbox(client);
389
407
                return FALSE;
390
408
        }
391
409
 
392
410
        ctx = p_new(cmd->pool, struct imap_select_context, 1);
393
411
        ctx->cmd = cmd;
394
 
        ctx->ns = client_find_namespace(cmd, &mailbox);
 
412
        ctx->ns = client_find_namespace_full(cmd->client, &mailbox, &error);
395
413
        if (ctx->ns == NULL) {
396
414
                close_selected_mailbox(client);
 
415
                client_send_tagline(cmd, error);
397
416
                return TRUE;
398
417
        }
 
418
        (void)gettimeofday(&ctx->start_time, NULL);
399
419
 
400
420
        if (imap_arg_get_list(&args[1], &list_args)) {
401
421
                if (!select_parse_options(ctx, list_args)) {