diff --git a/daemon.py b/daemon.py index 82eecc40..66b28ac8 100644 --- a/daemon.py +++ b/daemon.py @@ -4853,7 +4853,7 @@ def runDaemon(enableSharedInbox: bool,registration: bool, \ instanceId: str,clientToServer: bool, \ baseDir: str,domain: str, \ port=80,proxyPort=80,httpPrefix='https', \ - fedList=[],maxMentions=10, \ + fedList=[],maxMentions=10,maxEmoji=10, \ authenticatedFetch=False, \ noreply=False,nolike=False,nopics=False, \ noannounce=False,cw=False,ocapAlways=False, \ @@ -5027,7 +5027,8 @@ def runDaemon(enableSharedInbox: bool,registration: bool, \ domain,port,useTor,httpd.federationList, \ httpd.ocapAlways,maxReplies, \ domainMaxPostsPerDay,accountMaxPostsPerDay, \ - allowDeletion,debug,maxMentions,httpd.translate, \ + allowDeletion,debug,maxMentions,maxEmoji, \ + httpd.translate, \ unitTest,httpd.acceptedCaps),daemon=True) if not unitTest: httpd.thrWatchdog= \ diff --git a/epicyon.py b/epicyon.py index 6eb7bec7..3e3a83fa 100644 --- a/epicyon.py +++ b/epicyon.py @@ -243,6 +243,8 @@ parser.add_argument('--maxreplies', dest='maxReplies', type=int,default=64, \ help='Maximum number of replies to a post') parser.add_argument('--maxMentions','--hellthread', dest='maxMentions', type=int,default=10, \ help='Maximum number of mentions within a post') +parser.add_argument('--maxEmoji','--maxemoji', dest='maxEmoji', type=int,default=10, \ + help='Maximum number of emoji within a post') parser.add_argument('--role', dest='role', type=str,default=None, \ help='Set a role for a person') parser.add_argument('--organization','--project', dest='project', type=str,default=None, \ @@ -1482,7 +1484,7 @@ runDaemon(not args.nosharedinbox, \ instanceId,args.client,baseDir, \ domain,port,proxyPort,httpPrefix, \ federationList,args.maxMentions, \ - args.authenticatedFetch, \ + args.maxEmoji,args.authenticatedFetch, \ args.noreply,args.nolike,args.nopics, \ args.noannounce,args.cw,ocapAlways, \ useTor,args.maxReplies, \ diff --git a/inbox.py b/inbox.py index ee2bb1eb..1d4df69e 100644 --- a/inbox.py +++ b/inbox.py @@ -1181,14 +1181,14 @@ def populateReplies(baseDir :str,httpPrefix :str,domain :str, \ def estimateNumberOfMentions(content: str) -> int: """Returns a rough estimate of the number of mentions """ - words=content.split(' ') - ctr=0 - for word in words: - if word.startswith('@') or '>@' in word: - ctr+=1 - return ctr + return int(content.count('@')/2) -def validPostContent(messageJson: {},maxMentions: int) -> bool: +def estimateNumberOfEmoji(content: str) -> int: + """Returns a rough estimate of the number of emoji + """ + return int(content.count(':')/2) + +def validPostContent(messageJson: {},maxMentions: int,maxEmoji: int) -> bool: """Is the content of a received post valid? Check for bad html Check for hellthreads @@ -1205,14 +1205,19 @@ def validPostContent(messageJson: {},maxMentions: int) -> bool: for badStr in invalidStrings: if badStr in messageJson['object']['content']: if messageJson['object'].get('id'): - print('REJECT: '+messageJson['object']['id']) - print('REJECT: bad string in post - '+messageJson['object']['content']) + print('REJECT ARBITRARY HTML: '+messageJson['object']['id']) + print('REJECT ARBITRARY HTML: bad string in post - '+messageJson['object']['content']) return False # check (rough) number of mentions if estimateNumberOfMentions(messageJson['object']['content'])>maxMentions: if messageJson['object'].get('id'): - print('REJECT: '+messageJson['object']['id']) - print('REJECT: Too many mentions in post - '+messageJson['object']['content']) + print('REJECT HELLTHREAD: '+messageJson['object']['id']) + print('REJECT HELLTHREAD: Too many mentions in post - '+messageJson['object']['content']) + return False + if estimateNumberOfEmoji(messageJson['object']['content'])>maxEmoji: + if messageJson['object'].get('id'): + print('REJECT EMOJI OVERLOAD: '+messageJson['object']['id']) + print('REJECT EMOJI OVERLOAD: Too many emoji in post - '+messageJson['object']['content']) return False # check number of tags if messageJson['object'].get('tag'): @@ -1476,7 +1481,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \ acceptedCaps: [], \ queueFilename :str,destinationFilename :str, \ maxReplies: int,allowDeletion: bool, \ - maxMentions: int,translate: {}, \ + maxMentions: int,maxEmoji: int,translate: {}, \ unitTest: bool) -> bool: """ Anything which needs to be done after capabilities checks have passed """ @@ -1562,7 +1567,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \ else: postJsonObject=messageJson - if validPostContent(postJsonObject,maxMentions): + if validPostContent(postJsonObject,maxMentions,maxEmoji): # list of indexes to be updated updateIndexList=['inbox'] populateReplies(baseDir,httpPrefix,domain,messageJson,maxReplies,debug) @@ -1682,7 +1687,7 @@ def runInboxQueue(projectVersion: str, \ ocapAlways: bool,maxReplies: int, \ domainMaxPostsPerDay: int,accountMaxPostsPerDay: int, \ allowDeletion: bool,debug: bool,maxMentions: int, \ - translate: {},unitTest: bool, \ + maxEmoji: int,translate: {},unitTest: bool, \ acceptedCaps=["inbox:write","objects:read"]) -> None: """Processes received items and moves them to the appropriate directories @@ -2034,7 +2039,8 @@ def runInboxQueue(projectVersion: str, \ debug,acceptedCaps, \ queueFilename,destination, \ maxReplies,allowDeletion, \ - maxMentions,translate,unitTest) + maxMentions,maxEmoji, \ + translate,unitTest) else: if debug: print('DEBUG: object capabilities check has failed') @@ -2052,7 +2058,8 @@ def runInboxQueue(projectVersion: str, \ debug,acceptedCaps, \ queueFilename,destination, \ maxReplies,allowDeletion, \ - maxMentions,translate,unitTest) + maxMentions,maxEmoji, \ + translate,unitTest) if debug: pprint(queueJson['post']) print('No capability list within post') diff --git a/tests.py b/tests.py index 2fdc7b3f..f704bf42 100644 --- a/tests.py +++ b/tests.py @@ -228,10 +228,11 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \ global testServerAliceRunning testServerAliceRunning = True maxMentions=10 + maxEmoji=10 print('Server running: Alice') runDaemon(True,True,'en',__version__, \ "instanceId",False,path,domain,port,port, \ - httpPrefix,federationList,maxMentions,False, \ + httpPrefix,federationList,maxMentions,maxEmoji,False, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \ useTor,maxReplies, \ domainMaxPostsPerDay,accountMaxPostsPerDay, \ @@ -283,10 +284,11 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \ global testServerBobRunning testServerBobRunning = True maxMentions=10 + maxEmoji=10 print('Server running: Bob') runDaemon(True,True,'en',__version__, \ "instanceId",False,path,domain,port,port, \ - httpPrefix,federationList,maxMentions,False, \ + httpPrefix,federationList,maxMentions,maxEmoji,False, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \ useTor,maxReplies, \ domainMaxPostsPerDay,accountMaxPostsPerDay, \ @@ -318,10 +320,11 @@ def createServerEve(path: str,domain: str,port: int,federationList: [], \ global testServerEveRunning testServerEveRunning = True maxMentions=10 + maxEmoji=10 print('Server running: Eve') runDaemon(True,True,'en',__version__, \ "instanceId",False,path,domain,port,port, \ - httpPrefix,federationList,maxMentions,False, \ + httpPrefix,federationList,maxMentions,maxEmoji,False, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \ useTor,maxReplies,allowDeletion,True,True,False,sendThreads)