Skip to content

Commit

Permalink
prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Dec 4, 2024
1 parent a3f5814 commit b5c5be6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 41 deletions.
15 changes: 0 additions & 15 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ config = "0.14"
derive_builder = "0.20"
fantoccini = { version = "0.21.2" }
futures = { version = "0.3.30" }
fast-socks5 = "0.9.2"
hickory-proto = "0.24.0"
hickory-resolver = "0.24.0"
levenshtein = "1.0.5"
Expand Down
8 changes: 4 additions & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
//! - Email deliverability: Is an email sent to this address deliverable?
//! - Syntax validation. Is the address syntactically valid?
//! - DNS records validation. Does the domain of the email address have valid
//! MX DNS records?
//! MX DNS records?
//! - Disposable email address (DEA) validation. Is the address provided by a
//! known disposable email address provider?
//! known disposable email address provider?
//! - SMTP server validation. Can the mail exchanger of the email address
//! domain be contacted successfully?
//! domain be contacted successfully?
//! - Mailbox disabled. Has this email address been disabled by the email
//! provider?
//! provider?
//! - Full inbox. Is the inbox of this mailbox full?
//! - Catch-all address. Is this email address a catch-all address?
//!
Expand Down
50 changes: 29 additions & 21 deletions core/src/smtp/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ impl<T: AsyncRead + AsyncWrite + Unpin + Send> AsyncReadWrite for T {}
macro_rules! try_smtp (
($res: expr, $client: ident, $to_email: expr, $host: expr, $port: expr) => ({
if let Err(err) = $res {
log::debug!(target: LOG_TARGET, "[email={}] Closing [host={}:{}], because of error '{:?}'.", $to_email, $host, $port, err);
log::debug!(
target: LOG_TARGET,
"[email={}] Closing [host={}:{}], because of error '{:?}'.",
$to_email,
$host,
$port,err,
);
// Try to close the connection, but ignore if there's an error.
let _ = $client.quit().await;

Expand All @@ -63,24 +69,27 @@ async fn connect_to_host(

let smtp_client = SmtpClient::new().hello_name(ClientId::Domain(input.hello_name.clone()));

let stream: BufStream<Box<dyn AsyncReadWrite>> = if let Some(proxy) = &input.proxy {
let target_addr = format!("{}:{}", host, port);
let socks_stream = match (&proxy.username, &proxy.password) {
(Some(username), Some(password)) => {
Socks5Stream::connect_with_password(
(proxy.host.as_ref(), proxy.port),
target_addr,
username,
password,
)
.await?
}
_ => Socks5Stream::connect((proxy.host.as_ref(), proxy.port), target_addr).await?,
};
BufStream::new(Box::new(socks_stream) as Box<dyn AsyncReadWrite>)
} else {
let tcp_stream = TcpStream::connect(format!("{}:{}", host, port)).await?;
BufStream::new(Box::new(tcp_stream) as Box<dyn AsyncReadWrite>)
let stream: BufStream<Box<dyn AsyncReadWrite>> = match &input.proxy {
Some(proxy) => {
let target_addr = format!("{}:{}", host, port);
let socks_stream = match (&proxy.username, &proxy.password) {
(Some(username), Some(password)) => {
Socks5Stream::connect_with_password(
(proxy.host.as_ref(), proxy.port),
target_addr,
username,
password,
)
.await?
}
_ => Socks5Stream::connect((proxy.host.as_ref(), proxy.port), target_addr).await?,
};
BufStream::new(Box::new(socks_stream) as Box<dyn AsyncReadWrite>)
}
None => {
let tcp_stream = TcpStream::connect(format!("{}:{}", host, port)).await?;
BufStream::new(Box::new(tcp_stream) as Box<dyn AsyncReadWrite>)
}
};

let mut smtp_transport = SmtpTransport::new(smtp_client, stream).await?;
Expand Down Expand Up @@ -218,8 +227,7 @@ async fn smtp_is_catch_all<S: AsyncBufRead + AsyncWrite + Unpin + Send>(

// Create a random 15-char alphanumerical string.
let mut rng = SmallRng::from_entropy();
let random_email: String = iter::repeat(())
.map(|()| rng.sample(Alphanumeric))
let random_email: String = iter::repeat_with(|| rng.sample(Alphanumeric))
.map(char::from)
.take(15)
.collect();
Expand Down

0 comments on commit b5c5be6

Please sign in to comment.