282
290
"""See ExternalMailClient._get_compose_commandline"""
283
291
message_options = []
284
292
if subject is not None:
285
message_options.extend(
286
['-s', self._encode_safe(subject)])
293
message_options.extend(['-s', self._encode_safe(subject)])
287
294
if attach_path is not None:
288
message_options.extend(
289
['-a', self._encode_path(attach_path, 'attachment')])
295
message_options.extend(['-a',
296
self._encode_path(attach_path, 'attachment')])
290
297
if body is not None:
291
298
# Store the temp file object in self, so that it does not get
292
299
# garbage collected and delete the file before mutt can read it.
293
300
self._temp_file = tempfile.NamedTemporaryFile(
294
prefix="mutt-body-", suffix=".txt", mode="w+")
301
prefix="mutt-body-", suffix=".txt")
295
302
self._temp_file.write(body)
296
303
self._temp_file.flush()
297
304
message_options.extend(['-i', self._temp_file.name])
298
305
if to is not None:
299
306
message_options.extend(['--', self._encode_safe(to)])
300
307
return message_options
303
308
mail_client_registry.register('mutt', Mutt,
304
309
help=Mutt.__doc__)
583
576
_client_commands = ['osascript']
585
578
def _get_compose_commandline(self, to, subject, attach_path, body=None,
587
"""See ExternalMailClient._get_compose_commandline"""
589
fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
592
os.write(fd, 'tell application "Mail"\n')
593
os.write(fd, 'set newMessage to make new outgoing message\n')
594
os.write(fd, 'tell newMessage\n')
596
os.write(fd, 'make new to recipient with properties'
597
' {address:"%s"}\n' % to)
598
if from_ is not None:
599
# though from_ doesn't actually seem to be used
600
os.write(fd, 'set sender to "%s"\n'
601
% from_.replace('"', '\\"'))
602
if subject is not None:
603
os.write(fd, 'set subject to "%s"\n'
604
% subject.replace('"', '\\"'))
606
# FIXME: would be nice to prepend the body to the
607
# existing content (e.g., preserve signature), but
608
# can't seem to figure out the right applescript
610
os.write(fd, 'set content to "%s\\n\n"\n' %
611
body.replace('"', '\\"').replace('\n', '\\n'))
613
if attach_path is not None:
614
# FIXME: would be nice to first append a newline to
615
# ensure the attachment is on a new paragraph, but
616
# can't seem to figure out the right applescript
618
os.write(fd, 'tell content to make new attachment'
619
' with properties {file name:"%s"}'
620
' at after the last paragraph\n'
621
% self._encode_path(attach_path, 'attachment'))
622
os.write(fd, 'set visible to true\n')
623
os.write(fd, 'end tell\n')
624
os.write(fd, 'end tell\n')
626
os.close(fd) # Just close the handle but do not remove the file.
627
return [self.temp_file]
580
"""See ExternalMailClient._get_compose_commandline"""
582
fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
585
os.write(fd, 'tell application "Mail"\n')
586
os.write(fd, 'set newMessage to make new outgoing message\n')
587
os.write(fd, 'tell newMessage\n')
589
os.write(fd, 'make new to recipient with properties'
590
' {address:"%s"}\n' % to)
591
if from_ is not None:
592
# though from_ doesn't actually seem to be used
593
os.write(fd, 'set sender to "%s"\n'
594
% sender.replace('"', '\\"'))
595
if subject is not None:
596
os.write(fd, 'set subject to "%s"\n'
597
% subject.replace('"', '\\"'))
599
# FIXME: would be nice to prepend the body to the
600
# existing content (e.g., preserve signature), but
601
# can't seem to figure out the right applescript
603
os.write(fd, 'set content to "%s\\n\n"\n' %
604
body.replace('"', '\\"').replace('\n', '\\n'))
606
if attach_path is not None:
607
# FIXME: would be nice to first append a newline to
608
# ensure the attachment is on a new paragraph, but
609
# can't seem to figure out the right applescript
611
os.write(fd, 'tell content to make new attachment'
612
' with properties {file name:"%s"}'
613
' at after the last paragraph\n'
614
% self._encode_path(attach_path, 'attachment'))
615
os.write(fd, 'set visible to true\n')
616
os.write(fd, 'end tell\n')
617
os.write(fd, 'end tell\n')
619
os.close(fd) # Just close the handle but do not remove the file.
620
return [self.temp_file]
630
621
mail_client_registry.register('mail.app', MailApp,
631
622
help=MailApp.__doc__)
652
643
attachment, mime_subtype,
653
644
extension, basename, body)
654
645
except MailClientNotFound:
655
return Editor(self.config).compose(
656
prompt, to, subject, attachment, mime_subtype, extension, body)
646
return Editor(self.config).compose(prompt, to, subject,
647
attachment, mime_subtype, extension, body)
658
649
def compose_merge_request(self, to, subject, directive, basename=None,
660
651
"""See MailClient.compose_merge_request"""
662
return self._mail_client().compose_merge_request(
663
to, subject, directive, basename=basename, body=body)
653
return self._mail_client().compose_merge_request(to, subject,
654
directive, basename=basename, body=body)
664
655
except MailClientNotFound:
665
return Editor(self.config).compose_merge_request(
666
to, subject, directive, basename=basename, body=body)
669
mail_client_registry.register(u'default', DefaultMail,
656
return Editor(self.config).compose_merge_request(to, subject,
657
directive, basename=basename, body=body)
658
mail_client_registry.register('default', DefaultMail,
670
659
help=DefaultMail.__doc__)
671
mail_client_registry.default_key = u'default'
660
mail_client_registry.default_key = 'default'
673
opt_mail_client = _mod_config.RegistryOption(
674
'mail_client', mail_client_registry, help='E-mail client to use.',
662
opt_mail_client = _mod_config.RegistryOption('mail_client',
663
mail_client_registry, help='E-mail client to use.', invalid='error')