Check if an email address exists without sending any email, written in Rust. Comes with a ⚙️ HTTP backend.
Rust emailemail-validationemail-validation-apiemail-verificationemail-verification-apiemail-verifierhacktoberfest
refactor: Use futures (#78)
Amaury Martiny0e1f6b014929
diff --git a/Cargo.lock b/Cargo.lockindex decf780b..8fec2fda 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -120,12 +120,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"name = "check-if-email-exists"version = "0.4.0"dependencies = [+ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)","lettre 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)","log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)","mailchecker 3.3.1 (registry+https://github.com/rust-lang/crates.io-index)","native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)","rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",- "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)","serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)","serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)","trust-dns-resolver 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",@@ -138,6 +138,7 @@ dependencies = ["check-if-email-exists 0.4.0","clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)","env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)","serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)","serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",]@@ -147,6 +148,7 @@ name = "check-if-email-exists-test-suite"version = "0.4.0"dependencies = ["check-if-email-exists 0.4.0",+ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)","serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)","serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",]@@ -227,11 +229,6 @@ dependencies = ["lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",]-[[package]]-name = "either"-version = "1.5.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-[[package]]name = "enum-as-inner"version = "0.2.1"@@ -324,6 +321,88 @@ name = "futures"version = "0.1.28"source = "registry+https://github.com/rust-lang/crates.io-index"+[[package]]+name = "futures"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+]++[[package]]+name = "futures-channel"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+]++[[package]]+name = "futures-core"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"++[[package]]+name = "futures-executor"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+]++[[package]]+name = "futures-io"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"++[[package]]+name = "futures-macro"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",+ "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",+]++[[package]]+name = "futures-sink"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"++[[package]]+name = "futures-task"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"++[[package]]+name = "futures-util"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",+ "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",+ "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",+ "proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",+ "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",+]+[[package]]name = "getrandom"version = "0.1.12"@@ -632,6 +711,11 @@ name = "percent-encoding"version = "2.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"+[[package]]+name = "pin-utils"+version = "0.1.0-alpha.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+[[package]]name = "pkg-config"version = "0.3.16"@@ -642,6 +726,21 @@ name = "ppv-lite86"version = "0.2.5"source = "registry+https://github.com/rust-lang/crates.io-index"+[[package]]+name = "proc-macro-hack"+version = "0.5.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",+ "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",+]++[[package]]+name = "proc-macro-nested"+version = "0.1.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+[[package]]name = "proc-macro2"version = "0.4.27"@@ -650,6 +749,14 @@ dependencies = ["unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",]+[[package]]+name = "proc-macro2"+version = "1.0.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",+]+[[package]]name = "quick-error"version = "1.2.2"@@ -663,6 +770,14 @@ dependencies = ["proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",]+[[package]]+name = "quote"+version = "1.0.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",+]+[[package]]name = "rand"version = "0.6.5"@@ -796,28 +911,6 @@ dependencies = ["rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",]-[[package]]-name = "rayon"-version = "1.2.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-dependencies = [- "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",- "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",- "rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",-]--[[package]]-name = "rayon-core"-version = "1.6.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-dependencies = [- "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",- "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",- "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",- "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",- "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",-]-[[package]]name = "rdrand"version = "0.4.0"@@ -997,6 +1090,16 @@ dependencies = ["unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",]+[[package]]+name = "syn"+version = "1.0.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+dependencies = [+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",+ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",+]+[[package]]name = "synstructure"version = "0.10.1"@@ -1284,6 +1387,11 @@ name = "unicode-xid"version = "0.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"+[[package]]+name = "unicode-xid"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+[[package]]name = "url"version = "2.1.0"@@ -1420,7 +1528,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index""checksum crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04c9e3102cc2d69cd681412141b390abd55a362afc1540965dad0ad4d34280b4""checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b""checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c"-"checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac""checksum enum-as-inner 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3d58266c97445680766be408285e798d3401c6d4c378ec5552e78737e681e37d""checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36""checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"@@ -1433,6 +1540,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index""checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82""checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7""checksum futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "45dc39533a6cae6da2b56da48edae506bb767ec07370f86f70fc062e9d435869"+"checksum futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b6f16056ecbb57525ff698bb955162d0cd03bee84e6241c27ff75c08d8ca5987"+"checksum futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fcae98ca17d102fd8a3603727b9259fcf7fa4239b603d2142926189bc8999b86"+"checksum futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866"+"checksum futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e274736563f686a837a0568b478bdabfeaec2dca794b5649b04e2fe1627c231"+"checksum futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e676577d229e70952ab25f3945795ba5b16d63ca794ca9d2c860e5595d20b5ff"+"checksum futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52e7c56c15537adb4f76d0b7a76ad131cb4d2f4f32d3b0bcabcbe1c7c5e87764"+"checksum futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16"+"checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9"+"checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76""checksum getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "473a1265acc8ff1e808cd0a1af8cee3c2ee5200916058a2ca113c29f2d903571""checksum hostname 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "21ceb46a83a85e824ef93669c8b390009623863b5c195d1ba747292c0c72f94e""checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"@@ -1468,11 +1584,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index""checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337""checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9""checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"+"checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587""checksum pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "72d5370d90f49f70bd033c3d75e87fc529fbfff9d6f7cccef07d6170079d91ea""checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b"+"checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5"+"checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e""checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915"+"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27""checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0""checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"+"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe""checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca""checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412""checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"@@ -1487,8 +1608,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index""checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071""checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44""checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"-"checksum rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83a27732a533a1be0a0035a111fe76db89ad312f6f0347004c220c57f209a123"-"checksum rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "98dcf634205083b17d0861252431eb2acbfb698ab7478a2d20de07954f47ec7b""checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2""checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85""checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd"@@ -1513,6 +1632,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index""checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8""checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a""checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2"+"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92""checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015""checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9""checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e"@@ -1537,6 +1657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index""checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426""checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20""checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"+"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c""checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61""checksum vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95""checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"diff --git a/Cargo.toml b/Cargo.tomlindex e2164139..730e9134 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -12,6 +12,7 @@ path = "src/main.rs"check-if-email-exists = { path = "core" }clap = { version = "2.32", features = ["yaml"] }env_logger = "0.7"+futures = "0.3"serde = "1.0"serde_json = "1.0"diff --git a/core/Cargo.toml b/core/Cargo.tomlindex 1cc04bbd..63e4ced8 100644--- a/core/Cargo.toml+++ b/core/Cargo.toml@@ -17,12 +17,12 @@ appveyor = { repository = "amaurymartiny/check-if-email-exists", service = "githtravis-ci = { repository = "amaurymartiny/check-if-email-exists", service = "github" }[dependencies]+futures = "0.3"lettre = "0.9"log = "0.4"mailchecker = "3.3"native-tls = "^0.2"rand = "0.7"-rayon = "1.2.0"trust-dns-resolver = "0.12.0"serde = { version = "1.0", features = ["derive"] }serde_json = "1.0"diff --git a/core/src/lib.rs b/core/src/lib.rsindex 325ef47d..36aec78c 100644--- a/core/src/lib.rs+++ b/core/src/lib.rs@@ -20,7 +20,6 @@ extern crate log;extern crate mailchecker;extern crate native_tls;extern crate rand;-extern crate rayon;extern crate serde;extern crate trust_dns_resolver;@@ -29,9 +28,9 @@ mod smtp;mod syntax;mod util;+use futures::future::select_ok;use lettre::{smtp::SMTP_PORT, EmailAddress};use mx::{get_mx_lookup, MxDetails, MxError};-use rayon::prelude::*;use serde::{ser::SerializeMap, Serialize, Serializer};use smtp::{SmtpDetails, SmtpError};use std::str::FromStr;@@ -79,7 +78,7 @@ impl Serialize for SingleEmail {/// The main function: checks email format, checks MX records, and checks SMTP/// responses to the email inbox.-pub fn email_exists(to_email: &str, from_email: &str) -> SingleEmail {+pub async fn email_exists(to_email: &str, from_email: &str) -> SingleEmail {let from_email = EmailAddress::from_str(from_email).unwrap_or_else(|_| {EmailAddress::from_str("[email protected]").expect("This is a valid email. qed.")});@@ -110,31 +109,30 @@ pub fn email_exists(to_email: &str, from_email: &str) -> SingleEmail {};debug!("Found the following MX hosts {:?}", my_mx);- // `(host, port)` combination- // We could add ports 465 and 587 too- let combinations = my_mx+ // Create one future per lookup result+ let futures = my_mx.lookup.iter()- .map(|host| (host.exchange(), SMTP_PORT))- .collect::<Vec<_>>();-- let my_smtp = combinations- // Concurrently find any combination that returns true for email_exists- .par_iter()- // Attempt to make a SMTP call to host- .flat_map(|(host, port)| {- smtp::smtp_details(+ .map(|host| {+ let fut = smtp::smtp_details(&from_email,&my_syntax.address,- host,- *port,+ host.exchange(),+ // We could add ports 465 and 587 too+ SMTP_PORT,my_syntax.domain.as_str(),- )+ );++ // https://rust-lang.github.io/async-book/04_pinning/01_chapter.html+ Box::pin(fut)})- .find_any(|_| true)- // If all smtp calls timed out/got refused/errored, we assume that the- // ISP is blocking relevant ports- .ok_or(SmtpError::BlockedByIsp);+ .collect::<Vec<_>>();++ // Race, return the first future that resolves+ let my_smtp = match select_ok(futures).await {+ Ok((details, _)) => Ok(details),+ Err(err) => Err(err),+ };SingleEmail {mx: Ok(my_mx),diff --git a/core/src/smtp.rs b/core/src/smtp.rsindex 7d4693d5..a47c9e4a 100644--- a/core/src/smtp.rs+++ b/core/src/smtp.rs@@ -46,11 +46,9 @@ pub struct SmtpDetails {pub enum SmtpError {/// Skipped checking SMTP detailsSkipped,- /// ISP is blocking SMTP ports- BlockedByIsp,- /// IO error when communicating with SMTP server+ /// Error when communicating with SMTP server#[serde(serialize_with = "ser_with_display")]- SmtpError(LettreSmtpError),+ LettreError(LettreSmtpError),}/// Try to send an smtp command, close and return Err if fails.@@ -123,7 +121,7 @@ struct Deliverability {fn email_deliverable(smtp_client: &mut InnerClient<NetworkStream>,to_email: &EmailAddress,-) -> Result<Deliverability, LettreSmtpError> {+) -> Result<Deliverability, SmtpError> {// "RCPT TO: [email protected]"// FIXME Do not clone?let to_email = to_email.clone();@@ -138,10 +136,14 @@ fn email_deliverable(is_disabled: false,})} else {- Err(LettreSmtpError::Client("Can't find 2.1.5 in RCPT command"))+ Err(SmtpError::LettreError(LettreSmtpError::Client(+ "Can't find 2.1.5 in RCPT command",+ )))}}- None => Err(LettreSmtpError::Client("No response on RCPT command")),+ None => Err(SmtpError::LettreError(LettreSmtpError::Client(+ "No response on RCPT command",+ ))),},Err(err) => {let err_string = err.to_string();@@ -191,7 +193,7 @@ fn email_deliverable(});}- Err(err)+ Err(SmtpError::LettreError(err))}}}@@ -200,7 +202,7 @@ fn email_deliverable(fn email_has_catch_all(smtp_client: &mut InnerClient<NetworkStream>,domain: &str,-) -> Result<bool, LettreSmtpError> {+) -> Result<bool, SmtpError> {// Create a random 15-char alphanumerical stringlet random_email = rand::thread_rng().sample_iter(&Alphanumeric)@@ -216,14 +218,17 @@ fn email_has_catch_all(}/// Get all email details we can.-pub fn smtp_details(+pub async fn smtp_details(from_email: &EmailAddress,to_email: &EmailAddress,host: &Name,port: u16,domain: &str,-) -> Result<SmtpDetails, LettreSmtpError> {- let mut smtp_client = connect_to_host(from_email, host, port)?;+) -> Result<SmtpDetails, SmtpError> {+ let mut smtp_client = match connect_to_host(from_email, host, port) {+ Ok(client) => client,+ Err(err) => return Err(SmtpError::LettreError(err)),+ };let is_catch_all = email_has_catch_all(&mut smtp_client, domain).unwrap_or(false);let deliverability = email_deliverable(&mut smtp_client, to_email)?;diff --git a/src/main.rs b/src/main.rsindex 022196da..39339ca4 100644--- a/src/main.rs+++ b/src/main.rs@@ -20,6 +20,7 @@ extern crate serde;use check_if_email_exists::email_exists;use clap::App;+use futures::executor::block_on;use serde_json;fn main() -> serde_json::Result<()> {@@ -36,7 +37,9 @@ fn main() -> serde_json::Result<()> {.value_of("TO_EMAIL").expect("TO_EMAIL is required. qed.");- let output = serde_json::to_string_pretty(&email_exists(&to_email, &from_email))?;+ let result = block_on(email_exists(&to_email, &from_email));++ let output = serde_json::to_string_pretty(&result)?;println!("{}", output);Ok(())diff --git a/test_suite/Cargo.toml b/test_suite/Cargo.tomlindex 515e8302..f8888869 100644--- a/test_suite/Cargo.toml+++ b/test_suite/Cargo.toml@@ -6,5 +6,6 @@ publish = false[dependencies]check-if-email-exists = { path = "../core" }+futures = "0.3"serde = "1.0"serde_json = "1.0"diff --git a/test_suite/src/lib.rs b/test_suite/src/lib.rsindex de916816..49465e57 100644--- a/test_suite/src/lib.rs+++ b/test_suite/src/lib.rs@@ -19,19 +19,23 @@#[cfg(test)]mod tests {use check_if_email_exists::email_exists;+ use futures::executor::block_on;#[test]fn should_output_error_for_invalid_email() {+ let result = block_on(email_exists("foo", "[email protected]"));assert_eq!(- serde_json::to_string(&email_exists("foo", "[email protected]")).unwrap(),+ serde_json::to_string(&result).unwrap(),"{\"mx\":{\"error\":{\"type\":\"Skipped\"}},\"smtp\":{\"error\":{\"type\":\"Skipped\"}},\"syntax\":{\"error\":{\"type\":\"SyntaxError\",\"message\":\"invalid email address\"}}}");}#[test]fn should_output_error_for_invalid_mx() {+ let result = block_on(email_exists("[email protected]", "[email protected]"));+assert_eq!(- serde_json::to_string(&email_exists("[email protected]", "[email protected]")).unwrap(),+ serde_json::to_string(&result).unwrap(),"{\"mx\":{\"error\":{\"type\":\"ResolveError\",\"message\":\"no record found for name: bar.baz type: MX class: IN\"}},\"smtp\":{\"error\":{\"type\":\"Skipped\"}},\"syntax\":{\"address\":\"[email protected]\",\"domain\":\"bar.baz\",\"username\":\"foo\",\"valid_format\":true}}");}