mooli tayer has uploaded a new change for review.

Change subject: core: replace regexp validation for user email.
......................................................................

core: replace regexp validation for user email.

validating using an ad-hock regexp may cause problems(see bug).
using strinct java.mail.internetAddress() [1] for validation.
This enforces some (but not all) RFC822 syntax.

Using the strict form does not allow simple (user )names but
requires a domain although user@localhost is now accepted.

[1] https://javamail.java.net/nonav/docs/api/

Change-Id: I18904a669453baef632af1cd427b61852e7ab583
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1109169
Signed-off-by: Mooli Tayer <[email protected]>
---
M backend/manager/modules/bll/pom.xml
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
2 files changed, 14 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/42/28742/1

diff --git a/backend/manager/modules/bll/pom.xml 
b/backend/manager/modules/bll/pom.xml
index 0e1d7c9..c227d31 100644
--- a/backend/manager/modules/bll/pom.xml
+++ b/backend/manager/modules/bll/pom.xml
@@ -124,6 +124,11 @@
     </dependency>
 
     <dependency>
+      <groupId>javax.mail</groupId>
+      <artifactId>mail</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>javassist</groupId>
       <artifactId>javassist</artifactId>
       <scope>test</scope>
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
index bf7b424..09a69a5 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
@@ -18,6 +18,9 @@
 import org.ovirt.engine.core.compat.Regex;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+
 public abstract class EventSubscriptionCommandBase<T extends 
EventSubscriptionParametesBase> extends
         CommandBase<T> {
     protected EventSubscriptionCommandBase(T parameters) {
@@ -147,9 +150,12 @@
      *         otherwise, <c>false</c>.
      */
     protected static boolean ValidatMailAddress(String inputEmail) {
-        final String strRegex = 
"^[\\w-]+(?:\\.[\\w-]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7}$";
-        Regex re = new Regex(strRegex);
-        return re.IsMatch(inputEmail);
+        try {
+            new InternetAddress(inputEmail, true);
+        } catch (AddressException e) {
+            return false;
+        }
+        return true;
     }
 
     private static boolean ValidateSubscription(Iterable<event_subscriber> 
subscriptions, event_subscriber current) {


-- 
To view, visit http://gerrit.ovirt.org/28742
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I18904a669453baef632af1cd427b61852e7ab583
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: mooli tayer <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to