diff --git a/bemade_helpdesk_mailcow_blacklist/__manifest__.py b/bemade_helpdesk_mailcow_blacklist/__manifest__.py
index 72bdabf..9aad068 100644
--- a/bemade_helpdesk_mailcow_blacklist/__manifest__.py
+++ b/bemade_helpdesk_mailcow_blacklist/__manifest__.py
@@ -6,12 +6,10 @@
'summary': 'Module for adding blacklist functionality to the helpdesk.',
'description': """
Helpdesk Mailcow Blacklist
- ==========================
This module extends the functionality of the Helpdesk and Mailcow Blacklist modules by adding an action to blacklist the sender of a Helpdesk ticket.
Main Features:
- --------------
- Adds a button on Helpdesk tickets to blacklist the email sender.
- This button is only visible when an email is associated with the ticket.
- Blacklisting an email sender automatically moves the Helpdesk ticket to a new 'Spam' stage, which is marked as closed.
@@ -21,9 +19,12 @@
'license': 'GPL-3',
'author': 'Bemade',
'website': 'https://www.bemade.org',
- 'depends': ['helpdesk', 'bemade_mailcow_blacklist'],
+ 'depends': [
+ 'helpdesk',
+ 'bemade_mailcow_integration'
+ ],
'data': [
- 'security/ir.model.access.csv',
+ # 'security/ir.model.access.csv',
'data/helpdesk_stages.xml',
'views/helpdesk_ticket_views.xml',
],
diff --git a/bemade_helpdesk_mailcow_blacklist/data/helpdesk_stages.xml b/bemade_helpdesk_mailcow_blacklist/data/helpdesk_stages.xml
index 3656b40..3ff0278 100644
--- a/bemade_helpdesk_mailcow_blacklist/data/helpdesk_stages.xml
+++ b/bemade_helpdesk_mailcow_blacklist/data/helpdesk_stages.xml
@@ -4,7 +4,7 @@
Spam
50
- True
+ True
diff --git a/bemade_helpdesk_mailcow_blacklist/models/helpdesk_ticket.py b/bemade_helpdesk_mailcow_blacklist/models/helpdesk_ticket.py
index 5ca307f..c98ae98 100644
--- a/bemade_helpdesk_mailcow_blacklist/models/helpdesk_ticket.py
+++ b/bemade_helpdesk_mailcow_blacklist/models/helpdesk_ticket.py
@@ -1,16 +1,19 @@
from odoo import api, fields, models
from odoo.exceptions import UserError
-
+import re
class HelpdeskTicket(models.Model):
_inherit = 'helpdesk.ticket'
- def add_blacklist(self):
+ def action_add_blacklist(self):
self.ensure_one()
+ email_regex = r'<([^<>]+)>'
+
+ email_to_blacklist = re.findall(email_regex, self.email)[0]
# Create a new blacklist record
- blacklist = self.env['mailcow.blacklist'].create({
- 'email': self.email,
+ blacklist = self.env['mail.mailcow.blacklist'].create({
+ 'email': email_to_blacklist,
})
# Assign 'spam' as a closed stage
diff --git a/bemade_helpdesk_mailcow_blacklist/views/helpdesk_ticket_views.xml b/bemade_helpdesk_mailcow_blacklist/views/helpdesk_ticket_views.xml
index fb2fde7..cc02fe6 100644
--- a/bemade_helpdesk_mailcow_blacklist/views/helpdesk_ticket_views.xml
+++ b/bemade_helpdesk_mailcow_blacklist/views/helpdesk_ticket_views.xml
@@ -6,7 +6,7 @@
diff --git a/bemade_mailcow_integration/__manifest__.py b/bemade_mailcow_integration/__manifest__.py
index a076e1a..91e81e3 100644
--- a/bemade_mailcow_integration/__manifest__.py
+++ b/bemade_mailcow_integration/__manifest__.py
@@ -6,22 +6,24 @@
'summary': 'Module for integrating Mailcow email server with Odoo.',
'description': """
Mailcow Integration
- ===================
This module integrates the Mailcow email server with Odoo, providing a seamless email communication solution for your Odoo instance. It allows for syncing of mailboxes and email aliases from Mailcow to Odoo and vice versa.
Main Features:
- --------------
- * Synchronize Mailcow mailboxes with Odoo users.
- * Synchronize Mailcow email aliases with Odoo.
- * Configuration of Mailcow API credentials in Odoo settings.
- * Automatically create and manage mailboxes and aliases in Mailcow when they are created in Odoo.
+ Synchronize Mailcow mailboxes with Odoo users.
+ Synchronize Mailcow email aliases with Odoo.
+ Configuration of Mailcow API credentials in Odoo settings.
+ Automatically create and manage mailboxes and aliases in Mailcow when they are created in Odoo.
""",
'sequence': 10,
'license': 'GPL-3',
'author': 'Bemade',
'website': 'https://www.bemade.org',
- 'depends': ['hr', 'mail', 'bemade_user_password_bundle'],
+ 'depends': [
+ 'hr',
+ 'mail',
+ 'bemade_user_password_bundle'
+ ],
'data': [
'security/ir.model.access.csv',
'views/res_config_settings_views.xml',
@@ -32,10 +34,10 @@
],
"assets": {
"web.assets_backend": [
- "bemade_mailcow_blacklist/static/src/js/mailcow.js",
+ "bemade_mailcow_integration/static/src/js/mailcow.js",
],
"web.assets_qweb": [
- "bemade_mailcow_blacklist/static/src/xml/mailcow_templates.xml",
+ "bemade_mailcow_integration/static/src/xml/mailcow_templates.xml",
],
},
'demo': [],
diff --git a/bemade_mailcow_integration/models/mailcow.py b/bemade_mailcow_integration/models/mailcow.py
index 009d1eb..6f38c64 100644
--- a/bemade_mailcow_integration/models/mailcow.py
+++ b/bemade_mailcow_integration/models/mailcow.py
@@ -16,10 +16,8 @@ class MailMailcow(models.AbstractModel):
def get_credentials(self):
params = self.env['ir.config_parameter'].sudo()
- base_url = params.get_param('mailcow.base_url'),
- base_url = base_url[0]
- api_key = params.get_param('mailcow.api_key'),
- api_key = api_key[0]
+ base_url = params.get_param('mailcow.base_url')[0],
+ api_key = params.get_param('mailcow.api_key')[0],
if not base_url or not api_key:
_logger.error('No API key or base URL is set in the system parameters')
diff --git a/bemade_mailcow_integration/models/mailcow_blacklist.py b/bemade_mailcow_integration/models/mailcow_blacklist.py
index 6d00525..374e7b6 100644
--- a/bemade_mailcow_integration/models/mailcow_blacklist.py
+++ b/bemade_mailcow_integration/models/mailcow_blacklist.py
@@ -18,20 +18,26 @@ class MailcowBlacklist(models.Model):
"""
Overridden create method to add the new blacklist entry to the Mailcow server.
"""
- res = super().create(vals)
domain = self.env['ir.config_parameter'].sudo().get_param('mail.catchall.domain')
endpoint_add = '/api/v1/add/domain-policy'
endpoint_get_bl = f"/api/v1/get/policy_bl_domain/{domain}"
data = {
'domain': domain,
- 'object_from': res.email,
+ 'object_from': vals['email'],
'object_list': 'bl'
}
- res.api_request(endpoint_add, 'POST', data)
+
+
+
+ self.api_request(endpoint_add, 'POST', data)
_logger.info(f'Added {vals["email"]} to Mailcow blacklist')
- res.api_request(endpoint_get_bl, 'GET', None)
+ allblemail = self.api_request(endpoint_get_bl, 'GET', None)
+
+ mc_id = [d['prefid'] for d in allblemail if d['value'] == vals['email']]
+ vals['mc_id'] = mc_id[0]
+ res = super().create(vals)
return res
@@ -60,11 +66,12 @@ class MailcowBlacklist(models.Model):
Overridden unlink method to remove the blacklist entry from the Mailcow server.
"""
for record in self:
- endpoint = '/api/v1/delete/blacklist'
+ endpoint = '/api/v1/delete/domain-policy'
data = {
- 'items': [record.email]
+ 'items': [record.mc_id]
}
- record.api_request(endpoint, 'POST', data)
+ result = record.api_request(endpoint, 'POST', data)
+ print(result)
_logger.info(f'Removed {record.email} from Mailcow blacklist')
return super().unlink()
diff --git a/bemade_mailcow_integration/views/mailcow_mailbox_views.xml b/bemade_mailcow_integration/views/mailcow_mailbox_views.xml
index cef6200..fc233fd 100644
--- a/bemade_mailcow_integration/views/mailcow_mailbox_views.xml
+++ b/bemade_mailcow_integration/views/mailcow_mailbox_views.xml
@@ -57,7 +57,7 @@
+ web_icon="bemade_mailcow_integration,static/description/icon.png"/>