Browse Source

ADD mail_notify_bounce

pull/243/head
eLBati 7 years ago
committed by Holger Brunn
parent
commit
6a060c7d32
  1. 69
      mail_notify_bounce/README.rst
  2. 5
      mail_notify_bounce/__init__.py
  3. 21
      mail_notify_bounce/__manifest__.py
  4. 6
      mail_notify_bounce/models/__init__.py
  5. 11
      mail_notify_bounce/models/fetchmail.py
  6. 87
      mail_notify_bounce/models/mail_thread.py
  7. BIN
      mail_notify_bounce/static/description/icon.png
  8. 5
      mail_notify_bounce/tests/__init__.py
  9. 243
      mail_notify_bounce/tests/data/bounce_message
  10. 39
      mail_notify_bounce/tests/test_mail_notify_bounce.py
  11. 15
      mail_notify_bounce/views/fetchmail_view.xml

69
mail_notify_bounce/README.rst

@ -0,0 +1,69 @@
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: https://www.gnu.org/licenses/lgpl
:alt: License: LGPL-3
====================
Notify bounce emails
====================
In case of bounced email messages retrieved by fetchmail, sender of original message will be notified. Also, it is possible to configure email addresses to be notified about bounced emails.
Typical use case:
- User configures a partner with a wrong email address
- User sends a message to that partner
- User gets notified about wrong email address
In some cases (see `https://github.com/odoo/odoo/issues/21119
<https://github.com/odoo/odoo/issues/21119>`_.), these messages are silently discarded by odoo, so users don't know about possible failures.
Also, even when bounce messages are correctly fetched by odoo, the sender, or other people, will not be notified.
Configuration
=============
To configure additional recipients of bounced emails, you can open fetchmail server form and fill 'Notify bounce emails to' field
Usage
=====
.. 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/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/social/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
=======
Images
------
* Icon made by those-icons from https://www.flaticon.com/authors/those-icons
Contributors
------------
* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
Do not contact contributors directly about support or help with technical issues.
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

5
mail_notify_bounce/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from . import models

21
mail_notify_bounce/__manifest__.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Notify bounce emails",
"summary": "Notify bounce emails to preconfigured addresses",
"version": "10.0.1.0.0",
"category": "Mail",
"website": "https://github.com/OCA/social",
"author": "Agile Business Group, Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": [
"fetchmail",
],
"data": [
"views/fetchmail_view.xml",
],
}

6
mail_notify_bounce/models/__init__.py

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from . import fetchmail
from . import mail_thread

11
mail_notify_bounce/models/fetchmail.py

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from odoo import models, fields
class FetchmailServer(models.Model):
_inherit = 'fetchmail.server'
bounce_notify_partner_ids = fields.Many2many(
'res.partner', string='Notify bounce emails to')

87
mail_notify_bounce/models/mail_thread.py

