mirror of
https://github.com/domainaware/parsedmarc.git
synced 2026-05-13 23:45:26 +00:00
4.3.5 - Fix base64 attachment decoding (#26)
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
4.3.5
|
||||
-----
|
||||
|
||||
- Fix base64 attachment decoding (#26)
|
||||
|
||||
4.3.4
|
||||
-----
|
||||
|
||||
|
||||
@@ -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
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user