Error when FROM header contains square brackets

Hello !

KumoMTA version
kumod 2025.05.06-b29689af

When using the HTTP API with square brackets [ ] inside the FROM header (display name) :

{
"content": {
    "text_body": "test",
    "html_body": "<div>test</div>",
    "from": {
        "email": "test@gmail.com",
        "name": "TEST [ne_pas_repondre]"
    }
}
}

I get the following error when calling the msg:from_header().domain method :

somebody@gmail.com: invalid header: 0: at line 1:
TEST [ne_pas_repondre] <test@gmail.com>
     ^________________________________________
expected ':', found [

1: at line 1, in group:
TEST [ne_pas_repondre] <test@gmail.com>
^_____________________________________________

2: at line 1, in Alt:
TEST [ne_pas_repondre] <test@gmail.com>
^_____________________________________________

3: at line 1, in address:
TEST [ne_pas_repondre] <test@gmail.com>
^_____________________________________________

4: at line 1, in Many1:
TEST [ne_pas_repondre] <test@gmail.com>
^_____________________________________________

5: at line 1, in obs_address_list:
TEST [ne_pas_repondre] <test@gmail.com>
^_____________________________________________

6: at line 1, in Alt:
TEST [ne_pas_repondre] <test@gmail.com>
^_____________________________________________

7: at line 1, in address_list:
TEST [ne_pas_repondre] <test@gmail.com>
^_____________________________________________


stack traceback:
    [C]: in method 'from_header'

Is this the intended behavior ?

Thank you for your time

Can you wrap it in double quotes?

If i wrap it in double quotes it works (no more errors), but those quotes are visible in the mailbox of the recipient (i tested on Gmail)
I was wondering if there is a way to have a FROM display name with square brackets without showing any quote wrapping in the mailboxes

can you show us the From header from the email?

First one :
From: "\"Antoine . test % [ne_pas_repondre]\"" <antoine@test.com>

In the Kumo API payload, it was sent as :

        "from": {
            "email": "antoine@test.com",
            "name": "\"Antoine . test % [ne_pas_repondre]\""
        },

Second one :
From: "Antoine \"[ne_pas_repondre]\"" <antoine@test.com>

In the Kumo API payload, it was sent as :

        "from": {
            "email": "antoine@test.com",
            "name": "Antoine \"[ne_pas_repondre]\""
        },

Confirmed that the From header looks weird by running this script:

local kumo = require 'kumo'
local request = kumo.serde.json_parse [[
{
  "envelope_sender": "no-reply@example.com",
    "content": {
      "text_body": "test",
      "html_body": "<div>test</div>",
      "from": {
        "email": "test@gmail.com",
        "name": "TEST [ne_pas_repondre]"
      }
  },
  "recipients": [
  {
    "email": "a@gmail.com",
    "name": "a@gmail.com"
  }
  ]
}
]]

for _, msg in ipairs(kumo.api.inject.build_v1(request)) do
  print(msg:get_data())
  print(msg:from_header().domain)
end

You can run it like this, assuming that the script is named builder.lua:

$ kumod --script --policy ./builder.lua

Thanks for checking, should i open a GitHub issue regarding this problem?

Yes please

https://github.com/KumoCorp/kumomta/issues/428

Thank you again for your time

I think mailparsing: fix quoting issue with Mailbox display name · KumoCorp/kumomta@7eeb755 · GitHub will resolve this