~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/plugins/pop3-migration/pop3-migration-plugin.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
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 "array.h"
43
43
        union mail_storage_module_context module_ctx;
44
44
 
45
45
        const char *pop3_box_vname;
46
 
        struct mailbox *pop3_box;
47
 
        ARRAY_DEFINE(pop3_uidl_map, struct pop3_uidl_map);
 
46
        ARRAY(struct pop3_uidl_map) pop3_uidl_map;
48
47
 
49
48
        unsigned int all_mailboxes:1;
50
49
        unsigned int pop3_all_hdr_sha1_set:1;
53
52
struct pop3_migration_mailbox {
54
53
        union mailbox_module_context module_ctx;
55
54
 
56
 
        ARRAY_DEFINE(imap_msg_map, struct imap_msg_map);
 
55
        ARRAY(struct imap_msg_map) imap_msg_map;
57
56
        unsigned int first_unfound_idx;
58
57
 
59
58
        unsigned int uidl_synced:1;
72
71
        "X-UID",
73
72
        "X-UIDL"
74
73
};
75
 
const char *pop3_migration_plugin_version = DOVECOT_VERSION;
 
74
const char *pop3_migration_plugin_version = DOVECOT_ABI_VERSION;
76
75
 
77
76
static MODULE_CONTEXT_DEFINE_INIT(pop3_migration_storage_module,
78
77
                                  &mail_storage_module_register);
130
129
                                HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR,
131
130
                                hdr_hash_skip_headers,
132
131
                                N_ELEMENTS(hdr_hash_skip_headers),
133
 
                                null_header_filter_callback, NULL);
 
132
                                *null_header_filter_callback, (void *)NULL);
134
133
        i_stream_unref(&input2);
135
134
 
136
135
        sha1_init(&sha1_ctx);
149
148
        return 0;
150
149
}
151
150
 
152
 
static int pop3_mailbox_open(struct mail_storage *storage)
 
151
static struct mailbox *pop3_mailbox_alloc(struct mail_storage *storage)
153
152
{
154
153
        struct pop3_migration_mail_storage *mstorage =
155
154
                POP3_MIGRATION_CONTEXT(storage);
156
155
        struct mail_namespace *ns;
157
156
 
158
 
        if (mstorage->pop3_box != NULL)
159
 
                return 0;
160
 
 
161
157
        ns = mail_namespace_find(storage->user->namespaces,
162
158
                                 mstorage->pop3_box_vname);
163
 
        if (ns == NULL) {
164
 
                i_error("pop3_migration: Namespace not found for mailbox %s",
165
 
                        mstorage->pop3_box_vname);
166
 
                return -1;
167
 
        }
168
 
        mstorage->pop3_box = mailbox_alloc(ns->list, mstorage->pop3_box_vname,
169
 
                                           MAILBOX_FLAG_READONLY |
170
 
                                           MAILBOX_FLAG_POP3_SESSION);
171
 
        mstorage->all_mailboxes =
172
 
                mail_user_plugin_getenv(storage->user,
173
 
                                        "pop3_migration_all_mailboxes") != NULL;
174
 
        return 0;
 
159
        i_assert(ns != NULL);
 
160
        return mailbox_alloc(ns->list, mstorage->pop3_box_vname,
 
161
                             MAILBOX_FLAG_READONLY | MAILBOX_FLAG_POP3_SESSION);
175
162
}
176
163
 
177
 
static int pop3_map_read(struct mail_storage *storage)
 
164
static int pop3_map_read(struct mail_storage *storage, struct mailbox *pop3_box)
178
165
{
179
166
        struct pop3_migration_mail_storage *mstorage =
180
167
                POP3_MIGRATION_CONTEXT(storage);
181
 
        struct mailbox *pop3_box = mstorage->pop3_box;
182
168
        struct mailbox_transaction_context *t;
183
169
        struct mail_search_args *search_args;
184
170
        struct mail_search_context *ctx;
242
228
        return ret;
243
229
}
244
230
 
245
 
static int pop3_map_read_hdr_hashes(struct mail_storage *storage,
246
 
                                    unsigned first_seq)
 
231
static int
 
232
pop3_map_read_hdr_hashes(struct mail_storage *storage, struct mailbox *pop3_box,
 
233
                         unsigned first_seq)
247
234
{
248
235
        struct pop3_migration_mail_storage *mstorage =
249
236
                POP3_MIGRATION_CONTEXT(storage);
262
249
                first_seq = 1;
263
250
        }
