Skip to content

Commit

Permalink
refactor: use MIME Message in Spam Check Log
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Jan 7, 2025
1 parent 527cd97 commit db158b1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions mail/mail/doctype/mime_message/mime_message.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
{
"group": "Reference",
"link_doctype": "Spam Check Log",
"link_fieldname": "message"
"link_fieldname": "_message"
}
],
"modified": "2025-01-07 12:33:04.856689",
"modified": "2025-01-07 12:51:54.162433",
"modified_by": "Administrator",
"module": "Mail",
"name": "MIME Message",
Expand Down
27 changes: 13 additions & 14 deletions mail/mail/doctype/spam_check_log/spam_check_log.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
"column_break_9x8t",
"source_host",
"section_break_opob",
"spamd_response",
"column_break_c5vz",
"_message",
"scanning_mode",
"hybrid_scanning_threshold",
"spam_score",
"column_break_c5vz",
"spamd_response",
"section_break_5qon",
"started_at",
"completed_at",
"column_break_svei",
"duration",
"section_break_o1qt",
"message"
"duration"
],
"fields": [
{
Expand All @@ -33,6 +32,7 @@
"fieldname": "source_ip_address",
"fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Source IP Address",
"no_copy": 1,
"read_only": 1
Expand All @@ -45,6 +45,7 @@
"fieldname": "source_host",
"fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Source Host",
"no_copy": 1,
"read_only": 1
Expand All @@ -68,6 +69,7 @@
"fieldname": "scanning_mode",
"fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Scanning Mode",
"no_copy": 1,
"read_only": 1
Expand All @@ -85,6 +87,7 @@
"fieldname": "spam_score",
"fieldtype": "Float",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Spam Score",
"no_copy": 1,
"precision": "1",
Expand Down Expand Up @@ -122,23 +125,19 @@
"read_only": 1
},
{
"collapsible": 1,
"fieldname": "section_break_o1qt",
"fieldtype": "Section Break",
"label": "Message"
},
{
"fieldname": "message",
"fieldtype": "Code",
"fieldname": "_message",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Message",
"no_copy": 1,
"options": "MIME Message",
"read_only": 1
}
],
"in_create": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2025-01-06 14:04:19.381154",
"modified": "2025-01-07 12:55:07.324604",
"modified_by": "Administrator",
"module": "Mail",
"name": "Spam Check Log",
Expand Down
16 changes: 16 additions & 0 deletions mail/mail/doctype/spam_check_log/spam_check_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
from frappe.query_builder.functions import Now
from frappe.utils import now, time_diff_in_seconds

from mail.mail.doctype.mime_message.mime_message import (
create_mime_message,
get_mime_message,
update_mime_message,
)
from mail.utils.dns import get_host_by_ip


Expand All @@ -23,6 +28,17 @@ def clear_old_logs(days=7) -> None:
log = frappe.qb.DocType("Spam Check Log")
frappe.db.delete(log, filters=(log.creation < (Now() - Interval(days=days))))

@property
def message(self) -> str:
return get_mime_message(self._message)

@message.setter
def message(self, value: str | bytes) -> None:
if self._message:
update_mime_message(self._message, value)
else:
self._message = create_mime_message(value)

def validate(self) -> None:
if self.is_new():
self.set_source_ip_address()
Expand Down

0 comments on commit db158b1

Please sign in to comment.