~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/lib-index/mail-index-transaction-view.c

  • Committer: Bazaar Package Importer
  • Author(s): CHuck Short, Chuck Short
  • Date: 2009-11-06 00:47:29 UTC
  • mfrom: (4.1.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091106004729-i39n7v9e7d4h51f6
Tags: 1:1.2.6-1ubuntu1
* Merge from debian testing, remaining changes:
  Add new binary pkg dovecot-postfix that integrates postfix and dovecot
  automatically: (LP: #164837)
  + debian/control:
    - add new binary with short description
    - set Architecture all for dovecot-postfix (LP: #329878)
  + debian/dovecot-postfix.postinst:
    - create initial certificate symlinks to snakeoil.
    - set up postfix with postconf to:
      - use Maildir/ as the default mailbox.
      - use dovecot as the sasl authentication server.
      - use dovecot LDA (deliver).
      - use tls for smtp{d} services.
    - fix certificates paths in postfix' main.cf
    - add reject_unauth_destination to postfix' recipient restrictions
    - add reject_unknown_sender_domain to postfix' sender restrictions
    - rename configuration name on remove, delete on purge
    - restart dovecot after linking certificates
    - handle use case when postfix is unconfigurated
   + debian/dovecot-postfix.dirs: create backup directory for postfix's configuration
   + restart postfix and dovecot.
   + debian/dovecot-postfix.postrm:
     - remove all dovecot related configuration from postfix.
     - restart postfix and dovecot.
   + debian/dovecot-common.init:
     - check if /etc/dovecot/dovecot-postfix.conf exists and use it
       as the configuration file if so.
   + debian/patches/warning-ubuntu-postfix.dpatch
     - add warning about dovecot-postfix.conf in dovecot default 
       configuration file
   + debian/patches/dovecot-postfix.conf.diff:
     - Ubuntu server custom changes to the default dovecot configuration for
       better interfation with postfix
     - enable sieve plugin
   + debian/patches/dovecot-postfix.conf.diff:
     + Ubuntu server custom changes to the default dovecot configuration for
       better integration with postfix:
       - enable imap, pop3, imaps, pop3s and managesieve by default.
       - enable dovecot LDA (deliver).
       - enable SASL auth socket in postfix private directory.
   + debian/rules:
     - copy, patch and install dovecot-postfix.conf in /etc/dovecot/.
     - build architecure independent packages too
   + Use Snakeoil SSL certificates by default.
     - debian/control: Depend on ssl-cert.
     - debian/patches/ssl-cert-snakeoil.dpatch: Change default SSL cert
       paths to snakeoil.
     - debian/dovecot-common.postinst: Relax grep for SSL_* a bit.
   + Add autopkgtest to debian/tests/*.
   + Fast TearDown: Update the lsb init header to not stop in level 6.
   + Add ufw integration:
     - Created debian/dovecot-common.ufw.profile.
     - debian/rules:
       + install profile
     - debian/control:
       + Suggest ufw
   + debian/{control,rules}: enable PIE hardening.
   + dovecot-imapd, dovecot-pop3: Replaces dovecot-common (<< 1:1.1). LP: #254721
   + debian/control:
     - Update Vcs-* headers.
   + debian/rules:
     - Create emtpy stamp.h.in files in dovecot-sieve/ and dovecot-managesieve/
       if they're not there since empty files are not included in the diff.gz 
       file.
   + Add SMTP-AUTH support for Outlook (login auth mechanism)
   + Dropped:
     - debian/patches/security-CVE-2009-3235: Applied upstream.
     - debian/patches/fix-pop3-assertion.dpatch: Applied upstream.
     - dovecot-sieve and dovecot-managesieve: Use the debian patches instead.

  [Chuck Short]
  - Updated dovecot-sieve to 0.1.13.
  - Updated dovecot-managesieve to 0.11.9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
        struct mail_index_map *lookup_map;
17
17
        struct mail_index_header hdr;
 
18
 
18
19
        buffer_t *lookup_return_data;
 
20
        uint32_t lookup_prev_seq;
 
21
 
 
22
        unsigned int record_size;
 
23
        unsigned int recs_count;
 
24
        void *recs;
 
25
        ARRAY_DEFINE(all_recs, void *);
19
26
};
20
27
 
21
28
static void tview_close(struct mail_index_view *view)
23
30
        struct mail_index_view_transaction *tview =
24
31
                (struct mail_index_view_transaction *)view;
25
32
        struct mail_index_transaction *t = tview->t;
 
33
        void **recs;
 
34
        unsigned int i, count;
26
35
 
27
36
        if (tview->lookup_map != NULL)
28
37
                mail_index_unmap(&tview->lookup_map);
29
38
        if (tview->lookup_return_data != NULL)
30
39
                buffer_free(&tview->lookup_return_data);
31
40
 
 
41
        if (array_is_created(&tview->all_recs)) {
 
42
                recs = array_get_modifiable(&tview->all_recs, &count);
 
43
                for (i = 0; i < count; i++)
 
44
                        i_free(recs[i]);
 
45
                array_free(&tview->all_recs);
 
46
        }
 
47
 
32
48
        tview->super->close(view);
33
49
        mail_index_transaction_unref(&t);
34
50
}
64
80
}
65
81
 
66
82
static const struct mail_index_record *
 
83
tview_apply_flag_updates(struct mail_index_view_transaction *tview,
 
84
                         struct mail_index_map *map,
 
85
                         const struct mail_index_record *rec, uint32_t seq)
 
86
{
 
87
        struct mail_index_transaction *t = tview->t;
 
88
        const struct mail_transaction_flag_update *updates;
 
89
        struct mail_index_record *trec;
 
90
        unsigned int idx, count;
 
91
 
 
92
        /* see if there are any flag updates */
 
93
        if (seq < t->min_flagupdate_seq || seq > t->max_flagupdate_seq ||
 
94
            !array_is_created(&t->updates))
 
95
                return rec;
 
96
 
 
97
        updates = array_get(&t->updates, &count);
 
98
        idx = mail_index_transaction_get_flag_update_pos(t, 0, count, seq);
 
99
        if (seq < updates[idx].uid1 || seq > updates[idx].uid2)
 
100
                return rec;
 
101
 
 
102
        /* yes, we have flag updates. since we can't modify rec directly and
 
103
           we want to be able to handle multiple mail_index_lookup() calls
 
104
           without the second one overriding the first one's data, we'll
 
105
           create a records array and return data from there.
 
106
 
 
107
           it's also possible that the record size increases, so we potentially
 
108
           have to create multiple arrays. they all get eventually freed when
 
109
           the view gets freed. */
 
110
        if (map->hdr.record_size > tview->record_size) {
 
111
                if (!array_is_created(&tview->all_recs))
 
112
                        i_array_init(&tview->all_recs, 4);
 
113
                tview->recs_count = t->first_new_seq;
 
114
                tview->record_size = I_MAX(map->hdr.record_size,
 
115
                                           tview->view.map->hdr.record_size);
 
116
                tview->recs = i_malloc(tview->record_size *
 
117
                                       tview->recs_count);
 
118
                array_append(&tview->all_recs, &tview->recs, 1);
 
119
        }
 
120
        i_assert(tview->recs_count == t->first_new_seq);
 
121
        i_assert(seq > 0 && seq <= tview->recs_count);
 
122
 
 
123
        trec = PTR_OFFSET(tview->recs, (seq-1) * tview->record_size);
 
124
        memcpy(trec, rec, map->hdr.record_size);
 
125
        trec->flags |= updates[idx].add_flags;
 
126
        trec->flags &= ~updates[idx].remove_flags;
 
127
        return trec;
 
128
}
 
129
 
 
130
static const struct mail_index_record *
67
131
tview_lookup_full(struct mail_index_view *view, uint32_t seq,
68
132
                  struct mail_index_map **map_r, bool *expunged_r)
69
133
{
80
144
        }
81
145
 
82
146
        rec = tview->super->lookup_full(view, seq, map_r, expunged_r);
 
147
        rec = tview_apply_flag_updates(tview, *map_r, rec, seq);
83
148
 
84
 
        /* if we're expunged within this transaction, return 0 */
85
149
        if (array_is_created(&tview->t->expunges) &&
86
150
            seq_range_exists(&tview->t->expunges, seq))
87
151
                *expunged_r = TRUE;
189
253
        }
190
254
}
191
255
 
 
256
static void keyword_index_add(ARRAY_TYPE(keyword_indexes) *keywords,
 
257
                              unsigned int idx)
 
