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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B549F7AF6E for ; Tue, 11 May 2021 11:24:06 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A22FB1FAC8 for ; Tue, 11 May 2021 11:23:36 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 1E69B1FAB9 for ; Tue, 11 May 2021 11:23:36 +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 B942D4651B for ; Tue, 11 May 2021 11:23:35 +0200 (CEST) To: Proxmox Backup Server development discussion , Dominik Csapak References: <20210510115121.19664-1-d.csapak@proxmox.com> From: Dietmar Maurer Message-ID: <6066882b-211f-4ca7-9b12-05e13f41c137@proxmox.com> Date: Tue, 11 May 2021 11:23:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210510115121.19664-1-d.csapak@proxmox.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-SPAM-LEVEL: Spam detection results: 0 AWL 0.223 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [email.rs] Subject: Re: [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: Tue, 11 May 2021 09:24:06 -0000 As discussed offline, I would not do any check here (pass recipients as separate args) On 5/10/21 1:51 PM, Dominik Csapak wrote: > 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) > } >