Флаги теперь в sqlite
parent
451ca04d4b
commit
74b613722c
|
@ -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>
|
|
@ -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>
|
|
@ -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
|
|
@ -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 # Период проверки новых сообщений в ящике
|
|
@ -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': {},
|
|
||||||
'subscribed': False,
|
|
||||||
'uidvalidity': random.randint(0, 2**32),
|
|
||||||
'uid': {},
|
|
||||||
'uidnext': 1
|
|
||||||
}
|
|
||||||
self._save_flags()
|
|
||||||
self.__init_flags_()
|
|
||||||
|
|
||||||
def __check_flags(self):
|
|
||||||
l = [l for l in self.__msg_list_()]
|
l = [l for l in self.__msg_list_()]
|
||||||
for i in l:
|
for i in l:
|
||||||
if i.split('/')[-1] not in self.flags['uid'].keys() or i.split('/')[-1] not in self.flags['flags'].keys():
|
fn = i.split('/')[-1]
|
||||||
|
if fn not in msg_info.keys():
|
||||||
|
msg_info[fn] = {'uid': self.getUIDNext()}
|
||||||
if i.split('/')[-2] == 'new':
|
if i.split('/')[-2] == 'new':
|
||||||
self.flags['flags'][i.split('/')[-1]] = []
|
msg_info[fn]['flags'] = []
|
||||||
else:
|
else:
|
||||||
self.flags['flags'][i.split('/')[-1]] = misc.IMAP_FLAGS['SEEN']
|
msg_info[fn]['flags'] = [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
|
||||||
|
|
Loading…
Reference in New Issue