From b9bda4049540372811a86d8dd7ba873c9875e54d Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaury1729@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:38:24 +0100 Subject: [PATCH] feat(backend): Support RCH_SMTP_TIMEOUT (#1407) * feat(backend): Support RCH_SMTP_TIMEOUT * fix clippy --- backend/README.md | 1 + backend/src/check.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/README.md b/backend/README.md index 8c246e6a6..7def3e3a5 100644 --- a/backend/README.md +++ b/backend/README.md @@ -61,6 +61,7 @@ These are the environment variables used to configure the HTTP server. To pass t | `RCH_HEADER_SECRET` | No | If set, then all HTTP requests must have the `x-reacher-secret` header set to this value. This is used to protect the backend against public unwanted HTTP requests. | undefined | | `RCH_FROM_EMAIL` | No | Email to use in the `` SMTP step. Can be overwritten by each API request's `from_email` field. | reacher.email@gmail.com | | `RCH_HELLO_NAME` | No | Name to use in the `` SMTP step. Can be overwritten by each API request's `hello_name` field. | gmail.com | +| `RCH_SMTP_TIMEOUT` | No | Timeout for each SMTP connection. | 45s | | `RCH_WEBDRIVER_ADDR` | No | Set to a running WebDriver process endpoint (e.g. `http://localhost:9515`) to use a headless navigator to password recovery pages to check Yahoo and Hotmail/Outlook addresses. We recommend `chromedriver` as it allows parallel requests. | not defined | ## REST API Documentation diff --git a/backend/src/check.rs b/backend/src/check.rs index dcd7cfd15..d8dacff12 100644 --- a/backend/src/check.rs +++ b/backend/src/check.rs @@ -16,7 +16,7 @@ //! This file contains shared logic for checking one email. -use std::env; +use std::{env, time::Duration}; use check_if_email_exists::{check_email as ciee_check_email, CheckEmailInput, CheckEmailOutput}; use warp::Filter; @@ -30,12 +30,18 @@ pub async fn check_email(input: CheckEmailInput) -> CheckEmailOutput { env::var("RCH_FROM_EMAIL").unwrap_or_else(|_| CheckEmailInput::default().from_email); let hello_name = env::var("RCH_HELLO_NAME").unwrap_or_else(|_| CheckEmailInput::default().hello_name); + let smtp_timeout = env::var("RCH_SMTP_TIMEOUT") + .ok() + .and_then(|s| s.parse::().ok()) + .map(Duration::from_secs) + .or_else(|| CheckEmailInput::default().smtp_timeout); let input = CheckEmailInput { // If we want to override core check-if-email-exists's default values // for CheckEmailInput for the backend, we do it here. from_email, hello_name, + smtp_timeout, ..input };