Parse folders via regex. Fixes #127

This commit is contained in:
Patrick Ulbrich
2016-08-02 19:45:47 +02:00
parent 7321c117db
commit f446bc58ea

View File

@@ -23,6 +23,7 @@
# MA 02110-1301, USA.
#
import re
import poplib
import logging
import Mailnag.common.imaplib2 as imaplib
@@ -105,22 +106,14 @@ class Account:
# conn.close() # allowed in SELECTED state only
conn.logout()
separators = [ ' "/" ', ' "." ' ]
for d in data:
folder = ''
for s in separators:
if s in d:
folder = d.split(s)[-1]
break
if len(folder) == 0:
match = re.match('.+\s+("."|"?NIL"?)\s+"?([^".]+)"?$', d)
if match == None:
logging.warning("Folder format not supported.")
break
if (folder[0] == '"') and (folder[-1] == '"'):
folder = folder[1:-1]
lst.append(folder)
else:
folder = match.group(2)
lst.append(folder)
return lst