1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
from pixelated.adapter.pixelated_mail import PixelatedMail
class SoledadQuerier:
instance = None
@classmethod
def get_instance(cls):
if not cls.instance:
cls.instance = SoledadQuerier()
return cls.instance
def all_mails(self):
fdocs_chash = [(fdoc, fdoc.content['chash']) for fdoc in self.soledad.get_from_index('by-type', 'flags')]
return self._build_mails_from_fdocs(fdocs_chash)
def all_mails_by_mailbox(self, mailbox_name):
fdocs_chash = [(fdoc, fdoc.content['chash']) for fdoc in self.soledad.get_from_index('by-type-and-mbox', 'flags', mailbox_name)]
return self._build_mails_from_fdocs(fdocs_chash)
def _build_mails_from_fdocs(self, fdocs_chash):
fdocs_hdocs = [(f[0], self.soledad.get_from_index('by-type-and-contenthash', 'head', f[1])[0]) for f in fdocs_chash]
fdocs_hdocs_phash = [(f[0], f[1], f[1].content.get('body')) for f in fdocs_hdocs]
fdocs_hdocs_bdocs = [(f[0], f[1], self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', f[2])[0]) for f in fdocs_hdocs_phash]
return [PixelatedMail.from_soledad(*raw_mail, soledad_querier=self) for raw_mail in fdocs_hdocs_bdocs]
def save_mail(self, mail):
#self.soledad.put_doc(mail.fdoc)
#self.soledad.put_doc(mail.hdoc) # XXX update only what has to be updated
#self.soledad.put_doc(mail.bdoc)
pass
|