fix: [PgpDump parser] remove header comment (rfc4880) + remove empty lines

pull/486/head
Terrtia 2020-03-05 11:19:43 +01:00
parent 1944593a48
commit 4300fd7803
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
1 changed files with 13 additions and 0 deletions

View File

@ -86,6 +86,17 @@ def get_pgp_packet(message, save_path):
all_version = re.findall(regex_tool_version, save_path) all_version = re.findall(regex_tool_version, save_path)
for version in all_version: for version in all_version:
save_path = save_path.replace(version, '') save_path = save_path.replace(version, '')
# remove comment
all_comment= re.findall(regex_block_comment, save_path)
for comment in all_comment:
save_path = save_path.replace(comment, '')
# remove empty line
save_path = [s for s in save_path.splitlines() if s]
save_path[0] = save_path[0] + '\n'
save_path[-1] = '\n' + save_path[-1]
save_path = '\n'.join(save_path)
#print(save_path)
if len(save_path) > 131072: if len(save_path) > 131072:
save_in_file(message, save_path) save_in_file(message, save_path)
@ -173,6 +184,7 @@ if __name__ == '__main__':
regex_pgp_signature = '-----BEGIN PGP SIGNATURE-----[\s\S]+?-----END PGP SIGNATURE-----' regex_pgp_signature = '-----BEGIN PGP SIGNATURE-----[\s\S]+?-----END PGP SIGNATURE-----'
regex_pgp_message = '-----BEGIN PGP MESSAGE-----[\s\S]+?-----END PGP MESSAGE-----' regex_pgp_message = '-----BEGIN PGP MESSAGE-----[\s\S]+?-----END PGP MESSAGE-----'
regex_tool_version = r"\bVersion:.*\n" regex_tool_version = r"\bVersion:.*\n"
regex_block_comment = r"\bComment:.*\n"
re.compile(regex_user_id) re.compile(regex_user_id)
re.compile(regex_key_id) re.compile(regex_key_id)
@ -180,6 +192,7 @@ if __name__ == '__main__':
re.compile(regex_pgp_signature) re.compile(regex_pgp_signature)
re.compile(regex_pgp_message) re.compile(regex_pgp_message)
re.compile(regex_tool_version) re.compile(regex_tool_version)
re.compile(regex_block_comment)
max_execution_time = p.config.getint("PgpDump", "max_execution_time") max_execution_time = p.config.getint("PgpDump", "max_execution_time")