* [pbs-devel] [PATCH proxmox v2] fix #3302: allow for more characters for email
@ 2021-05-10 11:51 Dominik Csapak
2021-05-11 9:23 ` Dietmar Maurer
0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2021-05-10 11:51 UTC (permalink / raw)
To: pbs-devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [pbs-devel] [PATCH proxmox v2] fix #3302: allow for more characters for email
2021-05-10 11:51 [pbs-devel] [PATCH proxmox v2] fix #3302: allow for more characters for email Dominik Csapak
@ 2021-05-11 9:23 ` Dietmar Maurer
0 siblings, 0 replies; 2+ messages in thread
From: Dietmar Maurer @ 2021-05-11 9:23 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Dominik Csapak
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@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)
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-11 9:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10 11:51 [pbs-devel] [PATCH proxmox v2] fix #3302: allow for more characters for email Dominik Csapak
2021-05-11 9:23 ` Dietmar Maurer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox