moto/moto/ses/utils.py

28 lines
619 B
Python
Raw Normal View History

2013-02-24 23:30:51 -05:00
import random
import string
from email.utils import parseaddr
2013-02-24 23:30:51 -05:00
def random_hex(length):
2019-10-31 08:44:26 -07:00
return "".join(random.choice(string.ascii_lowercase) for x in range(length))
2013-02-24 23:30:51 -05:00
def get_random_message_id():
2013-10-03 20:34:13 -04:00
return "{0}-{1}-{2}-{3}-{4}-{5}-{6}".format(
2019-10-31 08:44:26 -07:00
random_hex(16),
random_hex(8),
random_hex(4),
random_hex(4),
random_hex(4),
random_hex(12),
random_hex(6),
2013-02-26 00:31:01 -05:00
)
def is_valid_address(addr):
_, address = parseaddr(addr)
address = address.split("@")
if len(address) != 2 or not address[1]:
return False, "Missing domain"
return True, None