From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Cesar Crusius Newsgroups: gmane.emacs.devel Subject: [PATCH] Make `smtpmail-try-auth-method' a generic function. Date: Wed, 10 Jan 2018 22:18:24 -0800 Message-ID: <87373c3olr.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1515651419 31867 195.159.176.226 (11 Jan 2018 06:16:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 11 Jan 2018 06:16:59 +0000 (UTC) User-Agent: mu4e 0.9.18; emacs 25.3.1 To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 11 07:16:55 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZWAT-0007eo-TF for ged-emacs-devel@m.gmane.org; Thu, 11 Jan 2018 07:16:50 +0100 Original-Received: from localhost ([::1]:45172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZWCT-00055z-9L for ged-emacs-devel@m.gmane.org; Thu, 11 Jan 2018 01:18:53 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39318) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZWCI-00055E-HR for emacs-devel@gnu.org; Thu, 11 Jan 2018 01:18:44 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZWCC-0008EJ-VD for emacs-devel@gnu.org; Thu, 11 Jan 2018 01:18:42 -0500 Original-Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]:39981) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZWCC-0008DK-PJ for emacs-devel@gnu.org; Thu, 11 Jan 2018 01:18:36 -0500 Original-Received: by mail-it0-x241.google.com with SMTP id f190so2271105ita.5 for ; Wed, 10 Jan 2018 22:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:date:message-id:mime-version; bh=qqyYhCWHzGrQQvsAzobbA2Dau2c9Qb/xu0G9OPjp9Cw=; b=BYyLh/FjlHH9feUtM2KzTogejSTbVcDCxWQFVsPiX1ZV2WStd7NJ1MNRkOfxCQSqLB XcOVWjnnt6ZAnN8eyIAwYxWHxokawS/hGecQwEt4h1bukLHAypdIMK8wAipiRgXo/3uq bZFESdfI3UIch4ZkNaJdRXyCiF/Mx4BDV1kSwB2Pir0ovCaBba2vtSKF/fSAaD/i2Pl8 d0GcRPML/DG4+SofJi3WE7Xc735zGwvD3I4r3PhsKspGJuJgnLzMbgwhtcCcotHv2a1T Qoy6xrj7pkaBsPcg0vHVt2N3WvYXp619z55ZGHaVkPVqHBR9Dqo0W34vL0IlVpyBk65b AsWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:date:message-id :mime-version; bh=qqyYhCWHzGrQQvsAzobbA2Dau2c9Qb/xu0G9OPjp9Cw=; b=WUEmu5Er/9xMtPHDMwF5BEa1rwNyVYuu5OOfCKRzbLUzeZS1O9ETHaycwTd7Wao1Ni 3F3Fjn/aHkq6FpD9EbeWqvoYfL2ukbqWjahvW5WnIOP4BLdCK/o0w8169leyawOfkp8B katewzIIn2vnLw/fQseOkt/I1uVzxobyZ8MdzILvWrdHN+7Wo8tKsce+etwZXXKLNL6s hpLRR89BKXX6chK0L6j+1Ci8Hs6U9xal03LjGpZtGD1Sidu9F5mX6YXOHuBC8/Orvhq2 I7nttu3VSvOd2eUM71PNIc54bIaa3lDtDWQUxdu7PakYD3rW5KdQrr2gnVlrSEqdMp89 uPzA== X-Gm-Message-State: AKwxytcGHQYlM2uVlR5ajfbB6vOPU5hNCxnavaih/RdYS6ZlIesEHWnn mjYypeXfHwEqA0AXAw36uDGhPMIQ X-Google-Smtp-Source: ACJfBov/HVthx0YVinr3Ft73q0JpqrKuJBrF11YtpC0CUWYNmNqXX6h3DdDS5c2+ugJFAh9djRb6UQ== X-Received: by 10.36.41.198 with SMTP id p189mr218163itp.40.1515651515235; Wed, 10 Jan 2018 22:18:35 -0800 (PST) Original-Received: from cesars-w520 (c-24-4-33-27.hsd1.ca.comcast.net. [24.4.33.27]) by smtp.gmail.com with ESMTPSA id e132sm117325ite.41.2018.01.10.22.18.33 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Jan 2018 22:18:34 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::241 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:221824 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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. =2D-- 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 =2D-- a/lisp/mail/smtpmail.el +++ b/lisp/mail/smtpmail.el @@ -181,7 +181,25 @@ This is relative to `smtpmail-queue-dir'." =20 (defconst smtpmail-auth-supported '(cram-md5 plain login) "List of supported SMTP AUTH mechanisms. =2DThe 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=3D\" user \"\\1auth=3DBearer \" password \"\\1\= \1\") t)) + 235)) + +\(add-to-list 'smtpmail-try-auth-method 'xoauth2)") =20 (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)))) =20 =2D(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) =2D-=20 2.15.0 =2D-=20 Cesar Crusius --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAEBCAAdFiEEsu/ErKn7yEV7E0FU/X9qSDfQj2EFAlpXAbEACgkQ/X9qSDfQ j2HXOgv+LLS54jcKvl+dp+ky7TfqskAC78UcvGp2tMbTDeLTwfXEuupSj4p8a36w MlD4XeCRTSTVN/KBL9NSs1uD80JuP60lsunSeSUiQgXB0CI8n19a2utBLI0nDWB6 PWslXG/hbweq15RayyrKduCYIV08i/LcQ5MRy/7jLJT1Ac4ogxNDqT5raUwY7TqC lFchTPBGhot7gqPFu1GZ8PikMR9+qmVXSlV/RUmdT6Tz84n3XeakX09GQhWZHjCa ksIGgrn1rwXoWKIDEo5ENvukKcVp+1sPduZyqodizzv0y0lt/TsAPk07s5mtPfh6 +wkvsayyNWT/aUnE+VMEfM9mpXfMQMO2PtYlc/+FiezTjgeJ4giPbftBX7EKzgTo n6ukARiz33B6XnpniHZg2SLBwqnXXyTkxd01GgSr8AmHQLq+ulis0/a3oHd3G0Y3 BxRRDRjrCvniOvrF/O8kp6klxlSP9yZHpxsmB+F3wsPLxQO5cVIwWn059bPEPprM 6K1KxN1R =F7Uk -----END PGP SIGNATURE----- --=-=-=--