attribute.py
4.25 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
import types
from mailutils.c_api import attribute
from mailutils.error import *
MU_ATTRIBUTE_ANSWERED = 0x01
MU_ATTRIBUTE_FLAGGED = 0x02
MU_ATTRIBUTE_DELETED = 0x04
MU_ATTRIBUTE_DRAFT = 0x08
MU_ATTRIBUTE_SEEN = 0x10
MU_ATTRIBUTE_READ = 0x20
MU_ATTRIBUTE_MODIFIED = 0x40
class Attribute:
def __init__ (self, attr):
self.attr = attr
def __del__ (self):
del self.attr
def __str__ (self):
return attribute.to_string (self.attr)
def __getitem__ (self, flag):
return self.is_flag (flag)
def __setitem__ (self, flag, value):
if value == True:
self.set_flags (flag)
elif value == False:
self.unset_flags (flag)
else:
raise TypeError, value
def is_modified (self):
return attribute.is_modified (self.attr)
def clear_modified (self):
attribute.clear_modified (self.attr)
def set_modified (self):
attribute.set_modified (self.attr)
def get_flags (self):
status, flags = attribute.get_flags (self.attr)
if status:
raise Error (status)
return flags
def set_flags (self, flags):
status = attribute.set_flags (self.attr, flags)
if status:
raise Error (status)
def unset_flags (self, flags):
status = attribute.unset_flags (self.attr, flags)
if status:
raise Error (status)
def is_flag (self, flag):
flags = self.get_flags ()
if flags & flag:
return True
return False
def set_userflag (self, flag):
status = attribute.set_userflag (self.attr, flag)
if status:
raise Error (status)
def unset_userflag (self, flag):
status = attribute.unset_userflag (self.attr, flag)
if status:
raise Error (status)
def is_userflag (self, flag):
return attribute.is_userflag (self.attr, flag)
def is_answered (self):
return self.is_flag (MU_ATTRIBUTE_ANSWERED)
def is_flagged (self):
return self.is_flag (MU_ATTRIBUTE_FLAGGED)
def is_deleted (self):
return self.is_flag (MU_ATTRIBUTE_DELETED)
def is_draft (self):
return self.is_flag (MU_ATTRIBUTE_DRAFT)
def is_seen (self):
return self.is_flag (MU_ATTRIBUTE_SEEN)
def is_read (self):
return self.is_flag (MU_ATTRIBUTE_READ)
def set_answered (self):
self.set_flags (MU_ATTRIBUTE_ANSWERED)
def set_flagged (self):
self.set_flags (MU_ATTRIBUTE_FLAGGED)
def set_deleted (self):
self.set_flags (MU_ATTRIBUTE_DELETED)
def set_draft (self):
self.set_flags (MU_ATTRIBUTE_DRAFT)
def set_seen (self):
self.set_flags (MU_ATTRIBUTE_SEEN)
def set_read (self):
self.set_flags (MU_ATTRIBUTE_READ)
def set_recent (self):
self.unset_flags (MU_ATTRIBUTE_READ | MU_ATTRIBUTE_SEEN)
def unset_answered (self):
self.unset_flags (MU_ATTRIBUTE_ANSWERED)
def unset_flagged (self):
self.unset_flags (MU_ATTRIBUTE_FLAGGED)
def unset_deleted (self):
self.unset_flags (MU_ATTRIBUTE_DELETED)
def unset_draft (self):
self.unset_flags (MU_ATTRIBUTE_DRAFT)
def unset_seen (self):
self.unset_flags (MU_ATTRIBUTE_SEEN)
def unset_read (self):
self.unset_flags (MU_ATTRIBUTE_READ)
def unset_recent (self):
self.unset_flags (MU_ATTRIBUTE_SEEN)