1

I have code that looks something like this

import imapclient

archive_folder = "Archive"

aggregate_reports_folder = "{0}/Aggregate".format(archive_folder)
forensic_reports_folder = "{0}/Forensic".format(archive_folder)

server = imapclient.IMAPClient("example.com", use_uid=True)
server.login("user", "foobar")

if not server.folder_exists(archive_folder):
    server.create_folder(archive_folder)
if not server.folder_exists(aggregate_reports_folder):
    server.create_folder(aggregate_reports_folder)
if not server.folder_exists(forensic_reports_folder):
    server.create_folder(forensic_reports_folder)

It works fine on Office 365/Exchange, but not dovecot. On dovecot it causes an error:

Error: create failed: [CANNOT] Invalid mailbox name: Name must not have '/' characters

I tried removing the /subfolder part of the folder name, and running select_folder(archive_folder) first, but that just creates folders at the same level as Archive. Yet, Thunderbird can create subfolders without a problem.

How can I create IMAP subfolders using imapclient, in a way that works with all IMAP servers? Also, How do I move mail to those subfolders?

Sean W.
  • 4,944
  • 8
  • 40
  • 66

1 Answers1

1

I found the answer in the dovecot mailing list.

Currently Dovecot supports only Maildir++ directory layout, which specifies that '.' character is used as the separator in the filesystem.

So when building subfolder paths, use . as the separator, not /.

Sean W.
  • 4,944
  • 8
  • 40
  • 66
  • The output of the list command includes the mailbox separator character. I don't know if imapclient gives you access to this information easily. – Max Aug 21 '18 at 19:25
  • @Max Yes, the `list_folders()`/`list_subfolders()` methods include the separator as second element in each entry. – BlackJack Sep 06 '18 at 15:54