mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
Merge pull request #4 from iotalabscompany/add-email-message-timestamps
Collect a timestamp from emails + migration
This commit is contained in:
commit
323f74728f
4 changed files with 32 additions and 0 deletions
|
|
@ -79,6 +79,7 @@ class MessageAdmin(admin.ModelAdmin):
|
|||
]
|
||||
list_display = (
|
||||
'subject',
|
||||
'timestamp',
|
||||
'processed',
|
||||
'read',
|
||||
'mailbox',
|
||||
|
|
|
|||
20
django_mailbox/migrations/0009_message_timestamp.py
Normal file
20
django_mailbox/migrations/0009_message_timestamp.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.1.4 on 2022-10-17 11:13
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('django_mailbox', '0008_auto_20190219_1553'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='message',
|
||||
name='timestamp',
|
||||
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Timestamp'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
|
|
@ -18,6 +18,7 @@ import os.path
|
|||
import sys
|
||||
import uuid
|
||||
from datetime import timedelta
|
||||
from dateutil import parser
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
import django
|
||||
|
|
@ -379,6 +380,13 @@ class Mailbox(models.Model):
|
|||
msg.to_header = utils.convert_header_to_unicode(
|
||||
message['Delivered-To']
|
||||
)
|
||||
if "date" in message:
|
||||
msg.timestamp = parser.parse(message["date"])
|
||||
elif "Date" in message:
|
||||
msg.timestamp = parser.parse(message["Date"])
|
||||
else:
|
||||
msg.timestamp = now()
|
||||
|
||||
|
||||
if Message.objects.filter(message_id=msg.message_id).count() != 0:
|
||||
logger.info("Skipping existing message: %s", msg.message_id,)
|
||||
|
|
@ -525,6 +533,8 @@ class Message(models.Model):
|
|||
help_text=_('True if the e-mail body is Base64 encoded'),
|
||||
)
|
||||
|
||||
timestamp = models.DateTimeField(_('Timestamp'))
|
||||
|
||||
processed = models.DateTimeField(
|
||||
_('Processed'),
|
||||
auto_now_add=True
|
||||
|
|
|
|||
1
setup.py
1
setup.py
|
|
@ -56,5 +56,6 @@ setup(
|
|||
include_package_data=True,
|
||||
install_requires=[
|
||||
'six>=1.6.1',
|
||||
'python-dateutil==2.8.2',
|
||||
]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue