68
70
attachment_mime_subtype=mime_subtype)
71
class Evolution(MailClient):
72
"""Evolution mail client."""
73
class ExternalMailClient(MailClient):
74
"""An external mail client."""
74
_client_commands = ['evolution']
76
def _get_client_commands(self):
77
if sys.platform == 'win32':
79
return [win32utils.get_app_path(i) for i in self._client_commands]
81
return self._client_commands
76
83
def compose(self, prompt, to, subject, attachment, mime_subtype,
80
87
os.write(fd, attachment)
83
for name in self._client_commands:
90
self._compose(prompt, to, subject, pathname, mime_subtype, extension)
92
def _compose(self, prompt, to, subject, attach_path, mime_subtype,
94
for name in self._get_client_commands():
85
96
cmdline.extend(self._get_compose_commandline(to, subject,
88
99
subprocess.call(cmdline)
89
100
except OSError, e:
95
106
raise errors.MailClientNotFound(self._client_commands)
97
108
def _get_compose_commandline(self, to, subject, attach_path):
109
raise NotImplementedError
112
class Evolution(ExternalMailClient):
113
"""Evolution mail client."""
115
_client_commands = ['evolution']
117
def _get_compose_commandline(self, to, subject, attach_path):
98
118
message_options = {}
99
119
if subject is not None:
100
120
message_options['subject'] = subject
162
182
return commandline
185
class MAPIClient(ExternalMailClient):
186
"""Default Windows mail client launched using MAPI."""
188
def _compose(self, prompt, to, subject, attach_path, mime_subtype,
190
from bzrlib.util import simplemapi
192
simplemapi.SendMail(to or '', subject or '', '', attach_path)
193
except simplemapi.MAPIError, e:
194
if e.code != simplemapi.MAPI_USER_ABORT:
195
raise errors.MailClientNotFound(['MAPI supported mail client'
196
' (error %d)' % (e.code,)])
165
199
class DefaultMail(MailClient):
166
"""Default mail handling. Tries XDGEmail, falls back to Editor"""
200
"""Default mail handling. Tries XDGEmail (or MAPIClient on Windows),
201
falls back to Editor"""
203
def _mail_client(self):
204
if osutils.supports_mapi():
205
return MAPIClient(self.config)
207
return XDGEmail(self.config)
168
209
def compose(self, prompt, to, subject, attachment, mime_subtype,
171
return XDGEmail(self.config).compose(prompt, to, subject,
172
attachment, mimie_subtype, extension)
212
return self._mail_client().compose(prompt, to, subject,
213
attachment, mimie_subtype,
173
215
except errors.MailClientNotFound:
174
216
return Editor(self.config).compose(prompt, to, subject,
175
217
attachment, mimie_subtype, extension)
177
219
def compose_merge_request(self, to, subject, directive):
179
return XDGEmail(self.config).compose_merge_request(to, subject,
221
return self._mail_client().compose_merge_request(to, subject,
181
223
except errors.MailClientNotFound:
182
224
return Editor(self.config).compose_merge_request(to, subject,