From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common 1/2] move email regex from JSONSchema to Tools
Date: Tue, 1 Sep 2020 11:18:03 +0200 [thread overview]
Message-ID: <20200901091804.23647-2-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20200901091804.23647-1-s.ivanov@proxmox.com>
Move the Regular expression used for matching e-mail addresses from
the verify sub in PVE::JSONSchema to PVE::Tools, so that it can be reused
in PVE::Tools::sendmail. This ensures that both uses have the same
definition of valid email addresses.
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
src/PVE/JSONSchema.pm | 4 ++--
src/PVE/Tools.pm | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 2ceb1bd..b27ffa7 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -7,7 +7,7 @@ use Getopt::Long;
use Encode::Locale;
use Encode;
use Devel::Cycle -quiet; # todo: remove?
-use PVE::Tools qw(split_list $IPV6RE $IPV4RE);
+use PVE::Tools qw(split_list $IPV6RE $IPV4RE $EMAILRE);
use PVE::Exception qw(raise);
use HTTP::Status qw(:constants);
use Net::IP qw(:PROC);
@@ -469,7 +469,7 @@ register_format('email', \&pve_verify_email);
sub pve_verify_email {
my ($email, $noerr) = @_;
- if ($email !~ /^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/) {
+ if ($email !~ /^${EMAILRE}$/) {
return undef if $noerr;
die "value does not look like a valid email address\n";
}
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index f9270d9..e849bdf 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -33,6 +33,7 @@ no warnings 'portable'; # Support for 64-bit ints required
our @EXPORT_OK = qw(
$IPV6RE
$IPV4RE
+$EMAILRE
lock_file
lock_file_full
run_command
@@ -84,6 +85,8 @@ our $IPV6RE = "(?:" .
our $IPRE = "(?:$IPV4RE|$IPV6RE)";
+our $EMAILRE = qr{[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*};
+
use constant {CLONE_NEWNS => 0x00020000,
CLONE_NEWUTS => 0x04000000,
CLONE_NEWIPC => 0x08000000,
--
2.20.1
next prev parent reply other threads:[~2020-09-01 9:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-01 9:18 [pve-devel] [PATCH common 0/2] adapt PVE::Tools::sendmail to match rust-implementation Stoiko Ivanov
2020-09-01 9:18 ` Stoiko Ivanov [this message]
2020-09-01 9:18 ` [pve-devel] [PATCH common 2/2] sendmail-helper: only send multipart if necessary Stoiko Ivanov
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=20200901091804.23647-2-s.ivanov@proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=pve-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.