proxy-mailbox.c revision a423d985ba7261661475811c22b21b80ec765a71
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (C) 2003 Timo Sirainen */
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen#include "lib.h"
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen#include "proxy-mailbox.h"
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenstatic int _is_readonly(struct mailbox *box)
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen{
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen return p->box->is_readonly(p->box);
e54512a5189192fe72d1e2c53927c98c5ac920b4Timo Sirainen}
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenstatic int _allow_new_keywords(struct mailbox *box)
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainen{
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen return p->box->allow_new_keywords(p->box);
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen}
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainenstatic int _close(struct mailbox *box)
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen{
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen
c9dea5c23355dea35c6fa423de69f6507852efe4Timo Sirainen return p->box->close(p->box);
c9dea5c23355dea35c6fa423de69f6507852efe4Timo Sirainen}
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic int _get_status(struct mailbox *box, enum mailbox_status_items items,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen struct mailbox_status *status)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen{
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen return p->box->get_status(p->box, items, status);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen}
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenstatic struct mailbox_sync_context *
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
c9dea5c23355dea35c6fa423de69f6507852efe4Timo Sirainen{
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return p->box->sync_init(p->box, flags);
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen}
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenstatic void _notify_changes(struct mailbox *box, unsigned int min_interval,
8fb1e3e2349c9940732b5bb77a2a4053b8f72a4fTimo Sirainen mailbox_notify_callback_t *callback, void *context)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen{
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
c9dea5c23355dea35c6fa423de69f6507852efe4Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return p->box->notify_changes(box, min_interval, callback, context);
c9dea5c23355dea35c6fa423de69f6507852efe4Timo Sirainen}
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic struct mail *_fetch(struct mailbox_transaction_context *t, uint32_t seq,
4b058f90f9e8a2c6b2eed275de4eb8cc5195a71dTimo Sirainen enum mail_fetch_field wanted_fields)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen{
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen struct proxy_mailbox_transaction_context *pt =
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen (struct proxy_mailbox_transaction_context *)t;
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen struct proxy_mailbox *pbox = (struct proxy_mailbox *)t->box;
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return pbox->box->fetch(pt->ctx, seq, wanted_fields);
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen}
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainenstatic int _get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen uint32_t *seq1_r, uint32_t *seq2_r)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen{
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen
5cda0bfea032000c4a51134c748d9efe6614870bTimo Sirainen return p->box->get_uids(p->box, uid1, uid2, seq1_r, seq2_r);
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen}
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic struct mailbox_header_lookup_ctx *
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen_header_lookup_init(struct mailbox *box, const char *const headers[])
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen{
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen
8b12e7b44abca3bd51a1c46e19ca504f3b55e723Timo Sirainen return p->box->header_lookup_init(p->box, headers);
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen}
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainenstatic int _search_get_sorting(struct mailbox *box,
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen enum mail_sort_type *sort_program)
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen{
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen
8b12e7b44abca3bd51a1c46e19ca504f3b55e723Timo Sirainen return p->box->search_get_sorting(p->box, sort_program);
8b12e7b44abca3bd51a1c46e19ca504f3b55e723Timo Sirainen}
8b12e7b44abca3bd51a1c46e19ca504f3b55e723Timo Sirainen
8b12e7b44abca3bd51a1c46e19ca504f3b55e723Timo Sirainenstatic struct mail_search_context *
8b12e7b44abca3bd51a1c46e19ca504f3b55e723Timo Sirainen_search_init(struct mailbox_transaction_context *t,
8b12e7b44abca3bd51a1c46e19ca504f3b55e723Timo Sirainen const char *charset, struct mail_search_arg *args,
872b8fd8a8db97dc54067b7ab25bda96ec0aac0dTimo Sirainen const enum mail_sort_type *sort_program,
872b8fd8a8db97dc54067b7ab25bda96ec0aac0dTimo Sirainen enum mail_fetch_field wanted_fields,
872b8fd8a8db97dc54067b7ab25bda96ec0aac0dTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers)
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen{
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen struct proxy_mailbox_transaction_context *pt =
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen (struct proxy_mailbox_transaction_context *)t;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct proxy_mailbox *pbox = (struct proxy_mailbox *)t->box;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen return pbox->box->search_init(pt->ctx, charset, args, sort_program,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen wanted_fields, wanted_headers);
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen}
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic int _transaction_commit(struct mailbox_transaction_context *t)
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen{
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct proxy_mailbox_transaction_context *pt =
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen (struct proxy_mailbox_transaction_context *)t;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct proxy_mailbox *pbox = (struct proxy_mailbox *)t->box;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return pbox->box->transaction_commit(pt->ctx);
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen}
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic void _transaction_rollback(struct mailbox_transaction_context *t)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen{
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct proxy_mailbox_transaction_context *pt =
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen (struct proxy_mailbox_transaction_context *)t;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct proxy_mailbox *pbox = (struct proxy_mailbox *)t->box;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen pbox->box->transaction_rollback(pt->ctx);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen}
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic struct mail_save_context *
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen_save_init(struct mailbox_transaction_context *t,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen const struct mail_full_flags *flags,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen time_t received_date, int timezone_offset,
5cda0bfea032000c4a51134c748d9efe6614870bTimo Sirainen const char *from_envelope, struct istream *input, int want_mail)
5cda0bfea032000c4a51134c748d9efe6614870bTimo Sirainen{
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen struct proxy_mailbox_transaction_context *pt =
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen (struct proxy_mailbox_transaction_context *)t;
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen struct proxy_mailbox *pbox = (struct proxy_mailbox *)t->box;
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen return pbox->box->save_init(pt->ctx, flags, received_date,
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen timezone_offset, from_envelope, input,
2aecf7be5834e7f6520f8deaad683a6fa1de4d61Timo Sirainen want_mail);
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen}
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainenstatic int _copy(struct mailbox_transaction_context *t, struct mail *mail,
2aecf7be5834e7f6520f8deaad683a6fa1de4d61Timo Sirainen struct mail **dest_mail_r)
2aecf7be5834e7f6520f8deaad683a6fa1de4d61Timo Sirainen{
e217d6fce33746e198ecc21bff0bc658664c9ef4Timo Sirainen struct proxy_mailbox_transaction_context *pt =
8ae72ad7d0c69e972cfa65d1e2ce4e3e9a8b765cTimo Sirainen (struct proxy_mailbox_transaction_context *)t;
70612e07102b75a8511aa7f9de60771176b18de0Timo Sirainen struct proxy_mailbox *pbox = (struct proxy_mailbox *)t->box;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen return pbox->box->copy(pt->ctx, mail, dest_mail_r);
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen}
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen
e217d6fce33746e198ecc21bff0bc658664c9ef4Timo Sirainenstatic int _is_inconsistent(struct mailbox *box)
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen{
5df33e9ee65eec194105b338c55dedbf8422f695Timo Sirainen struct proxy_mailbox *p = (struct proxy_mailbox *) box;
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen
5df33e9ee65eec194105b338c55dedbf8422f695Timo Sirainen return p->box->is_inconsistent(p->box);
5df33e9ee65eec194105b338c55dedbf8422f695Timo Sirainen}
e217d6fce33746e198ecc21bff0bc658664c9ef4Timo Sirainen
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainenvoid proxy_mailbox_init(struct proxy_mailbox *proxy, struct mailbox *box)
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen{
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen struct mailbox *pb = &proxy->proxy_box;
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen proxy->box = box;
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen pb->name = box->name;
77af0bd168cf3e3ddc3ae68abc82bfad7e9b5ff4Timo Sirainen pb->storage = box->storage;
77af0bd168cf3e3ddc3ae68abc82bfad7e9b5ff4Timo Sirainen
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen pb->is_readonly = _is_readonly;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen pb->allow_new_keywords = _allow_new_keywords;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen pb->close = _close;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen pb->get_status = _get_status;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen pb->sync_init = _sync_init;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen pb->sync_next = box->sync_next;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen pb->sync_deinit = box->sync_deinit;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen pb->notify_changes = _notify_changes;
77af0bd168cf3e3ddc3ae68abc82bfad7e9b5ff4Timo Sirainen pb->fetch = _fetch;
77af0bd168cf3e3ddc3ae68abc82bfad7e9b5ff4Timo Sirainen pb->get_uids = _get_uids;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->header_lookup_init = _header_lookup_init;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen pb->search_get_sorting = _search_get_sorting;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->search_init = _search_init;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->search_next = box->search_next;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->search_deinit = box->search_deinit;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen pb->transaction_begin = NULL; /* must be implemented */
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->transaction_commit = _transaction_commit;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->transaction_rollback = _transaction_rollback;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->save_init = _save_init;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen pb->save_continue = box->save_continue;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen pb->save_finish = box->save_finish;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->save_cancel = box->save_cancel;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->copy = _copy;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen pb->is_inconsistent = _is_inconsistent;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen}
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainenvoid proxy_transaction_init(struct proxy_mailbox *proxy_box,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct proxy_mailbox_transaction_context *proxy_ctx,
a4f09749814b93e8ad3ec8a0dc18885b874d6f8cTimo Sirainen struct mailbox_transaction_context *ctx)
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen{
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen proxy_ctx->proxy_ctx.box = &proxy_box->proxy_box;
e217d6fce33746e198ecc21bff0bc658664c9ef4Timo Sirainen proxy_ctx->ctx = ctx;
e217d6fce33746e198ecc21bff0bc658664c9ef4Timo Sirainen}
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen