Флаги теперь в sqlite

asyncio
inpos 2016-05-26 08:49:35 +03:00
parent 451ca04d4b
commit 74b613722c
5 changed files with 46 additions and 31 deletions

17
.project 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>serpent</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

5
.pydevproject 100644
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python2</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
</pydev_project>

View File

@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//serpent/config.py=utf-8
encoding//serpent/imap/mailbox.py=utf-8
encoding//serpent/misc.py=utf-8
encoding//serpent/queue.py=utf-8
encoding/main.py=utf-8

View File

@ -29,7 +29,8 @@ conf.smtp_email_tls_required = True
conf.imap_SENT = 'Sent' conf.imap_SENT = 'Sent'
conf.imap_TRASH = 'Trash' conf.imap_TRASH = 'Trash'
conf.imap_subscribed = '.subscribed' conf.imap_subscribed = '.subscribed'
conf.imap_flags = 'flags' conf.imap_msg_info = 'msg_info.db'
conf.imap_mbox_info = 'mbox_info.db'
conf.imap_auto_mbox = ['INBOX', 'Sent', 'Trash'] conf.imap_auto_mbox = ['INBOX', 'Sent', 'Trash']
conf.imap_expunge_on_close = True conf.imap_expunge_on_close = True
conf.imap_check_new_interval = 10.0 # Период проверки новых сообщений в ящике conf.imap_check_new_interval = 10.0 # Период проверки новых сообщений в ящике

View File

@ -17,6 +17,8 @@ import os
from serpent.config import conf from serpent.config import conf
from serpent import misc from serpent import misc
from sqlitedict import SqliteDict
class LoopingTask(Thread): class LoopingTask(Thread):
def __init__(self, func, event, interval): def __init__(self, func, event, interval):
Thread.__init__(self) Thread.__init__(self)
@ -99,35 +101,19 @@ class IMAPMailbox(ExtendedMaildir):
self.__load_flags_() self.__load_flags_()
def __load_flags_(self): def __load_flags_(self):
try: with SqliteDict(conf.imap_msg_info) as msg_info, SqliteDict(conf.imap_mbox_info) as mbox_info:
self.flags = load(file(os.path.join(self.path, conf.imap_flags), 'rb')) if 'subscribed' not in mbox_info.keys(): mbox_info['subscribed'] = False
except: if 'uidvalidity' not in mbox_info.keys(): mbox_info['uidvalidity'] = random.randint(0, 2**32)
self.flags = { if 'uidnext' not in mbox_info.keys(): mbox_info['uidnext'] = 1
'flags': {}, l = [l for l in self.__msg_list_()]
'subscribed': False, for i in l:
'uidvalidity': random.randint(0, 2**32), fn = i.split('/')[-1]
'uid': {}, if fn not in msg_info.keys():
'uidnext': 1 msg_info[fn] = {'uid': self.getUIDNext()}
} if i.split('/')[-2] == 'new':
self._save_flags() msg_info[fn]['flags'] = []
self.__init_flags_() else:
msg_info[fn]['flags'] = [misc.IMAP_FLAGS['SEEN']]
def __check_flags(self):
l = [l for l in self.__msg_list_()]
for i in l:
if i.split('/')[-1] not in self.flags['uid'].keys() or i.split('/')[-1] not in self.flags['flags'].keys():
if i.split('/')[-2] == 'new':
self.flags['flags'][i.split('/')[-1]] = []
else:
self.flags['flags'][i.split('/')[-1]] = misc.IMAP_FLAGS['SEEN']
self.flags['uid'][i.split('/')[-1]] = self.getUIDNext()
def _save_flags(self):
try:
with open(os.path.join(self.path, conf.imap_flags), 'wb') as f:
dump(self.flags, f, 2)
except:
pass
def __count_flagged_msgs_(self, flag): def __count_flagged_msgs_(self, flag):
c = 0 c = 0