-
Notifications
You must be signed in to change notification settings - Fork 524
Closed
Labels
typesRelated to @cloudflare/workers-typesRelated to @cloudflare/workers-types
Description
Currently with the Email Workers, an email message is defined with ForwardableEmailMessage. The message contains a property raw with the type ReadableStream to read the message. ReadableStream is a generic type and the possible types are not defined.
With the get started and the following script, every data read are an Uint8Array object.
export default {
/**
* @param {{raw: ReadableStream}} message
*/
async email(message, env, ctx) {
const reader = message.raw.getReader();
const read = await reader.read();
if (typeof read == 'object') {
console.log(`object type: ${read.value.constructor.name}`)
}
else {
console.log(`type: ${typeof read}`)
}
}
}Example of a log output from the Worker.
{
"outcome": "ok",
"scriptName": "email-test",
"diagnosticsChannelEvents": [],
"exceptions": [],
"logs": [
{
"message": [
"object type: Uint8Array"
],
"level": "log",
"timestamp": 1703151398815
}
],
"eventTimestamp": 1703151398801,
"event": {
"rawSize": 11889,
"rcptTo": "[email protected]",
"mailFrom": "[email protected]"
},
"id": 0
}All types are accepted or the stream is only a ReadableStream<Uint8Array>?
Metadata
Metadata
Assignees
Labels
typesRelated to @cloudflare/workers-typesRelated to @cloudflare/workers-types