Add static method for parsing single mbox messages

This commit is contained in:
XANTRONIX Development 2024-11-07 15:44:20 -05:00
parent 240a79e3ba
commit af9e264ff9

View file

@ -99,6 +99,34 @@ class MBoxMessage():
def is_first_line(self):
return len(self.headers) == 1 and self.body == ''
@staticmethod
def each_line(text: str):
start = 0
end = len(text)
while True:
try:
index = text.index('\n', start, end)
yield text[start:index+1]
start = index + 1
if start == end:
break
except ValueError:
yield text[start:end]
break
@staticmethod
def parse(text: str):
message = MBoxMessage()
for line in MBoxMessage.each_line(text):
message.add(line)
return message
class MBoxReader():
__slots__ = 'path', 'fh', 'line', 'buf', 'message',