diff --git a/daemon_utils.py b/daemon_utils.py index 3068611be..9ffc6e51b 100644 --- a/daemon_utils.py +++ b/daemon_utils.py @@ -36,7 +36,6 @@ from utils import get_instance_url from utils import remove_html from utils import get_locked_account from utils import post_summary_contains_links -from utils import local_only_is_local from utils import get_local_network_addresses from utils import has_object_dict from utils import get_nickname_from_actor @@ -44,6 +43,7 @@ from utils import get_domain_from_actor from utils import get_actor_from_post from utils import has_actor from utils import resembles_url +from flags import local_only_is_local from flags import is_system_account from cache import check_for_changed_actor from cache import get_person_from_cache diff --git a/flags.py b/flags.py index 326824fbe..18a61033a 100644 --- a/flags.py +++ b/flags.py @@ -13,6 +13,8 @@ from timeFunctions import date_utcnow from timeFunctions import get_published_date from timeFunctions import date_from_string_format from timeFunctions import date_epoch +from utils import get_full_domain +from utils import get_domain_from_actor from utils import acct_dir from utils import data_dir from utils import get_config_param @@ -680,3 +682,40 @@ def can_reply_to(base_dir: str, nickname: str, domain: str, hours_since_publication >= reply_interval_hours: return False return True + + +def local_only_is_local(message_json: {}, domain_full: str) -> bool: + """Returns True if the given json post is verified as local only + """ + if message_json['object']['localOnly'] is not True: + return True + + # check that the to addresses are local + if isinstance(message_json['object']['to'], list): + for to_actor in message_json['object']['to']: + to_domain, to_port = \ + get_domain_from_actor(to_actor) + if not to_domain: + continue + to_domain_full = \ + get_full_domain(to_domain, to_port) + if domain_full != to_domain_full: + print("REJECT: inbox " + + "local only post isn't local " + + str(message_json)) + return False + + # check that the sender is local + attrib_field = message_json['object']['attributedTo'] + local_actor = get_attributed_to(attrib_field) + local_domain, local_port = \ + get_domain_from_actor(local_actor) + if local_domain: + local_domain_full = \ + get_full_domain(local_domain, local_port) + if domain_full != local_domain_full: + print("REJECT: " + + "inbox local only post isn't local " + + str(message_json)) + return False + return True diff --git a/utils.py b/utils.py index dbd008b1e..6c0d04e56 100644 --- a/utils.py +++ b/utils.py @@ -3842,43 +3842,6 @@ def resembles_url(text: str) -> bool: return False -def local_only_is_local(message_json: {}, domain_full: str) -> bool: - """Returns True if the given json post is verified as local only - """ - if message_json['object']['localOnly'] is not True: - return True - - # check that the to addresses are local - if isinstance(message_json['object']['to'], list): - for to_actor in message_json['object']['to']: - to_domain, to_port = \ - get_domain_from_actor(to_actor) - if not to_domain: - continue - to_domain_full = \ - get_full_domain(to_domain, to_port) - if domain_full != to_domain_full: - print("REJECT: inbox " + - "local only post isn't local " + - str(message_json)) - return False - - # check that the sender is local - attrib_field = message_json['object']['attributedTo'] - local_actor = get_attributed_to(attrib_field) - local_domain, local_port = \ - get_domain_from_actor(local_actor) - if local_domain: - local_domain_full = \ - get_full_domain(local_domain, local_port) - if domain_full != local_domain_full: - print("REJECT: " + - "inbox local only post isn't local " + - str(message_json)) - return False - return True - - def post_summary_contains_links(message_json: {}) -> bool: """check if the json post summary contains links """