From 9443c971af3805eccdc7d962ef75c709da962c3a Mon Sep 17 00:00:00 2001 From: Antonio Espinosa Date: Tue, 14 Jun 2016 17:22:17 +0200 Subject: [PATCH] [8.0][ADD] mail_tracking addon (#67) * [ADD] mail_tracking addon * Add description icon * Fixes remarked * Fix Travis error * Remarks fixed --- mail_tracking/README.rst | 112 +++++ mail_tracking/__init__.py | 8 + mail_tracking/__openerp__.py | 32 ++ mail_tracking/controllers/__init__.py | 6 + mail_tracking/controllers/main.py | 86 ++++ mail_tracking/data/tracking_data.xml | 13 + mail_tracking/hooks.py | 24 + mail_tracking/i18n/es.po | 430 ++++++++++++++++++ mail_tracking/models/__init__.py | 11 + mail_tracking/models/ir_mail_server.py | 94 ++++ mail_tracking/models/mail_mail.py | 43 ++ mail_tracking/models/mail_message.py | 54 +++ mail_tracking/models/mail_tracking_email.py | 274 +++++++++++ mail_tracking/models/mail_tracking_event.py | 136 ++++++ mail_tracking/models/res_partner.py | 40 ++ mail_tracking/security/ir.model.access.csv | 5 + mail_tracking/static/description/icon.png | Bin 0 -> 5896 bytes .../static/src/css/mail_tracking.css | 13 + mail_tracking/static/src/img/delivered.png | Bin 0 -> 285 bytes mail_tracking/static/src/img/error.png | Bin 0 -> 257 bytes mail_tracking/static/src/img/opened.png | Bin 0 -> 368 bytes mail_tracking/static/src/img/sent.png | Bin 0 -> 294 bytes mail_tracking/static/src/img/unknown.png | Bin 0 -> 425 bytes mail_tracking/static/src/img/waiting.png | Bin 0 -> 348 bytes mail_tracking/static/src/js/mail_tracking.js | 63 +++ .../static/src/xml/mail_tracking.xml | 61 +++ mail_tracking/tests/__init__.py | 6 + mail_tracking/tests/test_mail_tracking.py | 135 ++++++ mail_tracking/views/assets.xml | 19 + .../views/mail_tracking_email_view.xml | 122 +++++ .../views/mail_tracking_event_view.xml | 125 +++++ mail_tracking/views/res_partner_view.xml | 33 ++ 32 files changed, 1945 insertions(+) create mode 100644 mail_tracking/README.rst create mode 100644 mail_tracking/__init__.py create mode 100644 mail_tracking/__openerp__.py create mode 100644 mail_tracking/controllers/__init__.py create mode 100644 mail_tracking/controllers/main.py create mode 100644 mail_tracking/data/tracking_data.xml create mode 100644 mail_tracking/hooks.py create mode 100644 mail_tracking/i18n/es.po create mode 100644 mail_tracking/models/__init__.py create mode 100644 mail_tracking/models/ir_mail_server.py create mode 100644 mail_tracking/models/mail_mail.py create mode 100644 mail_tracking/models/mail_message.py create mode 100644 mail_tracking/models/mail_tracking_email.py create mode 100644 mail_tracking/models/mail_tracking_event.py create mode 100644 mail_tracking/models/res_partner.py create mode 100644 mail_tracking/security/ir.model.access.csv create mode 100644 mail_tracking/static/description/icon.png create mode 100644 mail_tracking/static/src/css/mail_tracking.css create mode 100644 mail_tracking/static/src/img/delivered.png create mode 100644 mail_tracking/static/src/img/error.png create mode 100644 mail_tracking/static/src/img/opened.png create mode 100644 mail_tracking/static/src/img/sent.png create mode 100644 mail_tracking/static/src/img/unknown.png create mode 100644 mail_tracking/static/src/img/waiting.png create mode 100644 mail_tracking/static/src/js/mail_tracking.js create mode 100644 mail_tracking/static/src/xml/mail_tracking.xml create mode 100644 mail_tracking/tests/__init__.py create mode 100644 mail_tracking/tests/test_mail_tracking.py create mode 100644 mail_tracking/views/assets.xml create mode 100644 mail_tracking/views/mail_tracking_email_view.xml create mode 100644 mail_tracking/views/mail_tracking_event_view.xml create mode 100644 mail_tracking/views/res_partner_view.xml diff --git a/mail_tracking/README.rst b/mail_tracking/README.rst new file mode 100644 index 00000000..e2a9bd20 --- /dev/null +++ b/mail_tracking/README.rst @@ -0,0 +1,112 @@ +.. 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 tracking +============= + +This module shows email notification tracking status for any messages in +mail thread (chatter). Each notified partner will have an intuitive icon just +right to his name. + + +Installation +============ + +If you're using a multi-database installation (with or without dbfilter option) +where /web/databse/selector returns a list of more than one database, then +you need to add ``mail_tracking`` addon to wide load addons list +(by default, only ``web`` addon), setting ``--load`` option. +For example, ``--load=web,mail_tracking`` + + +Usage +===== + +When user sends a message in mail_thread (chatter), for instance in partner +form, then an email tracking is created for each email notification. Then a +status icon will appear just right to name of notified partner. + +These are all available status icons: + +.. |sent| image:: mail_tracking/static/src/img/sent.png + :width: 10px + +.. |delivered| image:: mail_tracking/static/src/img/delivered.png + :width: 15px + +.. |opened| image:: mail_tracking/static/src/img/opened.png + :width: 15px + +.. |error| image:: mail_tracking/static/src/img/error.png + :width: 10px + +.. |waiting| image:: mail_tracking/static/src/img/waiting.png + :width: 10px + +.. |unknown| image:: mail_tracking/static/src/img/unknown.png + :width: 10px + +|unknown| **Unknown**: No email tracking info available. Maybe this notified partner has 'Receive Inbox Notifications by Email' == 'Never' + +|waiting| **Waiting**: Waiting to be sent + +|error| **Error**: Error while sending + +|sent| **Sent**: Sent to SMTP server configured + +|delivered| **Delivered**: Delivered to final MX server + +|opened| **Opened**: Opened by partner + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/205/8.0 + +If you want to see all tracking emails and events you can go to + +* Settings > Technical > Email > Tracking emails +* Settings > Technical > Email > Tracking events + + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. +* Thanks to `LlubNek `_ and `Openclipart + `_ for `the icon + `_. + +Contributors +------------ + +* Pedro M. Baeza +* Antonio Espinosa + +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_tracking/__init__.py b/mail_tracking/__init__.py new file mode 100644 index 00000000..1c66d89e --- /dev/null +++ b/mail_tracking/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# flake8: noqa + +from . import models +from . import controllers +from .hooks import post_init_hook diff --git a/mail_tracking/__openerp__.py b/mail_tracking/__openerp__.py new file mode 100644 index 00000000..10cb3dcf --- /dev/null +++ b/mail_tracking/__openerp__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Email tracking", + "summary": "Email tracking system for all mails sent", + "version": "8.0.2.0.0", + "category": "Social Network", + "website": "http://www.tecnativa.com", + "author": "Tecnativa, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "decimal_precision", + "mail", + ], + "data": [ + "data/tracking_data.xml", + "security/ir.model.access.csv", + "views/assets.xml", + "views/mail_tracking_email_view.xml", + "views/mail_tracking_event_view.xml", + "views/res_partner_view.xml", + ], + "qweb": [ + "static/src/xml/mail_tracking.xml", + ], + "post_init_hook": "post_init_hook", +} diff --git a/mail_tracking/controllers/__init__.py b/mail_tracking/controllers/__init__.py new file mode 100644 index 00000000..73e11057 --- /dev/null +++ b/mail_tracking/controllers/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# flake8: noqa + +from . import main diff --git a/mail_tracking/controllers/main.py b/mail_tracking/controllers/main.py new file mode 100644 index 00000000..91e6063f --- /dev/null +++ b/mail_tracking/controllers/main.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import werkzeug +from psycopg2 import OperationalError +from openerp import api, http, registry, SUPERUSER_ID +import logging +_logger = logging.getLogger(__name__) + +BLANK = 'R0lGODlhAQABAIAAANvf7wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==' + + +def _env_get(db): + reg = False + try: + reg = registry(db) + except OperationalError: + _logger.warning("Selected BD '%s' not found", db) + except: # pragma: no cover + _logger.warning("Selected BD '%s' connection error", db) + if reg: + return api.Environment(reg.cursor(), SUPERUSER_ID, {}) + return False + + +class MailTrackingController(http.Controller): + + def _request_metadata(self): + request = http.request.httprequest + return { + 'ip': request.remote_addr or False, + 'user_agent': request.user_agent or False, + 'os_family': request.user_agent.platform or False, + 'ua_family': request.user_agent.browser or False, + } + + @http.route('/mail/tracking/all/', + type='http', auth='none') + def mail_tracking_all(self, db, **kw): + env = _env_get(db) + if not env: + return 'NOT FOUND' + metadata = self._request_metadata() + response = env['mail.tracking.email'].event_process( + http.request, kw, metadata) + env.cr.commit() + env.cr.close() + return response + + @http.route('/mail/tracking/event//', + type='http', auth='none') + def mail_tracking_event(self, db, event_type, **kw): + env = _env_get(db) + if not env: + return 'NOT FOUND' + metadata = self._request_metadata() + response = env['mail.tracking.email'].event_process( + http.request, kw, metadata, event_type=event_type) + env.cr.commit() + env.cr.close() + return response + + @http.route('/mail/tracking/open/' + '//blank.gif', + type='http', auth='none') + def mail_tracking_open(self, db, tracking_email_id, **kw): + env = _env_get(db) + if env: + tracking_email = env['mail.tracking.email'].search([ + ('id', '=', tracking_email_id), + ]) + if tracking_email: + metadata = self._request_metadata() + tracking_email.event_create('open', metadata) + else: + _logger.warning( + "MailTracking email '%s' not found", tracking_email_id) + env.cr.commit() + env.cr.close() + + # Always return GIF blank image + response = werkzeug.wrappers.Response() + response.mimetype = 'image/gif' + response.data = BLANK.decode('base64') + return response diff --git a/mail_tracking/data/tracking_data.xml b/mail_tracking/data/tracking_data.xml new file mode 100644 index 00000000..4bcb2cb8 --- /dev/null +++ b/mail_tracking/data/tracking_data.xml @@ -0,0 +1,13 @@ + + + + + + + MailTracking Timestamp + 6 + + + + diff --git a/mail_tracking/hooks.py b/mail_tracking/hooks.py new file mode 100644 index 00000000..2b6b20b1 --- /dev/null +++ b/mail_tracking/hooks.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging +from openerp import api, SUPERUSER_ID + +_logger = logging.getLogger(__name__) + + +def post_init_hook(cr, registry): + with api.Environment.manage(): + env = api.Environment(cr, SUPERUSER_ID, {}) + # Recalculate all partner tracking_email_ids + partners = env['res.partner'].search([ + ('email', '!=', False), + ]) + emails = partners.mapped('email') + _logger.info( + "Recalculating 'tracking_email_ids' in 'res.partner' " + "model for %d email addresses", len(emails)) + for email in emails: + env['mail.tracking.email'].tracking_ids_recalculate( + 'res.partner', 'email', 'tracking_email_ids', email) diff --git a/mail_tracking/i18n/es.po b/mail_tracking/i18n/es.po new file mode 100644 index 00000000..51e26719 --- /dev/null +++ b/mail_tracking/i18n/es.po @@ -0,0 +1,430 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_tracking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-06-07 19:45+0000\n" +"PO-Revision-Date: 2016-06-07 19:45+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_tracking +#: help:mail.tracking.email,state:0 +msgid " * The 'Error' status indicates that there was an error when trying to sent the email, for example, 'No valid recipient'\n" +" * The 'Sent' status indicates that message was succesfully sent via outgoing email server (SMTP).\n" +" * The 'Delivered' status indicates that message was succesfully delivered to recipient Mail Exchange (MX) server.\n" +" * The 'Open' status indicates that message was opened or clicked by recipient.\n" +" * The 'Rejected' status indicates that recipient email address is blacklisted by outgoing email server (SMTP). It is recomended to delete this email address.\n" +" * The 'Spam' status indicates that outgoing email server (SMTP) consider this message as spam.\n" +" * The 'Unsubscribed' status indicates that recipient has requested to be unsubscribed from this message.\n" +" * The 'Bounced' status indicates that message was bounced by recipient Mail Exchange (MX) server.\n" +" * The 'Soft bounced' status indicates that message was soft bounced by recipient Mail Exchange (MX) server.\n" +"" +msgstr " * 'Error' indica que ha habido un error al intentar el envío del email, por ejemplo, 'Email de destino no válido'\n" +" * 'Enviado' indica que el email se ha envíado correctamente al servidor de correo saliente (SMTP)\n" +" * 'Entregado' indica que el email se ha entregado al servidor de correo del destinatario (MX)\n" +" * 'Abierto' indica que el destinatario ha abierto o clicado en el email\n" +" * 'Rechazado' indica que la dirección del destinatario esta en una lista negra en el servidor de correo saliente (SMTP)\n" +" * 'Spam' indica que el servidor de correo saliente (SMTP) considera el email como spam\n" +" * 'Desuscrito' indica que el destinatarios ha solicitado desuscribirse desde este email\n" +" * 'Rebotado' indica que el email no ha sido aceptado por el servidor de correo del destinatario (MX)\n" +" * 'Rebotado leve' indica que el email no ha sido aceptado por motivos temporales por el servidor de correo del destinatario (MX)\n" + +#. module: mail_tracking +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "Bounce" +msgstr "Rebote" + +#. module: mail_tracking +#: field:mail.tracking.email,bounce_description:0 +msgid "Bounce description" +msgstr "Descripción del rebote" + +#. module: mail_tracking +#: field:mail.tracking.email,bounce_type:0 +msgid "Bounce type" +msgstr "Tipo de rebote" + +#. module: mail_tracking +#: selection:mail.tracking.email,state:0 +msgid "Bounced" +msgstr "Rebotado" + +#. module: mail_tracking +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "Click" +msgstr "Clic" + +#. module: mail_tracking +#: selection:mail.tracking.event,event_type:0 +msgid "Clicked" +msgstr "Clicado" + +#. module: mail_tracking +#: field:mail.tracking.event,url:0 +msgid "Clicked URL" +msgstr "URL clicada" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_form +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_tree +msgid "Country" +msgstr "País" + +#. module: mail_tracking +#: field:mail.tracking.email,create_uid:0 +#: field:mail.tracking.event,create_uid:0 +msgid "Created by" +msgstr "Creado por" + +#. module: mail_tracking +#: field:mail.tracking.email,create_date:0 +#: field:mail.tracking.event,create_date:0 +msgid "Created on" +msgstr "Creado en" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: field:mail.tracking.email,date:0 +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +#: field:mail.tracking.event,date:0 +msgid "Date" +msgstr "Fecha" + +#. module: mail_tracking +#: selection:mail.tracking.event,event_type:0 +msgid "Deferral" +msgstr "Retraso" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: selection:mail.tracking.email,state:0 +msgid "Deferred" +msgstr "Retrasado" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: selection:mail.tracking.email,state:0 +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +#: selection:mail.tracking.event,event_type:0 +msgid "Delivered" +msgstr "Entregado" + +#. module: mail_tracking +#: field:mail.tracking.email,display_name:0 +#: field:mail.tracking.event,display_name:0 +msgid "Display Name" +msgstr "Nombre a mostrar" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: field:mail.tracking.email,mail_id:0 +msgid "Email" +msgstr "Correo electrónico" + +#. module: mail_tracking +#: selection:mail.tracking.email,state:0 +msgid "Error" +msgstr "Error" + +#. module: mail_tracking +#: field:mail.tracking.email,error_smtp_server:0 +msgid "Error SMTP server" +msgstr "Error del servidor SMTP" + +#. module: mail_tracking +#: field:mail.tracking.email,error_description:0 +msgid "Error description" +msgstr "Descripción del error" + +#. module: mail_tracking +#: field:mail.tracking.email,error_type:0 +msgid "Error type" +msgstr "Tipo de error" + +#. module: mail_tracking +#: field:mail.tracking.event,event_type:0 +msgid "Event type" +msgstr "Tipo de evento" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "Failed" +msgstr "Ha fallado" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "Group By" +msgstr "Agrupar por" + +#. module: mail_tracking +#: selection:mail.tracking.event,event_type:0 +msgid "Hard bounce" +msgstr "Rebote duro" + +#. module: mail_tracking +#: field:mail.tracking.email,id:0 +#: field:mail.tracking.event,id:0 +msgid "ID" +msgstr "ID" + +#. module: mail_tracking +#: field:mail.tracking.event,mobile:0 +msgid "Is mobile?" +msgstr "¿Es desde móvil?" + +#. module: mail_tracking +#: field:mail.tracking.email,__last_update:0 +#: field:mail.tracking.event,__last_update:0 +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: mail_tracking +#: field:mail.tracking.email,write_uid:0 +#: field:mail.tracking.event,write_uid:0 +msgid "Last Updated by" +msgstr "Última modificación por" + +#. module: mail_tracking +#: field:mail.tracking.email,write_date:0 +#: field:mail.tracking.event,write_date:0 +msgid "Last Updated on" +msgstr "Última actualización en" + +#. module: mail_tracking +#: model:ir.model,name:mail_tracking.model_mail_tracking_email +msgid "MailTracking email" +msgstr "MailTracking email" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +msgid "MailTracking email search" +msgstr "MailTracking email search" + +#. module: mail_tracking +#: model:ir.actions.act_window,name:mail_tracking.action_view_mail_tracking_email +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_tree +msgid "MailTracking emails" +msgstr "MailTracking emails" + +#. module: mail_tracking +#: model:ir.model,name:mail_tracking.model_mail_tracking_event +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_form +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_form +msgid "MailTracking event" +msgstr "MailTracking event" + +#. module: mail_tracking +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "MailTracking event search" +msgstr "MailTracking event search" + +#. module: mail_tracking +#: model:ir.actions.act_window,name:mail_tracking.action_view_mail_tracking_event +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_tree +msgid "MailTracking events" +msgstr "MailTracking events" + +#. module: mail_tracking +#: model:ir.model,name:mail_tracking.model_mail_message +#: field:mail.tracking.email,mail_message_id:0 +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +#: field:mail.tracking.event,tracking_email_id:0 +msgid "Message" +msgstr "Mensaje" + +#. module: mail_tracking +#. openerp-web +#: code:addons/mail_tracking/static/src/js/mail_tracking.js:31 +#, python-format +msgid "Message tracking" +msgstr "Seguimiento de mensaje" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "Month" +msgstr "Mes" + +#. module: mail_tracking +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "Open" +msgstr "Abrir" + +#. module: mail_tracking +#: selection:mail.tracking.email,state:0 +#: selection:mail.tracking.event,event_type:0 +msgid "Open" +msgstr "Abierto" + +#. module: mail_tracking +#: field:mail.tracking.event,os_family:0 +msgid "Operating system family" +msgstr "Familia de sistema operativo" + +#. module: mail_tracking +#: model:ir.model,name:mail_tracking.model_mail_mail +msgid "Outgoing Mails" +msgstr "Emails de salida" + +#. module: mail_tracking +#: field:mail.tracking.email,partner_id:0 +msgid "Partner" +msgstr "Empresa" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_tree +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +#: field:mail.tracking.event,recipient:0 +msgid "Recipient" +msgstr "Destinatario" + +#. module: mail_tracking +#: field:mail.tracking.email,recipient:0 +msgid "Recipient email" +msgstr "Email del destinatario" + +#. module: mail_tracking +#: selection:mail.tracking.email,state:0 +#: selection:mail.tracking.event,event_type:0 +msgid "Rejected" +msgstr "Rechazado" + +#. module: mail_tracking +#: field:mail.tracking.event,smtp_server:0 +msgid "SMTP server" +msgstr "Servidor SMTP" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_tree +msgid "Sender" +msgstr "Remitente" + +#. module: mail_tracking +#: field:mail.tracking.email,sender:0 +msgid "Sender email" +msgstr "Email del remitente" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: selection:mail.tracking.email,state:0 +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +#: selection:mail.tracking.event,event_type:0 +msgid "Sent" +msgstr "Enviar" + +#. module: mail_tracking +#: selection:mail.tracking.event,event_type:0 +msgid "Soft bounce" +msgstr "Rebote suave" + +#. module: mail_tracking +#: selection:mail.tracking.email,state:0 +msgid "Soft bounced" +msgstr "Rebotado suave" + +#. module: mail_tracking +#: selection:mail.tracking.email,state:0 +#: selection:mail.tracking.event,event_type:0 +msgid "Spam" +msgstr "Spam" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: field:mail.tracking.email,state:0 +msgid "State" +msgstr "Estado" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: field:mail.tracking.email,name:0 +msgid "Subject" +msgstr "Asunto" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: field:mail.tracking.email,time:0 +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +#: field:mail.tracking.event,time:0 +msgid "Time" +msgstr "Hora" + +#. module: mail_tracking +#: model:ir.ui.menu,name:mail_tracking.menu_mail_tracking_email +msgid "Tracking emails" +msgstr "Emails de seguimiento" + +#. module: mail_tracking +#: model:ir.ui.menu,name:mail_tracking.menu_mail_tracking_event +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_form +#: field:mail.tracking.email,tracking_event_ids:0 +msgid "Tracking events" +msgstr "Eventos de seguimiento" + +#. module: mail_tracking +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "Type" +msgstr "Tipo" + +#. module: mail_tracking +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "URL" +msgstr "URL" + +#. module: mail_tracking +#: field:mail.tracking.email,timestamp:0 +#: field:mail.tracking.event,timestamp:0 +msgid "UTC timestamp" +msgstr "Tiempo UTC" + +#. module: mail_tracking +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +msgid "Unsubscribe" +msgstr "Desuscribirse" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_search +#: selection:mail.tracking.email,state:0 +#: selection:mail.tracking.event,event_type:0 +msgid "Unsubscribed" +msgstr "Desuscrito" + +#. module: mail_tracking +#: field:mail.tracking.event,ip:0 +msgid "User IP" +msgstr "IP usuario" + +#. module: mail_tracking +#: view:mail.tracking.email:mail_tracking.view_mail_tracking_email_form +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_tree +#: field:mail.tracking.event,user_agent:0 +msgid "User agent" +msgstr "Aplicación del usuario" + +#. module: mail_tracking +#: field:mail.tracking.event,ua_family:0 +msgid "User agent family" +msgstr "Familia de la aplicación del usuario" + +#. module: mail_tracking +#: view:mail.tracking.event:mail_tracking.view_mail_tracking_event_search +#: field:mail.tracking.event,ua_type:0 +msgid "User agent type" +msgstr "Tipo de aplicación del usuario" + +#. module: mail_tracking +#: field:mail.tracking.event,user_country_id:0 +msgid "User country" +msgstr "País del usuario" diff --git a/mail_tracking/models/__init__.py b/mail_tracking/models/__init__.py new file mode 100644 index 00000000..42a28f51 --- /dev/null +++ b/mail_tracking/models/__init__.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# flake8: noqa + +from . import ir_mail_server +from . import mail_mail +from . import mail_message +from . import mail_tracking_email +from . import mail_tracking_event +from . import res_partner diff --git a/mail_tracking/models/ir_mail_server.py b/mail_tracking/models/ir_mail_server.py new file mode 100644 index 00000000..e364a570 --- /dev/null +++ b/mail_tracking/models/ir_mail_server.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import re +import threading +from openerp import models, api, tools + + +class IrMailServer(models.Model): + _inherit = "ir.mail_server" + + def _tracking_headers_add(self, tracking_email_id, headers): + """Allow other addons to add its own tracking SMTP headers""" + headers = headers or {} + headers['X-Odoo-Database'] = getattr( + threading.currentThread(), 'dbname', None), + headers['X-Odoo-Tracking-ID'] = tracking_email_id + return headers + + def _tracking_email_id_body_get(self, body): + body = body or '' + tracking_email_id = False + # https://regex101.com/r/lW4cB1/2 + match = re.search( + r']* data-odoo-tracking-email=["\']([0-9]*)["\']', body) + if match: + try: + tracking_email_id = int(match.group(1)) + except: # pragma: no cover + pass + return tracking_email_id + + def build_email(self, email_from, email_to, subject, body, email_cc=None, + email_bcc=None, reply_to=False, attachments=None, + message_id=None, references=None, object_id=False, + subtype='plain', headers=None, body_alternative=None, + subtype_alternative='plain'): + tracking_email_id = self._tracking_email_id_body_get(body) + if tracking_email_id: + headers = self._tracking_headers_add(tracking_email_id, headers) + msg = super(IrMailServer, self).build_email( + email_from, email_to, subject, body, email_cc=email_cc, + email_bcc=email_bcc, reply_to=reply_to, attachments=attachments, + message_id=message_id, references=references, object_id=object_id, + subtype=subtype, headers=headers, + body_alternative=body_alternative, + subtype_alternative=subtype_alternative) + return msg + + def _tracking_email_get(self, message): + tracking_email_id = False + if message.get('X-Odoo-Tracking-ID', '').isdigit(): + tracking_email_id = int(message['X-Odoo-Tracking-ID']) + return self.env['mail.tracking.email'].browse(tracking_email_id) + + def _smtp_server_get(self, mail_server_id, smtp_server): + smtp_server_used = False + mail_server = None + if mail_server_id: + mail_server = self.browse(mail_server_id) + elif not smtp_server: + mail_server_ids = self.search([], order='sequence', limit=1) + mail_server = mail_server_ids[0] if mail_server_ids else None + if mail_server: + smtp_server_used = mail_server.smtp_host + else: # pragma: no cover + smtp_server_used = smtp_server or tools.config.get('smtp_server') + return smtp_server_used + + @api.model + def send_email(self, message, mail_server_id=None, smtp_server=None, + smtp_port=None, smtp_user=None, smtp_password=None, + smtp_encryption=None, smtp_debug=False): + message_id = False + tracking_email = self._tracking_email_get(message) + smtp_server_used = self._smtp_server_get( + mail_server_id, smtp_server) + try: + message_id = super(IrMailServer, self).send_email( + message, mail_server_id=mail_server_id, + smtp_server=smtp_server, smtp_port=smtp_port, + smtp_user=smtp_user, smtp_password=smtp_password, + smtp_encryption=smtp_encryption, smtp_debug=smtp_debug) + except Exception as e: + if tracking_email: + tracking_email.smtp_error(self, smtp_server_used, e) + raise + if message_id and tracking_email: + vals = tracking_email._tracking_sent_prepare( + self, smtp_server_used, message, message_id) + if vals: + self.env['mail.tracking.event'].sudo().create(vals) + return message_id diff --git a/mail_tracking/models/mail_mail.py b/mail_tracking/models/mail_mail.py new file mode 100644 index 00000000..9f5b004b --- /dev/null +++ b/mail_tracking/models/mail_mail.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import time +from datetime import datetime +from email.utils import COMMASPACE + +from openerp import models, api, fields + + +class MailMail(models.Model): + _inherit = 'mail.mail' + + @api.model + def _tracking_email_prepare(self, mail, partner, email): + ts = time.time() + dt = datetime.utcfromtimestamp(ts) + email_to_list = email.get('email_to', []) + email_to = COMMASPACE.join(email_to_list) + return { + 'name': email.get('subject', False), + 'timestamp': '%.6f' % ts, + 'time': fields.Datetime.to_string(dt), + 'mail_id': mail.id if mail else False, + 'mail_message_id': mail.mail_message_id.id if mail else False, + 'partner_id': partner.id if partner else False, + 'recipient': email_to, + 'sender': mail.email_from, + } + + @api.model + def send_get_email_dict(self, mail, partner=None): + email = super(MailMail, self).send_get_email_dict( + mail, partner=partner) + m_tracking = self.env['mail.tracking.email'] + tracking_email = False + if mail: + vals = self._tracking_email_prepare(mail, partner, email) + tracking_email = m_tracking.sudo().create(vals) + if tracking_email: + email = tracking_email.tracking_img_add(email) + return email diff --git a/mail_tracking/models/mail_message.py b/mail_tracking/models/mail_message.py new file mode 100644 index 00000000..d5d381ee --- /dev/null +++ b/mail_tracking/models/mail_message.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, api +import logging +_logger = logging.getLogger(__name__) + + +class MailMessage(models.Model): + _inherit = "mail.message" + + def _tracking_status_map_get(self): + return { + 'False': 'waiting', + 'error': 'error', + 'deferred': 'sent', + 'sent': 'sent', + 'delivered': 'delivered', + 'opened': 'opened', + 'rejected': 'error', + 'spam': 'error', + 'unsub': 'opened', + 'bounced': 'error', + 'soft-bounced': 'error', + } + + def _partner_tracking_status_get(self, tracking_email): + tracking_status_map = self._tracking_status_map_get() + status = 'unknown' + if tracking_email: + tracking_email_status = str(tracking_email.state) + status = tracking_status_map.get(tracking_email_status, 'unknown') + return status + + @api.model + def _message_read_dict_postprocess(self, messages, message_tree): + res = super(MailMessage, self)._message_read_dict_postprocess( + messages, message_tree) + for message_dict in messages: + mail_message_id = message_dict.get('id', False) + if mail_message_id: + partner_trackings = {} + for partner in message_dict.get('partner_ids', []): + partner_id = partner[0] + tracking_email = self.env['mail.tracking.email'].search([ + ('mail_message_id', '=', mail_message_id), + ('partner_id', '=', partner_id), + ]) + status = self._partner_tracking_status_get(tracking_email) + partner_trackings[str(partner_id)] = ( + status, tracking_email.id) + message_dict['partner_trackings'] = partner_trackings + return res diff --git a/mail_tracking/models/mail_tracking_email.py b/mail_tracking/models/mail_tracking_email.py new file mode 100644 index 00000000..d0452add --- /dev/null +++ b/mail_tracking/models/mail_tracking_email.py @@ -0,0 +1,274 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging +import urlparse +import time +import re +from datetime import datetime + +from openerp import models, api, fields, tools +import openerp.addons.decimal_precision as dp + +_logger = logging.getLogger(__name__) + + +class MailTrackingEmail(models.Model): + _name = "mail.tracking.email" + _order = 'time desc' + _rec_name = 'display_name' + _description = 'MailTracking email' + + name = fields.Char(string="Subject", readonly=True, index=True) + display_name = fields.Char( + string="Display name", readonly=True, store=True, + compute="_compute_display_name") + timestamp = fields.Float( + string='UTC timestamp', readonly=True, + digits=dp.get_precision('MailTracking Timestamp')) + time = fields.Datetime(string="Time", readonly=True) + date = fields.Date( + string="Date", readonly=True, compute="_compute_date", store=True) + mail_message_id = fields.Many2one( + string="Message", comodel_name='mail.message', readonly=True) + mail_id = fields.Many2one( + string="Email", comodel_name='mail.mail', readonly=True) + partner_id = fields.Many2one( + string="Partner", comodel_name='res.partner', readonly=True) + recipient = fields.Char(string='Recipient email', readonly=True) + recipient_address = fields.Char( + string='Recipient email address', readonly=True, store=True, + compute='_compute_recipient_address') + sender = fields.Char(string='Sender email', readonly=True) + state = fields.Selection([ + ('error', 'Error'), + ('deferred', 'Deferred'), + ('sent', 'Sent'), + ('delivered', 'Delivered'), + ('opened', 'Open'), + ('rejected', 'Rejected'), + ('spam', 'Spam'), + ('unsub', 'Unsubscribed'), + ('bounced', 'Bounced'), + ('soft-bounced', 'Soft bounced'), + ], string='State', index=True, readonly=True, default=False, + help=" * The 'Error' status indicates that there was an error " + "when trying to sent the email, for example, " + "'No valid recipient'\n" + " * The 'Sent' status indicates that message was succesfully " + "sent via outgoing email server (SMTP).\n" + " * The 'Delivered' status indicates that message was " + "succesfully delivered to recipient Mail Exchange (MX) server.\n" + " * The 'Open' status indicates that message was opened or " + "clicked by recipient.\n" + " * The 'Rejected' status indicates that recipient email " + "address is blacklisted by outgoing email server (SMTP). " + "It is recomended to delete this email address.\n" + " * The 'Spam' status indicates that outgoing email " + "server (SMTP) consider this message as spam.\n" + " * The 'Unsubscribed' status indicates that recipient has " + "requested to be unsubscribed from this message.\n" + " * The 'Bounced' status indicates that message was bounced " + "by recipient Mail Exchange (MX) server.\n" + " * The 'Soft bounced' status indicates that message was soft " + "bounced by recipient Mail Exchange (MX) server.\n") + error_smtp_server = fields.Char(string='Error SMTP server', readonly=True) + error_type = fields.Char(string='Error type', readonly=True) + error_description = fields.Char( + string='Error description', readonly=True) + bounce_type = fields.Char(string='Bounce type', readonly=True) + bounce_description = fields.Char( + string='Bounce description', readonly=True) + tracking_event_ids = fields.One2many( + string="Tracking events", comodel_name='mail.tracking.event', + inverse_name='tracking_email_id', readonly=True) + + @api.model + def tracking_ids_recalculate(self, model, email_field, tracking_field, + email, new_tracking=None): + objects = self.env[model].search([ + (email_field, '=ilike', email), + ]) + for obj in objects: + trackings = obj[tracking_field] + if new_tracking: + trackings |= new_tracking + trackings = trackings._email_score_tracking_filter() + if set(obj[tracking_field].ids) != set(trackings.ids): + if trackings: + obj.write({ + tracking_field: [(6, False, trackings.ids)] + }) + else: + obj.write({ + tracking_field: [(5, False, False)] + }) + return True + + @api.model + def _tracking_ids_to_write(self, email): + trackings = self.env['mail.tracking.email'].search([ + ('recipient_address', '=ilike', email) + ]) + trackings = trackings._email_score_tracking_filter() + if trackings: + return [(6, False, trackings.ids)] + else: + return [(5, False, False)] + + @api.multi + def _email_score_tracking_filter(self): + """Default email score filter for tracking emails""" + # Consider only last 10 tracking emails + return self.sorted(key=lambda r: r.time, reverse=True)[:10] + + @api.multi + def email_score(self): + """Default email score algorimth""" + score = 50.0 + trackings = self._email_score_tracking_filter() + for tracking in trackings: + if tracking.state in ('error',): + score -= 50.0 + elif tracking.state in ('rejected', 'spam', 'bounced'): + score -= 25.0 + elif tracking.state in ('soft-bounced', 'unsub'): + score -= 10.0 + elif tracking.state in ('delivered',): + score += 5.0 + elif tracking.state in ('opened',): + score += 10.0 + if score > 100.0: + score = 100.0 + return score + + @api.multi + @api.depends('recipient') + def _compute_recipient_address(self): + for email in self: + matches = re.search(r'<(.*@.*)>', email.recipient) + if matches: + email.recipient_address = matches.group(1) + else: + email.recipient_address = email.recipient + + @api.multi + @api.depends('name', 'recipient') + def _compute_display_name(self): + for email in self: + parts = [email.name] + if email.recipient: + parts.append(email.recipient) + email.display_name = ' - '.join(parts) + + @api.multi + @api.depends('time') + def _compute_date(self): + for email in self: + email.date = fields.Date.to_string( + fields.Date.from_string(email.time)) + + @api.model + def create(self, vals): + tracking = super(MailTrackingEmail, self).create(vals) + self.tracking_ids_recalculate( + 'res.partner', 'email', 'tracking_email_ids', + tracking.recipient_address, new_tracking=tracking) + return tracking + + def _get_mail_tracking_img(self): + base_url = self.env['ir.config_parameter'].get_param('web.base.url') + path_url = ( + 'mail/tracking/open/%(db)s/%(tracking_email_id)s/blank.gif' % { + 'db': self.env.cr.dbname, + 'tracking_email_id': self.id, + }) + track_url = urlparse.urljoin(base_url, path_url) + return ( + '' % { + 'url': track_url, + 'tracking_email_id': self.id, + }) + + @api.multi + def smtp_error(self, mail_server, smtp_server, exception): + self.sudo().write({ + 'error_smtp_server': tools.ustr(smtp_server), + 'error_type': exception.__class__.__name__, + 'error_description': tools.ustr(exception), + 'state': 'error', + }) + return True + + @api.multi + def tracking_img_add(self, email): + self.ensure_one() + tracking_url = self._get_mail_tracking_img() + if tracking_url: + body = tools.append_content_to_html( + email.get('body', ''), tracking_url, plaintext=False, + container_tag='div') + email['body'] = body + return email + + def _message_partners_check(self, message, message_id): + mail_message = self.mail_message_id + partners = mail_message.notified_partner_ids | mail_message.partner_ids + if (self.partner_id and self.partner_id not in partners): + # If mail_message haven't tracking partner, then + # add it in order to see his trackking status in chatter + if mail_message.subtype_id: + mail_message.sudo().write({ + 'notified_partner_ids': [(4, self.partner_id.id)], + }) + else: + mail_message.sudo().write({ + 'partner_ids': [(4, self.partner_id.id)], + }) + return True + + @api.multi + def _tracking_sent_prepare(self, mail_server, smtp_server, message, + message_id): + self.ensure_one() + ts = time.time() + dt = datetime.utcfromtimestamp(ts) + self._message_partners_check(message, message_id) + self.sudo().write({'state': 'sent'}) + return { + 'recipient': message['To'], + 'timestamp': '%.6f' % ts, + 'time': fields.Datetime.to_string(dt), + 'tracking_email_id': self.id, + 'event_type': 'sent', + 'smtp_server': smtp_server, + } + + def _event_prepare(self, event_type, metadata): + self.ensure_one() + m_event = self.env['mail.tracking.event'] + method = getattr(m_event, 'process_' + event_type, None) + if method and hasattr(method, '__call__'): + return method(self, metadata) + else: # pragma: no cover + _logger.info('Unknown event type: %s' % event_type) + return False + + @api.multi + def event_create(self, event_type, metadata): + event_ids = self.env['mail.tracking.event'] + for tracking_email in self: + vals = tracking_email._event_prepare(event_type, metadata) + if vals: + event_ids += event_ids.sudo().create(vals) + return event_ids + + @api.model + def event_process(self, request, post, metadata, event_type=None): + # Generic event process hook, inherit it and + # - return 'OK' if processed + # - return 'NONE' if this request is not for you + # - return 'ERROR' if any error + return 'NONE' # pragma: no cover diff --git a/mail_tracking/models/mail_tracking_event.py b/mail_tracking/models/mail_tracking_event.py new file mode 100644 index 00000000..728f88c0 --- /dev/null +++ b/mail_tracking/models/mail_tracking_event.py @@ -0,0 +1,136 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import time +from datetime import datetime + +from openerp import models, api, fields +import openerp.addons.decimal_precision as dp + + +class MailTrackingEvent(models.Model): + _name = "mail.tracking.event" + _order = 'timestamp desc' + _rec_name = 'event_type' + _description = 'MailTracking event' + + recipient = fields.Char(string="Recipient", readonly=True) + timestamp = fields.Float( + string='UTC timestamp', readonly=True, + digits=dp.get_precision('MailTracking Timestamp')) + time = fields.Datetime(string="Time", readonly=True) + date = fields.Date( + string="Date", readonly=True, compute="_compute_date", store=True) + tracking_email_id = fields.Many2one( + string='Message', readonly=True, + comodel_name='mail.tracking.email') + event_type = fields.Selection(string='Event type', selection=[ + ('sent', 'Sent'), + ('delivered', 'Delivered'), + ('deferral', 'Deferral'), + ('hard_bounce', 'Hard bounce'), + ('soft_bounce', 'Soft bounce'), + ('open', 'Open'), + ('click', 'Clicked'), + ('spam', 'Spam'), + ('unsub', 'Unsubscribed'), + ('reject', 'Rejected'), + ], readonly=True) + smtp_server = fields.Char(string='SMTP server', readonly=True) + url = fields.Char(string='Clicked URL', readonly=True) + ip = fields.Char(string='User IP', readonly=True) + user_agent = fields.Char(string='User agent', readonly=True) + mobile = fields.Boolean(string='Is mobile?', readonly=True) + os_family = fields.Char(string='Operating system family', readonly=True) + ua_family = fields.Char(string='User agent family', readonly=True) + ua_type = fields.Char(string='User agent type', readonly=True) + user_country_id = fields.Many2one(string='User country', readonly=True, + comodel_name='res.country') + error_type = fields.Char(string='Error type', readonly=True) + error_description = fields.Char(string='Error description', readonly=True) + error_details = fields.Text(string='Error details', readonly=True) + + @api.multi + @api.depends('time') + def _compute_date(self): + for email in self: + email.date = fields.Date.to_string( + fields.Date.from_string(email.time)) + + def _process_data(self, tracking_email, metadata, event_type, state): + ts = time.time() + dt = datetime.utcfromtimestamp(ts) + return { + 'recipient': metadata.get('recipient', tracking_email.recipient), + 'timestamp': metadata.get('timestamp', ts), + 'time': metadata.get('time', fields.Datetime.to_string(dt)), + 'date': metadata.get('date', fields.Date.to_string(dt)), + 'tracking_email_id': tracking_email.id, + 'event_type': event_type, + 'ip': metadata.get('ip', False), + 'url': metadata.get('url', False), + 'user_agent': metadata.get('user_agent', False), + 'mobile': metadata.get('mobile', False), + 'os_family': metadata.get('os_family', False), + 'ua_family': metadata.get('ua_family', False), + 'ua_type': metadata.get('ua_type', False), + 'user_country_id': metadata.get('user_country_id', False), + 'error_type': metadata.get('error_type', False), + 'error_description': metadata.get('error_description', False), + 'error_details': metadata.get('error_details', False), + } + + def _process_status(self, tracking_email, metadata, event_type, state): + tracking_email.sudo().write({'state': state}) + return self._process_data(tracking_email, metadata, event_type, state) + + def _process_bounce(self, tracking_email, metadata, event_type, state): + tracking_email.sudo().write({ + 'state': state, + 'bounce_type': metadata.get('bounce_type', False), + 'bounce_description': metadata.get('bounce_description', False), + }) + return self._process_data(tracking_email, metadata, event_type, state) + + @api.model + def process_delivered(self, tracking_email, metadata): + return self._process_status( + tracking_email, metadata, 'delivered', 'delivered') + + @api.model + def process_deferral(self, tracking_email, metadata): + return self._process_status( + tracking_email, metadata, 'deferral', 'deferred') + + @api.model + def process_hard_bounce(self, tracking_email, metadata): + return self._process_bounce( + tracking_email, metadata, 'hard_bounce', 'bounced') + + @api.model + def process_soft_bounce(self, tracking_email, metadata): + return self._process_bounce( + tracking_email, metadata, 'soft_bounce', 'soft-bounced') + + @api.model + def process_open(self, tracking_email, metadata): + return self._process_status(tracking_email, metadata, 'open', 'opened') + + @api.model + def process_click(self, tracking_email, metadata): + return self._process_status( + tracking_email, metadata, 'click', 'opened') + + @api.model + def process_spam(self, tracking_email, metadata): + return self._process_status(tracking_email, metadata, 'spam', 'spam') + + @api.model + def process_unsub(self, tracking_email, metadata): + return self._process_status(tracking_email, metadata, 'unsub', 'unsub') + + @api.model + def process_reject(self, tracking_email, metadata): + return self._process_status( + tracking_email, metadata, 'reject', 'rejected') diff --git a/mail_tracking/models/res_partner.py b/mail_tracking/models/res_partner.py new file mode 100644 index 00000000..d4ae19de --- /dev/null +++ b/mail_tracking/models/res_partner.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, api, fields + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + tracking_email_ids = fields.Many2many( + string="Tracking emails", comodel_name="mail.tracking.email", + readonly=True) + tracking_emails_count = fields.Integer( + string="Tracking emails count", store=True, readonly=True, + compute="_compute_tracking_emails_count") + email_score = fields.Float( + string="Email score", + compute="_compute_email_score", store=True, readonly=True) + + @api.one + @api.depends('tracking_email_ids.state') + def _compute_email_score(self): + self.email_score = self.tracking_email_ids.email_score() + + @api.one + @api.depends('tracking_email_ids') + def _compute_tracking_emails_count(self): + self.tracking_emails_count = self.env['mail.tracking.email'].\ + search_count([ + ('recipient_address', '=ilike', self.email) + ]) + + @api.multi + def write(self, vals): + email = vals.get('email') + if email is not None: + vals['tracking_email_ids'] = \ + self.env['mail.tracking.email']._tracking_ids_to_write(email) + return super(ResPartner, self).write(vals) diff --git a/mail_tracking/security/ir.model.access.csv b/mail_tracking/security/ir.model.access.csv new file mode 100644 index 00000000..ab17dc33 --- /dev/null +++ b/mail_tracking/security/ir.model.access.csv @@ -0,0 +1,5 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_mail_tracking_email_group_user","mail_tracking_email group_user","model_mail_tracking_email","base.group_user",1,0,0,0 +"access_mail_tracking_event_group_user","mail_tracking_event group_user","model_mail_tracking_event","base.group_user",1,0,0,0 +"access_mail_tracking_email_group_system","mail_tracking_email group_system","model_mail_tracking_email","base.group_system",1,1,1,1 +"access_mail_tracking_event_group_system","mail_tracking_event group_system","model_mail_tracking_event","base.group_system",1,1,1,1 diff --git a/mail_tracking/static/description/icon.png b/mail_tracking/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c1af495578ff7ae76542a5b3b88f7087de9ed771 GIT binary patch literal 5896 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 + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). */ + +.mail_tracking span { + color: #909090; +} +.mail_tracking_pointer { + cursor: pointer; +} + +.mail_tracking span.mail_tracking_opened { + color: #a34a8b; +} diff --git a/mail_tracking/static/src/img/delivered.png b/mail_tracking/static/src/img/delivered.png new file mode 100644 index 0000000000000000000000000000000000000000..25f980343ea39b87dac3f8b5efde781636abd9be GIT binary patch literal 285 zcmeAS@N?(olHy`uVBq!ia0vp^;y^6G!3HG%>OYYHQfx`y?k)`fL2$v|<&%LToCO|{ z#X!0Ngc;9=%`yiv*h@TpUD+S7u?xzxW?c5q1q!Y5ba4!^IDPh#E!QCfnYNGfUo7z6 zes7t&!23nb(+i8g3+SEWlXI9O6KmCVWoc{B?}=^#@h2v=|NpF}_$N_pVva$!&Bo&; zEYfG#Tyx(t-OMO#jAodeaIt={dFZ$dN={x6;_*eJJI9-h585>S a)ysGG@7nXy{c0G{)eN4lelF{r5}E+4UT`S@ literal 0 HcmV?d00001 diff --git a/mail_tracking/static/src/img/error.png b/mail_tracking/static/src/img/error.png new file mode 100644 index 0000000000000000000000000000000000000000..e8e114ae54673d6cb75e4d1363652f8839bc584f GIT binary patch literal 257 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?- zQl#xr}0AEPxQRV<$_l6`p zt_uvNCH_ZF{GD{Yr#oiOx(;VM#R$*y2LxtLxVqzVi`UBck$>gTe~DWM4f70p@M literal 0 HcmV?d00001 diff --git a/mail_tracking/static/src/img/opened.png b/mail_tracking/static/src/img/opened.png new file mode 100644 index 0000000000000000000000000000000000000000..a5ce70f1954c2d979bfb347b95ba54db886053d0 GIT binary patch literal 368 zcmeAS@N?(olHy`uVBq!ia0vp^;y^6G!3HG%>OYYHQfx`y?k)`fL2$v|<&%LToCO|{ z#X!0Ngc;9=%`yiv*h@TpUD+S7u?s3nUzW@S$^Z3qaSX9IefIJ~ucHYf2R`0!bL`GN zxQsu+Sb~SS`Hq3^_8Br9QeSOFYFb4%aq3H5l9T|;v$?LmWMPrWg zseR5pw~>2}j>>e2#MO>5Ng^ViVhL$`XLZLg!y|Cp%;n&xaW>P2?- z1`uXEA2!Pz$dD{?jVKAuPb(=;EJ|f4FE7{2%*!rLPAo{(%P&fw{mw=TsA#dLi(`mI z@6yQ|c@G(gxZD?1adAFw=5xR(U;~e=ZFWGg0i$q$gLAowg;AkQ`;AMccKg+9BjdNN zwA`#YVad~!#wD^Jrj$&&l2BdJVEaJhxYUgUwo|kdxJ~L0=qE65V9UFI+SovzyIp=y z$*HiQrs5_A%P9{OI@~3^m~N{@cuk7iAu6I0`NMs}M4m&P3X@_Q-8r}Q{@NBesiF04 gc~IH?YwJFzopr04zdgF#rGn literal 0 HcmV?d00001 diff --git a/mail_tracking/static/src/img/unknown.png b/mail_tracking/static/src/img/unknown.png new file mode 100644 index 0000000000000000000000000000000000000000..c17c681e737282f7f588b50ac3a000441d96ade9 GIT binary patch literal 425 zcmV;a0apHrP) zuRDO8vnZ0VhF9bt>@{-IH&?(%MdCY-v5rk#qFuy~sv=c^)gpL|{^}3K2^a8L2?- zMi6F{6|A@nWJs2{MwA5SrERCLqR#WBR9 zckN_bz9t8O*8PeiDqrLpjs#RQ^(CAR-P0^`=Rood1zpkfjm9N?teaC}1AGc5P2XVr zS?=@Z?p2SNZ!n8qU@mvg-&Zs3y + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). */ + +(function ($, window, document) { + 'use strict'; + + openerp.mail_tracking = function (instance) { + var _t = instance.web._t, + _lt = instance.web._lt; + var QWeb = instance.web.qweb; + var mail_orig = instance.mail; + var mail_inherit = function() { + instance.mail.MessageCommon.include({ + init: function (parent, datasets, options) { + this._super(parent, datasets, options); + this.partner_trackings = datasets.partner_trackings || []; + } + }); + instance.mail.ThreadMessage.include({ + bind_events: function () { + this._super(); + this.$('.oe_mail_action_tracking').on('click', this.on_tracking_status_clicked); + }, + on_tracking_status_clicked: function (event) { + event.preventDefault(); + var tracking_email_id = $(event.delegateTarget).data('tracking'); + var state = { + 'model': 'mail.tracking.email', + 'id': tracking_email_id, + 'title': _t("Message tracking"), + }; + instance.webclient.action_manager.do_push_state(state); + console.log('tracking_email_id = ' + tracking_email_id); + var action = { + type:'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: 'mail.tracking.email', + views: [[false, 'form']], + target: 'new', + res_id: tracking_email_id, + }; + this.do_action(action); + } + }); + }; + + // Tricky way to guarantee that this module is loaded always + // after mail module. + // When --load=web,mail_tracking is specified in init script, then + // web and mail_tracking are the first modules to load in JS + if (instance.mail.MessageCommon === undefined) { + instance.mail = function(instance) { + instance.mail = mail_orig; + instance.mail(instance, instance.mail); + mail_inherit(); + }; + } else { + mail_inherit(); + } + }; + +}(window.jQuery, window, document)); diff --git a/mail_tracking/static/src/xml/mail_tracking.xml b/mail_tracking/static/src/xml/mail_tracking.xml new file mode 100644 index 00000000..3d37216c --- /dev/null +++ b/mail_tracking/static/src/xml/mail_tracking.xml @@ -0,0 +1,61 @@ + + + diff --git a/mail_tracking/tests/__init__.py b/mail_tracking/tests/__init__.py new file mode 100644 index 00000000..ce3de1c8 --- /dev/null +++ b/mail_tracking/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# flake8: noqa + +from . import test_mail_tracking diff --git a/mail_tracking/tests/test_mail_tracking.py b/mail_tracking/tests/test_mail_tracking.py new file mode 100644 index 00000000..816a6bef --- /dev/null +++ b/mail_tracking/tests/test_mail_tracking.py @@ -0,0 +1,135 @@ +# -*- coding: utf-8 -*- +# © 2016 Antonio Espinosa - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import mock +import base64 +from openerp.tests.common import TransactionCase +from openerp.addons.mail_tracking.controllers.main import \ + MailTrackingController, BLANK + +mock_request = 'openerp.http.request' +mock_send_email = ('openerp.addons.base.ir.ir_mail_server.' + 'ir_mail_server.send_email') + + +class FakeUserAgent(object): + browser = 'Test browser' + platform = 'Test platform' + + def __str__(self): + """Return name""" + return 'Test suite' + + +# One test case per method +class TestMailTracking(TransactionCase): + # Use case : Prepare some data for current test case + def setUp(self): + super(TestMailTracking, self).setUp() + self.sender = self.env['res.partner'].create({ + 'name': 'Test sender', + 'email': 'sender@example.com', + 'notify_email': 'always', + }) + self.recipient = self.env['res.partner'].create({ + 'name': 'Test recipient', + 'email': 'recipient@example.com', + 'notify_email': 'always', + }) + self.request = { + 'httprequest': type('obj', (object,), { + 'remote_addr': '123.123.123.123', + 'user_agent': FakeUserAgent(), + }), + } + + def test_message_post(self): + # This message will generate a notification for recipient + message = self.env['mail.message'].create({ + 'subject': 'Message test', + 'author_id': self.sender.id, + 'email_from': self.sender.email, + 'type': 'comment', + 'model': 'res.partner', + 'res_id': self.recipient.id, + 'partner_ids': [(4, self.recipient.id)], + 'body': '

This is a test message

', + }) + # Search tracking created + tracking_email = self.env['mail.tracking.email'].search([ + ('mail_message_id', '=', message.id), + ('partner_id', '=', self.recipient.id), + ]) + # The tracking email must be sent + self.assertTrue(tracking_email) + self.assertEqual(tracking_email.state, 'sent') + # message_dict read by web interface + message_dict = self.env['mail.message'].message_read(message.id) + # First item is message content + self.assertTrue(len(message_dict) > 0) + message_dict = message_dict[0] + self.assertTrue(len(message_dict['partner_ids']) > 0) + # First partner is recipient + partner_id = message_dict['partner_ids'][0][0] + self.assertEqual(partner_id, self.recipient.id) + status = message_dict['partner_trackings'][str(partner_id)] + # Tracking status must be sent and + # mail tracking must be the one search before + self.assertEqual(status[0], 'sent') + self.assertEqual(status[1], tracking_email.id) + # And now open the email + metadata = { + 'ip': '127.0.0.1', + 'user_agent': 'Odoo Test/1.0', + 'os_family': 'linux', + 'ua_family': 'odoo', + } + tracking_email.event_create('open', metadata) + self.assertEqual(tracking_email.state, 'opened') + + def mail_send(self): + mail = self.env['mail.mail'].create({ + 'subject': 'Test subject', + 'email_from': 'from@domain.com', + 'email_to': 'to@domain.com', + 'body_html': '

This is a test message

', + }) + mail.send() + # Search tracking created + tracking_email = self.env['mail.tracking.email'].search([ + ('mail_id', '=', mail.id), + ]) + return mail, tracking_email + + def test_mail_send(self): + controller = MailTrackingController() + db = self.env.cr.dbname + image = base64.decodestring(BLANK) + mail, tracking = self.mail_send() + self.assertEqual(mail.email_to, tracking.recipient) + self.assertEqual(mail.email_from, tracking.sender) + with mock.patch(mock_request) as mock_func: + mock_func.return_value = type('obj', (object,), self.request) + res = controller.mail_tracking_open(db, tracking.id) + self.assertEqual(image, res.response[0]) + + def test_smtp_error(self): + with mock.patch(mock_send_email) as mock_func: + mock_func.side_effect = Warning('Test error') + mail, tracking = self.mail_send() + self.assertEqual('error', tracking.state) + self.assertEqual('Warning', tracking.error_type) + self.assertEqual('Test error', tracking.error_description) + + def test_db(self): + db = self.env.cr.dbname + controller = MailTrackingController() + with mock.patch(mock_request) as mock_func: + mock_func.return_value = type('obj', (object,), self.request) + not_found = controller.mail_tracking_all('not_found_db') + self.assertEqual('NOT FOUND', not_found.response[0]) + none = controller.mail_tracking_all(db) + self.assertEqual('NONE', none.response[0]) + none = controller.mail_tracking_event(db, 'open') + self.assertEqual('NONE', none.response[0]) diff --git a/mail_tracking/views/assets.xml b/mail_tracking/views/assets.xml new file mode 100644 index 00000000..6e737fbb --- /dev/null +++ b/mail_tracking/views/assets.xml @@ -0,0 +1,19 @@ + + + + + +