~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mail_client.py

  • Committer: Danny van Heumen
  • Date: 2010-03-09 21:42:11 UTC
  • mto: (4634.139.5 2.0)
  • mto: This revision was merged to the branch mainline in revision 5160.
  • Revision ID: danny@dannyvanheumen.nl-20100309214211-iqh42x6qcikgd9p3
Reverted now-useless TODO list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
89
89
 
90
90
 
91
91
class Editor(MailClient):
92
 
    __doc__ = """DIY mail client that uses commit message editor"""
 
92
    """DIY mail client that uses commit message editor"""
93
93
 
94
94
    supports_body = True
95
95
 
230
230
 
231
231
 
232
232
class ExternalMailClient(BodyExternalMailClient):
233
 
    __doc__ = """An external mail client."""
 
233
    """An external mail client."""
234
234
 
235
235
    supports_body = False
236
236
 
237
237
 
238
238
class Evolution(BodyExternalMailClient):
239
 
    __doc__ = """Evolution mail client."""
 
239
    """Evolution mail client."""
240
240
 
241
241
    _client_commands = ['evolution']
242
242
 
258
258
 
259
259
 
260
260
class Mutt(BodyExternalMailClient):
261
 
    __doc__ = """Mutt mail client."""
 
261
    """Mutt mail client."""
262
262
 
263
263
    _client_commands = ['mutt']
264
264
 
286
286
 
287
287
 
288
288
class Thunderbird(BodyExternalMailClient):
289
 
    __doc__ = """Mozilla Thunderbird (or Icedove)
 
289
    """Mozilla Thunderbird (or Icedove)
290
290
 
291
291
    Note that Thunderbird 1.5 is buggy and does not support setting
292
292
    "to" simultaneously with including a attachment.
321
321
 
322
322
 
323
323
class KMail(ExternalMailClient):
324
 
    __doc__ = """KDE mail client."""
 
324
    """KDE mail client."""
325
325
 
326
326
    _client_commands = ['kmail']
327
327
 
341
341
 
342
342
 
343
343
class Claws(ExternalMailClient):
344
 
    __doc__ = """Claws mail client."""
 
344
    """Claws mail client."""
345
345
 
346
346
    supports_body = True
347
347
 
387
387
 
388
388
 
389
389
class XDGEmail(BodyExternalMailClient):
390
 
    __doc__ = """xdg-email attempts to invoke the user's preferred mail client"""
 
390
    """xdg-email attempts to invoke the user's preferred mail client"""
391
391
 
392
392
    _client_commands = ['xdg-email']
393
393
 
409
409
 
410
410
 
411
411
class EmacsMail(ExternalMailClient):
412
 
    __doc__ = """Call emacsclient to have a mail buffer.
 
412
    """Call emacsclient to have a mail buffer.
413
413
 
414
414
    This only work for emacs >= 22.1 due to recent -e/--eval support.
415
415
 
424
424
 
425
425
    _client_commands = ['emacsclient']
426
426
 
427
 
    def __init__(self, config):
428
 
        super(EmacsMail, self).__init__(config)
429
 
        self.elisp_tmp_file = None
430
 
 
431
427
    def _prepare_send_function(self):
432
428
        """Write our wrapper function into a temporary file.
433
429
 
504
500
        if attach_path is not None:
505
501
            # Do not create a file if there is no attachment
506
502
            elisp = self._prepare_send_function()
507
 
            self.elisp_tmp_file = elisp
508
503
            lmmform = '(load "%s")' % elisp
509
504
            mmform  = '(bzr-add-mime-att "%s")' % \
510
505
                self._encode_path(attach_path, 'attachment')
519
514
 
520
515
 
521
516
class MAPIClient(BodyExternalMailClient):
522
 
    __doc__ = """Default Windows mail client launched using MAPI."""
 
517
    """Default Windows mail client launched using MAPI."""
523
518
 
524
519
    def _compose(self, prompt, to, subject, attach_path, mime_subtype,
525
520
                 extension, body=None):
539
534
                              help=MAPIClient.__doc__)
540
535
 
541
536
 
542
 
class MailApp(BodyExternalMailClient):
543
 
    __doc__ = """Use MacOS X's Mail.app for sending email messages.
544
 
 
545
 
    Although it would be nice to use appscript, it's not installed
546
 
    with the shipped Python installations.  We instead build an
547
 
    AppleScript and invoke the script using osascript(1).  We don't
548
 
    use the _encode_safe() routines as it's not clear what encoding
549
 
    osascript expects the script to be in.
550
 
    """
551
 
 
552
 
    _client_commands = ['osascript']
553
 
 
554
 
    def _get_compose_commandline(self, to, subject, attach_path, body=None,
555
 
                                from_=None):
556
 
       """See ExternalMailClient._get_compose_commandline"""
557
 
 
558
 
       fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
559
 
                                         suffix=".scpt")
560
 
       try:
561
 
           os.write(fd, 'tell application "Mail"\n')
562
 
           os.write(fd, 'set newMessage to make new outgoing message\n')
563
 
           os.write(fd, 'tell newMessage\n')
564
 
           if to is not None:
565
 
               os.write(fd, 'make new to recipient with properties'
566
 
                   ' {address:"%s"}\n' % to)
567
 
           if from_ is not None:
568
 
               # though from_ doesn't actually seem to be used
569
 
               os.write(fd, 'set sender to "%s"\n'
570
 
                   % sender.replace('"', '\\"'))
571
 
           if subject is not None:
572
 
               os.write(fd, 'set subject to "%s"\n'
573
 
                   % subject.replace('"', '\\"'))
574
 
           if body is not None:
575
 
               # FIXME: would be nice to prepend the body to the
576
 
               # existing content (e.g., preserve signature), but
577
 
               # can't seem to figure out the right applescript
578
 
               # incantation.
579
 
               os.write(fd, 'set content to "%s\\n\n"\n' %
580
 
                   body.replace('"', '\\"').replace('\n', '\\n'))
581
 
 
582
 
           if attach_path is not None:
583
 
               # FIXME: would be nice to first append a newline to
584
 
               # ensure the attachment is on a new paragraph, but
585
 
               # can't seem to figure out the right applescript
586
 
               # incantation.
587
 
               os.write(fd, 'tell content to make new attachment'
588
 
                   ' with properties {file name:"%s"}'
589
 
                   ' at after the last paragraph\n'
590
 
                   % self._encode_path(attach_path, 'attachment'))
591
 
           os.write(fd, 'set visible to true\n')
592
 
           os.write(fd, 'end tell\n')
593
 
           os.write(fd, 'end tell\n')
594
 
       finally:
595
 
           os.close(fd) # Just close the handle but do not remove the file.
596
 
       return [self.temp_file]
597
 
mail_client_registry.register('mail.app', MailApp,
598
 
                              help=MailApp.__doc__)
599
 
 
600
 
 
601
537
class DefaultMail(MailClient):
602
 
    __doc__ = """Default mail handling.  Tries XDGEmail (or MAPIClient on Windows),
 
538
    """Default mail handling.  Tries XDGEmail (or MAPIClient on Windows),
603
539
    falls back to Editor"""
604
540
 
605
541
    supports_body = True
634
570
mail_client_registry.register('default', DefaultMail,
635
571
                              help=DefaultMail.__doc__)
636
572
mail_client_registry.default_key = 'default'
637
 
 
638