[MERGE] Support GNU Emacs set of MUAs as mail_client option.

Aaron Bentley aaron at aaronbentley.com
Mon Mar 31 14:44:52 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Xavier Maillard wrote:
> Here is my new atttempt in adding GNU Emacs MUAs as an
> additionnal mail_client client.
> 
> Improvements since last submit are:
> 
> 1. we now use compose-mail instead of calling specific mail
> composition function. This way, every MUAs known by emacs will
> work. A user just needs to set ``mail-user-agent`` variable
> according to his taste.

Thanks.  This getting there.

bb:resubmit

Please merge from mainline before re-submitting; merging into bzr.dev
produced conflicts.

Also, please follow our 79-character line limit.

> This implementation has several cons though:
> 
> - we generate the function every time we call bzr send
> - we never delete the temporary file in order to let bzr send
>   load the file

That seems okay, though it's a shame it can't be done as a commandline
parameter.

> === modified file 'bzrlib/mail_client.py'
> --- bzrlib/mail_client.py	2008-03-16 14:41:10 +0000
> +++ bzrlib/mail_client.py	2008-03-29 19:01:44 +0000
> @@ -306,6 +306,94 @@
>          return commandline
>  
>  
> +class EmacsMail (ExternalMailClient):
> +    """Call emacsclient to have a mail buffer. This only work for emacs >= 22.1
> +
> +    The good news is that this implementation will work with all mail
> +    agent registered agains ``mail-user-agent``. So there is no need

                   ^^^ "against"

> +    to instantiate ExternalMailClient for each and every GNU Emacs
> +    MUA.
> +
> +    The user just has to ensure that ``mail-user-agent`` is set according to his tastes.
> +    """

^^^ We generally avoid using the male pronoun in cases where the female
would also be possible.  "their" or "his or her" would be fine.


> +    _client_commands = ['emacsclient']
> +    _defun = None
> +
> +    def __init__ (self, config):
> +        """ """
> +        self._defun = """(defun bzr-add-mime-att (file)
> +  \"Attach FILe to a mail buffer as a MIME attachment.\"
> +  (let ((agent mail-user-agent))
> +    (mail-text)
> +    (newline)
> +
> +    (if (and file
> +	     (file-exists-p file))
> +	(cond
> +	 ((eq agent \'sendmail-user-agent)
> +	  (etach-attach file))
> +	 ((or (eq agent \'message-user-agent)
> +	      (eq agent \'gnus-user-agent))
> +	  (mml-attach-file file \"text/x-patch\" \"BZR merge\" \"attachement\"))
> +	 (t
> +	  (message \"Unhandled MUA\")))
> +      (error \"File does not exist.\"))))
> +"""

Class variables should never be overridden with instance variables in
constructors.  Since this text will never very, it should be assigned as
a class variable.

> +        fd,temp_file = tempfile.mkstemp(prefix="emacs-bzr-send-", suffix=".el")

^^^ There should be spaces after commas.

> +
> +        try:
> +            os.write(fd,self._defun)

^^^ spaces after commas

> +        finally:
> +            os.close(fd) # Just close the handle but do not remove the file.
> +            return temp_file

^^^ The return isn't really part of the finally section.

> +
> +    def _get_compose_commandline (self, to, subject, attach_path):
> +        commandline = ["--eval"]
> +
> +        _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))
> +
> +        # Funcall the default mail composition function
> +        # This will work with any mail mode including default mail-mode
> +        # User must tweak mail-user-agent variable to tell what function
> +        # will be called inside compose-mail.
> +        mail_cmd = "(compose-mail %s %s)" % (_to,_subject)

^^^ comma again

> === modified file 'bzrlib/tests/test_mail_client.py'
> --- bzrlib/tests/test_mail_client.py	2008-03-19 20:13:06 +0000
> +++ bzrlib/tests/test_mail_client.py	2008-03-29 19:01:44 +0000
> @@ -71,6 +71,35 @@
>                  'Command-line item %r is unicode!' % item)
>  
>  
> +class TestEmacsMail(tests.TestCase):
> +
> +    def test_commandline(self):
> +        eclient = mail_client.EmacsMail(None)
> +
> +        commandline = eclient._get_compose_commandline(None,
> +                                                     'Hi there!', None)

^^^ Indent looks wrong.  Should be under None or indented 4 spaces vs
"commandline ="

> +        self.assertEqual(['--eval', '(compose-mail nil "Hi there!")'], commandline)
> +
> +        commandline = eclient._get_compose_commandline('jrandom at example.org',
> +                                                     'Hi there!', None)

^^^ Indent again.

> +        self.assertEqual(['--eval', '(compose-mail "jrandom at example.org" "Hi there!")'], commandline)
> +
> +        # FIXME: this won't work and we can't know by advance what
> +        # will be the temporary file we need to load in order to
> +        # attach a MIME file.

When you don't know the exact path, you can do assertContainsRe instead.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFH8OrU0F+nu1YWqI0RApEOAJ9z4GU82A3NuD8FTyCD3f1hars2NgCfTnZT
16FaYfETaSihaVZQi0NlF9c=
=5AYm
-----END PGP SIGNATURE-----



More information about the bazaar mailing list