Merge branch 'main' of ssh://code.freedombone.net:2222/bashrc/epicyon into main

main
Bob Mottram 2021-03-12 12:18:37 +00:00
commit a5936185f5
23 changed files with 82 additions and 61 deletions

View File

@ -16,6 +16,8 @@ from utils import loadJson
from utils import fileLastModified
from utils import getLinkPrefixes
from utils import dangerousMarkup
from utils import isPGPEncrypted
from utils import containsPGPPublicKey
from petnames import getPetName
@ -65,8 +67,7 @@ def _removeQuotesWithinQuotes(content: str) -> str:
def htmlReplaceEmailQuote(content: str) -> str:
"""Replaces an email style quote "> Some quote" with html blockquote
"""
if '--BEGIN PGP MESSAGE--' in content or \
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
if isPGPEncrypted(content) or containsPGPPublicKey(content):
return content
# replace quote paragraph
if '<p>&quot;' in content:
@ -109,8 +110,7 @@ def htmlReplaceQuoteMarks(content: str) -> str:
"""Replaces quotes with html formatting
"hello" becomes <q>hello</q>
"""
if '--BEGIN PGP MESSAGE--' in content or \
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
if isPGPEncrypted(content) or containsPGPPublicKey(content):
return content
if '"' not in content:
if '&quot;' not in content:
@ -203,8 +203,7 @@ def dangerousCSS(filename: str, allowLocalNetworkAccess: bool) -> bool:
def switchWords(baseDir: str, nickname: str, domain: str, content: str) -> str:
"""Performs word replacements. eg. Trump -> The Orange Menace
"""
if '--BEGIN PGP MESSAGE--' in content or \
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
if isPGPEncrypted(content) or containsPGPPublicKey(content):
return content
switchWordsFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/replacewords.txt'
@ -591,8 +590,7 @@ def _addMention(wordStr: str, httpPrefix: str, following: str, petnames: str,
def replaceContentDuplicates(content: str) -> str:
"""Replaces invalid duplicates within content
"""
if '--BEGIN PGP MESSAGE--' in content or \
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
if isPGPEncrypted(content) or containsPGPPublicKey(content):
return content
while '<<' in content:
content = content.replace('<<', '<')
@ -605,8 +603,7 @@ def replaceContentDuplicates(content: str) -> str:
def removeTextFormatting(content: str) -> str:
"""Removes markup for bold, italics, etc
"""
if '--BEGIN PGP MESSAGE--' in content or \
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
if isPGPEncrypted(content) or containsPGPPublicKey(content):
return content
if '<' not in content:
return content
@ -625,8 +622,7 @@ def removeLongWords(content: str, maxWordLength: int,
"""Breaks up long words so that on mobile screens this doesn't
disrupt the layout
"""
if '--BEGIN PGP MESSAGE--' in content or \
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
if isPGPEncrypted(content) or containsPGPPublicKey(content):
return content
content = replaceContentDuplicates(content)
if ' ' not in content:

View File

@ -17,6 +17,7 @@ from utils import saveJson
from utils import getNicknameFromActor
from utils import getDomainFromActor
from utils import getFullDomain
from utils import isPGPEncrypted
from session import createSession
from speaker import getSpeakerFromServer
from speaker import getSpeakerPitch
@ -31,7 +32,6 @@ from announce import sendAnnounceViaServer
from pgp import pgpDecrypt
from pgp import hasLocalPGPkey
from pgp import pgpEncryptToActor
from pgp import isPGPEncrypted
def _waitForKeypress(timeout: int, debug: bool) -> str:
@ -373,7 +373,7 @@ def _notificationNewDM(session, toHandle: str,
def _storeMessage(speakerJson: {}) -> None:
"""Stores a message for later reading
"""Stores a message in your home directory for later reading
"""
if not speakerJson.get('published'):
return
@ -549,6 +549,8 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str,
if speakerJson.get('content'):
if not encryptedMessage:
content = speakerJson['content']
else:
content = '🔓 ' + messageStr
# say the speaker's name
_sayCommand(nameStr, nameStr, screenreader,

20
pgp.py
View File

@ -10,6 +10,8 @@ import os
import subprocess
from pathlib import Path
from person import getActorJson
from utils import containsPGPPublicKey
from utils import isPGPEncrypted
def getEmailAddress(actorJson: {}) -> str:
@ -369,24 +371,6 @@ def pgpEncryptToActor(content: str, toHandle: str) -> str:
return _pgpEncrypt(content, recipientPubKey)
def isPGPEncrypted(content: str) -> bool:
"""Returns true if the given content is PGP encrypted
"""
if '--BEGIN PGP MESSAGE--' in content:
if '--END PGP MESSAGE--' in content:
return True
return False
def containsPGPPublicKey(content: str) -> bool:
"""Returns true if the given content contains a PGP public key
"""
if '--BEGIN PGP PUBLIC KEY BLOCK--' in content:
if '--END PGP PUBLIC KEY BLOCK--' in content:
return True
return False
def pgpDecrypt(content: str, fromHandle: str) -> str:
""" Encrypt using your default pgp key to the given recipient
fromHandle can be a handle or actor url

View File

@ -21,6 +21,7 @@ from utils import removeHtml
from utils import loadJson
from utils import saveJson
from utils import getFullDomain
from utils import isPGPEncrypted
from content import htmlReplaceQuoteMarks
speakerRemoveChars = ('.\n', '. ', ',', ';', '?', '!')
@ -413,7 +414,7 @@ def _postToSpeakerJson(baseDir: str, httpPrefix: str,
content = urllib.parse.unquote_plus(postJsonObject['object']['content'])
content = html.unescape(content)
content = content.replace('<p>', '').replace('</p>', ' ')
if '--BEGIN PGP MESSAGE--' not in content:
if not isPGPEncrypted(content):
# replace some emoji before removing html
if ' <3' in content:
content = content.replace(' <3', ' ' + translate['heart'])

View File

@ -52,6 +52,8 @@ from utils import getStatusNumber
from utils import getFollowersOfPerson
from utils import removeHtml
from utils import dangerousMarkup
from pgp import extractPGPPublicKey
from utils import containsPGPPublicKey
from follow import followerOfPerson
from follow import unfollowAccount
from follow import unfollowerOfAccount
@ -102,8 +104,6 @@ from mastoapiv1 import getNicknameFromMastoApiV1Id
from webapp_post import prepareHtmlPostNickname
from webapp_utils import markdownToHtml
from speaker import speakerReplaceLinks
from pgp import extractPGPPublicKey
from pgp import containsPGPPublicKey
testServerAliceRunning = False
testServerBobRunning = False

View File

@ -400,5 +400,6 @@
"heart": "قلب",
"counselor": "مستشار",
"Counselors": "المستشارين",
"shocked": "صدمت"
"shocked": "صدمت",
"Encrypted": "مشفر"
}

View File

@ -400,5 +400,6 @@
"heart": "cor",
"counselor": "conseller",
"Counselors": "Consellers",
"shocked": "sorprès"
"shocked": "sorprès",
"Encrypted": "Xifrat"
}

View File

@ -400,5 +400,6 @@
"heart": "galon",
"counselor": "cynghorydd",
"Counselors": "Cynghorwyr",
"shocked": "sioc"
"shocked": "sioc",
"Encrypted": "Amgryptio"
}

View File

@ -400,5 +400,6 @@
"heart": "herz",
"counselor": "Beraterin",
"Counselors": "Berater",
"shocked": "schockiert"
"shocked": "schockiert",
"Encrypted": "Verschlüsselt"
}

