Skip to content

Commit

Permalink
Merge pull request #2 from keraattin/development
Browse files Browse the repository at this point in the history
File & content digests extracting added
  • Loading branch information
keraattin authored Nov 25, 2022
2 parents d77489e + 302f6e5 commit 681eed5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions email-analyzer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python3

from email import message_from_string
from email.parser import HeaderParser
import pyfiglet
from argparse import ArgumentParser
import sys
import hashlib

SUPPORTED_FILE_TYPES = ["eml"]

Expand All @@ -19,6 +21,31 @@ def get_headers(mail_data : str):
print(val)
print("_"*70)

def get_digests(mail_data : str, filename : str):
'''Get & Print Hash value of mail'''
with open(filename, 'rb') as f:
file = f.read()
file_md5 = hashlib.md5(file).hexdigest()
file_sha1 = hashlib.sha1(file).hexdigest()
file_sha256 = hashlib.sha256(file).hexdigest()

digests = {
"File MD5":file_md5,
"File SHA1":file_sha1,
"File SHA256":file_sha256,
"Content MD5":hashlib.md5(mail_data.encode("utf-8")).hexdigest(),
"Content SHA1":hashlib.sha1(mail_data.encode("utf-8")).hexdigest(),
"Content SHA256":hashlib.sha256(mail_data.encode("utf-8")).hexdigest()
}

print(pyfiglet.figlet_format("Digests")) # Print Banner
# Print digests
for key,val in digests.items():
print("_"*70)
print(key+":")
print(val)
print("_"*70)

# Main
if __name__ == '__main__':
parser = ArgumentParser()
Expand All @@ -36,6 +63,13 @@ def get_headers(mail_data : str):
required=False,
action="store_true"
)
parser.add_argument(
"-d",
"--digests",
help="Digests of the eml file",
required=False,
action="store_true"
)
args = parser.parse_args()

# Filename
Expand All @@ -55,3 +89,8 @@ def get_headers(mail_data : str):
if args.headers:
# Get & Print Headers
get_headers(data)

# Digests
if args.digests:
# Get & Print Digests
get_digests(data,filename)

0 comments on commit 681eed5

Please sign in to comment.