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:
"""Does the given text look like a url?
"""
if '://' in text and \
'.' in text and \
' ' not in text and \
'<' not in text:
if '://' in text and '.' in text and \
' ' not in text and '<' not in text:
return True
return False
@ -5409,34 +5407,37 @@ def resembles_url(text: 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
"""
if message_json['object']['localOnly'] is 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 " +
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