/
configure.py
113 lines (92 loc) · 3.69 KB
/
configure.py
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
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from ConfigParser import SafeConfigParser as ConfigParser, NoOptionError
import os
import gtk
import logging
from sugar.profile import get_nick_name
import accounts
class ConfigureCanvas(gtk.Button):
def __init__(self, mailactivity):
gtk.Button.__init__(self, 'CONFIGURE')
class ConfigureToolbar(gtk.Toolbar):
def __init__(self, mailactivity):
gtk.Toolbar.__init__(self)
self.mailactivity = mailactivity
self.canvas = ConfigureCanvas
class Configuration:
def __init__(self, cfg_file):
self._cfg_file = cfg_file
if not os.path.exists(self._cfg_file): # create it
open(self._cfg_file, 'w')
self._cp = ConfigParser()
if not self._cp.read([self._cfg_file]):
logging.error('ConfigParser: error parsing %s', self._cfg_file)
### public options ###
# defaults
self.name = get_nick_name()
#self.name = "dingbat"
self.del_on_retr = False
self.store_account = accounts.DummyStoreAccount()
#self.store_account = accounts.POPStoreAccount("mew.don.gs", 110, "insecure", "sweetermail@mew.don.gs", "sugar", False)
self.transport_account = accounts.DummyTransportAccount()
# now parse (from the config file at "activityroot"/data/config.txt")
self._parse_profile()
self._parse_store()
#self._parse_transport()
def __del__(self):
fp = open(self._cfg_file, 'w')
self._cp.write(fp)
fp.close()
def _account_dict(self, sec):
kwds = {}
fields = ('host', 'port', 'auth_type', 'username', 'password')
for field in fields:
try:
kwds[field] = self._cp.get(sec, field)
except NoOptionError:
kwds[field] = None
kwds['port'] = int(kwds['port'])
return kwds
# name, address, sync_every
def _parse_profile(self):
sec = 'sending'
try:
self.name = self._cp.get(sec, 'name')
self.address = self._cp.get(sec, 'address')
except NoOptionError:
pass
# store_account
def _parse_store(self):
kwds = self._account_dict('store')
logging.debug(kwds)
try:
kwds['del_on_retr'] = self._cp.getboolean('store', 'delete_on_retrieval')
except NoOptionError:
kwds['del_on_retr'] = False
self.store_account = accounts.POPStoreAccount(**kwds)
'''
# transport_account
def _parse_transport(self):
kwds = self._account_dict('transport')
try:
kwds['del_on_retr'] = self._cp.getboolean('store', 'delete_on_retrieval')
except NoOptionError:
kwds['del_on_retr'] = False
self.transport_account = self.TransportAccount(**kwds)
'''
@property
def from_header(self):
from email.utils import formataddr
return formataddr((self.name, self.address))