myl-discovery 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: myl-discovery
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: email autodiscovery
5
5
  Author-email: Philipp Schmitt <philipp@schmitt.co>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -694,12 +694,13 @@ Email autoconfig library
694
694
  pip install myl-discovery
695
695
  ```
696
696
 
697
- ## Usage:
697
+ ## Usage
698
698
 
699
699
  ```python
700
700
  from myldiscovery import autodiscover
701
701
  autodiscover("me@example.com")
702
- # {'server': 'mail.example.com', 'port': 143, 'starttls': True}
702
+ # {'imap': {'server': 'mail.example.com', 'port': 993, 'starttls': False},
703
+ # 'smtp': {'server': 'mail.example.com', 'port': 587, 'starttls': False}}
703
704
  ```
704
705
 
705
706
 
@@ -8,12 +8,13 @@ Email autoconfig library
8
8
  pip install myl-discovery
9
9
  ```
10
10
 
11
- ## Usage:
11
+ ## Usage
12
12
 
13
13
  ```python
14
14
  from myldiscovery import autodiscover
15
15
  autodiscover("me@example.com")
16
- # {'server': 'mail.example.com', 'port': 143, 'starttls': True}
16
+ # {'imap': {'server': 'mail.example.com', 'port': 993, 'starttls': False},
17
+ # 'smtp': {'server': 'mail.example.com', 'port': 587, 'starttls': False}}
17
18
  ```
18
19
 
19
20
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: myl-discovery
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: email autodiscovery
5
5
  Author-email: Philipp Schmitt <philipp@schmitt.co>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -694,12 +694,13 @@ Email autoconfig library
694
694
  pip install myl-discovery
695
695
  ```
696
696
 
697
- ## Usage:
697
+ ## Usage
698
698
 
699
699
  ```python
700
700
  from myldiscovery import autodiscover
701
701
  autodiscover("me@example.com")
702
- # {'server': 'mail.example.com', 'port': 143, 'starttls': True}
702
+ # {'imap': {'server': 'mail.example.com', 'port': 993, 'starttls': False},
703
+ # 'smtp': {'server': 'mail.example.com', 'port': 587, 'starttls': False}}
703
704
  ```
704
705
 
705
706
 
@@ -44,21 +44,36 @@ def autodiscover_txt(domain):
44
44
  return res.split("=")[1]
45
45
 
46
46
 
47
- def autodiscover(email_addr):
47
+ def autodiscover(email_addr, srv_only=False):
48
48
  domain = email_addr.split("@")[-1]
49
49
  if not domain:
50
50
  raise ValueError(f"Invalid email address {email_addr}")
51
51
 
52
- autoconfig = autodiscover_txt(domain)
52
+ autoconfig = autodiscover_txt(domain) if not srv_only else None
53
53
 
54
54
  if not autoconfig:
55
- srv = resolve_srv(f"_imaps._tcp.{domain}")
55
+ imap = resolve_srv(f"_imaps._tcp.{domain}")
56
+ smtp = resolve_srv(f"_submission._tcp.{domain}")
57
+
56
58
  return {
57
- "server": srv[0].get("hostname"),
58
- "port": int(srv[0].get("port")),
59
- # FIXME We might want to "smartly" guess if starttls should be
60
- # enabled or not, depending on the port (143 -> starttls, 993 -> no)
61
- "starttls": False,
59
+ "imap": {
60
+ "server": imap[0].get("hostname"),
61
+ "port": int(imap[0].get("port")),
62
+ # FIXME We might want to "smartly" guess if starttls should be
63
+ # enabled or not, depending on the port:
64
+ # 143 -> starttls
65
+ # 993 -> no
66
+ "starttls": False,
67
+ },
68
+ "smtp": {
69
+ "server": smtp[0].get("hostname"),
70
+ "port": int(smtp[0].get("port")),
71
+ # FIXME We might want to "smartly" guess if starttls should be
72
+ # enabled or not, depending on the port:
73
+ # 465 -> starttls
74
+ # 587 -> no
75
+ "starttls": False,
76
+ }
62
77
  }
63
78
 
64
79
  res = requests.get(autoconfig)
@@ -70,16 +85,24 @@ def autodiscover(email_addr):
70
85
  .get("emailProvider", {})
71
86
  .get("incomingServer")
72
87
  )
73
- # smtp = (
74
- # data.get("clientConfig", {})
75
- # .get("emailProvider", {})
76
- # .get("outgoingServer")
77
- # )
88
+ smtp = (
89
+ data.get("clientConfig", {})
90
+ .get("emailProvider", {})
91
+ .get("outgoingServer")
92
+ )
78
93
 
79
94
  assert imap is not None
95
+ assert smtp is not None
80
96
 
81
97
  return {
82
- "server": imap.get("hostname"),
83
- "port": int(imap.get("port")),
84
- "starttls": imap.get("socketType") == "STARTTLS",
98
+ "imap": {
99
+ "server": imap.get("hostname"),
100
+ "port": int(imap.get("port")),
101
+ "starttls": imap.get("socketType") == "STARTTLS",
102
+ },
103
+ "smtp": {
104
+ "server": smtp.get("hostname"),
105
+ "port": int(smtp.get("port")),
106
+ "starttls": smtp.get("socketType") == "STARTTLS",
107
+ },
85
108
  }
@@ -20,7 +20,7 @@ dependencies = [
20
20
  "requests",
21
21
  "xmltodict"
22
22
  ]
23
- version = "0.1.0"
23
+ version = "0.2.0"
24
24
 
25
25
  [tool.black]
26
26
  line-length = 79
File without changes
File without changes
File without changes