diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index f9c59badc..8a861d263 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -28,7 +28,7 @@ class Account(object): """ MissingCredentials = MissingCredentials - def __init__(self, db_path, os_name=None, logging=True): + def __init__(self, db_path, os_name=None, logging=True, logid=None): """ initialize account object. :param db_path: a path to the account database. The database @@ -38,6 +38,7 @@ class Account(object): # initialize per-account plugin system self._pm = hookspec.PerAccount._make_plugin_manager() self._logging = logging + self.logid=logid self.add_account_plugin(self) diff --git a/python/src/deltachat/direct_imap.py b/python/src/deltachat/direct_imap.py index 12d4b4421..bfcd6af14 100644 --- a/python/src/deltachat/direct_imap.py +++ b/python/src/deltachat/direct_imap.py @@ -94,18 +94,19 @@ def make_direct_imap(account, folder): imap = ImapConn(folder, conn_info=conn_info) return imap -def print_imap_structure(database): - print_imap_structure_ac(Account(database)) +def print_imap_structure(database, dir="."): + print_imap_structure_ac(Account(database), dir) -def print_imap_structure_ac(ac): - print("================= ACCOUNT", ac.get_config("addr"), "=================") +def print_imap_structure_ac(ac, dir="."): + acinfo = ac.logid + "-" + ac.get_config("addr") + print("================= ACCOUNT", acinfo, "=================") print("----------------- CONFIG: -----------------") print(ac.get_info()) - for folder in [INBOX, MVBOX, SENT]: + for imapfolder in [INBOX, MVBOX, SENT]: try: - print("-----------------", folder, "-----------------") - imap = make_direct_imap(ac, folder) + print("-----------------", imapfolder, "-----------------") + imap = make_direct_imap(ac, imapfolder) c = imap.connection typ, data = c.search(None, 'ALL') c._get_tagged_response @@ -116,10 +117,10 @@ def print_imap_structure_ac(ac): typ, data = c.fetch(num, '(UID FLAGS)') info = data[0] - path = pathlib.Path("./IMAP-MESSAGES-" + ac.get_config("addr") + "~/" + folder) + path = pathlib.Path(dir).joinpath("IMAP-MESSAGES", acinfo, imapfolder) path.mkdir(parents=True, exist_ok=True) file = path.joinpath(str(info).replace("b'", "").replace("'", "").replace("\\", "")) file.write_bytes(body) print("Message", info, "saved as", file) except ConnectionError: - print("Seems like there is no", folder, "folder") + print("Seems like there is no", imapfolder, "folder") diff --git a/python/src/deltachat/testplugin.py b/python/src/deltachat/testplugin.py index 91a78f775..9495396dc 100644 --- a/python/src/deltachat/testplugin.py +++ b/python/src/deltachat/testplugin.py @@ -230,7 +230,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data): acc.disable_logging() def make_account(self, path, logid, quiet=False): - ac = Account(path, logging=self._logging) + ac = Account(path, logging=self._logging, logid=logid) ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac)) ac.addr = ac.get_self_contact().addr if not quiet: @@ -382,7 +382,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data): yield am if request.node.rep_call.failed: for ac in am._accounts: - direct_imap.print_imap_structure_ac(ac) + direct_imap.print_imap_structure_ac(ac, tmpdir) class BotProcess: