Exemple #1
0
 def __is_valid_recipients(self):
     """
     :return: True if all recipient email addresses are syntactically correct
             False, otherwise
     """
     for recipient in self.__recipients:
         if not EmailValidator.is_syntax_valid(recipient.email):
             return False
     for recipient in self.__cc:
         if not EmailValidator.is_syntax_valid(recipient.email):
             return False
     for recipient in self.__bcc:
         if not EmailValidator.is_syntax_valid(recipient.email):
             return False
     return True
Exemple #2
0
 def __is_valid_recipients(self):
     """
     :return: True if all recipient email addresses are syntactically correct
             False, otherwise
     """
     for recipient in self.__recipients:
         if not EmailValidator.is_syntax_valid(recipient.email):
             return False
     for recipient in self.__cc:
         if not EmailValidator.is_syntax_valid(recipient.email):
             return False
     for recipient in self.__bcc:
         if not EmailValidator.is_syntax_valid(recipient.email):
             return False
     return True
Exemple #3
0
def validate_email():
    """
        :param email: string the address to be validates
        :return: response: EmailValidatorResponse success status and message
        Read more at
        https://github.com/mariodmtrv/RobustMail/wiki#check-an-email
    """
    email = request.get_json()["email"].strip()
    if not EmailValidator.is_syntax_valid(email):
        response = EmailValidatorResponse(False, "Address syntax invalid")
    elif not EmailValidator.is_mx_valid(email):
        response = EmailValidatorResponse(False, "Address domain not found")
    else:
        response = EmailValidatorResponse(True, "Syntax and domain accepted")
        # address existence validation was excluded because of performance and reliability issues
    return response.to_JSON()
Exemple #4
0
def validate_email():
    """
        :param email: string the address to be validates
        :return: response: EmailValidatorResponse success status and message
        Read more at
        https://github.com/mariodmtrv/RobustMail/wiki#check-an-email
    """
    email = request.get_json()["email"].strip()
    if not EmailValidator.is_syntax_valid(email):
        response = EmailValidatorResponse(False, "Address syntax invalid")
    elif not EmailValidator.is_mx_valid(email):
        response = EmailValidatorResponse(False, "Address domain not found")
    else:
        response = EmailValidatorResponse(True, "Syntax and domain accepted")
        # address existence validation was excluded because of performance and reliability issues
    return response.to_JSON()
Exemple #5
0
    def validate(self):
        """
        Validates a message for syntactic correctness
        :return: A tuple with boolean validation value and validation text result
                 If a validation failed the first failed check will be returned
        """
        if len(self.__recipients) == 0:
            return (False, "No recipients added")
        if self.text == "" and self.body == "":
            return (False, "Text or body is required")

        if not EmailValidator.is_syntax_valid(self.__sender.email):
            return (False, "Sender email invalid")
        if not self.__is_valid_recipients():
            return (False, "One or more recipient addresses incorrect")
        if self.subject == "":
            return (True, "Adding a subject is recommended")
        return (True, "Success")
Exemple #6
0
    def validate(self):
        """
        Validates a message for syntactic correctness
        :return: A tuple with boolean validation value and validation text result
                 If a validation failed the first failed check will be returned
        """
        if len(self.__recipients) == 0:
            return (False, "No recipients added")
        if self.text == "" and self.body == "":
            return (False, "Text or body is required")

        if not EmailValidator.is_syntax_valid(self.__sender.email):
            return (False, "Sender email invalid")
        if not self.__is_valid_recipients():
            return (False, "One or more recipient addresses incorrect")
        if self.subject == "":
            return (True, "Adding a subject is recommended")
        return (True, "Success")