4.3.5 - Fix base64 attachment decoding (#26)

This commit is contained in:
Sean Whalen
2018-10-18 09:51:30 -04:00
parent 29324d4b2a
commit 90207a39a4
3 changed files with 25 additions and 2 deletions
+5
View File
@@ -1,3 +1,8 @@
4.3.5
-----
- Fix base64 attachment decoding (#26)
4.3.4
-----
+1 -1
View File
@@ -2,7 +2,7 @@
import platform
__version__ = "4.3.4"
__version__ = "4.3.5"
USER_AGENT = "Mozilla/5.0 ((0 {1})) parsedmarc/{2}".format(
platform.system(),
+19 -1
View File
@@ -34,6 +34,24 @@ class EmailParserError(RuntimeError):
"""Raised when an error parsing the email occurs"""
def decode_base64(data):
"""
Decodes a base64 string, with padding being optional
Args:
data: A base64 encoded string
Returns:
bytes: The decoded bytes
"""
data = str(data)
missing_padding = len(data) % 4
if missing_padding != 0:
data += b'=' * (4 - missing_padding)
return base64.b64decode(data)
def get_base_domain(domain):
"""
Gets the base domain name for the given domain
@@ -458,7 +476,7 @@ def parse_email(data, strip_attachment_payloads=False):
payload = attachment["payload"]
if "content_transfer_encoding" in attachment:
if attachment["content_transfer_encoding"] == "base64":
payload = base64.b64decode(payload)
payload = decode_base64(payload)
else:
payload = str.encode(payload)
attachment["sha256"] = hashlib.sha256(payload).hexdigest()