264
251
 
265
 
        t = mailbox_transaction_begin(mstorage->pop3_box, 0);
 
252
        t = mailbox_transaction_begin(pop3_box, 0);
266
253
        search_args = mail_search_build_init();
267
254
        mail_search_build_add_seqset(search_args, first_seq,
268
255
                                     array_count(&mstorage->pop3_uidl_map)+1);
395
382
        return i == count;
396
383
}
397
384
 
398
 
static int pop3_uidl_assign_by_hdr_hash(struct mailbox *box)
 
385
static int
 
386
pop3_uidl_assign_by_hdr_hash(struct mailbox *box, struct mailbox *pop3_box)
399
387
{
400
388
        struct pop3_migration_mail_storage *mstorage =
401
389
                POP3_MIGRATION_CONTEXT(box->storage);
407
395
        int ret;
408
396
 
409
397
        first_seq = mbox->first_unfound_idx+1;
410
 
        if (pop3_map_read_hdr_hashes(box->storage, first_seq) < 0 ||
 
398
        if (pop3_map_read_hdr_hashes(box->storage, pop3_box, first_seq) < 0 ||
411
399
            imap_map_read_hdr_hashes(box) < 0)
412
400
                return -1;
413
401
 
463
451
        struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT(box);
464
452
        struct pop3_migration_mail_storage *mstorage =
465
453
                POP3_MIGRATION_CONTEXT(box->storage);
 
454
        struct mailbox *pop3_box;
466
455
        const struct pop3_uidl_map *pop3_map;
467
456
        unsigned int i, count;
468
457
        uint32_t prev_uid;
470
459
        if (mbox->uidl_synced)
471
460
                return 0;
472
461
 
473
 
        if (pop3_mailbox_open(box->storage) < 0)
474
 
                return -1;
475
 
 
476
 
        if (pop3_map_read(box->storage) < 0 || imap_map_read(box) < 0)
477
 
                return -1;
 
462
        pop3_box = pop3_mailbox_alloc(box->storage);
 
463
        /* the POP3 server isn't connected to yet. handle all IMAP traffic
 
464
           first before connecting, so POP3 server won't disconnect us due to
 
465
           idling. */
 
466
        if (imap_map_read(box) < 0 ||
 
467
            pop3_map_read(box->storage, pop3_box) < 0) {
 
468
                mailbox_free(&pop3_box);
 
469
                return -1;
 
470
        }
478
471
 
479
472
        if (!pop3_uidl_assign_by_size(box)) {
480
473
                /* everything wasn't assigned, figure out the rest with
481
474
                   header hashes */
482
 
                if (pop3_uidl_assign_by_hdr_hash(box) < 0)
 
475
                if (pop3_uidl_assign_by_hdr_hash(box, pop3_box) < 0) {
 
476
                        mailbox_free(&pop3_box);
483
477
                        return -1;
 
478
                }
484
479
        }
485
480
 
486
481
        /* see if the POP3 UIDL order is the same as IMAP UID order */
499
494
        }
500
495
 
501
496
        mbox->uidl_synced = TRUE;
 
497
        mailbox_free(&pop3_box);
502
498
        return 0;
503
499
}
504
500
 
585
581
        struct pop3_migration_mail_storage *mstorage =
586
582
                POP3_MIGRATION_CONTEXT(storage);
587
583
 
588
 
        if (mstorage->pop3_box != NULL)
589
 
                mailbox_free(&mstorage->pop3_box);
590
584
        if (array_is_created(&mstorage->pop3_uidl_map))
591
585
                array_free(&mstorage->pop3_uidl_map);
592
586
 
593
 
        if (mstorage->module_ctx.super.destroy != NULL)
594
 
                mstorage->module_ctx.super.destroy(storage);
 
587
        mstorage->module_ctx.super.destroy(storage);
595
588
}
596
589
 
597
590
static void pop3_migration_mail_storage_created(struct mail_storage *storage)
611
604
        v->destroy = pop3_migration_mail_storage_destroy;
612
605
 
613
606
        mstorage->pop3_box_vname = p_strdup(storage->pool, pop3_box_vname);
 
607
        mstorage->all_mailboxes =
 
608
                mail_user_plugin_getenv(storage->user,
 
609
                                        "pop3_migration_all_mailboxes") != NULL;
614
610
 
615
611
        MODULE_CONTEXT_SET(storage, pop3_migration_storage_module, mstorage);
616
612
}