354
352
"""See ExternalMailClient._get_compose_commandline"""
356
354
if from_ is not None:
357
compose_url.append('from=' + urlutils.quote(from_))
355
compose_url.append('from=' + urllib.quote(from_))
358
356
if subject is not None:
359
# Don't use urlutils.quote_plus because Claws doesn't seem
357
# Don't use urllib.quote_plus because Claws doesn't seem
360
358
# to recognise spaces encoded as "+".
361
359
compose_url.append(
362
'subject=' + urlutils.quote(self._encode_safe(subject)))
360
'subject=' + urllib.quote(self._encode_safe(subject)))
363
361
if body is not None:
364
362
compose_url.append(
365
'body=' + urlutils.quote(self._encode_safe(body)))
363
'body=' + urllib.quote(self._encode_safe(body)))
366
364
# to must be supplied for the claws-mail --compose syntax to work.
368
366
raise errors.NoMailAddressSpecified()
379
377
extension, body=None, from_=None):
380
378
"""See ExternalMailClient._compose"""
381
379
if from_ is None:
382
from_ = self.config.get('email')
380
from_ = self.config.get_user_option('email')
383
381
super(Claws, self)._compose(prompt, to, subject, attach_path,
384
382
mime_subtype, extension, body, from_)
541
534
help=MAPIClient.__doc__)
544
class MailApp(BodyExternalMailClient):
545
__doc__ = """Use MacOS X's Mail.app for sending email messages.
547
Although it would be nice to use appscript, it's not installed
548
with the shipped Python installations. We instead build an
549
AppleScript and invoke the script using osascript(1). We don't
550
use the _encode_safe() routines as it's not clear what encoding
551
osascript expects the script to be in.
554
_client_commands = ['osascript']
556
def _get_compose_commandline(self, to, subject, attach_path, body=None,
558
"""See ExternalMailClient._get_compose_commandline"""
560
fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
563
os.write(fd, 'tell application "Mail"\n')
564
os.write(fd, 'set newMessage to make new outgoing message\n')
565
os.write(fd, 'tell newMessage\n')
567
os.write(fd, 'make new to recipient with properties'
568
' {address:"%s"}\n' % to)
569
if from_ is not None:
570
# though from_ doesn't actually seem to be used
571
os.write(fd, 'set sender to "%s"\n'
572
% sender.replace('"', '\\"'))
573
if subject is not None:
574
os.write(fd, 'set subject to "%s"\n'
575
% subject.replace('"', '\\"'))
577
# FIXME: would be nice to prepend the body to the
578
# existing content (e.g., preserve signature), but
579
# can't seem to figure out the right applescript
581
os.write(fd, 'set content to "%s\\n\n"\n' %
582
body.replace('"', '\\"').replace('\n', '\\n'))
584
if attach_path is not None:
585
# FIXME: would be nice to first append a newline to
586
# ensure the attachment is on a new paragraph, but
587
# can't seem to figure out the right applescript
589
os.write(fd, 'tell content to make new attachment'
590
' with properties {file name:"%s"}'
591
' at after the last paragraph\n'
592
% self._encode_path(attach_path, 'attachment'))
593
os.write(fd, 'set visible to true\n')
594
os.write(fd, 'end tell\n')
595
os.write(fd, 'end tell\n')
597
os.close(fd) # Just close the handle but do not remove the file.
598
return [self.temp_file]
599
mail_client_registry.register('mail.app', MailApp,
600
help=MailApp.__doc__)
603
537
class DefaultMail(MailClient):
604
__doc__ = """Default mail handling. Tries XDGEmail (or MAPIClient on Windows),
538
"""Default mail handling. Tries XDGEmail (or MAPIClient on Windows),
605
539
falls back to Editor"""
607
541
supports_body = True
618
552
"""See MailClient.compose"""
620
554
return self._mail_client().compose(prompt, to, subject,
621
attachment, mime_subtype,
555
attachment, mimie_subtype,
622
556
extension, basename, body)
623
557
except errors.MailClientNotFound:
624
558
return Editor(self.config).compose(prompt, to, subject,
625
attachment, mime_subtype, extension, body)
559
attachment, mimie_subtype, extension, body)
627
561
def compose_merge_request(self, to, subject, directive, basename=None,