all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox v2] fix #3302: allow for more characters for email
Date: Mon, 10 May 2021 13:51:21 +0200	[thread overview]
Message-ID: <20210510115121.19664-1-d.csapak@proxmox.com> (raw)

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 <d.csapak@proxmox.com>
---
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





             reply	other threads:[~2021-05-10 11:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10 11:51 Dominik Csapak [this message]
2021-05-11  9:23 ` Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210510115121.19664-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal