02.02.26
This commit is contained in:
@@ -17,6 +17,8 @@ from trytond.transaction import Transaction
|
|||||||
from trytond.wizard import Button, StateTransition, StateView, Wizard
|
from trytond.wizard import Button, StateTransition, StateView, Wizard
|
||||||
|
|
||||||
from .exceptions import DocumentIncomingSplitError
|
from .exceptions import DocumentIncomingSplitError
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
if config.getboolean('document_incoming', 'filestore', default=True):
|
if config.getboolean('document_incoming', 'filestore', default=True):
|
||||||
file_id = 'file_id'
|
file_id = 'file_id'
|
||||||
@@ -182,11 +184,17 @@ class Incoming(DeactivableMixin, Workflow, ModelSQL, ModelView):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def from_inbound_email(cls, email_, rule):
|
def from_inbound_email(cls, email_, rule):
|
||||||
message = email_.as_dict()
|
message = email_.as_dict()
|
||||||
active = not message.get('attachments')
|
attachments = message.get('attachments')
|
||||||
active = True
|
active = False
|
||||||
data = message.get('text', message.get('html'))
|
data = message.get('text', message.get('html'))
|
||||||
|
logger.info("DATA_FROM_INBOUND_MAIL:%s",data)
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
|
body = message.get('text') or message.get('html') or ''
|
||||||
|
if isinstance(body, str):
|
||||||
|
body_bytes = body.encode('utf-8')
|
||||||
|
else:
|
||||||
|
body_bytes = body
|
||||||
document = cls(
|
document = cls(
|
||||||
active=active,
|
active=active,
|
||||||
name=message.get('subject', 'No Subject'),
|
name=message.get('subject', 'No Subject'),
|
||||||
@@ -196,13 +204,23 @@ class Incoming(DeactivableMixin, Workflow, ModelSQL, ModelView):
|
|||||||
source='inbound_email',
|
source='inbound_email',
|
||||||
)
|
)
|
||||||
children = []
|
children = []
|
||||||
for attachment in message.get('attachments', []):
|
if attachments:
|
||||||
|
for attachment in attachments:
|
||||||
|
child = cls(
|
||||||
|
name=attachment['filename'] or 'data.bin',
|
||||||
|
company=rule.document_incoming_company,
|
||||||
|
data=attachment['data'],
|
||||||
|
type=rule.document_incoming_type,
|
||||||
|
source='inbound_email')
|
||||||
|
children.append(child)
|
||||||
|
else:
|
||||||
child = cls(
|
child = cls(
|
||||||
name=attachment['filename'] or 'data.bin',
|
name='mail.txt',
|
||||||
company=rule.document_incoming_company,
|
company=rule.document_incoming_company,
|
||||||
data=attachment['data'],
|
data=body_bytes,
|
||||||
type=rule.document_incoming_type,
|
type=rule.document_incoming_type,
|
||||||
source='inbound_email')
|
source='inbound_email',
|
||||||
|
)
|
||||||
children.append(child)
|
children.append(child)
|
||||||
document.children = children
|
document.children = children
|
||||||
document.save()
|
document.save()
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
from trytond.model import fields
|
from trytond.model import fields
|
||||||
from trytond.pool import Pool, PoolMeta
|
from trytond.pool import Pool, PoolMeta
|
||||||
from trytond.pyson import Eval
|
from trytond.pyson import Eval
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Rule(metaclass=PoolMeta):
|
class Rule(metaclass=PoolMeta):
|
||||||
__name__ = 'inbound.email.rule'
|
__name__ = 'inbound.email.rule'
|
||||||
@@ -64,6 +65,8 @@ class Rule(metaclass=PoolMeta):
|
|||||||
return
|
return
|
||||||
|
|
||||||
data = email_.as_dict()
|
data = email_.as_dict()
|
||||||
|
body = data.get('text') or data.get('html')
|
||||||
|
logger.info("BODY:%s",body)
|
||||||
attachments = data.get('attachments') or []
|
attachments = data.get('attachments') or []
|
||||||
|
|
||||||
# 👉 S'il y avait des pièces jointes, le module standard a déjà créé les documents
|
# 👉 S'il y avait des pièces jointes, le module standard a déjà créé les documents
|
||||||
@@ -73,7 +76,7 @@ class Rule(metaclass=PoolMeta):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# 🚨 Aucune pièce jointe → on crée un document depuis le corps du mail
|
# 🚨 Aucune pièce jointe → on crée un document depuis le corps du mail
|
||||||
body = data.get('text') or data.get('html')
|
|
||||||
if not body:
|
if not body:
|
||||||
return # rien à créer
|
return # rien à créer
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ from trytond.pyson import Eval
|
|||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.url import http_host
|
from trytond.url import http_host
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
if config.getboolean('inbound_email', 'filestore', default=True):
|
if config.getboolean('inbound_email', 'filestore', default=True):
|
||||||
file_id = 'data_id'
|
file_id = 'data_id'
|
||||||
store_prefix = config.get('inbound_email', 'store_prefix', default=None)
|
store_prefix = config.get('inbound_email', 'store_prefix', default=None)
|
||||||
@@ -74,6 +77,7 @@ class Inbox(ModelSQL, ModelView):
|
|||||||
assert email_.inbox == self
|
assert email_.inbox == self
|
||||||
for rule in self.rules:
|
for rule in self.rules:
|
||||||
if rule.match(email_.as_dict()):
|
if rule.match(email_.as_dict()):
|
||||||
|
logger.info("RULE_MATCHED:%s",rule)
|
||||||
email_.rule = rule
|
email_.rule = rule
|
||||||
rule.run(email_)
|
rule.run(email_)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user