File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change 25
25
from .datetime_util import datetime_to_INTERNALDATE , format_criteria_date
26
26
from .imap_utf7 import encode as encode_utf7 , decode as decode_utf7
27
27
from .response_parser import parse_response , parse_message_list , parse_fetch_response
28
- from .util import to_bytes , to_unicode , assert_imap_protocol
28
+ from .util import to_bytes , to_unicode , assert_imap_protocol , chunk
29
29
xrange = moves .xrange
30
30
31
31
if PY3 :
@@ -609,11 +609,7 @@ def _proc_folder_list(self, folder_data):
609
609
610
610
ret = []
611
611
parsed = parse_response (folder_data )
612
- while parsed :
613
- # TODO: could be more efficient
614
- flags , delim , name = parsed [:3 ]
615
- parsed = parsed [3 :]
616
-
612
+ for flags , delim , name in chunk (parsed , size = 3 ):
617
613
if isinstance (name , (int , long )):
618
614
# Some IMAP implementations return integer folder names
619
615
# with quotes. These get parsed to ints so convert them
Original file line number Diff line number Diff line change 4
4
5
5
from __future__ import unicode_literals
6
6
7
+ import six
7
8
import logging
8
9
from six import binary_type , text_type
9
10
@@ -37,3 +38,8 @@ def assert_imap_protocol(condition, message=None):
37
38
if message :
38
39
msg += "{}: {}" .format (msg , message )
39
40
raise exceptions .ProtocolError (msg )
41
+
42
+
43
+ def chunk (lst , size ):
44
+ for i in six .moves .range (0 , len (lst ), size ):
45
+ yield lst [i :i + size ]
You can’t perform that action at this time.
0 commit comments