summaryrefslogtreecommitdiff
path: root/pgweb/mailqueue/admin.py
diff options
context:
space:
mode:
authorMagnus Hagander2020-09-10 12:52:41 +0000
committerMagnus Hagander2020-09-10 12:52:41 +0000
commitf885aa205dff3e4710551a77297a941faf64a7c5 (patch)
treeee3432fce4396b2dd6152d0a07628e84e355e925 /pgweb/mailqueue/admin.py
parent9462c79318ed2250a714f3217f89f4bff4797da4 (diff)
Simplify admin preview of emails
Use the python3 function to get the plaintext body of the email, instead of our own very limited one we had before.
Diffstat (limited to 'pgweb/mailqueue/admin.py')
-rw-r--r--pgweb/mailqueue/admin.py14
1 files changed, 3 insertions, 11 deletions
diff --git a/pgweb/mailqueue/admin.py b/pgweb/mailqueue/admin.py
index 468283b6..77d07ee1 100644
--- a/pgweb/mailqueue/admin.py
+++ b/pgweb/mailqueue/admin.py
@@ -1,6 +1,7 @@
from django.contrib import admin
from email.parser import Parser
+from email import policy
from .models import QueuedMail
@@ -13,18 +14,9 @@ class QueuedMailAdmin(admin.ModelAdmin):
# We only try to parse the *first* piece, because we assume
# all our emails are trivial.
try:
- parser = Parser()
+ parser = Parser(policy=policy.default)
msg = parser.parsestr(obj.fullmsg)
- b = msg.get_payload(decode=True)
- if b:
- return b.decode('utf8')
-
- pl = msg.get_payload()
- for p in pl:
- b = p.get_payload(decode=True)
- if b:
- return b.decode('utf8')
- return "Could not find body"
+ return msg.get_body(preferencelist=('plain', )).get_payload(decode=True).decode('utf8')
except Exception as e:
return "Failed to get body: %s" % e