main
Bob Mottram 2024-08-05 10:34:41 +01:00
parent b2201d33f1
commit 09c2df6be1
1 changed files with 31 additions and 30 deletions

View File

@ -5398,10 +5398,8 @@ def is_valid_date(date_str: str) -> bool:
def resembles_url(text: str) -> bool: def resembles_url(text: str) -> bool:
"""Does the given text look like a url? """Does the given text look like a url?
""" """
if '://' in text and \ if '://' in text and '.' in text and \
'.' in text and \ ' ' not in text and '<' not in text:
' ' not in text and \
'<' not in text:
return True return True
return False return False
@ -5409,34 +5407,37 @@ def resembles_url(text: str) -> bool:
def local_only_is_local(message_json: {}, domain_full: str) -> bool: def local_only_is_local(message_json: {}, domain_full: str) -> bool:
"""Returns True if the given json post is verified as local only """Returns True if the given json post is verified as local only
""" """
if message_json['object']['localOnly'] is True: if message_json['object']['localOnly'] is not True:
# check that the to addresses are local return True
if isinstance(message_json['object']['to'], list):
for to_actor in message_json['object']['to']: # check that the to addresses are local
to_domain, to_port = \ if isinstance(message_json['object']['to'], list):
get_domain_from_actor(to_actor) for to_actor in message_json['object']['to']:
if not to_domain: to_domain, to_port = \
continue get_domain_from_actor(to_actor)
to_domain_full = \ if not to_domain:
get_full_domain(to_domain, to_port) continue
if domain_full != to_domain_full: to_domain_full = \
print("REJECT: inbox " + get_full_domain(to_domain, to_port)
"local only post isn't local " + if domain_full != to_domain_full:
str(message_json)) print("REJECT: inbox " +
return False "local only post isn't local " +
# 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)) str(message_json))
return False 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 return True