I am trying to copy mails from Inbox to a subfolder on live.com. Due limitations of the system, I only can work with the default libraries of python 3.8. The code to list the directories of the account looks like this:
imapcon = imaplib.IMAP4_SSL(imap_host)
imapcon.login(imap_user, imap_pass)
for i in imapcon.list()[1]:
print(i)
The result is:
b'(\\HasNoChildren) "/" Archive'
b'(\\HasNoChildren \\Trash) "/" Deleted'
b'(\\HasNoChildren \\Drafts) "/" Drafts'
b'(\\Marked \\HasChildren) "/" Inbox'
b'(\\HasNoChildren) "/" Inbox/check'
b'(\\Marked \\HasNoChildren) "/" Inbox/stuf'
b'(\\HasNoChildren) "/" Inbox/test1in'
b'(\\HasNoChildren) "/" Inbox/test1st'
b'(\\HasNoChildren \\Junk) "/" Junk'
b'(\\HasNoChildren) "/" Notes'
b'(\\HasNoChildren) "/" Outbox'
b'(\\HasNoChildren) "/" rootstuff'
b'(\\HasNoChildren \\Sent) "/" Sent'
My code to copy looks like this:
resp, items = imapcon.uid("search",None, 'All')
items = items[0].split()
for emailid in items:
cpres = imapcon.uid('COPY',emailid, 'Inbox/test1in')
print(cpres)
Unfortunately, the mail will not be copied. I found mostly Gmail folder specific hints, but nothing worked out. Tried cpres = imapcon.uid('COPY',emailid, '/test1in')
or cpres = imapcon.uid('COPY',emailid, '\Inbox.test1in')
I found examples with brackets.... so I tried cpres = imapcon.uid('COPY',emailid, '(\Inbox/test1in)')
To make life easier, I tried to copy the folder rootstuff cpres = imapcon.uid('COPY',emailid, 'rootstuff')
and this works fine. To the Inbox/Subfolders not. Where is my mistake?
EDIT:
the print for cpres = imapcon.uid('COPY',emailid, 'Inbox/test1in')
is
('NO', [b'[TRYCREATE] The destination mailbox could not be found.'])
and for cpres = imapcon.uid('COPY',emailid, 'rootstuff')
the script prints
('OK', [None])
I am not sure but I doubt it is something with subfolders.