diff --git a/changedetectionio/diff.py b/changedetectionio/diff.py index a1e58830..332f7e18 100644 --- a/changedetectionio/diff.py +++ b/changedetectionio/diff.py @@ -2,9 +2,10 @@ import difflib from typing import List, Iterator, Union # https://github.com/dgtlmoon/changedetection.io/issues/821#issuecomment-1241837050 -HTML_REMOVED_STYLE = "background-color: #ffebe9; color: #82071e" -HTML_ADDED_STYLE = "background-color: #dafbe1; color: #116329;" -HTML_CHANGED_STYLE = "background-color: #ffd8b5; color: #953800;" +HTML_ADDED_STYLE = "background-color: #d2f7c2; color: #255d00;" +HTML_CHANGED_INTO_STYLE = "background-color: #dafbe1; color: #116329;" +HTML_CHANGED_STYLE = "background-color: #ffd6cc; color: #7a2000;" +HTML_REMOVED_STYLE = "background-color: #ffebe9; color: #82071e;" # These get set to html or telegram type or discord compatible or whatever in handler.py # Something that cant get escaped to HTML by accident diff --git a/changedetectionio/notification/handler.py b/changedetectionio/notification/handler.py index d8b83dd4..cdeffd0b 100644 --- a/changedetectionio/notification/handler.py +++ b/changedetectionio/notification/handler.py @@ -8,10 +8,11 @@ from .apprise_plugin.assets import apprise_asset, APPRISE_AVATAR_URL from .apprise_plugin.custom_handlers import SUPPORTED_HTTP_METHODS from ..diff import HTML_REMOVED_STYLE, REMOVED_PLACEMARKER_OPEN, REMOVED_PLACEMARKER_CLOSED, ADDED_PLACEMARKER_OPEN, HTML_ADDED_STYLE, \ ADDED_PLACEMARKER_CLOSED, CHANGED_INTO_PLACEMARKER_OPEN, CHANGED_INTO_PLACEMARKER_CLOSED, CHANGED_PLACEMARKER_OPEN, \ - CHANGED_PLACEMARKER_CLOSED, HTML_CHANGED_STYLE + CHANGED_PLACEMARKER_CLOSED, HTML_CHANGED_STYLE, HTML_CHANGED_INTO_STYLE from ..notification_service import NotificationContextData, CUSTOM_LINEBREAK_PLACEHOLDER + def markup_text_links_to_html(body): """ Convert plaintext to HTML with clickable links. @@ -166,7 +167,7 @@ def apply_service_tweaks(url, n_body, n_title, requested_output_format): # Handle changed/replaced lines (old → new) n_body = n_body.replace(CHANGED_PLACEMARKER_OPEN, f'') n_body = n_body.replace(CHANGED_PLACEMARKER_CLOSED, f'') - n_body = n_body.replace(CHANGED_INTO_PLACEMARKER_OPEN, f'') + n_body = n_body.replace(CHANGED_INTO_PLACEMARKER_OPEN, f'') n_body = n_body.replace(CHANGED_INTO_PLACEMARKER_CLOSED, f'') n_body = n_body.replace('\n', f'{CUSTOM_LINEBREAK_PLACEHOLDER}\n') elif requested_output_format == 'html': diff --git a/changedetectionio/tests/smtp/smtp-test-server.py b/changedetectionio/tests/smtp/smtp-test-server.py index 4bb7fa6e..9fe15830 100755 --- a/changedetectionio/tests/smtp/smtp-test-server.py +++ b/changedetectionio/tests/smtp/smtp-test-server.py @@ -3,6 +3,8 @@ import threading import time from aiosmtpd.controller import Controller from flask import Flask, Response +from email import message_from_bytes +from email.policy import default # Accept a SMTP message and offer a way to retrieve the last message via HTTP @@ -27,6 +29,36 @@ class CustomSMTPHandler: print('*******************************') print(envelope.content.decode('utf8')) print('*******************************') + + # Parse the email message + msg = message_from_bytes(envelope.content, policy=default) + + # Write parts to files based on content type + if msg.is_multipart(): + for part in msg.walk(): + content_type = part.get_content_type() + payload = part.get_payload(decode=True) + + if payload: + if content_type == 'text/plain': + with open('/tmp/last.txt', 'wb') as f: + f.write(payload) + print(f'Written text/plain part to /tmp/last.txt') + elif content_type == 'text/html': + with open('/tmp/last.html', 'wb') as f: + f.write(payload) + print(f'Written text/html part to /tmp/last.html') + else: + # Single part message + content_type = msg.get_content_type() + payload = msg.get_payload(decode=True) + + if payload: + if content_type == 'text/plain' or content_type.startswith('text/'): + with open('/tmp/last.txt', 'wb') as f: + f.write(payload) + print(f'Written single part message to /tmp/last.txt') + return '250 Message accepted for delivery' finally: with smtp_lock: