Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadableStream in email message #1500

Closed
niquenen opened this issue Dec 21, 2023 · 1 comment
Closed

ReadableStream in email message #1500

niquenen opened this issue Dec 21, 2023 · 1 comment
Assignees
Labels
types Related to @cloudflare/workers-types

Comments

@niquenen
Copy link
Contributor

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.

Screenshot 2023-12-21 at 11h56

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>?

@niquenen niquenen added the types Related to @cloudflare/workers-types label Dec 21, 2023
@jasnell
Copy link
Member

jasnell commented Dec 21, 2023

In this case, the value should always be a Uint8Array.

@cloudflare cloudflare locked and limited conversation to collaborators Dec 21, 2023
@jasnell jasnell converted this issue into discussion #1501 Dec 21, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
types Related to @cloudflare/workers-types
Projects
None yet
Development

No branches or pull requests

3 participants