155
155
extension, **kwargs)
157
157
def _compose(self, prompt, to, subject, attach_path, mime_subtype,
158
extension, body=None, from_=None):
158
extension, body=None):
159
159
"""Invoke a mail client as a commandline process.
161
161
Overridden by MAPIClient.
166
166
"text", but the precise subtype can be specified here
167
167
:param extension: A file extension (including period) associated with
168
168
the attachment type.
169
:param body: Optional body text.
170
:param from_: Optional From: header.
172
170
for name in self._get_client_commands():
173
171
cmdline = [self._encode_path(name, 'executable')]
257
253
help=Evolution.__doc__)
260
class Mutt(BodyExternalMailClient):
256
class Mutt(ExternalMailClient):
261
257
"""Mutt mail client."""
263
259
_client_commands = ['mutt']
265
def _get_compose_commandline(self, to, subject, attach_path, body=None):
261
def _get_compose_commandline(self, to, subject, attach_path):
266
262
"""See ExternalMailClient._get_compose_commandline"""
267
263
message_options = []
268
264
if subject is not None:
270
266
if attach_path is not None:
271
267
message_options.extend(['-a',
272
268
self._encode_path(attach_path, 'attachment')])
274
# Store the temp file object in self, so that it does not get
275
# garbage collected and delete the file before mutt can read it.
276
self._temp_file = tempfile.NamedTemporaryFile(
277
prefix="mutt-body-", suffix=".txt")
278
self._temp_file.write(body)
279
self._temp_file.flush()
280
message_options.extend(['-i', self._temp_file.name])
281
269
if to is not None:
282
270
message_options.extend(['--', self._encode_safe(to)])
283
271
return message_options
343
331
class Claws(ExternalMailClient):
344
332
"""Claws mail client."""
348
334
_client_commands = ['claws-mail']
350
def _get_compose_commandline(self, to, subject, attach_path, body=None,
336
def _get_compose_commandline(self, to, subject, attach_path):
352
337
"""See ExternalMailClient._get_compose_commandline"""
354
if from_ is not None:
355
compose_url.append('from=' + urllib.quote(from_))
338
compose_url = ['mailto:']
340
compose_url.append(self._encode_safe(to))
341
compose_url.append('?')
356
342
if subject is not None:
357
343
# Don't use urllib.quote_plus because Claws doesn't seem
358
344
# to recognise spaces encoded as "+".
359
345
compose_url.append(
360
'subject=' + urllib.quote(self._encode_safe(subject)))
363
'body=' + urllib.quote(self._encode_safe(body)))
364
# to must be supplied for the claws-mail --compose syntax to work.
366
raise errors.NoMailAddressSpecified()
367
compose_url = 'mailto:%s?%s' % (
368
self._encode_safe(to), '&'.join(compose_url))
346
'subject=%s' % urllib.quote(self._encode_safe(subject)))
369
347
# Collect command-line options.
370
message_options = ['--compose', compose_url]
348
message_options = ['--compose', ''.join(compose_url)]
371
349
if attach_path is not None:
372
350
message_options.extend(
373
351
['--attach', self._encode_path(attach_path, 'attachment')])
374
352
return message_options
376
def _compose(self, prompt, to, subject, attach_path, mime_subtype,
377
extension, body=None, from_=None):
378
"""See ExternalMailClient._compose"""
380
from_ = self.config.get_user_option('email')
381
super(Claws, self)._compose(prompt, to, subject, attach_path,
382
mime_subtype, extension, body, from_)
385
353
mail_client_registry.register('claws', Claws,
386
354
help=Claws.__doc__)