Add Date: parser
This commit is contained in:
parent
f205a0320e
commit
9081f5d699
1 changed files with 8 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
import re
|
import re
|
||||||
import enum
|
import enum
|
||||||
|
import dateparser
|
||||||
|
|
||||||
class MBoxReaderError(Exception):
|
class MBoxReaderError(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -87,7 +88,7 @@ class MBoxMessage():
|
||||||
match = re.match('^([^:]+): (.*)$', line)
|
match = re.match('^([^:]+): (.*)$', line)
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
self.key = match[1]
|
self.key = match[1].lower()
|
||||||
|
|
||||||
self.headers[self.key] = match[2].rstrip()
|
self.headers[self.key] = match[2].rstrip()
|
||||||
elif self.state is MBoxMessageState.BODY:
|
elif self.state is MBoxMessageState.BODY:
|
||||||
|
@ -98,6 +99,12 @@ class MBoxMessage():
|
||||||
|
|
||||||
self.line = line
|
self.line = line
|
||||||
|
|
||||||
|
def header(self, key: str):
|
||||||
|
return self.headers[key.lower()]
|
||||||
|
|
||||||
|
def date(self):
|
||||||
|
return dateparser.parse(self.headers['date'])
|
||||||
|
|
||||||
def is_first_line(self):
|
def is_first_line(self):
|
||||||
return len(self.headers) == 1 and (self.body == '' or self.body is None)
|
return len(self.headers) == 1 and (self.body == '' or self.body is None)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue