Флаги теперь в 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_TRASH = 'Trash'
|
||||
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_expunge_on_close = True
|
||||
conf.imap_check_new_interval = 10.0 # Период проверки новых сообщений в ящике
|
|
@ -17,6 +17,8 @@ import os
|
|||
from serpent.config import conf
|
||||
from serpent import misc
|
||||
|
||||
from sqlitedict import SqliteDict
|
||||
|
||||
class LoopingTask(Thread):
|
||||
def __init__(self, func, event, interval):
|
||||
Thread.__init__(self)
|
||||
|
@ -99,35 +101,19 @@ class IMAPMailbox(ExtendedMaildir):
|
|||
self.__load_flags_()
|
||||
|
||||
def __load_flags_(self):
|
||||
try:
|
||||
self.flags = load(file(os.path.join(self.path, conf.imap_flags), 'rb'))
|
||||
except:
|
||||
self.flags = {
|
||||
'flags': {},
|
||||
'subscribed': False,
|
||||
'uidvalidity': random.randint(0, 2**32),
|
||||
'uid': {},
|
||||
'uidnext': 1
|
||||
}
|
||||
self._save_flags()
|
||||
self.__init_flags_()
|
||||
|
||||
def __check_flags(self):
|
||||
with SqliteDict(conf.imap_msg_info) as msg_info, SqliteDict(conf.imap_mbox_info) as mbox_info:
|
||||
if 'subscribed' not in mbox_info.keys(): mbox_info['subscribed'] = False
|
||||
if 'uidvalidity' not in mbox_info.keys(): mbox_info['uidvalidity'] = random.randint(0, 2**32)
|
||||
if 'uidnext' not in mbox_info.keys(): mbox_info['uidnext'] = 1
|
||||
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():
|
||||
fn = i.split('/')[-1]
|
||||
if fn not in msg_info.keys():
|
||||
msg_info[fn] = {'uid': self.getUIDNext()}
|
||||
if i.split('/')[-2] == 'new':
|
||||
self.flags['flags'][i.split('/')[-1]] = []
|
||||
msg_info[fn]['flags'] = []
|
||||
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
|
||||
msg_info[fn]['flags'] = [misc.IMAP_FLAGS['SEEN']]
|
||||
|
||||
def __count_flagged_msgs_(self, flag):
|
||||
c = 0
|
||||
|
|
Loading…
Reference in New Issue