@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
import logging
from odoo import models, api, tools, _
_logger = logging.getLogger(__name__)
class MailThread(models.AbstractModel):
_inherit = 'mail.thread'
@api.model
def notify_bounce_partners(self, message, fetchmail, message_dict):
message_id = message.get('Message-Id')
email_from = tools.decode_message_header(message, 'From')
email_from_localpart = (
(
tools.email_split(email_from) or ['']
)[0].split('@', 1)[0].lower()
)
# same criteria used by odoo
# see addons/mail/models/mail_thread.py
if (
message.get_content_type() == 'multipart/report' or
email_from_localpart == 'mailer-daemon'
):
references = tools.decode_message_header(message, 'References')
in_reply_to = tools.decode_message_header(
message, 'In-Reply-To').strip()
thread_references = references or in_reply_to
msg_references = [
ref for ref in
tools.mail_header_msgid_re.findall(thread_references) if
'reply_to' not in ref
]
MailMessage = self.env['mail.message']
mail_messages = MailMessage.sudo().search([
('message_id', 'in', msg_references)], limit=1)
recipients = mail_messages.mapped('author_id')
recipients |= fetchmail.bounce_notify_partner_ids
if not recipients:
_logger.info(
'Not notifying bounce email from %s with Message-Id %s: '
'no recipients found',
email_from, message_id
)
return
_logger.info(
'Notifying bounce email from %s with Message-Id %s',
email_from, message_id
)
email = self.env['mail.mail'].create({
'body_html': (
u"%s<br/><br/><br/>%s<br/><br/>%s"
% (
unicode(message_dict['body'], errors='replace'),
_("Raw message:"),
unicode(message.__str__(), errors='replace').replace(
"\n", "<br/>")
)),
'subject': message_dict['subject'],
'recipient_ids': [
(6, 0, [p.id for p in recipients])
]
})
email.send()
@api.model
def message_route(
self, message, message_dict, model=None, thread_id=None,
custom_values=None
):
if self.env.context.get('fetchmail_server_id'):
fetchmail = self.env['fetchmail.server'].browse(
self.env.context['fetchmail_server_id'])
self.notify_bounce_partners(message, fetchmail, message_dict)
return super(MailThread, self).message_route(
message=message, message_dict=message_dict, model=model,
thread_id=thread_id, custom_values=custom_values
)

BIN
mail_notify_bounce/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 2.1 KiB

5
mail_notify_bounce/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from . import test_mail_notify_bounce

243
mail_notify_bounce/tests/data/bounce_message

