mkdir -p alike folder creation

When creating a folder in one command on Gmail you end up with
one tag such as 'x/y/z' instead of three nested tags such as 'z'
inside of 'y' inside of 'x'.  Creating each layer individually
results in the desired nested label structure.

This was tested in a personal transfer of email from a remote
IMAP server to Gmail.

OfflineIMAP/offlineimap#335
OfflineIMAP/offlineimap#598

Signed-off-by: Kyle Altendorf <sda@fstab.net>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Kyle Altendorf 2019-02-23 21:13:54 -05:00 committed by Nicolas Sebrecht
parent f9aefed704
commit 57a43f5bba

View File

@ -552,6 +552,19 @@ class IMAPRepository(BaseRepository):
foldername = self.getreference() + self.getsep() + foldername
if not foldername: # Create top level folder as folder separator.
foldername = self.getsep()
self.makefolder_single(foldername)
return
parts = foldername.split(self.getsep())
folder_paths = [self.getsep().join(parts[:n + 1]) for n in range(len(parts))]
for folder_path in folder_paths:
try:
self.makefolder_single(folder_path)
except OfflineImapError as e:
if '[ALREADYEXISTS]' not in e.reason:
raise
def makefolder_single(self, foldername):
self.ui.makefolder(self, foldername)
if self.account.dryrun:
return