mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-05 18:34:52 +00:00

Sent email can be assigned a "stagger type", for which he system will maintain a "last sent" information. When the email is sent, it will be delayed to be at least "stagger" time after the last one sent of the same type. If no email of this type has been sent before, the email is of course sent immediately.
28 lines
827 B
Python
28 lines
827 B
Python
from django.contrib import admin
|
|
|
|
from email.parser import Parser
|
|
from email import policy
|
|
|
|
from .models import QueuedMail
|
|
|
|
|
|
class QueuedMailAdmin(admin.ModelAdmin):
|
|
model = QueuedMail
|
|
readonly_fields = ('parsed_content', )
|
|
list_display = ('pk', 'sender', 'receiver', 'sendat')
|
|
|
|
def parsed_content(self, obj):
|
|
# We only try to parse the *first* piece, because we assume
|
|
# all our emails are trivial.
|
|
try:
|
|
parser = Parser(policy=policy.default)
|
|
msg = parser.parsestr(obj.fullmsg)
|
|
return msg.get_body(preferencelist=('plain', )).get_payload(decode=True).decode('utf8')
|
|
except Exception as e:
|
|
return "Failed to get body: %s" % e
|
|
|
|
parsed_content.short_description = 'Parsed mail'
|
|
|
|
|
|
admin.site.register(QueuedMail, QueuedMailAdmin)
|