2022-05-31 22:09:10 +02:00
|
|
|
import sys
|
|
|
|
|
2022-06-02 19:56:32 +02:00
|
|
|
# The standard way to encode line-ending in email:
|
|
|
|
EOL = "\r\n"
|
|
|
|
|
2022-06-01 23:00:05 +02:00
|
|
|
PGP_INLINE_BEGIN = b"-----BEGIN PGP MESSAGE-----"
|
|
|
|
PGP_INLINE_END = b"-----END PGP MESSAGE-----"
|
|
|
|
|
2022-05-31 22:09:10 +02:00
|
|
|
def parse_content_type(content_type):
|
2022-06-01 23:44:41 +02:00
|
|
|
parts = [p.strip() for p in content_type.split(';')]
|
|
|
|
if len(parts) == 1:
|
|
|
|
# No additional attributes provided. Use default encoding.
|
2022-05-31 22:09:10 +02:00
|
|
|
return (content_type, sys.getdefaultencoding())
|
2022-06-01 23:44:41 +02:00
|
|
|
|
|
|
|
# At least one attribute provided. Find out if any of them is named
|
|
|
|
# 'charset' and if so, use it.
|
|
|
|
ctype = parts[0]
|
|
|
|
encoding = [p for p in parts[1:] if p.startswith('charset=') ]
|
|
|
|
if encoding:
|
|
|
|
eq_idx = encoding[0].index('=')
|
|
|
|
return (ctype, encoding[0][eq_idx+1:])
|
2022-05-31 22:09:10 +02:00
|
|
|
else:
|
2022-06-01 23:44:41 +02:00
|
|
|
return (ctype, sys.getdefaultencoding())
|
2022-06-01 23:00:05 +02:00
|
|
|
|
|
|
|
def is_pgp_inline(payload):
|
|
|
|
"""Finds out if the payload (bytes) contains PGP/INLINE markers."""
|
|
|
|
return PGP_INLINE_BEGIN in payload and PGP_INLINE_END in payload
|