aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2020-03-11 11:57:42 +0100
committerThomas Gleixner <tglx@linutronix.de>2020-03-11 12:10:07 +0100
commit7e4cace1e286e98d2d4d6b90f72671c16a30bbee (patch)
treea5080aa58f0925b4a6c2a38f4897622781014d33
parent76c07f6d490ae01bb5610185f22b546fca9c06ea (diff)
downloadremail-7e4cace1e286e98d2d4d6b90f72671c16a30bbee.tar.gz
remail/mail: Handle dwmw2s magic evo plugin
dwmw2's evolution plugin which seems to workaround ms-exchange oddities has another interesting format not handled by remail yet: multipart/mixed with: - empty text/plain section - application/pgp-encrypted - application/octed-stream Check for this with at least some sanity checks and morph it into a regular multipart/encrypted message so decrypt can handle it without adding more mess to that part. Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r--remail/mail.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/remail/mail.py b/remail/mail.py
index 92ee364..b14a2f3 100644
--- a/remail/mail.py
+++ b/remail/mail.py
@@ -402,6 +402,56 @@ def msg_sanitize_outlook(msg):
# code.
continue
+def msg_handle_multimix(msg):
+ '''
+ Magic format used by dwmw2's devolution plugin to prevent
+ exchange from wreckaging mail. It's kinda valid, but sigh...
+
+ Multipart mixed message with:
+ - empty text/plain
+ - application/pgp-encrypted
+ - application/octed-stream
+
+ Make it look like a sane PGP application/encrypted mail
+ '''
+ ct = msg.get_content_type()
+ if ct != 'multipart/mixed':
+ return
+
+ fnames = ['msg.asc', 'encrypted.asc']
+ gpgpl = 0
+ otherpl = []
+
+ payloads = msg.get_payload()
+ for payload in payloads:
+ try:
+ ct = payload.get_content_type()
+ print(ct)
+ if ct == 'application/pgp-encrypted':
+ gpgpl += 1
+ continue
+ elif ct == 'application/octet-stream':
+ fname = payload.get_filename(None)
+ if gpgpl == 1 and fname in fnames:
+ gpgpl += 1
+ continue
+ # None of the above. Mark it as other
+ otherpl.append(payload)
+ except:
+ # Ignore fails here. This is all best effort
+ # guesswork.
+ pass
+
+ if gpgpl != 2:
+ return
+
+ # Remove the irrelevant payload parts
+ for pl in otherpl:
+ payloads.remove(pl)
+ # Fixup the message type so decrypt knows what to do with it
+ msg.set_type('multipart/encrypted')
+ msg.set_param('protocol', 'application/pgp-encrypted')
+
def decode_base64(msg):
#
# Decode base64 encoded text/plain sections
@@ -436,6 +486,9 @@ def msg_sanitize_incoming(msg):
# Strip html multipart first
msg_strip_html(msg)
+ # Handle multipart/mixed
+ msg_handle_multimix(msg)
+
# Sanitize outlook crappola
msg_sanitize_outlook(msg)