]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Don't execute quota_over_script if userdb lookup was over 10 secs ago
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 10 Oct 2016 14:19:32 +0000 (17:19 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 13 Oct 2016 08:26:06 +0000 (10:26 +0200)
src/plugins/quota/quota.c

index 05002da445f61f6f5aa00122fd76f23c8da3c066..902277c819c06e5d3b9b7b916ec264a49f901d2c 100644 (file)
@@ -4,6 +4,7 @@
 #include "array.h"
 #include "hash.h"
 #include "str.h"
+#include "ioloop.h"
 #include "net.h"
 #include "write-full.h"
 #include "eacces-error.h"
        "Quota exceeded (mailbox for user is full)"
 #define QUOTA_LIMIT_SET_PATH DICT_PATH_PRIVATE"quota/limit/"
 
+/* How many seconds after the userdb lookup do we still want to execute the
+   quota_over_script. This applies to quota_over_flag_lazy_check=yes and also
+   after unhibernating IMAP connections. */
+#define QUOTA_OVER_FLAG_MAX_DELAY_SECS 10
+
 struct quota_root_iter {
        struct quota *quota;
        struct mailbox *box;
@@ -1038,6 +1044,17 @@ static void quota_over_flag_check_root(struct quota_root *root)
 
        if (root->quota_over_flag_checked)
                return;
+       if (root->quota->user->session_create_time +
+           QUOTA_OVER_FLAG_MAX_DELAY_SECS < ioloop_time) {
+               /* userdb's quota_over_flag lookup is too old. */
+               return;
+       }
+       if (root->quota->user->session_restored) {
+               /* we don't know whether the quota_over_script was executed
+                  before hibernation. just assume that it was, so we don't
+                  unnecessarily call it too often. */
+               return;
+       }
        root->quota_over_flag_checked = TRUE;
        quota_over_flag_init_root(root);