From 0cf872fe26ae51f1a5f78d3818cbf7ea745fede6 Mon Sep 17 00:00:00 2001 From: Jon Mahoney Date: Sat, 17 Oct 2020 12:37:41 +0100 Subject: [PATCH] Handle non-naive dates correctly --- mailosaur/operations/messages_operations.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mailosaur/operations/messages_operations.py b/mailosaur/operations/messages_operations.py index 6b000ce..66772f3 100644 --- a/mailosaur/operations/messages_operations.py +++ b/mailosaur/operations/messages_operations.py @@ -110,7 +110,9 @@ def list(self, server, page=None, items_per_page=None, received_after=None): url = "%sapi/messages" % (self.base_url) if received_after is not None: - received_after = self.timezone.localize(received_after).isoformat() + if received_after.tzinfo is None or received_after.tzinfo.utcoffset(received_after) is None: + received_after = self.timezone.localize(received_after) + received_after = received_after.isoformat() params = {'server': server, 'page': page, 'itemsPerPage': items_per_page, 'receivedAfter': received_after} response = self.session.get(url, params=params) @@ -174,7 +176,9 @@ def search(self, server, criteria, page=None, items_per_page=None, timeout=None, url = "%sapi/messages/search" % (self.base_url) if received_after is not None: - received_after = self.timezone.localize(received_after).isoformat() + if received_after.tzinfo is None or received_after.tzinfo.utcoffset(received_after) is None: + received_after = self.timezone.localize(received_after) + received_after = received_after.isoformat() params = {'server': server, 'page': page, 'itemsPerPage': items_per_page, 'receivedAfter': received_after}