Rev 4130: (abentley) bzr send accepts --body in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Mar 12 09:57:41 GMT 2009


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

------------------------------------------------------------
revno: 4130
revision-id: pqm at pqm.ubuntu.com-20090312095736-fizxxpwp4gj9zqx9
parent: pqm at pqm.ubuntu.com-20090312091731-9trx3k1cehgpwhbm
parent: aaron at aaronbentley.com-20090312080837-e9t05lzj2b6yfr5a
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-03-12 09:57:36 +0000
message:
  (abentley) bzr send accepts --body
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
  bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
    ------------------------------------------------------------
    revno: 4098.5.13
    revision-id: aaron at aaronbentley.com-20090312080837-e9t05lzj2b6yfr5a
    parent: aaron at aaronbentley.com-20090312070332-6e33t7e939fkdhk2
    parent: pqm at pqm.ubuntu.com-20090312075222-g575i2pcrliafetw
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Thu 2009-03-12 18:08:37 +1000
    message:
      Merge bzr.dev into send-hookage.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/shelf_ui.py             shelver.py-20081005210102-33worgzwrtdw0yrm-1
      bzrlib/tests/blackbox/test_shelve.py test_ls_shelf.py-20081202053526-thlo8yt0pi1cgor1-1
      bzrlib/tests/test_shelf_ui.py  test_shelf_ui.py-20081027155203-wtcuazg85wp9u4fv-1
    ------------------------------------------------------------
    revno: 4098.5.12
    revision-id: aaron at aaronbentley.com-20090312070332-6e33t7e939fkdhk2
    parent: aaron at aaronbentley.com-20090312070249-3swo2cqsrpd74kri
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Thu 2009-03-12 17:03:32 +1000
    message:
      Update NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4098.5.11
    revision-id: aaron at aaronbentley.com-20090312070249-3swo2cqsrpd74kri
    parent: aaron at aaronbentley.com-20090312061421-zcyio4fy5cv7rqpj
    parent: pqm at pqm.ubuntu.com-20090312063229-ucuyuhmuc7ya8e54
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Thu 2009-03-12 17:02:49 +1000
    message:
      Merge bzr.dev into send-hookage
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzr                            bzr.py-20050313053754-5485f144c7006fa6
      bzrlib/__init__.py             __init__.py-20050309040759-33e65acf91bbcd5d
      bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
      bzrlib/shelf.py                prepare_shelf.py-20081005181341-n74qe6gu1e65ad4v-1
      bzrlib/tests/branch_implementations/test_sprout.py test_sprout.py-20070521151739-b8t8p7axw1h966ws-1
      bzrlib/tests/test_shelf.py     test_prepare_shelf.p-20081005181341-n74qe6gu1e65ad4v-2
      bzrlib/tests/tree_implementations/test_path_content_summary.py test_path_content_su-20070904100855-3vrwedz6akn34kl5-1
      bzrlib/tests/workingtree_implementations/test_parents.py test_set_parents.py-20060807231740-yicmnlci1mj8smu1-1
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
    ------------------------------------------------------------
    revno: 4098.5.10
    revision-id: aaron at aaronbentley.com-20090312061421-zcyio4fy5cv7rqpj
    parent: aaron at aaronbentley.com-20090312050041-jbs1oa1ts6pmpz0z
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Thu 2009-03-12 16:14:21 +1000
    message:
      Fix test case.
    modified:
      bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
    ------------------------------------------------------------
    revno: 4098.5.9
    revision-id: aaron at aaronbentley.com-20090312050041-jbs1oa1ts6pmpz0z
    parent: aaron at aaronbentley.com-20090312045915-c4ubvbitnnw1p4fz
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Thu 2009-03-12 15:00:41 +1000
    message:
      Update NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4098.5.8
    revision-id: aaron at aaronbentley.com-20090312045915-c4ubvbitnnw1p4fz
    parent: aaron at aaronbentley.com-20090312044357-43bqilmvojr8rcr1
    parent: pqm at pqm.ubuntu.com-20090312033910-9umj7rwjo98zl7up
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Thu 2009-03-12 14:59:15 +1000
    message:
      Merge bzr.dev into send-hookage.
    added:
      bzrlib/tests/per_repository_reference/test_default_stacking.py test_default_stackin-20090311055345-9ajahgm58oq3wh6h-1
      tools/check-newsbugs.py        checknewsbugs.py-20090128204947-lsdwd8nlswm1yrwv-1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/_dirstate_helpers_c.pyx dirstate_helpers.pyx-20070503201057-u425eni465q4idwn-3
      bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/hooks.py                hooks.py-20070325015548-ix4np2q0kd8452au-1
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/lock.py                 lock.py-20050527050856-ec090bb51bc03349
      bzrlib/lockable_files.py       control_files.py-20051111201905-bb88546e799d669f
      bzrlib/reconcile.py            reweave_inventory.py-20051108164726-1e5e0934febac06e
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/branch_implementations/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
      bzrlib/tests/interrepository_implementations/test_fetch.py test_fetch.py-20080425213627-j60cjh782ufm83ry-1
      bzrlib/tests/intertree_implementations/test_compare.py test_compare.py-20060724101752-09ysswo1a92uqyoz-2
      bzrlib/tests/per_repository/test_fileid_involved.py test_file_involved.py-20051215205901-728a172d1014daaa
      bzrlib/tests/per_repository_reference/__init__.py __init__.py-20080220025549-nnm2s80it1lvcwnc-2
      bzrlib/tests/test__dirstate_helpers.py test_dirstate_helper-20070504035751-jsbn00xodv0y1eve-2
      bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
      bzrlib/tests/test_fetch.py     testfetch.py-20050825090644-f73e07e7dfb1765a
      bzrlib/tests/test_hooks.py     test_hooks.py-20070628030849-89rtsbe5dmer5npz-1
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      bzrlib/tests/test_source.py    test_source.py-20051207061333-a58dea6abecc030d
      bzrlib/tests/test_urlutils.py  test_urlutils.py-20060502192900-46b1f9579987cf9c
      bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
      bzrlib/tests/test_workingtree_4.py test_workingtree_4.p-20070223025758-531n3tznl3zacv2o-1
      bzrlib/tests/workingtree_implementations/test_mkdir.py test_mkdir.py-20060907214856-4omn6hf1u7fvrart-3
      bzrlib/tests/workingtree_implementations/test_nested_specifics.py test_nested_specific-20070306004443-qut978c488jr11sg-1
      bzrlib/tests/workingtree_implementations/test_workingtree.py test_workingtree.py-20060203003124-817757d3e31444fb
      bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
      bzrlib/ui/text.py              text.py-20051130153916-2e438cffc8afc478
      bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
      bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
      bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
      doc/developers/releasing.txt   releasing.txt-20080502015919-fnrcav8fwy8ccibu-1
    ------------------------------------------------------------
    revno: 4098.5.7
    revision-id: aaron at aaronbentley.com-20090312044357-43bqilmvojr8rcr1
    parent: aaron at aaronbentley.com-20090311072912-p7kui5njo3av6e49
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Thu 2009-03-12 14:43:57 +1000
    message:
      Fix bundle-revisions after adjusting cmd_send._run
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
    ------------------------------------------------------------
    revno: 4098.5.6
    revision-id: aaron at aaronbentley.com-20090311072912-p7kui5njo3av6e49
    parent: aaron at aaronbentley.com-20090311072419-029z2ec0lxfc6ns1
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Wed 2009-03-11 17:29:12 +1000
    message:
      Add body=None to support old mail clients better.
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 4098.5.5
    revision-id: aaron at aaronbentley.com-20090311072419-029z2ec0lxfc6ns1
    parent: aaron at aaronbentley.com-20090311072253-fqkbpkjbttqajocc
    parent: pqm at pqm.ubuntu.com-20090311015637-v73ocbv9bcexe4dm
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Wed 2009-03-11 17:24:19 +1000
    message:
      Merge bzr.dev into send-hookage
    added:
      bzrlib/clean_tree.py           clean_tree.py-20050827022328-5ba46e22d074695c
      bzrlib/tests/blackbox/test_clean_tree.py test_clean_tree.py-20090219235516-em1ybc01twsqacx9-1
      bzrlib/tests/test_clean_tree.py test_clean_tree.py-20060603174249-ozlk5sl2166opxbk-1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/__init__.py             __init__.py-20050309040759-33e65acf91bbcd5d
      bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
      bzrlib/bugtracker.py           bugtracker.py-20070410073305-vu1vu1qosjurg8kb-1
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
      bzrlib/hooks.py                hooks.py-20070325015548-ix4np2q0kd8452au-1
      bzrlib/lsprof.py               lsprof.py-20051208071030-833790916798ceed
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
      bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
      bzrlib/tests/branch_implementations/__init__.py __init__.py-20060123013057-b12a52c3f361daf4
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
      bzrlib/tests/test_graph.py     test_graph_walker.py-20070525030405-enq4r60hhi9xrujc-1
      bzrlib/tests/test_hooks.py     test_hooks.py-20070628030849-89rtsbe5dmer5npz-1
      bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
      bzrlib/tests/test_trace.py     testtrace.py-20051110225523-a21117fc7a07eeff
      bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
      bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
      tools/doc_generate/autodoc_man.py bzrman.py-20050601153041-0ff7f74de456d15e
    ------------------------------------------------------------
    revno: 4098.5.4
    revision-id: aaron at aaronbentley.com-20090311072253-fqkbpkjbttqajocc
    parent: aaron at aaronbentley.com-20090310123821-g1ev3vb0y7mjiggh
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Wed 2009-03-11 17:22:53 +1000
    message:
      Cleaner support for mail clients lacking body support.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 4098.5.3
    revision-id: aaron at aaronbentley.com-20090310123821-g1ev3vb0y7mjiggh
    parent: aaron at aaronbentley.com-20090310123301-ijo1c962wimkujh0
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Tue 2009-03-10 22:38:21 +1000
    message:
      Add Windows MAPI support for send --body
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 4098.5.2
    revision-id: aaron at aaronbentley.com-20090310123301-ijo1c962wimkujh0
    parent: aaron at aaronbentley.com-20090310082334-u4dphlqn32w9zi0n
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Tue 2009-03-10 22:33:01 +1000
    message:
      Push body support through bzr send.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 4098.5.1
    revision-id: aaron at aaronbentley.com-20090310082334-u4dphlqn32w9zi0n
    parent: pqm at pqm.ubuntu.com-20090309084556-9i2m12qlud2qcrtw
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: send-hookage
    timestamp: Tue 2009-03-10 18:23:34 +1000
    message:
      Allow specifying body for t-bird, evo and xdg
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
=== modified file 'NEWS'
--- a/NEWS	2009-03-12 09:17:31 +0000
+++ b/NEWS	2009-03-12 09:57:36 +0000
@@ -19,6 +19,9 @@
     * shelve can now apply changes without storing anything on the shelf, via
       the new --destroy option.  (Aaron Bentley)
 
