From e1aed4d8ea091f8f3b54d153061b7fcbe4adad40 Mon Sep 17 00:00:00 2001 From: Kerem Date: Fri, 25 Nov 2022 15:05:31 +0300 Subject: [PATCH] Header extracting added --- email-analyzer.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/email-analyzer.py b/email-analyzer.py index e03422a..7b1c285 100644 --- a/email-analyzer.py +++ b/email-analyzer.py @@ -7,6 +7,17 @@ SUPPORTED_FILE_TYPES = ["eml"] +def get_headers(mail_data : str): + '''Get & Print Headers from mail data''' + print(pyfiglet.figlet_format("Headers")) # Print Banner + # Get Headers from mail data + headers = HeaderParser().parsestr(mail_data, headersonly=True) + # Print Headers + for key,val in headers.items(): + print("_"*70) + print(key+":") + print(val) + print("_"*70) # Main if __name__ == '__main__': @@ -18,8 +29,15 @@ help="Name of file", required=True ) + parser.add_argument( + "-H", + "--headers", + help="Headers of the eml file", + required=False, + action="store_true" + ) args = parser.parse_args() - + # Filename if args.filename: # Get Filename @@ -31,4 +49,9 @@ sys.exit(-1) #Exit with error code with open(filename,"r",encoding="utf-8") as file: - data = file.read().rstrip( + data = file.read().rstrip() + + # Headers + if args.headers: + # Get & Print Headers + get_headers(data)