Перелал счётчики

sqlitedict
inpos 2016-06-11 09:51:16 +03:00
parent 0a34f252d4
commit 8f88a79980
3 changed files with 17 additions and 30 deletions

View File

@ -218,24 +218,6 @@ class IMAPServerProtocol(imap4.IMAP4Server):
#log.err() #log.err()
raise imap4.IllegalMailboxEncoding(name) 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): def _cbCopySelectedMailbox(self, mbox, tag, messages, mailbox, uid):
if not isinstance(mbox, IMAPMailbox): if not isinstance(mbox, IMAPMailbox):
self.sendNegativeResponse(tag, 'No such mailbox: ' + mailbox) self.sendNegativeResponse(tag, 'No such mailbox: ' + mailbox)

View File

@ -69,7 +69,8 @@ class MailDirStore(object):
inbox = os.path.join(mdir, 'INBOX') inbox = os.path.join(mdir, 'INBOX')
mailbox = self.mbox.IMAPMailbox(inbox) mailbox = self.mbox.IMAPMailbox(inbox)
try: try:
mailbox.addMessage(message, [IMAP_FLAGS['RECENT']]) #mailbox.addMessage(message, [IMAP_FLAGS['RECENT']])
mailbox.addMessage(message, [])
return True return True
except: except:
raise raise

View File

@ -92,8 +92,10 @@ class IMAPMailbox(ExtendedMaildir):
def _new_files(self, wo, path, code): def _new_files(self, wo, path, code):
if code == inotify.IN_MOVED_TO or code == inotify.IN_DELETE: if code == inotify.IN_MOVED_TO or code == inotify.IN_DELETE:
c = self.getMessageCount()
r = self.getRecentCount()
for l in self.listeners: for l in self.listeners:
l.newMessages(self.getMessageCount(), self.getRecentCount()) l.newMessages(c, r)
def __check_flags_(self): def __check_flags_(self):
if 'subscribed' not in self.mbox_info.keys(): self.mbox_info['subscribed'] = False 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 '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 '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 '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 #self.mbox_info.commit(blocking=False) # XXX
l = [l for l in self.__msg_list_()] l = [l for l in self.__msg_list_()]
for i in l: 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) return sum(1 for flags in self.msg_flags.itervalues() if misc.IMAP_FLAGS['DELETED'] not in flags)
def getRecentCount(self): def getRecentCount(self):
c = 0 #c = 0
for m_items in self.msg_flags.iteritems(): #for m_items in self.msg_flags.iteritems():
if misc.IMAP_FLAGS['RECENT'] in m_items[1]: # if misc.IMAP_FLAGS['RECENT'] in m_items[1]:
c += 1 # c += 1
self.msg_flags[m_items[0]] = list(set(m_items[1]).difference(set([misc.IMAP_FLAGS['RECENT']]))) # self.msg_flags[m_items[0]] = list(set(m_items[1]).difference(set([misc.IMAP_FLAGS['RECENT']])))
#self.msg_info.commit(blocking=False) # XXX ##self.msg_info.commit(blocking=False) # XXX
c = len(self.mbox_info['recent'])
if c > 0:
self.mbox_info['recent'] = []
return c return c
def getUnseenCount(self): 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): def isWriteable(self):
return True return True
@ -206,6 +212,7 @@ class IMAPMailbox(ExtendedMaildir):
if misc.IMAP_FLAGS['SEEN'] in flags and path.split('/')[-2] != 'cur': if misc.IMAP_FLAGS['SEEN'] in flags and path.split('/')[-2] != 'cur':
new_path = os.path.join(self.path, 'cur', fn) new_path = os.path.join(self.path, 'cur', fn)
os.rename(path, new_path) os.rename(path, new_path)
self.mbox_info['recent'] = list(set(self.mbox_info['recent']).union(set([fn])))
def __msg_list_(self): def __msg_list_(self):
a = [] a = []
@ -303,9 +310,6 @@ class IMAPMailbox(ExtendedMaildir):
self._stop_monitor() self._stop_monitor()
if conf.imap_expunge_on_close: if conf.imap_expunge_on_close:
self.expunge() self.expunge()
self.msg_uids.close()
self.msg_flags.close()
self.mbox_info.close()
self.closed = True self.closed = True
class MaildirMessagePart(object): class MaildirMessagePart(object):