mailcycle 0.2.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.2.0 → mailcycle-0.4.0}/PKG-INFO +9 -3
- {mailcycle-0.2.0 → mailcycle-0.4.0}/README.md +8 -2
- {mailcycle-0.2.0 → mailcycle-0.4.0}/pyproject.toml +1 -1
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/__init__.py +5 -1
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/client.py +84 -19
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/crypto/authproof.py +2 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/models.py +14 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/tests/test_client.py +101 -1
- {mailcycle-0.2.0 → mailcycle-0.4.0}/.gitignore +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/LICENSE +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/live/README.md +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/_encoding.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/crypto/__init__.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/crypto/asymmetric.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/crypto/cipher.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/crypto/identity.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/crypto/mnemonic.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/crypto/primitives.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/crypto/sealedbox.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/crypto/wordlist.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/errors.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/events.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/http.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/keys.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/mail.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/pairing.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/py.typed +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/trackers.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/src/mailcycle/webhooks.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/tests/conftest.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/tests/test_cross_implementation.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/tests/test_events.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/tests/test_pairing.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/tests/test_pairing_reference.py +0 -0
- {mailcycle-0.2.0 → mailcycle-0.4.0}/tests/test_trackers.py +0 -0
- {mailcycle-0.2.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
|
|
|
@@ -250,9 +250,15 @@ print(usage["addresses"]["used"], "of", usage["addresses"]["limit"], "addresses"
|
|
|
250
250
|
|
|
251
251
|
for entry in mc.activity(50):
|
|
252
252
|
print(entry.created_at, entry.kind)
|
|
253
|
+
|
|
254
|
+
page = mc.activity_page(limit=100)
|
|
255
|
+
older = mc.activity_page(limit=100, cursor=page.next_cursor)
|
|
256
|
+
|
|
257
|
+
for entry in mc.iter_activity(): # every event the server still holds
|
|
258
|
+
print(entry.id)
|
|
253
259
|
```
|
|
254
260
|
|
|
255
|
-
`usage()` reads back the counters the API enforces its limits on, so it says what a request would be refused on before it is refused. `activity()` is the account's own event log: ids and times, never content.
|
|
261
|
+
`usage()` reads back the counters the API enforces its limits on, so it says what a request would be refused on before it is refused. `activity()` is the account's own event log: ids and times, never content. Events are kept for 90 days; `activity_page()` pages back through them and `iter_activity()` walks them all.
|
|
256
262
|
|
|
257
263
|
## Events
|
|
258
264
|
|
|
@@ -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
|
|
|
@@ -188,9 +188,15 @@ print(usage["addresses"]["used"], "of", usage["addresses"]["limit"], "addresses"
|
|
|
188
188
|
|
|
189
189
|
for entry in mc.activity(50):
|
|
190
190
|
print(entry.created_at, entry.kind)
|
|
191
|
+
|
|
192
|
+
page = mc.activity_page(limit=100)
|
|
193
|
+
older = mc.activity_page(limit=100, cursor=page.next_cursor)
|
|
194
|
+
|
|
195
|
+
for entry in mc.iter_activity(): # every event the server still holds
|
|
196
|
+
print(entry.id)
|
|
191
197
|
```
|
|
192
198
|
|
|
193
|
-
`usage()` reads back the counters the API enforces its limits on, so it says what a request would be refused on before it is refused. `activity()` is the account's own event log: ids and times, never content.
|
|
199
|
+
`usage()` reads back the counters the API enforces its limits on, so it says what a request would be refused on before it is refused. `activity()` is the account's own event log: ids and times, never content. Events are kept for 90 days; `activity_page()` pages back through them and `iter_activity()` walks them all.
|
|
194
200
|
|
|
195
201
|
## Events
|
|
196
202
|
|
|
@@ -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"
|
|
@@ -35,6 +35,7 @@ from .models import (
|
|
|
35
35
|
Account,
|
|
36
36
|
AccountEvent,
|
|
37
37
|
ActivityEntry,
|
|
38
|
+
ActivityPage,
|
|
38
39
|
Address,
|
|
39
40
|
ApiKey,
|
|
40
41
|
Attachment,
|
|
@@ -45,6 +46,7 @@ from .models import (
|
|
|
45
46
|
Domain,
|
|
46
47
|
Message,
|
|
47
48
|
MessagePage,
|
|
49
|
+
NameStyle,
|
|
48
50
|
OutgoingAttachment,
|
|
49
51
|
Plan,
|
|
50
52
|
SendResult,
|
|
@@ -58,7 +60,7 @@ from .models import (
|
|
|
58
60
|
from .trackers import BlockedTracker, strip_remote_content, summarize_blocked
|
|
59
61
|
from .webhooks import verify_webhook_signature, webhook_signature_header
|
|
60
62
|
|
|
61
|
-
__version__ = "0.
|
|
63
|
+
__version__ = "0.4.0"
|
|
62
64
|
|
|
63
65
|
__all__ = [
|
|
64
66
|
"Mailcycle",
|
|
@@ -67,6 +69,7 @@ __all__ = [
|
|
|
67
69
|
"Account",
|
|
68
70
|
"AccountEvent",
|
|
69
71
|
"ActivityEntry",
|
|
72
|
+
"ActivityPage",
|
|
70
73
|
"Address",
|
|
71
74
|
"ApiKey",
|
|
72
75
|
"Attachment",
|
|
@@ -78,6 +81,7 @@ __all__ = [
|
|
|
78
81
|
"Domain",
|
|
79
82
|
"Message",
|
|
80
83
|
"MessagePage",
|
|
84
|
+
"NameStyle",
|
|
81
85
|
"OutgoingAttachment",
|
|
82
86
|
"Plan",
|
|
83
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
|
|
@@ -34,6 +35,7 @@ from .models import (
|
|
|
34
35
|
Account,
|
|
35
36
|
AccountEvent,
|
|
36
37
|
ActivityEntry,
|
|
38
|
+
ActivityPage,
|
|
37
39
|
Address,
|
|
38
40
|
ApiKey,
|
|
39
41
|
CreatedApiKey,
|
|
@@ -43,6 +45,7 @@ from .models import (
|
|
|
43
45
|
Domain,
|
|
44
46
|
Message,
|
|
45
47
|
MessagePage,
|
|
48
|
+
NameStyle,
|
|
46
49
|
OutgoingAttachment,
|
|
47
50
|
Plan,
|
|
48
51
|
SendResult,
|
|
@@ -67,6 +70,9 @@ _CLOCK_SKEW_SECONDS = 5.0
|
|
|
67
70
|
_MAX_ATTACHMENTS = 10
|
|
68
71
|
_MAX_ATTACHMENT_BYTES = int(3.5 * 1024 * 1024)
|
|
69
72
|
|
|
73
|
+
#: The styles the API rolls address names in.
|
|
74
|
+
_NAME_STYLES = ("person", "business", "team", "neutral")
|
|
75
|
+
|
|
70
76
|
|
|
71
77
|
class _Unset:
|
|
72
78
|
"""Distinguishes "leave the label alone" from "clear it"."""
|
|
@@ -95,6 +101,11 @@ def _attachments_body(attachments: Sequence[OutgoingAttachment]) -> list[dict[st
|
|
|
95
101
|
return body
|
|
96
102
|
|
|
97
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
|
+
|
|
98
109
|
def _vault_aad(kind: str, identifier: str) -> str:
|
|
99
110
|
"""What a record sealed under the vault key is bound to.
|
|
100
111
|
|
|
@@ -290,17 +301,34 @@ class Mailcycle:
|
|
|
290
301
|
|
|
291
302
|
def activity(self, limit: int = 20) -> list[ActivityEntry]:
|
|
292
303
|
"""Recent account events, newest first: ids and times, never content."""
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
+
return list(self.activity_page(limit=limit).activity)
|
|
305
|
+
|
|
306
|
+
def activity_page(self, *, limit: int | None = None, cursor: str | None = None) -> ActivityPage:
|
|
307
|
+
"""One page of account events, newest first. Pass `next_cursor` back as `cursor` for the page before."""
|
|
308
|
+
result = self._http.request("GET", "/activity", params={"limit": limit, "cursor": cursor})
|
|
309
|
+
return ActivityPage(
|
|
310
|
+
activity=tuple(
|
|
311
|
+
ActivityEntry(
|
|
312
|
+
id=entry.get("id", ""),
|
|
313
|
+
kind=entry.get("kind", ""),
|
|
314
|
+
created_at=entry.get("createdAt", ""),
|
|
315
|
+
address_id=entry.get("inboxId"),
|
|
316
|
+
worker_id=entry.get("workerId"),
|
|
317
|
+
)
|
|
318
|
+
for entry in result.get("activity", [])
|
|
319
|
+
),
|
|
320
|
+
next_cursor=result.get("nextCursor"),
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
def iter_activity(self, *, limit: int = 200) -> Iterator[ActivityEntry]:
|
|
324
|
+
"""Every event the server still holds (the last 90 days), newest first, a page at a time."""
|
|
325
|
+
cursor: str | None = None
|
|
326
|
+
while True:
|
|
327
|
+
page = self.activity_page(limit=limit, cursor=cursor)
|
|
328
|
+
yield from page.activity
|
|
329
|
+
cursor = page.next_cursor
|
|
330
|
+
if not cursor:
|
|
331
|
+
return
|
|
304
332
|
|
|
305
333
|
def usage(self) -> dict[str, Any]:
|
|
306
334
|
"""What the account has used, against what its plan allows."""
|
|
@@ -320,8 +348,21 @@ class Mailcycle:
|
|
|
320
348
|
|
|
321
349
|
There is no undo and no grace period. Its addresses are retired and
|
|
322
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.
|
|
323
354
|
"""
|
|
324
|
-
|
|
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)
|
|
325
366
|
self._http.set_token(None)
|
|
326
367
|
|
|
327
368
|
def sign_out(self) -> None:
|
|
@@ -389,6 +430,7 @@ class _Addresses:
|
|
|
389
430
|
domain: str | None = None,
|
|
390
431
|
prefix: str | None = None,
|
|
391
432
|
local_part: str | None = None,
|
|
433
|
+
style: NameStyle | None = None,
|
|
392
434
|
label: str | None = None,
|
|
393
435
|
retention_days: int | None = None,
|
|
394
436
|
) -> Address:
|
|
@@ -396,15 +438,16 @@ class _Addresses:
|
|
|
396
438
|
|
|
397
439
|
Needs the phrase: the address's public key is derived from it here, and
|
|
398
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.
|
|
399
445
|
"""
|
|
446
|
+
if style is not None:
|
|
447
|
+
_check_style(style)
|
|
400
448
|
keys = self._client._require_keys("create an address that receives mail")
|
|
401
449
|
address_id = _new_id("ibx")
|
|
402
|
-
chosen = domain
|
|
403
|
-
if chosen is None:
|
|
404
|
-
domains = self._client.domains.list()
|
|
405
|
-
if not domains:
|
|
406
|
-
raise MailcycleError("The account has no domain to create addresses on.")
|
|
407
|
-
chosen = domains[0].domain
|
|
450
|
+
chosen = self._domain(domain)
|
|
408
451
|
|
|
409
452
|
body: dict[str, Any] = {
|
|
410
453
|
"id": address_id,
|
|
@@ -418,12 +461,34 @@ class _Addresses:
|
|
|
418
461
|
body["localPart"] = local_part
|
|
419
462
|
elif prefix:
|
|
420
463
|
body["prefix"] = prefix
|
|
464
|
+
elif style:
|
|
465
|
+
body["style"] = style
|
|
421
466
|
if retention_days is not None:
|
|
422
467
|
body["retentionDays"] = retention_days
|
|
423
468
|
|
|
424
469
|
result = self._client._http.request("POST", "/inboxes", body=body)
|
|
425
470
|
return self._to_address(result["inbox"])
|
|
426
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
|
+
|
|
427
492
|
def update(
|
|
428
493
|
self, address_id: str, *, label: str | None = UNSET, retention_days: int | None = None
|
|
429
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]:
|
|
@@ -165,6 +166,19 @@ class ActivityEntry:
|
|
|
165
166
|
worker_id: str | None = None
|
|
166
167
|
|
|
167
168
|
|
|
169
|
+
@dataclass(frozen=True)
|
|
170
|
+
class ActivityPage:
|
|
171
|
+
activity: tuple[ActivityEntry, ...]
|
|
172
|
+
#: Opaque. Pass it back as `cursor` for the next page; None on the last.
|
|
173
|
+
next_cursor: str | None
|
|
174
|
+
|
|
175
|
+
def __iter__(self):
|
|
176
|
+
return iter(self.activity)
|
|
177
|
+
|
|
178
|
+
def __len__(self) -> int:
|
|
179
|
+
return len(self.activity)
|
|
180
|
+
|
|
181
|
+
|
|
168
182
|
@dataclass(frozen=True)
|
|
169
183
|
class AccountEvent:
|
|
170
184
|
id: str
|
|
@@ -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,
|
|
@@ -444,6 +464,19 @@ class FakeAPI:
|
|
|
444
464
|
if path == "/accounts/signout":
|
|
445
465
|
return httpx.Response(200, json={"ok": True})
|
|
446
466
|
|
|
467
|
+
if path == "/activity":
|
|
468
|
+
rows = [
|
|
469
|
+
{"id": f"act_{n}", "kind": "mail.received", "createdAt": f"2026-09-2{n}T10:00:00.000Z"}
|
|
470
|
+
for n in range(5, 0, -1)
|
|
471
|
+
]
|
|
472
|
+
limit = int(request.url.params.get("limit", 20))
|
|
473
|
+
cursor = request.url.params.get("cursor")
|
|
474
|
+
if cursor:
|
|
475
|
+
at, _, last = cursor.partition("~")
|
|
476
|
+
rows = [r for r in rows if (r["createdAt"], r["id"]) < (at, last)]
|
|
477
|
+
page = rows[:limit]
|
|
478
|
+
next_cursor = f"{page[-1]['createdAt']}~{page[-1]['id']}" if len(rows) > limit else None
|
|
479
|
+
return httpx.Response(200, json={"activity": page, "nextCursor": next_cursor})
|
|
447
480
|
if path == "/plans":
|
|
448
481
|
return httpx.Response(
|
|
449
482
|
200,
|
|
@@ -537,6 +570,59 @@ def test_creating_an_address_uploads_only_the_public_key(keys):
|
|
|
537
570
|
assert address.email_address.endswith("@letterhold.com")
|
|
538
571
|
|
|
539
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
|
+
|
|
540
626
|
def test_an_address_label_opens_with_the_phrase_and_not_without(keys):
|
|
541
627
|
api = FakeAPI(keys)
|
|
542
628
|
assert api.client(phrase=PHRASE).addresses.list()[0].label == "Sign-in codes"
|
|
@@ -856,6 +942,19 @@ def test_the_message_cursor_is_passed_back_as_it_came(keys):
|
|
|
856
942
|
assert sorted(m.id for m in client.messages.iterate(ADDRESS_ID, limit=2)) == [f"msg_{n}" for n in range(5)]
|
|
857
943
|
|
|
858
944
|
|
|
945
|
+
def test_the_activity_cursor_is_passed_back_as_it_came(keys):
|
|
946
|
+
api = FakeAPI(keys)
|
|
947
|
+
client = api.client()
|
|
948
|
+
first = client.activity_page(limit=2)
|
|
949
|
+
assert [e.id for e in first] == ["act_5", "act_4"]
|
|
950
|
+
assert first.next_cursor == "2026-09-24T10:00:00.000Z~act_4"
|
|
951
|
+
second = client.activity_page(limit=2, cursor=first.next_cursor)
|
|
952
|
+
assert api.requests[-1].url.params["cursor"] == "2026-09-24T10:00:00.000Z~act_4"
|
|
953
|
+
assert [e.id for e in second] == ["act_3", "act_2"]
|
|
954
|
+
assert [e.id for e in client.iter_activity(limit=2)] == ["act_5", "act_4", "act_3", "act_2", "act_1"]
|
|
955
|
+
assert [e.id for e in client.activity(3)] == ["act_5", "act_4", "act_3"]
|
|
956
|
+
|
|
957
|
+
|
|
859
958
|
# -- sign_out ------------------------------------------------------------
|
|
860
959
|
|
|
861
960
|
|
|
@@ -1050,6 +1149,7 @@ def test_delete_account_signs_out(keys):
|
|
|
1050
1149
|
client = _signed_in(api)
|
|
1051
1150
|
client.delete_account()
|
|
1052
1151
|
assert api.account_deleted
|
|
1152
|
+
assert api.requests[-2].url.path == "/accounts/challenge"
|
|
1053
1153
|
assert api.requests[-1].method == "DELETE" and api.requests[-1].url.path == "/accounts/me"
|
|
1054
1154
|
assert client.session_token is None
|
|
1055
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
|