virtual-mail.c revision dee43975a70bcdb9dc83d34d6a2b177d37bb7194
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen/* Copyright (c) 2008 Dovecot authors, see the included COPYING file */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* currently active mail */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* all allocated mails */
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenvirtual_mail_alloc(struct mailbox_transaction_context *t,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mailbox *mbox = (struct virtual_mailbox *)t->box;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen array_create(&vmail->imail.mail.module_contexts, pool,
3d4450c252790b03bb5ce054987ac91110f1ff62Timo Sirainen sizeof(void *), 5);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen pool_alloconly_create("virtual index_mail", 512);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen vmail->imail.trans = (struct index_transaction_context *)t;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen i_array_init(&vmail->backend_mails, array_count(&mbox->backend_boxes));
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenstatic void virtual_mail_free(struct mail *mail)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
0fd246126fece57712566c725d6353f255f5fcfaTimo Sirainen unsigned int i, count;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen mails = array_get_modifiable(&vmail->backend_mails, &count);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen for (i = 0; i < count; i++)
fda168427e1950518acd6d600f1a10a29a5baef0Timo Sirainenstatic struct mail *
fda168427e1950518acd6d600f1a10a29a5baef0Timo Sirainenbackend_mail_find(struct virtual_mail *vmail, struct mailbox *box)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen unsigned int i, count;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen mails = array_get(&vmail->backend_mails, &count);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen for (i = 0; i < count; i++) {
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainenstatic void virtual_mail_set_seq(struct mail *mail, uint32_t seq)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
94f90df2cfb7587bb5af432b2ba065d1c364e1f7Timo Sirainen struct virtual_mailbox *mbox = (struct virtual_mailbox *)mail->box;
94f90df2cfb7587bb5af432b2ba065d1c364e1f7Timo Sirainen struct mailbox_transaction_context *backend_trans;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen mail_index_lookup_ext(mbox->ibox.view, seq, mbox->virtual_ext_id,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen bbox = virtual_backend_box_lookup(mbox, vrec->mailbox_id);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->backend_mail = backend_mail_find(vmail, bbox->box);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen virtual_transaction_get(mail->transaction, bbox->box);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->backend_mail = mail_alloc(backend_trans,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen array_append(&vmail->backend_mails, &vmail->backend_mail, 1);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen mail_set_uid(vmail->backend_mail, vrec->real_uid);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen memset(&vmail->imail.data, 0, sizeof(vmail->imail.data));
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen rec = mail_index_lookup(mbox->ibox.view, seq);
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen vmail->imail.data.flags = rec->flags & MAIL_FLAGS_NONRECENT;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen mail->expunged = vmail->backend_mail->expunged;
20b136f04257b0ba338e49f31a999c0d4b243647Timo Sirainen mail->has_nuls = vmail->backend_mail->has_nuls;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen mail->has_no_nuls = vmail->backend_mail->has_no_nuls;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenstatic bool virtual_mail_set_uid(struct mail *mail, uint32_t uid)
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct virtual_mailbox *mbox = (struct virtual_mailbox *)mail->box;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen if (!mail_index_lookup_seq(mbox->ibox.view, uid, &seq))
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen virtual_mail_set_seq(vmail->backend_mail, seq);
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenvirtual_mail_get_parts(struct mail *mail, const struct message_part **parts_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_parts(vmail->backend_mail, parts_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenvirtual_mail_get_date(struct mail *mail, time_t *date_r, int *timezone_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_date(vmail->backend_mail, date_r, timezone_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int virtual_mail_get_received_date(struct mail *mail, time_t *date_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen return mail_get_received_date(vmail->backend_mail, date_r);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenstatic int virtual_mail_get_save_date(struct mail *mail, time_t *date_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_save_date(vmail->backend_mail, date_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int virtual_mail_get_virtual_mail_size(struct mail *mail, uoff_t *size_r)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen return mail_get_virtual_size(vmail->backend_mail, size_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int virtual_mail_get_physical_size(struct mail *mail, uoff_t *size_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_physical_size(vmail->backend_mail, size_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenvirtual_mail_get_first_header(struct mail *mail, const char *field,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct mail_private *p = (struct mail_private *)vmail->backend_mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return p->v.get_first_header(vmail->backend_mail, field,
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenvirtual_mail_get_headers(struct mail *mail, const char *field,
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen bool decode_to_utf8, const char *const **value_r)
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
c63544d7d2580c680b07f9569e87e9cebee383d5Timo Sirainen struct mail_private *p = (struct mail_private *)vmail->backend_mail;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen return p->v.get_headers(vmail->backend_mail, field,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenvirtual_mail_get_header_stream(struct mail *mail,
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen return mail_get_header_stream(vmail->backend_mail, headers, stream_r);
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenvirtual_mail_get_stream(struct mail *mail, struct message_size *hdr_size,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_stream(vmail->backend_mail, hdr_size, body_size, stream_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenvirtual_mail_get_special(struct mail *mail, enum mail_fetch_field field,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen const char **value_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_special(vmail->backend_mail, field, value_r);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenstatic void virtual_mail_expunge(struct mail *mail)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
f0bf9880c05266114a9b85bf95b72f6cdf83b901Timo Sirainenvirtual_mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field)
f0bf9880c05266114a9b85bf95b72f6cdf83b901Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
f0bf9880c05266114a9b85bf95b72f6cdf83b901Timo Sirainen mail_set_cache_corrupted(vmail->backend_mail, field);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic struct index_mail *virtual_mail_get_index_mail(struct mail *mail)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return (struct index_mail *)vmail->backend_mail;