1
1
#!/usr/bin/env python
2
2
3
3
import plistlib # 3.4+
4
+ import logging
4
5
from maildir_lite import MaildirMessage
5
6
6
7
@@ -12,23 +13,24 @@ class EmlxMessage(object):
12
13
def __init__ (self , message = None ):
13
14
if isinstance (message , bytes ):
14
15
# The size of the message is the first line of the file.
15
- start = end = 0
16
- end = message . find ( b' \n ' )
17
- if end is - 1 :
16
+ first_line = message . split ( b" \n " )[ 0 ]
17
+ self . content_size = int ( first_line )
18
+ if self . content_size is 0 :
18
19
return
19
- self .content_size = int (message [start :end ])
20
20
21
21
# Read in the message portion.
22
- start = end + 1
22
+ start = len ( first_line ) + 1
23
23
end = start + self .content_size
24
24
if start > 0 and end > 0 :
25
25
self .content = message [start :end ]
26
26
27
27
# Read in the plist metadata at the end.
28
28
if start > 0 and end > 0 :
29
29
meta = message [end :]
30
- if meta :
30
+ try :
31
31
self .plist = plistlib .loads (meta )
32
+ except :
33
+ logging .error ("failed to parse message metadata plist" )
32
34
33
35
def __str__ (self ):
34
36
if not self .content :
@@ -105,6 +107,13 @@ def get_maildir_message(self):
105
107
m .set_date (self .date_received )
106
108
107
109
flags_dict = self .flags
110
+
111
+ # If the plist failed to parse, this will be empty.
112
+ # We do lose state here, but there's little to be done
113
+ # at this point.
114
+ if len (flags_dict ) == 0 :
115
+ return m
116
+
108
117
if flags_dict ['draft' ]:
109
118
m .add_flag ('D' )
110
119
if flags_dict ['flagged' ]:
0 commit comments