---
title: "Administration -- Advanced"
weight: 23
description: "Custom flags, extra fields, column order and one-shot maintenance tools."
source_hash: "beb692f1"
---

# Administration -- Advanced

This tab (`admin/advanced.php`) groups technical settings and maintenance tools. Use with caution on destructive actions.

## "Custom flags" section

Capmail offers 4 flags synchronized with the IMAP keywords `$Label1` to `$Label4` (compatible with Thunderbird and most webmails). Each flag has a configurable label.

| Constant | Suggested default |
|----------|-------------------|
| `CAPMAIL_CapmailUserFlag1` | Important |
| `CAPMAIL_CapmailUserFlag2` | To process |
| `CAPMAIL_CapmailUserFlag3` | Waiting |
| `CAPMAIL_CapmailUserFlag4` | For information |

Flags 5 to 8 exist internally but are local to Capmail (not IMAP-synchronized).

## "Extra fields" section

Allows up to 8 additional third party fields to be displayed in the preview sidebar. Handy to see at a glance the customer code, phone, or any extra field of the third party card.

For each slot 1 to 8:

- **Field** (`CAPMAIL_fk_extra1` to `_fk_extra8`) -- selects which third party field to display (phone, customer code, or any extra field of the third party card).
- **Label** (`CAPMAIL_fk_extra1_label` to `_fk_extra8_label`) -- text displayed to the left of the value.

Fields are displayed in order 1 -> 8.

## "Column order (classic list mode)" section

Defines the column order in the classic list view (`postinmessage_list.php`). For each visible column, choose its position (0 = first, 1 = second, etc.).

Constants: `CAPMAIL_COLD_ORDER_{column_name}`.

Does not apply to Lead Mode, which has its own fixed rendering.

## Maintenance tools

All tools are accessible via buttons at the bottom of the page. Several offer a **"Dry run"** mode that shows what would be done without changing anything.

### Recalculate dates

Goes through all stored EML files and rebuilds the `date_mail` field from the message's `Date:` header. Useful after a migration or if some dates are incorrect.

### Fix PROV references

Validates `PostInMessage` records stuck with a provisional reference (`PROV...`) by assigning them a real reference via the numbering module. Typical case: interrupted import.

### Purge orphan emails

Deletes Dolibarr emails that no longer exist on the IMAP server. For each email with a `message_int`, the IMAP server is queried: if the UID has disappeared, the email is deleted locally.

**Warning**: destructive action. Backup recommended before running.

### Re-link third parties

Re-applies the automatic linking algorithm on all emails with no linked third party (`fk_soc IS NULL`). Useful after bulk import of new third parties or contacts.

### Clean orphan folder links

Deletes entries in the `capmail_imap_folder_message` link table that point to non-existent emails. Preventive maintenance, risk-free.

### Clean obsolete IMAP folders

Compares Capmail's known folder list with those actually present on the IMAP server. Deletes local entries that no longer correspond to a server folder (e.g. folder renamed directly via webmail). Emails are preserved.

### Repair duplicated-prefix folders

Some servers, when asked to create a folder whose path already contains the mailbox prefix, create a folder with a **doubled** prefix: `INBOX.INBOX.Sent` instead of `INBOX.Sent`. These folders are invisible in most webmails and accumulate mail that nobody reads.

This tool detects them, moves their messages to the correct path, deletes the emptied folder, then fixes the local references (sync tracking, folder-email links, and the mailbox configuration itself).

**The folder is only deleted once its messages have actually been moved**: if a move fails, the folder is kept and the error is reported. A simulation button shows what would be done before acting.

### Re-archive

For each email marked `STATUS_ARCHIVE` locally but with no link to a server archive folder, replays the IMAP move. Useful to catch up failed archiving (temporary IMAP outage).

### Purge duplicate emails

Detects strict duplicates (same `message_id` + same mailbox + same in/out direction) and keeps the most complete one (with linked third party/contact/project). Dry-run mode available.

**Warning**: destructive action on the main table. Always run a dry-run first.

### Resync all folders

Resets the `last_sync_uid` counters and relaunches a full `SINCE` fetch from the chosen date for all visible folders of all active mailboxes. Slow on large mailboxes but allows recovering missed emails.
