Email worker - how to get all values for header?


In my email worker, I would like to get all values for a given header, for example, the “to” or “cc” headers. Currently, the worker is returning only the first value for a given header.

Notes: We are assuming that the “cc” is not null. Also, the below refers to what has been observed with actual emails; the issue does not occur in the code editor’s console.

Example headers of an email processed by the worker:

to: A, B
cc: C, D

Example email worker code:

let to = message.headers.get("to");
let cc = message.headers.get("cc");
console.log(to, cc);

Expected output:

"A, B, C, D"

Observed output:

"A, C"

Any ideas?

Thank you in advance