all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] Make `smtpmail-try-auth-method' a generic function.
Date: Thu, 11 Jan 2018 09:09:29 -0500	[thread overview]
Message-ID: <jwvd12g7aj0.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: 87373c3olr.fsf@gmail.com

I can install that, but I'm not sure if it should go into
emacs-26 or master.


        Stefan


Cesar Crusius <cesar.crusius@gmail.com> writes:

> This allows for extra authentication mechanisms (such as XOAuth2) to
> be added without having to advise any functions.
>
> * lisp/mail/smtpmail.el: Turn `smtpmail-try-auth-method' into a
> generic function.
> ---
>  lisp/mail/smtpmail.el | 33 +++++++++++++++++++++++++++++++--
>  1 file changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
> index 20cbeb5f4e..46c1639832 100644
> --- a/lisp/mail/smtpmail.el
> +++ b/lisp/mail/smtpmail.el
> @@ -181,7 +181,25 @@ This is relative to `smtpmail-queue-dir'."
>  
>  (defconst smtpmail-auth-supported '(cram-md5 plain login)
>    "List of supported SMTP AUTH mechanisms.
> -The list is in preference order.")
> +The list is in preference order.
> +
> +New mechanisms can be added by defining a method implementing the
> +`smtpmail-try-auth-method' generic function for that mechanism, and
> +then adding the mechanism to this list.  As an example, the code below
> +adds support for XOAuth2 authentication (assuming that there is an
> +appropriate auth source extension that can provide the correct user
> +and password):
> +
> +\(cl-defmethod smtpmail-try-auth-method
> +    (process (mech (eql xoauth2)) user password)
> +  (smtpmail-command-or-throw
> +   process
> +   (concat \"AUTH XOAUTH2 \"
> +           (base64-encode-string
> +            (concat \"user=\" user \"\\1auth=Bearer \" password \"\\1\\1\") t))
> +   235))
> +
> +\(add-to-list 'smtpmail-try-auth-method 'xoauth2)")
>  
>  (defvar smtpmail-mail-address nil
>    "Value to use for envelope-from address for mail from ambient buffer.")
> @@ -539,7 +557,18 @@ The list is in preference order.")
>  	  (funcall save-function))
>  	result))))
>  
> -(defun smtpmail-try-auth-method (process mech user password)
> +(cl-defgeneric smtpmail-try-auth-method (process mech user password)
> +  "Try to authenticate to an SMTP process.
> +Authenticate to PROCESS using the MECH authentication mechanism, with
> +the given USER and PASSWORD. Implementations should either return the
> +result code from the authentication command, or throw 'done with an
> +error string. (This is usually done by calling
> +`smtpmail-command-or-throw' as the last step in the function.)")
> +
> +(cl-defmethod smtpmail-try-auth-method (process mech user password)
> +  "Default `smtpmail-try-auth-method' implementation.
> +This implementation provides support for the SMTP authentication
> +mechanisms 'cram-md5, 'login, and 'plain."
>    (let (ret)
>      (cond
>       ((or (not mech)
> -- 
> 2.15.0




  reply	other threads:[~2018-01-11 14:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-11  6:18 [PATCH] Make `smtpmail-try-auth-method' a generic function Cesar Crusius
2018-01-11 14:09 ` Stefan Monnier [this message]
2018-01-11 14:54   ` Cesar Crusius
2018-01-11 16:11   ` Eli Zaretskii
2018-01-11 16:57     ` Stefan Monnier
2018-01-11 14:42 ` Robert Pluim
2018-01-11 17:00   ` Cesar Crusius
2018-01-11 19:33     ` Stefan Monnier
2018-01-11 21:36       ` Cesar Crusius

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvd12g7aj0.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.