~ubuntu-dev/ubuntu/lucid/dovecot/lucid-201002101918

« back to all changes in this revision

Viewing changes to src/lib-storage/index/index-mail.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:
13
13
#include "imap-bodystructure.h"
14
14
#include "imap-envelope.h"
15
15
#include "mail-cache.h"
 
16
#include "mail-index-modseq.h"
16
17
#include "index-storage.h"
 
18
#include "istream-mail-stats.h"
17
19
#include "index-mail.h"
18
20
 
19
21
struct mail_cache_field global_cache_fields[MAIL_INDEX_CACHE_FIELD_COUNT] = {
32
34
        { "imap.bodystructure", 0, MAIL_CACHE_FIELD_STRING, 0, 0 },
33
35
        { "imap.envelope", 0, MAIL_CACHE_FIELD_STRING, 0, 0 },
34
36
        { "pop3.uidl", 0, MAIL_CACHE_FIELD_STRING, 0, 0 },
 
37
        { "guid", 0, MAIL_CACHE_FIELD_STRING, 0, 0 },
35
38
        { "mime.parts", 0, MAIL_CACHE_FIELD_VARIABLE_SIZE, 0, 0 }
36
39
};
37
40
 
38
41
static int index_mail_parse_body(struct index_mail *mail,
39
42
                                 enum index_cache_field field);
40
43
 
 
44
int index_mail_cache_lookup_field(struct index_mail *mail, buffer_t *buf,
 
45
                                  unsigned int field_idx)
 
46
{
 
47
        int ret;
 
48
 
 
49
        ret = mail_cache_lookup_field(mail->trans->cache_view, buf,
 
50
                                      mail->data.seq, field_idx);
 
51
        if (ret > 0)
 
52
                mail->mail.stats_cache_hit_count++;
 
53
        return ret;
 
54
}
 
55
 
