Rev 3323: Add mail-mode GNU Emacs mail package as a mail client option (Xavier in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Apr 1 06:59:54 BST 2008


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

------------------------------------------------------------
revno: 3323
revision-id:pqm at pqm.ubuntu.com-20080401055945-3pmuiy0q0301axv6
parent: pqm at pqm.ubuntu.com-20080401035104-fnjlf47gtles4byl
parent: ian.clatworthy at canonical.com-20080401041906-s7ekpfpo0tnyfkbz
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2008-04-01 06:59:45 +0100
message:
  Add mail-mode GNU Emacs mail package as a mail client option (Xavier
  	Maillard)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
  bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
    ------------------------------------------------------------
    revno: 3322.1.1
    revision-id:ian.clatworthy at canonical.com-20080401041906-s7ekpfpo0tnyfkbz
    parent: pqm at pqm.ubuntu.com-20080401035104-fnjlf47gtles4byl
    parent: xma at gnu.org-20080326062148-f7mnwvttv4oq8013
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: ianc-integration
    timestamp: Tue 2008-04-01 14:19:06 +1000
    message:
      Add mail-mode GNU Emacs mail package as a mail client option (Xavier Maillard)
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
    ------------------------------------------------------------
    revno: 3302.6.1
    revision-id:xma at gnu.org-20080326062148-f7mnwvttv4oq8013
    parent: pqm at pqm.ubuntu.com-20080323231145-nh7pyfd19alqp471
    committer: Xavier Maillard <xma at gnu.org>
    branch nick: xma-mailmode
    timestamp: Wed 2008-03-26 07:21:48 +0100
    message:
      Add mail-mode GNU Emacs mail package as a mail_client option.
          
      Idea and original code by Bojan Nikolic modified in this way:
          
      1. define a different python class EmacsMailMode
      2. use mail-mode package instead of message-mode. mail-mode is the
         default mail mode in GNU Emacs.
      3. put the patch as a MIME attachment (see NOTE)
      4. add tests as required to fulfil merge strategy requirements
          
      To use this option, just put these lines into ~/.bazaar/bazaar.conf
          
      [DEFAULT]
      mail_client = emacs-mailmode
      
      NOTE: this will work only for GNU Emacs version from 22.1 and superior.
            The MIME attachment is handled by etach[1] package. Just put
            etach.el into your `load-path'. GNU Emacs is not shipped with a
            simple MIME package thus the need of a simple and reliable
            alternative (etach does both reading and writing of MIME objects).
      
      [1] http://rulnick.com/etach/download
    modified:
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      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	2008-04-01 03:51:04 +0000
+++ b/NEWS	2008-04-01 04:19:06 +0000
@@ -24,6 +24,9 @@
 
   FEATURES:
 
+    * Added mail-mode GNU Emacs mail package as a mail_client.
+      (Xavier Maillard, Bojan Nikolic)
+
   IMPROVEMENTS:
 
     * Diff is now more specific about execute-bit changes it describes

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2007-12-02 18:59:28 +0000
+++ b/bzrlib/config.py	2008-03-26 06:21:48 +0000
@@ -159,6 +159,7 @@
                 'default': mail_client.DefaultMail,
                 'editor': mail_client.Editor,
                 'mapi': mail_client.MAPIClient,
+                'emacs-mailmode': mail_client.EmacsMailMode,
                 'xdg-email': mail_client.XDGEmail,
             }[selected_client]
         except KeyError:

=== modified file 'bzrlib/mail_client.py'
--- a/bzrlib/mail_client.py	2008-03-16 14:41:10 +0000
+++ b/bzrlib/mail_client.py	2008-04-01 04:19:06 +0000
@@ -306,6 +306,39 @@
         return commandline
 
 
+class EmacsMailMode(ExternalMailClient):
+    """Call emacsclient in mail-mode.
+    
+    This only work for emacs >= 22.1.
+    """
+    _client_commands = ['emacsclient']
+
+    def _get_compose_commandline(self, to, subject, attach_path):
+        commandline = ["--eval"]
+        # Ensure we can at least have an empty mail-mode buffer
+        _to = "nil"
+        _subject = "nil"
+
+        if to is not None:
+            _to = ("\"%s\"" % self._encode_safe(to))
+        if subject is not None:
+            _subject = ("\"%s\"" % self._encode_safe(subject))
+        mmform = "(mail nil %s %s)" % (_to ,_subject)
+
+        # call mail-mode, move the point to body and insert a new blank line
+        # we *must* force this point movement for the case when To is not passed
+        # with --mail-to. Without this, the patch could be inserted at the wrong place
+        commandline.append(mmform)
+        commandline.append("(mail-text)")
+        commandline.append("(newline)")
+
+        # ... and put a MIME attachment (if any)
+        if attach_path is not None:
+            ifform = "(attach \"%s\")" % self._encode_path(attach_path,'attachment')
+            commandline.append(ifform)
+        return commandline
+
+
 class MAPIClient(ExternalMailClient):
     """Default Windows mail client launched using MAPI."""
 

=== modified file 'bzrlib/tests/test_mail_client.py'
--- a/bzrlib/tests/test_mail_client.py	2008-03-19 20:13:06 +0000
+++ b/bzrlib/tests/test_mail_client.py	2008-04-01 04:19:06 +0000
@@ -71,6 +71,32 @@
                 'Command-line item %r is unicode!' % item)
 
 
+class TestEmacsMailMode(tests.TestCase):
+
+    def test_commandline(self):
+        eclient = mail_client.EmacsMailMode(None)
+        commandline = eclient._get_compose_commandline(None, None, 'file%')
+        self.assertEqual(['--eval', '(mail nil nil nil)',
+                          '(mail-text)', '(newline)',
+                          '(attach "file%")'], commandline)
+
+        commandline = eclient._get_compose_commandline('jrandom at example.org',
+                                                     'Hi there!', None)
+        self.assertEqual(['--eval', '(mail nil "jrandom at example.org" "Hi there!")',
+                          '(mail-text)', '(newline)'], commandline)
+
+    def test_commandline_is_8bit(self):
+        eclient = mail_client.EmacsMailMode(None)
+        commandline = eclient._get_compose_commandline(u'jrandom at example.org',
+            u'Hi there!', u'file%')
+        self.assertEqual(['--eval', '(mail nil "jrandom at example.org" "Hi there!")',
+                          '(mail-text)', '(newline)',
+                          '(attach "file%")'], commandline)
+        for item in commandline:
+            self.assertFalse(isinstance(item, unicode),
+                'Command-line item %r is unicode!' % item)
+
+
 class TestXDGEmail(tests.TestCase):
 
     def test_commandline(self):




More information about the bazaar-commits mailing list