Browse Source

[9.0][add] mail_log_messages_to_process

pull/933/head
Jordi Ballester 7 years ago
committed by mreficent
parent
commit
c4c492307d
  1. 48
      mail_log_messages_to_process/README.rst
  2. 5
      mail_log_messages_to_process/__init__.py
  3. 16
      mail_log_messages_to_process/__openerp__.py
  4. 5
      mail_log_messages_to_process/models/__init__.py
  5. 79
      mail_log_messages_to_process/models/mail_thread.py
  6. BIN
      mail_log_messages_to_process/static/description/icon.png

48
mail_log_messages_to_process/README.rst

@ -0,0 +1,48 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
============================
Mail log messages to process
============================
This module allows to log into the server the basic information of emails
that have been fetched from the mail server, before they start to be processed.
This allows for a better analysis of situations where emails are found to be
missing in Odoo. Can help to better resolve questions of the type 'Was it that
the email was never fetched, or a problem found when it was processed by
Odoo?'.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Contributors
------------
* Jordi Ballester <jordi.ballester@eficent.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

5
mail_log_messages_to_process/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models

16
mail_log_messages_to_process/__openerp__.py

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'Mail Log Messages to Process',
'version': '9.0.1.0.0',
'category': 'Tools',
'summary': 'Log all messages received, before they start to be processed.',
'author': "Eficent, "
"Odoo Community Association (OCA)",
'license': 'AGPL-3',
'website': 'https://github.com/OCA/server-tools',
'depends': ['mail'],
'installable': True,
}

5
mail_log_messages_to_process/models/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import mail_thread

79
mail_log_messages_to_process/models/mail_thread.py

@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import email
import xmlrpclib
import logging
from email.message import Message
from openerp import api, models
from openerp.addons.mail.models.mail_message import decode
_logger = logging.getLogger(__name__)
class MailThread(models.AbstractModel):
_inherit = 'mail.thread'
@api.model
def message_parse_basic_data(self, message):
"""Parses a string or email.message.Message representing an RFC-2822
email, and returns a generic dict holding the message details.
:param message: the message to parse
:rtype: dict
:return: A dict with the following structure, where each field
may not be present if missing in original message:
{ 'message_id': msg_id,
'subject': subject,
'from': from,
'to': to,
'cc': cc
}
"""
msg_dict = {
'message_type': 'email',
}
if not isinstance(message, Message):
if isinstance(message, unicode):
# Warning: message_from_string doesn't always work
# correctly on unicode, we must use utf-8 strings here :-(
message = message.encode('utf-8')
message = email.message_from_string(message)
message_id = message['message-id']
if not message_id:
message_id = 'None'
msg_dict['message_id'] = message_id
if message.get('Subject'):
msg_dict['subject'] = decode(message.get('Subject'))
# Envelope fields not stored in mail.message but made available
# for message_new()
msg_dict['from'] = decode(message.get('from'))
msg_dict['to'] = decode(message.get('to'))
msg_dict['cc'] = decode(message.get('cc'))
msg_dict['email_from'] = decode(message.get('from'))
return msg_dict
@api.model
def message_process(self, model, message, custom_values=None,
save_original=False, strip_attachments=False,
thread_id=None):
if isinstance(message, xmlrpclib.Binary):
message = str(message.data)
# Warning: message_from_string doesn't always work correctly on
# unicode, we must use utf-8 strings here :-(
if isinstance(message, unicode):
message = message.encode('utf-8')
msg_txt = email.message_from_string(message)
msg = self.message_parse_basic_data(msg_txt)
_logger.info(
'Fetched mail from %s to %s with Message-Id %s',
msg.get('from'), msg.get('to'), msg.get('message_id'))
return super(MailThread, self).message_process(
model, message, custom_values=custom_values,
save_original=save_original,
strip_attachments=strip_attachments, thread_id=thread_id)

BIN
mail_log_messages_to_process/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

Loading…
Cancel
Save