Missing Spam/Junk and standard folders after cPanel to DirectAdmin migration

Environment

  • DirectAdmin server with Dovecot (IMAP/LMTP) + Exim (MTA) + Roundcube (Webmail)
  • Dovecot subscriptions v2 format
  • Mail stored in Maildir format

Problem

After migrating email accounts from cPanel to DirectAdmin, users report that Spam/Junk emails are not visible in Roundcube. Upon investigation, all standard folders (Drafts, Sent, Trash, Junk) may also be missing from the webmail interface.

Root Cause

Three issues caused by the cPanel-to-DirectAdmin migration:

1. Wrong spam folder name in subscriptions file

cPanel uses spam as the IMAP folder name for junk mail. DirectAdmin uses INBOX.spam. After migration, the Dovecot subscriptions file still references the old cPanel name, so the folder is not visible in Roundcube even though spam is being delivered correctly by Exim to .INBOX.spam/new/.

2. Missing standard folder subscriptions

The migrated subscriptions files are missing entries for standard IMAP folders: Drafts, Sent, Trash, and Junk. These folders exist on disk (as .Drafts, .Sent, .Trash, .Junk inside Maildir) but are not listed in the subscriptions file.

A native DirectAdmin account's subscriptions file looks like:

Drafts
INBOX.spam
Junk
Sent
Trash
V    2

A migrated account only has:

V    2

spam
Archive
...

3. File ownership changed to root after CLI edits

When editing subscriptions files with sed -i as root, the -i flag creates a temporary file and replaces the original, changing ownership to root:root. Dovecot runs as the system user, so Roundcube returns "Unable to perform operation, permission denied".

Correct ownership: {da_user}:mail with permissions 660.

Relevant File Locations

File Purpose
/home/{user}/imap/{domain}/{account}/Maildir/subscriptions Dovecot IMAP folder subscriptions (controls what Roundcube shows)
/etc/virtual/{domain}/filter Exim domain-level filter (handles spam delivery routing)
/etc/dovecot/conf/namespace_private.conf Dovecot namespace config (defines special-use folders)

Fix

Step 1: Replace cPanel folder name with DirectAdmin name

for acc in user1 user2 user3; do
    sub="/home/{da_user}/imap/{domain}/${acc}/Maildir/subscriptions"
    if [ -f "$sub" ]; then
        sed -i 's/^spam$/INBOX.spam/' "$sub"
    fi
done

Step 2: Add missing standard folder subscriptions

for acc in user1 user2 user3; do
    sub="/home/{da_user}/imap/{domain}/${acc}/Maildir/subscriptions"
    if [ -f "$sub" ]; then
        for folder in Drafts Sent Trash Junk; do
            if ! grep -q "^${folder}$" "$sub"; then
                sed -i "/^$/a ${folder}" "$sub"
            fi
        done
    fi
done

Step 3: Restore correct ownership and permissions

Critical after any CLI edit to subscriptions files:

for acc in user1 user2 user3; do
    sub="/home/{da_user}/imap/{domain}/${acc}/Maildir/subscriptions"
    if [ -f "$sub" ]; then
        chown {da_user}:mail "$sub"
        chmod 660 "$sub"
    fi
done

Verification

No service restart is required. Dovecot reads the subscriptions file on each IMAP session. Users just need to refresh or re-login to Roundcube.

General Guidance for Future cPanel Migrations

  1. Subscriptions file has INBOX.spam instead of spam
  2. Standard folders (Drafts, Sent, Trash, Junk) are listed in the subscriptions file
  3. File ownership is {da_user}:mail with 660 permissions
  4. Exim filter (/etc/virtual/{domain}/filter) delivers spam to .INBOX.spam/new/
  5. Orphaned folders like .spam (cPanel legacy) can be cleaned up if empty