annotate src/plugins/trash/trash-plugin.c @ 5577:1fd9616157e4 HEAD

Updated to support namespaces
author Timo Sirainen <tss@iki.fi>
date Tue, 17 Apr 2007 21:00:48 +0300
parents 67b8d61c988f
children 6074e9e6059d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2005 Timo Sirainen */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "array.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "istream.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "home-expand.h"
5577
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
7 #include "mail-namespace.h"
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "mail-search.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "quota-private.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "quota-plugin.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "trash-plugin.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include <stdlib.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include <unistd.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include <fcntl.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
5187
9dd18b285223 Minor memory allocation optimizations.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
17 #define INIT_TRASH_MAILBOX_COUNT 4
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #define MAX_RETRY_COUNT 3
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 struct trash_mailbox {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 const char *name;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 int priority; /* lower number = higher priority */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 struct mail_storage *storage;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 /* temporarily set while cleaning: */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 struct mailbox *box;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 struct mailbox_transaction_context *trans;
4748
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
29 struct mail_search_arg search_arg;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 struct mail_search_context *search_ctx;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 struct mail *mail;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 unsigned int mail_set:1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 };
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35
5185
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 5158
diff changeset
36 const char *trash_plugin_version = PACKAGE_VERSION;
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 5158
diff changeset
37
4514
511f1f5c76fa Changes to make trash plugin working again.
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
38 static int (*trash_next_quota_test_alloc)(struct quota_transaction_context *,
511f1f5c76fa Changes to make trash plugin working again.
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
39 uoff_t, bool *);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 static pool_t config_pool;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 /* trash_boxes ordered by priority, highest first */
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4400
diff changeset
43 static ARRAY_DEFINE(trash_boxes, struct trash_mailbox);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44
4748
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
45 static int sync_mailbox(struct mailbox *box)
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
46 {
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
47 struct mailbox_sync_context *ctx;
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
48 struct mailbox_sync_rec sync_rec;
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
49
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
50 ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
51 while (mailbox_sync_next(ctx, &sync_rec) > 0)
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
52 ;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4796
diff changeset
53 return mailbox_sync_deinit(&ctx, 0, NULL);
4748
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
54 }
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
55
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 static int trash_clean_mailbox_open(struct trash_mailbox *trash)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 trash->box = mailbox_open(trash->storage, trash->name, NULL,
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 MAILBOX_OPEN_KEEP_RECENT);
5147
6b0032df7008 If trash mailbox can't be opened, don't crash.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
60 if (trash->box == NULL)
5188
519ab252f1a3 Fixes for handling multiple storages.
Timo Sirainen <tss@iki.fi>
parents: 5187
diff changeset
61 return 0;
5147
6b0032df7008 If trash mailbox can't be opened, don't crash.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
62
4748
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
63 if (sync_mailbox(trash->box) < 0)
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
64 return -1;
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
65
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 trash->trans = mailbox_transaction_begin(trash->box, 0);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67
4748
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
68 trash->search_ctx = mailbox_search_init(trash->trans, NULL,
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
69 &trash->search_arg, NULL);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 trash->mail = mail_alloc(trash->trans, MAIL_FETCH_PHYSICAL_SIZE |
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 MAIL_FETCH_RECEIVED_DATE, NULL);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 return mailbox_search_next(trash->search_ctx, trash->mail);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 static int trash_clean_mailbox_get_next(struct trash_mailbox *trash,
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 time_t *received_time_r)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 int ret;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 if (!trash->mail_set) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 if (trash->box == NULL)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 ret = trash_clean_mailbox_open(trash);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 else
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 ret = mailbox_search_next(trash->search_ctx,
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 trash->mail);
5188
519ab252f1a3 Fixes for handling multiple storages.
Timo Sirainen <tss@iki.fi>
parents: 5187
diff changeset
87 if (ret <= 0) {
519ab252f1a3 Fixes for handling multiple storages.
Timo Sirainen <tss@iki.fi>
parents: 5187
diff changeset
88 *received_time_r = 0;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 return ret;
5188
519ab252f1a3 Fixes for handling multiple storages.
Timo Sirainen <tss@iki.fi>
parents: 5187
diff changeset
90 }
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 trash->mail_set = TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 *received_time_r = mail_get_received_date(trash->mail);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 return 1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97
5577
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
98 static void trash_find_storage(struct trash_mailbox *trash)
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
99 {
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
100 struct mail_storage *const *storages;
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
101 unsigned int i, count;
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
102
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
103 storages = array_get(&quota_set->storages, &count);
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
104 for (i = 0; i < count; i++) {
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
105 if (mail_namespace_update_name(storages[i]->ns, &trash->name)) {
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
106 trash->storage = storages[i];
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
107 return;
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
108 }
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
109 }
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
110 i_fatal("trash: Namespace not found for mailbox '%s'", trash->name);
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
111 }
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
112
5158
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
113 static int trash_try_clean_mails(struct quota_transaction_context *ctx,
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
114 uint64_t size_needed)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 struct trash_mailbox *trashes;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 unsigned int i, j, count, oldest_idx;
5297
67b8d61c988f compiler warning fix
Timo Sirainen <tss@iki.fi>
parents: 5189
diff changeset
118 time_t oldest, received = 0;
5158
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
119 uint64_t size, size_expunged = 0, expunged_count = 0;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 int ret = 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4400
diff changeset
122 trashes = array_get_modifiable(&trash_boxes, &count);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 for (i = 0; i < count; ) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 /* expunge oldest mails first in all trash boxes with
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 same priority */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 oldest_idx = count;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 oldest = (time_t)-1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 for (j = i; j < count; j++) {
5189
7ec060a7c29f Fixed priority handling.
Timo Sirainen <tss@iki.fi>
parents: 5188
diff changeset
129 if (trashes[j].priority != trashes[i].priority)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 break;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131
5577
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
132 if (trashes[j].storage == NULL)
1fd9616157e4 Updated to support namespaces
Timo Sirainen <tss@iki.fi>
parents: 5297
diff changeset
133 trash_find_storage(&trashes[j]);
5188
519ab252f1a3 Fixes for handling multiple storages.
Timo Sirainen <tss@iki.fi>
parents: 5187
diff changeset
134
519ab252f1a3 Fixes for handling multiple storages.
Timo Sirainen <tss@iki.fi>
parents: 5187
diff changeset
135 ret = trash_clean_mailbox_get_next(&trashes[j],
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136 &received);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 if (ret < 0)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 goto __err;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 if (ret > 0) {
5188
519ab252f1a3 Fixes for handling multiple storages.
Timo Sirainen <tss@iki.fi>
parents: 5187
diff changeset
140 if (oldest == (time_t)-1 || received < oldest) {
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 oldest = received;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 oldest_idx = j;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 if (oldest_idx < count) {
5158
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
148 size = mail_get_physical_size(trashes[oldest_idx].mail);
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
149 if (size == (uoff_t)-1) {
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
150 /* maybe expunged already? */
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
151 trashes[oldest_idx].mail_set = FALSE;
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
152 continue;
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
153 }
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
154
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 if (mail_expunge(trashes[oldest_idx].mail) < 0)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 break;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157
5158
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
158 expunged_count++;
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
159 size_expunged += size;
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
160 if (size_expunged >= size_needed)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 break;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 trashes[oldest_idx].mail_set = FALSE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 } else {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 /* find more mails from next priority's mailbox */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 i = j;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 __err:
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 for (i = 0; i < count; i++) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 struct trash_mailbox *trash = &trashes[i];
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172
5157
df22aec605b7 If trash mailbox couldn't be opened, don't crash later either.
Timo Sirainen <tss@iki.fi>
parents: 5147
diff changeset
173 if (trash->box == NULL)
df22aec605b7 If trash mailbox couldn't be opened, don't crash later either.
Timo Sirainen <tss@iki.fi>
parents: 5147
diff changeset
174 continue;
df22aec605b7 If trash mailbox couldn't be opened, don't crash later either.
Timo Sirainen <tss@iki.fi>
parents: 5147
diff changeset
175
4748
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
176 trash->mail_set = FALSE;
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
177 mail_free(&trash->mail);
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
178 (void)mailbox_search_deinit(&trash->search_ctx);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179
5158
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
180 if (size_expunged >= size_needed) {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
181 (void)mailbox_transaction_commit(&trash->trans,
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 MAILBOX_SYNC_FLAG_FULL_WRITE);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 } else {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 /* couldn't get enough space, don't expunge anything */
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
185 mailbox_transaction_rollback(&trash->trans);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
188 mailbox_close(&trash->box);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 }
5158
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
190
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
191 if (size_expunged < size_needed)
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
192 return FALSE;
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
193
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
194 ctx->bytes_used = ctx->bytes_used > (int64_t)size_expunged ?
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
195 ctx->bytes_used - size_expunged : 0;
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
196 ctx->count_used = ctx->count_used > (int64_t)expunged_count ?
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
197 ctx->count_used - expunged_count : 0;
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
198 return TRUE;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 static int
4514
511f1f5c76fa Changes to make trash plugin working again.
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
202 trash_quota_test_alloc(struct quota_transaction_context *ctx,
511f1f5c76fa Changes to make trash plugin working again.
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
203 uoff_t size, bool *too_large_r)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
204 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 int ret, i;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 for (i = 0; ; i++) {
4514
511f1f5c76fa Changes to make trash plugin working again.
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
208 ret = trash_next_quota_test_alloc(ctx, size, too_large_r);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209 if (ret != 0 || *too_large_r)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
210 return ret;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
211
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 if (i == MAX_RETRY_COUNT) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 /* trash_try_clean_mails() should have returned 0 if
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214 it couldn't get enough space, but allow retrying
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 it a couple of times if there was some extra space
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 that was needed.. */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 break;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220 /* not enough space. try deleting some from mailbox. */
5158
aa9b1fec1c21 Although messages were expunged, the expunges weren't counted in that same
Timo Sirainen <tss@iki.fi>
parents: 5157
diff changeset
221 ret = trash_try_clean_mails(ctx, size);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222 if (ret <= 0)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
223 return 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
225
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
226 return 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229 static int trash_mailbox_priority_cmp(const void *p1, const void *p2)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 const struct trash_mailbox *t1 = p1, *t2 = p2;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 return t1->priority - t2->priority;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 static int read_configuration(const char *path)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238 struct istream *input;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 const char *line, *name;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240 struct trash_mailbox *trash;
4602
444edc8abef9 Don't allow giving NULL parameter to array_get() or array_get_modifiable().
Timo Sirainen <tss@iki.fi>
parents: 4596
diff changeset
241 unsigned int count;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242 int fd;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
244 fd = open(path, O_RDONLY);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245 if (fd == -1) {
4400
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
246 i_error("open(%s) failed: %m", path);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
247 return -1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
249
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 p_clear(config_pool);
5187
9dd18b285223 Minor memory allocation optimizations.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
251 p_array_init(&trash_boxes, config_pool, INIT_TRASH_MAILBOX_COUNT);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 input = i_stream_create_file(fd, default_pool, (size_t)-1, FALSE);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254 while ((line = i_stream_read_next_line(input)) != NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255 /* <priority> <mailbox name> */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 name = strchr(line, ' ');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257 if (name == NULL || name[1] == '\0')
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
258 continue;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 trash = array_append_space(&trash_boxes);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261 trash->name = p_strdup(config_pool, name+1);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 trash->priority = atoi(t_strdup_until(line, name));
4748
5fb199ed254a Trash plugin was completely broken before.
Timo Sirainen <tss@iki.fi>
parents: 4602
diff changeset
263 trash->search_arg.type = SEARCH_ALL;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
264 }
4070
71b8faa84ec6 Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
265 i_stream_destroy(&input);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 (void)close(fd);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267
4602
444edc8abef9 Don't allow giving NULL parameter to array_get() or array_get_modifiable().
Timo Sirainen <tss@iki.fi>
parents: 4596
diff changeset
268 trash = array_get_modifiable(&trash_boxes, &count);
444edc8abef9 Don't allow giving NULL parameter to array_get() or array_get_modifiable().
Timo Sirainen <tss@iki.fi>
parents: 4596
diff changeset
269 qsort(trash, count, sizeof(*trash), trash_mailbox_priority_cmp);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270 return 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
272
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273 void trash_plugin_init(void)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 {
4400
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
275 const char *env;
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
276
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
277 env = getenv("TRASH");
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
278 if (env == NULL)
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
279 return;
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
280
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4748
diff changeset
281 if (quota_set == NULL) {
4400
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
282 i_error("trash plugin: quota plugin not initialized");
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
283 return;
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
284 }
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
285
5187
9dd18b285223 Minor memory allocation optimizations.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
286 config_pool = pool_alloconly_create("trash config",
9dd18b285223 Minor memory allocation optimizations.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
287 sizeof(trash_boxes) +
9dd18b285223 Minor memory allocation optimizations.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
288 BUFFER_APPROX_SIZE +
9dd18b285223 Minor memory allocation optimizations.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
289 INIT_TRASH_MAILBOX_COUNT *
9dd18b285223 Minor memory allocation optimizations.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
290 (sizeof(struct trash_mailbox) + 32));
4400
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
291 if (read_configuration(env) < 0)
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
292 return;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4748
diff changeset
294 trash_next_quota_test_alloc = quota_set->test_alloc;
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4748
diff changeset
295 quota_set->test_alloc = trash_quota_test_alloc;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
297
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298 void trash_plugin_deinit(void)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299 {
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4748
diff changeset
300 quota_set->test_alloc = trash_next_quota_test_alloc;
4514
511f1f5c76fa Changes to make trash plugin working again.
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
301
4400
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
302 if (config_pool != NULL)
593523f53500 Removed hardcoded trash plugin configuration paths. Added information about
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
303 pool_unref(config_pool);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304 }