diff --git a/addons/hr_recruitment/models/hr_applicant.py b/addons/hr_recruitment/models/hr_applicant.py index cd8f97f95f2..18b05892aab 100644 --- a/addons/hr_recruitment/models/hr_applicant.py +++ b/addons/hr_recruitment/models/hr_applicant.py @@ -413,7 +413,8 @@ class Applicant(models.Model): return res def _email_is_blacklisted(self, mail): - return mail in [m.strip() for m in self.env['ir.config_parameter'].sudo().get_param('hr_recruitment.blacklisted_emails', '').split(',')] + normalized_mail = tools.email_normalize(mail) + return normalized_mail in [m.strip() for m in self.env['ir.config_parameter'].sudo().get_param('hr_recruitment.blacklisted_emails', '').split(',')] def get_empty_list_help(self, help_message): if 'active_id' in self.env.context and self.env.context.get('active_model') == 'hr.job': @@ -610,10 +611,12 @@ class Applicant(models.Model): defaults = { 'name': msg.get('subject') or _("No Subject"), 'partner_name': partner_name or email_from_normalized, - 'partner_id': msg.get('author_id', False), } if msg.get('from') and not self._email_is_blacklisted(msg.get('from')): defaults['email_from'] = msg.get('from') + defaults['partner_id'] = msg.get('author_id', False) + if msg.get('email_from') and self._email_is_blacklisted(msg.get('email_from')): + del msg['email_from'] if msg.get('priority'): defaults['priority'] = msg.get('priority') if stage and stage.id: diff --git a/addons/hr_recruitment/tests/test_recruitment_process.py b/addons/hr_recruitment/tests/test_recruitment_process.py index 5cbaab8eef2..215d82da040 100644 --- a/addons/hr_recruitment/tests/test_recruitment_process.py +++ b/addons/hr_recruitment/tests/test_recruitment_process.py @@ -95,3 +95,23 @@ class TestRecruitmentProcess(TestHrCommon): self.assertTrue( user.partner_id in new_application_message.notified_partner_ids ) + + def test_blacklist_providers(self): + """Test blacklisting providers feature. + In case the mail comes from the blacklisted mails list, + we should not: + - set the email_from to the newly created applicant + - create an partner for the blaclisted mail and link it + with the newly created applicant + """ + self.env['ir.config_parameter'].set_param('hr_recruitment.blacklisted_emails', + 'bla@com.com, mail-to-blacklist@gmail.com, bla1@odoo.com') + applicant = self.env['hr.applicant'].message_new({ + 'message_id': 'message_id_for_rec', + 'email_from': '"Mail to Blacklist Name" ', + 'from': '"Mail to Blacklist Name" ', + 'subject': 'CV', + 'body': 'I want to apply to your company', + }) + self.assertFalse(applicant.email_from) + self.assertFalse(applicant.partner_id)