mailcycle 0.3.0__tar.gz → 0.4.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.
- {mailcycle-0.3.0 → mailcycle-0.4.0}/PKG-INFO +2 -2
- {mailcycle-0.3.0 → mailcycle-0.4.0}/README.md +1 -1
- {mailcycle-0.3.0 → mailcycle-0.4.0}/pyproject.toml +1 -1
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/__init__.py +3 -1
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/client.py +55 -8
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/crypto/authproof.py +2 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/models.py +1 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/tests/test_client.py +75 -1
- {mailcycle-0.3.0 → mailcycle-0.4.0}/.gitignore +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/LICENSE +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/live/README.md +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/_encoding.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/crypto/__init__.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/crypto/asymmetric.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/crypto/cipher.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/crypto/identity.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/crypto/mnemonic.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/crypto/primitives.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/crypto/sealedbox.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/crypto/wordlist.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/errors.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/events.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/http.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/keys.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/mail.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/pairing.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/py.typed +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/trackers.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/src/mailcycle/webhooks.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/tests/conftest.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/tests/test_cross_implementation.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/tests/test_events.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/tests/test_pairing.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/tests/test_pairing_reference.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/tests/test_trackers.py +0 -0
- {mailcycle-0.3.0 → mailcycle-0.4.0}/tests/test_vectors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: mailcycle
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Python client for the Mailcycle API. Create addresses that receive mail, read and decrypt it on your machine, send, and listen for events.
|
|
5
5
|
Project-URL: Homepage, https://mailcycle.email/
|
|
6
6
|
Project-URL: Documentation, https://docs.mailcycle.email/
|
|
@@ -238,7 +238,7 @@ mc.sessions.revoke_others() # everywhere but here
|
|
|
238
238
|
mc.delete_account()
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
-
This erases the account and everything in it at once, with no undo. Its addresses are never issued again. Session only.
|
|
241
|
+
This erases the account and everything in it at once, with no undo. Its addresses are never issued again. Session only. It confirms with the phrase by answering a fresh challenge.
|
|
242
242
|
|
|
243
243
|
`mc.subscription()` returns the plan, its status and renewal date, and the account balance. `mc.plans()` lists every plan.
|
|
244
244
|
|
|
@@ -176,7 +176,7 @@ mc.sessions.revoke_others() # everywhere but here
|
|
|
176
176
|
mc.delete_account()
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
This erases the account and everything in it at once, with no undo. Its addresses are never issued again. Session only.
|
|
179
|
+
This erases the account and everything in it at once, with no undo. Its addresses are never issued again. Session only. It confirms with the phrase by answering a fresh challenge.
|
|
180
180
|
|
|
181
181
|
`mc.subscription()` returns the plan, its status and renewal date, and the account balance. `mc.plans()` lists every plan.
|
|
182
182
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mailcycle"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "Python client for the Mailcycle API. Create addresses that receive mail, read and decrypt it on your machine, send, and listen for events."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -46,6 +46,7 @@ from .models import (
|
|
|
46
46
|
Domain,
|
|
47
47
|
Message,
|
|
48
48
|
MessagePage,
|
|
49
|
+
NameStyle,
|
|
49
50
|
OutgoingAttachment,
|
|
50
51
|
Plan,
|
|
51
52
|
SendResult,
|
|
@@ -59,7 +60,7 @@ from .models import (
|
|
|
59
60
|
from .trackers import BlockedTracker, strip_remote_content, summarize_blocked
|
|
60
61
|
from .webhooks import verify_webhook_signature, webhook_signature_header
|
|
61
62
|
|
|
62
|
-
__version__ = "0.
|
|
63
|
+
__version__ = "0.4.0"
|
|
63
64
|
|
|
64
65
|
__all__ = [
|
|
65
66
|
"Mailcycle",
|
|
@@ -80,6 +81,7 @@ __all__ = [
|
|
|
80
81
|
"Domain",
|
|
81
82
|
"Message",
|
|
82
83
|
"MessagePage",
|
|
84
|
+
"NameStyle",
|
|
83
85
|
"OutgoingAttachment",
|
|
84
86
|
"Plan",
|
|
85
87
|
"SendResult",
|
|
@@ -13,6 +13,7 @@ this machine holds the matching private one.
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
15
|
import base64
|
|
16
|
+
import builtins
|
|
16
17
|
import secrets
|
|
17
18
|
import time
|
|
18
19
|
from collections.abc import Callable, Iterator, Sequence
|
|
@@ -22,7 +23,7 @@ from typing import Any
|
|
|
22
23
|
import httpx
|
|
23
24
|
|
|
24
25
|
from ._encoding import to_b64u
|
|
25
|
-
from .crypto.authproof import prove_account
|
|
26
|
+
from .crypto.authproof import DELETE_DOMAIN, prove_account
|
|
26
27
|
from .crypto.cipher import is_sealed_box, open_json, seal_json
|
|
27
28
|
from .crypto.mnemonic import generate_phrase
|
|
28
29
|
from .errors import APIError, DecryptionError, MailcycleError
|
|
@@ -44,6 +45,7 @@ from .models import (
|
|
|
44
45
|
Domain,
|
|
45
46
|
Message,
|
|
46
47
|
MessagePage,
|
|
48
|
+
NameStyle,
|
|
47
49
|
OutgoingAttachment,
|
|
48
50
|
Plan,
|
|
49
51
|
SendResult,
|
|
@@ -68,6 +70,9 @@ _CLOCK_SKEW_SECONDS = 5.0
|
|
|
68
70
|
_MAX_ATTACHMENTS = 10
|
|
69
71
|
_MAX_ATTACHMENT_BYTES = int(3.5 * 1024 * 1024)
|
|
70
72
|
|
|
73
|
+
#: The styles the API rolls address names in.
|
|
74
|
+
_NAME_STYLES = ("person", "business", "team", "neutral")
|
|
75
|
+
|
|
71
76
|
|
|
72
77
|
class _Unset:
|
|
73
78
|
"""Distinguishes "leave the label alone" from "clear it"."""
|
|
@@ -96,6 +101,11 @@ def _attachments_body(attachments: Sequence[OutgoingAttachment]) -> list[dict[st
|
|
|
96
101
|
return body
|
|
97
102
|
|
|
98
103
|
|
|
104
|
+
def _check_style(style: str) -> None:
|
|
105
|
+
if style not in _NAME_STYLES:
|
|
106
|
+
raise MailcycleError(f"style must be one of {', '.join(_NAME_STYLES)}.")
|
|
107
|
+
|
|
108
|
+
|
|
99
109
|
def _vault_aad(kind: str, identifier: str) -> str:
|
|
100
110
|
"""What a record sealed under the vault key is bound to.
|
|
101
111
|
|
|
@@ -338,8 +348,21 @@ class Mailcycle:
|
|
|
338
348
|
|
|
339
349
|
There is no undo and no grace period. Its addresses are retired and
|
|
340
350
|
never issued again. The client is signed out afterwards.
|
|
351
|
+
|
|
352
|
+
It answers a fresh challenge with the phrase, so a copied session
|
|
353
|
+
token alone cannot erase the account.
|
|
341
354
|
"""
|
|
342
|
-
|
|
355
|
+
body = None
|
|
356
|
+
if self._keys is not None and not self._api_key:
|
|
357
|
+
keys = self._keys
|
|
358
|
+
challenge = self._http.request("POST", "/accounts/challenge", body={"accountId": keys.account_id})
|
|
359
|
+
body = {
|
|
360
|
+
"nonce": challenge["nonce"],
|
|
361
|
+
"proof": prove_account(
|
|
362
|
+
keys.auth_key, challenge["challengeKey"], challenge["nonce"], keys.account_id, DELETE_DOMAIN
|
|
363
|
+
),
|
|
364
|
+
}
|
|
365
|
+
self._http.request("DELETE", "/accounts/me", body=body)
|
|
343
366
|
self._http.set_token(None)
|
|
344
367
|
|
|
345
368
|
def sign_out(self) -> None:
|
|
@@ -407,6 +430,7 @@ class _Addresses:
|
|
|
407
430
|
domain: str | None = None,
|
|
408
431
|
prefix: str | None = None,
|
|
409
432
|
local_part: str | None = None,
|
|
433
|
+
style: NameStyle | None = None,
|
|
410
434
|
label: str | None = None,
|
|
411
435
|
retention_days: int | None = None,
|
|
412
436
|
) -> Address:
|
|
@@ -414,15 +438,16 @@ class _Addresses:
|
|
|
414
438
|
|
|
415
439
|
Needs the phrase: the address's public key is derived from it here, and
|
|
416
440
|
only the public half is uploaded. Mail sealed to it opens nowhere else.
|
|
441
|
+
|
|
442
|
+
`local_part` asks for an exact name, `prefix` for a name that starts
|
|
443
|
+
with it, and `style` for a name rolled in that style. The first one
|
|
444
|
+
given is used.
|
|
417
445
|
"""
|
|
446
|
+
if style is not None:
|
|
447
|
+
_check_style(style)
|
|
418
448
|
keys = self._client._require_keys("create an address that receives mail")
|
|
419
449
|
address_id = _new_id("ibx")
|
|
420
|
-
chosen = domain
|
|
421
|
-
if chosen is None:
|
|
422
|
-
domains = self._client.domains.list()
|
|
423
|
-
if not domains:
|
|
424
|
-
raise MailcycleError("The account has no domain to create addresses on.")
|
|
425
|
-
chosen = domains[0].domain
|
|
450
|
+
chosen = self._domain(domain)
|
|
426
451
|
|
|
427
452
|
body: dict[str, Any] = {
|
|
428
453
|
"id": address_id,
|
|
@@ -436,12 +461,34 @@ class _Addresses:
|
|
|
436
461
|
body["localPart"] = local_part
|
|
437
462
|
elif prefix:
|
|
438
463
|
body["prefix"] = prefix
|
|
464
|
+
elif style:
|
|
465
|
+
body["style"] = style
|
|
439
466
|
if retention_days is not None:
|
|
440
467
|
body["retentionDays"] = retention_days
|
|
441
468
|
|
|
442
469
|
result = self._client._http.request("POST", "/inboxes", body=body)
|
|
443
470
|
return self._to_address(result["inbox"])
|
|
444
471
|
|
|
472
|
+
def roll_names(self, style: NameStyle, domain: str | None = None) -> builtins.list[str]:
|
|
473
|
+
"""Up to eight names in `style` that are free on the domain right now.
|
|
474
|
+
|
|
475
|
+
Pass one to `create` as `local_part`. Rolled names work on every plan.
|
|
476
|
+
"""
|
|
477
|
+
_check_style(style)
|
|
478
|
+
result = self._client._http.request(
|
|
479
|
+
"GET", "/inboxes/names", params={"style": style, "domain": self._domain(domain)}
|
|
480
|
+
)
|
|
481
|
+
return [name for name in result.get("names", []) if isinstance(name, str)]
|
|
482
|
+
|
|
483
|
+
def _domain(self, domain: str | None) -> str:
|
|
484
|
+
"""The domain given, or the account's first one."""
|
|
485
|
+
if domain is not None:
|
|
486
|
+
return domain
|
|
487
|
+
domains = self._client.domains.list()
|
|
488
|
+
if not domains:
|
|
489
|
+
raise MailcycleError("The account has no domain to create addresses on.")
|
|
490
|
+
return domains[0].domain
|
|
491
|
+
|
|
445
492
|
def update(
|
|
446
493
|
self, address_id: str, *, label: str | None = UNSET, retention_days: int | None = None
|
|
447
494
|
) -> Address:
|
|
@@ -28,6 +28,8 @@ from ..errors import AuthProofError, Base64URLError
|
|
|
28
28
|
from .primitives import hmac_sha256, is_all_zero, shared_secret
|
|
29
29
|
|
|
30
30
|
DOMAIN = "mailcycle/v1/auth-proof"
|
|
31
|
+
# Confirming the account's erasure, so an unlock proof cannot stand in for it.
|
|
32
|
+
DELETE_DOMAIN = "mailcycle/v1/delete-proof"
|
|
31
33
|
|
|
32
34
|
|
|
33
35
|
def prove_account(
|
|
@@ -14,6 +14,7 @@ from typing import Any, Literal
|
|
|
14
14
|
from .trackers import BlockedTracker
|
|
15
15
|
|
|
16
16
|
Folder = Literal["inbox", "sent", "junk", "trash"]
|
|
17
|
+
NameStyle = Literal["person", "business", "team", "neutral"]
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
def _rest(data: dict[str, Any], *known: str) -> dict[str, Any]:
|
|
@@ -21,7 +21,7 @@ import pytest
|
|
|
21
21
|
from mailcycle import Mailcycle, OutgoingAttachment
|
|
22
22
|
from mailcycle._encoding import to_b64u
|
|
23
23
|
from mailcycle.crypto.asymmetric import seal_to_public_key
|
|
24
|
-
from mailcycle.crypto.authproof import prove_account
|
|
24
|
+
from mailcycle.crypto.authproof import DELETE_DOMAIN, prove_account
|
|
25
25
|
from mailcycle.crypto.cipher import open_json, seal_json
|
|
26
26
|
from mailcycle.crypto.identity import address_key_pair
|
|
27
27
|
from mailcycle.crypto.primitives import public_key_from
|
|
@@ -168,6 +168,16 @@ class FakeAPI:
|
|
|
168
168
|
},
|
|
169
169
|
)
|
|
170
170
|
if path == "/accounts/me" and request.method == "DELETE":
|
|
171
|
+
# Checked under the erase domain, so an unlock proof would not pass.
|
|
172
|
+
expected = prove_account(
|
|
173
|
+
self.keys.auth_key,
|
|
174
|
+
to_b64u(public_key_from(self.challenge_private_key)),
|
|
175
|
+
"nonce-1",
|
|
176
|
+
self.keys.account_id,
|
|
177
|
+
DELETE_DOMAIN,
|
|
178
|
+
)
|
|
179
|
+
if body.get("nonce") != "nonce-1" or body.get("proof") != expected:
|
|
180
|
+
return httpx.Response(403, json={"code": "confirmation_required", "message": "No."})
|
|
171
181
|
self.account_deleted = True
|
|
172
182
|
return httpx.Response(200, json={"ok": True})
|
|
173
183
|
if path == "/accounts/me":
|
|
@@ -187,6 +197,16 @@ class FakeAPI:
|
|
|
187
197
|
return httpx.Response(
|
|
188
198
|
200, json={"domains": [{"domain": "letterhold.com", "reserved": False}]}
|
|
189
199
|
)
|
|
200
|
+
if path == "/inboxes/names":
|
|
201
|
+
style = request.url.params.get("style")
|
|
202
|
+
return httpx.Response(
|
|
203
|
+
200,
|
|
204
|
+
json={
|
|
205
|
+
"style": style,
|
|
206
|
+
"domain": request.url.params.get("domain"),
|
|
207
|
+
"names": ["maya.holt", "harbor-supply42"] if style == "person" else ["quiet_falcon"],
|
|
208
|
+
},
|
|
209
|
+
)
|
|
190
210
|
if path == "/inboxes" and request.method == "POST":
|
|
191
211
|
return httpx.Response(
|
|
192
212
|
200,
|
|
@@ -550,6 +570,59 @@ def test_creating_an_address_uploads_only_the_public_key(keys):
|
|
|
550
570
|
assert address.email_address.endswith("@letterhold.com")
|
|
551
571
|
|
|
552
572
|
|
|
573
|
+
def test_a_style_is_sent_when_no_name_or_prefix_is_given(keys):
|
|
574
|
+
api = FakeAPI(keys)
|
|
575
|
+
client = api.client(phrase=PHRASE)
|
|
576
|
+
client.addresses.create(style="business")
|
|
577
|
+
sent = json.loads(api.requests[-1].content)
|
|
578
|
+
assert sent["style"] == "business"
|
|
579
|
+
assert "prefix" not in sent and "localPart" not in sent
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
def test_a_name_or_prefix_wins_over_a_style(keys):
|
|
583
|
+
api = FakeAPI(keys)
|
|
584
|
+
client = api.client(phrase=PHRASE)
|
|
585
|
+
client.addresses.create(local_part="maya.holt", prefix="quiet", style="person")
|
|
586
|
+
sent = json.loads(api.requests[-1].content)
|
|
587
|
+
assert sent["localPart"] == "maya.holt"
|
|
588
|
+
assert "prefix" not in sent and "style" not in sent
|
|
589
|
+
|
|
590
|
+
client.addresses.create(prefix="quiet", style="person")
|
|
591
|
+
sent = json.loads(api.requests[-1].content)
|
|
592
|
+
assert sent["prefix"] == "quiet"
|
|
593
|
+
assert "style" not in sent
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def test_an_unknown_style_is_refused_before_sending(keys):
|
|
597
|
+
api = FakeAPI(keys)
|
|
598
|
+
client = api.client(phrase=PHRASE)
|
|
599
|
+
before = len(api.requests)
|
|
600
|
+
with pytest.raises(MailcycleError):
|
|
601
|
+
client.addresses.create(style="fancy")
|
|
602
|
+
with pytest.raises(MailcycleError):
|
|
603
|
+
client.addresses.roll_names("fancy")
|
|
604
|
+
assert len(api.requests) == before
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
def test_rolling_names_asks_for_the_style_on_the_given_domain(keys):
|
|
608
|
+
api = FakeAPI(keys)
|
|
609
|
+
names = api.client().addresses.roll_names("person", domain="example.org")
|
|
610
|
+
assert names == ["maya.holt", "harbor-supply42"]
|
|
611
|
+
request = api.requests[-1]
|
|
612
|
+
assert request.method == "GET"
|
|
613
|
+
assert request.url.path == "/inboxes/names"
|
|
614
|
+
assert request.url.params["style"] == "person"
|
|
615
|
+
assert request.url.params["domain"] == "example.org"
|
|
616
|
+
assert request.headers["authorization"] == "Bearer mak_test"
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
def test_rolling_names_without_a_domain_uses_the_first_one(keys):
|
|
620
|
+
api = FakeAPI(keys)
|
|
621
|
+
assert api.client().addresses.roll_names("neutral") == ["quiet_falcon"]
|
|
622
|
+
assert [r.url.path for r in api.requests] == ["/domains", "/inboxes/names"]
|
|
623
|
+
assert api.requests[-1].url.params["domain"] == "letterhold.com"
|
|
624
|
+
|
|
625
|
+
|
|
553
626
|
def test_an_address_label_opens_with_the_phrase_and_not_without(keys):
|
|
554
627
|
api = FakeAPI(keys)
|
|
555
628
|
assert api.client(phrase=PHRASE).addresses.list()[0].label == "Sign-in codes"
|
|
@@ -1076,6 +1149,7 @@ def test_delete_account_signs_out(keys):
|
|
|
1076
1149
|
client = _signed_in(api)
|
|
1077
1150
|
client.delete_account()
|
|
1078
1151
|
assert api.account_deleted
|
|
1152
|
+
assert api.requests[-2].url.path == "/accounts/challenge"
|
|
1079
1153
|
assert api.requests[-1].method == "DELETE" and api.requests[-1].url.path == "/accounts/me"
|
|
1080
1154
|
assert client.session_token is None
|
|
1081
1155
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|