myl-discovery 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

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
@@ -697,12 +697,13 @@ Email autoconfig library
697
697
  pip install myl-discovery
698
698
  ```
699
699
 
700
- ## Usage:
700
+ ## Usage
701
701
 
702
702
  ```python
703
703
  from myldiscovery import autodiscover
704
704
  autodiscover("me@example.com")
705
- # {'server': 'mail.example.com', 'port': 143, 'starttls': True}
705
+ # {'imap': {'server': 'mail.example.com', 'port': 993, 'starttls': False},
706
+ # 'smtp': {'server': 'mail.example.com', 'port': 587, 'starttls': False}}
706
707
  ```
707
708
 
708
709
 
@@ -0,0 +1,6 @@
1
+ myldiscovery/__init__.py,sha256=pGTsuY2G9_Az6DKftLsQM9vBbcNIAy8q2vPRh3486XA,2950
2
+ myl_discovery-0.2.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
3
+ myl_discovery-0.2.0.dist-info/METADATA,sha256=rEmMa99hvijh3l8VCmvDui8DyugVVIAu4c1IL49q9nA,41297
4
+ myl_discovery-0.2.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
5
+ myl_discovery-0.2.0.dist-info/top_level.txt,sha256=v_h72JexaacqBNY6iOMD9PpGg8lnGoL-pkmUIzxdiVU,13
6
+ myl_discovery-0.2.0.dist-info/RECORD,,
myldiscovery/__init__.py CHANGED
@@ -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
  }
@@ -1,6 +0,0 @@
1
- myldiscovery/__init__.py,sha256=xalUlWBnrOfGhkQL6ipCF2qJrTPF1yjkKpD4pibkMrk,2149
2
- myl_discovery-0.1.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
3
- myl_discovery-0.1.0.dist-info/METADATA,sha256=8U3XgyA-Mudg3Y3lxnlh1JkdbB3MKEi3IEzNzWT1-lA,41212
4
- myl_discovery-0.1.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
5
- myl_discovery-0.1.0.dist-info/top_level.txt,sha256=v_h72JexaacqBNY6iOMD9PpGg8lnGoL-pkmUIzxdiVU,13
6
- myl_discovery-0.1.0.dist-info/RECORD,,