handle undefined envelope
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Elizabeth Hunt 2024-12-15 12:10:02 -08:00
parent 2e8f6a1d14
commit 8e5fabec3e
Signed by: simponic
GPG Key ID: 2909B9A7FF6213EE

View File

@ -159,10 +159,10 @@ const fetchMessages = (
*/
type EmailMatcher = (email: Email) => (message: FetchMessageObject) => boolean;
const matchesEmail: EmailMatcher = (email) => (message) => {
const subjectMatches = email.subject === message.envelope.subject;
const subjectMatches = email.subject === message.envelope?.subject;
const bodyMatches =
message.bodyParts.get("text")?.toString().trim() === email.text.trim();
const headers = message.headers.toLocaleString();
message.bodyParts?.get("text")?.toString().trim() === email.text.trim();
const headers = message.headers?.toLocaleString();
const fromMatches = headers.includes(`Return-Path: <${email.from}>`);
const toMatches = headers.includes(`Delivered-To: ${email.to}`);
return subjectMatches && bodyMatches && fromMatches && toMatches;