-
Notifications
You must be signed in to change notification settings - Fork 1
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
✨(dimail) synchronize mailboxes from dimail to our db #453
Conversation
b5ae653
to
7376efc
Compare
7376efc
to
f4d82cc
Compare
This is not considered a new email and will not trigger any mail notification.""" | ||
|
||
domain = models.MailDomain.objects.get(name=domain_name) | ||
people_mailboxes = models.Mailbox.objects.filter(domain=domain) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
models.Mailbox.objects.values_list("local_part", flat=True)
f4d82cc
to
4357e59
Compare
68f4532
to
439bf14
Compare
3d3d958
to
12e85cd
Compare
], # secondary email is mandatory. Unfortunately, dimail doesn't store any. | ||
# We temporarily give current email as secondary email. | ||
) | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
est-ce qu'on pourrait pas renvoyer des infos utiles comme combien de boite mail on était importé pour chaque domain synchronisé ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai implémenté ma proposition dans un second commit. Je rajouterai des tests si c'est ok.
mailbox = models.Mailbox.objects.create( | ||
first_name=dimail_mailbox["givenName"], | ||
last_name=dimail_mailbox["surName"], | ||
local_part=dimail_mailbox["email"].split("@")[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Est-ce qu'on ne devrait pas vérifier que la deuxième partie correspond bien au domain name ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you consider using from email.headerregistry import Address
here to prevent any CVE (I did the same mistake elsewhere)? I know we should trust dimail but anyway I think it's safer to use battle-tested Python helpers here, just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bonne question. Je préfèrerais qu'on laisse dimail tester de son côté que son API fonctionne bien comme il faut.
Si tu veux vérifier si le fix a été poussé, tu peux vérifier sur la prod de dimail que betagouv ne renvoie bien que des adresses betagouv (ou dans leur codebase que le test existe bien de leur côté)
Mais si tu veux faire ceinture+bretelle, on peut ajouter un filtre ligne 196 pour ne garder que les dimail_mailboxes qui correspondent au domaine.
EDIT : je confirme qu'au moment de mon test lundi 13h, dimail a toujours au moins un domaine avec plusieurs domaines dans les adresses.
{ | ||
"type": "mailbox", | ||
"status": "broken", | ||
"email": "[email protected]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
le nom de domaine ne match pas avec le factory au dessus
60e3fa0
to
60b68c4
Compare
dimail_mailboxes = ast.literal_eval( | ||
response.content.decode("utf-8") | ||
) # format output str to proper list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is response.json()
not proper here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think dimail's response is not json-ready !
mailbox = models.Mailbox.objects.create( | ||
first_name=dimail_mailbox["givenName"], | ||
last_name=dimail_mailbox["surName"], | ||
local_part=dimail_mailbox["email"].split("@")[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you consider using from email.headerregistry import Address
here to prevent any CVE (I did the same mistake elsewhere)? I know we should trust dimail but anyway I think it's safer to use battle-tested Python helpers here, just in case.
7f3375a
to
d26c03e
Compare
d26c03e
to
2175e3d
Compare
Synchronize mailboxes existing on dimail's api and not on our side, on domains we are administrating.
2175e3d
to
edde9c8
Compare
Purpose
I want to synchronize mailboxes FROM dimail TO people, by instance if a domain has already been existing for a while (i.e. beta.gouv)
Proposal
I don't think this synchronization needs to be on a CRON. Create a route below /domains/ to call for a synchronization.