diff --git a/mail_log_message_to_process/README.rst b/mail_log_message_to_process/README.rst new file mode 100644 index 000000000..33c22cbb0 --- /dev/null +++ b/mail_log_message_to_process/README.rst @@ -0,0 +1,51 @@ +.. 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 +=========================== + +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?'. + +.. 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 + +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. + + +Credits +======= + +Contributors +------------ + +* Jordi Ballester + +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. diff --git a/mail_log_message_to_process/__init__.py b/mail_log_message_to_process/__init__.py new file mode 100644 index 000000000..149f4e4fd --- /dev/null +++ b/mail_log_message_to_process/__init__.py @@ -0,0 +1,4 @@ +# -*- 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 new file mode 100644 index 000000000..4ede8aea1 --- /dev/null +++ b/mail_log_message_to_process/__manifest__.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 Message to Process', + 'version': '10.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, +} diff --git a/mail_log_message_to_process/i18n/ca.po b/mail_log_message_to_process/i18n/ca.po new file mode 100644 index 000000000..2ba39ced8 --- /dev/null +++ b/mail_log_message_to_process/i18n/ca.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_log_messages_to_process +# +# Translators: +# Marc Tormo i Bochaca , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-21 22:54+0000\n" +"PO-Revision-Date: 2017-10-21 22:54+0000\n" +"Last-Translator: Marc Tormo i Bochaca , 2017\n" +"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: ca\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_log_messages_to_process +#: model:ir.model,name:mail_log_messages_to_process.model_mail_thread +msgid "Email Thread" +msgstr "Tema del Correu electrònic " diff --git a/mail_log_message_to_process/i18n/de.po b/mail_log_message_to_process/i18n/de.po new file mode 100644 index 000000000..75281bdc0 --- /dev/null +++ b/mail_log_message_to_process/i18n/de.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_log_messages_to_process +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-21 22:54+0000\n" +"PO-Revision-Date: 2017-10-21 22:54+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: de\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_log_messages_to_process +#: model:ir.model,name:mail_log_messages_to_process.model_mail_thread +msgid "Email Thread" +msgstr "Email-Thread" diff --git a/mail_log_message_to_process/i18n/es.po b/mail_log_message_to_process/i18n/es.po new file mode 100644 index 000000000..24d548d6e --- /dev/null +++ b/mail_log_message_to_process/i18n/es.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_log_messages_to_process +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-21 22:54+0000\n" +"PO-Revision-Date: 2017-10-21 22:54+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: es\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_log_messages_to_process +#: model:ir.model,name:mail_log_messages_to_process.model_mail_thread +msgid "Email Thread" +msgstr "Hilo correo electrónico" diff --git a/mail_log_message_to_process/i18n/fr.po b/mail_log_message_to_process/i18n/fr.po new file mode 100644 index 000000000..e0e253e30 --- /dev/null +++ b/mail_log_message_to_process/i18n/fr.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_log_messages_to_process +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-21 22:54+0000\n" +"PO-Revision-Date: 2017-10-21 22:54+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: mail_log_messages_to_process +#: model:ir.model,name:mail_log_messages_to_process.model_mail_thread +msgid "Email Thread" +msgstr "Discussion de courriel" diff --git a/mail_log_message_to_process/i18n/it.po b/mail_log_message_to_process/i18n/it.po new file mode 100644 index 000000000..69d99834a --- /dev/null +++ b/mail_log_message_to_process/i18n/it.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_log_messages_to_process +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-21 22:54+0000\n" +"PO-Revision-Date: 2017-10-21 22:54+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: it\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_log_messages_to_process +#: model:ir.model,name:mail_log_messages_to_process.model_mail_thread +msgid "Email Thread" +msgstr "Discussione Email" diff --git a/mail_log_message_to_process/i18n/pt_BR.po b/mail_log_message_to_process/i18n/pt_BR.po new file mode 100644 index 000000000..f134b1c5b --- /dev/null +++ b/mail_log_message_to_process/i18n/pt_BR.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_log_messages_to_process +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-21 22:54+0000\n" +"PO-Revision-Date: 2017-10-21 22:54+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Portuguese (Brazil) (https://www.transifex.com/oca/teams/23907/pt_BR/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: pt_BR\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: mail_log_messages_to_process +#: model:ir.model,name:mail_log_messages_to_process.model_mail_thread +msgid "Email Thread" +msgstr "Processo Email" diff --git a/mail_log_message_to_process/i18n/pt_PT.po b/mail_log_message_to_process/i18n/pt_PT.po new file mode 100644 index 000000000..eef8d581e --- /dev/null +++ b/mail_log_message_to_process/i18n/pt_PT.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_log_messages_to_process +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-21 22:54+0000\n" +"PO-Revision-Date: 2017-10-21 22:54+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Portuguese (Portugal) (https://www.transifex.com/oca/teams/23907/pt_PT/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: pt_PT\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_log_messages_to_process +#: model:ir.model,name:mail_log_messages_to_process.model_mail_thread +msgid "Email Thread" +msgstr "Tópico de Email" diff --git a/mail_log_message_to_process/i18n/sl.po b/mail_log_message_to_process/i18n/sl.po new file mode 100644 index 000000000..b83b72a9a --- /dev/null +++ b/mail_log_message_to_process/i18n/sl.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_log_messages_to_process +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-21 22:54+0000\n" +"PO-Revision-Date: 2017-10-21 22:54+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: sl\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" + +#. module: mail_log_messages_to_process +#: model:ir.model,name:mail_log_messages_to_process.model_mail_thread +msgid "Email Thread" +msgstr "E-poštna nit" diff --git a/mail_log_message_to_process/i18n/tr.po b/mail_log_message_to_process/i18n/tr.po new file mode 100644 index 000000000..6fec17aa7 --- /dev/null +++ b/mail_log_message_to_process/i18n/tr.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_log_messages_to_process +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-21 22:54+0000\n" +"PO-Revision-Date: 2017-10-21 22:54+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Turkish (https://www.transifex.com/oca/teams/23907/tr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: tr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: mail_log_messages_to_process +#: model:ir.model,name:mail_log_messages_to_process.model_mail_thread +msgid "Email Thread" +msgstr "Eposta konuşması" diff --git a/mail_log_message_to_process/models/__init__.py b/mail_log_message_to_process/models/__init__.py new file mode 100644 index 000000000..89b259c6c --- /dev/null +++ b/mail_log_message_to_process/models/__init__.py @@ -0,0 +1,4 @@ +# -*- 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 new file mode 100644 index 000000000..a18110f50 --- /dev/null +++ b/mail_log_message_to_process/models/mail_thread.py @@ -0,0 +1,81 @@ +# -*- 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 logging +from email.message import Message +from odoo import api, models +from odoo.tools import decode_smtp_header as 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) diff --git a/mail_log_message_to_process/static/description/icon.png b/mail_log_message_to_process/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mail_log_message_to_process/static/description/icon.png differ