Skip to content

Check if an email address exists without sending any email, written in Rust. Comes with a ⚙️ HTTP backend.

refactor!: Remove HTTP backend from CLI (#1151)

Amaury71843720c9b8
diff --git a/Cargo.lock b/Cargo.lock
index 1cb4083d..83e0fa9a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -473,7 +473,6 @@ dependencies = [
"check-if-email-exists 0.8.32",
"clap",
"env_logger",
- "hyper",
"once_cell",
"openssl",
"serde",
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index cf4953d8..16cf1ec7 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.8.32"
default-run = "check_if_email_exists"
edition = "2018"
description = "Check if an email address exists without sending any email."
-authors = ["Amaury <[email protected]>"]
+authors = ["Amaury <[email protected]>"]
license = "AGPL-3.0"
publish = false
@@ -14,16 +14,12 @@ path = "src/main.rs"
[dependencies]
check-if-email-exists = { path = "../core" }
-clap = { version = "3.2.17", features = ["derive", "env"] }
-env_logger = "0.9.0"
-once_cell = "1.13.0"
-openssl = { version = "0.10.41", features = ["vendored"] }
-serde = "1.0.143"
-serde_json = "1.0.83"
-
-[dependencies.hyper]
-version = "0.14.20"
-features = ["full"]
+clap = { version = "3.2", features = ["derive", "env"] }
+env_logger = "0.9"
+once_cell = "1.13"
+openssl = { version = "0.10", features = ["vendored"] }
+serde = "1.0"
+serde_json = "1.0"
[dependencies.tokio]
version = "1.16.1"
diff --git a/cli/README.md b/cli/README.md
index 7781d08e..6350c441 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -15,37 +15,46 @@ Then run:
```bash
> $ check_if_email_exists --help
-check_if_email_exists 0.8.32
-Check if an email address exists without sending an email.
+check-if-email-exists-cli 0.8.32
+Check if an email address exists without sending any email.
USAGE:
- check_if_email_exists [FLAGS] [OPTIONS] [TO_EMAIL]
+ check_if_email_exists [OPTIONS] <TO_EMAIL>
ARGS:
<TO_EMAIL> The email to check
-FLAGS:
- -h, --help Print help information
- --http DEPRECATED. Runs an HTTP server. This option will be removed in v0.9.0
- -V, --version Print version information
-
OPTIONS:
--from-email <FROM_EMAIL>
The email to use in the `MAIL FROM:` SMTP command [env: FROM_EMAIL=] [default:
+ -h, --help
+ Print help information
+
--hello-name <HELLO_NAME>
The name to use in the `EHLO:` SMTP command [env: HELLO_NAME=] [default: localhost]
--proxy-host <PROXY_HOST>
Use the specified SOCKS5 proxy host to perform email verification [env: PROXY_HOST=]
+ --proxy-password <PROXY_PASSWORD>
+ Username passed to the specified SOCKS5 proxy port to perform email verification. Only
+ used when `--proxy-host` flag is set [env: PROXY_PASSWORD=]
+
--proxy-port <PROXY_PORT>
Use the specified SOCKS5 proxy port to perform email verification. Only used when
`--proxy-host` flag is set [env: PROXY_PORT=] [default: 1080]
+ --proxy-username <PROXY_USERNAME>
+ Username passed to the specified SOCKS5 proxy port to perform email verification. Only
+ used when `--proxy-host` flag is set [env: PROXY_USERNAME=]
+
--smtp-port <SMTP_PORT>
- The email to check [env: SMTP_PORT=] [default: 25]
+ The port to use for the SMTP request [env: SMTP_PORT=] [default: 25]
+
+ -V, --version
+ Print version information
--yahoo-use-api <YAHOO_USE_API>
For Yahoo email addresses, use Yahoo's API instead of connecting directly to their SMTP
diff --git a/cli/src/http.rs b/cli/src/http.rs
deleted file mode 100644
index 0a3d6c2e..00000000
--- a/cli/src/http.rs
+++ /dev/null
@@ -1,131 +0,0 @@
-// check-if-email-exists
-// Copyright (C) 2018-2022 Reacher
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published
-// by the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-use std::{borrow::Cow, net::SocketAddr};
-
-use check_if_email_exists::{check_email, CheckEmailInput, CheckEmailInputProxy};
-use hyper::service::{make_service_fn, service_fn};
-use hyper::{Body, Method, Request, Response, Server, StatusCode};
-use serde::{Deserialize, Serialize};
-
-use crate::CONF;
-
-/// JSON Request from POST /
-#[derive(Debug, Deserialize, Serialize)]
-#[deprecated(
- since = "0.8.24",
- note = "The HTTP server will be removed from the CLI, please use https://github.com/reacherhq/backend instead"
-)]
-pub struct PostReqBody {
- from_email: Option<String>,
- hello_name: Option<String>,
- to_emails: Vec<String>,
- proxy_host: Option<String>,
- proxy_port: Option<u16>,
-}
-
-/// Error Response from POST /
-#[derive(Debug, Deserialize, Serialize)]
-#[deprecated(
- since = "0.8.24",
- note = "The HTTP server will be removed from the CLI, please use https://github.com/reacherhq/backend instead"
-)]
-pub struct PostResError {
- error: String,
-}
-
-async fn req_handler(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
- match (req.method(), req.uri().path()) {
- // Serve some instructions at /
- (&Method::GET, "/") => Ok(Response::new(Body::from(
- "Send a POST request with JSON `{ \"from_email\"?: \"<email>\", \"hello_name\"?: \"<name>\", to_emails: \"<email>\" }` in the body",
- ))),
-
- // Do email_exists check on POST /
- (&Method::POST, "/") => {
- let body = hyper::body::to_bytes(req.into_body()).await?;
-
- let body = match serde_json::from_slice::<PostReqBody>(&body) {
- Ok(b) => b,
- Err(err) => {
- return Ok(Response::builder()
- .status(StatusCode::BAD_REQUEST)
- .body(Body::from(format!("{}", err)))
- .expect("Response::builder with this body will not throw. qed.")
- );
- }
- };
-
- // Create EmailInput from body
- let mut input = CheckEmailInput::new(body.to_emails);
- input
- .set_from_email(body.from_email.unwrap_or_else(|| CONF.from_email.clone()))
- .set_hello_name(body.hello_name.unwrap_or_else(|| CONF.hello_name.clone()))
- .set_yahoo_use_api(CONF.yahoo_use_api);
- if let Some(proxy_host) = body.proxy_host.map(Cow::Owned).or_else(|| CONF.proxy_host.as_ref().map(Cow::Borrowed)) {
- input.set_proxy(CheckEmailInputProxy {
- host:proxy_host.into_owned(),
- port: body.proxy_port.unwrap_or(CONF.proxy_port),
- ..Default::default()
- });
- }
-
- let body = check_email(&input).await;
- let body = match serde_json::to_string(&body) {
- Ok(b) => b,
- Err(err) => {
- return Ok(Response::builder()
- .status(StatusCode::BAD_REQUEST)
- .body(Body::from(format!("{}", err)))
- .expect("Response::builder with this body will not throw. qed.")
- );
- }
- };
-
- Ok(Response::new(Body::from(body)))
- }
-
- // Return the 404 Not Found for other routes.
- _ => {
- Ok(Response::builder()
- .status(StatusCode::NOT_FOUND)
- .body(Body::empty())
- .expect("Response::builder with this body will not throw. qed.")
- )
- }
- }
-}
-
-#[deprecated(
- since = "0.8.24",
- note = "The HTTP server will be removed from the CLI, please use https://github.com/reacherhq/backend instead"
-)]
-pub async fn run<A: Into<SocketAddr>>(
- addr: A,
-) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
- println!("WARNING: The HTTP server is deprecated, and will be removed in v0.9.0. Please see https://github.com/reacherhq/backend for a replacement.");
-
- let service = make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(req_handler)) });
-
- let addr = addr.into();
- let server = Server::bind(&addr).serve(service);
-
- println!("Listening on http://{}", addr);
-
- server.await?;
-
- Ok(())
-}
diff --git a/cli/src/main.rs b/cli/src/main.rs
index 4834e0ff..fe184fe2 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -14,17 +14,13 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
-mod http;
-
-use std::net::IpAddr;
-
use check_if_email_exists::{check_email, CheckEmailInput, CheckEmailInputProxy};
use clap::Parser;
use once_cell::sync::Lazy;
/// CLI options of this binary.
#[derive(Parser, Debug)]
-#[clap(author, version, about)]
+#[clap(version, about)]
pub struct Cli {
/// The email to use in the `MAIL FROM:` SMTP command.
#[clap(long, env, default_value = "[email protected]")]
@@ -63,37 +59,7 @@ pub struct Cli {
pub yahoo_use_api: bool,
/// The email to check.
- pub to_email: Option<String>,
-
- /// DEPRECATED. Runs a HTTP server.
- /// This option will be removed in v0.9.0.
- #[clap(long)]
- #[deprecated(
- since = "0.8.24",
- note = "The HTTP server will be removed from the CLI, please use https://github.com/reacherhq/backend instead"
- )]
- pub http: bool,
-
- /// DEPRECATED. Sets the host IP address on which the HTTP server should bind.
- /// Only used when `--http` flag is on.
- /// This option will be removed in v0.9.0.
- #[clap(long, env = "HOST", default_value = "127.0.0.1")]
- #[deprecated(
- since = "0.8.24",
- note = "The HTTP server will be removed from the CLI, please use https://github.com/reacherhq/backend instead"
- )]
- pub http_host: IpAddr,
-
- /// DEPRECATED. Sets the port on which the HTTP server should bind.
- /// Only used when `--http` flag is on.
- /// If not set, then it will use $PORT, or default to 3000.
- /// This option will be removed in v0.9.0.
- #[clap(long, env = "PORT", default_value = "3000")]
- #[deprecated(
- since = "0.8.24",
- note = "The HTTP server will be removed from the CLI, please use https://github.com/reacherhq/backend instead"
- )]
- pub http_port: u16,
+ pub to_email: String,
}
/// Global config of this application.
@@ -103,38 +69,33 @@ pub(crate) static CONF: Lazy<Cli> = Lazy::new(Cli::parse);
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
env_logger::init();
- if let Some(to_email) = &CONF.to_email {
- let mut input = CheckEmailInput::new(vec![to_email.clone()]);
- input
- .set_from_email(CONF.from_email.clone())
- .set_hello_name(CONF.hello_name.clone())
- .set_smtp_port(CONF.smtp_port)
- .set_yahoo_use_api(CONF.yahoo_use_api);
- if let Some(proxy_host) = &CONF.proxy_host {
- input.set_proxy(CheckEmailInputProxy {
- host: proxy_host.clone(),
- port: CONF.proxy_port,
- username: CONF.proxy_username.clone(),
- password: CONF.proxy_password.clone(),
- });
- }
-
- let result = check_email(&input).await;
-
- match serde_json::to_string_pretty(&result) {
- Ok(output) => {
- println!("{}", output);
- }
- Err(err) => {
- println!("{}", err);
- }
- };
+ let to_email = &CONF.to_email;
+
+ let mut input = CheckEmailInput::new(vec![to_email.clone()]);
+ input
+ .set_from_email(CONF.from_email.clone())
+ .set_hello_name(CONF.hello_name.clone())
+ .set_smtp_port(CONF.smtp_port)
+ .set_yahoo_use_api(CONF.yahoo_use_api);
+ if let Some(proxy_host) = &CONF.proxy_host {
+ input.set_proxy(CheckEmailInputProxy {
+ host: proxy_host.clone(),
+ port: CONF.proxy_port,
+ username: CONF.proxy_username.clone(),
+ password: CONF.proxy_password.clone(),
+ });
}
- // Run the web server if --http flag is on.
- if CONF.http {
- http::run((CONF.http_host, CONF.http_port)).await?;
- }
+ let result = check_email(&input).await;
+
+ match serde_json::to_string_pretty(&result) {
+ Ok(output) => {
+ println!("{}", output);
+ }
+ Err(err) => {
+ println!("{}", err);
+ }
+ };
Ok(())
}
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 06dfb702..920c8296 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "check-if-email-exists"
version = "0.8.32"
-authors = ["Amaury <[email protected]>"]
+authors = ["Amaury <[email protected]>"]
categories = ["email"]
description = "Check if an email address exists without sending any email"
documentation = "http://docs.rs/check-if-email-exists"
@@ -12,10 +12,6 @@ publish = true
readme = "../README.md"
repository = "https://github.com/reacherhq/check-if-email-exists"
-[badges]
-appveyor = { repository = "reacherhq/check-if-email-exists", service = "github" }
-travis-ci = { repository = "reacherhq/check-if-email-exists", service = "github" }
-
[dependencies]
async-native-tls = { version = "0.4", default-features = false }
async-recursion = "1.0.0"