-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
438 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from html import unescape | ||
from typing import Literal | ||
|
||
import frappe | ||
from frappe import _ | ||
|
||
from mail_server.mail_server.doctype.spam_check_log.spam_check_log import create_spam_check_log | ||
|
||
|
||
@frappe.whitelist(methods=["POST"], allow_guest=True) | ||
def scan(message: str) -> dict: | ||
"""Returns the spam score, spamd response and scanning mode of the message""" | ||
|
||
message = get_unescaped_message(message) | ||
spam_log = create_spam_check_log(message) | ||
return { | ||
"spam_score": spam_log.spam_score, | ||
"spamd_response": spam_log.spamd_response, | ||
"scanning_mode": spam_log.scanning_mode, | ||
} | ||
|
||
|
||
@frappe.whitelist(methods=["POST"], allow_guest=True) | ||
def is_spam(message: str, message_type: Literal["Inbound", "Outbound"] = "Outbound") -> bool: | ||
"""Returns True if the message is spam else False""" | ||
|
||
message = get_unescaped_message(message) | ||
spam_log = create_spam_check_log(message) | ||
return spam_log.is_spam(message_type) | ||
|
||
|
||
@frappe.whitelist(methods=["POST"], allow_guest=True) | ||
def get_spam_score(message: str) -> float: | ||
"""Returns the spam score of the message""" | ||
|
||
message = get_unescaped_message(message) | ||
spam_log = create_spam_check_log(message) | ||
return spam_log.spam_score | ||
|
||
|
||
def get_unescaped_message(message: str) -> str: | ||
"""Returns the unescaped message""" | ||
|
||
return unescape(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
8 changes: 8 additions & 0 deletions
8
mail_server/mail_server/doctype/spam_check_log/spam_check_log.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors | ||
// For license information, please see license.txt | ||
|
||
// frappe.ui.form.on("Spam Check Log", { | ||
// refresh(frm) { | ||
|
||
// }, | ||
// }); |
162 changes: 162 additions & 0 deletions
162
mail_server/mail_server/doctype/spam_check_log/spam_check_log.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
{ | ||
"actions": [], | ||
"allow_rename": 1, | ||
"autoname": "hash", | ||
"creation": "2024-10-11 14:41:45.624692", | ||
"doctype": "DocType", | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"section_break_vtj1", | ||
"source_ip_address", | ||
"column_break_9x8t", | ||
"source_host", | ||
"section_break_opob", | ||
"spamd_response", | ||
"column_break_c5vz", | ||
"scanning_mode", | ||
"hybrid_scanning_threshold", | ||
"spam_score", | ||
"section_break_5qon", | ||
"started_at", | ||
"completed_at", | ||
"column_break_svei", | ||
"duration", | ||
"section_break_o1qt", | ||
"message" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "section_break_vtj1", | ||
"fieldtype": "Section Break" | ||
}, | ||
{ | ||
"fieldname": "source_ip_address", | ||
"fieldtype": "Data", | ||
"in_list_view": 1, | ||
"label": "Source IP Address", | ||
"no_copy": 1, | ||
"read_only": 1 | ||
}, | ||
{ | ||
"fieldname": "column_break_9x8t", | ||
"fieldtype": "Column Break" | ||
}, | ||
{ | ||
"fieldname": "source_host", | ||
"fieldtype": "Data", | ||
"in_list_view": 1, | ||
"label": "Source Host", | ||
"no_copy": 1, | ||
"read_only": 1 | ||
}, | ||
{ | ||
"fieldname": "section_break_opob", | ||
"fieldtype": "Section Break" | ||
}, | ||
{ | ||
"fieldname": "spamd_response", | ||
"fieldtype": "Code", | ||
"label": "Response", | ||
"no_copy": 1, | ||
"read_only": 1 | ||
}, | ||
{ | ||
"fieldname": "column_break_c5vz", | ||
"fieldtype": "Column Break" | ||
}, | ||
{ | ||
"fieldname": "scanning_mode", | ||
"fieldtype": "Data", | ||
"in_list_view": 1, | ||
"label": "Scanning Mode", | ||
"no_copy": 1, | ||
"read_only": 1 | ||
}, | ||
{ | ||
"depends_on": "eval: doc.scanning_mode == \"Hybrid Approach\"", | ||
"fieldname": "hybrid_scanning_threshold", | ||
"fieldtype": "Float", | ||
"label": "Hybrid Scanning Threshold", | ||
"no_copy": 1, | ||
"precision": "1", | ||
"read_only": 1 | ||
}, | ||
{ | ||
"fieldname": "spam_score", | ||
"fieldtype": "Float", | ||
"in_list_view": 1, | ||
"label": "Spam Score", | ||
"no_copy": 1, | ||
"precision": "1", | ||
"read_only": 1 | ||
}, | ||
{ | ||
"fieldname": "section_break_5qon", | ||
"fieldtype": "Section Break" | ||
}, | ||
{ | ||
"fieldname": "started_at", | ||
"fieldtype": "Datetime", | ||
"label": "Started At", | ||
"no_copy": 1, | ||
"read_only": 1 | ||
}, | ||
{ | ||
"fieldname": "completed_at", | ||
"fieldtype": "Datetime", | ||
"label": "Completed At", | ||
"no_copy": 1, | ||
"read_only": 1 | ||
}, | ||
{ | ||
"fieldname": "column_break_svei", | ||
"fieldtype": "Column Break" | ||
}, | ||
{ | ||
"depends_on": "eval: doc.started_at && doc.completed_at", | ||
"fieldname": "duration", | ||
"fieldtype": "Float", | ||
"in_list_view": 1, | ||
"label": "Duration (Seconds)", | ||
"no_copy": 1, | ||
"read_only": 1 | ||
}, | ||
{ | ||
"fieldname": "section_break_o1qt", | ||
"fieldtype": "Section Break" | ||
}, | ||
{ | ||
"fieldname": "message", | ||
"fieldtype": "Code", | ||
"label": "Message", | ||
"no_copy": 1, | ||
"read_only": 1 | ||
} | ||
], | ||
"in_create": 1, | ||
"index_web_pages_for_search": 1, | ||
"links": [], | ||
"modified": "2024-10-18 19:02:13.151207", | ||
"modified_by": "Administrator", | ||
"module": "Mail Server", | ||
"name": "Spam Check Log", | ||
"naming_rule": "Random", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"export": 1, | ||
"print": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "System Manager", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"sort_field": "creation", | ||
"sort_order": "DESC", | ||
"states": [] | ||
} |
Oops, something went wrong.