-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ MailChecker currently supports: | |
* [Python](https://github.com/FGRibreau/mailchecker/tree/master/platform/python) | ||
* [Ruby](https://github.com/FGRibreau/mailchecker/tree/master/platform/ruby) | ||
* [Elixir](https://github.com/FGRibreau/mailchecker/tree/master/platform/elixir) | ||
* [Clojure](https://github.com/FGRibreau/mailchecker/tree/master/platform/clojure) | ||
* **Easily add support for your own language with MailChecker template system and [send us a pull-request!](https://github.com/FGRibreau/mailchecker/fork_select)** | ||
|
||
------------------------- | ||
|
@@ -114,6 +115,19 @@ unless MailChecker.valid?('[email protected]') | |
end | ||
``` | ||
|
||
### Clojure | ||
|
||
```clojure | ||
; no package yet; just drop in mailchecker.clj where you want to use it. | ||
(load-file "platform/clojure/mailchecker.clj") | ||
|
||
(if (not (mailchecker/valid? "[email protected]")) | ||
(throw (Throwable. "O RLY!"))) | ||
|
||
(if (not (mailchecker/valid? "myemail.com")) | ||
(throw (Throwable. "O RLY!"))) | ||
``` | ||
|
||
-------------------- | ||
|
||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,13 @@ | |
|
||
(def ^:const blacklist (set [{{& listSTR }}])) | ||
|
||
; Copied from https://github.com/scstarkey/noir/blob/998e846dd44f42b8e01a6977e6d22a3eff5e4542/src/noir/validation.clj#L37-L40 | ||
; Source: https://github.com/scstarkey/noir/blob/998e846dd44f42b8e01a6977e6d22a3eff5e4542/src/noir/validation.clj#L37-L40 | ||
; Modified to return true/false | ||
(defn is-email? | ||
"Returns true if email is an email address" | ||
[email] | ||
(re-matches #"(?i)[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" email)) | ||
(if (re-matches #"(?i)[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" email) | ||
true false)) | ||
|
||
(defn at-split | ||
"Returns list from string splitted on @ char" | ||
|
@@ -55,25 +57,3 @@ | |
(is-email? email) | ||
(not | ||
(in-blacklist? email)))) | ||
|
||
; (println (valid? "[email protected]")) | ||
; (println (valid? "example.com")) | ||
; (println (top-domain-part "[email protected]")) | ||
|
||
; Valid | ||
(println (valid? "[email protected]")) | ||
(println (valid? "[email protected]")) | ||
(println (valid? "[email protected]")) | ||
(println (valid? "[email protected]")) | ||
(println (valid? "[email protected]")) | ||
(println (valid? "[email protected]")) | ||
|
||
; Invalid | ||
(println (not (valid? "plopplop.com"))) | ||
(println (not (valid? "my+ok@ok=plop.com"))) | ||
(println (not (valid? "my,[email protected]"))) | ||
|
||
(println (not (valid? "[email protected]"))) | ||
(println (not (valid? "[email protected]"))) | ||
(println (not (valid? "[email protected]"))) | ||
(println (not (valid? "[email protected]"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
; Run test with the lein-exec plugin: | ||
; $ lein exec test/platform.clojure.test.clj | ||
(load-file "platform/clojure/mailchecker.clj") | ||
|
||
(ns clojure.test.example | ||
(:use clojure.test)) | ||
|
||
; Valid | ||
(deftest true-for-valid-1 | ||
(is (= true (mailchecker/valid? "[email protected]")))) | ||
(deftest true-for-valid-2 | ||
(is (= true (mailchecker/valid? "[email protected]")))) | ||
(deftest true-for-valid-3 | ||
(is (= true (mailchecker/valid? "[email protected]")))) | ||
(deftest true-for-valid-4 | ||
(is (= true (mailchecker/valid? "[email protected]")))) | ||
(deftest true-for-valid-5 | ||
(is (= true (mailchecker/valid? "[email protected]")))) | ||
(deftest true-for-valid-6 | ||
(is (= true (mailchecker/valid? "[email protected]")))) | ||
|
||
; Invalid | ||
(deftest false-for-invalid-1 | ||
(is(= false (mailchecker/valid? "plopplop.com")))) | ||
(deftest false-for-invalid-2 | ||
(is(= false (mailchecker/valid? "my+ok@ok=plop.com")))) | ||
(deftest false-for-invalid-3 | ||
(is(= false (mailchecker/valid? "my,[email protected]")))) | ||
|
||
(deftest false-for-spam-1 | ||
(is(= false (mailchecker/valid? "[email protected]")))) | ||
(deftest false-for-spam-2 | ||
(is(= false (mailchecker/valid? "[email protected]")))) | ||
(deftest false-for-spam-3 | ||
(is(= false (mailchecker/valid? "[email protected]")))) | ||
(deftest false-for-spam-4 | ||
(is(= false (mailchecker/valid? "[email protected]")))) | ||
|
||
(run-all-tests) |