From f446bc58ea3f2aa40230664e15360baa913b8ae7 Mon Sep 17 00:00:00 2001 From: Patrick Ulbrich Date: Tue, 2 Aug 2016 19:45:47 +0200 Subject: [PATCH] Parse folders via regex. Fixes #127 --- Mailnag/common/accounts.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/Mailnag/common/accounts.py b/Mailnag/common/accounts.py index 8d87172..264b6b1 100644 --- a/Mailnag/common/accounts.py +++ b/Mailnag/common/accounts.py @@ -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