+    * ``bzr send`` now accepts --body to specify an initial message body.
+      (Aaron bentley)
+
   IMPROVEMENTS:
 
     * Progress bars now show the rate of network activity for

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-03-12 07:00:36 +0000
+++ b/bzrlib/builtins.py	2009-03-12 08:08:37 +0000
@@ -4743,6 +4743,7 @@
                type=unicode),
         'revision',
         'message',
+        Option('body', help='Body for the email.', type=unicode),
         RegistryOption.from_kwargs('format',
         'Use the specified output format.',
         **{'4': 'Bundle format 4, Merge Directive 2 (default)',
@@ -4751,13 +4752,13 @@
 
     def run(self, submit_branch=None, public_branch=None, no_bundle=False,
             no_patch=False, revision=None, remember=False, output=None,
-            format='4', mail_to=None, message=None, **kwargs):
+            format='4', mail_to=None, message=None, body=None, **kwargs):
         return self._run(submit_branch, revision, public_branch, remember,
                          format, no_bundle, no_patch, output,
-                         kwargs.get('from', '.'), mail_to, message)
+                         kwargs.get('from', '.'), mail_to, message, body)
 
     def _run(self, submit_branch, revision, public_branch, remember, format,
-             no_bundle, no_patch, output, from_, mail_to, message):
+             no_bundle, no_patch, output, from_, mail_to, message, body):
         from bzrlib.revision import NULL_REVISION
         branch = Branch.open_containing(from_)[0]
         if output is None:
@@ -4775,6 +4776,11 @@
                 if mail_to is None:
                     mail_to = config.get_user_option('submit_to')
                 mail_client = config.get_mail_client()
+                if (not getattr(mail_client, 'supports_body', False)
+                    and body is not None):
+                    raise errors.BzrCommandError(
+                        'Mail client "%s" does not support specifying body' %
+                        mail_client.__class__.__name__)
             if remember and submit_branch is None:
                 raise errors.BzrCommandError(
                     '--remember requires a branch to be specified.')
@@ -4857,7 +4863,8 @@
                     subject += revision.get_summary()
                 basename = directive.get_disk_name(branch)
                 mail_client.compose_merge_request(mail_to, subject,
-                                                  outfile.getvalue(), basename)
+                                                  outfile.getvalue(),
+                                                  basename, body)
         finally:
             if output != '-':
                 outfile.close()
@@ -4931,7 +4938,7 @@
             output = '-'
         return self._run(submit_branch, revision, public_branch, remember,
                          format, no_bundle, no_patch, output,
-                         kwargs.get('from', '.'), None, None)
+                         kwargs.get('from', '.'), None, None, None)
 
 
 class cmd_tag(Command):

=== modified file 'bzrlib/mail_client.py'
--- a/bzrlib/mail_client.py	2009-02-26 08:44:15 +0000
+++ b/bzrlib/mail_client.py	2009-03-11 07:29:12 +0000
@@ -41,7 +41,7 @@
         self.config = config
 
     def compose(self, prompt, to, subject, attachment, mime_subtype,
-                extension, basename=None):
+                extension, basename=None, body=None):
         """Compose (and possibly send) an email message
 
         Must be implemented by subclasses.
@@ -61,7 +61,8 @@
         """
         raise NotImplementedError
 
-    def compose_merge_request(self, to, subject, directive, basename=None):
+    def compose_merge_request(self, to, subject, directive, basename=None,
+                              body=None):
         """Compose (and possibly send) a merge request
 
         :param to: The address to send the request to
@@ -74,7 +75,7 @@
         prompt = self._get_merge_prompt("Please describe these changes:", to,
                                         subject, directive)
         self.compose(prompt, to, subject, directive,
-            'x-patch', '.patch', basename)
+            'x-patch', '.patch', basename, body)
 
     def _get_merge_prompt(self, prompt, to, subject, attachment):
         """Generate a prompt string.  Overridden by Editor.
@@ -90,6 +91,8 @@
 class Editor(MailClient):
     """DIY mail client that uses commit message editor"""
 
+    supports_body = True
+
     def _get_merge_prompt(self, prompt, to, subject, attachment):
         """See MailClient._get_merge_prompt"""
         return (u"%s\n\n"
@@ -99,11 +102,11 @@
                          attachment.decode('utf-8', 'replace')))
 
     def compose(self, prompt, to, subject, attachment, mime_subtype,
-                extension, basename=None):
+                extension, basename=None, body=None):
         """See MailClient.compose"""
         if not to:
             raise errors.NoMailAddressSpecified()
-        body = msgeditor.edit_commit_message(prompt)
+        body = msgeditor.edit_commit_message(prompt, start_message=body)
         if body == '':
             raise errors.NoMessageSupplied()
         email_message.EmailMessage.send(self.config,
@@ -117,8 +120,9 @@
                               help=Editor.__doc__)
 
 
-class ExternalMailClient(MailClient):
-    """An external mail client."""
+class BodyExternalMailClient(MailClient):
+
+    supports_body = True
 
     def _get_client_commands(self):
         """Provide a list of commands that may invoke the mail client"""
@@ -129,7 +133,7 @@
             return self._client_commands
 
     def compose(self, prompt, to, subject, attachment, mime_subtype,
-                extension, basename=None):
+                extension, basename=None, body=None):
         """See MailClient.compose.
 
         Writes the attachment to a temporary file, invokes _compose.
@@ -143,11 +147,15 @@
             outfile.write(attachment)
         finally:
             outfile.close()
+        if body is not None:
+            kwargs = {'body': body}
+        else:
+            kwargs = {}
         self._compose(prompt, to, subject, attach_path, mime_subtype,
-                      extension)
+                      extension, **kwargs)
 
     def _compose(self, prompt, to, subject, attach_path, mime_subtype,
-                extension):
+                extension, body=None):
         """Invoke a mail client as a commandline process.
 
         Overridden by MAPIClient.
@@ -161,8 +169,13 @@
         """
         for name in self._get_client_commands():
             cmdline = [self._encode_path(name, 'executable')]
+            if body is not None:
+                kwargs = {'body': body}
+            else:
+                kwargs = {}
             cmdline.extend(self._get_compose_commandline(to, subject,
-                                                         attach_path))
+                                                         attach_path,
+                                                         **kwargs))
             try:
                 subprocess.call(cmdline)
             except OSError, e:
@@ -173,7 +186,7 @@
         else:
             raise errors.MailClientNotFound(self._client_commands)
 
-    def _get_compose_commandline(self, to, subject, attach_path):
+    def _get_compose_commandline(self, to, subject, attach_path, body):
         """Determine the commandline to use for composing a message
 
         Implemented by various subclasses
@@ -212,18 +225,26 @@
         return path
 
 
-class Evolution(ExternalMailClient):
+class ExternalMailClient(BodyExternalMailClient):
+    """An external mail client."""
+
+    supports_body = False
+
+
+class Evolution(BodyExternalMailClient):
     """Evolution mail client."""
 
     _client_commands = ['evolution']
 
-    def _get_compose_commandline(self, to, subject, attach_path):
+    def _get_compose_commandline(self, to, subject, attach_path, body=None):
         """See ExternalMailClient._get_compose_commandline"""
         message_options = {}
         if subject is not None:
             message_options['subject'] = subject
         if attach_path is not None:
             message_options['attach'] = attach_path
+        if body is not None:
+            message_options['body'] = body
         options_list = ['%s=%s' % (k, urlutils.escape(v)) for (k, v) in
                         sorted(message_options.iteritems())]
         return ['mailto:%s?%s' % (self._encode_safe(to or ''),
@@ -252,7 +273,7 @@
                               help=Mutt.__doc__)
 
 
-class Thunderbird(ExternalMailClient):
+class Thunderbird(BodyExternalMailClient):
     """Mozilla Thunderbird (or Icedove)
 
     Note that Thunderbird 1.5 is buggy and does not support setting
@@ -266,7 +287,7 @@
         '/Applications/Mozilla/Thunderbird.app/Contents/MacOS/thunderbird-bin',
         '/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin']
 
-    def _get_compose_commandline(self, to, subject, attach_path):
+    def _get_compose_commandline(self, to, subject, attach_path, body=None):
         """See ExternalMailClient._get_compose_commandline"""
         message_options = {}
         if to is not None:
@@ -276,8 +297,12 @@
         if attach_path is not None:
             message_options['attachment'] = urlutils.local_path_to_url(
                 attach_path)
-        options_list = ["%s='%s'" % (k, v) for k, v in
-                        sorted(message_options.iteritems())]
+        if body is not None:
+            options_list = ['body=%s' % urllib.quote(self._encode_safe(body))]
+        else:
+            options_list = []
+        options_list.extend(["%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__)
@@ -329,12 +354,12 @@
                               help=Claws.__doc__)
 
 
-class XDGEmail(ExternalMailClient):
+class XDGEmail(BodyExternalMailClient):
     """xdg-email attempts to invoke the user's preferred mail client"""
 
     _client_commands = ['xdg-email']
 
-    def _get_compose_commandline(self, to, subject, attach_path):
+    def _get_compose_commandline(self, to, subject, attach_path, body=None):
         """See ExternalMailClient._get_compose_commandline"""
         if not to:
             raise errors.NoMailAddressSpecified()
@@ -344,6 +369,8 @@
         if attach_path is not None:
             commandline.extend(['--attach',
                 self._encode_path(attach_path, 'attachment')])
+        if body is not None:
+            commandline.extend(['--body', self._encode_safe(body)])
         return commandline
 mail_client_registry.register('xdg-email', XDGEmail,
                               help=XDGEmail.__doc__)
@@ -454,18 +481,19 @@
                               help=EmacsMail.__doc__)
 
 
-class MAPIClient(ExternalMailClient):
+class MAPIClient(BodyExternalMailClient):
     """Default Windows mail client launched using MAPI."""
 
     def _compose(self, prompt, to, subject, attach_path, mime_subtype,
-                 extension):
+                 extension, body):
         """See ExternalMailClient._compose.
 
         This implementation uses MAPI via the simplemapi ctypes wrapper
         """
         from bzrlib.util import simplemapi
         try:
-            simplemapi.SendMail(to or '', subject or '', '', attach_path)
+            simplemapi.SendMail(to or '', subject or '', body or '',
+                                attach_path)
         except simplemapi.MAPIError, e:
             if e.code != simplemapi.MAPI_USER_ABORT:
                 raise errors.MailClientNotFound(['MAPI supported mail client'
@@ -486,24 +514,25 @@
             return XDGEmail(self.config)
 
     def compose(self, prompt, to, subject, attachment, mime_subtype,
-                extension, basename=None):
+                extension, basename=None, body=None):
         """See MailClient.compose"""
         try:
             return self._mail_client().compose(prompt, to, subject,
                                                attachment, mimie_subtype,
-                                               extension, basename)
+                                               extension, basename, body)
         except errors.MailClientNotFound:
             return Editor(self.config).compose(prompt, to, subject,
-                          attachment, mimie_subtype, extension)
+                          attachment, mimie_subtype, extension, body)
 
-    def compose_merge_request(self, to, subject, directive, basename=None):
+    def compose_merge_request(self, to, subject, directive, basename=None,
+                              body=None):
         """See MailClient.compose_merge_request"""
         try:
             return self._mail_client().compose_merge_request(to, subject,
-                    directive, basename=basename)
+                    directive, basename=basename, body=body)
         except errors.MailClientNotFound:
             return Editor(self.config).compose_merge_request(to, subject,
-                          directive, basename=basename)
+                          directive, basename=basename, body=body)
 mail_client_registry.register('default', DefaultMail,
                               help=DefaultMail.__doc__)
 mail_client_registry.default_key = 'default'

=== modified file 'bzrlib/tests/test_mail_client.py'
--- a/bzrlib/tests/test_mail_client.py	2009-01-08 14:22:30 +0000
+++ b/bzrlib/tests/test_mail_client.py	2009-03-12 06:14:21 +0000
@@ -56,9 +56,12 @@
         self.assertEqual(['-compose', "attachment='%s'" %
                           urlutils.local_path_to_url('file%')], commandline)
         commandline = tbird._get_compose_commandline('jrandom at example.org',
-                                                     'Hi there!', None)
-        self.assertEqual(['-compose', "subject='Hi there!',"
-                                      "to='jrandom at example.org'"], commandline)
+                                                     'Hi there!', None,
+                                                     "bo'dy")
+        self.assertEqual(['-compose', "body=bo%27dy,"
+                                      "subject='Hi there!',"
+                                      "to='jrandom at example.org'"],
+                                      commandline)
 
     def test_commandline_is_8bit(self):
         # test for bug #139318
@@ -119,9 +122,9 @@
         self.assertEqual(['jrandom at example.org', '--attach', 'file%'],
                          commandline)
         commandline = xdg_email._get_compose_commandline(
-            'jrandom at example.org', 'Hi there!', None)
-        self.assertEqual(['jrandom at example.org', '--subject', 'Hi there!'],
-                         commandline)
+            'jrandom at example.org', 'Hi there!', None, "bo'dy")
+        self.assertEqual(['jrandom at example.org', '--subject', 'Hi there!',
+                          '--body', "bo'dy"], commandline)
 
     def test_commandline_is_8bit(self):
         xdg_email = mail_client.XDGEmail(None)
@@ -143,9 +146,9 @@
         commandline = evo._get_compose_commandline(None, None, 'file%')
         self.assertEqual(['mailto:?attach=file%25'], commandline)
         commandline = evo._get_compose_commandline('jrandom at example.org',
-                                                   'Hi there!', None)
-        self.assertEqual(['mailto:jrandom at example.org?subject=Hi%20there%21'],
-                         commandline)
+                                                   'Hi there!', None, 'bo&dy')
+        self.assertEqual(['mailto:jrandom at example.org?body=bo%26dy&'
+                          'subject=Hi%20there%21'], commandline)
 
     def test_commandline_is_8bit(self):
         evo = mail_client.Evolution(None)
@@ -257,4 +260,5 @@
                                      basename=basename)
         dummy_client = client.client
         self.assertEqual(dummy_client.args, (to, subject, directive))
-        self.assertEqual(dummy_client.kwargs, {"basename":basename})
+        self.assertEqual(dummy_client.kwargs,
+                         {"basename": basename, 'body': None})




More information about the bazaar-commits mailing list