Automatic purging of old email in all mailboxes

Edgar Pettijohn edgar at pettijohn-web.com
Mon Aug 29 22:18:58 UTC 2016



Sent from my iPhone

> On Aug 29, 2016, at 3:29 PM, Scott W. Sander <scottwsx96 at gmail.com> wrote:
> 
> I used this guide as the starting point for this postfix + Dovecot server:
> http://www.binarytides.com/install-postfix-dovecot-debian/.
> 
> My /etc/dovecot/dovecot-users passwd-file only has username:password (as
> mentioned in that article) and my userdb driver is static as laid out in
> the article as well.  Therefore I do not have uid's.
> 
> As far as changing the userdb driver from static to passwd-file, I'm not
> sure what the consequence of that would be for my existing mailboxes or my
> Dovecot implementation in general.  Everything I needed thus far is
> working, I just want to add clearing out old email automatically.
> 
> 
>> On Mon, Aug 29, 2016 at 4:13 PM Joseph Tam <jtam.home at gmail.com> wrote:
>> 
>> "Scott W. Sander" <scottwsx96 at gmail.com> writes:
>> 
>>> A few of the mailboxes in Dovecot receive hundreds of emails per day.
>> I'd
>>> like to automatically remove all emails in all mailboxes and mailbox
>>> folders that were received more than 90 days prior to the received date.
>>> As I'm a novice Dovecot administrator, I'm not exactly sure what the best
>>> way to accomplish this is, but I've started looking at the "doveadm
>>> expunge" command.  I figure I could create a cron job that calls this
>>> command with the -A switch and that has a search query that finds all
>>> emails older than 90 days.
>> 
>> That more of less what I do.
>> 
>>        doveadm expunge -A mailbox INBOX savedbefore 7d

Cron

>> 
>>> Error: User listing returned failure
>>> doveadm: Error: Failed to iterate through some users
>> 
>> I think this may be avoided (or made into warnings) if you bracket all
>> user UID ranges with
>> 
>>        first_valid_uid = {first user uid}
>>        last_valid_uid = {last user uid}
>> 
>> Sean Greenslade <sean at seangreenslade.com> then writes:
>> 
>>> Since you're using maildirs as the storage backend, it might be easier
>>> to just write a small script in the language of your preference (bash,
>>> python, perl, etc.) that walks the directory tree and deletes files
>>> based on their mtime.
>> 
>> The downside is that the Dovecot caches will be out of date.  Perhaps
>> follow this up with a "doveadm index ..." operation.
>> 
>> Joseph Tam <jtam.home at gmail.com>
>> 


More information about the dovecot mailing list