41
56
static struct message_part *get_unserialized_parts(struct index_mail *mail)
42
57
{
43
58
        unsigned int field_idx =
48
63
        int ret;
49
64
 
50
65
        part_buf = buffer_create_dynamic(pool_datastack_create(), 128);
51
 
        ret = mail_cache_lookup_field(mail->trans->cache_view, part_buf,
52
 
                                      mail->data.seq, field_idx);
 
66
        ret = index_mail_cache_lookup_field(mail, part_buf, field_idx);
53
67
        if (ret <= 0)
54
68
                return NULL;
55
69
 
98
112
                buf = buffer_create_data(pool_datastack_create(),
99
113
                                         data, data_size);
100
114
 
101
 
                if (mail_cache_lookup_field(mail->trans->cache_view, buf,
102
 
                                            mail->data.seq, field_idx) <= 0)
 
115
                if (index_mail_cache_lookup_field(mail, buf, field_idx) <= 0)
103
116
                        ret = FALSE;
104
117
                else {
105
118
                        i_assert(buf->used == data_size);
120
133
enum mail_flags index_mail_get_flags(struct mail *_mail)
121
134
{
122
135
        struct index_mail *mail = (struct index_mail *)_mail;
123
 
        struct index_mail_data *data = &mail->data;
 
136
        const struct mail_index_record *rec;
 
137
        enum mail_flags flags;
 
138
 
 
139
        rec = mail_index_lookup(mail->trans->trans_view, _mail->seq);
 
140
        flags = rec->flags & (MAIL_FLAGS_NONRECENT |
 
141
                              MAIL_INDEX_MAIL_FLAG_BACKEND);
124
142
 
125
143
        if (index_mailbox_is_recent(mail->ibox, _mail->uid))
126
 
                data->flags |= MAIL_RECENT;
127
 
 
128
 
        return data->flags;
 
144
                flags |= MAIL_RECENT;
 
145
 
 
146
        return flags;
 
147
}
 
148
 
 
149
uint64_t index_mail_get_modseq(struct mail *_mail)
 
150
{
 
151
        struct index_mail *mail = (struct index_mail *)_mail;
 
152
 
 
153
        if (mail->data.modseq != 0)
 
154
                return mail->data.modseq;
 
155
 
 
156
        mail_index_modseq_enable(mail->ibox->index);
 
157
        mail->data.modseq =
 
158
                mail_index_modseq_lookup(mail->trans->trans_view, _mail->seq);
 
159
        return mail->data.modseq;
129
160
}
130
161
 
131
162
const char *const *index_mail_get_keywords(struct mail *_mail)
165
196
 
166
197
        if (!array_is_created(&data->keyword_indexes)) {
167
198
                p_array_init(&data->keyword_indexes, mail->data_pool, 32);
168
 
                mail_index_lookup_keywords(mail->ibox->view, mail->data.seq,
 
199
                mail_index_lookup_keywords(mail->trans->trans_view,
 
200
                                           mail->data.seq,
169
201
                                           &data->keyword_indexes);
170
202
        }
171
203
        return &data->keyword_indexes;
407
439
                        return;
408
440
        }
409
441
 
410
 
        if (!mail->data.no_caching) {
 
442
        if (!mail->data.no_caching &&
 
443
            mail->data.dont_cache_field_idx != field_idx) {
411
444
                mail_cache_add(mail->trans->cache_trans, mail->data.seq,
412
445
                               field_idx, data, data_size);
413
446
        }
774
807
        mail->data.destroying_stream = FALSE;
775
808
}
776
809
 
 
810
void index_mail_set_read_buffer_size(struct mail *_mail, struct istream *input)
 
811
{
 
812
        struct index_mail *mail = (struct index_mail *)_mail;
 
813
        unsigned int block_size;
 
814
 
 
815
        i_stream_set_max_buffer_size(input, MAIL_READ_FULL_BLOCK_SIZE);
 
816
        block_size = (mail->data.access_part & READ_BODY) != 0 ?
 
817
                MAIL_READ_FULL_BLOCK_SIZE : MAIL_READ_HDR_BLOCK_SIZE;
 
818
        i_stream_set_init_buffer_size(input, block_size);
 
819
}
 
820
 
777
821
int index_mail_init_stream(struct index_mail *mail,
778
822
                           struct message_size *hdr_size,
779
823
                           struct message_size *body_size,
780
824
                           struct istream **stream_r)
781
825
{
782
826
        struct index_mail_data *data = &mail->data;
 
827
        struct istream *input;
783
828
        int ret;
784
829
 
 
830
        if (!data->initialized_wrapper_stream && mail->mail.stats_track) {
 
831
                input = i_stream_create_mail_stats_counter(&mail->mail,
 
832
                                                           data->stream);
 
833
                i_stream_unref(&data->stream);
 
834
                data->stream = input;
 
835
                data->initialized_wrapper_stream = TRUE;
 
836
        }
 
837
 
785
838
        i_stream_set_destroy_callback(data->stream,
786
839
                                      index_mail_stream_destroy_callback, mail);
787
840
 
931
984
                    get_cached_parts(mail)) {
932
985
                        index_mail_get_plain_bodystructure(mail, str, FALSE);
933
986
                        data->body = str_c(str);
934
 
                } else if (mail_cache_lookup_field(mail->trans->cache_view, str,
935
 
                                        mail->data.seq, body_cache_field) > 0)
 
987
                } else if (index_mail_cache_lookup_field(mail, str,
 
988
                                                         body_cache_field) > 0)
936
989
                        data->body = str_c(str);
937
 
                else if (mail_cache_lookup_field(mail->trans->cache_view, str,
938
 
                                        mail->data.seq,
 
990
                else if (index_mail_cache_lookup_field(mail, str,
939
991
                                        bodystructure_cache_field) > 0) {
940
992
                        data->bodystructure =
941
993
                                p_strdup(mail->data_pool, str_c(str));
976
1028
                    get_cached_parts(mail)) {
977
1029
                        index_mail_get_plain_bodystructure(mail, str, TRUE);
978
1030
                        data->bodystructure = str_c(str);
979
 
                } else if (mail_cache_lookup_field(mail->trans->cache_view, str,
980
 
                                        mail->data.seq,
 
1031
                } else if (index_mail_cache_lookup_field(mail, str,
981
1032
                                        bodystructure_cache_field) > 0) {
982
1033
                        data->bodystructure = str_c(str);
983
1034
                } else {
1001
1052
        case MAIL_FETCH_UIDL_FILE_NAME:
1002
1053
        case MAIL_FETCH_UIDL_BACKEND:
1003
1054
        case MAIL_FETCH_SEARCH_SCORE:
 
1055
        case MAIL_FETCH_GUID:
1004
1056
                *value_r = "";
1005
1057
                return 0;
1006
1058
        case MAIL_FETCH_HEADER_MD5:
1013
1065
                }
1014
1066
                *value_r = binary_to_hex(ext_data, 16);
1015
1067
                return 0;
 
1068
        case MAIL_FETCH_MAILBOX_NAME:
 
1069
                *value_r = _mail->box->name;
 
1070
                return 0;
1016
1071
        default:
1017
1072
                i_unreached();
1018
1073
                return -1;
1052
1107
        mail->mail.v = *t->ibox->mail_vfuncs;
1053
1108
        mail->mail.mail.box = &t->ibox->box;
1054
1109
        mail->mail.mail.transaction = &t->mailbox_ctx;
 
1110
        mail->mail.wanted_fields = wanted_fields;
 
1111
        mail->mail.wanted_headers = _wanted_headers;
1055
1112
 
1056
1113
        hdr = mail_index_get_header(t->ibox->view);
1057
1114
        mail->uid_validity = hdr->uid_validity;
1061
1118
        mail->ibox = t->ibox;
1062
1119
        mail->trans = t;
1063
1120
        mail->wanted_fields = wanted_fields;
1064
 
        mail->wanted_headers = wanted_headers;
 
1121
        if (wanted_headers != NULL) {
 
1122
                mail->wanted_headers = wanted_headers;
 
1123
                mailbox_header_lookup_ref(_wanted_headers);
 
1124
        }
1065
1125
}
1066
1126
 
1067
1127
void index_mail_close(struct mail *_mail)
1108
1168
        data->save_date = (time_t)-1;
1109
1169
        data->received_date = (time_t)-1;
1110
1170
        data->sent_date.time = (uint32_t)-1;
 
1171
        data->dont_cache_field_idx = -1U;
1111
1172
 
1112
1173
        mail->mail.mail.seq = 0;
1113
1174
        mail->mail.mail.uid = 0;
1151
1212
        struct index_mail *mail = (struct index_mail *)_mail;
1152
1213
        struct index_mail_data *data = &mail->data;
1153
1214
        struct mail_cache_field *cache_fields = mail->ibox->cache_fields;
1154
 
        struct mail_cache_view *cache_view = mail->trans->cache_view;
 
1215
        struct mail_cache_view *cache_view = mail->trans->cache_view;
1155
1216
        const struct mail_index_header *hdr;
1156
 
        const struct mail_index_record *rec;
1157
1217
        struct istream *input;
1158
1218
 
1159
1219
        if (data->seq == seq)
1161
1221
 
1162
1222
        index_mail_reset(mail);
1163
1223
 
1164
 
        rec = mail_index_lookup(mail->trans->trans_view, seq);
1165
1224
        data->seq = seq;
1166
 
        data->flags = rec->flags & (MAIL_FLAGS_NONRECENT |
1167
 
                                    MAIL_INDEX_MAIL_FLAG_BACKEND);
1168
1225
 
1169
1226
        mail->mail.mail.seq = seq;
1170
 
        mail->mail.mail.uid = rec->uid;
 
1227
        mail_index_lookup_uid(mail->trans->trans_view, seq,
 
1228
                              &mail->mail.mail.uid);
1171
1229
 
1172
1230
        if (mail_index_view_is_inconsistent(mail->trans->trans_view)) {
1173
1231
                mail_set_expunged(&mail->mail.mail);
1248
1306
                if (mail_cache_field_exists(cache_view, seq,
1249
1307
                                            cache_field) <= 0) {
1250
1308
                        data->access_part |= PARSE_HDR;
1251
 
                        data->save_sent_date = TRUE;;
 
1309
                        data->save_sent_date = TRUE;
1252
1310
                }
1253
1311
        }
1254
1312
 
1288
1346
void index_mail_free(struct mail *_mail)
1289
1347
{
1290
1348
        struct index_mail *mail = (struct index_mail *)_mail;
 
1349
        struct mailbox_header_lookup_ctx *headers_ctx =
 
1350
                (struct mailbox_header_lookup_ctx *)mail->wanted_headers;
1291
1351
 
1292
1352
        mail->mail.v.close(_mail);
1293
1353
 
1303
1363
        if (array_is_created(&mail->header_match_lines))
1304
1364
                array_free(&mail->header_match_lines);
1305
1365
 
 
1366
        if (headers_ctx != NULL)
 
1367
                mailbox_header_lookup_unref(&headers_ctx);
1306
1368
        pool_unref(&mail->data_pool);
1307
1369
        pool_unref(&mail->mail.pool);
1308
1370
}
1372
1434
{
1373
1435
        struct index_mail *imail = (struct index_mail *)mail;
1374
1436
 
 
1437
        if (array_is_created(&imail->data.keyword_indexes))
 
1438
                array_free(&imail->data.keyword_indexes);
 
1439
        if (array_is_created(&imail->data.keywords)) {
 
1440
                /* clear the keywords array so the next mail_get_keywords()
 
1441
                   returns the updated keywords. don't free the array, because
 
1442
                   then any existing mail_get_keywords() return values would
 
1443
                   point to broken data. this won't leak memory because the
 
1444
                   array is allocated from mail's memory pool. */
 
1445
                memset(&imail->data.keywords, 0,
 
1446
                       sizeof(imail->data.keywords));
 
1447
        }
 
1448
 
1375
1449
        mail_index_update_keywords(imail->trans->trans, mail->seq, modify_type,
1376
1450
                                   keywords);
1377
1451
}