Skip to content

Commit

Permalink
refactor: prevent filtering on OPEN or SEND
Browse files Browse the repository at this point in the history
  • Loading branch information
KishenKumarrrrr committed Sep 13, 2023
1 parent f4cd7b7 commit 4ff780e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions backend/src/email/utils/callback/parsers/ses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const parseNotificationAndEvent = async (
message: any,
metadata: Metadata
): Promise<void> => {
if (!isNotificationAndEventForMainRecipient(message)) {
if (!isNotificationAndEventForMainRecipient(message, type)) {
logger.info({
message: 'SES notification or event is not for the main recipient',
action: 'filterNotification',
Expand Down Expand Up @@ -259,8 +259,14 @@ const parseRecord = async (record: SesRecord): Promise<void> => {
}

// Checks whether the notification/event is meant for the main recipient of the email.
// We cannot check "OPEN" and "SEND" events due to the response given by AWS SES
function isNotificationAndEventForMainRecipient(message: any): boolean {
function isNotificationAndEventForMainRecipient(
message: any,
type: SesEventType
): boolean {
// We cannot filter "OPEN" and "SEND" events due to the response given by AWS SES
if (type === SesEventType.Open || type === SesEventType.Send) {
return true
}
const mainRecipient = message?.mail?.commonHeaders?.to
if (!mainRecipient) {
throw new Error('Failed to find main recipient in message')
Expand Down

0 comments on commit 4ff780e

Please sign in to comment.