1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
// check-if-email-exists
// Copyright (C) 2018-2022 Reacher
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// 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 gravatar;
use crate::haveibeenpwned::check_haveibeenpwned;
use serde::{Deserialize, Serialize};
use std::default::Default;
use crate::syntax::SyntaxDetails;
use gravatar::check_gravatar;
const ROLE_ACCOUNTS: &str = include_str!("./roles.json");
/// Miscelleanous details about the email address.
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct MiscDetails {
/// Is this a DEA (disposable email account)?
pub is_disposable: bool,
/// Is this email a role-based account?
pub is_role_account: bool,
pub gravatar_url: Option<String>,
/// Is this email address listed in the haveibeenpwned database for
/// previous breaches?
pub haveibeenpwned: Option<bool>,
}
/// Error occured connecting to this email server via SMTP. Right now this
/// enum has no variant, as `check_misc` cannot fail. But putting a placeholder
/// right now to avoid future breaking changes.
#[derive(Debug, Serialize)]
#[serde(tag = "type", content = "message")]
pub enum MiscError {}
/// Fetch misc details about the email address, such as whether it's disposable.
pub async fn check_misc(
syntax: &SyntaxDetails,
cfg_check_gravatar: bool,
haveibeenpwned_api_key: Option<String>,
) -> MiscDetails {
let role_accounts: Vec<&str> =
serde_json::from_str(ROLE_ACCOUNTS).expect("roles.json is a valid json. qed.");
let address = syntax
.address
.as_ref()
.expect("We already checked that the syntax was valid. qed.")
.to_string();
let mut gravatar_url: Option<String> = None;
if cfg_check_gravatar {
gravatar_url = check_gravatar(address.as_ref()).await;
}
let mut haveibeenpwned: Option<bool> = None;
if haveibeenpwned_api_key.is_some() {
haveibeenpwned = check_haveibeenpwned(address.as_ref(), haveibeenpwned_api_key).await;
}
MiscDetails {
// mailchecker::is_valid checks also if the syntax is valid. But if
// we're here, it means we're sure the syntax is valid, so is_valid
// actually will only check if it's disposable.
is_disposable: !mailchecker::is_valid(address.as_ref()),
is_role_account: role_accounts.contains(&syntax.username.to_lowercase().as_ref()),
gravatar_url,
haveibeenpwned,
}
}