This is an automated email from the ASF dual-hosted git repository. humbedooh pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
commit f59b37678d7b0ee1671c5dc63138959d06a5e28d Author: Daniel Gruno <[email protected]> AuthorDate: Mon Mar 29 14:55:12 2021 +0200 PEP8 linting --- server/endpoints/compose.py | 36 +++++++++++++++++------------------- server/endpoints/email.py | 21 ++++++--------------- server/endpoints/mbox.py | 13 +++---------- server/endpoints/oauth.py | 24 +++++++++--------------- server/endpoints/pminfo.py | 4 +--- server/endpoints/preferences.py | 10 ++++------ server/endpoints/source.py | 10 +++------- server/endpoints/stats.py | 24 +++++------------------- server/endpoints/thread.py | 9 +++------ 9 files changed, 51 insertions(+), 100 deletions(-) diff --git a/server/endpoints/compose.py b/server/endpoints/compose.py index 003ea9e..bb5c75a 100644 --- a/server/endpoints/compose.py +++ b/server/endpoints/compose.py @@ -26,9 +26,7 @@ import aiohttp.web async def process( - server: plugins.server.BaseServer, - session: plugins.session.SessionObject, - indata: dict, + server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict, ) -> typing.Union[dict, aiohttp.web.Response]: if not server.config.ui.mailhost: @@ -37,15 +35,15 @@ async def process( # Figure out outgoing MTA mailhost = server.config.ui.mailhost mailport = 25 - if ':' in mailhost: - mailhost, _mailport = mailhost.split(':', 1) + if ":" in mailhost: + mailhost, _mailport = mailhost.split(":", 1) mailport = int(_mailport) # Figure out if recipient list is on allowed list - to = indata.get('to', '') - mldomain = to.strip("<>").split('@')[-1] + to = indata.get("to", "") + mldomain = to.strip("<>").split("@")[-1] allowed_to_send = False - for allowed_domain in server.config.ui.sender_domains.split(' '): + for allowed_domain in server.config.ui.sender_domains.split(" "): if fnmatch.fnmatch(mldomain, allowed_domain): allowed_to_send = True break @@ -54,22 +52,22 @@ async def process( # If logged in and everything, prep for dispatch if session.credentials and session.credentials.authoritative: - subject = indata.get('subject') - body = indata.get('body') - irt = indata.get('in-repl-to') - references = indata.get('references') + subject = indata.get("subject") + body = indata.get("body") + irt = indata.get("in-repl-to") + references = indata.get("references") if to and subject and body: msg = email.message.EmailMessage() if irt: - msg['in-reply-to'] = irt + msg["in-reply-to"] = irt if references: - msg['references'] = references - msg['from'] = "%s <%s>" % (session.credentials.name, session.credentials.email) - msg['to'] = to - msg['subject'] = subject - msg['X-Sender'] = "Apache Pony Mail Foal Composer v/0.1" - msg.set_charset('utf-8') + msg["references"] = references + msg["from"] = "%s <%s>" % (session.credentials.name, session.credentials.email) + msg["to"] = to + msg["subject"] = subject + msg["X-Sender"] = "Apache Pony Mail Foal Composer v/0.1" + msg.set_charset("utf-8") msg.set_content(body) await aiosmtplib.send(msg, hostname=mailhost, port=mailport) return {"okay": True, "message": "Message dispatched!"} diff --git a/server/endpoints/email.py b/server/endpoints/email.py index fb534a4..c80351f 100644 --- a/server/endpoints/email.py +++ b/server/endpoints/email.py @@ -27,10 +27,9 @@ import plugins.aaa import base64 import typing + async def process( - server: plugins.server.BaseServer, - session: plugins.session.SessionObject, - indata: dict, + server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict, ) -> typing.Union[dict, aiohttp.web.Response]: # First, assume permalink and look up the email based on that @@ -57,26 +56,18 @@ async def process( "Content-Length": str(entry.get("size")), } if "image/" not in ct and "text/" not in ct: - headers[ - "Content-Disposition" - ] = f"attachment; filename=\"{entry.get('filename')}\"" + headers["Content-Disposition"] = f"attachment; filename=\"{entry.get('filename')}\"" try: assert session.database, "Database not connected!" attachment = await session.database.get( index=session.database.dbs.attachment, id=indata.get("file") ) if attachment: - blob = base64.decodebytes( - attachment["_source"].get("source").encode("utf-8") - ) - return aiohttp.web.Response( - headers=headers, status=200, body=blob - ) + blob = base64.decodebytes(attachment["_source"].get("source").encode("utf-8")) + return aiohttp.web.Response(headers=headers, status=200, body=blob) except plugins.database.DBError: pass # attachment not found - return aiohttp.web.Response( - headers={}, status=404, text="Attachment not found" - ) + return aiohttp.web.Response(headers={}, status=404, text="Attachment not found") return aiohttp.web.Response(headers={}, status=404, text="Email not found") diff --git a/server/endpoints/mbox.py b/server/endpoints/mbox.py index 14b811e..aff4ee8 100644 --- a/server/endpoints/mbox.py +++ b/server/endpoints/mbox.py @@ -26,15 +26,11 @@ import aiohttp.web async def process( - server: plugins.server.BaseServer, - session: plugins.session.SessionObject, - indata: dict, + server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict, ) -> typing.Union[dict, aiohttp.web.Response]: query_defuzzed = plugins.defuzzer.defuzz(indata) - results = await plugins.mbox.query( - session, query_defuzzed, query_limit=server.config.database.max_hits, - ) + results = await plugins.mbox.query(session, query_defuzzed, query_limit=server.config.database.max_hits,) sources = [] for email in results: @@ -58,10 +54,7 @@ async def process( # Return mbox archive with filename return aiohttp.web.Response( - headers={ - "Content-Type": "application/mbox", - "Content-Disposition": f"attachment; filename={dlfile}", - }, + headers={"Content-Type": "application/mbox", "Content-Disposition": f"attachment; filename={dlfile}",}, status=200, text="\n\n".join(sources), ) diff --git a/server/endpoints/oauth.py b/server/endpoints/oauth.py index 8ab02f6..414c682 100644 --- a/server/endpoints/oauth.py +++ b/server/endpoints/oauth.py @@ -28,27 +28,24 @@ import hashlib async def process( - server: plugins.server.BaseServer, - session: plugins.session.SessionObject, - indata: dict, + server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict, ) -> typing.Union[dict, aiohttp.web.Response]: state = indata.get("state") code = indata.get("code") - id_token = indata.get('id_token') + id_token = indata.get("id_token") oauth_token = indata.get("oauth_token") rv: typing.Optional[dict] = None # Google OAuth - currently fetches email address only - if indata.get('key', '') == 'google' and id_token: + if indata.get("key", "") == "google" and id_token: rv = await plugins.oauthGoogle.process(indata, session, server) # GitHub OAuth - Fetches name and email - if indata.get('key', '') == 'github' and code: + if indata.get("key", "") == "github" and code: rv = await plugins.oauthGithub.process(indata, session, server) - # Generic OAuth handler, only one we support for now. Works with ASF OAuth. elif state and code and oauth_token: rv = await plugins.oauthGeneric.process(indata, session, server) @@ -60,12 +57,10 @@ async def process( uid = rv.get("email") if uid: cid = hashlib.shake_128( - ("%s-%s" % (rv.get("oauth_domain", "generic"), uid)).encode( - "ascii", "ignore" - ) + ("%s-%s" % (rv.get("oauth_domain", "generic"), uid)).encode("ascii", "ignore") ).hexdigest(16) authoritative = rv.get("oauth_domain", "generic") in server.config.oauth.authoritative_domains - admin = authoritative and rv.get('email') in server.config.oauth.admins + admin = authoritative and rv.get("email") in server.config.oauth.admins cookie = await plugins.session.set_session( server, cid, @@ -77,16 +72,15 @@ async def process( authoritative=authoritative, oauth_provider=rv.get("oauth_domain", "generic"), oauth_data=rv, - admin=admin + admin=admin, ) # This could be improved upon, instead of a raw response return value return aiohttp.web.Response( - headers={"set-cookie": cookie, "content-type": "application/json"}, - status=200, - text='{"okay": true}', + headers={"set-cookie": cookie, "content-type": "application/json"}, status=200, text='{"okay": true}', ) return {"okay": False, "message": "Could not process OAuth login!"} + def register(server: plugins.server.BaseServer): return plugins.server.Endpoint(process) diff --git a/server/endpoints/pminfo.py b/server/endpoints/pminfo.py index 21bf996..98e6f48 100644 --- a/server/endpoints/pminfo.py +++ b/server/endpoints/pminfo.py @@ -20,9 +20,7 @@ import plugins.server -async def process( - server: plugins.server.BaseServer, session: dict, indata: dict -) -> dict: +async def process(server: plugins.server.BaseServer, session: dict, indata: dict) -> dict: return server.data.activity diff --git a/server/endpoints/preferences.py b/server/endpoints/preferences.py index 7a473aa..1cb2821 100644 --- a/server/endpoints/preferences.py +++ b/server/endpoints/preferences.py @@ -23,9 +23,7 @@ import plugins.session """ This is incomplete, but will work for anonymous tests. """ -async def process( - server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict -) -> dict: +async def process(server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict) -> dict: prefs: dict = {"login": {}} lists: dict = {} for ml, entry in server.data.lists.items(): @@ -40,7 +38,7 @@ async def process( lists[ldomain][lname] = entry["count"] prefs["lists"] = lists if session and session.credentials: - prefs['login'] = { + prefs["login"] = { "credentials": { "uid": session.credentials.uid, "email": session.credentials.email, @@ -48,10 +46,10 @@ async def process( } } if session.credentials.admin is True: - prefs['login']['credentials']['admin'] = True + prefs["login"]["credentials"]["admin"] = True # Logging out?? - if indata.get('logout'): + if indata.get("logout"): # Remove session from ElasticSearch await plugins.session.remove_session(session) diff --git a/server/endpoints/source.py b/server/endpoints/source.py index 44bbcc5..60fa085 100644 --- a/server/endpoints/source.py +++ b/server/endpoints/source.py @@ -25,9 +25,7 @@ import plugins.aaa async def process( - server: plugins.server.BaseServer, - session: plugins.session.SessionObject, - indata: dict, + server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict, ) -> aiohttp.web.Response: # First, assume permalink and look up the email based on that email = await plugins.mbox.get_email(session, permalink=indata.get("id")) @@ -35,15 +33,13 @@ async def process( # If not found via permalink, it might be message-id instead, so try that if email is None: email = await plugins.mbox.get_email(session, messageid=indata.get("id")) - + if email and isinstance(email, dict) and not email.get("deleted"): if plugins.aaa.can_access_email(session, email): source = await plugins.mbox.get_source(session, permalink=email["mid"]) if source: return aiohttp.web.Response( - headers={"Content-Type": "text/plain"}, - status=200, - text=source["_source"]["source"], + headers={"Content-Type": "text/plain"}, status=200, text=source["_source"]["source"], ) return aiohttp.web.Response(headers={}, status=404, text="Email not found") diff --git a/server/endpoints/stats.py b/server/endpoints/stats.py index ed328fd..40746b7 100644 --- a/server/endpoints/stats.py +++ b/server/endpoints/stats.py @@ -30,19 +30,12 @@ import typing PYPONY_RE_PREFIX = re.compile(r"^([a-zA-Z]+:\s*)+") -async def process( - server: plugins.server.BaseServer, - session: plugins.session.SessionObject, - indata: dict, -) -> dict: +async def process(server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict,) -> dict: query_defuzzed = plugins.defuzzer.defuzz(indata) query_defuzzed_nodate = plugins.defuzzer.defuzz(indata, nodate=True) results = await plugins.mbox.query( - session, - query_defuzzed, - query_limit=server.config.database.max_hits, - shorten=True, + session, query_defuzzed, query_limit=server.config.database.max_hits, shorten=True, ) for msg in results: @@ -58,20 +51,13 @@ async def process( xlist = indata.get("list", "*") xdomain = indata.get("domain", "*") - all_authors = sorted( - [[author, count] for author, count in authors.items()], key=lambda x: x[1] - ) + all_authors = sorted([[author, count] for author, count in authors.items()], key=lambda x: x[1]) top10_authors = [] for x in [x for x in reversed([x for x in all_authors])][:10]: author, count = x name, address = email.utils.parseaddr(author) top10_authors.append( - { - "email": address, - "name": name, - "count": count, - "gravatar": plugins.mbox.gravatar(author), - } + {"email": address, "name": name, "count": count, "gravatar": plugins.mbox.gravatar(author),} ) # Trim email data so as to reduce download sizes @@ -84,7 +70,7 @@ async def process( "hits": len(results), "numparts": len(authors), "no_threads": len(tstruct), - "emails": list(sorted(results, key=lambda x: x['epoch'])), + "emails": list(sorted(results, key=lambda x: x["epoch"])), "cloud": wordcloud, "participants": top10_authors, "thread_struct": tstruct, diff --git a/server/endpoints/thread.py b/server/endpoints/thread.py index af3cc1a..b583bbe 100644 --- a/server/endpoints/thread.py +++ b/server/endpoints/thread.py @@ -23,18 +23,15 @@ import plugins.mbox import plugins.defuzzer import typing + async def process( - server: plugins.server.BaseServer, - session: plugins.session.SessionObject, - indata: dict, + server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict, ) -> typing.Optional[dict]: email = await plugins.mbox.get_email(session, permalink=indata.get("id")) if not email: email = await plugins.mbox.get_email(session, messageid=indata.get("id")) if email and isinstance(email, dict): - thread, emails, pdocs = await plugins.mbox.fetch_children( - session, email, short=True - ) + thread, emails, pdocs = await plugins.mbox.fetch_children(session, email, short=True) else: return None
