|
@@ -55,13 +55,12 @@ def get_formatted_email(user): |
|
|
"""get Email Address of user formatted as: `John Doe <johndoe@example.com>`""" |
|
|
"""get Email Address of user formatted as: `John Doe <johndoe@example.com>`""" |
|
|
if user == "Administrator": |
|
|
if user == "Administrator": |
|
|
return user |
|
|
return user |
|
|
from email.utils import formataddr |
|
|
|
|
|
fullname = get_fullname(user) |
|
|
fullname = get_fullname(user) |
|
|
return formataddr((fullname, user)) |
|
|
return formataddr((fullname, user)) |
|
|
|
|
|
|
|
|
def extract_email_id(email): |
|
|
def extract_email_id(email): |
|
|
"""fetch only the email part of the Email Address""" |
|
|
"""fetch only the email part of the Email Address""" |
|
|
full_name, email_id = parse_addr(email) |
|
|
|
|
|
|
|
|
email_id = parse_addr(email)[1] |
|
|
if email_id and isinstance(email_id, basestring) and not isinstance(email_id, unicode): |
|
|
if email_id and isinstance(email_id, basestring) and not isinstance(email_id, unicode): |
|
|
email_id = email_id.decode("utf-8", "ignore") |
|
|
email_id = email_id.decode("utf-8", "ignore") |
|
|
return email_id |
|
|
return email_id |
|
@@ -70,8 +69,6 @@ def validate_email_add(email_str, throw=False): |
|
|
"""Validates the email string""" |
|
|
"""Validates the email string""" |
|
|
email = email_str = (email_str or "").strip() |
|
|
email = email_str = (email_str or "").strip() |
|
|
|
|
|
|
|
|
valid = True |
|
|
|
|
|
|
|
|
|
|
|
def _check(e): |
|
|
def _check(e): |
|
|
_valid = True |
|
|
_valid = True |
|
|
if not e: |
|
|
if not e: |
|
@@ -387,7 +384,6 @@ def is_markdown(text): |
|
|
return not re.search("<p[\s]*>|<br[\s]*>", text) |
|
|
return not re.search("<p[\s]*>|<br[\s]*>", text) |
|
|
|
|
|
|
|
|
def get_sites(sites_path=None): |
|
|
def get_sites(sites_path=None): |
|
|
import os |
|
|
|
|
|
if not sites_path: |
|
|
if not sites_path: |
|
|
sites_path = getattr(frappe.local, 'sites_path', None) or '.' |
|
|
sites_path = getattr(frappe.local, 'sites_path', None) or '.' |
|
|
|
|
|
|
|
@@ -464,30 +460,38 @@ def parse_addr(email_string): |
|
|
""" |
|
|
""" |
|
|
name, email = parseaddr(email_string) |
|
|
name, email = parseaddr(email_string) |
|
|
if check_format(email): |
|
|
if check_format(email): |
|
|
|
|
|
name = get_name_from_email_string(email_string, email, name) |
|
|
return (name, email) |
|
|
return (name, email) |
|
|
else: |
|
|
else: |
|
|
email_regex = re.compile(r"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)") |
|
|
email_regex = re.compile(r"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)") |
|
|
email_list = re.findall(email_regex, email_string) |
|
|
email_list = re.findall(email_regex, email_string) |
|
|
if len(email_list) > 0 and check_format(email_list[0]): |
|
|
if len(email_list) > 0 and check_format(email_list[0]): |
|
|
#take only first email address |
|
|
#take only first email address |
|
|
return (name, email_list[0]) |
|
|
|
|
|
|
|
|
email = email_list[0] |
|
|
|
|
|
name = get_name_from_email_string(email_string, email, name) |
|
|
|
|
|
return (name, email) |
|
|
return (None, email) |
|
|
return (None, email) |
|
|
|
|
|
|
|
|
def check_format(email_id): |
|
|
def check_format(email_id): |
|
|
""" |
|
|
""" |
|
|
Check if email_id is valid. valid email:text@example.com |
|
|
Check if email_id is valid. valid email:text@example.com |
|
|
String check ensures that email_id contains both '.' and |
|
|
|
|
|
'@' and index of '@' is less than '.' |
|
|
|
|
|
|
|
|
String check ensures that email_id contains both '.' and |
|
|
|
|
|
'@' and index of '@' is less than '.' |
|
|
""" |
|
|
""" |
|
|
is_valid = False |
|
|
|
|
|
|
|
|
is_valid = False |
|
|
try: |
|
|
try: |
|
|
pos = email_id.rindex("@") |
|
|
pos = email_id.rindex("@") |
|
|
is_valid = pos > 0 and (email_id.rindex(".") > pos) and (len(email_id) - pos > 4) |
|
|
is_valid = pos > 0 and (email_id.rindex(".") > pos) and (len(email_id) - pos > 4) |
|
|
except Exception, e: |
|
|
|
|
|
|
|
|
except Exception: |
|
|
#print(e) |
|
|
#print(e) |
|
|
pass |
|
|
pass |
|
|
return is_valid |
|
|
return is_valid |
|
|
|
|
|
|
|
|
|
|
|
def get_name_from_email_string(email_string, email_id, name): |
|
|
|
|
|
name = email_string.replace(email_id, '') |
|
|
|
|
|
name = re.sub('[^A-Za-z0-9 ]+', '', name).strip() |
|
|
|
|
|
return name |
|
|
|
|
|
|
|
|
def get_installed_apps_info(): |
|
|
def get_installed_apps_info(): |
|
|
out = [] |
|
|
out = [] |
|
|
for app in frappe.get_installed_apps(): |
|
|
for app in frappe.get_installed_apps(): |
|
|