delete all unnecessary headers in PGP

This commit is contained in:
Son NK 2020-03-14 22:24:02 +01:00
parent 7bf1baaafa
commit 69198ff08a
4 changed files with 24 additions and 1 deletions

View File

@ -307,6 +307,15 @@ def delete_header(msg: Message, header: str):
del msg._headers[i]
def delete_all_headers_except(msg: Message, headers: [str]):
headers = [h.lower() for h in headers]
for i in reversed(range(len(msg._headers))):
header_name = msg._headers[i][0].lower()
if header_name not in headers:
del msg._headers[i]
def email_belongs_to_alias_domains(email: str) -> bool:
"""return True if an email ends with one of the alias domains provided by SimpleLogin"""
for domain in ALIAS_DOMAINS:

View File

@ -64,6 +64,7 @@ from app.email_utils import (
email_belongs_to_alias_domains,
render,
get_orig_message_from_bounce,
delete_all_headers_except,
)
from app.extensions import db
from app.log import LOG
@ -269,6 +270,17 @@ def prepare_pgp_message(orig_msg: Message, pgp_fingerprint: str):
if header_name != "Content-Type".lower():
msg[header_name] = orig_msg._headers[i][1]
# Delete unnecessary headers in orig_msg except to save space
delete_all_headers_except(
orig_msg,
[
"MIME-Version",
"Content-Type",
"Content-Disposition",
"Content-Transfer-Encoding",
],
)
first = MIMEApplication(
_subtype="pgp-encrypted", _encoder=encoders.encode_7or8bit, _data=""
)

View File

@ -22,6 +22,8 @@ def load_pgp_public_keys(app):
db.session.commit()
LOG.d("Finish load_pgp_public_keys")
if __name__ == "__main__":
app = create_app()

View File

@ -151,7 +151,7 @@ def fake_data():
db.session.commit()
api_key = ApiKey.create(user_id=user.id, name="Chrome")
api_key.code = "codeCH"
api_key.code = "code"
api_key = ApiKey.create(user_id=user.id, name="Firefox")
api_key.code = "codeFF"