From 7ac963456f8ca11d34832375bef4e925b1fc5934 Mon Sep 17 00:00:00 2001 From: Boris Kocherov <bk@raskon.org> Date: Sun, 1 Sep 2013 19:57:41 +0400 Subject: [PATCH] EmailReader compatibility with various ImapServers is improved. * imap.mail.ru and imap.gmail.com use '/' as a delimiter. * gmail.com does not support '( ALL )', use 'ALL' instead. * parse multiple flags. --- .../document.erp5.EmailReader.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bt5/erp5_email_reader/DocumentTemplateItem/portal_components/document.erp5.EmailReader.py b/bt5/erp5_email_reader/DocumentTemplateItem/portal_components/document.erp5.EmailReader.py index 576bed4418..726853b0ba 100644 --- a/bt5/erp5_email_reader/DocumentTemplateItem/portal_components/document.erp5.EmailReader.py +++ b/bt5/erp5_email_reader/DocumentTemplateItem/portal_components/document.erp5.EmailReader.py @@ -153,7 +153,7 @@ class IMAPSServer(MailServer): message_folder -- the name of the folder to ingest messages from """ self._selectMessageFolder(message_folder) - query = "( ALL )" + query = "ALL" response, message_id_list = self.server.uid('search', None, query) # XXX - reponse not taken into account result = message_id_list[0].split() result.reverse() # Download the latest first @@ -171,13 +171,13 @@ class IMAPSServer(MailServer): result = [] response, folder_list = self.server.list() # XXX - reponse not taken into account for folder in folder_list: - if folder is not None: - folder_definition_list = folder.split(' "." ') - # XXX - Here we consider that + if folder is not None: # strings are of the form '(\\HasChildren) "." "INBOX.Business.OpenBrick.Prospects"' - # but is this really the generic case - review IMAP protocol - folder_type, folder_name = folder_definition_list - folder_name = folder_name[1:-1] + # folder_flags delimeter folder + folder_flags, folder_name = folder.split(') "', 1) + folder_flags = folder_flags.strip('(') + folder_delimiter, folder_name = folder.split('" ', 1) + folder_name = folder_name.strip('"') result.append(folder_name) return result @@ -434,7 +434,7 @@ class EmailReader(ExternalSource): """ if message_folder is None: return str(uid) - return "%s-%s" % (message_folder, uid) # Can this be configurable, based on what ? date? + return "%s-%s" % (message_folder.replace('/','.'), uid) # Can this be configurable, based on what ? date? security.declareProtected(Permissions.AccessContentsInformation, 'getMessageFolderList') def getMessageFolderList(self): -- 2.30.9