Rev 3646: (Neil Martinsen-Burrell) Mail clients listed in a registry. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sat Aug 23 19:24:53 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3646
revision-id: pqm at pqm.ubuntu.com-20080823182447-e5emry5ut2d0c3ex
parent: pqm at pqm.ubuntu.com-20080823174134-lx67nymraun1onby
parent: jelmer at samba.org-20080823175334-mipkzuwc62qbhd9u
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2008-08-23 19:24:47 +0100
message:
  (Neil Martinsen-Burrell) Mail clients listed in a registry.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 3644.1.2
    revision-id: jelmer at samba.org-20080823175334-mipkzuwc62qbhd9u
    parent: jelmer at samba.org-20080823152030-zz5d4mcu1rlp1q51
    parent: nmb at wartburg.edu-20080819194906-ozq57i7uozwnwpos
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: bzr.dev
    timestamp: Sat 2008-08-23 19:53:34 +0200
    message:
      Merge Neil's email client registry patch.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 3638.2.5
    revision-id: nmb at wartburg.edu-20080819194906-ozq57i7uozwnwpos
    parent: nmb at wartburg.edu-20080819193359-7ae05y62mfu6x52a
    committer: Neil Martinsen-Burrell <nmb at wartburg.edu>
    branch nick: email-client-registry
    timestamp: Tue 2008-08-19 14:49:06 -0500
    message:
      use docstrings as help messages for registered mail clients
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 3638.2.4
    revision-id: nmb at wartburg.edu-20080819193359-7ae05y62mfu6x52a
    parent: nmb at wartburg.edu-20080819160950-3toy7mhz2ticb6dc
    committer: Neil Martinsen-Burrell <nmb at wartburg.edu>
    branch nick: email-client-registry
    timestamp: Tue 2008-08-19 14:33:59 -0500
    message:
      Address JAMs review.  Dont use register_lazy and dont lazy_import anything other than modules
    modified:
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 3638.2.3
    revision-id: nmb at wartburg.edu-20080819160950-3toy7mhz2ticb6dc
    parent: nmb at wartburg.edu-20080819151434-om1o3k0np4dem3uw
    committer: Neil Martinsen-Burrell <nmb at wartburg.edu>
    branch nick: email-client-registry
    timestamp: Tue 2008-08-19 11:09:50 -0500
    message:
      Mention mail_client_registry in NEWS and help
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
    ------------------------------------------------------------
    revno: 3638.2.2
    revision-id: nmb at wartburg.edu-20080819151434-om1o3k0np4dem3uw
    parent: nmb at wartburg.edu-20080819031255-bs3kjjz8aresvu92
    committer: Neil Martinsen-Burrell <nmb at wartburg.edu>
    branch nick: email-client-registry
    timestamp: Tue 2008-08-19 10:14:34 -0500
    message:
      put registry information with each class
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 3638.2.1
    revision-id: nmb at wartburg.edu-20080819031255-bs3kjjz8aresvu92
    parent: pqm at pqm.ubuntu.com-20080816000954-t0401ff8s3ydnkr6
    committer: Neil Martinsen-Burrell <nmb at wartburg.edu>
    branch nick: email-client-registry
    timestamp: Mon 2008-08-18 22:12:55 -0500
    message:
      Use a registry for mail clients.
    modified:
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
=== modified file 'NEWS'
--- a/NEWS	2008-08-23 15:20:30 +0000
+++ b/NEWS	2008-08-23 17:53:34 +0000
@@ -80,6 +80,11 @@
       is unknown in both source and target.
       (Robert Collins, Aaron Bentley)
 
+    * Mail clients for `bzr send` are now listed in a registry.  This
+      allows plugins to add new clients by registering them with
+      ``bzrlib.mail_client.mail_client_registry``.  All of the built-in
+      clients now use this mechanism.  (Neil Martinsen-Burrell)
+
 
 bzr 1.6rc5 2008-08-19
 ---------------------

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-08-19 03:08:37 +0000
+++ b/bzrlib/builtins.py	2008-08-23 17:53:34 +0000
@@ -4112,7 +4112,7 @@
     (For Thunderbird 1.5, this works around some bugs.)  Supported values for
     specific clients are "evolution", "kmail", "mutt", and "thunderbird";
     generic options are "default", "editor", "emacsclient", "mapi", and
-    "xdg-email".
+    "xdg-email".  Plugins may also add supported clients.
 
     If mail is being sent, a to address is required.  This can be supplied
     either on the commandline, by setting the submit_to configuration

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2008-06-16 19:09:28 +0000
+++ b/bzrlib/config.py	2008-08-19 19:33:59 +0000
@@ -147,21 +147,9 @@
     def get_mail_client(self):
         """Get a mail client to use"""
         selected_client = self.get_user_option('mail_client')
