Some headers not importing via import_x_headers

Hey gang. I’ve noticed that any headers I import via import_x_headers that has a - will not import. For instance, Subject imports just fine, List-Id does not. I’ve tried specifying headers in all possible cases and with an underscore instead of a dash (ex: list-id, list_id). No matter what, if the header has one or more - in it, it’s not imported into the meta data for the logs. (X-* headers do import, but not headers that are not X headers that have a dash)

Any idea what I’m doing wrong?

Some example code:

kumo.on('init', function()

  kumo.configure_local_logs {
    -- ...
    meta = { 'subject', 'message_id' },
    -- ...
  }
-- ...
end)

kumo.on('smtp_server_message_received', function(msg, conn_meta)
  -- ...
  msg:import_x_headers { 'subject', 'message_id' }
  -- ...
end)

In the above code, subject will import, message_id will not. Doesn’t matter if I specify it as Message-Id or any other variation.

Thanks for the help!

The x is to be taken literally.

For a non X header you need to use one of the other header functions.

Hey Mike! You have example where non-x headers are provided (ex: https://docs.kumomta.com/userguide/configuration/logging/)

And the function works just fine to pull non-X headers - so long as it’s a single word header without any dashes

I’m on mobile but search docs for header and there’s functions to read specific named headers.

Here’s the example I was speaking of

I know you can just specify headers like this:

kumo.configure_local_logs {
  -- This is convenient, but costly! Prefer to capture the
  -- headers into meta and log those instead, as shown in
  -- the example below!
  headers = { 'Subject', 'X-Client-ID' },
}

but you guys advise against doing that

Ah mimepart.headers? https://docs.kumomta.com/reference/mimepart/headers/

Or get_first_named_header_value - KumoMTA Docs

Got it - so those work without the penalty of needing to reparse the message?

I think there’s an edge case there in the x header function, and there’s negative performance impact to specifying headers in the logger

Yeah you can get headers into meta during reception easily because it’s still in active memory being processed. You specify headers in the logger and it has to re-parse the message.

Sweet - thanks Mike! I’ll give that a try and let you know if I get stuck again :slightly_smiling_face:

You can use msg:import_x_headers with any headers, not just X- headers. I think the confusion is with - vs. _ in the example you shared.

You want to import the header name message-id (with a dash, and the name is case in-sensitive), but because the imported header must be a valid JSON object field name, the resulting imported name is message_id (all lower case, with an underscore), which is what you see in the example that you referenced from the docs.

You can fix the code that you shared up the top like this:

kumo.on('init', function()
  kumo.configure_local_logs {
    meta = { 'subject', 'message_id' },
  }
end)

kumo.on('smtp_server_message_received', function(msg, conn_meta)
  msg:import_x_headers { 'subject', 'message-id' } -- dash, not underscore!
end)

yep that was the issue. log_parameters needs underscores, import_x_headers needs dashes. I tried both but didn’t try underscores for one and dashes for the other. Thanks Wez!