DOVEADM-EXPUNGE(1)
π DOVEADM-EXPUNGE π
okay bestie, gather round, because today we're learning about doveadm-expunge β one of the doveadm(1) girlies, straight outta the Dovecot family. this one expunges messages matching a given search query. it's giving janitor energy but make it couture. π§Ήβ¨
πΈ NAME πΈ
doveadm-expunge β expunge messages matching given search query
β¨ SYNOPSIS β¨
doveadm [GLOBAL OPTIONS] expunge [-S socket_path] [-d] -A search_query
doveadm [GLOBAL OPTIONS] expunge [-S socket_path] [-d] -F file search_query
doveadm [GLOBAL OPTIONS] expunge [-S socket_path] [-d] --no-userdb-lookup search_query
doveadm [GLOBAL OPTIONS] expunge [-S socket_path] [-d] -u user search_query
four whole forms, she's versatile like that π
π¦ DESCRIPTION π¦
so like, this command expunges mails that match the search query you give it. that's the whole vibe. it's typically used to yeet old mails out of users' Trash and/or Spam mailboxes, which honestly? iconic. trash day but it's automated.
not me about to tell you the most important part: if you wanna test which messages a given search query would match before you nuke them, go usedoveadm fetchordoveadm searchfirst. bestie. PLEASE. do the vibe check first. π
okay so the four forms, one by one:
- first form β the command runs for all users. everybody. the whole group chat.
- second form β
doveadm(1)expunges messages of the users listed in the given file. - third form β the command runs for the user contained in the
USERenvironment variable. - final form β only the matching mails of the given user(s) get expunged. just them. nobody else. periodt.
π GLOBAL OPTIONS π
these are the global doveadm(1) options, so they're like, the shared fit that every doveadm command wears π
-Dβ turns on verbosity AND debug messages. she's chatty and she's telling you everything.-Oβ do not read any config file, just use defaults. thedovecot_storage_versionsetting defaults to the latest version, but you can override it with-o. (yes, defaults-only mode. feral. love that for her.)-kβ preserve the entire environment fordoveadm, not just theimport_environmentsetting.-vβ enables verbosity, including a progress counter. progress bar slay π-iinstance-name β if you're running multiple Dovecot instances, choose the config file based on this instance name. see theinstance_namesetting for more info.-cconfig-file β read configuration from the given config-file. by default it first reads config socket, and then falls back to/etc/dovecot/dovecot.conf. you can also point this at the config socket of some instance running a compatible version.-osetting=value β overrides the configuration setting from/etc/dovecot/dovecot.confand from the userdb with the given value. to override multiple settings, you can specify the-ooption multiple times. stack 'em like bracelets. π
π OPTIONS π
-Aβ if the-Aoption is present, the command will be performed for all users. β οΈ but listen: using this option in combination with system users fromuserdb { driver = passwd }is not recommended, because it also contains users with a lower UID than the one configured with thefirst_valid_uidsetting. so like, be careful, okay?
when the SQL userdb module is used, make sure that the userdb_sql_iterate_query setting setting matches your database layout.
when using the LDAP userdb module, make sure that the userdb_fields setting and userdb_ldap_iterate_fields setting settings match your LDAP schema. otherwise doveadm(1) will be unable to iterate over all users. and then she's just sitting there like π§ββοΈ
-dβ delete the mailbox if it is empty after expunging. if it's empty, it's gone-gone. bye mailbox π-Ffile β execute the command for all the users in the file. this is similar to the-Aoption, but instead of getting the list of users from the userdb, they are read from the given file. the file contains one username per line. one per line bestie, don't get cute with it.--no-userdb-lookupβ do not perform userdb lookup. use theUSERenvironment variable to specify the username.-Ssocket_path β the option's argument is either an absolute path to a local UNIX domain socket, or a hostname and port (hostname:port), in order to connect a remote host via a TCP socket.
this allows an administrator to execute doveadm(1) mail commands through the given socket. remote queen behavior π₯
-uuser/mask β run the command only for the given user. it's also possible to use'*'and'?'wildcards (e.g.-u *@example.org). wildcards, we love a flexible filter β¨
π ARGUMENTS π
search_query
expunge messages matching this search query. see doveadm-search-query(7) for details.
A mailbox parameter is REQUIRED. π
A message range limiter is REQUIRED. in other words, you must have at least one query parameter that limits the message range. if all messages are needed, the "all" query parameter can be used. no accidentally expunging the entire mailbox, we are NOT doing that today. π
ββοΈ
π EXAMPLE π
this example expunges messages from the Spam mailbox that were saved/copied there more than two weeks ago:
doveadm expunge -u jane.doe@example.org mailbox Spam savedbefore 2w
look at that. clean. savedbefore 2w. two weeks of spam, evaporated. she ate. π
π REPORTING BUGS π
found a bug? report it β including doveconf -n output β to the Dovecot Mailing List β¨dovecot@dovecot.orgβ©.
info about reporting bugs lives at: β¨https://dovecot.org/bugreport.htmlβ©
(and yes, include the doveconf -n output, they will ask for it, save yourself the round trip bestie π«Ά)
π₯ SEE ALSO π₯
and that's the whole page, bestie!! π this one's from the Dovecot manual, page revision f979264, dated April 2026. mwah. go expunge responsibly. π¦πβ¨
π¦ where this page comes from
- alpine 3.23: dovecot-doc 2.4.5-r0 Β· MIT AND LGPL-2.1-or-later
- alpine 3.24: dovecot-doc 2.4.5-r0 Β· MIT AND LGPL-2.1-or-later
- arch rolling: dovecot 2.4.5-1 Β· MIT AND LGPL-2.1-only
- fedora 43: dovecot 1:2.4.5-1.fc43 Β· MIT AND LGPL-2.1-only
- fedora 44: dovecot 1:2.4.5-1.fc44 Β· MIT AND LGPL-2.1-only
- nixos 26.05: dovecot 2.4.5
- nixpkgs unstable: dovecot 2.4.5
- opensuse-leap 16.0: dovecot24 2.4.5-160000.1.1 Β· BSD-3-Clause AND LGPL-2.1-or-later AND MIT
- opensuse-leap 16.0: dovecot24 2.4.5-160000.1.1 Β· BSD-3-Clause AND LGPL-2.1-or-later AND MIT
- opensuse-leap 16.0: dovecot24 2.4.5-160000.1.1 Β· BSD-3-Clause AND LGPL-2.1-or-later AND MIT
- opensuse-leap 16.0: dovecot24 2.4.5-160000.1.1 Β· BSD-3-Clause AND LGPL-2.1-or-later AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms