Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The import never creates Contacts on its own, even when the Email Account has *C

Scan and import run on the `long` queue in jobs of about 20 minutes and continue in a new job until they are done. The form shows the counters and refreshes when a job finishes. If a job dies, start the step again after 25 minutes; it continues where it stopped. If a folder's UIDVALIDITY changes on the server, its mails are not imported and the import asks for a new scan.

While a Communication is inserted by the import, `frappe.flags.mailsync_import` is `True`, so other apps can skip notifications or other work for old mail.
While the import inserts a Communication and then sets it to *Closed*, `frappe.flags.mailsync_import` is `True`, so other apps can skip notifications or other work for old mail.

## TLS

Expand Down
7 changes: 4 additions & 3 deletions mailsync/backfill/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ def create(self):
frappe.flags.mailsync_import = True
try:
communication = self._build_communication_doc()
communication.db_set(
{"email_account": self.email_account.name, "status": "Closed", "seen": 1},
update_modified=False,
)
finally:
frappe.flags.mailsync_import = False
communication.db_set(
{"email_account": self.email_account.name, "status": "Closed", "seen": 1}, update_modified=False
)
return communication


Expand Down
19 changes: 19 additions & 0 deletions mailsync/tests/test_backfill_import.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

import frappe
from frappe.tests import IntegrationTestCase

Expand Down Expand Up @@ -241,6 +243,23 @@ def test_failing_link_hook_does_not_fail_mail(self):
self.assertEqual(self.states(), ["Imported"])
self.assertTrue(self.communication(message_id))

def test_import_flag_set_during_status_update(self):
from frappe.model.document import Document

seen = []
original = Document.run_method

def spy(doc, method, *args, **kwargs):
if doc.doctype == "Communication" and method == "before_change":
seen.append((doc.status, frappe.flags.mailsync_import))
return original(doc, method, *args, **kwargs)

self.add(self.customer, self.own)
with patch.object(Document, "run_method", spy):
self.run_import()
self.assertIn(("Closed", True), seen)
self.assertFalse(frappe.flags.mailsync_import)


def broken_hook(address):
raise ValueError("broken hook")
1 change: 1 addition & 0 deletions mailsync/translations/de.csv
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Recipient links failed: {0},Verknüpfungen für Empfänger fehlgeschlagen: {0}
Address review failed: {0},Prüfung der Adresse fehlgeschlagen: {0}
Could not log in to {0},Anmeldung bei {0} nicht möglich
Account and dates cannot change after the first scan. Create a new import.,Konto und Zeitraum lassen sich nach dem ersten Scan nicht mehr ändern. Legen Sie einen neuen Import an.
Folders,Ordner
Loading