View File

@ -400,5 +400,6 @@
"heart": "heart",
"counselor": "counselor",
"Counselors": "Counselors",
"shocked": "shocked"
"shocked": "shocked",
"Encrypted": "Encrypted"
}

View File

@ -400,5 +400,6 @@
"heart": "corazón",
"counselor": "Consejera",
"Counselors": "Consejeras",
"shocked": "conmocionada"
"shocked": "conmocionada",
"Encrypted": "Cifrada"
}

View File

@ -400,5 +400,6 @@
"heart": "cœur",
"counselor": "Conseillère",
"Counselors": "Conseillères",
"shocked": "sous le choc"
"shocked": "sous le choc",
"Encrypted": "Crypté"
}

View File

@ -400,5 +400,6 @@
"heart": "chroí",
"counselor": "Comhairleoir",
"Counselors": "Comhairleoirí",
"shocked": "ionadh"
"shocked": "ionadh",
"Encrypted": "Criptithe"
}

View File

@ -400,5 +400,6 @@
"heart": "दिल",
"counselor": "काउंसलर",
"Counselors": "सलाहकार",
"shocked": "हैरान"
"shocked": "हैरान",
"Encrypted": "को गोपित"
}

View File

@ -400,5 +400,6 @@
"heart": "cuore",
"counselor": "Consulente",
"Counselors": "Consiglieri",
"shocked": "scioccata"
"shocked": "scioccata",
"Encrypted": "Crittografato"
}

