diff --git a/.project b/.project
new file mode 100644
index 0000000..57319a1
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ serpent
+
+
+
+
+
+ org.python.pydev.PyDevBuilder
+
+
+
+
+
+ org.python.pydev.pythonNature
+
+
diff --git a/.pydevproject b/.pydevproject
new file mode 100644
index 0000000..da88ef5
--- /dev/null
+++ b/.pydevproject
@@ -0,0 +1,5 @@
+
+
+python2
+python 2.7
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..edc3ef8
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -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
diff --git a/serpent/config.py b/serpent/config.py
index 860f25f..f365764 100644
--- a/serpent/config.py
+++ b/serpent/config.py
@@ -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 # Период проверки новых сообщений в ящике
\ No newline at end of file
diff --git a/serpent/imap/mailbox.py b/serpent/imap/mailbox.py
index fe5480e..4d02215 100644
--- a/serpent/imap/mailbox.py
+++ b/serpent/imap/mailbox.py
@@ -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,36 +101,20 @@ 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):
- 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
-
+ 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:
+ fn = i.split('/')[-1]
+ if fn not in msg_info.keys():
+ msg_info[fn] = {'uid': self.getUIDNext()}
+ if i.split('/')[-2] == 'new':
+ msg_info[fn]['flags'] = []
+ else:
+ msg_info[fn]['flags'] = [misc.IMAP_FLAGS['SEEN']]
+
def __count_flagged_msgs_(self, flag):
c = 0
self.__load_flags_()