quota-storage.c revision 7ee626fd396f5549fb1fc6b0c320038638af9058
/* Copyright (c) 2005-2017 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "istream.h"
#include "mail-search-build.h"
#include "mail-storage-private.h"
#include "mailbox-list-private.h"
#include "maildir-storage.h"
#include "index-mailbox-size.h"
#include "quota-private.h"
#include "quota-plugin.h"
#define QUOTA_CONTEXT(obj) \
#define QUOTA_MAIL_CONTEXT(obj) \
#define QUOTA_LIST_CONTEXT(obj) \
struct quota_mailbox_list {
};
struct quota_mailbox {
union mailbox_module_context module_ctx;
struct mailbox_transaction_context *expunge_trans;
struct quota_transaction_context *expunge_qt;
unsigned int prev_idx;
bool recalculate:1;
bool sync_transaction_expunge:1;
};
struct quota_user_module quota_user_module =
struct mail_storage *storage,
enum quota_alloc_result res,
const char *internal_err)
{
switch (res) {
break;
break;
break;
case QUOTA_ALLOC_RESULT_OK:
i_unreached();
}
}
{
int ret;
if (qt->auto_updating) {
return;
}
/* We need to handle the situation where multiple transactions expunged
the mail at the same time. In here we'll just save the message's
physical size and do the quota freeing later when the message was
known to be expunged. */
else
if (ret == 0) {
}
/* we're running dsync. if this brings the quota below
a negative quota warning, don't execute it, because
it probably was already executed by the replica. */
} else {
}
}
}
static int
struct mailbox_status *status_r)
{
struct quota_transaction_context *qt;
int ret = 0;
if ((items & STATUS_CHECK_OVER_QUOTA) != 0) {
const char *error;
if (qret != QUOTA_ALLOC_RESULT_OK) {
ret = -1;
}
if ((items & ~STATUS_CHECK_OVER_QUOTA) == 0) {
/* don't bother calling parent, it may unnecessarily
try to open the mailbox */
return ret < 0 ? -1 : 0;
}
}
ret = -1;
return ret < 0 ? -1 : 0;
}
static struct mailbox_transaction_context *
const char *reason)
{
struct mailbox_transaction_context *t;
struct quota_transaction_context *qt;
return t;
}
static int
struct mail_transaction_commit_changes *changes_r)
{
return -1;
} else {
(void)quota_transaction_commit(&qt);
return 0;
}
}
static void
{
}
{
union mail_module_context *qmail;
return;
v->expunge = quota_mail_expunge;
}
static bool
{
struct quota_root *const *rootp;
bool have_src_quota, have_dest_quota;
if (have_src_quota == have_dest_quota) {
} else if (have_dest_quota) {
/* Destination mailbox has a quota that doesn't exist
in source. We'll need to check if it's being
exceeded. */
return TRUE;
} else {
/* Source mailbox has a quota root that doesn't exist
in destination. We're not increasing the source
quota, so ignore it. */
}
}
return FALSE;
}
{
enum quota_alloc_result ret;
/* the mail is being moved. the quota won't increase (after
the following expunge), so allow this even if user is
currently over quota */
return 0;
}
const char *error;
switch (ret) {
case QUOTA_ALLOC_RESULT_OK:
return 0;
/* Log the error, but allow saving anyway. */
return 0;
/* Could not determine if there is enough space due to ongoing
background quota calculation, allow saving anyway. */
return 0;
default:
return -1;
}
}
static int
{
/* we always want to know the mail size */
/* get quota before copying any mails. this avoids .vsize.lock
enum quota_get_result error_res;
const char *error;
return -1;
if (ctx->copying_via_save) {
/* copying used saving internally, we already checked the
quota */
return 0;
}
}
static int
{
const char *error;
/* Input size is known, check for quota immediately. This
check isn't perfect, especially because input stream's
linefeeds may contain CR+LFs while physical message would
only contain LFs. With mbox some headers might be skipped
entirely.
I think these don't really matter though compared to the
benefit of giving "out of quota" error before sending the
full mail. */
switch (qret) {
case QUOTA_ALLOC_RESULT_OK:
/* Great, there is space. */
break;
/* Log the error, but allow saving anyway. */
break;
/* Could not determine if there is enough space due to
* ongoing background quota calculation, allow saving
* anyway. */
break;
default:
return -1;
}
}
/* we always want to know the mail size */
/* get quota before copying any mails. this avoids .vsize.lock
enum quota_get_result error_res;
}
{
return -1;
}
{
}
}
}
{
}
enum mailbox_sync_type sync_type)
{
unsigned int i, count;
if (uid == 0) {
/* free the transaction before view syncing begins,
otherwise it'll crash. */
}
return;
}
}
make sure count_used changes so quota_warnings are
executed */
return;
}
/* we're in the middle of syncing the mailbox, so it's a bad idea to
try and get the message sizes at this point. Rely on sizes that
we saved earlier, or recalculate the whole quota if we don't know
the size. */
i = count = 0;
} else {
break;
}
if (i >= count) {
break;
}
i = count;
}
}
if (i != count) {
/* we already know the size */
/* FIXME: it's not ideal that we do the vsize update here, but
this is the easiest place for it for now.. maybe the mail
size checking code could be moved to lib-storage */
return;
}
/* try to look up the size. this works only if it's cached. */
/* FIXME: ugly kludge to open the transaction for sync_view.
box->view may not have all the new messages that
sync_notify() notifies about, and those messages would
cause a quota recalculation. */
}
;
return;
}
} else {
/* there's no way to get the size. recalculate the quota. */
}
}
struct mailbox_sync_status *status_r)
{
int ret;
/* update quota only after syncing is finished. the quota commit may
recalculate the quota and cause all mailboxes to be synced,
including the one we're already syncing. */
return ret;
}
{
struct quota_root *const *roots;
unsigned int i, count;
for (i = 0; i < count; i++) {
}
}
{
/* sync_notify() may be called outside sync_begin()..sync_deinit().
make sure we apply changes at close time at latest. */
/* make sure quota backend flushes all data. this could also be done
somewhat later, but user.deinit() is too late, since the flushing
can trigger quota recalculation which isn't safe to do anymore
at user.deinit() when most of the loaded plugins have already been
deinitialized. */
}
{
}
}
{
struct quota_mailbox *qbox;
return;
return;
v->get_status = quota_get_status;
v->save_begin = quota_save_begin;
v->save_finish = quota_save_finish;
v->copy = quota_copy;
v->close = quota_mailbox_close;
v->free = quota_mailbox_free;
}
{
}
{
}
{
}
{
struct quota_user *quser;
struct quota_settings *set;
const char *error;
int ret;
ret = -1;
}
}
if (ret < 0) {
"Failed to initialize quota: %s", error);
return;
}
if (ret > 0) {
v->deinit = quota_user_deinit;
} else if (user->mail_debug) {
i_debug("quota: No quota setting - plugin disabled");
}
}
static struct quota_root *
{
struct quota_root *const *roots;
unsigned int i, count;
for (i = 0; i < count; i++) {
return roots[i];
}
return NULL;
}
{
struct quota_mailbox_list *qlist;
struct quota_root *root;
struct mail_user *quota_user;
bool add;
/* see if we have a quota explicitly defined for this namespace */
return;
/* explicit quota root */
} else {
}
/* public namespace - add quota only if namespace is
explicitly defined for it */
} else {
/* for shared namespaces add only if the owner has quota
enabled */
}
if (add) {
}
}
struct mail_namespace *namespaces)
{
const struct quota_rule *rule;
const char *name;
struct mail_namespace *ns;
/* silence errors for autocreated (shared) users */
i_error("quota: Unknown namespace: %s",
}
}
}
}
{
struct quota_root *const *roots;
unsigned int i, count;
return;
for (i = 0; i < count; i++)
}