-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
24 lines (22 loc) · 989 Bytes
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(ns email-normalisation.core
(:require [email-normalisation.providers :refer [providers get-email-provider normalise-for-provider]]
[clj-http.client :as client]
[clojure.string :as string]
[clojure.data.json :as json]))
(defn get-mx-records
"Get the mx records for the domain part of the email"
[domain]
(let [response (json/read-str
(:body
(client/get
"https://cloudflare-dns.com/dns-query"
{:accept "application/dns-json" :query-params {"type" "MX" "name" domain}})))]
(or (get response "Answer") (get response "Authority"))
))
(defn normalise-email
"Normalise an email address based on provider from mx record to apply rules"
[email]
(let [[username domain] (string/split email #"@")
mx-records (get-mx-records domain)
email-provider (get-email-provider mx-records)]
(normalise-for-provider email-provider username domain)))