Skip to content

Retention and exclusion rules#

How long piler keeps an email, and which emails it doesn't archive at all. The admin manages both on Compliance > Retention Policy.

How the retention of an email is set#

When piler archives an email:

  1. Exclusion rules. If an enabled exclusion rule matches, the email is not archived, see Exclusion rules.
  2. Retention rules. The first enabled retention rule that matches gives the number of days. The rules are checked in the order they were created, the oldest first.
  3. Default retention. If no rule matches, the default retention of the tenant applies (10 years on a new install).

The retention date of the email is its Date header plus these days. It's stored with the email and doesn't change later: a new or changed rule, or a new default retention, applies to the emails archived from then on, not to those already in the archive.

After its retention date the purge removes the email, see Purge.

Default retention#

The days of the emails no retention rule matches: retention_days of the tenant in piler.tenant_settings.

  • Single tenant: the retention page shows it, and the admin changes it there (2.3.1+), from MIN_RETENTION_DAYS to 36500 days. Before 2.3.1 it could be changed with SQL only.
  • Multi-tenant: the admin of the master (the piler tenant) sets the retention of each tenant in the tenant editor, Admin > Tenant > Tenant. The admin of a tenant sees it on the retention page, but can't change it.
  • Multi-node: each node has its own piler.tenant_settings, and each worker archives with its own retention_days. Nothing copies it from the master: change it on every worker too, see Change a tenant's settings. The retention page of a multi-node master shows the master's value and doesn't change it. A worker without the tenant's row archives with DEFAULT_RETENTION_DAYS of the piler daemon (3653 days).

The default retention can't be shorter than MIN_RETENTION_DAYS (30 days by default), see Config options.

Until the end of the year#

Piler counts the retention from the date of the email: an email of 15 March 2020 kept for 6 years (2191 days) is due on 15 March 2026. The German retention periods (HGB §257(5), AO §147(4)) start at the end of the calendar year of the document instead, so that email may go on 1 January 2027.

With RETENTION_UNTIL_YEAR_END=true (2.4.0+, default false) piler keeps an email with a retention of 365 days or more to the end of the calendar year its retention ends in, for the default retention and the rules alike:

  • The retention date is the next 1 January: the email is purged on that day.
  • Only a retention of 365 days or more: the German periods are whole years. A shorter one keeps its date, so a 30-day spam rule or a data minimisation rule still removes the mail after its days, not at the end of the year.
  • A retention of at least k × 365 days keeps the email for k full calendar years after the year it was sent in. Set the periods in plain years: 3650 days (or 3653) for 10 years, 2920 for 8, 2190 for 6. Every email of 2020 kept for 10 years is purged on 1 January 2031, whether it was sent on 1 January or 31 December.
  • A retention of other days from 365 on (e.g. 400) ends at the end of the year in which those days end.
  • Whole years count from the end of the sent year, so the email may stay a year past the plain date's year: an email of 1 January 2021 kept 365 days is purged on 1 January 2023, not 2022.
  • There is no exception for a single rule. A rule that should remove the mail after exactly its days, such as "newsletters after a year", needs fewer than 365 days (e.g. 364) to keep its date.

The value is true or false (also 1/0, t/f). Another value, such as yes or on, stops piler, pilerimport and piler-ui at startup, and the tenant editor and the tenant API refuse it in settings_json.

Set it in the environment of the piler daemon and of pilerimport (the .env of the Docker installation, /var/piler/.env on a deb/rpm install), and of piler-ui so the retention page and the configuration report show it. With Docker, give the piler and piler-ui containers the same .env: the retention page and the configuration report show the tenant's settings_json value, else piler-ui's .env value, so with two files they can show a value the archive doesn't use. For one tenant only, set "RETENTION_UNTIL_YEAR_END": true in its settings_json in the tenant editor; on a multi-node setup change it on every worker too, in the worker's .env or its tenant_settings row, as the retention days: the workers archive, and nothing copies the master's settings to them. The retention page, the simulation and the configuration report of the master show the master's value. It applies to the emails archived from then on: the emails already in the archive keep their retention date.

