]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: convert index to use container_of
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Thu, 7 Sep 2017 10:04:01 +0000 (13:04 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Mon, 18 Sep 2017 14:40:24 +0000 (17:40 +0300)
15 files changed:
src/lib-storage/index/cydir/cydir-mail.c
src/lib-storage/index/imapc/imapc-mail.c
src/lib-storage/index/imapc/imapc-save.c
src/lib-storage/index/index-mail-binary.c
src/lib-storage/index/index-mail-headers.c
src/lib-storage/index/index-mail.c
src/lib-storage/index/index-mail.h
src/lib-storage/index/index-search.c
src/lib-storage/index/index-storage.c
src/lib-storage/index/maildir/maildir-mail.c
src/lib-storage/index/maildir/maildir-save.c
src/lib-storage/index/mbox/mbox-mail.c
src/lib-storage/index/pop3c/pop3c-mail.c
src/lib-storage/index/raw/raw-mail.c
src/plugins/pop3-migration/pop3-migration-plugin.c

index 8c8f22a3fb60a3b9b099f2b6eaa183d96711ba08..cbac6956a494c3090466cba876aaf52cbd06bca0 100644 (file)
@@ -43,7 +43,7 @@ static int cydir_mail_stat(struct mail *mail, struct stat *st_r)
 
 static int cydir_mail_get_received_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct stat st;
 
@@ -60,7 +60,7 @@ static int cydir_mail_get_received_date(struct mail *_mail, time_t *date_r)
 
 static int cydir_mail_get_save_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct stat st;
 
@@ -77,7 +77,7 @@ static int cydir_mail_get_save_date(struct mail *_mail, time_t *date_r)
 
 static int cydir_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct stat st;
 
@@ -98,7 +98,7 @@ cydir_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED,
                      struct message_size *body_size,
                      struct istream **stream_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct istream *input;
        const char *path;
        int fd;
index d4f6f94dbef2096fbd4e6d4b0a475e52aa9ee544..dc974f805c9fd78e62f023523f2b30dc4f50c82b 100644 (file)
@@ -118,7 +118,7 @@ static uint64_t imapc_mail_get_modseq(struct mail *_mail)
 
 static int imapc_mail_get_received_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        if (index_mail_get_received_date(_mail, date_r) == 0)
@@ -141,7 +141,7 @@ static int imapc_mail_get_received_date(struct mail *_mail, time_t *date_r)
 
 static int imapc_mail_get_save_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        if (data->save_date == (time_t)-1) {
@@ -155,7 +155,7 @@ static int imapc_mail_get_save_date(struct mail *_mail, time_t *date_r)
 static int imapc_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 {
        struct imapc_mailbox *mbox = IMAPC_MAILBOX(_mail->box);
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct istream *input;
        uoff_t old_offset;
@@ -205,7 +205,7 @@ static int imapc_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 
 static int imapc_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        if (imapc_mail_get_physical_size(_mail, size_r) < 0)
@@ -416,7 +416,7 @@ imapc_mail_add_temp_wanted_fields(struct mail *_mail,
                                  enum mail_fetch_field fields,
                                  struct mailbox_header_lookup_ctx *headers)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        index_mail_add_temp_wanted_fields(_mail, fields, headers);
        if (_mail->seq != 0)
@@ -492,7 +492,7 @@ static int imapc_mail_get_hdr_hash(struct index_mail *imail)
 
 static bool imapc_mail_get_cached_guid(struct mail *_mail)
 {
-       struct index_mail *imail = (struct index_mail *)_mail;
+       struct index_mail *imail = INDEX_MAIL(_mail);
        const enum index_cache_field cache_idx =
                imail->ibox->cache_fields[MAIL_CACHE_GUID].idx;
        string_t *str;
@@ -518,7 +518,7 @@ static bool imapc_mail_get_cached_guid(struct mail *_mail)
 
 static int imapc_mail_get_guid(struct mail *_mail, const char **value_r)
 {
-       struct index_mail *imail = (struct index_mail *)_mail;
+       struct index_mail *imail = INDEX_MAIL(_mail);
        struct imapc_mailbox *mbox = IMAPC_MAILBOX(_mail->box);
        const enum index_cache_field cache_idx =
                imail->ibox->cache_fields[MAIL_CACHE_GUID].idx;
@@ -553,7 +553,7 @@ imapc_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
                       const char **value_r)
 {
        struct imapc_mailbox *mbox = IMAPC_MAILBOX(_mail->box);
-       struct index_mail *imail = (struct index_mail *)_mail;
+       struct index_mail *imail = INDEX_MAIL(_mail);
        uint64_t num;
 
        switch (field) {
index 2d81c867075768c25840f4d27bf6c642099cdc3f..e2215badeb43aaee02da13a6fadf5c4c968cceb8 100644 (file)
@@ -136,7 +136,7 @@ static void
 imapc_save_add_to_index(struct imapc_save_context *ctx, uint32_t uid)
 {
        struct mail *_mail = ctx->ctx.dest_mail;
-       struct index_mail *imail = (struct index_mail *)_mail;
+       struct index_mail *imail = INDEX_MAIL(_mail);
        uint32_t seq;
 
        /* we'll temporarily append messages and at commit time expunge
index 191c047d305d052808f405f5d3f7885497036385..9533a470ad52e9cb5419fc2f582340ec9e5919c4 100644 (file)
@@ -240,7 +240,7 @@ static void
 binary_parts_update(struct binary_ctx *ctx, const struct message_part *part,
                    struct message_binary_part **msg_bin_parts)
 {
-       struct index_mail *mail = (struct index_mail *)ctx->mail;
+       struct index_mail *mail = INDEX_MAIL(ctx->mail);
        struct binary_block *blocks;
        struct message_binary_part bin_part;
        unsigned int i, count;
@@ -279,7 +279,7 @@ binary_parts_update(struct binary_ctx *ctx, const struct message_part *part,
 
 static void binary_parts_cache(struct binary_ctx *ctx)
 {
-       struct index_mail *mail = (struct index_mail *)ctx->mail;
+       struct index_mail *mail = INDEX_MAIL(ctx->mail);
        buffer_t *buf;
 
        buf = buffer_create_dynamic(pool_datastack_create(), 128);
@@ -364,7 +364,7 @@ index_mail_read_binary_to_cache(struct mail *_mail,
                                bool include_hdr, const char *reason,
                                bool *binary_r, bool *converted_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct mail_binary_cache *cache = &_mail->box->storage->binary_cache;
        struct binary_ctx ctx;
        struct istream *is;
@@ -482,7 +482,7 @@ index_mail_get_binary_size(struct mail *_mail,
                           const struct message_part *part, bool include_hdr,
                           uoff_t *size_r, unsigned int *lines_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct message_part *all_parts, *msg_part;
        const struct message_binary_part *bin_part, *root_bin_part;
        uoff_t size, end_offset;
@@ -549,7 +549,7 @@ int index_mail_get_binary_stream(struct mail *_mail,
                                 unsigned int *lines_r, bool *binary_r,
                                 struct istream **stream_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct mail_binary_cache *cache = &_mail->box->storage->binary_cache;
        struct istream *input;
        bool binary, converted;
index 87289a58ec3ad51e75e8433238caf52d948cb48e..d6d65cabac4c86fa0a1d4fc14d13dbe22bedf602 100644 (file)
@@ -373,7 +373,7 @@ index_mail_parse_header_cb(struct message_header_line *hdr,
 struct istream *
 index_mail_cache_parse_init(struct mail *_mail, struct istream *input)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct istream *input2;
 
        i_assert(mail->data.tee_stream == NULL);
@@ -788,7 +788,7 @@ index_mail_headers_decode(struct index_mail *mail, const char *const **_list,
 int index_mail_get_headers(struct mail *_mail, const char *field,
                           bool decode_to_utf8, const char *const **value_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        bool retry = TRUE;
        int ret;
 
@@ -822,7 +822,7 @@ int index_mail_get_headers(struct mail *_mail, const char *field,
 int index_mail_get_first_header(struct mail *_mail, const char *field,
                                bool decode_to_utf8, const char **value_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        const char *const *list;
        bool retry = TRUE;
        int ret;
@@ -868,7 +868,7 @@ int index_mail_get_header_stream(struct mail *_mail,
                                 struct mailbox_header_lookup_ctx *headers,
                                 struct istream **stream_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct istream *input;
        string_t *dest;
 
index 0d3afff8151c637be85194c6f3e92ccb8523b213..4ec92214220ed668037784394153376301a6a5ca 100644 (file)
@@ -154,7 +154,7 @@ void index_mail_set_message_parts_corrupted(struct mail *mail, const char *error
        buffer_t *part_buf;
        const char *parts_str;
 
-       if (get_serialized_parts((struct index_mail *)mail, &part_buf) <= 0)
+       if (get_serialized_parts(INDEX_MAIL(mail), &part_buf) <= 0)
                parts_str = "";
        else
                parts_str = binary_to_hex(part_buf->data, part_buf->used);
@@ -239,7 +239,7 @@ enum mail_flags index_mail_get_flags(struct mail *_mail)
 
 uint64_t index_mail_get_modseq(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        if (mail->data.modseq != 0)
                return mail->data.modseq;
@@ -252,7 +252,7 @@ uint64_t index_mail_get_modseq(struct mail *_mail)
 
 uint64_t index_mail_get_pvt_modseq(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        if (mail->data.pvt_modseq != 0)
                return mail->data.pvt_modseq;
@@ -270,7 +270,7 @@ uint64_t index_mail_get_pvt_modseq(struct mail *_mail)
 
 const char *const *index_mail_get_keywords(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        const char *const *names;
        const unsigned int *keyword_indexes;
@@ -300,7 +300,7 @@ const char *const *index_mail_get_keywords(struct mail *_mail)
 const ARRAY_TYPE(keyword_indexes) *
 index_mail_get_keyword_indexes(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        if (!array_is_created(&data->keyword_indexes)) {
@@ -314,7 +314,7 @@ index_mail_get_keyword_indexes(struct mail *_mail)
 
 int index_mail_get_parts(struct mail *_mail, struct message_part **parts_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        data->cache_fetch_fields |= MAIL_FETCH_MESSAGE_PARTS;
@@ -343,7 +343,7 @@ int index_mail_get_parts(struct mail *_mail, struct message_part **parts_r)
 
 int index_mail_get_received_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        data->cache_fetch_fields |= MAIL_FETCH_RECEIVED_DATE;
@@ -361,7 +361,7 @@ int index_mail_get_received_date(struct mail *_mail, time_t *date_r)
 
 int index_mail_get_save_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        data->cache_fetch_fields |= MAIL_FETCH_SAVE_DATE;
@@ -406,7 +406,7 @@ static int index_mail_cache_sent_date(struct index_mail *mail)
 
 int index_mail_get_date(struct mail *_mail, time_t *date_r, int *timezone_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct mail_sent_date sentdate;
 
@@ -452,7 +452,7 @@ static bool get_cached_msgpart_sizes(struct index_mail *mail)
 
 const uint32_t *index_mail_get_vsize_extension(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        const void *idata;
        bool expunged ATTR_UNUSED;
 
@@ -539,7 +539,7 @@ static void index_mail_get_cached_body_size(struct index_mail *mail)
 
 int index_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct message_size hdr_size, body_size;
        struct istream *input;
@@ -561,7 +561,7 @@ int index_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r)
 
 int index_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        uoff_t size;
 
@@ -1196,7 +1196,7 @@ static void index_mail_stream_destroy_callback(struct index_mail *mail)
 
 void index_mail_set_read_buffer_size(struct mail *_mail, struct istream *input)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        unsigned int block_size;
 
        i_stream_set_max_buffer_size(input, MAIL_READ_FULL_BLOCK_SIZE);
@@ -1489,7 +1489,7 @@ bool index_mail_get_cached_bodystructure(struct index_mail *mail,
 int index_mail_get_special(struct mail *_mail,
                           enum mail_fetch_field field, const char **value_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        switch (field) {
@@ -1673,7 +1673,7 @@ static void index_mail_reset_data(struct index_mail *mail)
 
 void index_mail_close(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        if (mail->mail.mail.seq == 0) {
                /* mail_set_seq*() hasn't been called yet, or is being called
@@ -1738,7 +1738,7 @@ static void check_envelope(struct index_mail *mail)
 
 void index_mail_update_access_parts_pre(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct mail_storage *storage = _mail->box->storage;
        const struct mail_cache_field *cache_fields = mail->ibox->cache_fields;
@@ -1857,7 +1857,7 @@ void index_mail_update_access_parts_pre(struct mail *_mail)
 
 void index_mail_update_access_parts_post(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        const struct mail_index_header *hdr;
        struct istream *input;
@@ -1889,7 +1889,7 @@ void index_mail_update_access_parts_post(struct mail *_mail)
 
 void index_mail_set_seq(struct mail *_mail, uint32_t seq, bool saving)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        if (mail->data.seq == seq) {
                if (!saving)
@@ -1925,7 +1925,7 @@ void index_mail_set_seq(struct mail *_mail, uint32_t seq, bool saving)
 
 bool index_mail_prefetch(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 /* HAVE_POSIX_FADVISE alone isn't enough for CentOS 4.9 */
 #if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
        struct mail_storage *storage = _mail->box->storage;
@@ -1967,7 +1967,7 @@ bool index_mail_prefetch(struct mail *_mail)
 
 bool index_mail_set_uid(struct mail *_mail, uint32_t uid)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        uint32_t seq;
 
        if (mail_index_lookup_seq(_mail->transaction->view, uid, &seq)) {
@@ -1985,7 +1985,7 @@ void index_mail_add_temp_wanted_fields(struct mail *_mail,
                                       enum mail_fetch_field fields,
                                       struct mailbox_header_lookup_ctx *headers)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct mailbox_header_lookup_ctx *new_wanted_headers;
        ARRAY_TYPE(const_string) names;
@@ -2027,14 +2027,14 @@ void index_mail_add_temp_wanted_fields(struct mail *_mail,
 
 void index_mail_set_uid_cache_updates(struct mail *_mail, bool set)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        mail->data.no_caching = set || mail->data.forced_no_caching;
 }
 
 void index_mail_free(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct mailbox_header_lookup_ctx *headers_ctx =
                (struct mailbox_header_lookup_ctx *)mail->mail.wanted_headers;
 
@@ -2065,7 +2065,7 @@ void index_mail_free(struct mail *_mail)
 
 void index_mail_cache_parse_continue(struct mail *_mail)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct message_block block;
 
        while (message_parser_parse_next_block(mail->data.parser_ctx,
@@ -2087,7 +2087,7 @@ void index_mail_cache_parse_continue(struct mail *_mail)
 void index_mail_cache_parse_deinit(struct mail *_mail, time_t received_date,
                                   bool success)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        if (!success) {
                /* we're going to delete this mail anyway,
@@ -2183,7 +2183,7 @@ void index_mail_update_flags(struct mail *_mail, enum modify_type modify_type,
 void index_mail_update_keywords(struct mail *mail, enum modify_type modify_type,
                                struct mail_keywords *keywords)
 {
-       struct index_mail *imail = (struct index_mail *)mail;
+       struct index_mail *imail = INDEX_MAIL(mail);
 
        if (array_is_created(&imail->data.keyword_indexes))
                array_free(&imail->data.keyword_indexes);
@@ -2235,7 +2235,7 @@ void index_mail_expunge(struct mail *mail)
 
 static void index_mail_parse(struct mail *mail, bool parse_body)
 {
-       struct index_mail *imail = (struct index_mail *)mail;
+       struct index_mail *imail = INDEX_MAIL(mail);
 
        imail->data.access_part |= PARSE_HDR;
        if (index_mail_parse_headers(imail, NULL, "precache") == 0) {
@@ -2248,7 +2248,7 @@ static void index_mail_parse(struct mail *mail, bool parse_body)
 
 void index_mail_precache(struct mail *mail)
 {
-       struct index_mail *imail = (struct index_mail *)mail;
+       struct index_mail *imail = INDEX_MAIL(mail);
        enum mail_fetch_field cache;
        time_t date;
        uoff_t size;
@@ -2297,7 +2297,7 @@ void index_mail_set_cache_corrupted(struct mail *mail,
                                    enum mail_fetch_field field,
                                    const char *reason)
 {
-       struct index_mail *imail = (struct index_mail *)mail;
+       struct index_mail *imail = INDEX_MAIL(mail);
        const char *field_name;
 
        switch ((int)field) {
@@ -2364,7 +2364,7 @@ int index_mail_opened(struct mail *mail ATTR_UNUSED,
 
 void index_mail_save_finish(struct mail_save_context *ctx)
 {
-       struct index_mail *imail = (struct index_mail *)ctx->dest_mail;
+       struct index_mail *imail = INDEX_MAIL(ctx->dest_mail);
 
        if (ctx->data.from_envelope != NULL &&
            imail->data.from_envelope == NULL) {
index 7b3073eae89c5553a2c9dcbd7d88175949c61dec..f8438a9d60ccc0ca61e15c35c5c8e28d43ebb61a 100644 (file)
@@ -157,6 +157,8 @@ struct index_mail {
        bool freeing:1;
 };
 
+#define INDEX_MAIL(s)  container_of(s, struct index_mail, mail.mail)
+
 struct mail *
 index_mail_alloc(struct mailbox_transaction_context *t,
                 enum mail_fetch_field wanted_fields,
index ba22699bcba322566c42448d42cc40b1e5ad2a85..2abcdae8a6b9b0c244cdae670e083e997653f8ae 100644 (file)
@@ -716,7 +716,7 @@ static int search_arg_match_text(struct mail_search_arg *args,
 {
        const enum message_header_parser_flags hdr_parser_flags =
                MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE;
-       struct index_mail *imail = (struct index_mail *)ctx->cur_mail;
+       struct index_mail *imail = INDEX_MAIL(ctx->cur_mail);
        struct mail *real_mail;
        struct istream *input = NULL;
        struct mailbox_header_lookup_ctx *headers_ctx;
@@ -739,7 +739,7 @@ static int search_arg_match_text(struct mail_search_arg *args,
                search_cur_mail_failed(ctx);
                return -1;
        }
-       hdr_ctx.imail = (struct index_mail *)real_mail;
+       hdr_ctx.imail = INDEX_MAIL(real_mail);
        hdr_ctx.custom_header = TRUE;
        hdr_ctx.args = args;
 
@@ -1357,7 +1357,7 @@ int index_storage_search_deinit(struct mail_search_context *_ctx)
        array_free(&ctx->mail_ctx.module_contexts);
 
        array_foreach_modifiable(&ctx->mails, mailp) {
-               struct index_mail *imail = (struct index_mail *)*mailp;
+               struct index_mail *imail = INDEX_MAIL(*mailp);
 
                imail->search_mail = FALSE;
                mail_free(mailp);
@@ -1585,7 +1585,7 @@ static int search_more_with_mail(struct index_search_context *ctx,
 {
        struct mail_search_context *_ctx = &ctx->mail_ctx;
        struct mailbox *box = _ctx->transaction->box;
-       struct index_mail *imail = (struct index_mail *)mail;
+       struct index_mail *imail = INDEX_MAIL(mail);
        unsigned long long cost1, cost2;
        int match, ret;
 
@@ -1677,7 +1677,7 @@ struct mail *index_search_get_mail(struct index_search_context *ctx)
        mail = mail_alloc(ctx->mail_ctx.transaction,
                          ctx->mail_ctx.wanted_fields,
                          ctx->mail_ctx.wanted_headers);
-       imail = (struct index_mail *)mail;
+       imail = INDEX_MAIL(mail);
        imail->search_mail = TRUE;
        ctx->mail_ctx.transaction->stats_track = TRUE;
 
@@ -1769,7 +1769,7 @@ static int search_more(struct index_search_context *ctx,
        int ret;
 
        while ((ret = search_more_with_prefetching(ctx, mail_r)) > 0) {
-               imail = (struct index_mail *)*mail_r;
+               imail = INDEX_MAIL(*mail_r);
                if (imail->data.search_results == NULL)
                        break;
 
index 8f27a2cf8d7cd3d734db8a957685b13e276a9e4d..815684b87d3ddb296c257590fa4715687d47c8fa 100644 (file)
@@ -945,7 +945,7 @@ mail_copy_cache_field(struct mail_save_context *ctx, struct mail *src_mail,
                           cached data from buffer, we'll do this optimization
                           to make quota plugin's work faster */
                        struct index_mail *imail =
-                               (struct index_mail *)ctx->dest_mail;
+                               INDEX_MAIL(ctx->dest_mail);
                        uoff_t size;
 
                        i_assert(buf->used == sizeof(size));
@@ -966,7 +966,7 @@ static void
 index_copy_vsize_extension(struct mail_save_context *ctx,
                           struct mail *src_mail, uint32_t dest_seq)
 {
-       struct index_mail *src_imail = (struct index_mail *)src_mail;
+       struct index_mail *src_imail = INDEX_MAIL(src_mail);
        unsigned int idx;
        bool expunged ATTR_UNUSED;
 
@@ -1178,7 +1178,7 @@ int index_storage_save_continue(struct mail_save_context *ctx,
 
 void index_storage_save_abort_last(struct mail_save_context *ctx, uint32_t seq)
 {
-       struct index_mail *imail = (struct index_mail *)ctx->dest_mail;
+       struct index_mail *imail = INDEX_MAIL(ctx->dest_mail);
 
        /* Close the mail before it's expunged. This allows it to be
           reset cleanly. */
index 25c1bf1c042ae5c4440d2b5373a97c8d8c88360c..7bf049d147631a276ed148832a95b87bf81d80cd 100644 (file)
@@ -104,7 +104,7 @@ maildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail,
 static int maildir_mail_stat(struct mail *mail, struct stat *st_r)
 {
        struct maildir_mailbox *mbox = MAILDIR_MAILBOX(mail->box);
-       struct index_mail *imail = (struct index_mail *)mail;
+       struct index_mail *imail = INDEX_MAIL(mail);
        const char *path;
        int fd, ret;
 
@@ -153,7 +153,7 @@ static int maildir_mail_stat(struct mail *mail, struct stat *st_r)
 
 static int maildir_mail_get_received_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct stat st;
 
@@ -169,7 +169,7 @@ static int maildir_mail_get_received_date(struct mail *_mail, time_t *date_r)
 
 static int maildir_mail_get_save_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct stat st;
 
@@ -380,7 +380,7 @@ maildir_handle_size_caching(struct index_mail *mail, bool quick_check,
 static int maildir_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r)
 {
        struct maildir_mailbox *mbox = MAILDIR_MAILBOX(_mail->box);
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct message_size hdr_size, body_size;
        struct istream *input;
@@ -424,7 +424,7 @@ static int maildir_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r)
 
 static int maildir_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct maildir_mailbox *mbox = MAILDIR_MAILBOX(_mail->box);
        struct index_mail_data *data = &mail->data;
        struct stat st;
@@ -492,7 +492,7 @@ static int
 maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
                         const char **value_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct maildir_mailbox *mbox = MAILDIR_MAILBOX(_mail->box);
        const char *path, *fname = NULL, *end, *guid, *uidl, *order;
        struct stat st;
@@ -597,7 +597,7 @@ maildir_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED,
                        struct message_size *body_size,
                        struct istream **stream_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct maildir_mailbox *mbox = MAILDIR_MAILBOX(_mail->box);
        struct index_mail_data *data = &mail->data;
        bool deleted;
index 5f2689aa5e002fcce7111712e72a46fe11a6fc58..43210208d9a49e3a9cec714d74e5035ec0cef889 100644 (file)
@@ -540,7 +540,7 @@ static int maildir_save_finish_real(struct mail_save_context *_ctx)
 
        if (_ctx->data.save_date != (time_t)-1) {
                /* we can't change ctime, but we can add the date to cache */
-               struct index_mail *mail = (struct index_mail *)_ctx->dest_mail;
+               struct index_mail *mail = INDEX_MAIL(_ctx->dest_mail);
                uint32_t t = _ctx->data.save_date;
 
                index_mail_cache_add(mail, MAIL_CACHE_SAVE_DATE, &t, sizeof(t));
index bd14699a113b0f9f3cc6b5c1f709377b027b5a01..0ee2c729fa42260d025b64aacc99a4180ff83bcc 100644 (file)
@@ -111,7 +111,7 @@ static int mbox_mail_seek(struct index_mail *mail)
 
 static int mbox_mail_get_received_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct mbox_mailbox *mbox = MBOX_MAILBOX(_mail->box);
 
@@ -134,7 +134,7 @@ static int mbox_mail_get_received_date(struct mail *_mail, time_t *date_r)
 
 static int mbox_mail_get_save_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        if (index_mail_get_save_date(_mail, date_r) == 0)
@@ -181,7 +181,7 @@ static int
 mbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
                      const char **value_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct mbox_mailbox *mbox = MBOX_MAILBOX(_mail->box);
        uoff_t offset;
        bool move_offset;
@@ -287,7 +287,7 @@ mbox_mail_get_next_offset(struct index_mail *mail, uoff_t *next_offset_r)
 
 static int mbox_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
        struct mbox_mailbox *mbox = MBOX_MAILBOX(_mail->box);
        struct istream *input;
@@ -382,7 +382,7 @@ static int mbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED,
                                struct message_size *body_size,
                                struct istream **stream_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        if (mail->data.stream == NULL) {
                if (mbox_mail_init_stream(mail) < 0)
@@ -394,7 +394,7 @@ static int mbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED,
 
 static void mbox_mail_set_seq(struct mail *_mail, uint32_t seq, bool saving)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        index_mail_set_seq(_mail, seq, saving);
        mail->data.dont_cache_fetch_fields |= MAIL_FETCH_PHYSICAL_SIZE;
@@ -402,7 +402,7 @@ static void mbox_mail_set_seq(struct mail *_mail, uint32_t seq, bool saving)
 
 static bool mbox_mail_set_uid(struct mail *_mail, uint32_t uid)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        bool ret;
 
        ret = index_mail_set_uid(_mail, uid);
index 5a63437b91be345d3f74007cfba953eb845037ec..efd44e8a57dcab04508b21ae09b5d6245cd479a6 100644 (file)
@@ -56,7 +56,7 @@ static int pop3c_mail_get_received_date(struct mail *_mail, time_t *date_r)
 
 static int pop3c_mail_get_save_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct index_mail_data *data = &mail->data;
 
        if (data->save_date == (time_t)-1) {
@@ -69,7 +69,7 @@ static int pop3c_mail_get_save_date(struct mail *_mail, time_t *date_r)
 
 static int pop3c_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct pop3c_mailbox *mbox = POP3C_MAILBOX(_mail->box);
        struct message_size hdr_size, body_size;
        struct istream *input;
index a98c0e2e57f34d1299d26a56b757f0fd84ab09cb..79ab8f3ae79620366a3ab59ccc7f94d0387e79f3 100644 (file)
@@ -38,7 +38,7 @@ static int raw_mail_stat(struct mail *mail)
 
 static int raw_mail_get_received_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct raw_mailbox *mbox = RAW_MAILBOX(_mail->box);
 
        if (mbox->mtime == (time_t)-1) {
@@ -52,7 +52,7 @@ static int raw_mail_get_received_date(struct mail *_mail, time_t *date_r)
 
 static int raw_mail_get_save_date(struct mail *_mail, time_t *date_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct raw_mailbox *mbox = RAW_MAILBOX(_mail->box);
 
        if (mbox->ctime == (time_t)-1) {
@@ -66,7 +66,7 @@ static int raw_mail_get_save_date(struct mail *_mail, time_t *date_r)
 
 static int raw_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
        struct raw_mailbox *mbox = RAW_MAILBOX(_mail->box);
 
        if (mbox->size == (uoff_t)-1) {
@@ -83,7 +83,7 @@ raw_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED,
                    struct message_size *hdr_size,
                    struct message_size *body_size, struct istream **stream_r)
 {
-       struct index_mail *mail = (struct index_mail *)_mail;
+       struct index_mail *mail = INDEX_MAIL(_mail);
 
        if (mail->data.stream == NULL) {
                /* we can't just reference mbox->input, because
index 85d884fcb985db38185fb12967e895e0a1f96f51..3f76466978c399105bdc3903215e7bec092f5918 100644 (file)
@@ -805,7 +805,7 @@ static void imap_uidls_add_to_cache(struct mailbox *box)
 
        t = mailbox_transaction_begin(box, 0);
        mail = mail_alloc(t, 0, NULL);
-       imail = (struct index_mail *)mail;
+       imail = INDEX_MAIL(mail);
        field_idx = imail->ibox->cache_fields[MAIL_CACHE_POP3_UIDL].idx;
 
        imap_map = array_get_modifiable(&mbox->imap_msg_map, &count);