258
{
 
259
        const unsigned int *indexes;
 
260
        unsigned int i, count;
 
261
 
 
262
        indexes = array_get(keywords, &count);
 
263
        for (i = 0; i < count; i++) {
 
264
                if (indexes[i] == idx)
 
265
                        return;
 
266
        }
 
267
        array_append(keywords, &idx, 1);
 
268
}
 
269
 
 
270
static void keyword_index_remove(ARRAY_TYPE(keyword_indexes) *keywords,
 
271
                                 unsigned int idx)
 
272
{
 
273
        const unsigned int *indexes;
 
274
        unsigned int i, count;
 
275
 
 
276
        indexes = array_get(keywords, &count);
 
277
        for (i = 0; i < count; i++) {
 
278
                if (indexes[i] == idx) {
 
279
                        array_delete(keywords, i, 1);
 
280
                        break;
 
281
                }
 
282
        }
 
283
}
 
284
 
 
285
static void tview_lookup_keywords(struct mail_index_view *view, uint32_t seq,
 
286
                                  ARRAY_TYPE(keyword_indexes) *keyword_idx)
 
287
{
 
288
        struct mail_index_view_transaction *tview =
 
289
                (struct mail_index_view_transaction *)view;
 
290
        struct mail_index_transaction *t = tview->t;
 
291
        const struct mail_index_transaction_keyword_update *updates;
 
292
        unsigned int i, count;
 
293
 
 
294
        tview->super->lookup_keywords(view, seq, keyword_idx);
 
295
 
 
296
        if (seq < t->min_flagupdate_seq || seq > t->max_flagupdate_seq) {
 
297
                /* no keyword updates for this sequence */
 
298
                return;
 
299
        }
 
300
 
 
301
        /* apply any keyword updates in this transaction */
 
302
        if (array_is_created(&t->keyword_resets)) {
 
303
                if (seq_range_exists(&t->keyword_resets, seq))
 
304
                        array_clear(keyword_idx);
 
305
        }
 
306
 
 
307
        if (array_is_created(&t->keyword_updates))
 
308
                updates = array_get(&t->keyword_updates, &count);
 
309
        else {
 
310
                updates = NULL;
 
311
                count = 0;
 
312
        }
 
313
        for (i = 0; i < count; i++) {
 
314
                if (array_is_created(&updates[i].add_seq) &&
 
315
                    seq_range_exists(&updates[i].add_seq, seq))
 
316
                        keyword_index_add(keyword_idx, i);
 
317
                else if (array_is_created(&updates[i].remove_seq) &&
 
318
                         seq_range_exists(&updates[i].remove_seq, seq))
 
319
                        keyword_index_remove(keyword_idx, i);
 
320
        }
 
321
}
 
