Inbound mail traces missing for emails rejected by inbuilt spam filter

Issue Description

When an email is rejected by the inbuilt spam filter no traces of it are generated at all.
In my opinion that defeats the purpose of those traces, since they provide meaningful insight in what happens to an email, but only for the happy path. The name in the Web UI “Inbound Delivery Attempts” suggests it shows attempts, no matter if successful or not, but it doesn’t.

Expected Behavior

Stalwart should show trace spans for rejected email

Actual Behavior

Stalwart silently rejects the email with no sign in traces

Reproduction Steps

  1. Configure a Reject threshold or a Milter that rejects an email
  2. Send an email that triggers the rejection to stalwart
  3. Look at Inbound Delivery Attempts, nothing appears there

Stalwart Version

v0.16.x

Installation Method

Docker

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

Let me research how Stalwart handles tracing for spam-rejected emails.

This will be included in v0.16.6.

I just tested v0.16.6

Unfortunately rejected mails still don’t show up at all in the E-Mails → History → Inbound delivery list.

I am testing with The Spamhaus Blocklist Tester (https://blt.spamhaus.com) to generate mails that are rejected. The reject threshold is set to 6 in my instance.

The previous fix only logged the error but since a QueueId was not included in the log (since the message never entered the system), the trace was not being stored. This has now been fixed.

I will have to test this some more but from a first glance it looks good in v0.16.7.

Thank you.