Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Remove HTTP backend from CLI #1151

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <amaurym10@protonmail.com>"]
authors = ["Amaury <amaury@reacher.email>"]
license = "AGPL-3.0"
publish = false

Expand All @@ -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"
Expand Down
27 changes: 18 additions & 9 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
user@example.org]

-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
Expand Down
131 changes: 0 additions & 131 deletions cli/src/http.rs

This file was deleted.

93 changes: 27 additions & 66 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "user@example.org")]
Expand Down Expand Up @@ -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.
Expand All @@ -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(())
}
6 changes: 1 addition & 5 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "check-if-email-exists"
version = "0.8.32"
authors = ["Amaury <amaurym10@protonmail.com>"]
authors = ["Amaury <amaury@reacher.email>"]
categories = ["email"]
description = "Check if an email address exists without sending any email"
documentation = "http://docs.rs/check-if-email-exists"
Expand All @@ -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"
Expand Down