3
from main import Application
4
from ..utils import show_desktop
5
import ldtp, ldtputils, ooldtp
9
from shutil import move, rmtree, copytree, copy
10
from ConfigParser import ConfigParser
11
from string import Formatter
12
from ..cmd import globals
16
gettext.install (True)
17
gettext.bindtextdomain (PACKAGE, globals.LOCALE_SHARE)
18
gettext.textdomain (PACKAGE)
19
t = gettext.translation(PACKAGE, globals.LOCALE_SHARE, fallback = True)
22
class AccountInfo(object):
24
def __init__(self, name, credentials):
25
if not isinstance(credentials, ConfigParser):
26
creds_fn = credentials
27
credentials = ConfigParser()
28
credentials.read(creds_fn)
29
self.details = dict(credentials.items(name))
32
def __getattr__(self, name):
34
return self.details[name]
39
def template_args(self):
41
for arg in ('popaccount', 'popserver', 'smtpaccount', 'smtpserver',
42
'emailaddress', 'accountname', 'realname', 'protocol', 'password'):
43
args[arg] = getattr(self, arg)
46
class Evolution(Application):
48
Evolution application helper class.
50
WINDOW = _("*-Evolution")
51
LAUNCHER = "evolution"
54
# Main window elements
55
BTN_SENDRECEIVE = _("btnSend/Receive")
56
DLG_SENDRECEIVE = _("dlgSend&ReceiveMail")
57
DLG_ENTER_PASSWORD = _("dlgEnterPasswordfor*")
58
TBL_MSG_FOLDERS = 'ttblMailFolderTree'
60
# Compose message constants
61
MNU_COMPOSENEW = _("mnuComposeNewMessage")
62
FRM_COMPOSE = _("frmComposeMessage")
64
TXT_SUBJECT = _("txtSubject")
66
BTN_SEND = _("btnSend")
69
MESSAGES = "ttblMessages"
70
STATUS_LBL = _("Status")
72
ATTACH_LBL = _("Attachment")
74
FLAGGED_LBL = _("Flagged")
78
SUBJECT_LBL = _("Subject")
84
Application.__init__(self)
86
def open(self, clean_profile=True, credentials=''):
88
It saves the old profile (if needed) and
89
set up a new one. After this initial process,
90
it opens the application
92
@type clean_profile: boolean
93
@param clean_profile: True, to back up the old profile and create a
95
@type credentials: string
96
@param credentials: Path to the config file with accounts information
98
clean_profile = clean_profile not in ('False', '0', False)
99
self.creds_fn = credentials
100
self.credentials = ConfigParser()
101
self.credentials.read(self.creds_fn)
106
Application.open(self)
108
def generate_profile(self, profile_template, template_args=None):
110
It uses the profile_template and the
111
credentials to build a new profile folder
114
conf_folder = '~/.gconf/apps/evolution'
115
template_file = 'mail/%gconf.xml'
117
formatter = Formatter()
118
copytree(profile_template, os.path.expanduser(conf_folder))
120
buf = open(os.path.join(os.path.join(profile_template, template_file))).read()
121
f = open(os.path.join(os.path.expanduser(conf_folder), template_file), 'w')
123
buf = formatter.format(buf, **template_args)
129
def compose_new_message(self, to, subject='', body='', account=''):
131
evolution = ooldtp.context(self.WINDOW)
132
mnuComposeNew = evolution.getchild(self.MNU_COMPOSENEW)
133
mnuComposeNew.click()
134
ldtp.waittillguiexist(self.FRM_COMPOSE)
135
compose_window = ooldtp.context(self.FRM_COMPOSE)
136
txtTo = compose_window.getchild(self.TXT_TO)
137
txtTo.settextvalue(to)
138
txtSubject = compose_window.getchild(self.TXT_SUBJECT)
139
txtSubject.settextvalue(subject)
141
# Remap is needed because the frame changes its name
144
compose_window = ooldtp.context(subject)
146
txtBody = compose_window.getchild(self.TXT_BODY)
147
txtBody.settextvalue(body)
149
def send_email(self, subject):
151
compose_window = ooldtp.context(subject)
152
btnSend = compose_window.getchild(self.BTN_SEND)
155
def send_and_receive(self, password='', minimize=False, dont_wait=False):
156
evolution = ooldtp.context(self.WINDOW)
157
btnsr = evolution.getchild(self.BTN_SENDRECEIVE)
159
ldtp.waittillguiexist(self.DLG_SENDRECEIVE)
164
if ldtp.waittillguiexist(self.DLG_ENTER_PASSWORD, guiTimeOut=2) == 1:
165
enter_pass_dlg = ooldtp.context(self.DLG_ENTER_PASSWORD)
166
txt_pass = enter_pass_dlg.getchild(role='password_text')[0]
167
txt_pass.settextvalue(password)
168
btn_ok = enter_pass_dlg.getchild(self.BTN_OK)
176
ldtp.waittillguinotexist(self.DLG_SENDRECEIVE)
179
def get_list_messages(self, only_unread=False, folder="Inbox"):
183
self.select_folder(folder)
185
evolution = ooldtp.context(self.WINDOW)
186
messages = evolution.getchild(self.MESSAGES)
188
for i in range(messages.getrowcount()):
189
status = messages.getcellvalue(i, self.STATUS_INDEX)
190
sender = messages.getcellvalue(i, self.FROM_INDEX)
191
subject = messages.getcellvalue(i, self.SUBJECT_INDEX)
193
if not only_unread or status == '0':
194
messages_list.append({'subject':subject,'sender':sender,'status':status})
198
def select_folder(self, folder):
199
evolution = ooldtp.context(self.WINDOW)
200
table_msg = evolution.getchild(self.TBL_MSG_FOLDERS)
201
table_msg.selectrowpartialmatch(folder)
203
def backup_config(self):
205
It saves the configuration of Evolution in a file
206
called ~/.evo.bak.tar.gz{.n}
208
It saves the evolution config & messages
210
p = os.path.expanduser('~/.evo.bak.tar.gz')
213
while os.path.exists(backup_path):
214
backup_path = '%s.%d' % (p, i)
218
tar = tarfile.open(backup_path, mode='w:gz')
219
evolution_conf = os.path.expanduser('~/.evolution')
220
evolution_gconf = os.path.expanduser('~/.gconf/apps/evolution')
222
if os.path.exists(evolution_conf):
223
tar.add(evolution_conf)
224
rmtree(evolution_conf)
225
if os.path.exists(evolution_gconf):
226
tar.add(evolution_gconf)
227
rmtree(evolution_gconf)
232
self.backup_path = backup_path
234
# Shutdown processes related to the evolution configuration
235
os.popen("evolution --force-shutdown")
236
os.popen("gconftool-2 --shutdown")
238
def restore_config(self):
240
It deletes the configuration folder and restore then
241
one backed up (at backup_path)
244
rmtree(os.path.expanduser('~/.evolution'))
245
rmtree(os.path.expanduser('~/.gconf/apps/evolution'))
250
tar = tarfile.open(self.backup_path, mode='r:gz')
251
tar.extractall(os.path.expanduser('/.'))
253
traceback.print_exc()
257
if __name__ == "__main__":
258
from time import sleep
261
#subject = "Greetings"
262
#test.compose_new_message("tester.ubuntu@gmail.com", subject, "hey hey")
263
#test.send_email(subject)
264
#test.send_and_receive('testingubuntu')
266
test.restore_config()