Retention rules#

A retention rule keeps the emails it matches for a number of days instead of the default retention, e.g. 30 days for newsletters, or 8 years for the emails of the accounting department.

Field Matches
Domain the domain of the From address
Sender (From) the From address
Recipient (To) any recipient: To, Cc, and the envelope recipients
Subject contains the subject
Body contains the first 10 KB of the text of the email
Message size the size of the email in bytes, with >, <, >= or <=
Spam status spam or not spam, by the SPAM_HEADER_LINE of the piler daemon
  • All the filled fields must match. An empty field matches every email.
  • The text fields match a part of the value, regardless of case. example.com in Domain also matches sub.example.com and myexample.com; @example.com in Sender matches only the addresses of that domain.
  • The first matching rule wins, in the order the rules were created. If the rules overlap, e.g. a domain and a sender of that domain, create the more specific one first; there is no other priority.
  • Days: at least MIN_RETENTION_DAYS. A rule shorter than the default retention is saved after the admin types its days, to confirm it.
  • Disable a rule with its switch to stop using it and keep it for later; a deleted rule is gone.

Exclusion rules#

An exclusion rule has the same fields as a retention rule, without the days. An email it matches is not archived: the piler daemon removes it, logs it with status=discarded and the name of the rule, and counts it among the discarded emails. It can't be recovered from piler later, so keep these rules narrow, e.g. the notifications of a monitoring system.

The envelope recipients count for the exclusion rules too: an email with a recipient a rule matches is excluded even if that recipient is only in the envelope.

When a change applies#

  • The piler daemon reads the rules again every 30 minutes: a new or changed rule applies within 30 minutes. It reads the default retention for each email.
  • pilerimport reads the rules and the default retention when it starts: a change applies to the next import run.
  • Multi-node: the rules are created on the master. Each worker copies them from the master every hour with sync_tables_from_master.sh, a cron job of the piler user on the worker: the Docker worker image turns it on, on a native worker check that the crontab of the piler user has it uncommented (crontab -l -u piler). A change reaches the workers within an hour and a half. The legal holds are copied the same way. The default retention isn't copied, see Default retention.

Simulate a rule#

Simulate counts the archived emails a rule matches, with the date of the oldest and the newest. For a retention rule it counts those older than the rule's days: the emails that would be past their retention if the rule had applied when they were archived. With RETENTION_UNTIL_YEAR_END=true (2.4.0+) it counts a rule of 365 days or more by the year-end retention date, see Until the end of the year. It changes nothing, the rules don't apply to the emails already archived.

The simulation matches the criteria like the archiving does (2.3.1+), except the body: the text of the archived emails isn't in the database, so a body criterion isn't counted, and the result says so. A rule with a body criterion may match fewer emails than the simulation shows. Before 2.3.1 the simulation of a rule with a domain, sender, recipient or body criterion failed.

On a multi-node master the emails are on the workers, so the simulation there finds none.

Who can change the rules#

  • Single tenant: the admin.
  • Multi-tenant: each tenant has its own rules, in its own database. The admin of a tenant manages them on the tenant's retention page. With ENABLE_TENANT_RETENTION_POLICIES=false, globally or in a tenant's settings_json, the admin of that tenant can view and simulate the rules, but not change them: the page says the platform operator manages them. To change them, the operator turns the setting on for the tenant, changes the rules as the tenant's admin, and turns it off again. The rules of the piler tenant are always managed by its admin. See Config options.

Every change of a rule is on the Audit Log tab of the retention page, with the rule before and after the change, and in the audit log of the configuration changes (2.3.0+). A change of the default retention on the retention page is in the audit log as retention_default_update, with the previous value.

Purge#

