68
70
attachment_mime_subtype=mime_subtype)
71
class Evolution(MailClient):
72
"""Evolution mail client."""
74
_client_commands = ['evolution']
73
class ExternalMailClient(MailClient):
74
"""An external mail client."""
76
76
def compose(self, prompt, to, subject, attachment, mime_subtype,
80
80
os.write(fd, attachment)
83
self._compose(prompt, to, subject, pathname, mime_subtype, extension)
85
def _compose(self, prompt, to, subject, attach_path, mime_subtype,
83
87
for name in self._client_commands:
85
cmdline.extend(self._get_compose_commandline(to, subject,
89
cmdline.extend(self._get_compose_commandline(to, subject,
88
92
subprocess.call(cmdline)
95
99
raise errors.MailClientNotFound(self._client_commands)
97
101
def _get_compose_commandline(self, to, subject, attach_path):
102
raise NotImplementedError
105
class Evolution(ExternalMailClient):
106
"""Evolution mail client."""
108
_client_commands = ['evolution']
110
def _get_compose_commandline(self, to, subject, attach_path):
98
111
message_options = {}
99
112
if subject is not None:
100
113
message_options['subject'] = subject
145
158
return commandline
161
class MAPIClient(ExternalMailClient):
162
"""Default Windows mail client launched using MAPI."""
164
def _compose(self, prompt, to, subject, attach_path, mime_subtype,
166
from bzrlib.util import simplemapi
168
simplemapi.SendMail(to or '', subject or '', '', attach_path)
169
except simplemapi.MAPIError, e:
170
if e.code != simplemapi.MAPI_USER_ABORT:
171
raise errors.MailClientNotFound(['MAPI supported mail client'
172
' (error %d)' % (e.code,)])
148
175
class DefaultMail(MailClient):
149
"""Default mail handling. Tries XDGEmail, falls back to Editor"""
176
"""Default mail handling. Tries XDGEmail (or MAPIClient on Windows),
177
falls back to Editor"""
179
def _mail_client(self):
180
if osutils.supports_mapi():
181
return MAPIClient(self.config)
183
return XDGEmail(self.config)
151
185
def compose(self, prompt, to, subject, attachment, mime_subtype,
154
return XDGEmail(self.config).compose(prompt, to, subject,
155
attachment, mimie_subtype, extension)
188
return self._mail_client().compose(prompt, to, subject,
189
attachment, mimie_subtype,
156
191
except errors.MailClientNotFound:
157
192
return Editor(self.config).compose(prompt, to, subject,
158
193
attachment, mimie_subtype, extension)
160
195
def compose_merge_request(self, to, subject, directive):
162
return XDGEmail(self.config).compose_merge_request(to, subject,
197
return self._mail_client().compose_merge_request(to, subject,
164
199
except errors.MailClientNotFound:
165
200
return Editor(self.config).compose_merge_request(to, subject,