From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Mon, 6 Mar 2023 20:52:50 +0000 (-0800) Subject: Ensure dates from emails are made timezone aware if not already X-Git-Tag: v1.14.0-beta.rc1~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db02d5eff03ceae915e508728e817e23b547227a;p=thirdparty%2Fpaperless-ngx.git Ensure dates from emails are made timezone aware if not already --- diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py index 355ad4b633..e90ad46eb0 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 5e9b654fbb..d4b844ff77 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