Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions Lib/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,9 +922,11 @@ def _generate_toc(self):
starts, stops = [], []
last_was_empty = False
self._file.seek(0)
next_pos = 0
while True:
line_pos = self._file.tell()
line_pos = next_pos
line = self._file.readline()
next_pos += len(line)
if line.startswith(b'From '):
if len(stops) < len(starts):
if last_was_empty:
Expand Down Expand Up @@ -972,17 +974,18 @@ def _generate_toc(self):
starts, stops = [], []
self._file.seek(0)
next_pos = 0
sep = b'\001\001\001\001' + linesep
while True:
line_pos = next_pos
line = self._file.readline()
next_pos = self._file.tell()
if line.startswith(b'\001\001\001\001' + linesep):
next_pos += len(line)
if line.startswith(sep):
starts.append(next_pos)
while True:
line_pos = next_pos
line = self._file.readline()
next_pos = self._file.tell()
if line == b'\001\001\001\001' + linesep:
next_pos += len(line)
if line == sep:
stops.append(line_pos - len(linesep))
break
elif not line:
Expand Down Expand Up @@ -1418,19 +1421,23 @@ def _generate_toc(self):
self._file.seek(0)
next_pos = 0
label_lists = []
msg_sep = b'\037\014' + linesep
end_sep = b'\037' + linesep
while True:
line_pos = next_pos
line = self._file.readline()
next_pos = self._file.tell()
if line == b'\037\014' + linesep:
next_pos += len(line)
if line == msg_sep:
if len(stops) < len(starts):
stops.append(line_pos - len(linesep))
starts.append(next_pos)
label_line = self._file.readline()
next_pos += len(label_line)
labels = [label.strip() for label
in self._file.readline()[1:].split(b',')
in label_line[1:].split(b',')
if label.strip()]
label_lists.append(labels)
elif line == b'\037' or line == b'\037' + linesep:
elif line == b'\037' or line == end_sep:
if len(stops) < len(starts):
stops.append(line_pos - len(linesep))
elif not line:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up reading :class:`mailbox.mbox`, :class:`mailbox.MMDF` and
:class:`mailbox.Babyl` mailboxes.
Loading