diff --git a/mail_log_message_to_process/README.rst b/mail_log_message_to_process/README.rst index 33c22cbb0..ec900e5f3 100644 --- a/mail_log_message_to_process/README.rst +++ b/mail_log_message_to_process/README.rst @@ -1,11 +1,30 @@ -.. 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 message to process +Mail Log Message to Process =========================== +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/11.0/mail_log_message_to_process + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-11-0/server-tools-11-0-mail_log_message_to_process + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/149/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + 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. @@ -14,38 +33,48 @@ 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?'. -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/149/10.0 +**Table of contents** + +.. contents:: + :local: Bug Tracker =========== -Bugs are tracked on `GitHub 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. +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. +Do not contact contributors directly about support or help with technical issues. Credits ======= +Authors +~~~~~~~ + +* Eficent + Contributors ------------- +~~~~~~~~~~~~ * Jordi Ballester +* Héctor Villarreal -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. 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. +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_log_message_to_process/__init__.py b/mail_log_message_to_process/__init__.py index 149f4e4fd..0650744f6 100644 --- a/mail_log_message_to_process/__init__.py +++ b/mail_log_message_to_process/__init__.py @@ -1,4 +1 @@ -# -*- coding: utf-8 -*- -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - from . import models diff --git a/mail_log_message_to_process/__manifest__.py b/mail_log_message_to_process/__manifest__.py index 4ede8aea1..7009c8e06 100644 --- a/mail_log_message_to_process/__manifest__.py +++ b/mail_log_message_to_process/__manifest__.py @@ -1,10 +1,9 @@ -# -*- 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 Message to Process', - 'version': '10.0.1.0.0', + 'version': '11.0.1.0.0', 'category': 'Tools', 'summary': 'Log all messages received, before they start to be processed.', 'author': "Eficent, " diff --git a/mail_log_message_to_process/models/__init__.py b/mail_log_message_to_process/models/__init__.py index 89b259c6c..b70a9f2d0 100644 --- a/mail_log_message_to_process/models/__init__.py +++ b/mail_log_message_to_process/models/__init__.py @@ -1,4 +1 @@ -# -*- coding: utf-8 -*- -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - from . import mail_thread diff --git a/mail_log_message_to_process/models/mail_thread.py b/mail_log_message_to_process/models/mail_thread.py index a18110f50..7f218acb7 100644 --- a/mail_log_message_to_process/models/mail_thread.py +++ b/mail_log_message_to_process/models/mail_thread.py @@ -1,14 +1,12 @@ -# -*- coding: utf-8 -*- # Copyright 2017-18 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 xmlrpc.client as xmlrpclib import logging -from email.message import Message from odoo import api, models -from odoo.tools import decode_smtp_header as decode +from odoo.tools import pycompat _logger = logging.getLogger(__name__) @@ -16,61 +14,24 @@ _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 = bytes(message.data) + # message_from_string parses from a *native string*, except + # apparently sometimes message is ISO-8859-1 binary data or some + # shit and the straightforward version (pycompat.to_native) won't + # work right -> always encode message to bytes then use the + # relevant method depending on ~python version + if isinstance(message, pycompat.text_type): message = message.encode('utf-8') - msg_txt = email.message_from_string(message) - msg = self.message_parse_basic_data(msg_txt) + extract = getattr(email, 'message_from_bytes', + email.message_from_string) + msg_txt = extract(message) + msg = self.message_parse(msg_txt) _logger.info( 'Fetched mail from %s to %s with Message-Id %s', msg.get('from'), msg.get('to'), msg.get('message_id')) diff --git a/mail_log_message_to_process/readme/CONTRIBUTORS.rst b/mail_log_message_to_process/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..01ff4524b --- /dev/null +++ b/mail_log_message_to_process/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Jordi Ballester +* Héctor Villarreal \ No newline at end of file diff --git a/mail_log_message_to_process/readme/DESCRIPTION.rst b/mail_log_message_to_process/readme/DESCRIPTION.rst new file mode 100644 index 000000000..024647958 --- /dev/null +++ b/mail_log_message_to_process/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +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?'. \ No newline at end of file diff --git a/mail_log_message_to_process/static/description/index.html b/mail_log_message_to_process/static/description/index.html new file mode 100644 index 000000000..213f0ec0d --- /dev/null +++ b/mail_log_message_to_process/static/description/index.html @@ -0,0 +1,403 @@ + + + + + + +Mail Log Message to Process + + + +
+

Mail Log Message to Process

+ + +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

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?’.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Eficent
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/server-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_log_message_to_process/tests/__init__.py b/mail_log_message_to_process/tests/__init__.py new file mode 100644 index 000000000..545d1c2d3 --- /dev/null +++ b/mail_log_message_to_process/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_log_message_to_process \ No newline at end of file diff --git a/mail_log_message_to_process/tests/test_mail_log_message_to_process.py b/mail_log_message_to_process/tests/test_mail_log_message_to_process.py new file mode 100644 index 000000000..606a99744 --- /dev/null +++ b/mail_log_message_to_process/tests/test_mail_log_message_to_process.py @@ -0,0 +1,35 @@ +# Copyright 2017-18 Eficent Business and IT Consulting Services S.L. +# (www.eficent.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.addons.mail.tests.common import TestMail +from odoo.addons.mail.tests.test_mail_gateway import MAIL_TEMPLATE + + +class TestMailLogMessageToProcess(TestMail): + + def setUp(self): + super(TestMailLogMessageToProcess, self).setUp() + + self.fetchmail_server = self.env['fetchmail.server'].create({ + 'name': 'Test Fetchmail Server', + 'type': 'imap', + }) + + def test_message_process(self): + email_from = 'test1@example.com' + to_email = 'test2@example.com' + msg_id = 'Test log message to process' + with self.assertRaises(ValueError): + mail = MAIL_TEMPLATE.format( + to=to_email, + email_from=email_from, + cc='', + subject='testing', + extra='', + msg_id=msg_id, + ) + self.env['mail.thread'].with_context({ + 'fetchmail_server_id': self.fetchmail_server.id, + }).message_process(None, mail)