From 04fb7b1fee129925aa7524f74bc1b0898d39d04e Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 17 Apr 2013 14:11:54 +0200 Subject: [PATCH] Make use of aware datetime objects. see #399 --- .../postfix_autoreply/management/commands/autoreply.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modoboa/extensions/postfix_autoreply/management/commands/autoreply.py b/modoboa/extensions/postfix_autoreply/management/commands/autoreply.py index b39f5c066..9a4009e3c 100644 --- a/modoboa/extensions/postfix_autoreply/management/commands/autoreply.py +++ b/modoboa/extensions/postfix_autoreply/management/commands/autoreply.py @@ -1,9 +1,9 @@ #!/usr/bin/env python # coding: utf-8 - import sys import datetime from django.core.management.base import BaseCommand, CommandError +from django.utils import timezone from modoboa.lib import parameters from modoboa.lib.emailutils import split_mailbox, sendmail_simple from modoboa.admin.models import Mailbox @@ -11,8 +11,10 @@ from modoboa.extensions.postfix_autoreply import PostfixAutoreply from modoboa.extensions.postfix_autoreply.models import ARmessage, ARhistoric def send_autoreply(sender, mailbox, armessage): + today = timezone.make_aware(datetime.datetime.today(), + timezone.get_default_timezone()) if armessage.untildate is not None \ - and armessage.untildate < datetime.datetime.today(): + and armessage.untildate < today: armessage.enabled = False armessage.save() return @@ -23,7 +25,9 @@ def send_autoreply(sender, mailbox, armessage): timeout = parameters.get_admin("AUTOREPLIES_TIMEOUT", app="postfix_autoreply") delta = datetime.timedelta(seconds=int(timeout)) - if lastar.last_sent + delta > datetime.datetime.now(): + now = timezone.make_aware(datetime.datetime.now(), + timezone.get_default_timezone()) + if lastar.last_sent + delta > now: sys.exit(0) except ARhistoric.DoesNotExist: lastar = ARhistoric()