2 mailbox_state.py - The module contains the MailboxState class.
4 Copyright (c) 2012 Intra2net AG
5 Author: Plamen Dimitrov
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
19 """This class is responsible for containing and updating a mailbox data."""
22 # string with quotation marks for the mailbox name
24 # string for the mailbox uidvalidity
26 # string for user owning the mailbox
28 # list of bytes for last cached mail uids
30 # tolerance with which the mailbox was synced
32 # boolean flag for committing state changes
34 # integer for found date conflicts
36 # integer for found messages with missing received headers
37 no_received_field = None
38 # unique key for a mailbox
41 def __init__(self, name, uidvalidity, owner):
43 self.uidvalidity = uidvalidity
48 self.needs_save = False
50 self.date_conflicts = 0
51 self.no_received_field = 0
53 #special key to ensure better mailbox uniqueness
54 self.key = self.name.strip('"') + self.uidvalidity
58 def __getstate__(self):
59 """Prepares the MailboxState instance for pickling."""
60 changed_dict = self.__dict__.copy()
61 # remove the following attributes for pickling
62 del changed_dict['needs_save']
63 del changed_dict['date_conflicts']
64 del changed_dict['no_received_field']
67 def __setstate__(self, dict):
68 """Prepares the MailboxState instance for unpickling."""
69 self.name = dict["name"]
70 self.uidvalidity = dict["uidvalidity"]
71 self.owner = dict["owner"]
73 self.uids = dict["uids"]
74 self.tolerance = dict["tolerance"]
75 self.needs_save = False
77 self.date_conflicts = 0
78 self.no_received_field = 0
80 self.key = dict["key"]
85 """Makes the class printable."""
88 def synchronize(self, list_ids, tolerance):
89 """Adds new messages to the cache and returns a list of them.
90 Confirm the changes to a mailbox to finally save it."""
92 # cache is invalid if mailbox is synced with different tolerance
93 if(len(self.uids)==0 or tolerance != self.tolerance):
95 self.tolerance = tolerance
102 # update this mailbox potential uids
106 def confirm_change(self):
107 """Confirm the chages to the cached mailbox and specify used tolerance."""
108 self.needs_save = True