@ -0,0 +1,243 @@
Delivered-To: support@agilebg.com
Received: by 10.80.142.237 with SMTP id x42csp662854edx;
Tue, 13 Mar 2018 03:25:12 -0700 (PDT)
X-Received: by 10.28.217.213 with SMTP id q204mr246173wmg.141.1520936712614;
Tue, 13 Mar 2018 03:25:12 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1520936712; cv=none;
d=google.com; s=arc-20160816;
b=qbz1vQti1TNpvFCsZ3oTK/NIA1yd7l5SDqjVtAExKOkroR8+NmbDVISr2K0T/+sK0e
WdDQD33xDCJJXct74JCj7fK+r0JJzv0GDhbMT9lU5W/eSBHqzvrbAxMXPKXog6xYabFh
GrIke9W/HwnN3qztgMAEbD0yVb3as3/DFhp2dRcJwPFf/zu/0RHxIzLRFs/7OzUc+bVc
KIWXkDOWduHwGX7MAyCS0R3/whTmkxardwUQuytNclN65OLURU0aU9ACNJ0WQSzRC6wX
oOEB/WjMdirTbv+mm4ZMI0d45fpH9xhQ6cCrzumXpc3sLdBXL86It54OEM/8AclQ32Vy
A+LQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
h=date:message-id:in-reply-to:references:subject:auto-submitted:to
:from:dkim-signature:arc-authentication-results;
bh=dMVfhTfiY+WIHZkvVKWnGHTG12r2Aw1JK67YJWXZEHc=;
b=tejri4tYrPpIZAr4xgujZQNaHIxNFnQ+Pi9W6z3X09n37kRtnET9Bdsg+tlg1Io6zc
c4hC1eTCNEyNq4LYUM++nngwRpgFFqFdb6R0O9b3pmGru0XdO2xF0/uwtJGmIVnDM3n3
rmr+7gsi9JF/Et0J8Sle7CIsqXsrKcKRv06SwfTjikSHlKWHegS9EP3p3oVv2eTcwwWz
Rz7QupEM3clvNn32qaUjvdnOJkpRP8iQ/9RoDNfFcrOzaL3bgk3xWZ2wZAsOdCr5MF5p
ihN5XKpJhOtaByodI+McJtJUP0w7tVtOJ9pu+Jgr6N543zHM95oymMvaccU8sXTIi2aO
Ds7A==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=@googlemail.com header.s=20161025 header.b=YYg5WZz/;
spf=pass (google.com: best guess record for domain of postmaster@mail-sor-f69.google.com designates 209.85.220.69 as permitted sender) smtp.helo=mail-sor-f69.google.com;
dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com
Return-Path: <>
Received: from mail-sor-f69.google.com (mail-sor-f69.google.com. [209.85.220.69])
by mx.google.com with SMTPS id j4sor60079wmi.79.2018.03.13.03.25.12
for <support@agilebg.com>
(Google Transport Security);
Tue, 13 Mar 2018 03:25:12 -0700 (PDT)
Received-SPF: pass (google.com: best guess record for domain of postmaster@mail-sor-f69.google.com designates 209.85.220.69 as permitted sender) client-ip=209.85.220.69;
Authentication-Results: mx.google.com;
dkim=pass header.i=@googlemail.com header.s=20161025 header.b=YYg5WZz/;
spf=pass (google.com: best guess record for domain of postmaster@mail-sor-f69.google.com designates 209.85.220.69 as permitted sender) smtp.helo=mail-sor-f69.google.com;
dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlemail.com; s=20161025;
h=from:to:auto-submitted:subject:references:in-reply-to:message-id
:date;
bh=dMVfhTfiY+WIHZkvVKWnGHTG12r2Aw1JK67YJWXZEHc=;
b=YYg5WZz/fxHVm3S7KhH7Q3SmGSIwsFJYJrQzs3ZMLywKytJrXGatFipeRbDvfWIdvt
EeLwNna6r6mMeWWWST/p9ZktwEvdQ3b8BB7qzHnv6knTxldpB6y/J06bI40xgr/NnP6y
C87zqlBMOwGuYw1tDUkfCcwXTz/bz50blhtmd4Iz1Q1oZbTgMAMVTsjIyCJexANP/0dh
s56QktPnpBHH86bKNxi/BG0Yv2ShROf/42HO1iEIHxlhYU/Sr1CIwrfwBy4J4NwAp+Ae
K8pBl/MO0pUeM/3ANn4mrApDK1+oqpYWJvXxzv+YigZJxeWfYJ9wESC2PLV6bS8tDJSW
yQTg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:from:to:auto-submitted:subject:references
:in-reply-to:message-id:date;
bh=dMVfhTfiY+WIHZkvVKWnGHTG12r2Aw1JK67YJWXZEHc=;
b=ncoceBRXPA6alPEdKWega4icd2pN6Bi+jacNSHpG2DgKYSEMSoAwwHPOglbrZqWPSs
M3YNYbF6/Eyx3HlY1fhtbh+0XkJU0z2/2FQcU/YCnA6sQ2IU4usztMv3LLv5XvYHt7MM
hRR2e5h1E6obIPKXhBroYf3nyRNCE6HU+OwE/GnLeNeyWCkBhCLfNZKUJbNHpEpHt3sw
7jveCrDsnoeOf3Apx9hKqbEpaVY1j83ZXd8Xlgh3TKpaLWTkJ7kXpjWI1dtyoHu2gqDa
eAYNugD7LEf/Z4eqAscxDh1BGLoP08nnSuNOLFp2vSllOOJ9lrn4j+7oNh2kH5rqCo5p
Bsng==
X-Gm-Message-State: AElRT7HLs9wf2hitIMHNLIfimcazh71cW/FEbkyUsTU7RxS/X/F91dLP 6bBRDO9/IVMugWthex/F5ETZimzvqruF11fKqp8mEQ==
X-Google-Smtp-Source: AG47ELvXcyNHPl+/aUdcgG+CzQeXrs6eiMf+ZMiUhyKwChcSc4RVtQp8GCoTITDyrD8DFPmc3XUPXWoqXdygX6xt4XSc4Il/Zw+ygz4=
X-Received: by 10.28.106.19 with SMTP id f19mr289852wmc.84.1520936712492;
Tue, 13 Mar 2018 03:25:12 -0700 (PDT)
Content-Type: multipart/report; boundary="089e082ce1a07949ad056748acaf"; report-type=delivery-status
Return-Path: <>
Received: by 10.28.106.19 with SMTP id f19mr318417wmc.84; Tue, 13 Mar 2018 03:25:12 -0700 (PDT)
From: Mail Delivery Subsystem <mailer-daemon@googlemail.com>
To: support@agilebg.com
Auto-Submitted: auto-replied
Subject: Delivery Status Notification (Failure)
References: <1520936710.340821981430054.404664939598865-openerp-7-res.partner@elbati-Vostro-3550>
In-Reply-To: <1520936710.340821981430054.404664939598865-openerp-7-res.partner@elbati-Vostro-3550>
X-Failed-Recipients: jj@jj.pink
Message-ID: <5aa7a708.136a1c0a.1b2fb.07f5.GMRIR@mx.google.com>
Date: Tue, 13 Mar 2018 03:25:12 -0700 (PDT)
--089e082ce1a07949ad056748acaf
Content-Type: multipart/related; boundary="089e082ce1a07950b2056748acb0"
--089e082ce1a07950b2056748acb0
Content-Type: multipart/alternative; boundary="089e082ce1a07950c1056748acb1"
--089e082ce1a07950c1056748acb1
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
** Indirizzo non trovato **
Il tuo messaggio per jj@jj.pink non è stato recapitato perchè il =
dominio jj.pink risulta inesistente. Verifica di non aver inserito errori d=
i battitura o spazi superflui e riprova.
Risposta:
DNS Error: 21006586 DNS type 'mx' lookup of jj.pink responded with code NXD=
OMAIN
Domain name not found: jj.pink
--089e082ce1a07950c1056748acb1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<style>
* {
font-family:Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
</style>
</head>
<body>
<table cellpadding=3D"0" cellspacing=3D"0" class=3D"email-wrapper" style=3D=
"padding-top:32px;background-color:#ffffff;"><tbody>
<tr><td>
<table cellpadding=3D0 cellspacing=3D0><tbody>
<tr><td style=3D"max-width:560px;padding:24px 24px 32px;background-color:#f=
afafa;border:1px solid #e0e0e0;border-radius:2px">
<img style=3D"padding:0 24px 16px 0;float:left" width=3D72 height=3D72 alt=
=3D"Icona di errore" src=3D"cid:icon.png">
<table style=3D"min-width:272px;padding-top:8px"><tbody>
<tr><td><h2 style=3D"font-size:20px;color:#212121;font-weight:bold;margin:0=
">
Indirizzo non trovato
</h2></td></tr>
<tr><td style=3D"padding-top:20px;color:#757575;font-size:16px;font-weight:=
normal;text-align:left">
Il tuo messaggio per <a style=3D'color:#212121;text-decoration:none'><b>jj@=
jj.pink</b></a> non è stato recapitato perchè il dominio jj.pink =
risulta inesistente. Verifica di non aver inserito errori di battitura o sp=
azi superflui e riprova.
</td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</td></tr>
<tr style=3D"border:none;background-color:#fff;font-size:12.8px;width:90%">
<td align=3D"left" style=3D"padding:48px 10px">
Risposta:<br/>
<p style=3D"font-family:monospace">
DNS Error: 21006586 DNS type &#39;mx&#39; lookup of jj.pink responded with =
code NXDOMAIN
Domain name not found: jj.pink
</p>
</td>
</tr>
</tbody></table>
</body>
</html>
--089e082ce1a07950c1056748acb1--
--089e082ce1a07950b2056748acb0
Content-Type: image/png; name="icon.png"
Content-Disposition: attachment; filename="icon.png"
Content-Transfer-Encoding: base64
Content-ID: <icon.png>
--089e082ce1a07950b2056748acb0--
--089e082ce1a07949ad056748acaf
Content-Type: message/delivery-status
--089e082ce1a07949ad056748acaf
Content-Type: message/rfc822
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=agilebg-com.20150623.gappssmtp.com; s=20150623;
h=from:mime-version:message-id:subject:reply-to:to:date;
bh=JoCx/XdOebyfcX3JwqQu+w3RwEEedYScqlTnqxEbYdc=;
b=JO54Xix6Gwe2oYDyjNk/g5m1/tO5P4uV0uFG6P4wEt6ADH8WyM61eoFI1RQXVpFdtr
8F6h0gF+n6+qxWNu7W/0xroNgILJmDJYz8uM0yVlLDivt1/3YVS2+vCY4lxhfmEnQW4A
Z43steYkQdkrtDk4xa39zBwwsomJx9mViNF/diZ7919RvTzujMel5tLF8ZAUGIZvAQOX
RlVBUiBFQeY5vjBCh22/7dlnbt3aiwQDOUrM844zuxjPQrN/4DOIVXIJ5xg/akMUVCd6
G6RlJ/mwAkquhSMmo8qITJZ/SOtC1NdRn7ZM1jK9u3R4uNHA07Se85rRrR/ay9ptgFUw
wQqw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:from:mime-version:message-id:subject:reply-to:to
:date;
bh=JoCx/XdOebyfcX3JwqQu+w3RwEEedYScqlTnqxEbYdc=;
b=P3+oyRfjA7k/46qFeJlG3dwtiAiK0X+zdvJbu6tiDenD27KfhLBOh3n3cARxu8GkGg
X3nWbjd/Dp3ifjwrj43SY8qWjJrLJgREt7NiS+CSRUoVtFzzg88D95v0CUbUW1gHSFdJ
nWWMUwD9eOBQvpf6RSV3KlN3cmFTHwqDBKD9yt5mosKB/yHBKSYqIBEzVT1kWtwEFx2r
i6XTqVWrZjPxSGhF3QtKqX3emLuxdp2HGwXEgFHqK2Ckti2zwkqvnZRyclXhsjz3BCW3
B6cfziTjxnfRzClZozTOO30u+FkF7NWHeZ6SX7mkRC3iymnayRif4qs0yASNmFdWSo+Q
DPiA==
X-Gm-Message-State: AElRT7HcU/pKvDTBS+u1vpLED5d18RpMEMxDuQNGJQTybNHBL+tOFsPm r4kpiCsS45ObtQFm602vRGNTpfrY
X-Google-Smtp-Source: AG47ELuqwAATDTpeGPm3Bkd+l3Xvi+nW1YzPRybnU3Co5geAM45/LlwjsooGXjg1mt8dvHtnVDi+bA==
X-Received: by 10.28.106.19 with SMTP id f19mr289835wmc.84.1520936712169;
Tue, 13 Mar 2018 03:25:12 -0700 (PDT)
Return-Path: <support@agilebg.com>
Received: from [127.0.1.1] ([153.92.179.94])
by smtp.gmail.com with ESMTPSA id y111sm66797wrc.0.2018.03.13.03.25.10
for <jj@jj.pink>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Tue, 13 Mar 2018 03:25:11 -0700 (PDT)
From: Administrator <support@agilebg.com>
X-Google-Original-From: Administrator <admin@agilebg.com>
Content-Type: multipart/mixed; boundary="===============8882118813701652090=="
MIME-Version: 1.0
Message-Id: <1520936710.340821981430054.404664939598865-openerp-7-res.partner@elbati-Vostro-3550>
Subject: Re: jj
Reply-To: Administrator <admin@agilebg.com>
To: jj <jj@jj.pink>
Date: Tue, 13 Mar 2018 10:25:10 -0000
X-Odoo-db-uuid: b155a0e0-2612-11e8-b332-08edb9323673
X-Odoo-Objects: res.partner-7
--===============8882118813701652090==
Content-Type: multipart/alternative; boundary="===============5618999107486207453=="
MIME-Version: 1.0
--===============5618999107486207453==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
dGVzdAotLQpBZG1pbmlzdHJhdG9yCgpTZW50IGJ5Ck15IENvbXBhbnkKWzFdCnVzaW5nCk9kb28g
WzJdIC4KCgoKWzFdIGh0dHA6Ly93d3cueW91cmNvbXBhbnkuY29tClsyXSBodHRwczovL3d3dy5v
ZG9vLmNvbQo=
--===============5618999107486207453==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
PGRpdiBkYXRhLW8tbWFpbC1xdW90ZS1jb250YWluZXI9IjEiPjxwPnRlc3Q8L3A+CiAgICA8c3Bh
biBkYXRhLW8tbWFpbC1xdW90ZT0iMSI+LS0gPGJyIGRhdGEtby1tYWlsLXF1b3RlPSIxIj4KQWRt
aW5pc3RyYXRvcjwvc3Bhbj4KPGJyIGRhdGEtby1tYWlsLXF1b3RlPSIxIj4KPHAgc3R5bGU9ImNv
bG9yOiAjNTU1NTU1OyIgZGF0YS1vLW1haWwtcXVvdGU9IjEiPgogICAgU2VudCBieQogICAgPGEg
aHJlZj0iaHR0cDovL3d3dy55b3VyY29tcGFueS5jb20iIHN0eWxlPSJ0ZXh0LWRlY29yYXRpb246
bm9uZTsgY29sb3I6ICM4NzVBN0I7IiBkYXRhLW8tbWFpbC1xdW90ZT0iMSI+CiAgICBNeSBDb21w
YW55CiAgICA8L2E+CiAgICB1c2luZwogICAgPGEgaHJlZj0iaHR0cHM6Ly93d3cub2Rvby5jb20i
IHN0eWxlPSJ0ZXh0LWRlY29yYXRpb246bm9uZTsgY29sb3I6ICM4NzVBN0I7IiBkYXRhLW8tbWFp
bC1xdW90ZT0iMSI+T2RvbzwvYT4uCjwvcD4KPC9kaXY+
--===============5618999107486207453==--
--===============8882118813701652090==--
--089e082ce1a07949ad056748acaf--

39
mail_notify_bounce/tests/test_mail_notify_bounce.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
import odoo.tests.common as common
from odoo.modules.module import get_module_resource
class TestMailNotification(common.TransactionCase):
def setUp(self):
super(TestMailNotification, self).setUp()
self.fetchmail_model = self.env['fetchmail.server']
self.partner_model = self.env['res.partner']
self.thread_model = self.env['mail.thread']
def test_notify_bounce_partners(self):
admin_id = self.partner_model.search(
[('name', '=', 'Administrator')])[0].id
server = self.fetchmail_model.create({
'name': 'disabled',
'server': 'disabled',
'user': 'disabled',
'password': 'disabled',
'bounce_notify_partner_ids': [(6, 0, [admin_id])]
})
path = get_module_resource(
'mail_notify_bounce',
'tests', 'data', 'bounce_message'
)
with open(path) as bounce_message:
self.thread_model.with_context(
fetchmail_server_id=server.id
).message_process(
model='res.partner', message=bounce_message.read())
sent_mail = self.env['mail.mail'].search(
[], order="create_date desc")[0]
self.assertEqual(sent_mail.recipient_ids.name, 'Administrator')
self.assertEqual(
sent_mail.subject, 'Delivery Status Notification (Failure)')

15
mail_notify_bounce/views/fetchmail_view.xml

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<odoo>
<record id="view_email_server_form_bounce_address" model="ir.ui.view">
<field name="name">view_email_server_form_bounce_address</field>
<field name="model">fetchmail.server</field>
<field name="inherit_id" ref="fetchmail.view_email_server_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Notify bounce emails to">
<field name="bounce_notify_partner_ids"/>
</page>
</notebook>
</field>
</record>
</odoo>
Loading…
Cancel
Save