Parse the author name from email address

This commit is contained in:
Hongbo Wu 2023-04-14 18:48:24 +08:00
parent f7d46752e1
commit 0a2598e296
2 changed files with 10 additions and 1 deletions

View file

@ -16,6 +16,7 @@ import {
handleGoogleConfirmationEmail,
isGoogleConfirmationEmail,
isSubscriptionConfirmationEmail,
parseAuthor,
parseUnsubscribe,
} from './newsletter'
import { handlePdfAttachment } from './pdf'
@ -182,7 +183,7 @@ export const inboundEmailHandler = Sentry.GCPFunction.wrapHttpFunction(
content: html,
url: generateUniqueUrl(),
title: subject,
author: from,
author: parseAuthor(from),
text,
unsubMailTo: unsubscribe.mailTo,
unsubHttpUrl: unsubscribe.httpUrl,

View file

@ -34,6 +34,14 @@ const parseAddress = (address: string): string => {
return ''
}
export const parseAuthor = (address: string): string => {
const parsed = addressparser(address)
if (parsed.length > 0) {
return parsed[0].name
}
return address
}
export const handleGoogleConfirmationEmail = async (
email: string,
subject: string