diff --git a/.gitignore b/.gitignore index e4d6245..adffc7d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__/ bulletins.db venv/ .venv +.idea diff --git a/command_handlers.py b/command_handlers.py index 0f7e008..c247133 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -41,7 +41,7 @@ def handle_exit_command(sender_id, interface): def handle_help_command(sender_id, interface, state=None): - title = "█▓▒░ TC² BBS ░▒▓█\n" + title = "TC2 BBS\n" commands = [ "[M]ail Menu", "[B]ulletin Menu", diff --git a/config.ini b/config.ini index 3dc354f..b953fd1 100644 --- a/config.ini +++ b/config.ini @@ -17,7 +17,7 @@ [interface] type = serial -# port = /dev/ttyUSB0 +# port = /dev/ttyACM0 # hostname = 192.168.x.x diff --git a/db_operations.py b/db_operations.py index 2325bb7..0f366c7 100644 --- a/db_operations.py +++ b/db_operations.py @@ -132,17 +132,16 @@ def get_mail_content(mail_id, recipient_id): return c.fetchone() def delete_mail(unique_id, recipient_id, bbs_nodes, interface): - # TODO: ensure only recipient can delete mail - logging.info(f"Attempting to delete mail with unique_id: {unique_id} by {recipient_id}") conn = get_db_connection() c = conn.cursor() try: - c.execute("SELECT unique_id FROM mail WHERE unique_id = ? and recipient = ?", (unique_id, recipient_id,)) + c.execute("SELECT recipient FROM mail WHERE unique_id = ?", (unique_id,)) result = c.fetchone() - logging.debug(f"Fetch result for unique_id {unique_id}: {result}") if result is None: logging.error(f"No mail found with unique_id: {unique_id}") return # Early exit if no matching mail found + recipient_id = result[0] + logging.info(f"Attempting to delete mail with unique_id: {unique_id} by {recipient_id}") c.execute("DELETE FROM mail WHERE unique_id = ? and recipient = ?", (unique_id, recipient_id,)) conn.commit() send_delete_mail_to_bbs_nodes(unique_id, bbs_nodes, interface) @@ -150,3 +149,5 @@ def delete_mail(unique_id, recipient_id, bbs_nodes, interface): except Exception as e: logging.error(f"Error deleting mail with unique_id {unique_id}: {e}") raise + + diff --git a/message_processing.py b/message_processing.py index 88a18ce..1efc252 100644 --- a/message_processing.py +++ b/message_processing.py @@ -9,7 +9,7 @@ from command_handlers import ( handle_channel_directory_command, handle_channel_directory_steps ) -from db_operations import add_bulletin, add_mail, delete_bulletin, delete_mail +from db_operations import add_bulletin, add_mail, delete_bulletin, delete_mail, get_db_connection from utils import get_user_state, get_node_short_name, get_node_id_from_num, send_message command_handlers = { @@ -47,7 +47,8 @@ def process_message(sender_id, message, interface, is_sync_message=False): elif message.startswith("DELETE_MAIL|"): unique_id = message.split("|")[1] logging.info(f"Processing delete mail with unique_id: {unique_id}") - delete_mail(unique_id, [], interface) + recipient_id = get_recipient_id_by_mail(unique_id) # Fetch the recipient_id using this helper function + delete_mail(unique_id, recipient_id, [], interface) else: if message_lower in command_handlers: command_handlers[message_lower](sender_id, interface) @@ -95,3 +96,13 @@ def on_receive(packet, interface): logging.info("Ignoring message sent to group chat or from unknown node") except KeyError as e: logging.error(f"Error processing packet: {e}") + +def get_recipient_id_by_mail(unique_id): + # Fix for Mail Delete sync issue + conn = get_db_connection() + c = conn.cursor() + c.execute("SELECT recipient FROM mail WHERE unique_id = ?", (unique_id,)) + result = c.fetchone() + if result: + return result[0] + return None