-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat(core): email relay #2741
feat(core): email relay #2741
Conversation
4d10d26
to
482ee4f
Compare
Initial pull request was #2735 |
ae2b9b0
to
c496524
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to test this, so maybe we can schedule a pairing together tomorrow morning. Left some questions for then.
} | ||
|
||
const recipients = new Array<Address>() | ||
.concat(email.to || []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we handle empty to
differently? Can we hit this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is better to be ready for any possible case.
platform/core/src/relay.ts
Outdated
|
||
const response = await fetch(request) | ||
if (!response.ok) | ||
console.error(JSON.stringify(await response.json(), null, 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance to hit a scenario where the response is not of type json
but rather a text
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. MailChannels responds with JSON for errors but it is also possible to have any kind of failure. It should be guarded.
2e3c1b9
to
6013865
Compare
991901c
to
9a49797
Compare
9238f6f
to
5091c56
Compare
9a49797
to
02ea3dc
Compare
02ea3dc
to
05be9b8
Compare
2da7a83
to
9d15ad5
Compare
|
INTERNAL_RELAY_DKIM_DOMAIN = "" | ||
INTERNAL_RELAY_DKIM_SELECTOR = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these ones, DOMAIN & SELECTOR, here? If we declare them in the TOML files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I just put them here as an example for local development if needed.
.github/workflows/main-core.yaml
Outdated
INTERNAL_RELAY_DKIM_DOMAIN | ||
INTERNAL_RELAY_DKIM_SELECTOR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we declare them in the TOML files, are these (DOMAIN & SELECTOR) injected in the GitHub CI pipeline or are they taken from the TOML? Should they be here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, not. I am going to check it.
.github/workflows/main-core.yaml
Outdated
INTERNAL_RELAY_DKIM_DOMAIN: ${{ secrets.INTERNAL_RELAY_DKIM_DOMAIN }} | ||
INTERNAL_RELAY_DKIM_SELECTOR: ${{ secrets.INTERNAL_RELAY_DKIM_SELECTOR }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we declare them in the TOML files, are these (DOMAIN & SELECTOR) injected in the GitHub CI pipeline or are they taken from the TOML? Should they be here?
Same for next
and release
platform/core/src/index.ts
Outdated
const decoder = new TextDecoder() | ||
const reader = message.raw.getReader() | ||
let content = '' | ||
while (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the while (true) loop, you can simplify the loop condition to exit when done:
let { done, value } = await reader.read();
while (!done) {
content += decoder.decode(value);
({ done, value } = await reader.read());
}
@@ -36,6 +37,17 @@ export default { | |||
}, | |||
}) | |||
}, | |||
async email(message: CloudflareEmailMessage, env: Environment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a name such as decodeAndRelayEmail
be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is called by the worker when an email is received.
platform/core/src/index.ts
Outdated
const reader = message.raw.getReader() | ||
let content = '' | ||
while (true) { | ||
const { done, value } = await reader.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should failure scenarios be considered? I'm a fan of letting it blow up but not sure what we want to do in case it fails. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I'll lookup what kind of errors can be thrown by this call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found anything useful.
|
||
import type { Environment } from './types' | ||
|
||
export interface CloudflareEmailMessage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this differ from the interfaces in platform/test/src/index.ts
and platform/email/src/types.ts
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a slight difference. I didn't want to couple the two modules just for this interface.
recipient.address.endsWith(`@${env.INTERNAL_RELAY_DKIM_DOMAIN}`) | ||
) | ||
|
||
for (const recipient of recipients) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth considering parallelization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, not right away at least. This is only a background process.
9d15ad5
to
90da3ad
Compare
90da3ad
to
6670435
Compare
Description
TBD
Related Issues
Testing
Checklist