~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mail_client.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-30 12:52:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6418.
  • Revision ID: jelmer@samba.org-20111230125254-igy1abnixsvulfqd
Simplify code a bit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import errno
18
20
import os
19
21
import subprocess
20
22
import sys
21
23
import tempfile
22
 
import urllib
23
24
 
24
25
import bzrlib
25
26
from bzrlib import (
89
90
 
90
91
 
91
92
class Editor(MailClient):
92
 
    """DIY mail client that uses commit message editor"""
 
93
    __doc__ = """DIY mail client that uses commit message editor"""
93
94
 
94
95
    supports_body = True
95
96
 
230
231
 
231
232
 
232
233
class ExternalMailClient(BodyExternalMailClient):
233
 
    """An external mail client."""
 
234
    __doc__ = """An external mail client."""
234
235
 
235
236
    supports_body = False
236
237
 
237
238
 
238
239
class Evolution(BodyExternalMailClient):
239
 
    """Evolution mail client."""
 
240
    __doc__ = """Evolution mail client."""
240
241
 
241
242
    _client_commands = ['evolution']
242
243
 
258
259
 
259
260
 
260
261
class Mutt(BodyExternalMailClient):
261
 
    """Mutt mail client."""
 
262
    __doc__ = """Mutt mail client."""
262
263
 
263
264
    _client_commands = ['mutt']
264
265
 
286
287
 
287
288
 
288
289
class Thunderbird(BodyExternalMailClient):
289
 
    """Mozilla Thunderbird (or Icedove)
 
290
    __doc__ = """Mozilla Thunderbird (or Icedove)
290
291
 
291
292
    Note that Thunderbird 1.5 is buggy and does not support setting
292
293
    "to" simultaneously with including a attachment.
310
311
            message_options['attachment'] = urlutils.local_path_to_url(
311
312
                attach_path)
312
313
        if body is not None:
313
 
            options_list = ['body=%s' % urllib.quote(self._encode_safe(body))]
 
314
            options_list = ['body=%s' % urlutils.quote(self._encode_safe(body))]
314
315
        else:
315
316
            options_list = []
316
317
        options_list.extend(["%s='%s'" % (k, v) for k, v in
321
322
 
322
323
 
323
324
class KMail(ExternalMailClient):
324
 
    """KDE mail client."""
 
325
    __doc__ = """KDE mail client."""
325
326
 
326
327
    _client_commands = ['kmail']
327
328
 
341
342
 
342
343
 
343
344
class Claws(ExternalMailClient):
344
 
    """Claws mail client."""
 
345
    __doc__ = """Claws mail client."""
345
346
 
346
347
    supports_body = True
347
348
 
352
353
        """See ExternalMailClient._get_compose_commandline"""
353
354
        compose_url = []
354
355
        if from_ is not None:
355
 
            compose_url.append('from=' + urllib.quote(from_))
 
356
            compose_url.append('from=' + urlutils.quote(from_))
356
357
        if subject is not None:
357
 
            # Don't use urllib.quote_plus because Claws doesn't seem
 
358
            # Don't use urlutils.quote_plus because Claws doesn't seem
358
359
            # to recognise spaces encoded as "+".
359
360
            compose_url.append(
360
 
                'subject=' + urllib.quote(self._encode_safe(subject)))
 
361
                'subject=' + urlutils.quote(self._encode_safe(subject)))
361
362
        if body is not None:
362
363
            compose_url.append(
363
 
                'body=' + urllib.quote(self._encode_safe(body)))
 
364
                'body=' + urlutils.quote(self._encode_safe(body)))
364
365
        # to must be supplied for the claws-mail --compose syntax to work.
365
366
        if to is None:
366
367
            raise errors.NoMailAddressSpecified()
387
388
 
388
389
 
389
390
class XDGEmail(BodyExternalMailClient):
390
 
    """xdg-email attempts to invoke the user's preferred mail client"""
 
391
    __doc__ = """xdg-email attempts to invoke the user's preferred mail client"""
391
392
 
392
393
    _client_commands = ['xdg-email']
393
394
 
409
410
 
410
411
 
411
412
class EmacsMail(ExternalMailClient):
412
 
    """Call emacsclient to have a mail buffer.
 
413
    __doc__ = """Call emacsclient to have a mail buffer.
413
414
 
414
415
    This only work for emacs >= 22.1 due to recent -e/--eval support.
415
416
 
519
520
 
520
521
 
521
522
class MAPIClient(BodyExternalMailClient):
522
 
    """Default Windows mail client launched using MAPI."""
 
523
    __doc__ = """Default Windows mail client launched using MAPI."""
523
524
 
524
525
    def _compose(self, prompt, to, subject, attach_path, mime_subtype,
525
526
                 extension, body=None):
540
541
 
541
542
 
542
543
class MailApp(BodyExternalMailClient):
543
 
    """Use MacOS X's Mail.app for sending email messages.
 
544
    __doc__ = """Use MacOS X's Mail.app for sending email messages.
544
545
 
545
546
    Although it would be nice to use appscript, it's not installed
546
547
    with the shipped Python installations.  We instead build an
599
600
 
600
601
 
601
602
class DefaultMail(MailClient):
602
 
    """Default mail handling.  Tries XDGEmail (or MAPIClient on Windows),
 
603
    __doc__ = """Default mail handling.  Tries XDGEmail (or MAPIClient on Windows),
603
604
    falls back to Editor"""
604
605
 
605
606
    supports_body = True