Skip to content

Commit

Permalink
Check if content of email is encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
Incred committed Nov 14, 2021
1 parent feed539 commit 96affc5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import base64
import re

from email import policy, message_from_string
from email.parser import Parser
from email.utils import getaddresses, unquote
import collections.abc
from math import ceil


"""
Expand Down Expand Up @@ -37,8 +36,15 @@ def _parse_body(self):
continue
for mime_type in MIME_TYPES:
if part.get_content_type() == MIME_TYPES[mime_type]:
self.data[mime_type] = part.get_payload().replace('\r',
'')
self.data[mime_type] = self._get_payload(part)

def _get_payload(self, part):
# Check if content is encoded
if part.get('Content-Transfer-Encoding', '').lower() == 'base64':
content = base64.b64decode(part.get_payload()).decode()
else:
content = part.get_payload()
return content.replace('\r', '')

def _clean_varp(self, to):
match = VERP_ADDRESS_RE.search(to)
Expand Down

0 comments on commit 96affc5

Please sign in to comment.