322
 
192
323
static struct mail_index_map *
193
324
tview_get_lookup_map(struct mail_index_view_transaction *tview)
194
325
{
201
332
 
202
333
static const void *
203
334
tview_return_updated_ext(struct mail_index_view_transaction *tview,
204
 
                         const void *data, uint32_t ext_id)
 
335
                         uint32_t seq, const void *data, uint32_t ext_id)
205
336
{
206
337
        const struct mail_index_ext *ext;
207
338
        const struct mail_index_registered_ext *rext;
208
339
        const struct mail_transaction_ext_intro *intro;
209
340
        unsigned int record_align, record_size;
210
341
        uint32_t ext_idx;
 
342
        size_t pos;
211
343
 
212
344
        /* data begins with a 32bit sequence, followed by the actual
213
345
           extension data */
244
376
                        tview->lookup_return_data =
245
377
                                buffer_create_dynamic(default_pool,
246
378
                                                      record_size + 64);
 
379
                } else if (seq != tview->lookup_prev_seq) {
 
380
                        /* clear the buffer between lookups for different
 
381
                           messages */
 
382
                        buffer_set_used_size(tview->lookup_return_data, 0);
247
383
                }
248
 
                buffer_write(tview->lookup_return_data, 0, data, record_size);
249
 
                return tview->lookup_return_data->data;
 
384
                tview->lookup_prev_seq = seq;
 
385
                pos = tview->lookup_return_data->used;
 
386
                buffer_append(tview->lookup_return_data, data, record_size);
 
387
                return CONST_PTR_OFFSET(tview->lookup_return_data->data, pos);
250
388
        }
251
389
}
252
390
 
274
412
                    mail_index_seq_array_lookup(ext_buf, seq, &idx)) {
275
413
                        data = array_idx(ext_buf, idx);
276
414
                        *map_r = tview_get_lookup_map(tview);
277
 
                        *data_r = tview_return_updated_ext(tview, data,
 
415
                        *data_r = tview_return_updated_ext(tview, seq, data,
278
416
                                                           ext_id);
279
417
                        return;
280
418
                }
328
466
        tview_lookup_uid,
329
467
        tview_lookup_seq_range,
330
468
        tview_lookup_first,
 
469
        tview_lookup_keywords,
331
470
        tview_lookup_ext_full,
332
471
        tview_get_header_ext,
333
472
        tview_ext_get_reset_id