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
|
# Copyright 2009 Shikhar Bhushan <shikhar@schmizz.net>
#
# This file is part of the Sweetmail activity for Sugar.
#
# Sweetmail is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Sweetmail 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Sweetmail. If not, see <http://www.gnu.org/licenses/>.
from tags import HARDCODED, FLAGS
import sugar.util
import email.utils
import logging
class MsgInfo(object):
def __init__(self, mailstore, key, flags, hdr_from, hdr_to, hdr_subj, hdr_date):
self._ms = mailstore
self._key = key
self._flags = flags
self._hdr_from = hdr_from
self._hdr_to = hdr_to
self._hdr_subj = hdr_subj
self._hdr_date = hdr_date
def destroy(self):
attrs = (self._ms,
self._key,
self._flags,
self._hdr_from,
self._hdr_subj,
self._hdr_date)
for attr in attrs:
del attr
def mark(self, flag):
flag = FLAGS.get(flag, None)
if flag is not None:
self._ms.flag(self._key, flag)
self._flags = self._flags|flag
def unmark(self, flag):
flag = FLAGS.get(flag, None)
if flag is not None:
self._ms.unflag(self._key, flag)
self._flags = self._flags&(~flag)
def mark_sent(self):
self._ms.unflag(FLAGS['outbound'])
self._ms.flag(self._key, FLAGS['sent'])
def mark_has_attachment(self):
self._ms.unflag(FLAGS['has_attachment'])
def _whoify(self, hdr):
if hdr=='undefined':
return _('Unknown')
else:
(name, addr) = email.utils.parseaddr(hdr)
return name if not name=='' else addr
@property
def msg_id(self):
return self._key
@property
def who(self):
internal = FLAGS['draft'] | FLAGS['outbound'] | FLAGS['sent']
if self._flags & internal:
logging.debug('self._hdr_to %s' % self._hdr_to)
return self._whoify(self._hdr_to)
else:
logging.debug('self._hdr_from %s' % self._hdr_from)
return self._whoify(self._hdr_from)
@property
def what(self):
if self._hdr_subj=='undefined':
return _('No subject')
else:
return self._hdr_subj
@property
def timestamp(self):
ti = email.utils.parsedate_tz(self._hdr_date)
return email.utils.mktime_tz(ti)
@property
def when(self):
return sugar.util.timestamp_to_elapsed_string(self.timestamp)
seen = property(lambda self: bool(self._flags & FLAGS['seen']))
unseen = property(lambda self: not self.seen)
starred = property(lambda self: bool(self._flags & FLAGS['starred']))
has_attachment = property(lambda self: bool(self._flags & FLAGS['has_attachment']))
|