580
599
_client_commands = ['osascript']
582
601
def _get_compose_commandline(self, to, subject, attach_path, body=None,
584
"""See ExternalMailClient._get_compose_commandline"""
586
fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
589
os.write(fd, 'tell application "Mail"\n')
590
os.write(fd, 'set newMessage to make new outgoing message\n')
591
os.write(fd, 'tell newMessage\n')
593
os.write(fd, 'make new to recipient with properties'
594
' {address:"%s"}\n' % to)
595
if from_ is not None:
596
# though from_ doesn't actually seem to be used
597
os.write(fd, 'set sender to "%s"\n'
598
% sender.replace('"', '\\"'))
599
if subject is not None:
600
os.write(fd, 'set subject to "%s"\n'
601
% subject.replace('"', '\\"'))
603
# FIXME: would be nice to prepend the body to the
604
# existing content (e.g., preserve signature), but
605
# can't seem to figure out the right applescript
607
os.write(fd, 'set content to "%s\\n\n"\n' %
608
body.replace('"', '\\"').replace('\n', '\\n'))
610
if attach_path is not None:
611
# FIXME: would be nice to first append a newline to
612
# ensure the attachment is on a new paragraph, but
613
# can't seem to figure out the right applescript
615
os.write(fd, 'tell content to make new attachment'
616
' with properties {file name:"%s"}'
617
' at after the last paragraph\n'
618
% self._encode_path(attach_path, 'attachment'))
619
os.write(fd, 'set visible to true\n')
620
os.write(fd, 'end tell\n')
621
os.write(fd, 'end tell\n')
623
os.close(fd) # Just close the handle but do not remove the file.
624
return [self.temp_file]
603
"""See ExternalMailClient._get_compose_commandline"""
605
fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
608
os.write(fd, 'tell application "Mail"\n')
609
os.write(fd, 'set newMessage to make new outgoing message\n')
610
os.write(fd, 'tell newMessage\n')
612
os.write(fd, 'make new to recipient with properties'
613
' {address:"%s"}\n' % to)
614
if from_ is not None:
615
# though from_ doesn't actually seem to be used
616
os.write(fd, 'set sender to "%s"\n'
617
% from_.replace('"', '\\"'))
618
if subject is not None:
619
os.write(fd, 'set subject to "%s"\n'
620
% subject.replace('"', '\\"'))
622
# FIXME: would be nice to prepend the body to the
623
# existing content (e.g., preserve signature), but
624
# can't seem to figure out the right applescript
626
os.write(fd, 'set content to "%s\\n\n"\n' %
627
body.replace('"', '\\"').replace('\n', '\\n'))
629
if attach_path is not None:
630
# FIXME: would be nice to first append a newline to
631
# ensure the attachment is on a new paragraph, but
632
# can't seem to figure out the right applescript
634
os.write(fd, 'tell content to make new attachment'
635
' with properties {file name:"%s"}'
636
' at after the last paragraph\n'
637
% self._encode_path(attach_path, 'attachment'))
638
os.write(fd, 'set visible to true\n')
639
os.write(fd, 'end tell\n')
640
os.write(fd, 'end tell\n')
642
os.close(fd) # Just close the handle but do not remove the file.
643
return [self.temp_file]
625
646
mail_client_registry.register('mail.app', MailApp,
626
647
help=MailApp.__doc__)
647
668
attachment, mime_subtype,
648
669
extension, basename, body)
649
670
except MailClientNotFound:
650
return Editor(self.config).compose(prompt, to, subject,
651
attachment, mime_subtype, extension, body)
671
return Editor(self.config).compose(
672
prompt, to, subject, attachment, mime_subtype, extension, body)
653
674
def compose_merge_request(self, to, subject, directive, basename=None,
655
676
"""See MailClient.compose_merge_request"""
657
return self._mail_client().compose_merge_request(to, subject,
658
directive, basename=basename, body=body)
678
return self._mail_client().compose_merge_request(
679
to, subject, directive, basename=basename, body=body)
659
680
except MailClientNotFound:
660
return Editor(self.config).compose_merge_request(to, subject,
661
directive, basename=basename, body=body)
681
return Editor(self.config).compose_merge_request(
682
to, subject, directive, basename=basename, body=body)
662
685
mail_client_registry.register(u'default', DefaultMail,
663
686
help=DefaultMail.__doc__)
664
687
mail_client_registry.default_key = u'default'
666
opt_mail_client = _mod_config.RegistryOption('mail_client',
667
mail_client_registry, help='E-mail client to use.', invalid='error')
689
opt_mail_client = _mod_config.RegistryOption(
690
'mail_client', mail_client_registry, help='E-mail client to use.',