]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Ensure dates from emails are made timezone aware if not already
authorTrenton H <797416+stumpylog@users.noreply.github.com>
Mon, 6 Mar 2023 20:52:50 +0000 (12:52 -0800)
committerTrenton H <797416+stumpylog@users.noreply.github.com>
Tue, 7 Mar 2023 18:01:40 +0000 (10:01 -0800)
src/paperless_mail/mail.py
src/paperless_mail/tests/test_mail.py

index 355ad4b633c27c28c534b6d141a99b0d4e694090..e90ad46eb0cb5fd9ff4017c0c5508c43ad8da2a3 100644 (file)
@@ -19,6 +19,8 @@ from celery import shared_task
 from celery.canvas import Signature
 from django.conf import settings
 from django.db import DatabaseError
+from django.utils.timezone import is_naive
+from django.utils.timezone import make_aware
 from documents.loggers import LoggingMixin
 from documents.models import Correspondent
 from documents.parsers import is_mime_type_supported
@@ -236,6 +238,10 @@ def apply_mail_action(
     rule = MailRule.objects.get(pk=rule_id)
     account = MailAccount.objects.get(pk=rule.account.pk)
 
+    # Ensure the date is properly timezone aware
+    if is_naive(message_date):
+        message_date = make_aware(message_date)
+
     try:
 
         action = get_rule_action(rule)
index 5e9b654fbbbda35f3e3d7b82e8d400ec65ba3ca0..d4b844ff773bfb37111a2340c3e85b4a0e5828f5 100644 (file)
@@ -1,6 +1,5 @@
 import dataclasses
 import email.contentmanager
-import os
 import random
 import uuid
 from collections import namedtuple