The purge removes the emails whose retention date has passed: their stored files and their index entries, and marks them deleted in the database. It runs every night at 2:02 (/usr/libexec/piler/purge.sh, a cron job of the piler user; in Docker, of the piler container), for each tenant whose enable_purge is on in piler.tenant_settings. It's on by default.

  • Legal hold: an email of a custodian under an active legal hold (a user, a domain or a group, as sender or recipient) is not purged, even after its retention date.
  • Multi-node: the purge runs on every worker, by the enable_purge of the tenant on that worker. A worker without the tenant's row doesn't purge it.
  • Turned off (enable_purge is 0): the emails stay in the archive after their retention date, until it's turned on again. Until then:
  • an email that was indexed before its retention date ended stays searchable and viewable;
  • an email whose retention had already ended when it was archived is stored, but not indexed, so it isn't searchable;
  • an export and a reindex leave out the emails past their retention, and a removed email stays out of them as before.

So if you keep the mail of a tenant without purging it, set the retention long enough for it to be kept: e.g. 36500 days (100 years) for the default retention, or in a retention rule. The default retention is 10 years on a new install.

To see what a purge would remove, run it with -dry-run. The dry run lists only the stored skeleton files (.m) of the emails it would purge. A purge without -dry-run also removes the stored attachment files of those emails, unless another email that is kept still has the same attachment. The dry run marks nothing in the database, so it doesn't list the attachments.

An attachment that two emails share is kept while one of them is stored. Purging the first of them keeps the attachment for the other. When the other is purged later, the attachment is removed, and the first email can no longer be restored: the restore finds the attachment file missing and refuses, listing the file. So an email purged earlier can only be restored while all its attachment files are still stored. See Restore a purged email.

Restore a purged email#

The purge keeps the database row of a purged email, marked deleted. While its stored files can be recovered, the email can be brought back with purge -restore-id. The command works whether enable_purge is on or off.

1. Find the id of the email#

The restore takes the email's id in the tenant database: piler on a single-tenant install, the tenant id on a multi-tenant one. Run the queries with mariadb --defaults-file=/etc/piler/.my.cnf <database>; in Docker, in the piler container.

With KEEP_PURGED_METADATA=true the purge keeps the sender, the subject, the Message-ID and the recipients, so the email can be found by them:

select id, piler_id, sent, `from`, subject from metadata
 where deleted=1 and message_id='<the Message-ID>';

By default the purge clears the sender, the subject and the Message-ID, and removes the recipients. Find the id in another way: in the audit log, where an entry about the email (e.g. when someone viewed or downloaded it) has its id, or by its piler id, the name of its .m file in the backup without .m:

select id from metadata where piler_id='<piler id>';

2. Recover the stored files#

The purge removed the email's .m file, and its attachment files that no other email uses. Put them back where they were:

  • Local store: from the backup of /var/piler/store and /var/piler/astore, owned by the piler user.
  • S3: in a bucket with versioning, the purge leaves delete markers. Remove the markers of the email's objects to bring them back.

If you don't know which files these are, run the restore of step 3: it checks the files first, lists the missing ones and changes nothing.

3. Restore the email#

purge -tenantid <tenant> -restore-id <id> -retain-days <N>

Run it as the piler user. In Docker: docker exec piler su piler -c "purge -tenantid <tenant> -restore-id <id> -retain-days <N>". A single-tenant install uses the tenant piler.

The restore refuses an email that isn't purged, and an email with a missing file. Otherwise it makes the email and its attachments active again, sets its retention date to today plus N days, and puts the email back in the search index. It prints Restored id=....

-retain-days is required. The email's old retention date has passed, so without a new one the next purge would remove it again. After the new date the purge removes it as any other email; to keep it longer, choose a larger N. The retention rules don't apply to a restored email: its period is the admin's decision, and the restore logs it.

4. Reindex the email#

The restored entry of the search index has no text: the body and the attachments are not searchable until the email is reindexed:

reindex -tenantid <tenant> -start <id> -stop <id>

With KEEP_PURGED_METADATA=true the email can be found by its sender, its recipients and its subject right after the restore. By default it can't: the purge cleared them, so only the auditors find it, by its date. The reindex reads them from the stored email again, and its recipients see it again. Recipients that were only in the envelope (e.g. Bcc) are not in the stored email, so they don't get it back.