From 64806b143b78bcc0b7103c0893a5fdd3898d6aff Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Mon, 2 Feb 2026 08:44:09 +0100 Subject: [PATCH] 02.02.26 --- modules/document_incoming/inbound_email.py | 50 ++-------------------- 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/modules/document_incoming/inbound_email.py b/modules/document_incoming/inbound_email.py index 60ade78..4aed774 100755 --- a/modules/document_incoming/inbound_email.py +++ b/modules/document_incoming/inbound_email.py @@ -47,53 +47,11 @@ class Rule(metaclass=PoolMeta): DocumentIncoming = pool.get('document.incoming') return DocumentIncoming.fields_get(['type'])['type']['selection'] - # def run(self, email_): - # pool = Pool() - # DocumentIncoming = pool.get('document.incoming') - # super().run(email_) - # if (self.action == 'document.incoming|from_inbound_email' - # and self.document_incoming_process): - # document = email_.result - # DocumentIncoming.process([document], with_children=True) - def run(self, email_): pool = Pool() DocumentIncoming = pool.get('document.incoming') super().run(email_) - - if self.action != 'document.incoming|from_inbound_email': - return - - data = email_.as_dict() - body = data.get('text') or data.get('html') - logger.info("BODY:%s",body) - attachments = data.get('attachments') or [] - - # 👉 S'il y avait des pièces jointes, le module standard a déjà créé les documents - if attachments: - if self.document_incoming_process and email_.result: - DocumentIncoming.process([email_.result], with_children=True) - return - - # 🚨 Aucune pièce jointe → on crée un document depuis le corps du mail - - if not body: - return # rien à créer - - filename = (data.get('subject') or "email").strip() - filename = f"{filename}.txt" - - document, = DocumentIncoming.create([{ - 'type': self.document_incoming_type, - 'company': self.document_incoming_company.id - if self.document_incoming_company else None, - 'filename': filename, - 'data': body.encode('utf-8'), - 'mime_type': 'text/plain', - 'source': 'email', - }]) - - email_.result = document - - if self.document_incoming_process: - DocumentIncoming.process([document], with_children=True) + if (self.action == 'document.incoming|from_inbound_email' + and self.document_incoming_process): + document = email_.result + DocumentIncoming.process([document], with_children=True) \ No newline at end of file