Skip to content

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

Update stuff

Amaury Martiny3c652b1b1689
diff --git a/.travis.yml b/.travis.yml
index bfc2c314..046d3523 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,4 +4,5 @@ rust:
cache: cargo
script:
- cargo test
- - RUST_LOG=debug cargo run -- $TEST_EMAIL | grep true
+ - cargo build
+ - RUST_LOG=debug ./target/debug/check-if-email-exists $TEST_EMAIL | grep true
diff --git a/src/smtp.rs b/src/smtp.rs
index 60f57d35..bca4ae2e 100644
--- a/src/smtp.rs
+++ b/src/smtp.rs
@@ -8,8 +8,8 @@ use trust_dns_resolver::Name;
// Try to send an smtp command, close if fails.
macro_rules! try_smtp (
- ($err: expr, $client: ident) => ({
- match $err {
+ ($res: expr, $client: ident) => ({
+ match $res {
Ok(res) => res,
_ => {
$client.close();
@@ -32,30 +32,27 @@ macro_rules! ensure_positive (
pub fn email_exists(from: &str, to: &str, host: &Name, port: u16) -> Result<bool, ()> {
debug!("Connecting to {}:{}...", host, port);
- let mut email_client: InnerClient<NetworkStream> = InnerClient::new();
+ let mut smtp_client: InnerClient<NetworkStream> = InnerClient::new();
// Set timeout.
try_smtp!(
- email_client.set_timeout(Some(Duration::new(3, 0))),
- email_client
+ smtp_client.set_timeout(Some(Duration::new(3, 0))),
+ smtp_client
);
// Connect to the host.
- ensure_positive!(
- try_smtp!(
- email_client.connect(&(host.to_utf8().as_str(), port), None),
- email_client
- ),
- email_client
+ try_smtp!(
+ smtp_client.connect(&(host.to_utf8().as_str(), port), None),
+ smtp_client
);
// Send ehlo and get server info.
let ehlo_response = ensure_positive!(
try_smtp!(
- email_client.command(EhloCommand::new(ClientId::new("localhost".to_string()))),
- email_client
+ smtp_client.command(EhloCommand::new(ClientId::new("localhost".to_string()))),
+ smtp_client
),
- email_client
+ smtp_client
);
let server_info = ServerInfo::from_response(&ehlo_response);
debug!("Server info: {}", server_info.as_ref().unwrap());
@@ -63,34 +60,37 @@ pub fn email_exists(from: &str, to: &str, host: &Name, port: u16) -> Result<bool
// Send from.
ensure_positive!(
try_smtp!(
- email_client.command(MailCommand::new(
+ smtp_client.command(MailCommand::new(
Some(EmailAddress::new(from.to_string()).unwrap()),
vec![],
)),
- email_client
+ smtp_client
),
- email_client
+ smtp_client
);
// Send to.
let rctp_response = try_smtp!(
- email_client.command(RcptCommand::new(
+ smtp_client.command(RcptCommand::new(
EmailAddress::new(to.to_string()).unwrap(),
vec![],
)),
- email_client
+ smtp_client
);
// Quit.
- try_smtp!(email_client.command(QuitCommand), email_client);
+ smtp_client.close();
if let Some(message) = rctp_response.first_line() {
+ debug!("message {}", message);
// 250 2.1.5 Recipient e-mail address ok.
if message.contains("2.1.5") {
+ debug!("1.5.2. {}", message);
return Ok(true);
}
// 550 5.1.1 Mailbox does not exist.
if message.contains("5.1.1") {
+ debug!("5.1.1 {}", message);
return Ok(false);
}
}