Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use email_validator in SignalEngagement flow instead of regular expression #3286

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/dispatch/signal/flows.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import re

from email_validator import validate_email, EmailNotValidError
from sqlalchemy.orm import Session

from dispatch.auth.models import DispatchUser, UserRegister
Expand Down Expand Up @@ -131,9 +131,12 @@ def engage_signal_identity(db_session: Session, signal_instance: SignalInstance)
for engagement in engagements:
for entity in signal_instance.entities:
if engagement.entity_type_id == entity.entity_type_id:
if not re.fullmatch(r"[^@]+@[^@]+\.[^@]+", entity.value):
try:
email = validate_email(entity.value, check_deliverability=False)
email = email.normalized
except EmailNotValidError as e:
log.warning(
f"Discovered entity value in Signal {signal_instance.signal.id} that did not appear to be a valid email"
f"Discovered entity value in Signal {signal_instance.signal.id} that did not appear to be a valid email: {e}"
)
else:
users_to_engage.append(
Expand Down