Skip to content

adding missing requirement #417

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

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.12.3
current_version = 0.12.4
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<release>[a-z]+)(?P<num>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion coverage.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<coverage version="7.5.1" timestamp="1715882846152" lines-valid="674" lines-covered="674" line-rate="1" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
<coverage version="7.5.1" timestamp="1715884369689" lines-valid="674" lines-covered="674" line-rate="1" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.5.1 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
Expand Down
99 changes: 99 additions & 0 deletions docs/recipes/emailValidation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Validating Email Addresses
Example of how to use in a script

```python

from dsg_lib.common_functions.email_validation import validate_email_address

import pprint
import time


if __name__ == "__main__":

# create a list of email addresses to check if valid
email_addresses = [
"bob@devsetgo.com",
"bob@devset.go",
"foo@yahoo.com",
"bob@gmail.com",
"very fake@devsetgo.com",
"jane.doe@example.com",
"john_doe@example.co.uk",
"user.name+tag+sorting@example.com",
"x@example.com", # shortest possible email address
"example-indeed@strange-example.com",
"admin@mailserver1", # local domain name with no TLD
"example@s.example", # see the list of Internet top-level domains
'" "@example.org', # space between the quotes
'"john..doe"@example.org', # quoted double dot
"mailhost!username@example.org", # bangified host route used for uucp mailers
"user%example.com@example.org", # percent sign in local part
"user-@example.org", # valid due to the last character being an allowed character
# Invalid email addresses
"Abc.example.com", # no @ character
"A@b@c@example.com", # only one @ is allowed outside quotation marks
'a"b(c)d,e:f;g<h>i[j\\k]l@example.com', # none of the special characters in this local part are allowed outside quotation marks
'just"not"right@example.com', # quoted strings must be dot separated or the only element making up the local-part
'this is"not\\allowed@example.com', # spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a backslash
'this\\ still\\"not\\\\allowed@example.com', # even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes
"1234567890123456789012345678901234567890123456789012345678901234+x@example.com", # local part is longer than 64 characters

# Emails with empty local part
"@example.com", # only valid if allow_empty_local is True

# Emails with non-ASCII characters
"üñîçøðé@example.com", # only valid if allow_smtputf8 is True
"user@üñîçøðé.com", # only valid if allow_smtputf8 is True

# Emails with quoted local part
'"john.doe"@example.com', # only valid if allow_quoted_local is True
'"john..doe"@example.com', # only valid if allow_quoted_local is True

# Emails with display name
'John Doe <john@example.com>', # only valid if allow_display_name is True

# Emails with domain literal
'user@[192.0.2.1]', # only valid if allow_domain_literal is True

# Emails with long local part
"a"*65 + "@example.com", # local part is longer than 64 characters

# Emails with invalid characters
"john doe@example.com", # space is not allowed
"john@doe@example.com", # only one @ is allowed
"john.doe@.com", # domain can't start with a dot
"john.doe@example..com", # domain can't have two consecutive dots
"test@google.com",
]

# create a list of configurations
configurations = [
{"check_deliverability": True, "test_environment": False, "allow_smtputf8": False, "allow_empty_local": False, "allow_quoted_local": False, "allow_display_name": False, "allow_domain_literal": False, "globally_deliverable": None, "timeout": 10, "dns_type": 'timeout'},
{"check_deliverability": False, "test_environment": True, "allow_smtputf8": True, "allow_empty_local": True, "allow_quoted_local": True, "allow_display_name": True, "allow_domain_literal": True, "globally_deliverable": None, "timeout": 5, "dns_type": 'dns'},
{"check_deliverability": True},
{"check_deliverability": False, "test_environment": False, "allow_smtputf8": True, "allow_empty_local": False, "allow_quoted_local": True, "allow_display_name": False, "allow_domain_literal": True, "globally_deliverable": None, "timeout": 15, "dns_type": 'timeout'},
{"check_deliverability": True, "test_environment": True, "allow_smtputf8": False, "allow_empty_local": True, "allow_quoted_local": False, "allow_display_name": True, "allow_domain_literal": False, "globally_deliverable": None, "timeout": 20, "dns_type": 'dns'},
{"check_deliverability": False, "test_environment": False, "allow_smtputf8": True, "allow_empty_local": True, "allow_quoted_local": True, "allow_display_name": True, "allow_domain_literal": True, "globally_deliverable": None, "timeout": 25, "dns_type": 'timeout'},
{"check_deliverability": True, "test_environment": True, "allow_smtputf8": False, "allow_empty_local": False, "allow_quoted_local": False, "allow_display_name": False, "allow_domain_literal": False, "globally_deliverable": None, "timeout": 30, "dns_type": 'dns'},
{"check_deliverability": False, "test_environment": True, "allow_smtputf8": True, "allow_empty_local": False, "allow_quoted_local": True, "allow_display_name": True, "allow_domain_literal": False, "globally_deliverable": None, "timeout": 35, "dns_type": 'timeout'},
{"check_deliverability": True, "test_environment": False, "allow_smtputf8": False, "allow_empty_local": True, "allow_quoted_local": True, "allow_display_name": False, "allow_domain_literal": True, "globally_deliverable": None, "timeout": 40, "dns_type": 'dns'},
{"check_deliverability": False, "test_environment": True, "allow_smtputf8": True, "allow_empty_local": False, "allow_quoted_local": False, "allow_display_name": True, "allow_domain_literal": True, "globally_deliverable": None, "timeout": 45, "dns_type": 'timeout'},
]

t0 = time.time()
validity=[]

for email in email_addresses:
for config in configurations:

res = validate_email_address(email, **config)
validity.append(res)
t1 = time.time()
validity = sorted(validity, key=lambda x: x['email'])

for v in validity:
pprint.pprint(v, indent=4)

print(f"Time taken: {t1 - t0:.2f}")
```
2 changes: 1 addition & 1 deletion dsg_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = '0.12.3'
__version__ = '0.12.4'
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ nav:
- Async Database: 'recipes/asyncDatabase.md'
- Logging: 'recipes/loggingExample.md'
- Patterns: 'recipes/patterns.md'
- EmailValidation: 'recipes/emailValidation.md'
- About:
- Contributing: 'contribute.md'
- Release Notes: release-notes.md
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "hatchling.build"

[project]
name = "devsetgo_lib"
version = "0.12.3"
version = "0.12.4"
requires-python = ">=3.9"
description = "DevSetGo Common Library provides reusable Python functions for enhanced code efficiency. It includes utilities for file operations, calendar, pattern matching, logging, FastAPI endpoints, and async database handling with CRUD operations."
readme = "README.md"
Expand All @@ -34,6 +34,7 @@ classifiers = [
dependencies = [
"loguru>=0.7.0",
"packaging>=20.0",
"email-validator>=2.1.1"
]
# loguru = ">=0.7.0"
# packaging = ">=20.0"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ loguru==0.7.2 # Vulnerabilities: None
mkdocs-material==9.5.23 # From 9.5.18 | Vulnerabilities: None
mkdocs-print-site-plugin==2.4.1 # From 2.4.0 | Vulnerabilities: None
mkdocstrings[python,shell]==0.25.1 # From 0.24.3 | Vulnerabilities: None

packaging==24.0 # Vulnerabilities: None
pre-commit==3.7.1 # From 3.7.0 | Vulnerabilities: None
psycopg2==2.9.9 # Vulnerabilities: None
Expand Down