352
354
"""See ExternalMailClient._get_compose_commandline"""
354
356
if from_ is not None:
355
compose_url.append('from=' + urllib.quote(from_))
357
compose_url.append('from=' + urlutils.quote(from_))
356
358
if subject is not None:
357
# Don't use urllib.quote_plus because Claws doesn't seem
359
# Don't use urlutils.quote_plus because Claws doesn't seem
358
360
# to recognise spaces encoded as "+".
359
361
compose_url.append(
360
'subject=' + urllib.quote(self._encode_safe(subject)))
362
'subject=' + urlutils.quote(self._encode_safe(subject)))
361
363
if body is not None:
362
364
compose_url.append(
363
'body=' + urllib.quote(self._encode_safe(body)))
365
'body=' + urlutils.quote(self._encode_safe(body)))
364
366
# to must be supplied for the claws-mail --compose syntax to work.
366
368
raise errors.NoMailAddressSpecified()
377
379
extension, body=None, from_=None):
378
380
"""See ExternalMailClient._compose"""
379
381
if from_ is None:
380
from_ = self.config.get_user_option('email')
382
from_ = self.config.get('email')
381
383
super(Claws, self)._compose(prompt, to, subject, attach_path,
382
384
mime_subtype, extension, body, from_)
534
541
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__)
537
603
class DefaultMail(MailClient):
538
"""Default mail handling. Tries XDGEmail (or MAPIClient on Windows),
604
__doc__ = """Default mail handling. Tries XDGEmail (or MAPIClient on Windows),
539
605
falls back to Editor"""
541
607
supports_body = True
552
618
"""See MailClient.compose"""
554
620
return self._mail_client().compose(prompt, to, subject,
555
attachment, mimie_subtype,
621
attachment, mime_subtype,
556
622
extension, basename, body)
557
623
except errors.MailClientNotFound:
558
624
return Editor(self.config).compose(prompt, to, subject,
559
attachment, mimie_subtype, extension, body)
625
attachment, mime_subtype, extension, body)
561
627
def compose_merge_request(self, to, subject, directive, basename=None,