From 8f88a799801e457b3f01cb587ebdc494139963cc Mon Sep 17 00:00:00 2001 From: inpos Date: Sat, 11 Jun 2016 09:51:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=81=D1=87=D1=91=D1=82=D1=87=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mech_imap.py | 18 ------------------ serpent/dataio.py | 3 ++- serpent/imap/mailbox.py | 26 +++++++++++++++----------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/mech_imap.py b/mech_imap.py index 2426d11..3673a4c 100644 --- a/mech_imap.py +++ b/mech_imap.py @@ -217,25 +217,7 @@ class IMAPServerProtocol(imap4.IMAP4Server): except: #log.err() raise imap4.IllegalMailboxEncoding(name) - - def do_CLOSE(self, tag): - d = None - cmbx = imap4.ICloseableMailbox(self.mbox, None) - if cmbx is not None: - d = imap4.maybeDeferred(cmbx.close) - if d is not None: - d.addCallbacks(self.__cbClose, self.__ebClose, (tag,), None, (tag,), None) - else: - self.__cbClose(None, tag) - select_CLOSE = (do_CLOSE,) - - def __cbClose(self, result, tag): - self.sendPositiveResponse(tag, 'CLOSE completed') - self.mbox.removeListener(self) - self.mbox = None - self.state = 'auth' - def _cbCopySelectedMailbox(self, mbox, tag, messages, mailbox, uid): if not isinstance(mbox, IMAPMailbox): self.sendNegativeResponse(tag, 'No such mailbox: ' + mailbox) diff --git a/serpent/dataio.py b/serpent/dataio.py index b809dec..edde7e4 100644 --- a/serpent/dataio.py +++ b/serpent/dataio.py @@ -69,7 +69,8 @@ class MailDirStore(object): inbox = os.path.join(mdir, 'INBOX') mailbox = self.mbox.IMAPMailbox(inbox) try: - mailbox.addMessage(message, [IMAP_FLAGS['RECENT']]) + #mailbox.addMessage(message, [IMAP_FLAGS['RECENT']]) + mailbox.addMessage(message, []) return True except: raise diff --git a/serpent/imap/mailbox.py b/serpent/imap/mailbox.py index 3fdbc04..8258007 100644 --- a/serpent/imap/mailbox.py +++ b/serpent/imap/mailbox.py @@ -92,8 +92,10 @@ class IMAPMailbox(ExtendedMaildir): def _new_files(self, wo, path, code): if code == inotify.IN_MOVED_TO or code == inotify.IN_DELETE: + c = self.getMessageCount() + r = self.getRecentCount() for l in self.listeners: - l.newMessages(self.getMessageCount(), self.getRecentCount()) + l.newMessages(c, r) def __check_flags_(self): if 'subscribed' not in self.mbox_info.keys(): self.mbox_info['subscribed'] = False @@ -101,6 +103,7 @@ class IMAPMailbox(ExtendedMaildir): if 'special' not in self.mbox_info.keys(): self.mbox_info['special'] = '' if 'uidvalidity' not in self.mbox_info.keys(): self.mbox_info['uidvalidity'] = random.randint(0, 2**32) if 'uidnext' not in self.mbox_info.keys(): self.mbox_info['uidnext'] = 1 + if 'recent' not in self.mbox_info.keys(): self.mbox_info['recent'] = [] #self.mbox_info.commit(blocking=False) # XXX l = [l for l in self.__msg_list_()] for i in l: @@ -167,16 +170,19 @@ class IMAPMailbox(ExtendedMaildir): return sum(1 for flags in self.msg_flags.itervalues() if misc.IMAP_FLAGS['DELETED'] not in flags) def getRecentCount(self): - c = 0 - for m_items in self.msg_flags.iteritems(): - if misc.IMAP_FLAGS['RECENT'] in m_items[1]: - c += 1 - self.msg_flags[m_items[0]] = list(set(m_items[1]).difference(set([misc.IMAP_FLAGS['RECENT']]))) - #self.msg_info.commit(blocking=False) # XXX + #c = 0 + #for m_items in self.msg_flags.iteritems(): + # if misc.IMAP_FLAGS['RECENT'] in m_items[1]: + # c += 1 + # self.msg_flags[m_items[0]] = list(set(m_items[1]).difference(set([misc.IMAP_FLAGS['RECENT']]))) + ##self.msg_info.commit(blocking=False) # XXX + c = len(self.mbox_info['recent']) + if c > 0: + self.mbox_info['recent'] = [] return c def getUnseenCount(self): - return self.getMessageCount() - self.__count_flagged_msgs_(misc.IMAP_FLAGS['SEEN']) + return sum(1 for flags in self.msg_flags.itervalues() if misc.IMAP_FLAGS['SEEN'] not in flags) def isWriteable(self): return True @@ -206,6 +212,7 @@ class IMAPMailbox(ExtendedMaildir): if misc.IMAP_FLAGS['SEEN'] in flags and path.split('/')[-2] != 'cur': new_path = os.path.join(self.path, 'cur', fn) os.rename(path, new_path) + self.mbox_info['recent'] = list(set(self.mbox_info['recent']).union(set([fn]))) def __msg_list_(self): a = [] @@ -303,9 +310,6 @@ class IMAPMailbox(ExtendedMaildir): self._stop_monitor() if conf.imap_expunge_on_close: self.expunge() - self.msg_uids.close() - self.msg_flags.close() - self.mbox_info.close() self.closed = True class MaildirMessagePart(object):