OfflineIMAP / offlineimap3

Read/sync your IMAP mailboxes (python3)
Other
455 stars 64 forks source link

Cannot handle 'already exists' and 'Cannot create this folder' messages when syncing folders with Courier IMAP #188

Open RigacciOrg opened 8 months ago

RigacciOrg commented 8 months ago

General informations

Configuration file offlineimaprc

[general]
accounts = CopyFromIMAP

[Account CopyFromIMAP]
remoterepository = OldServer
localrepository = Ipbox

[Repository OldServer]
type = IMAP
nametrans = lambda foldername: re.sub(r'^INBOX\/$', 'INBOX', 'INBOX/' + re.sub(r'(^INBOX$)|(^INBOX\.)', '', foldername))
remotehost = RemoteHost
remoteuser = RemoteUser
remotepass = MySecret
createfolders = False
sslcacertfile = /usr/share/ca-certificates/mozilla/ISRG_Root_X1.crt

[Repository Ipbox]
type = IMAP
remotehost = 127.0.0.1
remoteuser = LocalUser
remotepass = MySecret
sslcacertfile = /usr/share/ca-certificates/mozilla/ISRG_Root_X1.crt

pythonfile (if any)

Logs, error

Without the patch https://github.com/OfflineIMAP/offlineimap/pull/646/commits/5943e13737ebf1086a1adff6f8d2299324110d0a the error rises when syncing the first subdirectory (e.g. INBOX.Archive):

 Creating folder INBOX[Ipbox]
 ERROR: Creating folder INBOX.Archive on repository Ipbox
  Folder 'INBOX'[Ipbox] could not be created. Server responded: ('NO', [b'INBOX already exists!'])
 ERROR: Folder 'INBOX'[Ipbox] could not be created. Server responded: ('NO', [b'INBOX already exists!'])

After applying the patch https://github.com/OfflineIMAP/offlineimap/pull/646/commits/5943e13737ebf1086a1adff6f8d2299324110d0a the error rises at the second level subdirectory (e.g. INBOX.Archive.2013):

 Creating folder INBOX[Ipbox]
 Creating folder INBOX.Archives[Ipbox]
 ERROR: Creating folder INBOX.Archives.2013 on repository Ipbox
  Folder 'INBOX.Archives'[Ipbox] could not be created. Server responded: ('NO', [b'Cannot create this folder.'])
 ERROR: Folder 'INBOX.Archives'[Ipbox] could not be created. Server responded: ('NO', [b'Cannot create this folder.'])

Steps to reproduce the error

As you can see in the following IMAP session, the Courier IMAP server responds with different messages when creating an already existing subfolder, depending on the subfolder depth:

AAA1 LIST "" "*"
* LIST (\HasNoChildren) "." "INBOX.Archives.2013"
* LIST (\HasNoChildren) "." "INBOX.Sent"
* LIST (\HasChildren) "." "INBOX.Archives"
* LIST (\HasNoChildren) "." "INBOX.Trash"
* LIST (\HasNoChildren) "." "INBOX.Archive"
* LIST (\Unmarked \HasChildren) "." "INBOX"
* LIST (\HasNoChildren) "." "INBOX.Drafts"
* LIST (\HasNoChildren) "." "INBOX.Spam"
AAA1 OK LIST completed
AAA2 CREATE INBOX
AAA2 NO INBOX already exists!
AAA3 CREATE INBOX.Archives
AAA3 NO Cannot create this folder.
AAA4 CREATE INBOX.Archives.2024
AAA4 OK "INBOX.Archives.2024" created.
AAA5 CREATE INBOX.Archives.2024
AAA5 NO Cannot create this folder.

The problem is that offlineimap is programmed to only ignore errors containing the string [ALREADYEXISTS]. Errors containing the already exists! and Cannot create this folder strings are instead raised.

The the already exists! problem is the same reported by issue #130.

thekix commented 3 months ago

Hi,

I applied the patch "Merge pull request https://github.com/OfflineIMAP/offlineimap3/pull/178 from roboshim/dont-create-existing-folder". This patch solves this problem?

Regards, kix