utf8: implement utf8foldernames option
If utf8foldernames is enabled on account level all folder names read from the IMAP server will immediately be reencoded to UTF-8. Names will be treated as UTF-8 as long as the IMAP server isn't contacted again, for which they are reencoded to IMAP4-UTF-7. This means that any further processing such as nametrans, folderfilter etc. will act upon the UTF-8 names, which will have to be documented carefully. NOTE 1: GMail repositories and folders inherit from the IMAP... classes, so I don't know yet if these changes have ugly side-effects. But web research suggests that GMail IMAP folders are equally encoded in UTF-7 so that should work identically here and incorporate the same improvements. NOTE 2: I could not test the behaviour with idlefolders as I didn't get this option to work at all, not even with the latest stable version. NOTE 3: I *did* test to sync an IMAP repository against another IMAP repository. Signed-off-by: Urs Liska <git@ursliska.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:

committed by
Nicolas Sebrecht

parent
14d83dbf48
commit
36d726763d
@ -242,7 +242,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
|
||||
# Get IMAPFolder and see if the reverse nametrans works fine.
|
||||
# TODO: getfolder() works only because we succeed in getting
|
||||
# inexisting folders which I would like to change. Take care!
|
||||
tmp_remotefolder = remote_repo.getfolder(remote_name)
|
||||
tmp_remotefolder = remote_repo.getfolder(remote_name, decode=False)
|
||||
loop_name = tmp_remotefolder.getvisiblename().replace(
|
||||
remote_repo.getsep(), local_repo.getsep())
|
||||
if local_name != loop_name:
|
||||
|
@ -428,10 +428,10 @@ class IMAPRepository(BaseRepository):
|
||||
# No strategy yielded a password!
|
||||
return None
|
||||
|
||||
def getfolder(self, foldername):
|
||||
def getfolder(self, foldername, decode=True):
|
||||
"""Return instance of OfflineIMAP representative folder."""
|
||||
|
||||
return self.getfoldertype()(self.imapserver, foldername, self)
|
||||
return self.getfoldertype()(self.imapserver, foldername, self, decode)
|
||||
|
||||
def getfoldertype(self):
|
||||
return folder.IMAP.IMAPFolder
|
||||
@ -488,7 +488,7 @@ class IMAPRepository(BaseRepository):
|
||||
try:
|
||||
for foldername in self.folderincludes:
|
||||
try:
|
||||
imapobj.select(foldername, readonly=True)
|
||||
imapobj.select(imaputil.utf8_IMAP(foldername), readonly=True)
|
||||
except OfflineImapError as e:
|
||||
# couldn't select this folderinclude, so ignore folder.
|
||||
if e.severity > OfflineImapError.ERROR.FOLDER:
|
||||
@ -497,7 +497,7 @@ class IMAPRepository(BaseRepository):
|
||||
'Invalid folderinclude:')
|
||||
continue
|
||||
retval.append(self.getfoldertype()(
|
||||
self.imapserver, foldername, self))
|
||||
self.imapserver, foldername, self, decode=False))
|
||||
finally:
|
||||
self.imapserver.releaseconnection(imapobj)
|
||||
|
||||
@ -555,6 +555,9 @@ class IMAPRepository(BaseRepository):
|
||||
return
|
||||
imapobj = self.imapserver.acquireconnection()
|
||||
try:
|
||||
if self.account.utf_8_support:
|
||||
foldername = imaputil.utf8_IMAP(foldername)
|
||||
|
||||
result = imapobj.create(foldername)
|
||||
if result[0] != 'OK':
|
||||
raise OfflineImapError("Folder '%s'[%s] could not be created. "
|
||||
|
Reference in New Issue
Block a user