Skip to content

Spam training via dovecot-antispam is silently broken on Dovecot 2.3.x (IMAP MOVE not intercepted) #2570

@yeah

Description

@yeah

Summary

The Bayesian spam training (sa-learn) that is supposed to happen when users move messages to/from the Spam folder does not work. The dovecot-antispam plugin silently fails to intercept IMAP MOVE operations on Dovecot 2.3.x, which means sa-learn is never called for most users.

Root Cause

Mail-in-a-Box uses the dovecot-antispam plugin (configured in setup/spamassassin.sh) to trigger sa-learn when messages are moved to/from the Spam folder. This plugin was last updated in 2017 and was designed for Dovecot 2.2.x.

Dovecot 2.3.x (shipped with Ubuntu 22.04) added native support for the IMAP MOVE command (RFC 6851). Modern IMAP clients — including Thunderbird, Apple Mail, and most mobile clients — use MOVE rather than COPY + expunge. The dovecot-antispam plugin only hooks into COPY operations, so it never sees MOVE and never triggers sa-learn.

The plugin loads without errors and appears in doveconf -n, making the problem completely silent.

How to Reproduce

  1. Move a message into the Spam folder using any modern IMAP client
  2. Check sa-learn --dump magic — the nspam counter does not increment
  3. Instead, copy (not move) a message to Spam (e.g. Ctrl+drag)
  4. Check sa-learn --dump magic again — the counter does increment

This confirms the plugin works for COPY but not MOVE.

Impact

Bayesian spam training is effectively non-functional for all MIAB users who use IMAP clients that default to MOVE (which is virtually all modern clients). The shared Bayes database never learns from user actions, so spam filtering does not improve over time.

This also affects #2560, which identified additional problems with the antispam setup but did not identify this as the primary cause.

Proposed Fix

Replace the deprecated dovecot-antispam plugin with IMAPSieve, which is Dovecot's officially supported replacement (documentation). IMAPSieve properly intercepts both COPY and MOVE operations and is actively maintained.

This would involve:

  1. Removing dovecot-antispam from apt_install in setup/spamassassin.sh
  2. Removing the 99-local-spampd.conf antispam plugin config
  3. Removing the sed lines that enable the antispam plugin in 20-imap.conf / 20-pop3.conf
  4. Adding IMAPSieve configuration: imap_sieve plugin, sieve scripts for report-spam/report-ham, and shell wrappers that call sa-learn
  5. Configuring sieve to watch both "Spam" and "Junk" folders (also fixes Dovecot Antispam Plugin Fails to Load and Ignores 'Junk' Folder #2560)

I'd be happy to prepare a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions