mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-01 15:54:53 +00:00
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.
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user