From d9b07bf2185f50a8c265c5f94cf3d0382eb65a2a Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:05:42 +0500 Subject: [PATCH 01/10] Update AddressValidator.py Refactored email validation code for clarity and maintainability. Improved function naming and added docstrings for better documentation. Simplified the disposable domain check and enhanced error handling. Ensured consistent variable usage throughout the code. --- Address Validator/AddressValidator.py | 125 +++++++++++++++++++++++--- 1 file changed, 111 insertions(+), 14 deletions(-) diff --git a/Address Validator/AddressValidator.py b/Address Validator/AddressValidator.py index 0dc49be1..65c6de4c 100644 --- a/Address Validator/AddressValidator.py +++ b/Address Validator/AddressValidator.py @@ -1,16 +1,113 @@ -def addressVal(address): - dot = address.find(".") - at = address.find("@") - if (dot == -1): - print("Invalid") - elif (at == -1): - print("Invalid") - else: - print("Valid") +import re +import dns.resolver # Corrected import statement +import idna + +# List of disposable email domains +disposable_domains = [ + "mailinator.com", + "10minutemail.com", + "guerrillamail.com", + "throwawaymail.com", + "getnada.com", + "maildrop.cc", + "temp-mail.com", + "fakemailgenerator.com", + "yopmail.com", + "jetable.com" +] + +# Regular expression for basic email syntax validation +email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' + +def is_valid_email(email): + """ + Validates an email address through multiple checks. + + Args: + email (str): The email address to validate. + + Returns: + bool: True if the email is valid, False otherwise. + """ + # Check if the email contains '@' + if '@' not in email: + return False + + # Split the email into local and domain parts + try: + local_part, domain_part = email.split('@') + except ValueError: + return False + + # Check length constraints for local and domain parts + if len(local_part) > 64 or len(domain_part) > 255 or len(email) > 320: + return False + + # Perform basic syntax validation + if not re.match(email_regex, email): + return False + + # Check if the domain is a disposable email domain + if is_disposable_domain(domain_part): + return False -print("This program will decide if your input is a valid email address") -while(True): - print("A valid email address needs an '@' symbol and a '.'") - x = input("Input your email address:") + # Validate the domain using DNS MX records + if not is_valid_domain(domain_part): + return False - addressVal(x) + # Validate if the domain supports internationalized domain names (IDNs) + if not validate_international_email(domain_part): + return False + + return True + +def is_valid_domain(domain): + """ + Checks if the domain has valid MX records. + + Args: + domain (str): The domain to check. + + Returns: + bool: True if the domain has valid MX records, False otherwise. + """ + try: + mx_records = dns.resolver.resolve(domain, 'MX') + return len(mx_records) > 0 + except Exception: + return False + +def validate_international_email(domain): + """ + Validates that the domain supports internationalized domain names (IDNs). + + Args: + domain (str): The domain to validate. + + Returns: + bool: True if the domain supports IDNs, False otherwise. + """ + try: + idna.encode(domain).decode('utf-8') + return True + except idna.IDNAError: + return False + +def is_disposable_domain(domain): + """ + Checks if the email domain belongs to a disposable domain. + + Args: + domain (str): The domain to check. + + Returns: + bool: True if the domain is disposable, False otherwise. + """ + return domain in disposable_domains + +if __name__ == "__main__": + email_input = input("Enter your email address: ") + if is_valid_email(email_input): + print("The email address is valid.") + else: + print("The email address is invalid.") From a706eddb5c1f24c39ec0ec4c70f3457074563196 Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:08:02 +0500 Subject: [PATCH 02/10] Create requirements.txt --- Address Validator/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Address Validator/requirements.txt diff --git a/Address Validator/requirements.txt b/Address Validator/requirements.txt new file mode 100644 index 00000000..574e874c --- /dev/null +++ b/Address Validator/requirements.txt @@ -0,0 +1,2 @@ +dnspython==2.2.1 +idna==3.4 From c4c29d64b9ea39f6dcaeb8dcd93695769cf677e8 Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:08:33 +0500 Subject: [PATCH 03/10] Update AddressValidator.py --- Address Validator/AddressValidator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Address Validator/AddressValidator.py b/Address Validator/AddressValidator.py index 65c6de4c..8e534358 100644 --- a/Address Validator/AddressValidator.py +++ b/Address Validator/AddressValidator.py @@ -1,5 +1,5 @@ import re -import dns.resolver # Corrected import statement +import dns.resolver import idna # List of disposable email domains From 202af1bdb6f0b3580e3708e3f0f944953ab0aeff Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:18:37 +0500 Subject: [PATCH 04/10] Update README.md --- Address Validator/README.md | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Address Validator/README.md b/Address Validator/README.md index 49dd8006..721b8839 100644 --- a/Address Validator/README.md +++ b/Address Validator/README.md @@ -1,21 +1,32 @@ -![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=style=flat&color=BC4E99) +![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=flat&color=BC4E99) ![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103) # Address Validator +## 🛠️ Description +This program validates email addresses through multiple checks, including syntax validation, disposable domain detection, and DNS MX record verification. It ensures that the email address contains an '@' symbol, checks for proper length constraints, and verifies that the domain is not from a disposable email service. The program also supports internationalized domain names, enhancing its usability for a global audience. -## 🛠️ Description +## ⚙️ Languages and Packages Used + +- **Language**: Python +- **Packages**: + - `dnspython` - For DNS resolution and MX record checks + - `idna` - To handle internationalized domain names + +## 🌟 How to Run -This program checks if your email adress is valid by looking for an '@' symbol and a '.' +Open the `AddressValidator.py` file with a Python IDE and hit run. -## ⚙️ Languages or Frameworks Used -Python +## 📦 Requirements -## 🌟 How to run -Open the file AddressValidator.py file with the python IDE and hit run. +To install the necessary dependencies, use the following command: +```bash +pip install -r requirements.txt +``` +## 🤖 Authors -## 🤖 Author -tommcgurn10 +- **m-hassanqureshi** - Primary author of the renewed code +- **tommcgurn10** - Original author of the initial project From 290b31f000b5ac91bdd7e7e35bfb109def0ff0e0 Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:26:22 +0500 Subject: [PATCH 05/10] Update AddressValidator.py --- Address Validator/AddressValidator.py | 30 --------------------------- 1 file changed, 30 deletions(-) diff --git a/Address Validator/AddressValidator.py b/Address Validator/AddressValidator.py index 8e534358..9d0b8b3e 100644 --- a/Address Validator/AddressValidator.py +++ b/Address Validator/AddressValidator.py @@ -2,20 +2,6 @@ import dns.resolver import idna -# List of disposable email domains -disposable_domains = [ - "mailinator.com", - "10minutemail.com", - "guerrillamail.com", - "throwawaymail.com", - "getnada.com", - "maildrop.cc", - "temp-mail.com", - "fakemailgenerator.com", - "yopmail.com", - "jetable.com" -] - # Regular expression for basic email syntax validation email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' @@ -47,10 +33,6 @@ def is_valid_email(email): if not re.match(email_regex, email): return False - # Check if the domain is a disposable email domain - if is_disposable_domain(domain_part): - return False - # Validate the domain using DNS MX records if not is_valid_domain(domain_part): return False @@ -93,18 +75,6 @@ def validate_international_email(domain): except idna.IDNAError: return False -def is_disposable_domain(domain): - """ - Checks if the email domain belongs to a disposable domain. - - Args: - domain (str): The domain to check. - - Returns: - bool: True if the domain is disposable, False otherwise. - """ - return domain in disposable_domains - if __name__ == "__main__": email_input = input("Enter your email address: ") if is_valid_email(email_input): From d66df6cbad78e2defb65dc17dcb0f159d4e0b927 Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:27:19 +0500 Subject: [PATCH 06/10] Update README.md --- Address Validator/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Address Validator/README.md b/Address Validator/README.md index 721b8839..b7bf71c0 100644 --- a/Address Validator/README.md +++ b/Address Validator/README.md @@ -6,7 +6,7 @@ ## 🛠️ Description -This program validates email addresses through multiple checks, including syntax validation, disposable domain detection, and DNS MX record verification. It ensures that the email address contains an '@' symbol, checks for proper length constraints, and verifies that the domain is not from a disposable email service. The program also supports internationalized domain names, enhancing its usability for a global audience. +This program validates email addresses through multiple checks, including syntax validation, and DNS MX record verification. It ensures that the email address contains an '@' symbol, checks for proper length constraints, and verifies that the domain is not unauthorized email service. The program also supports internationalized domain names, enhancing its usability for a global audience. ## ⚙️ Languages and Packages Used From beafc4b1bc8bc3d43885da17ac0f646ffdf92047 Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 19:34:29 +0500 Subject: [PATCH 07/10] Update README.md --- Address Validator/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/Address Validator/README.md b/Address Validator/README.md index b7bf71c0..9558b231 100644 --- a/Address Validator/README.md +++ b/Address Validator/README.md @@ -19,8 +19,6 @@ This program validates email addresses through multiple checks, including syntax Open the `AddressValidator.py` file with a Python IDE and hit run. -## 📦 Requirements - To install the necessary dependencies, use the following command: ```bash From 60f2f694a445dc48cb4a631e836e23a32809c755 Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 19:38:39 +0500 Subject: [PATCH 08/10] Delete Address Validator/requirements.txt I will add these requirements in repo requirements.txt --- Address Validator/requirements.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Address Validator/requirements.txt diff --git a/Address Validator/requirements.txt b/Address Validator/requirements.txt deleted file mode 100644 index 574e874c..00000000 --- a/Address Validator/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -dnspython==2.2.1 -idna==3.4 From d7aa4c21338fdbb06636c0840630da124f868abe Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 19:39:22 +0500 Subject: [PATCH 09/10] Update README.md --- Address Validator/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Address Validator/README.md b/Address Validator/README.md index 9558b231..9661ae69 100644 --- a/Address Validator/README.md +++ b/Address Validator/README.md @@ -19,11 +19,6 @@ This program validates email addresses through multiple checks, including syntax Open the `AddressValidator.py` file with a Python IDE and hit run. -To install the necessary dependencies, use the following command: - -```bash -pip install -r requirements.txt -``` ## 🤖 Authors - **m-hassanqureshi** - Primary author of the renewed code From 9472885f459923ccc4860285a9ff34fa3b35e960 Mon Sep 17 00:00:00 2001 From: Hassan Qureshi <140505321+m-hassanqureshi@users.noreply.github.com> Date: Sat, 18 Jan 2025 19:45:04 +0500 Subject: [PATCH 10/10] Added Requirements requirements.txt --- requirements.txt | Bin 1826 -> 1023 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9539deb476191e9ff68a4453b08cc212aba32b72..6bed75d145f419393424d8d070e7e5e9ded4bedb 100644 GIT binary patch literal 1023 zcmaiyy-ve06h`+*eTS$!RvZV);*JbROb9VMiQAeucCcfl=G7Q@BwhjMIxSR4x2tu| z{d|AEKfh`z!l-sZdmDy|^NP@tl&kE;%e=9DFHD=S2Q}o%_)%z`*S^ZF%P*cTYOGh; zDyy|JophX2vLOXlE`cC5(#5YR&dZ`?gi=B`h`G?oJP7CIcw?;Vg;vv?%m_mpY5qB> zlvYj0`8|n0$I@pk307Mtdck=?DsqQ83klkT7Cz=MQlRqz38%J)gK!4M`hkbIj7-b;y`&4t_#Dn*vXW~kU{*ipbp14zA1V%4uc}z0)ph^ zdysyF?pPEN?Sz6i-?>-v1HO5SSZ5Hl;IvjXOTA%X3kcGybloJwKCKz+>_mdr8b2Jz WgEiZ@Is81%D2Vg=w^vWcc%Ng11@B8FxZ#oD93diJBb?#{k9?maK*q1$d88;Y<@1RDD0l|E zmi(sXn>mjF6Fw!pFHrHi|Ev9Vj2v0?2^FRP#u_SDU&zX?c#h50^%XrSbA%?9!jU2} zBE&8aQA2WVi43*-%onCsxrA$+(Wf#~#;WnV^Q; ztJWth=ulo$=T@9CIqJPjGiRvjX}4sh%((HR9L2Ksk5}`Af)i1aAs^DWdT4d}$~7yW zQoF>n>j%y1%8@jq>Pu@^6r9;z+Ma&rX782ssPlFVv9IST_tdYrI@*IC_Z==74<*pE@#?Gy!94uh_<=fR`tAgKVNb6a(r&w wDa{L`v;T^ow&vPt-!HgV$DOw(OPjNyq9;AkiTXtAwdORm({{|7ZEKG32dDTW