Sanitize mail addresses

This commit is contained in:
Jonas Lochmann
2019-10-10 10:47:56 +02:00
parent df2cdab180
commit 196afe8ed1
4 changed files with 32 additions and 3 deletions
+17
View File
@@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { parseOneAddress } from 'email-addresses'
import * as Email from 'email-templates'
import { join } from 'path'
@@ -89,3 +90,19 @@ export function isMailServerBlacklisted (mail: string) {
return mailServerBlacklist.indexOf(domain.toLowerCase()) !== -1
}
export function sanitizeMailAddress (input: string): string | null {
const parsed = parseOneAddress(input)
if ((!parsed) || (parsed.type !== 'mailbox')) {
return null
}
const address = (parsed as any).address
if (typeof address !== 'string') {
throw new Error('illegal state')
}
return address
}