Add support to the case when from address is in Name <address> format

This commit is contained in:
Hongbo Wu
2022-07-28 10:26:15 +08:00
parent 0bdab51bbd
commit c99c1db57e
7 changed files with 39 additions and 22 deletions

View File

@ -19,6 +19,7 @@ import { getRepository } from '../entity/utils'
import { User } from '../entity/user'
import { ILike } from 'typeorm'
import { v4 as uuid } from 'uuid'
import addressparser from 'addressparser'
const logger = buildLogger('utils.parse')
@ -567,3 +568,14 @@ export const getTitleFromEmailSubject = (subject: string) => {
const title = subject.replace(ARTICLE_PREFIX, '')
return title.trim()
}
export const parseEmailAddress = (from: string): addressparser.EmailAddress => {
// get author name from email
// e.g. 'Jackson Harper from Omnivore App <jacksonh@substack.com>'
// or 'Mike Allen <mike@axios.com>'
const parsed = addressparser(from)
if (parsed.length > 0) {
return parsed[0]
}
return { name: from, address: from }
}