commit
6dd3e74c63
35
README.md
35
README.md
|
@ -831,6 +831,30 @@ Input:
|
||||||
|
|
||||||
Output: always return 200, even if email doesn't exist. User need to enter correctly their email.
|
Output: always return 200, even if email doesn't exist. User need to enter correctly their email.
|
||||||
|
|
||||||
|
#### GET /api/mailboxes
|
||||||
|
|
||||||
|
Get user verified mailboxes.
|
||||||
|
|
||||||
|
Input:
|
||||||
|
- `Authentication` header that contains the api key
|
||||||
|
|
||||||
|
Output:
|
||||||
|
List of mailboxes. Each mailbox has id, email field.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mailboxes": [
|
||||||
|
{
|
||||||
|
"email": "a@b.c",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"email": "m1@example.com",
|
||||||
|
"id": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### GET /api/v2/aliases
|
#### GET /api/v2/aliases
|
||||||
|
|
||||||
|
@ -852,6 +876,9 @@ If success, 200 with the list of aliases. Each alias has the following fields:
|
||||||
- nb_block
|
- nb_block
|
||||||
- nb_forward
|
- nb_forward
|
||||||
- nb_reply
|
- nb_reply
|
||||||
|
- mailbox
|
||||||
|
- id
|
||||||
|
- email
|
||||||
- (optional) latest_activity:
|
- (optional) latest_activity:
|
||||||
- action: forward|reply|block|bounced
|
- action: forward|reply|block|bounced
|
||||||
- timestamp
|
- timestamp
|
||||||
|
@ -871,6 +898,10 @@ Here's an example:
|
||||||
"email": "prefix1.cat@sl.local",
|
"email": "prefix1.cat@sl.local",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"id": 3,
|
"id": 3,
|
||||||
|
"mailbox": {
|
||||||
|
"email": "a@b.c",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
"latest_activity": {
|
"latest_activity": {
|
||||||
"action": "forward",
|
"action": "forward",
|
||||||
"contact": {
|
"contact": {
|
||||||
|
@ -891,6 +922,10 @@ Here's an example:
|
||||||
"email": "prefix0.hey@sl.local",
|
"email": "prefix0.hey@sl.local",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"id": 2,
|
"id": 2,
|
||||||
|
"mailbox": {
|
||||||
|
"email": "a@b.c",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
"latest_activity": {
|
"latest_activity": {
|
||||||
"action": "forward",
|
"action": "forward",
|
||||||
"contact": {
|
"contact": {
|
||||||
|
|
|
@ -51,6 +51,8 @@ def serialize_alias_info_v2(alias_info: AliasInfo) -> dict:
|
||||||
"nb_forward": alias_info.nb_forward,
|
"nb_forward": alias_info.nb_forward,
|
||||||
"nb_block": alias_info.nb_blocked,
|
"nb_block": alias_info.nb_blocked,
|
||||||
"nb_reply": alias_info.nb_reply,
|
"nb_reply": alias_info.nb_reply,
|
||||||
|
# mailbox
|
||||||
|
"mailbox": {"id": alias_info.mailbox.id, "email": alias_info.mailbox.email},
|
||||||
}
|
}
|
||||||
if alias_info.latest_email_log:
|
if alias_info.latest_email_log:
|
||||||
email_log = alias_info.latest_email_log
|
email_log = alias_info.latest_email_log
|
||||||
|
|
|
@ -117,6 +117,27 @@ def get_aliases_v2():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_bp.route("/mailboxes", methods=["GET"])
|
||||||
|
@cross_origin()
|
||||||
|
@require_api_auth
|
||||||
|
def get_mailboxes():
|
||||||
|
"""
|
||||||
|
Get mailboxes
|
||||||
|
Output:
|
||||||
|
- mailboxes: list of alias:
|
||||||
|
- id
|
||||||
|
- email
|
||||||
|
"""
|
||||||
|
user = g.user
|
||||||
|
|
||||||
|
return (
|
||||||
|
jsonify(
|
||||||
|
mailboxes=[{"id": mb.id, "email": mb.email} for mb in user.mailboxes()]
|
||||||
|
),
|
||||||
|
200,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@api_bp.route("/aliases/<int:alias_id>", methods=["DELETE"])
|
@api_bp.route("/aliases/<int:alias_id>", methods=["DELETE"])
|
||||||
@cross_origin()
|
@cross_origin()
|
||||||
@require_api_auth
|
@require_api_auth
|
||||||
|
|
21
server.py
21
server.py
|
@ -51,6 +51,8 @@ from app.models import (
|
||||||
Directory,
|
Directory,
|
||||||
Mailbox,
|
Mailbox,
|
||||||
DeletedAlias,
|
DeletedAlias,
|
||||||
|
Contact,
|
||||||
|
EmailLog,
|
||||||
)
|
)
|
||||||
from app.monitor.base import monitor_bp
|
from app.monitor.base import monitor_bp
|
||||||
from app.oauth.base import oauth_bp
|
from app.oauth.base import oauth_bp
|
||||||
|
@ -160,12 +162,25 @@ def fake_data():
|
||||||
m1 = Mailbox.create(user_id=user.id, email="m1@cd.ef", verified=True)
|
m1 = Mailbox.create(user_id=user.id, email="m1@cd.ef", verified=True)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
Alias.create_new(user, "e1@", mailbox_id=m1.id)
|
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
if i % 2 == 0:
|
if i % 2 == 0:
|
||||||
Alias.create_new(user, f"e{i}@", mailbox_id=m1.id)
|
a = Alias.create_new(user, f"e{i}@", mailbox_id=m1.id)
|
||||||
else:
|
else:
|
||||||
Alias.create_new(user, f"e{i}@")
|
a = Alias.create_new(user, f"e{i}@")
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
# some aliases don't have any activity
|
||||||
|
if i % 3 != 0:
|
||||||
|
contact = Contact.create(
|
||||||
|
user_id=user.id,
|
||||||
|
alias_id=a.id,
|
||||||
|
website_email=f"contact{i}@example.com",
|
||||||
|
reply_email=f"rep{i}@sl.local",
|
||||||
|
)
|
||||||
|
db.session.commit()
|
||||||
|
for _ in range(3):
|
||||||
|
EmailLog.create(user_id=user.id, contact_id=contact.id)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
||||||
CustomDomain.create(
|
CustomDomain.create(
|
||||||
|
|
|
@ -150,9 +150,9 @@ def test_get_aliases_v2(flask_client):
|
||||||
r0 = r.json["aliases"][0]
|
r0 = r.json["aliases"][0]
|
||||||
# r0 will have the following format
|
# r0 will have the following format
|
||||||
# {
|
# {
|
||||||
# "creation_date": "2020-04-06 17:52:47+00:00",
|
# "creation_date": "2020-04-25 21:10:01+00:00",
|
||||||
# "creation_timestamp": 1586195567,
|
# "creation_timestamp": 1587849001,
|
||||||
# "email": "prefix1.hey@sl.local",
|
# "email": "prefix1.yeah@sl.local",
|
||||||
# "enabled": true,
|
# "enabled": true,
|
||||||
# "id": 3,
|
# "id": 3,
|
||||||
# "latest_activity": {
|
# "latest_activity": {
|
||||||
|
@ -162,7 +162,11 @@ def test_get_aliases_v2(flask_client):
|
||||||
# "name": null,
|
# "name": null,
|
||||||
# "reverse_alias": "\"c1 at example.com\" <re1@SL>"
|
# "reverse_alias": "\"c1 at example.com\" <re1@SL>"
|
||||||
# },
|
# },
|
||||||
# "timestamp": 1586195567
|
# "timestamp": 1587849001
|
||||||
|
# },
|
||||||
|
# "mailbox": {
|
||||||
|
# "email": "a@b.c",
|
||||||
|
# "id": 1
|
||||||
# },
|
# },
|
||||||
# "nb_block": 0,
|
# "nb_block": 0,
|
||||||
# "nb_forward": 1,
|
# "nb_forward": 1,
|
||||||
|
@ -177,6 +181,9 @@ def test_get_aliases_v2(flask_client):
|
||||||
assert "name" in r0["latest_activity"]["contact"]
|
assert "name" in r0["latest_activity"]["contact"]
|
||||||
assert "reverse_alias" in r0["latest_activity"]["contact"]
|
assert "reverse_alias" in r0["latest_activity"]["contact"]
|
||||||
|
|
||||||
|
assert "id" in r0["mailbox"]
|
||||||
|
assert "email" in r0["mailbox"]
|
||||||
|
|
||||||
|
|
||||||
def test_delete_alias(flask_client):
|
def test_delete_alias(flask_client):
|
||||||
user = User.create(
|
user = User.create(
|
||||||
|
@ -473,3 +480,28 @@ def test_get_alias(flask_client):
|
||||||
assert "nb_reply" in res
|
assert "nb_reply" in res
|
||||||
assert "enabled" in res
|
assert "enabled" in res
|
||||||
assert "note" in res
|
assert "note" in res
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_mailboxes(flask_client):
|
||||||
|
user = User.create(
|
||||||
|
email="a@b.c", password="password", name="Test User", activated=True
|
||||||
|
)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
# create api_key
|
||||||
|
api_key = ApiKey.create(user.id, "for test")
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
Mailbox.create(user_id=user.id, email="m1@example.com", verified=True)
|
||||||
|
Mailbox.create(user_id=user.id, email="m2@example.com", verified=False)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
r = flask_client.get(
|
||||||
|
url_for("api.get_mailboxes"), headers={"Authentication": api_key.code},
|
||||||
|
)
|
||||||
|
assert r.status_code == 200
|
||||||
|
# m2@example.com is not returned as it's not verified
|
||||||
|
assert r.json == {
|
||||||
|
"mailboxes": [{"email": "a@b.c", "id": 1}, {"email": "m1@example.com", "id": 2}]
|
||||||
|
}
|
||||||
|
print(json.dumps(r.json, indent=2))
|
||||||
|
|
Loading…
Reference in a new issue