2021-01-02 19:28:03 +01:00
|
|
|
from typing import Dict
|
|
|
|
|
2020-05-17 16:42:44 +02:00
|
|
|
from urllib3.util import parse_url
|
|
|
|
|
2021-01-20 16:32:00 +01:00
|
|
|
from .exceptions import InvalidEmailUrlScheme
|
2020-05-17 16:42:44 +02:00
|
|
|
|
|
|
|
|
2021-01-02 19:28:03 +01:00
|
|
|
def parse_email_url(email_url: str) -> Dict:
|
2020-05-17 16:42:44 +02:00
|
|
|
parsed_url = parse_url(email_url)
|
|
|
|
if parsed_url.scheme != 'smtp':
|
|
|
|
raise InvalidEmailUrlScheme()
|
2022-01-01 11:04:08 +01:00
|
|
|
credentials = (
|
|
|
|
parsed_url.auth.split(':') if parsed_url.auth else [None, None]
|
|
|
|
)
|
2020-05-17 16:42:44 +02:00
|
|
|
return {
|
|
|
|
'host': parsed_url.host,
|
2022-01-01 11:27:16 +01:00
|
|
|
'port': 25 if parsed_url.port is None else parsed_url.port,
|
2020-05-17 16:42:44 +02:00
|
|
|
'use_tls': True if parsed_url.query == 'tls=True' else False,
|
|
|
|
'use_ssl': True if parsed_url.query == 'ssl=True' else False,
|
|
|
|
'username': credentials[0],
|
|
|
|
'password': credentials[1],
|
|
|
|
}
|