Browse Source
[11.0] [MIG] [fetchmail_notify_error_to_sender] - readme, tests, fix template tech. msg issue
pull/1306/head
[11.0] [MIG] [fetchmail_notify_error_to_sender] - readme, tests, fix template tech. msg issue
pull/1306/head
Nedas
6 years ago
committed by
Pedro M. Baeza
7 changed files with 101 additions and 77 deletions
-
77fetchmail_notify_error_to_sender/README.rst
-
2fetchmail_notify_error_to_sender/data/email_template_data.xml
-
4fetchmail_notify_error_to_sender/readme/CONFIGURE.rst
-
4fetchmail_notify_error_to_sender/readme/CONTRIBUTORS.rst
-
10fetchmail_notify_error_to_sender/readme/DESCRIPTION.rst
-
3fetchmail_notify_error_to_sender/tests/__init__.py
-
78fetchmail_notify_error_to_sender/tests/test_fetchmail_notify_error_to_sender.py
@ -1,76 +1 @@ |
|||
.. 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 |
|||
|
|||
================================ |
|||
Fetchmail Notify Error to Sender |
|||
================================ |
|||
|
|||
If fetchmail is not able to correctly route an email, the email is |
|||
"silently" lost (you get an error message in server log). |
|||
|
|||
For example, if you configure odoo mail system to route received emails |
|||
according to recipient address, it may happen users send emails to wrong |
|||
email address. |
|||
|
|||
This module extends the functionality of fetchmail to allow you to |
|||
automatically send a notification email to sender, when odoo can't |
|||
correctly process the received email. |
|||
|
|||
|
|||
Configuration |
|||
============= |
|||
|
|||
To configure this module, you need to: |
|||
|
|||
#. Configure your fetchmail server setting 'Error notice template' = 'Fetchmail - error notice'. |
|||
#. You can edit the 'Fetchmail - error notice' email template according to your needs. |
|||
|
|||
.. figure:: path/to/local/image.png |
|||
:alt: alternative description |
|||
:width: 600 px |
|||
|
|||
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/149/11.0 |
|||
|
|||
Bug Tracker |
|||
=========== |
|||
|
|||
Bugs are tracked on `GitHub Issues |
|||
<https://github.com/OCA/server-tools/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 |
|||
------ |
|||
|
|||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
|||
* Miquel Raïch <miquel.raich@eficent.com> (migration to v9 and v10) |
|||
* Hai Dinh <haidd.uit@gmail.com> (migration to V11) |
|||
|
|||
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. |
|||
**This file is going to be generated by oca-gen-addon-readme.** |
@ -0,0 +1,4 @@ |
|||
To configure this module, you need to: |
|||
|
|||
#. Configure your fetchmail server setting 'Error notice template' = 'Fetchmail - error notice'. |
|||
#. You can edit the 'Fetchmail - error notice' email template according to your needs. |
@ -0,0 +1,4 @@ |
|||
* Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
|||
* Miquel Raïch <miquel.raich@eficent.com> (migration to v9 and v10) |
|||
* Hai Dinh <haidd.uit@gmail.com> (migration to V11) |
|||
* Nedas Zilinskas <nedas.zilinskas@xpansa.com> (Ventor, Xpansa Group <https://ventor.tech/>) |
@ -0,0 +1,10 @@ |
|||
If fetchmail is not able to correctly route an email, the email is |
|||
"silently" lost (you get an error message in server log). |
|||
|
|||
For example, if you configure odoo mail system to route received emails |
|||
according to recipient address, it may happen users send emails to wrong |
|||
email address. |
|||
|
|||
This module extends the functionality of fetchmail to allow you to |
|||
automatically send a notification email to sender, when odoo can't |
|||
correctly process the received email. |
@ -0,0 +1,3 @@ |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from . import test_fetchmail_notify_error_to_sender |
@ -0,0 +1,78 @@ |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
|
|||
import socket |
|||
from odoo.addons.mail.tests.common import TestMail |
|||
from odoo.addons.mail.tests.test_mail_gateway import MAIL_TEMPLATE |
|||
from odoo.tools import mute_logger |
|||
|
|||
|
|||
class TestFetchmailNotifyErrorToSender(TestMail): |
|||
|
|||
def setUp(self): |
|||
super(TestFetchmailNotifyErrorToSender, self).setUp() |
|||
|
|||
self.fetchmail_server = self.env['fetchmail.server'].create({ |
|||
'name': 'Test Fetchmail Server', |
|||
'type': 'imap', |
|||
'error_notice_template_id': self.env.ref('%s.%s' % ( |
|||
'fetchmail_notify_error_to_sender', |
|||
'email_template_error_notice', |
|||
)).id |
|||
}) |
|||
|
|||
def format_and_process_with_context( |
|||
self, template, to_email='groups@example.com, other@gmail.com', |
|||
subject='Frogs', extra='', |
|||
email_from='Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>', |
|||
cc_email='', |
|||
msg_id='<1198923581.41972151344608186760.JavaMail@agrolait.com>', |
|||
model=None, target_model='mail.test', target_field='name', ctx=False, |
|||
): |
|||
self.assertFalse(self.env[target_model].search([ |
|||
(target_field, '=', subject), |
|||
])) |
|||
mail = template.format( |
|||
to=to_email, |
|||
subject=subject, |
|||
cc=cc_email, |
|||
extra=extra, |
|||
email_from=email_from, |
|||
msg_id=msg_id, |
|||
) |
|||
self.env['mail.thread'].with_context(ctx or {}).message_process( |
|||
model, |
|||
mail, |
|||
) |
|||
return self.env[target_model].search([(target_field, '=', subject)]) |
|||
|
|||
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models') |
|||
def test_message_process(self): |
|||
email_from = 'valid.lelitre@agrolait.com' |
|||
|
|||
count_return_mails_before = self.env['mail.mail'].search_count([ |
|||
('email_to', '=', email_from), |
|||
]) |
|||
|
|||
with self.assertRaises(ValueError): |
|||
self.format_and_process_with_context( |
|||
MAIL_TEMPLATE, |
|||
email_from=email_from, |
|||
to_email='noone@example.com', |
|||
subject='spam', |
|||
extra='In-Reply-To: <12321321-openerp-%d-mail.test@%s>' % ( |
|||
self.test_public.id, |
|||
socket.gethostname(), |
|||
), |
|||
ctx={ |
|||
'fetchmail_server_id': self.fetchmail_server.id, |
|||
} |
|||
) |
|||
|
|||
count_return_mails_after = self.env['mail.mail'].search_count([ |
|||
('email_to', '=', email_from), |
|||
]) |
|||
self.assertEqual( |
|||
count_return_mails_after, |
|||
count_return_mails_before + 1, |
|||
) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue