Skip to content

Commit

Permalink
fix: Check deliverability using successful response code instead of m…
Browse files Browse the repository at this point in the history
…essage parsing (#822)

* Check deliverability using successful response code instead of message parsing

* Mention no 3xx response codes in comment
  • Loading branch information
tyranron authored Jan 7, 2021
1 parent c703144 commit 39d0ecd
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions core/src/smtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,24 @@ async fn email_deliverable(
.command(RcptCommand::new(to_email.clone(), vec![]))
.await
{
Ok(response) => match response.first_line() {
Some(message) => {
let message = message.to_lowercase();
let is_deliverable = message.contains("2.1.5") ||
// 250 Recipient address accepted
// 250 Accepted
message.contains("accepted")||
// 250 OK
// 250 Recipient <email> OK
message.contains("ok");
Ok(Deliverability {
has_full_inbox: false,
is_deliverable,
is_disabled: false,
})
}
None => Err(SmtpError::SmtpError(AsyncSmtpError::Client(
"No response on RCPT command",
))),
},
Ok(_) => {
// According to RFC 5321, `RCPT TO` command succeeds with 250 and
// 251 codes only (no 3xx codes at all):
// https://tools.ietf.org/html/rfc5321#page-56
//
// Where the 251 code is used for forwarding, which is not our case,
// because we always deliver to the SMTP server hosting the address
// itself.
//
// So, if `response.is_positive()` (which is a condition for
// returning `Ok` from the `command()` method above), then delivery
// succeeds, accordingly to RFC 5321.
Ok(Deliverability {
has_full_inbox: false,
is_deliverable: true, // response.is_positive()
is_disabled: false,
})
}
Err(err) => {
// We cast to lowercase, because our matched strings below are all
// lowercase.
Expand Down

0 comments on commit 39d0ecd

Please sign in to comment.