Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Masked Email? #66

Closed
stefan2904 opened this issue Sep 28, 2022 · 4 comments
Closed

Support for Masked Email? #66

stefan2904 opened this issue Sep 28, 2022 · 4 comments

Comments

@stefan2904
Copy link

Since Fastmail now opened up their JMAP API and included the MaskedEmail management in it, do you think it makes sense to also add that to your library?

@gexzam
Copy link

gexzam commented Oct 23, 2022

Hi @stefan2904 please, can you help me with my question?

@smkent
Copy link
Owner

smkent commented Oct 25, 2022

@stefan2904 Great idea! I wrote some code to support this in #73. Feel free to try that out and let me know what you think.

As this is the first provider-specific functionality in jmapc, I've set the MaskedEmail model and related methods to import from the jmapc.fastmail namespace (e.g. from jmapc.fastmail import MaskedEmail) rather than the root jmapc namespace.

@smkent smkent closed this as completed Nov 4, 2022
smkent added a commit that referenced this issue Nov 5, 2022
Applied upstream commits:

smkent/cookie-python@224c0e2...a893079

*   a893079 Merge pull request #66 from smkent/codecov-action-v3
|\
| * a336750 Update codecov-action to v3
|/
* d4ea3a7 Merge pull request #65 from smkent/python-3.11
* fad136b Add Python 3.11 to builds, and use Python 3.11 for releases
@stefan2904
Copy link
Author

@smkent first of all, thanks a lot for the implementation, and very sorry for my late reply!

I finally found some time to experiment with your implementation.


Retrieving existing masked emails works fine!

def getMaskedEmails(client):
	method = MaskedEmailGet(ids=None)
	result = client.request(method)
	return result.data

Unfortunately something is weird when I try to create a masked email.
Let me know if you want this in a new issue.

def createMaskedEmail(client):
	method = MaskedEmailSet(create=dict(
		foo= MaskedEmail(
			for_domain="example.com",
			description="TEST from python",
			email_prefix="stefan"
		)
	))
	result = client.request(method)
	return result

The interesting thing is: this works, but results in the following error anyway:

DEBUG:jmapc:Sending JMAP request {"using": ["https://www.fastmail.com/dev/maskedemail", "urn:ietf:params:jmap:core"], "methodCalls": [["MaskedEmail/set", {"accountId": "XXX", "create": {"foo": {"forDomain": "example.com", "description": "TEST from python", "url": "gopass websites/example.com", "emailPrefix": "stefan"}}}, "single.MaskedEmail/set"]]}

DEBUG:jmapc:Received JMAP response {"methodResponses":[["MaskedEmail/set",{"accountId":"XXX","destroyed":[],"updated":{},"created":{"foo":{"createdBy":"API Token: python-maskedemail 2022-12-12","id":"masked-74132944","lastMessageAt":null,"state":"pending","email":"stefan.askne@XXX","createdAt":"2022-12-12T15:25:31Z"}},"oldState":null,"newState":null},"single.MaskedEmail/set"]],"latestClientVersion":"","sessionState":"cyrus-119948;p-dc20fb7730"}

Traceback (most recent call last):
File "/home/st/projects/gopass-maskedemail/experiment_create.py", line 41, in
main()
File "/home/st/projects/gopass-maskedemail/experiment_create.py", line 36, in main
result = createMaskedEmail(client)
File "/home/st/projects/gopass-maskedemail/experiment_create.py", line 26, in createMaskedEmail
result = client.request(method)
File "/home/stsm/.local/lib/python3.10/site-packages/jmapc/client.py", line 227, in request
] = self._api_request(
File "/home/st/.local/lib/python3.10/site-packages/jmapc/client.py", line 275, in _api_request
return self._parse_method_responses(r.json())
File "/home/st/.local/lib/python3.10/site-packages/jmapc/client.py", line 285, in _parse_method_responses
return [
File "/home/st/.local/lib/python3.10/site-packages/jmapc/client.py", line 288, in
response=self._response_type(name).from_dict(response),
File "/home/st/.local/lib/python3.10/site-packages/dataclasses_json/api.py", line 72, in from_dict
return _decode_dataclass(cls, kvs, infer_missing)
File "/home/st/.local/lib/python3.10/site-packages/dataclasses_json/core.py", line 159, in _decode_dataclass
field_value = kvs[field.name]
KeyError: 'not_created'

(I am also not sure what to set for the id (set to foo in the example) when creating, since the ID is set by the server.)

Btw, I think the state field is missing in the model, you it cannot be set during creation.

TypeError: MaskedEmail.init() got an unexpected keyword argument 'state'

@smkent
Copy link
Owner

smkent commented Dec 12, 2022

@stefan2904 Thanks for giving this a try and for the detailed report! If you wouldn't mind opening a new issue, it'll help me keep track of it as it'll show up on my dashboard. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants