From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C7EA27ABB9 for ; Mon, 10 May 2021 13:51:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B422D17929 for ; Mon, 10 May 2021 13:51:23 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 972801791E for ; Mon, 10 May 2021 13:51:22 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 642D1461A5 for ; Mon, 10 May 2021 13:51:22 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 10 May 2021 13:51:21 +0200 Message-Id: <20210510115121.19664-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.015 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox v2] fix #3302: allow for more characters for email X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 May 2021 11:51:53 -0000 change to something similar as in pve-common word characters, +, -, ~ and . for the local part and refactor it in a const_regex for reuse Signed-off-by: Dominik Csapak --- note that we cannot use the regex in the api yet, as that would be a breaking API change (we use a much more relaxed regex for a users email), but we should do that for 2.0 proxmox/src/tools/email.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/proxmox/src/tools/email.rs b/proxmox/src/tools/email.rs index b5d42c4..945f4db 100644 --- a/proxmox/src/tools/email.rs +++ b/proxmox/src/tools/email.rs @@ -1,10 +1,15 @@ //! Email related utilities. use crate::tools::time::epoch_i64; +use crate::const_regex; use anyhow::{bail, Error}; use std::io::Write; use std::process::{Command, Stdio}; +const_regex!{ + pub EMAIL_REGEX = r"^[\w\+\-\~\.]+@[a-zA-Z\.0-9-]+$"; +} + /// Sends multi-part mail with text and/or html to a list of recipients /// /// ``sendmail`` is used for sending the mail. @@ -16,20 +21,18 @@ pub fn sendmail( mailfrom: Option<&str>, author: Option<&str>, ) -> Result<(), Error> { - let mail_regex = regex::Regex::new(r"^[a-zA-Z\.0-9-]+@[a-zA-Z\.0-9-]+$").unwrap(); - if mailto.is_empty() { bail!("At least one recipient has to be specified!") } for recipient in mailto { - if !mail_regex.is_match(recipient) { + if !EMAIL_REGEX.is_match(recipient) { bail!("'{}' is not a valid email address", recipient) } } let mailfrom = mailfrom.unwrap_or("root"); - if !mailfrom.eq("root") && !mail_regex.is_match(mailfrom) { + if !mailfrom.eq("root") && !EMAIL_REGEX.is_match(mailfrom) { bail!("'{}' is not a valid email address", mailfrom) } -- 2.20.1