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

Add check_catchall to functions #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions mailscout/scout.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def generate_email_variants(self, names: List[str], domain: str, normalize: bool
def find_valid_emails(self,
domain: str,
names: Optional[Union[str, List[str], List[List[str]]]] = None,
check_catchall: Optional[bool] = None,
)-> List[str]:
"""
Find valid email addresses for a given domain based on various checks.
Expand All @@ -201,12 +202,13 @@ def find_valid_emails(self,
domain (str): The domain to check email addresses against.
names (Union[str, List[str], List[List[str]]], optional): Names to generate email variants.
Can be a single string, a list of strings, or a list of lists of strings.

check_catchall (bool, optional): Flag to check if the domain is a catch-all. Defaults to True.
Option to disable this check on a function level.
Returns:
List[str]: A list of valid email addresses found.
"""
# Pre-flight checks
if self.check_catchall:
if check_catchall or (check_catchall is None and self.check_catchall):
if self.check_email_catchall(domain):
return []

Expand Down Expand Up @@ -275,13 +277,16 @@ def worker():

def find_valid_emails_bulk(self,
email_data: List[Dict[str, Union[str, List[str]]]],
check_catchall: Optional[bool] = None,
) -> List[Dict[str, Union[str, List[str], List[Dict[str, str]]]]]:
"""
Find valid email addresses in bulk for multiple domains and names.

Args:
email_data (List[Dict[str, Union[str, List[str]]]]): A list of dictionaries,
each containing domain and optional names to check.
check_catchall (bool, optional): Flag to check if the domain is a catch-all. Defaults to True.
Option to disable this check on a function level.

Returns:
List[Dict[str, Union[str, List[str], List[Dict[str, str]]]]]: A list of dictionaries,
Expand All @@ -302,7 +307,7 @@ def worker():
check_prefixes_value = False if names else self.check_prefixes

valid_emails = self.find_valid_emails(
domain, names
domain, names, check_catchall
)
all_valid_emails.append({"domain": domain, "names": names, "valid_emails": valid_emails})
except Exception as e:
Expand Down