trash-plugin.c revision bd8f849ab303e0da30a0383107a1b8078aece4f0
5aefb6555731130ca4fd295960123d71f2d21fe8rie/* Copyright (C) 2005 Timo Sirainen */
5aefb6555731130ca4fd295960123d71f2d21fe8rie const char *name;
5aefb6555731130ca4fd295960123d71f2d21fe8rie /* temporarily set while cleaning: */
5aefb6555731130ca4fd295960123d71f2d21fe8riestatic int (*trash_next_quota_test_alloc)(struct quota_transaction_context *,
5aefb6555731130ca4fd295960123d71f2d21fe8rie/* trash_boxes ordered by priority, highest first */
981a172d53aeb81520fcfecf6ab2615277c7bd18ab ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahramistatic int trash_clean_mailbox_open(struct trash_mailbox *trash)
981a172d53aeb81520fcfecf6ab2615277c7bd18ab trash->box = mailbox_open(trash->storage, trash->name, NULL,
981a172d53aeb81520fcfecf6ab2615277c7bd18ab return -1;
981a172d53aeb81520fcfecf6ab2615277c7bd18ab trash->search_ctx = mailbox_search_init(trash->trans, NULL,
981a172d53aeb81520fcfecf6ab2615277c7bd18ab trash->mail = mail_alloc(trash->trans, MAIL_FETCH_PHYSICAL_SIZE |
981a172d53aeb81520fcfecf6ab2615277c7bd18ab return mailbox_search_next(trash->search_ctx, trash->mail);
981a172d53aeb81520fcfecf6ab2615277c7bd18abstatic int trash_clean_mailbox_get_next(struct trash_mailbox *trash,
5aefb6555731130ca4fd295960123d71f2d21fe8rie for (i = 0; i < count; ) {
5aefb6555731130ca4fd295960123d71f2d21fe8rie /* FIXME: this is really ugly. it'll do however until
5aefb6555731130ca4fd295960123d71f2d21fe8rie we get proper namespace support for lib-storage. */
31fdd7ca2d295948f9f1bcc2a1178c66467bca63ab /* expunge oldest mails first in all trash boxes with
5aefb6555731130ca4fd295960123d71f2d21fe8rie same priority */
5aefb6555731130ca4fd295960123d71f2d21fe8rie for (j = i; j < count; j++) {
5aefb6555731130ca4fd295960123d71f2d21fe8rie if (ret > 0) {
981a172d53aeb81520fcfecf6ab2615277c7bd18ab /* find more mails from next priority's mailbox */
981a172d53aeb81520fcfecf6ab2615277c7bd18ab for (i = 0; i < count; i++) {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab /* couldn't get enough space, don't expunge anything */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab return size_needed == 0;
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtrash_quota_test_alloc(struct quota_transaction_context *ctx,
5aefb6555731130ca4fd295960123d71f2d21fe8rie for (i = 0; ; i++) {
5aefb6555731130ca4fd295960123d71f2d21fe8rie ret = trash_next_quota_test_alloc(ctx, size, too_large_r);
5aefb6555731130ca4fd295960123d71f2d21fe8rie /* trash_try_clean_mails() should have returned 0 if
5aefb6555731130ca4fd295960123d71f2d21fe8rie it couldn't get enough space, but allow retrying
5aefb6555731130ca4fd295960123d71f2d21fe8rie it a couple of times if there was some extra space
5aefb6555731130ca4fd295960123d71f2d21fe8rie that was needed.. */
5aefb6555731130ca4fd295960123d71f2d21fe8rie /* not enough space. try deleting some from mailbox. */
5aefb6555731130ca4fd295960123d71f2d21fe8riestatic int trash_mailbox_priority_cmp(const void *p1, const void *p2)
5aefb6555731130ca4fd295960123d71f2d21fe8rie unsigned int count;
5aefb6555731130ca4fd295960123d71f2d21fe8rie return -1;
5aefb6555731130ca4fd295960123d71f2d21fe8rie input = i_stream_create_file(fd, default_pool, (size_t)-1, FALSE);
5aefb6555731130ca4fd295960123d71f2d21fe8rie while ((line = i_stream_read_next_line(input)) != NULL) {
5aefb6555731130ca4fd295960123d71f2d21fe8rie /* <priority> <mailbox name> */
39773e466ff90ce703d7f52f3267d7e96c09c6f5ab qsort(trash, count, sizeof(*trash), trash_mailbox_priority_cmp);
5aefb6555731130ca4fd295960123d71f2d21fe8rie const char *env;
void trash_plugin_deinit(void)