]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Replace MAIL_STORAGE_SERVICE_FLAG_AUTOEXPUNGE with explicit mail_user_au...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 23 Mar 2017 12:15:49 +0000 (14:15 +0200)
committerGitLab <gitlab@git.dovecot.net>
Thu, 23 Mar 2017 17:21:35 +0000 (19:21 +0200)
This allows better control of which users are being autoexpunged. This
patch changes behavior at least in two ways now:

1) After shared folder access, the owner user isn't autoexpunged at deinit.
Although this is a bit questionable of whether it should be or not.

2) LMTP's quota check at RCPT TO stage doesn't trigger autoexpunging.

src/imap/imap-client.c
src/imap/main.c
src/lib-storage/mail-storage-service.c
src/lib-storage/mail-storage-service.h
src/lib-storage/mail-user.c
src/lib-storage/mail-user.h
src/lmtp/commands.c
src/lmtp/main.c
src/pop3/main.c
src/pop3/pop3-client.c

index e53eb6b314aaefa6b163e355891e5032a3eb90a6..ccedbdcd8850553c7c7bf2f2ef87a323144df58a 100644 (file)
@@ -19,6 +19,7 @@
 #include "mail-error.h"
 #include "mail-namespace.h"
 #include "mail-storage-service.h"
+#include "mail-autoexpunge.h"
 #include "imap-state.h"
 #include "imap-search.h"
 #include "imap-notify.h"
@@ -448,10 +449,13 @@ static void client_default_destroy(struct client *client, const char *reason)
        /* i/ostreams are already closed at this stage, so fd can be closed */
        fd_close_maybe_stdio(&client->fd_in, &client->fd_out);
 
-       /* refresh proctitle before a potentially long-running user unref */
+       /* Autoexpunging might run for a long time. Disconnect the client
+          before it starts, and refresh proctitle so it's clear that it's
+          doing autoexpunging. We've also sent DISCONNECT to anvil already,
+          because this is background work and shouldn't really be counted
+          as an active IMAP session for the user. */
        imap_refresh_proctitle();
-       /* Free the user after client is already disconnected. It may start
-          some background work like autoexpunging. */
+       mail_user_autoexpunge(client->user);
        mail_user_unref(&client->user);
 
        /* free the i/ostreams after mail_user_unref(), which could trigger
index 583086b72861e8980ba3ed64b6a6846e67107491..1edca743fa1dfe9063d5e172530b496d356b6e31 100644 (file)
@@ -381,8 +381,7 @@ int main(int argc, char *argv[])
        };
        struct master_login_settings login_set;
        enum master_service_flags service_flags = 0;
-       enum mail_storage_service_flags storage_service_flags =
-               MAIL_STORAGE_SERVICE_FLAG_AUTOEXPUNGE;
+       enum mail_storage_service_flags storage_service_flags = 0;
        const char *username = NULL, *auth_socket_path = "auth-master";
        int c;
 
index 815e89b914fb13d0d17e418f9de5311ed04b49e6..b37b7b73e456e889e5913efca8c642e6d1ff864f 100644 (file)
@@ -689,8 +689,6 @@ mail_storage_service_init_post(struct mail_storage_service_ctx *ctx,
        }
        mail_user->userdb_fields = user->input.userdb_fields == NULL ? NULL :
                p_strarray_dup(mail_user->pool, user->input.userdb_fields);
-       mail_user->autoexpunge_enabled =
-               (user->flags & MAIL_STORAGE_SERVICE_FLAG_AUTOEXPUNGE) != 0;
        
        mail_set = mail_user_set_get_storage_set(mail_user);
 
index d21667f6345f72bddc8562f05d7d27f6c50136b0..22f5b0403496c48428508b35d8f1b9330b831413 100644 (file)
@@ -34,8 +34,6 @@ enum mail_storage_service_flags {
        MAIL_STORAGE_SERVICE_FLAG_USE_SYSEXITS          = 0x400,
        /* Don't create namespaces, only the user. */
        MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES         = 0x800,
-       /* Enable autoexpunging at deinit. */
-       MAIL_STORAGE_SERVICE_FLAG_AUTOEXPUNGE           = 0x1000
 };
 
 struct mail_storage_service_input {
index 7221c79ccabd906136db98ef07746495951ab40b..ba47897026ba13ac323fffefebc7d4ffe6c721fe 100644 (file)
@@ -199,9 +199,6 @@ void mail_user_unref(struct mail_user **_user)
                return;
        }
 
