mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Sanitize mail addresses
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user