summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/soledad/soledad_facade_mixin.py
blob: 1df038ea4c2977bd8821d6dcc7ed33531cab6c3a (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#
# Copyright (c) 2014 ThoughtWorks, Inc.
#
# Pixelated is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pixelated is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.


class SoledadDbFacadeMixin(object):

    def get_all_flags(self):
        return self.soledad.get_from_index('by-type', 'flags')

    def get_all_flags_by_mbox(self, mbox):
        return self.soledad.get_from_index('by-type-and-mbox', 'flags', mbox)

    def get_content_by_phash(self, phash):
        content = self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', phash)
        if len(content):
            return content[0]

    def get_flags_by_chash(self, chash):
        flags = self.soledad.get_from_index('by-type-and-contenthash', 'flags', chash)
        if len(flags):
            return flags[0]

    def get_header_by_chash(self, chash):
        header = self.soledad.get_from_index('by-type-and-contenthash', 'head', chash)
        if len(header):
            return header[0]

    def get_recent_by_mbox(self, mbox):
        return self.soledad.get_from_index('by-type-and-mbox', 'rct', mbox)

    def put_doc(self, doc):
        return self.soledad.put_doc(doc)

    def create_doc(self, doc):
        return self.soledad.create_doc(doc)

    def delete_doc(self, doc):
        return self.soledad.delete_doc(doc)

    def idents_by_mailbox(self, mbox):
        return set(doc.content['chash'] for doc in self.soledad.get_from_index('by-type-and-mbox-and-deleted', 'flags', mbox, '0'))

    def get_all_mbox(self):
        return self.soledad.get_from_index('by-type', 'mbox')

    def get_mbox(self, mbox):
        return self.soledad.get_from_index('by-type-and-mbox', 'mbox', mbox)

    def get_search_index_masterkey(self):
        return self.soledad.get_from_index('by-type', 'index_key')