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

« back to all changes in this revision

Viewing changes to src/lib-storage/index/index-thread.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) 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
/* doc/thread-refs.txt describes the incremental algorithm we use here. */
4
4
 
28
28
        ARRAY_TYPE(seq_range) added_uids;
29
29
 
30
30
        unsigned int failed:1;
 
31
        unsigned int corrupted:1;
31
32
};
32
33
 
33
34
struct mail_thread_mailbox {
52
53
static void mail_thread_clear(struct mail_thread_context *ctx);
53
54
 
54
55
static int
55
 
mail_strmap_rec_get_msgid(struct mail *mail,
 
56
mail_strmap_rec_get_msgid(struct mail_thread_context *ctx,
56
57
                          const struct mail_index_strmap_rec *rec,
57
58
                          const char **msgid_r)
58
59
{
 
60
        struct mail *mail = ctx->tmp_mail;
59
61
        const char *msgids = NULL, *msgid;
60
62
        unsigned int n = 0;
61
63
        int ret;
91
93
        /* get the nth message-id */
92
94
        msgid = message_id_get_next(&msgids);
93
95
        if (msgid != NULL) {
94
 
                for (; n > 0 && *msgids != '\0'; n--)
 
96
                for (; n > 0; n--)
95
97
                        msgid = message_id_get_next(&msgids);
96
98
        }
97
99
 
98
100
        if (msgid == NULL) {
99
 
                /* shouldn't have happened */
 
101
                /* shouldn't have happened, probably corrupted */
100
102
                mail_storage_set_critical(mail->box->storage,
101
 
                                          "Threading lost Message ID");
 
103
                        "Corrupted thread index for mailbox %s: "
 
104
                        "UID %u lost Message ID %u",
 
105
                        mail->box->vname, mail->uid, rec->ref_index);
 
106
                ctx->failed = TRUE;
 
107
                ctx->corrupted = TRUE;
102
108
                return -1;
103
109
        }
104
110
        *msgid_r = msgid;
118
124
 
119
125
        /* either a match or a collision, need to look closer */
120
126
        T_BEGIN {
121
 
                ret = mail_strmap_rec_get_msgid(ctx->tmp_mail, rec, &msgid);
 
127
                ret = mail_strmap_rec_get_msgid(ctx, rec, &msgid);
122
128
                if (ret <= 0) {
123
129
                        if (ret < 0)
124
130
                                ctx->failed = TRUE;
141
147
        int ret;
142
148
 
143
149
        T_BEGIN {
144
 
                ret = mail_strmap_rec_get_msgid(ctx->tmp_mail, rec1, &msgid1);
 
150
                ret = mail_strmap_rec_get_msgid(ctx, rec1, &msgid1);
145
151
                if (ret > 0) {
146
152
                        msgid1 = t_strdup(msgid1);
147
 
                        ret = mail_strmap_rec_get_msgid(ctx->tmp_mail, rec2,
148
 
                                                        &msgid2);
 
153
                        ret = mail_strmap_rec_get_msgid(ctx, rec2, &msgid2);
149
154
                }
150
155
                ret = ret <= 0 ? -1 :
151
156
                        strcmp(msgid1, msgid2) == 0;
352
357
        return ret;
353
358
}
354
359
 
355
 
static int msgid_map_cmp(const void *key, const void *value)
 
360
static int msgid_map_cmp(const uint32_t *uid,
 
361
                         const struct mail_index_strmap_rec *rec)
356
362
{
357
 
        const uint32_t *uid = key;
358
 
        const struct mail_index_strmap_rec *rec = value;
359
 
 
360
363
        return *uid < rec->uid ? -1 :
361
364
                (*uid > rec->uid ? 1 : 0);
362
365
}
387
390
        uids = array_get(&removed_uids, &uid_count);
388
391
        for (i = j = 0; i < uid_count; i++) {
389
392
                /* find and remove from the map */
390
 
                bsearch_insert_pos(&uids[i].seq1, &msgid_map[j], map_count - j,
391
 
                                   sizeof(*msgid_map), msgid_map_cmp, &idx);
 
393
                bsearch_insert_pos(&uids[i].seq1, &msgid_map[j],
 
394
                                   map_count - j, sizeof(*msgid_map),
 
395
                                   msgid_map_cmp, &idx);
392
396
                j += idx;
393
397
                if (j == map_count) {
394
398
                        /* all removals after this are about messages we never
567
571
                mail_thread_cache_sync_add(tbox, ctx, search_ctx);
568
572
        if (mailbox_search_deinit(&search_ctx) < 0)
569
573
                ret = -1;
570
 
 
 
574
        if (ctx->failed) {
 
575
                ret = -1;
 
576
                if (ctx->corrupted)
 
577
                        mail_index_strmap_view_set_corrupted(tbox->strmap_view);
 
578
        }
571
579
        if (ret < 0) {
572
580
                mail_thread_deinit(&ctx);
573
581
                return -1;