-       if (user->autoexpunge_enabled && user->namespaces_created)
-               mail_user_autoexpunge(user);
-
        user->deinitializing = TRUE;
 
        /* call deinit() with refcount=1, otherwise we may assert-crash in
index 40731f772e2611e0cafff1e592208acd1a0c79d7..d6e3fb66e29b71a08b86c5958461f7e56c6691b6 100644 (file)
@@ -95,8 +95,6 @@ struct mail_user {
        bool admin:1;
        /* Enable all statistics gathering */
        bool stats_enabled:1;
-       /* Enable autoexpunging at deinit. */
-       bool autoexpunge_enabled:1;
        /* This session was restored (e.g. IMAP unhibernation) */
        bool session_restored:1;
 };
index e28e0f0a6f645aa34bd3b2bacfc99909132b6138..18c97965d6cede475a97bf8a508a932505c898a8 100644 (file)
@@ -27,6 +27,7 @@
 #include "index/raw/raw-storage.h"
 #include "lda-settings.h"
 #include "lmtp-settings.h"
+#include "mail-autoexpunge.h"
 #include "mail-namespace.h"
 #include "mail-deliver.h"
 #include "main.h"
@@ -968,8 +969,10 @@ static bool client_deliver_next(struct client *client, struct mail *src_mail,
                if (ret == 0)
                        return TRUE;
                /* failed. try the next one. */
-               if (client->state.dest_user != NULL)
+               if (client->state.dest_user != NULL) {
+                       mail_user_autoexpunge(client->state.dest_user);
                        mail_user_unref(&client->state.dest_user);
+               }
        }
        return FALSE;
 }
@@ -1056,9 +1059,10 @@ client_input_data_write_local(struct client *client, struct istream *input)
        src_mail = client->state.raw_mail;
        while (client_deliver_next(client, src_mail, session)) {
                if (client->state.first_saved_mail == NULL ||
-                   client->state.first_saved_mail == src_mail)
+                   client->state.first_saved_mail == src_mail) {
+                       mail_user_autoexpunge(client->state.dest_user);
                        mail_user_unref(&client->state.dest_user);
-               else {
+               else {
                        /* use the first saved message to save it elsewhere too.
                           this might allow hard linking the files. */
                        client->state.dest_user = NULL;
@@ -1087,6 +1091,7 @@ client_input_data_write_local(struct client *client, struct istream *input)
                mail_free(&mail);
                mailbox_transaction_rollback(&trans);
                mailbox_free(&box);
+               mail_user_autoexpunge(user);
                mail_user_unref(&user);
        }
 
index 2ef0dd81d84c189f2b61832ac07fb4ea753b3d22..232c5006aa0331d9cc8ac1abf8393927e3397456 100644 (file)
@@ -95,8 +95,7 @@ int main(int argc, char *argv[])
                MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP |
                MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP |
                MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT |
-               MAIL_STORAGE_SERVICE_FLAG_NO_IDLE_TIMEOUT |
-               MAIL_STORAGE_SERVICE_FLAG_AUTOEXPUNGE;
+               MAIL_STORAGE_SERVICE_FLAG_NO_IDLE_TIMEOUT;
        const char *tmp_base_dir;
        int c;
 
index ea846457fa042f306b8247993b9e35ac8434d98a..e12d3da43eabb5c6c594aaf87a67beb2d9369572 100644 (file)
@@ -215,8 +215,7 @@ int main(int argc, char *argv[])
        };
        struct master_login_settings login_set;
        enum master_service_flags service_flags = 0;
-       enum mail_storage_service_flags storage_service_flags =
-               MAIL_STORAGE_SERVICE_FLAG_AUTOEXPUNGE;
+       enum mail_storage_service_flags storage_service_flags = 0;
        const char *username = NULL, *auth_socket_path = "auth-master";
        int c;
 
index 0a8aad6f34f363aa5589ce4ed8bf7c6671a5d138..2d64a7ed84cc6133a8d1a994279acf89f2d2dfbe 100644 (file)
@@ -17,6 +17,7 @@
 #include "master-service.h"
 #include "mail-storage.h"
 #include "mail-storage-service.h"
+#include "mail-autoexpunge.h"
 #include "pop3-commands.h"
 #include "mail-search-build.h"
 #include "mail-namespace.h"
@@ -636,8 +637,13 @@ static void client_default_destroy(struct client *client, const char *reason)
 
        fd_close_maybe_stdio(&client->fd_in, &client->fd_out);
 
-       /* refresh proctitle before a potentially long-running user unref */
+       /* Autoexpunging might run for a long time. Disconnect the client
+          before it starts, and refresh proctitle so it's clear that it's
+          doing autoexpunging. We've also sent DISCONNECT to anvil already,
+          because this is background work and shouldn't really be counted
+          as an active POP3 session for the user. */
        pop3_refresh_proctitle();
+       mail_user_autoexpunge(client->user);
        mail_user_unref(&client->user);
        mail_storage_service_user_unref(&client->service_user);