summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/soledad/soledad_writer_mixin.py
blob: 869f7c07f83817a720c4ac88994b16e3e433e42e (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
#
# 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/>.
from pixelated.adapter.model.mail import PixelatedMail
from pixelated.adapter.soledad.soledad_facade_mixin import SoledadDbFacadeMixin


class SoledadWriterMixin(SoledadDbFacadeMixin, object):

    def mark_all_as_not_recent(self):
        for mailbox in ['INBOX', 'DRAFTS', 'SENT', 'TRASH']:
            rct = self.get_recent_by_mbox(mailbox)
            if len(rct) == 0:
                return
            rct = rct[0]
            rct.content['rct'] = []
            self.put_doc(rct)

    def save_mail(self, mail):
        self.put_doc(mail.fdoc)

    def create_mail(self, mail, mailbox_name):
        mbox = self.get_mbox(mailbox_name)[0]
        uid = mbox.content['lastuid'] + 1

        [self.create_doc(doc) for doc in mail.get_for_save(next_uid=uid, mailbox=mailbox_name)]

        mbox.content['lastuid'] = uid
        self.put_doc(mbox)

        return self.mail(mail.ident)

    def remove_mail(self, mail):
        # FIX-ME: Must go through all the part_map phash to delete all the cdocs
        self.delete_doc(mail.fdoc)
        self.delete_doc(mail.hdoc)
        self.delete_doc(mail.bdoc)