[IMP] fetchmail_incoming_log: black, isort, prettier

pull/1820/head
mreficent 2020-04-21 16:51:35 +02:00
parent 8e4ab0ca2b
commit 6772399715
3 changed files with 47 additions and 39 deletions

View File

@ -2,16 +2,13 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'Fetchmail Incoming Log',
'version': '12.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', 'test_mail',
],
'installable': True,
"name": "Fetchmail Incoming Log",
"version": "12.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", "test_mail",],
"installable": True,
}

View File

@ -3,8 +3,9 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import email
import xmlrpc.client as xmlrpclib
import logging
import xmlrpc.client as xmlrpclib
from odoo import api, models
from odoo.tools import pycompat
@ -12,12 +13,18 @@ _logger = logging.getLogger(__name__)
class MailThread(models.AbstractModel):
_inherit = 'mail.thread'
_inherit = "mail.thread"
@api.model
def message_process(self, model, message, custom_values=None,
save_original=False, strip_attachments=False,
thread_id=None):
def message_process(
self,
model,
message,
custom_values=None,
save_original=False,
strip_attachments=False,
thread_id=None,
):
if isinstance(message, xmlrpclib.Binary):
message = bytes(message.data)
@ -27,16 +34,22 @@ class MailThread(models.AbstractModel):
# 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')
extract = getattr(email, 'message_from_bytes',
email.message_from_string)
message = message.encode("utf-8")
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'))
"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,
model,
message,
custom_values=custom_values,
save_original=save_original,
strip_attachments=strip_attachments, thread_id=thread_id)
strip_attachments=strip_attachments,
thread_id=thread_id,
)

View File

@ -3,33 +3,31 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.addons.test_mail.tests.test_mail_gateway import TestMailgateway
from odoo.addons.test_mail.data.test_mail_data import MAIL_TEMPLATE
from odoo.addons.test_mail.tests.test_mail_gateway import TestMailgateway
class TestFetchmailIncomingLog(TestMailgateway):
def setUp(self):
super(TestFetchmailIncomingLog, self).setUp()
self.fetchmail_server = self.env['fetchmail.server'].create({
'name': 'Test Fetchmail Server',
'type': 'imap',
})
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'
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='',
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)
self.env["mail.thread"].with_context(
{"fetchmail_server_id": self.fetchmail_server.id,}
).message_process(None, mail)