summaryrefslogtreecommitdiff
path: root/pgweb/mailqueue/admin.py
diff options
context:
space:
mode:
authorMagnus Hagander2016-12-17 13:00:22 +0000
committerMagnus Hagander2016-12-17 13:00:22 +0000
commitaf5e5d327b8991ce76b0277c4c9ff8653eddeda0 (patch)
treed2abc08dc885e2003240b8a62a1bda279adcd1db /pgweb/mailqueue/admin.py
parent0a93c65f20a2a495c4d1552e01828fe2a37ffdbe (diff)
Decode emails in the queue
Imported from pgeu. Do simple decoding of emails in the queue instead of just showing the b64-encoded version in the admin interface. Intended to help with debugging only.
Diffstat (limited to 'pgweb/mailqueue/admin.py')
-rw-r--r--pgweb/mailqueue/admin.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/pgweb/mailqueue/admin.py b/pgweb/mailqueue/admin.py
index ccabb813..50ddc9e3 100644
--- a/pgweb/mailqueue/admin.py
+++ b/pgweb/mailqueue/admin.py
@@ -1,5 +1,30 @@
from django.contrib import admin
+from email.parser import Parser
+
from models import QueuedMail
-admin.site.register(QueuedMail)
+class QueuedMailAdmin(admin.ModelAdmin):
+ model = QueuedMail
+ readonly_fields = ('parsed_content', )
+
+ def parsed_content(self, obj):
+ # We only try to parse the *first* piece, because we assume
+ # all our emails are trivial.
+ try:
+ parser = Parser()
+ msg = parser.parsestr(obj.fullmsg)
+ b = msg.get_payload(decode=True)
+ if b: return b
+
+ pl = msg.get_payload()
+ for p in pl:
+ b = p.get_payload(decode=True)
+ if b: return b
+ return "Could not find body"
+ except Exception, e:
+ return "Failed to get body: %s" % e
+
+ parsed_content.short_description = 'Parsed mail'
+
+admin.site.register(QueuedMail, QueuedMailAdmin)