Skip to content

Commit

Permalink
Merge branch 'master' into feature/optional-providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Mar 27, 2024
2 parents 874c155 + 419d515 commit 998d10d
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
import_deps: [:dns]
import_deps: []
]
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
otp-version: "22.2"
elixir-version: "1.9.4"
otp-version: "24.2.1"
elixir-version: "1.13.2"

- name: Cache deps
id: cache-deps
Expand Down Expand Up @@ -80,8 +80,8 @@ jobs:
- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
otp-version: "22.2"
elixir-version: "1.9.4"
otp-version: "24.2.1"
elixir-version: "1.13.2"

- name: Cache deps
id: cache-deps
Expand Down Expand Up @@ -118,8 +118,8 @@ jobs:
- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
otp-version: "22.2"
elixir-version: "1.9.4"
otp-version: "24.2.1"
elixir-version: "1.13.2"

- name: Cache deps
id: cache-deps
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ iex> Burnex.is_burner? "\"this is a valid address! crazy right ?\"@yopmail.fr"
true

iex> Burnex.providers
#MapSet<["mysunrise.tech", "gmailom.co", "renwoying.org", "xn--c3cralk2a3ak7a5gghbv.com", "vevevevevery.ru", "ghork.live", "totobaksa.website", "wellnessmarketing.solutions", "zerograv.top", "votenoonnov6.com", "b45win.org", "dataleak01.site", "muslimahcollection.online", "barcntenef.ml", "lpi1iyi7m3zfb0i.gq", "ceco3kvloj5s3.tk", "outlettomsshoesstore.com", "kebabishcosladacoslada.com", "utoo.email", "pedia-egypt.org", "bestmemory.net", "8263813.com", "hz6m.com", "anocor.gq", "charltons.biz", "qvady.network", "2v3vjqapd6itot8g4z.gq", "yliora.site", "ectseep.site", "2m46.space", "godrejpropertiesforestgrove.com", "smart-thailand.com", "takebacktheregent.com", "dozarb.online", "mail22.space", "ttsbcq.us", "clubhowse.com", "gayflorida.net", "specialsshorts.info", "dubainaturalsoap.com", "carolynlove.website", "jlqiqd.tokyo", "kulitlumpia8.cf", "adastralflying.com", "superstachel.de", "diyarbakirengelliler.xyz", "notatempmail.info", "directproductinvesting.com", "francisxkelly.com", "saclouisvuittonboutiquefrance.com", ...]>
#MapSet<["alivemail.ga", "nalds.live", "unalstore.xyz", "studiodesain.me", "betofis111.com", "gehu.site", "6q70sdpgjzm2irltn.tk", "zomg.info", "spingenie.org", "analyticalwe.us", "dickwangdong.net", "ezzzi.com", "caroil-promo.xyz", "enfsmq2wel.cf", "eagleinbox.com", "hikeeastcoasttrail.com", "indumento.club", "ro-na.com", "freebeautyofsweden.se", "gratislink.net", "bluetree.holiday", "alamedahomealarm.com", "waredbarn.com", "letslearnarduino.com", "folderiowa.com", "ufcticket.ru", "iqsfu65qbbkrioew.tk", "guzzthickfull.tk", "stanmody.ga", "erothde.gq", "nat4.us", "vnuova.icu", "wertuoicikax8.site", "0nedrive.ml", "tarjetasdecredito.company", "0374445.com", "lottoegg.live", "698424.com", "dfet356ads1.ml", "d9jdnvyk1m6audwkgm.tk", "rc94stgoffreg1.com", "langleyrecord.org", "mailed.ro", "sltmail.com", "dogfishmail.com", "vologdalestopprom.ru", "gnomebots.com", "cu8wzkanv7.cf", "czaresy.info", "7p6kz0omk2kb6fs8lst.tk", ...]>
```

### With an Ecto changeset
Expand Down Expand Up @@ -81,8 +81,8 @@ This is done like this:
```
iex> Burnex.check_domain_mx_record("gmail.com")
:ok
iex> Burnex.check_domain_mx_record("gmail.fr")
{:error, "Cannot find MX record"}
iex> Burnex.check_domain_mx_record("gmail.dklfsd")
{:error, "Cannot find MX records"}
```

Here is an example function to check if an email is valid:
Expand Down Expand Up @@ -130,7 +130,6 @@ Here is an example function to check if an email is valid:
end
```


## License

This software is licensed under MIT license. Copyright (c) 2018- Benjamin Piouffle.
72 changes: 38 additions & 34 deletions lib/burnex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ defmodule Burnex do

@dialyzer {:nowarn_function, is_burner_domain?: 1}

@inet_res_opts [
{:alt_nameservers,
[
# Cloudflare primary
{{1, 1, 1, 1}, 53},
# Google primary
{{8, 8, 8, 8}, 53},
# Cloudflare secondary
{{1, 0, 0, 1}, 53},
# Google secondary
{{8, 8, 4, 4}, 53}
]}
]

@typep option :: {:providers, MapSet.t()}

@doc """
Expand Down Expand Up @@ -71,7 +85,9 @@ defmodule Burnex do
"""
@spec is_burner_domain?(binary(), list(option)) :: boolean()
def is_burner_domain?(domain, opts \\ []) when is_list(opts) do
def is_burner_domain?(domain, opts \\ [])

def is_burner_domain?(domain, opts) when is_list(opts) and is_binary(domain) do
providers = Keyword.get(opts, :providers, @providers)

case MapSet.member?(providers, domain) do
Expand All @@ -89,56 +105,44 @@ defmodule Burnex do
end
end

def is_burner_domain?(_domain, _opts), do: true

@doc """
Returns a MapSet with all blocked domains providers.
## Examples
iex> Burnex.providers()
#MapSet<["mysunrise.tech", "gmailom.co", "renwoying.org", "xn--c3cralk2a3ak7a5gghbv.com", "vevevevevery.ru", "ghork.live", "totobaksa.website", "wellnessmarketing.solutions", "zerograv.top", "votenoonnov6.com", "b45win.org", "dataleak01.site", "muslimahcollection.online", "barcntenef.ml", "lpi1iyi7m3zfb0i.gq", "ceco3kvloj5s3.tk", "outlettomsshoesstore.com", "kebabishcosladacoslada.com", "utoo.email", "pedia-egypt.org", "bestmemory.net", "8263813.com", "hz6m.com", "anocor.gq", "charltons.biz", "qvady.network", "2v3vjqapd6itot8g4z.gq", "yliora.site", "ectseep.site", "2m46.space", "godrejpropertiesforestgrove.com", "smart-thailand.com", "takebacktheregent.com", "dozarb.online", "mail22.space", "ttsbcq.us", "clubhowse.com", "gayflorida.net", "specialsshorts.info", "dubainaturalsoap.com", "carolynlove.website", "jlqiqd.tokyo", "kulitlumpia8.cf", "adastralflying.com", "superstachel.de", "diyarbakirengelliler.xyz", "notatempmail.info", "directproductinvesting.com", "francisxkelly.com", "saclouisvuittonboutiquefrance.com", ...]>
#MapSet<["alivemail.ga", "nalds.live", "unalstore.xyz", "studiodesain.me", "betofis111.com", "gehu.site", "6q70sdpgjzm2irltn.tk", "zomg.info", "spingenie.org", "analyticalwe.us", "dickwangdong.net", "ezzzi.com", "caroil-promo.xyz", "enfsmq2wel.cf", "eagleinbox.com", "hikeeastcoasttrail.com", "indumento.club", "ro-na.com", "freebeautyofsweden.se", "gratislink.net", "bluetree.holiday", "alamedahomealarm.com", "waredbarn.com", "letslearnarduino.com", "folderiowa.com", "ufcticket.ru", "iqsfu65qbbkrioew.tk", "guzzthickfull.tk", "stanmody.ga", "erothde.gq", "nat4.us", "vnuova.icu", "wertuoicikax8.site", "0nedrive.ml", "tarjetasdecredito.company", "0374445.com", "lottoegg.live", "698424.com", "dfet356ads1.ml", "d9jdnvyk1m6audwkgm.tk", "rc94stgoffreg1.com", "langleyrecord.org", "mailed.ro", "sltmail.com", "dogfishmail.com", "vologdalestopprom.ru", "gnomebots.com", "cu8wzkanv7.cf", "czaresy.info", "7p6kz0omk2kb6fs8lst.tk", ...]>
"""
def providers do
@providers
end

defp bad_mx_server_domains(mx_resolution, opts) do
@spec check_domain_mx_record(binary(), list(option)) :: :ok | {:error, binary()}
def check_domain_mx_record(domain, opts \\ []) when is_list(opts) do
providers = Keyword.get(opts, :providers, @providers)

Enum.filter(mx_resolution, fn item ->
case item do
{_port, server_domain} ->
server_domain
|> to_string()
|> is_burner_domain?(providers: providers)

_ ->
true
end
end)
case :inet_res.lookup(to_charlist(domain), :in, :mx, @inet_res_opts, 5_000) do
[] -> {:error, "Cannot find MX records"}
mx_records -> check_bad_mx_server_domains(mx_records, providers: providers)
end
end

@spec check_domain_mx_record(binary(), list(option)) :: :ok | {:error, binary()}
def check_domain_mx_record(domain, opts \\ []) when is_list(opts) do
defp check_bad_mx_server_domains(mx_records, opts) do
providers = Keyword.get(opts, :providers, @providers)

with {:dns_resolve, {:ok, mx_resolution}} <- {:dns_resolve, DNS.resolve(domain, :mx)},
{:bad_server_domains, []} <-
{:bad_server_domains, bad_mx_server_domains(mx_resolution, providers: providers)} do
:ok
else
{:dns_resolve, _} ->
{:error, "Cannot find MX record"}

{:bad_server_domains, bad_server_domains} ->
{:error,
"Forbidden MX server(s): " <>
Enum.join(
Enum.map(bad_server_domains, fn {_port, server} -> server end),
", "
)}
end
rescue
Socket.Error -> {:error, "MX record search timed out"}
mx_records
|> Enum.map(fn {_port, domain} -> to_string(domain) end)
|> Enum.filter(fn domain -> is_burner_domain?(domain, providers: providers) end)
|> mx_server_check_response()
end

defp mx_server_check_response([]), do: :ok

defp mx_server_check_response(domains) do
{:error, "Forbidden MX server(s): " <> Enum.join(domains, ", ")}
end
end
4 changes: 1 addition & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ defmodule Burnex.Mixfile do

defp deps do
[
{:dns, "~> 2.2.0"},

# Dev
{:credo, "~> 1.5.0", only: [:dev, :test], runtime: false},
{:credo, "~> 1.6.0", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.22", only: :dev, runtime: false},
{:eliver, "~> 2.0.0", only: :dev},
Expand Down
Loading

0 comments on commit 998d10d

Please sign in to comment.