diff --git a/fetchmail_notify_error_to_sender/README.rst b/fetchmail_notify_error_to_sender/README.rst index 3f27c836b..3f6262529 100644 --- a/fetchmail_notify_error_to_sender/README.rst +++ b/fetchmail_notify_error_to_sender/README.rst @@ -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 -`_. 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 `_. - -Contributors ------------- - -* Lorenzo Battistini -* Miquel Raïch (migration to v9 and v10) -* Hai Dinh (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. \ No newline at end of file +**This file is going to be generated by oca-gen-addon-readme.** diff --git a/fetchmail_notify_error_to_sender/data/email_template_data.xml b/fetchmail_notify_error_to_sender/data/email_template_data.xml index 2a90fad4b..d85ba35c7 100644 --- a/fetchmail_notify_error_to_sender/data/email_template_data.xml +++ b/fetchmail_notify_error_to_sender/data/email_template_data.xml @@ -17,7 +17,7 @@

Maybe you used a wrong recipient address?


Technical details:

-

${ctx.get('route_exception').message}

+

${ctx.get('route_exception')}

]]> diff --git a/fetchmail_notify_error_to_sender/readme/CONFIGURE.rst b/fetchmail_notify_error_to_sender/readme/CONFIGURE.rst new file mode 100644 index 000000000..bffe75f5e --- /dev/null +++ b/fetchmail_notify_error_to_sender/readme/CONFIGURE.rst @@ -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. diff --git a/fetchmail_notify_error_to_sender/readme/CONTRIBUTORS.rst b/fetchmail_notify_error_to_sender/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..62bb4ffa9 --- /dev/null +++ b/fetchmail_notify_error_to_sender/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Lorenzo Battistini +* Miquel Raïch (migration to v9 and v10) +* Hai Dinh (migration to V11) +* Nedas Zilinskas (Ventor, Xpansa Group ) diff --git a/fetchmail_notify_error_to_sender/readme/DESCRIPTION.rst b/fetchmail_notify_error_to_sender/readme/DESCRIPTION.rst new file mode 100644 index 000000000..b2aed0cd4 --- /dev/null +++ b/fetchmail_notify_error_to_sender/readme/DESCRIPTION.rst @@ -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. diff --git a/fetchmail_notify_error_to_sender/tests/__init__.py b/fetchmail_notify_error_to_sender/tests/__init__.py new file mode 100644 index 000000000..f6a213969 --- /dev/null +++ b/fetchmail_notify_error_to_sender/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_fetchmail_notify_error_to_sender diff --git a/fetchmail_notify_error_to_sender/tests/test_fetchmail_notify_error_to_sender.py b/fetchmail_notify_error_to_sender/tests/test_fetchmail_notify_error_to_sender.py new file mode 100644 index 000000000..65ab0bf9a --- /dev/null +++ b/fetchmail_notify_error_to_sender/tests/test_fetchmail_notify_error_to_sender.py @@ -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 ', + 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, + )