summaryrefslogtreecommitdiff
path: root/postgresqleu/mailqueue/admin.py
blob: 50ddc9e3200b9ff043e20cbb518a4f1e8ec1365c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django.contrib import admin

from email.parser import Parser

from models import 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)