Email/get: `header:List-Id:asText` is always null although the header is present

Issue Description

Email/get returns null for header:List-Id:asText on messages that do have a List-Id header. The raw form header:List-Id is returned correctly, and asText works for other headers (for example header:X-Probe:asText). Clients that detect mailing lists by reading List-Id in the Text form (the form RFC 8621 explicitly allows for this header) see nothing.

Expected Behavior

RFC 8621, section 4.1.2.2 (Text form): “this form may only be fetched or set for the following header fields: Subject, Comments, Keywords, List-Id, Any header field not defined in [RFC5322] or [RFC2369].” So header:List-Id:asText should be "Probe list <probe-17925.example.com>".

Actual Behavior

null, both for a message imported with Email/import and for one created with Email/set (where the header was set through header:List-Id:asText and is stored correctly, as the raw form shows).

Reproduction Steps

  1. Import a message with these headers (blob upload + Email/import):
From: Probe <[email protected]>
To: [email protected]
Subject: RE: Budget zq17925 planning
List-Id: Probe list <probe-17925.example.com>
List-Unsubscribe: <mailto:[email protected]>
X-Probe: yes
Content-Type: text/plain; charset=utf-8

hello
  1. Fetch it:
curl -s -u "[email protected]:$PASS1" -H 'Content-Type: application/json' https://mail.example.com/jmap/ -d '{
  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
  "methodCalls": [["Email/get", {"accountId": "c", "ids": ["qiaaaaec", "qmaaaaed"], "properties": [
    "subject", "header:List-Id", "header:List-Id:asText", "header:X-Probe:asText",
    "header:List-Unsubscribe:asURLs"]}, "g"]]}'

(qmaaaaed was created with Email/set and "header:List-Id:asText": "Set list <set-17925.example.com>".)

Response:

{"methodResponses": [["Email/get", {"accountId": "c", "state": "srqca", "list": [
  {"subject": "RE: Budget zq17925 planning", "header:List-Id": " Probe list <probe-17925.example.com>",
   "header:List-Id:asText": null, "header:X-Probe:asText": "yes",
   "header:List-Unsubscribe:asURLs": ["mailto:[email protected]"], "id": "qiaaaaec"},
  {"subject": "setprobe 17925", "header:List-Id": " Set list <set-17925.example.com>",
   "header:List-Id:asText": null, "header:X-Probe:asText": "yes",
   "header:List-Unsubscribe:asURLs": null, "id": "qmaaaaed"}], "notFound": []}, "g"]]}

Stalwart Version

v0.16.x

Installation Method

Docker

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

Additional Context

Where it seems to come from:

crates/email/src/message/headers.rs: for a structured header the stored, already parsed value is used (header.value.clone()), and the raw bytes are re-parsed only when the form is Raw or the header is not structured (is_raw = matches!(form, HeaderForm::Raw) || !header_name.is_structured()). List-Id is stored in its parsed address-like form, and converting that value to HeaderForm::Text gives null. Re-parsing the raw value with parse_unstructured() when Text is requested would fix it.

Stalwart v0.16.27, Docker image stalwartlabs/stalwart:v0.16-alpine, default setup from the bootstrap wizard.

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

This confirms the user’s analysis is accurate: the bug is real in crates/email/src/message/headers.rs. List-Id is treated as a structured header (header_name.is_structured() returns true for it), so when HeaderForm::Text is requested, the code uses the already-parsed stored value (header.value.clone()) instead of re-parsing the raw bytes with parse_unstructured(), and converting the address-form parsed value into Text form yields null.

I’ve confirmed this against the source, this is indeed a bug rather than a documented limitation.

Your root-cause analysis matches the code. In crates/email/src/message/headers.rs, header_to_value only re-parses the raw header bytes when form is HeaderForm::Raw or the header name is unstructured (!header_name.is_structured()). Since List-Id is treated as a structured (address-like) header, a Text form request skips re-parsing and instead converts the already-stored address-parsed HeaderValue via into_form(&form), which yields null for this value type instead of calling parse_unstructured() on the raw bytes.

This does look like a genuine mismatch with RFC 8621 §4.1.2.2, which explicitly lists List-Id as a header that may be fetched in Text form. I can’t find anything in the docs or source indicating this is handled differently on purpose, so this appears to be a bug in how List-Id is classified/handled for the Text form rather than expected behavior.

A human maintainer will need to confirm and address the fix (e.g. special-casing List-Id so Text form always re-parses from raw bytes with parse_unstructured(), as you suggested).

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

On 0.16 List-Id is stored already parsed as an address, and nothing converts it back to Text, so asText comes out null every time.

1.0 parses each header from its raw bytes in whatever form you ask for, so header:List-Id:asText returns the value there. It’s released this week; until then, header:List-Id in raw form has the same content.