From db02d5eff03ceae915e508728e817e23b547227a Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Mon, 6 Mar 2023 12:52:50 -0800 Subject: [PATCH] Ensure dates from emails are made timezone aware if not already --- src/paperless_mail/mail.py | 6 ++++++ src/paperless_mail/tests/test_mail.py | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py index 355ad4b63..e90ad46eb 100644 --- a/src/paperless_mail/mail.py +++ b/src/paperless_mail/mail.py @@ -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) diff --git a/src/paperless_mail/tests/test_mail.py b/src/paperless_mail/tests/test_mail.py index 5e9b654fb..d4b844ff7 100644 --- a/src/paperless_mail/tests/test_mail.py +++ b/src/paperless_mail/tests/test_mail.py @@ -1,6 +1,5 @@ import dataclasses import email.contentmanager -import os import random import uuid from collections import namedtuple