+        _registry = mail_client.mail_client_registry
         try:
-            mail_client_class = {
-                None: mail_client.DefaultMail,
-                # Specific clients
-                'emacsclient': mail_client.EmacsMail,
-                'evolution': mail_client.Evolution,
-                'kmail': mail_client.KMail,
-                'mutt': mail_client.Mutt,
-                'thunderbird': mail_client.Thunderbird,
-                # Generic options
-                'default': mail_client.DefaultMail,
-                'editor': mail_client.Editor,
-                'mapi': mail_client.MAPIClient,
-                'xdg-email': mail_client.XDGEmail,
-            }[selected_client]
+            mail_client_class = _registry.get(selected_client)
         except KeyError:
             raise errors.UnknownMailClient(selected_client)
         return mail_client_class(self)

=== modified file 'bzrlib/mail_client.py'
--- a/bzrlib/mail_client.py	2008-07-05 14:19:34 +0000
+++ b/bzrlib/mail_client.py	2008-08-19 19:49:06 +0000
@@ -27,8 +27,11 @@
     msgeditor,
     osutils,
     urlutils,
+    registry
     )
 
+mail_client_registry = registry.Registry()
+
 
 class MailClient(object):
     """A mail client that can send messages with attachements."""
@@ -109,6 +112,8 @@
                                         body,
                                         attachment,
                                         attachment_mime_subtype=mime_subtype)
+mail_client_registry.register('editor', Editor,
+                              help=Editor.__doc__)
 
 
 class ExternalMailClient(MailClient):
@@ -222,6 +227,8 @@
                         sorted(message_options.iteritems())]
         return ['mailto:%s?%s' % (self._encode_safe(to or ''),
             '&'.join(options_list))]
+mail_client_registry.register('evolution', Evolution,
+                              help=Evolution.__doc__)
 
 
 class Mutt(ExternalMailClient):
@@ -240,6 +247,8 @@
         if to is not None:
             message_options.append(self._encode_safe(to))
         return message_options
+mail_client_registry.register('mutt', Mutt,
+                              help=Mutt.__doc__)
 
 
 class Thunderbird(ExternalMailClient):
@@ -253,7 +262,8 @@
     """
 
     _client_commands = ['thunderbird', 'mozilla-thunderbird', 'icedove',
-        '/Applications/Mozilla/Thunderbird.app/Contents/MacOS/thunderbird-bin']
+        '/Applications/Mozilla/Thunderbird.app/Contents/MacOS/thunderbird-bin',
+        '/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin']
 
     def _get_compose_commandline(self, to, subject, attach_path):
         """See ExternalMailClient._get_compose_commandline"""
@@ -268,6 +278,8 @@
         options_list = ["%s='%s'" % (k, v) for k, v in
                         sorted(message_options.iteritems())]
         return ['-compose', ','.join(options_list)]
+mail_client_registry.register('thunderbird', Thunderbird,
+                              help=Thunderbird.__doc__)
 
 
 class KMail(ExternalMailClient):
@@ -286,6 +298,8 @@
         if to is not None:
             message_options.extend([self._encode_safe(to)])
         return message_options
+mail_client_registry.register('kmail', KMail,
+                              help=KMail.__doc__)
 
 
 class XDGEmail(ExternalMailClient):
@@ -304,6 +318,8 @@
             commandline.extend(['--attach',
                 self._encode_path(attach_path, 'attachment')])
         return commandline
+mail_client_registry.register('xdg-email', XDGEmail,
+                              help=XDGEmail.__doc__)
 
 
 class EmacsMail(ExternalMailClient):
@@ -405,6 +421,8 @@
             commandline.append(rmform)
 
         return commandline
+mail_client_registry.register('emacsclient', EmacsMail,
+                              help=EmacsMail.__doc__)
 
 
 class MAPIClient(ExternalMailClient):
@@ -423,6 +441,8 @@
             if e.code != simplemapi.MAPI_USER_ABORT:
                 raise errors.MailClientNotFound(['MAPI supported mail client'
                                                  ' (error %d)' % (e.code,)])
+mail_client_registry.register('mapi', MAPIClient,
+                              help=MAPIClient.__doc__)
 
 
 class DefaultMail(MailClient):
@@ -455,3 +475,6 @@
         except errors.MailClientNotFound:
             return Editor(self.config).compose_merge_request(to, subject,
                           directive, basename=basename)
+mail_client_registry.register('default', DefaultMail,
+                              help=DefaultMail.__doc__)
+mail_client_registry.default_key = 'default'




More information about the bazaar-commits mailing list