[pbs-devel] [PATCH proxmox v2] fix #3302: allow for more characters for email

Dietmar Maurer dietmar at proxmox.com
Tue May 11 11:23:35 CEST 2021


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 <d.csapak at 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)
>       }
>   





More information about the pbs-devel mailing list