# Automatic replies

Card #3416 reviewed release candidate. Jonathan approved the actual interface and instructed proceeding on 2026-10-08. The root recovery record tracks the authorized release and its fresh verification; this document describes behavior and does not grant standing deployment authority.

## Profile policy and migration defaults

Jonathan instructed on 2026-10-12 that Nuhet should handle automatic replies by default and that this should be set for all current sender profiles. The forward migration changes the database default to **Nuhet handles automatic replies** and switches only non-deleted sender profiles to Handle once, including profiles belonging to retained deleted companies. New unsaved and persisted profiles default to Handle; an explicit Forward all choice remains available. Saved category rules, destinations, timestamps, deletion flags and verification stay intact. Existing replies, pauses and campaign skips are untouched; changing mode creates no pause and does not replay past notices. Only future ordinary intake can act under the existing category, proof and company-availability gates. Deleted companies remain deleted and cannot send or receive processing through this metadata change.

MySQL schema changes implicitly commit, so changing the default and updating current profile modes are not one atomic operation. Release recovery must preserve the exact pre-change profile modes. Migration rollback restores only the database default to Forward all; it does not overwrite row modes or later user choices. Restoring previous profile values requires separately controlled recovery from that pre-change evidence, with application code rollback coordinated as needed.

In **Nuhet handles automatic replies**, each category keeps its own Forward/Handle choice and cooldown: temporary absence defaults to Handle/14 days, acknowledgement defaults to Handle/0 days, and permanent departure, changed contact information, challenge and unknown default to Forward. Switching the top mode hides or reveals saved choices without clearing them. Cooldown accepts integer days from 0 to 3650; zero saves and handles the notice without pausing.

Forwarding uses a verified, usable mailbox on the original sender profile. An explicit destination can select another verified receiving sender profile in the same company. A post.nuhet.se profile needs that explicit destination. Body addresses and suggested replacement contacts never become destinations or update recipients automatically. Profiles without a usable destination retain a blocked notice for review and recheck the destination hourly.

## Intake, proof and retained evidence

True structured MIME delivery-status reports keep the existing recipient verification and hard-bounce pipeline in both profile modes. Personal and service notices do not increment bounce statistics. Plain gateway NDR prose without structured DSN evidence remains reviewable and does not independently hard-suppress a recipient.

Actions require a consistent original company, campaign, recipient and sender profile plus original-message proof. Bounce tags are read only from allowlisted destination headers; conflicting tags are rejected. Future campaign messages carry a random Message-ID stored with their original delivery reference. In-Reply-To/References must identify that reference. Legacy proof can use an authenticated Nuhet token inside a structurally attached original message with matching original recipient, sender and referenced Message-ID. A guessed numeric bounce tag and spoofed From alone cannot authorize forwarding or a pause. Uncorrelated messages remain in the spool quarantine; correlated but insufficiently verified notices are saved for review.

Classification uses the fresh decoded body, excluding common HTML/text quote containers and attached originals. A campaign subject alone cannot create a high-confidence absence. Actionable cooldowns require a recognized category with high confidence and automatic-reply evidence. Unknown or low-confidence notices remain reviewable. The original MIME bytes are stored as base64, decoded exactly for download and forwarding; the decoded notice is displayed as escaped text. No free-text replacement address is applied.

## Pause and campaign behavior

Pauses are separate company/normalized-email records shared by duplicate recipient rows and sender profiles in that company. Another company is unaffected. Contacts remain active and continue to count toward package limits. A pause records its reason, expiry, originating reply, sender profile and campaign.

Expiry is calculated from original receipt time, not processing time. Deduplication precedes actions, so replay cannot extend the pause. A new verified notice may extend but never shorten an existing expiry; an already-expired delayed notice creates no new pause. Profile policy changes do not clear an existing pause. An authorized, company-scoped manual clear requires deliberate confirmation and rejects stale source data. Notices received before that clear cannot reinstate the cleared pause. Clearing a pause does not bypass unsubscribe, blacklist, consent, manual inactivation or hard-bounce restrictions.

The dispatcher checks before creating campaign statistics, and the queue rechecks immediately before SMTP. Explicit cooldown skips are saved separately from sent/bounce metrics. A saved skip remains effective for that campaign and company/email after expiry or manual clear, preventing an old campaign from replaying. A future campaign can send after expiry or clear if its other restrictions permit it.

## Forwarding outcomes

The attachment-compatibility candidate prepared on 2026-10-09 keeps the decoded notice in the email body and attaches the unmodified MIME source as `automatic-reply.txt` with `application/octet-stream`. The receiving test server rejected the prior `.eml` extension. The generic MIME type avoids declaring arbitrary original bytes to be UTF-8; transport base64 preserves them exactly. This source file can be saved and renamed to `.eml` for opening in a mail client. Stored originals and Nuhet's authorized `.eml` download retain their existing format. Local verification does not prove receiving-server acceptance, and this new candidate requires a scoped release decision before deployment. Closed replies are never replayed to test it.

A durable claim is recorded before submission. Successful SMTP submission is recorded once; this does not prove delivery to the receiving inbox. A proven pre-submission preparation failure retries at 5, 10, 20 and 40 minutes, up to five attempts. Missing destinations are retained and rechecked without counting an SMTP attempt. Ambiguous transport results and interrupted claims become uncertain and require log review; they are never automatically submitted twice. Loop markers and suppression headers prevent automatic forwarding loops.

The scheduled `automatic-replies:forward` command runs after bounce intake. Deployment must apply the schema before enabling code/scheduling and verify the existing ingress and mail configuration as part of an authorized release. This feature makes no Postfix change. No live configuration, credentials or delivery was exercised during implementation.

## Company retention integration

Fresh company availability locks protect reply intake, queue consumption, forwarding and interrupted-claim recovery. Deleted or missing companies retain their existing history without intake writes, new forwarding claims or SMTP submission. The scheduled forwarder excludes those companies from its bounded batch.

Forwarding uses two company-locked phases: claim and commit first, then reacquire the company and reply locks through submission/outcome recording. This preserves a durable claim before any SMTP call. Marking between phases prevents submission and retains the claim; after restoration, interrupted recovery conservatively marks it uncertain rather than replaying it. A process death during SMTP cannot roll the committed claim back to pending.

Permanent cleanup fails closed when any automatic reply, outgoing delivery reference, email pause or cooldown skip belongs to the company, or when foreign reply data references children that would be purged. No destructive cleanup support is added here. These records also count as business history in the registration-spam audit. Production migration uses explicit short unique-index names to satisfy MySQL's identifier limit; the actual migration and two-connection claim/locking behavior are tested on a disposable local MariaDB database before release.
## Local verification and actual-page preview

Targeted command:

```sh
php vendor/phpunit/phpunit/phpunit --filter "AutomaticReply|FetchBounceStatsQuarantineTest|HardBounceRecipientSuppressorTest|BounceSpoolWriterTest|ReceiverListEditQueryTest|HardBounceMigrationRecoveryTest|SMTPQueueMailerInvalidReceiverTest"
```

Verified 80 tests and 370 assertions, including actual array-transport forwarding, exact non-UTF8 original bytes, correlation attacks, quoted-message classification, original-profile preservation, pause timing, persisted campaign skips and authorization. All 34 changed non-Blade PHP files passed lint; the changed source/documentation UTF-8 and Nordic text scan and `git diff --check` passed. The existing PHPUnit XML configuration emits one deprecation; it does not fail the suite.

`scripts/automatic-replies-preview.php` serves actual controllers and Blade fragments using credential-free SQLite fixture data and array mail. It permits only PHP's local CLI server and loopback clients. Root owns the current disposable database `storage/app/automatic-replies-3416-preview.sqlite`, supervised `nuhet-3416-preview.service` on 127.0.0.1:3416 and screenshot artifacts. Do not reset this database during review. The server command, run by an owned supervisor rather than a finite WSL runner, is:

```sh
php -S 127.0.0.1:3416 -t public scripts/automatic-replies-preview.php
```

Actual preview routes are `/senderprofile/2/edit` (Forward), `/senderprofile/1/edit` (expanded 14/0), `/receiver/1/edit` (pause), `/automatic-replies`, `/automatic-replies/1` and `/sendout/11/receivers` (saved skip). The root-staged baseline view directory is supplied through `NUHET_PREVIEW_BASELINE_VIEWS`; `?baseline=1` renders exact base fragments and records the new routes as unavailable before. Preview setup never copies a live `.env`, connects a live database or sends mail. Root owns final independent review, actual before/after screenshots and acceptance. Explicit approval remains required before go-live.
