This fixes #126.
Removed horrible INTERNALDATE parsing code (use parse_to_datetime
instead).
+datetime_to_imap has been moved to the datetime_util module and is now
+called datetime_to_INTERNALDATE. This will only affect you in the
+unlikely case that you were importing this function out of the
+IMAPClient package.
+
======
0.12
======
def datetime_to_native(dt):
return dt.astimezone(FixedOffset.for_system()).replace(tzinfo=None)
+def datetime_to_INTERNALDATE(dt):
+ """Convert a datetime instance to a IMAP INTERNALDATE string.
+
+ If timezone information is missing the current system
+ timezone is used.
+ """
+ if not dt.tzinfo:
+ dt = dt.replace(tzinfo=FixedOffset.for_system())
+ return dt.strftime("%d-%b-%Y %H:%M:%S %z")
+
# Matches timestamp strings where the time separator is a dot (see
# issue #154). For example: 'Sat, 8 May 2010 16.03.09 +0200'
oauth_module = None
from . import response_lexer
+from .datetime_util import datetime_to_INTERNALDATE
from .imap_utf7 import encode as encode_utf7, decode as decode_utf7
-from .fixed_offset import FixedOffset
from .response_types import SearchIds
from .six import moves, iteritems, text_type, integer_types, PY3, binary_type, string_types
xrange = moves.xrange
if 'XLIST' not in imaplib.Commands:
imaplib.Commands['XLIST'] = imaplib.Commands['LIST']
+
# ...and IDLE
if 'IDLE' not in imaplib.Commands:
imaplib.Commands['IDLE'] = imaplib.Commands['APPEND']
Returns the APPEND response as returned by the server.
"""
if msg_time:
- time_val = '"%s"' % datetime_to_imap(msg_time)
+ time_val = '"%s"' % datetime_to_INTERNALDATE(msg_time)
if PY3:
time_val = to_unicode(time_val)
else:
out[to_bytes(key)] = value
return out
-def datetime_to_imap(dt):
- """Convert a datetime instance to a IMAP datetime string.
-
- If timezone information is missing the current system
- timezone is used.
- """
- if not dt.tzinfo:
- dt = dt.replace(tzinfo=FixedOffset.for_system())
- return dt.strftime("%d-%b-%Y %H:%M:%S %z")
-
def _parse_untagged_response(text):
assert text.startswith(b'* ')
text = text[2:]
from datetime import datetime
-from ..datetime_util import parse_to_datetime, datetime_to_native
+from mock import patch
+
+from ..datetime_util import parse_to_datetime, datetime_to_native, datetime_to_INTERNALDATE
from ..fixed_offset import FixedOffset
from .util import unittest
def test_invalid(self):
self.assertRaises(ValueError, parse_to_datetime, b'ABC')
+
+
+class TestDatetimeToINTERNALDATE(unittest.TestCase):
+
+ def test_with_timezone(self):
+ dt = datetime(2009, 1, 2, 3, 4, 5, 0, FixedOffset(2*60 + 30))
+ self.assertEqual(datetime_to_INTERNALDATE(dt), '02-Jan-2009 03:04:05 +0230')
+
+ @patch('imapclient.datetime_util.FixedOffset.for_system')
+ def test_without_timezone(self, for_system):
+ dt = datetime(2009, 1, 2, 3, 4, 5, 0)
+ for_system.return_value = FixedOffset(-5 * 60)
+
+ self.assertEqual(datetime_to_INTERNALDATE(dt), '02-Jan-2009 03:04:05 -0500')
self.client._imap.append.assert_called_with(
b'"foobar"', '(FLAG WAVE)', None, b'hi')
- @patch('imapclient.imapclient.datetime_to_imap')
- def test_with_msg_time(self, datetime_to_imap):
- datetime_to_imap.return_value = 'somedate'
+ @patch('imapclient.imapclient.datetime_to_INTERNALDATE')
+ def test_with_msg_time(self, datetime_to_INTERNALDATE):
+ datetime_to_INTERNALDATE.return_value = 'somedate'
self.client._imap.append.return_value = ('OK', [b'Good'])
msg = b'bye'
self.client.append('foobar', msg, ['FLAG', 'WAVE'],
datetime(2009, 4, 5, 11, 0, 5, 0, FixedOffset(2*60)))
- self.assertTrue(datetime_to_imap.called)
+ self.assertTrue(datetime_to_INTERNALDATE.called)
self.client._imap.append.assert_called_with(
b'"foobar"', '(FLAG WAVE)', '"somedate"', msg)
from __future__ import unicode_literals
-from datetime import datetime
-
-from mock import patch
-
from imapclient.imapclient import (
- datetime_to_imap,
join_message_ids,
normalise_search_criteria,
normalise_text_list,
seq_to_parenstr,
seq_to_parenstr_upper,
)
-from imapclient.fixed_offset import FixedOffset
from imapclient.test.util import unittest
def test_empty(self):
self.assertRaises(ValueError, normalise_search_criteria, '')
-
-class TestDateTimeToImap(unittest.TestCase):
-
- def test_with_timezone(self):
- dt = datetime(2009, 1, 2, 3, 4, 5, 0, FixedOffset(2*60 + 30))
- self.assertEqual(datetime_to_imap(dt), '02-Jan-2009 03:04:05 +0230')
-
- @patch('imapclient.imapclient.FixedOffset.for_system')
- def test_without_timezone(self, for_system):
- dt = datetime(2009, 1, 2, 3, 4, 5, 0)
- for_system.return_value = FixedOffset(-5 * 60)
-
- self.assertEqual(datetime_to_imap(dt), '02-Jan-2009 03:04:05 -0500')