diff --git a/README.md b/README.md index cd264ef..b3adf71 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/mailsync/backfill/importer.py b/mailsync/backfill/importer.py index 45566c3..6d3fcb1 100644 --- a/mailsync/backfill/importer.py +++ b/mailsync/backfill/importer.py @@ -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 diff --git a/mailsync/tests/test_backfill_import.py b/mailsync/tests/test_backfill_import.py index 94f085a..b5c3231 100644 --- a/mailsync/tests/test_backfill_import.py +++ b/mailsync/tests/test_backfill_import.py @@ -1,3 +1,5 @@ +from unittest.mock import patch + import frappe from frappe.tests import IntegrationTestCase @@ -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") diff --git a/mailsync/translations/de.csv b/mailsync/translations/de.csv index 8f71268..622dd72 100644 --- a/mailsync/translations/de.csv +++ b/mailsync/translations/de.csv @@ -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