353
352
"""See ExternalMailClient._get_compose_commandline"""
355
354
if from_ is not None:
356
compose_url.append('from=' + urlutils.quote(from_))
355
compose_url.append('from=' + urllib.quote(from_))
357
356
if subject is not None:
358
# Don't use urlutils.quote_plus because Claws doesn't seem
357
# Don't use urllib.quote_plus because Claws doesn't seem
359
358
# to recognise spaces encoded as "+".
360
359
compose_url.append(
361
'subject=' + urlutils.quote(self._encode_safe(subject)))
360
'subject=' + urllib.quote(self._encode_safe(subject)))
362
361
if body is not None:
363
362
compose_url.append(
364
'body=' + urlutils.quote(self._encode_safe(body)))
363
'body=' + urllib.quote(self._encode_safe(body)))
365
364
# to must be supplied for the claws-mail --compose syntax to work.
367
366
raise errors.NoMailAddressSpecified()
540
534
help=MAPIClient.__doc__)
543
class MailApp(BodyExternalMailClient):
544
__doc__ = """Use MacOS X's Mail.app for sending email messages.
546
Although it would be nice to use appscript, it's not installed
547
with the shipped Python installations. We instead build an
548
AppleScript and invoke the script using osascript(1). We don't
549
use the _encode_safe() routines as it's not clear what encoding
550
osascript expects the script to be in.
553
_client_commands = ['osascript']
555
def _get_compose_commandline(self, to, subject, attach_path, body=None,
557
"""See ExternalMailClient._get_compose_commandline"""
559
fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
562
os.write(fd, 'tell application "Mail"\n')
563
os.write(fd, 'set newMessage to make new outgoing message\n')
564
os.write(fd, 'tell newMessage\n')
566
os.write(fd, 'make new to recipient with properties'
567
' {address:"%s"}\n' % to)
568
if from_ is not None:
569
# though from_ doesn't actually seem to be used
570
os.write(fd, 'set sender to "%s"\n'
571
% sender.replace('"', '\\"'))
572
if subject is not None:
573
os.write(fd, 'set subject to "%s"\n'
574
% subject.replace('"', '\\"'))
576
# FIXME: would be nice to prepend the body to the
577
# existing content (e.g., preserve signature), but
578
# can't seem to figure out the right applescript
580
os.write(fd, 'set content to "%s\\n\n"\n' %
581
body.replace('"', '\\"').replace('\n', '\\n'))
583
if attach_path is not None:
584
# FIXME: would be nice to first append a newline to
585
# ensure the attachment is on a new paragraph, but
586
# can't seem to figure out the right applescript
588
os.write(fd, 'tell content to make new attachment'
589
' with properties {file name:"%s"}'
590
' at after the last paragraph\n'
591
% self._encode_path(attach_path, 'attachment'))
592
os.write(fd, 'set visible to true\n')
593
os.write(fd, 'end tell\n')
594
os.write(fd, 'end tell\n')
596
os.close(fd) # Just close the handle but do not remove the file.
597
return [self.temp_file]
598
mail_client_registry.register('mail.app', MailApp,
599
help=MailApp.__doc__)
602
537
class DefaultMail(MailClient):
603
__doc__ = """Default mail handling. Tries XDGEmail (or MAPIClient on Windows),
538
"""Default mail handling. Tries XDGEmail (or MAPIClient on Windows),
604
539
falls back to Editor"""
606
541
supports_body = True