virtual-mail.c revision dee43975a70bcdb9dc83d34d6a2b177d37bb7194
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen/* Copyright (c) 2008 Dovecot authors, see the included COPYING file */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen#include "lib.h"
0fd246126fece57712566c725d6353f255f5fcfaTimo Sirainen#include "array.h"
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen#include "index-mail.h"
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen#include "virtual-storage.h"
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstruct virtual_mail {
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct index_mail imail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen enum mail_fetch_field wanted_fields;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* currently active mail */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct mail *backend_mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* all allocated mails */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen ARRAY_DEFINE(backend_mails, struct mail *);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen};
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstruct mail *
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenvirtual_mail_alloc(struct mailbox_transaction_context *t,
0fd246126fece57712566c725d6353f255f5fcfaTimo Sirainen enum mail_fetch_field wanted_fields,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mailbox *mbox = (struct virtual_mailbox *)t->box;
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen struct virtual_mail *vmail;
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen pool_t pool;
a1761856683b4bf745eb4e32cefabeb851efb301Timo Sirainen
a1761856683b4bf745eb4e32cefabeb851efb301Timo Sirainen pool = pool_alloconly_create("vmail", 1024);
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen vmail = p_new(pool, struct virtual_mail, 1);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->imail.mail.pool = pool;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->imail.mail.v = virtual_mail_vfuncs;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->imail.mail.mail.box = t->box;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->imail.mail.mail.transaction = t;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen array_create(&vmail->imail.mail.module_contexts, pool,
3d4450c252790b03bb5ce054987ac91110f1ff62Timo Sirainen sizeof(void *), 5);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen vmail->imail.data_pool =
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen pool_alloconly_create("virtual index_mail", 512);
bc93929cdd9000ca560a5f42a27f50ab307f1efbTimo Sirainen vmail->imail.ibox = &mbox->ibox;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen vmail->imail.trans = (struct index_transaction_context *)t;
bc93929cdd9000ca560a5f42a27f50ab307f1efbTimo Sirainen
3d4450c252790b03bb5ce054987ac91110f1ff62Timo Sirainen vmail->wanted_fields = wanted_fields;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->wanted_headers = wanted_headers;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen i_array_init(&vmail->backend_mails, array_count(&mbox->backend_boxes));
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen return &vmail->imail.mail.mail;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen}
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenstatic void virtual_mail_free(struct mail *mail)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen{
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct mail **mails;
0fd246126fece57712566c725d6353f255f5fcfaTimo Sirainen unsigned int i, count;
0fd246126fece57712566c725d6353f255f5fcfaTimo Sirainen
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen mails = array_get_modifiable(&vmail->backend_mails, &count);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen for (i = 0; i < count; i++)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen mail_free(&mails[i]);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen array_free(&vmail->backend_mails);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen
85a4ae7e8df7ea45a7665828e5edf48a5fc85730Timo Sirainen pool_unref(&vmail->imail.data_pool);
85a4ae7e8df7ea45a7665828e5edf48a5fc85730Timo Sirainen pool_unref(&vmail->imail.mail.pool);
85a4ae7e8df7ea45a7665828e5edf48a5fc85730Timo Sirainen}
85a4ae7e8df7ea45a7665828e5edf48a5fc85730Timo Sirainen
fda168427e1950518acd6d600f1a10a29a5baef0Timo Sirainenstatic struct mail *
fda168427e1950518acd6d600f1a10a29a5baef0Timo Sirainenbackend_mail_find(struct virtual_mail *vmail, struct mailbox *box)
fda168427e1950518acd6d600f1a10a29a5baef0Timo Sirainen{
fda168427e1950518acd6d600f1a10a29a5baef0Timo Sirainen struct mail *const *mails;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen unsigned int i, count;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen mails = array_get(&vmail->backend_mails, &count);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen for (i = 0; i < count; i++) {
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen if (mails[i]->box == box)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mails[i];
94f90df2cfb7587bb5af432b2ba065d1c364e1f7Timo Sirainen }
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return NULL;
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen}
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainenstatic void virtual_mail_set_seq(struct mail *mail, uint32_t seq)
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
94f90df2cfb7587bb5af432b2ba065d1c364e1f7Timo Sirainen struct virtual_mailbox *mbox = (struct virtual_mailbox *)mail->box;
94f90df2cfb7587bb5af432b2ba065d1c364e1f7Timo Sirainen struct virtual_backend_box *bbox;
94f90df2cfb7587bb5af432b2ba065d1c364e1f7Timo Sirainen struct mailbox_transaction_context *backend_trans;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen const struct virtual_mail_index_record *vrec;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen const struct mail_index_record *rec;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen const void *data;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen bool expunged;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen mail_index_lookup_ext(mbox->ibox.view, seq, mbox->virtual_ext_id,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen &data, &expunged);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vrec = data;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen bbox = virtual_backend_box_lookup(mbox, vrec->mailbox_id);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->backend_mail = backend_mail_find(vmail, bbox->box);
3fb1c1f0375ec0a2b00be90b5d61fbc8374e9b90Timo Sirainen if (vmail->backend_mail == NULL) {
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen backend_trans =
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen virtual_transaction_get(mail->transaction, bbox->box);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->backend_mail = mail_alloc(backend_trans,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->wanted_fields,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->wanted_headers);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen array_append(&vmail->backend_mails, &vmail->backend_mail, 1);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen }
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen mail_set_uid(vmail->backend_mail, vrec->real_uid);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen memset(&vmail->imail.data, 0, sizeof(vmail->imail.data));
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen p_clear(vmail->imail.data_pool);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen rec = mail_index_lookup(mbox->ibox.view, seq);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen vmail->imail.data.seq = seq;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen vmail->imail.data.flags = rec->flags & MAIL_FLAGS_NONRECENT;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen mail->seq = seq;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen mail->uid = rec->uid;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen
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 Sirainen}
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenstatic bool virtual_mail_set_uid(struct mail *mail, uint32_t uid)
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen{
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct virtual_mailbox *mbox = (struct virtual_mailbox *)mail->box;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen uint32_t seq;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen if (!mail_index_lookup_seq(mbox->ibox.view, uid, &seq))
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen return FALSE;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen virtual_mail_set_seq(vmail->backend_mail, seq);
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen return TRUE;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen}
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenstatic int
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenvirtual_mail_get_parts(struct mail *mail, const struct message_part **parts_r)
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_parts(vmail->backend_mail, parts_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenvirtual_mail_get_date(struct mail *mail, time_t *date_r, int *timezone_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen int tz;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen if (timezone_r == NULL)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen timezone_r = &tz;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_date(vmail->backend_mail, date_r, timezone_r);
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int virtual_mail_get_received_date(struct mail *mail, time_t *date_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen return mail_get_received_date(vmail->backend_mail, date_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenstatic int virtual_mail_get_save_date(struct mail *mail, time_t *date_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_save_date(vmail->backend_mail, date_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int virtual_mail_get_virtual_mail_size(struct mail *mail, uoff_t *size_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen{
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen return mail_get_virtual_size(vmail->backend_mail, size_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int virtual_mail_get_physical_size(struct mail *mail, uoff_t *size_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_physical_size(vmail->backend_mail, size_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenvirtual_mail_get_first_header(struct mail *mail, const char *field,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen bool decode_to_utf8, const char **value_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct mail_private *p = (struct mail_private *)vmail->backend_mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return p->v.get_first_header(vmail->backend_mail, field,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen decode_to_utf8, value_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenvirtual_mail_get_headers(struct mail *mail, const char *field,
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen bool decode_to_utf8, const char *const **value_r)
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen{
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
c63544d7d2580c680b07f9569e87e9cebee383d5Timo Sirainen struct mail_private *p = (struct mail_private *)vmail->backend_mail;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen return p->v.get_headers(vmail->backend_mail, field,
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen decode_to_utf8, value_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenvirtual_mail_get_header_stream(struct mail *mail,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct mailbox_header_lookup_ctx *headers,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct istream **stream_r)
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen{
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen return mail_get_header_stream(vmail->backend_mail, headers, stream_r);
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen}
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenstatic int
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenvirtual_mail_get_stream(struct mail *mail, struct message_size *hdr_size,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct message_size *body_size,
20b136f04257b0ba338e49f31a999c0d4b243647Timo Sirainen struct istream **stream_r)
20b136f04257b0ba338e49f31a999c0d4b243647Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_stream(vmail->backend_mail, hdr_size, body_size, stream_r);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic int
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenvirtual_mail_get_special(struct mail *mail, enum mail_fetch_field field,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen const char **value_r)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
bc93929cdd9000ca560a5f42a27f50ab307f1efbTimo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return mail_get_special(vmail->backend_mail, field, value_r);
bc93929cdd9000ca560a5f42a27f50ab307f1efbTimo Sirainen}
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenstatic void virtual_mail_expunge(struct mail *mail)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen mail_expunge(vmail->backend_mail);
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen}
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic void
f0bf9880c05266114a9b85bf95b72f6cdf83b901Timo Sirainenvirtual_mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field)
f0bf9880c05266114a9b85bf95b72f6cdf83b901Timo Sirainen{
f0bf9880c05266114a9b85bf95b72f6cdf83b901Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
f0bf9880c05266114a9b85bf95b72f6cdf83b901Timo Sirainen
f0bf9880c05266114a9b85bf95b72f6cdf83b901Timo Sirainen mail_set_cache_corrupted(vmail->backend_mail, field);
f0bf9880c05266114a9b85bf95b72f6cdf83b901Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic struct index_mail *virtual_mail_get_index_mail(struct mail *mail)
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen{
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen struct virtual_mail *vmail = (struct virtual_mail *)mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen return (struct index_mail *)vmail->backend_mail;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen}
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstruct mail_vfuncs virtual_mail_vfuncs = {
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen NULL,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_free,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_set_seq,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_set_uid,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen index_mail_get_flags,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen index_mail_get_keywords,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen index_mail_get_keyword_indexes,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen index_mail_get_modseq,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_get_parts,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_get_date,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_get_received_date,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_get_save_date,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen virtual_mail_get_virtual_mail_size,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_get_physical_size,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_get_first_header,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_get_headers,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen virtual_mail_get_header_stream,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen virtual_mail_get_stream,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen virtual_mail_get_special,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen index_mail_update_flags,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen index_mail_update_keywords,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen virtual_mail_expunge,
7c311effa7150d364232e6f2d0a1fa623dbb8d95Timo Sirainen virtual_mail_set_cache_corrupted,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen virtual_mail_get_index_mail
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen};
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen