Rev 4417: (mbp) allow passing body as attachment to mutt in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jun 9 04:27:22 BST 2009


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

------------------------------------------------------------
revno: 4417
revision-id: pqm at pqm.ubuntu.com-20090609032718-j717ilvc5elzr91r
parent: pqm at pqm.ubuntu.com-20090606005240-2qms4n1eqdshzp0w
parent: mbp at sourcefrog.net-20090608233854-t4tlfebl0ivo5bzt
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-06-09 04:27:18 +0100
message:
  (mbp) allow passing body as attachment to mutt
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
  bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
    ------------------------------------------------------------
    revno: 4416.2.2
    revision-id: mbp at sourcefrog.net-20090608233854-t4tlfebl0ivo5bzt
    parent: mbp at sourcefrog.net-20090608233803-le5upk6jts7lrl6y
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: integration
    timestamp: Tue 2009-06-09 09:38:54 +1000
    message:
      News for fix of 384158
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4416.2.1
    revision-id: mbp at sourcefrog.net-20090608233803-le5upk6jts7lrl6y
    parent: pqm at pqm.ubuntu.com-20090606005240-2qms4n1eqdshzp0w
    parent: edwin.grubbs at canonical.com-20090608174519-e37dqzq2wv6kz436
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: integration
    timestamp: Tue 2009-06-09 09:38:03 +1000
    message:
      Fix from Edwin for attachments in mutt
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
    ------------------------------------------------------------
    revno: 4416.1.3
    revision-id: edwin.grubbs at canonical.com-20090608174519-e37dqzq2wv6kz436
    parent: edwin.grubbs at canonical.com-20090607011713-peahmxl805e5yxwm
    committer: Edwin Grubbs <edwin.grubbs at canonical.com>
    branch nick: bug-384158-passing-body-to-mutt
    timestamp: Mon 2009-06-08 12:45:19 -0500
    message:
      Stored temp file in self to allow using NamedTemporaryFile.
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 4416.1.2
    revision-id: edwin.grubbs at canonical.com-20090607011713-peahmxl805e5yxwm
    parent: edwin.grubbs at canonical.com-20090606032519-yvfaen4wy7m1o3qu
    committer: Edwin Grubbs <edwin.grubbs at canonical.com>
    branch nick: bug-384158-passing-body-to-mutt
    timestamp: Sat 2009-06-06 20:17:13 -0500
    message:
      Added comment.
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
    ------------------------------------------------------------
    revno: 4416.1.1
    revision-id: edwin.grubbs at canonical.com-20090606032519-yvfaen4wy7m1o3qu
    parent: pqm at pqm.ubuntu.com-20090606005240-2qms4n1eqdshzp0w
    committer: Edwin Grubbs <edwin.grubbs at canonical.com>
    branch nick: bug-384158-passing-body-to-mutt
    timestamp: Fri 2009-06-05 22:25:19 -0500
    message:
      Added ability to pass the body into mutt.
    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-06-05 23:21:51 +0000
+++ b/NEWS	2009-06-08 23:38:54 +0000
@@ -63,6 +63,9 @@
 Bug Fixes
 *********
 
+* Bazaar can now pass attachment files to the mutt email client.
+  (Edwin Grubbs, #384158)
+
 * Better message in ``bzr add`` output suggesting using ``bzr ignored`` to
   see which files can also be added.  (Jason Spashett, #76616)
 

=== modified file 'bzrlib/mail_client.py'
--- a/bzrlib/mail_client.py	2009-06-04 21:05:44 +0000
+++ b/bzrlib/mail_client.py	2009-06-08 17:45:19 +0000
@@ -257,12 +257,12 @@
                               help=Evolution.__doc__)
 
 
-class Mutt(ExternalMailClient):
+class Mutt(BodyExternalMailClient):
     """Mutt mail client."""
 
     _client_commands = ['mutt']
 
-    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:
@@ -270,6 +270,14 @@
         if attach_path is not None:
             message_options.extend(['-a',
                 self._encode_path(attach_path, 'attachment')])
+        if body is not None:
+            # Store the temp file object in self, so that it does not get
+            # garbage collected and delete the file before mutt can read it.
+            self._temp_file = tempfile.NamedTemporaryFile(
+                prefix="mutt-body-", suffix=".txt")
+            self._temp_file.write(body)
+            self._temp_file.flush()
+            message_options.extend(['-i', self._temp_file.name])
         if to is not None:
             message_options.extend(['--', self._encode_safe(to)])
         return message_options

=== modified file 'bzrlib/tests/test_mail_client.py'
--- a/bzrlib/tests/test_mail_client.py	2009-06-04 19:56:42 +0000
+++ b/bzrlib/tests/test_mail_client.py	2009-06-06 03:25:19 +0000
@@ -28,8 +28,10 @@
 
     def test_commandline(self):
         mutt = mail_client.Mutt(None)
-        commandline = mutt._get_compose_commandline(None, None, 'file%')
-        self.assertEqual(['-a', 'file%'], commandline)
+        commandline = mutt._get_compose_commandline(
+            None, None, 'file%', body="hello")
+        # The temporary filename is randomly generated, so it is not matched.
+        self.assertEqual(['-a', 'file%', '-i'], commandline[:-1])
         commandline = mutt._get_compose_commandline('jrandom at example.org',
                                                      'Hi there!', None)
         self.assertEqual(['-s', 'Hi there!', '--', 'jrandom at example.org'],




More information about the bazaar-commits mailing list