View File

@ -400,5 +400,6 @@
"heart": "ハート",
"counselor": "カウンセラー",
"Counselors": "カウンセラー",
"shocked": "ショックを受けた"
"shocked": "ショックを受けた",
"Encrypted": "暗号化"
}

View File

@ -400,5 +400,6 @@
"heart": "dil",
"counselor": "Pêşnîyarvan",
"Counselors": "Selêwirmendan",
"shocked": "şok kirin"
"shocked": "şok kirin",
"Encrypted": "Encîfre kirin"
}

View File

@ -396,5 +396,6 @@
"heart": "heart",
"counselor": "Counselors",
"Counselors": "Counselors",
"shocked": "shocked"
"shocked": "shocked",
"Encrypted": "Encrypted"
}

View File

@ -400,5 +400,6 @@
"heart": "coração",
"counselor": "Conselheira",
"Counselors": "Conselheiras",
"shocked": "chocada"
"shocked": "chocada",
"Encrypted": "Criptografada"
}

View File

@ -400,5 +400,6 @@
"heart": "сердце",
"counselor": "Советник",
"Counselors": "Советники",
"shocked": "потрясенный"
"shocked": "потрясенный",
"Encrypted": "Зашифрованный"
}

View File

@ -400,5 +400,6 @@
"heart": "心",
"counselor": "顾问",
"Counselors": "辅导员",
"shocked": "震惊的"
"shocked": "震惊的",
"Encrypted": "加密的"
}

View File

@ -2130,3 +2130,21 @@ def isReply(postJsonObject: {}, actor: str) -> bool:
if actor in tag['href']:
return True
return False
def containsPGPPublicKey(content: str) -> bool:
"""Returns true if the given content contains a PGP public key
"""
if '--BEGIN PGP PUBLIC KEY BLOCK--' in content:
if '--END PGP PUBLIC KEY BLOCK--' in content:
return True
return False
def isPGPEncrypted(content: str) -> bool:
"""Returns true if the given content is PGP encrypted
"""
if '--BEGIN PGP MESSAGE--' in content:
if '--END PGP MESSAGE--' in content:
return True
return False

View File

@ -21,6 +21,7 @@ from posts import postIsMuted
from posts import getPersonBox
from posts import downloadAnnounce
from posts import populateRepliesJson
from utils import isPGPEncrypted
from utils import isDM
from utils import rejectPostId
from utils import isRecentPost
@ -1570,6 +1571,7 @@ def individualPostAsHtml(allowDownloads: bool,
_logPostTiming(enableTimingLog, postStartTime, '16')
if not isPGPEncrypted(postJsonObject['object']['content']):
if not isPatch:
objectContent = \
removeLongWords(postJsonObject['object']['content'], 40, [])
@ -1581,6 +1583,8 @@ def individualPostAsHtml(allowDownloads: bool,
else:
objectContent = \
postJsonObject['object']['content']
else:
objectContent = '🔒 ' + translate['Encrypted']
objectContent = '<article>' + objectContent + '</article>'