From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#52205: Allow configuring multiple mail accounts for smtpmail.el Date: Tue, 30 Nov 2021 19:45:10 +0000 Message-ID: <87fsrdmnqx.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8470"; mail-complaints-to="usenet@ciao.gmane.io" To: 52205@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 30 20:46:12 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ms94u-00025p-EG for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 30 Nov 2021 20:46:12 +0100 Original-Received: from localhost ([::1]:37632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ms94t-0004E2-7E for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 30 Nov 2021 14:46:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ms94l-0004CX-6f for bug-gnu-emacs@gnu.org; Tue, 30 Nov 2021 14:46:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59248) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ms94k-0008Cs-UH for bug-gnu-emacs@gnu.org; Tue, 30 Nov 2021 14:46:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ms94k-0002X7-KH for bug-gnu-emacs@gnu.org; Tue, 30 Nov 2021 14:46:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 30 Nov 2021 19:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 52205 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16383015269686 (code B ref -1); Tue, 30 Nov 2021 19:46:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Nov 2021 19:45:26 +0000 Original-Received: from localhost ([127.0.0.1]:42561 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ms949-0002W9-N9 for submit@debbugs.gnu.org; Tue, 30 Nov 2021 14:45:26 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:38602) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ms947-0002W1-9x for submit@debbugs.gnu.org; Tue, 30 Nov 2021 14:45:23 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ms946-0003ek-Iy for bug-gnu-emacs@gnu.org; Tue, 30 Nov 2021 14:45:23 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:47887) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ms942-00081S-35 for bug-gnu-emacs@gnu.org; Tue, 30 Nov 2021 14:45:21 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 0BD36240103 for ; Tue, 30 Nov 2021 20:45:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1638301512; bh=7o8+aF/RIYNoYF2uy1i6I9TijEP07DhJKir55cuQcBg=; h=From:To:Subject:Date:From; b=kKNqeLGkPs22Q0p3CWd7HYocNU/d7B98765ES2YBhvBaqdSGpTUPrB936W7VVtW+n HO7xcHq4FmCq7MJ65L5lBk3Ww5UT3tq+o5yr5z9L6TLEm+43g0LG/Y9AXrKUzEdegz 60ddbBClYdj+pb5peEepNKI8eO3nkWlFwJeZIoiisb6JqRrJuYOD1Sh6EEyud8EYsv 2gAHNFW5yyFygwfWYA0XWGGvDuZ6b8iF1MCuJd3PeUEJK07JbaoBh6QScFVYiWih4s Gq1tbWwwYARPZ18APEpXrHnmHA3lrIDxfJfrZBmk4NvRS9KGt0Q/VqzUlVaw5fuLhn CwXwnG/9FwOBQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4J3XkH2sWPz6tmq for ; Tue, 30 Nov 2021 20:45:11 +0100 (CET) Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:221169 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Tags: patch Hi, the below patch should allow for multiple mail accounts being configured for smtpmail.el, without having to use tricks like X-Message-SMTP-Method, that only work when the MUA also inserts them at the right time. This is an initial patch, and everything seems to work on my end. I had a little issue with the indentation, because Emacs re-indented everything at first, but I didn't want to send a patch consisting of mainly unrelated whitespace changes. In GNU Emacs 28.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0) of 2021-11-30 built on viero Repository revision: c4daff9cf844ec85930bdcd2064787c92c260861 Repository branch: emacs-28 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 Configured using: 'configure CC=gcc PKG_CONFIG_PATH=/gnu/store/sfqc239vzd9d1hxmnvav385x1nl9zx5d-profile/lib/pkgconfig:/gnu/store/sfqc239vzd9d1hxmnvav385x1nl9zx5d-profile/share/pkgconfig:/home/philip/.guix-profile/lib/pkgconfig:/home/philip/.guix-profile/share/pkgconfig:/home/philip/.guix-profile/lib/pkgconfig:/home/philip/.guix-profile/share/pkgconfig' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Allow-configuring-multiple-mail-accounts-for-smtpmai.patch >From d4685683a265d53b28471e68c68ec8c6411e4aa7 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 30 Nov 2021 20:00:58 +0100 Subject: [PATCH] Allow configuring multiple mail accounts for smtpmail.el * lisp/mail/smtpmail.el (smtpmail-smtp-server-alist): New option to configure what server to use for what outgoing address. --- lisp/mail/smtpmail.el | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el index bd8aa611e9..95e7abdeae 100644 --- a/lisp/mail/smtpmail.el +++ b/lisp/mail/smtpmail.el @@ -78,6 +78,19 @@ smtpmail-smtp-server "The name of the host running SMTP server." :type '(choice (const nil) string)) +(defcustom smtpmail-smtp-server-alist '() + "Alist of SMTP servers for different addresses." + :type '(alist :key-type + (string :tag "Sender") + :value-type + (list (string :tag "SMTP Server") + (natnum :tag "Service") + (choice :tag "Stream type" + (const :tag "Possibly upgrade to STARTTLS" nil) + (const :tag "Always use STARTTLS" starttls) + (const :tag "Never use STARTTLS" plain) + (const :tag "Use TLS/SSL" ssl))))) + (defcustom smtpmail-smtp-service 25 "SMTP service port number. The default value would be \"smtp\" or 25." @@ -706,13 +719,9 @@ smtpmail-user-mail-address (defun smtpmail-via-smtp (recipient smtpmail-text-buffer &optional ask-for-password send-attempts) - (unless smtpmail-smtp-server + (unless (or smtpmail-smtp-server smtpmail-smtp-server-alist) (smtpmail-query-smtp-server)) - (let ((process nil) - (send-attempts (or send-attempts 1)) - (host (or smtpmail-smtp-server - (error "`smtpmail-smtp-server' not defined"))) - (port smtpmail-smtp-service) + (let* ((process nil) ;; `smtpmail-mail-address' should be set to the appropriate ;; buffer-local value by the caller, but in case not: (envelope-from @@ -727,6 +736,14 @@ smtpmail-via-smtp (and from (cadr (mail-extract-address-components from)))) (smtpmail-user-mail-address)))) + (send-attempts (or send-attempts 1)) + (server (alist-get envelope-from smtpmail-smtp-server-alist + (list smtpmail-smtp-server) + nil #'string=)) + (host (or (car server) + (error "No known SMTP Server for %S" envelope-from))) + (port (or (cadr server) + smtpmail-smtp-service)) process-buffer result auth-mechanisms @@ -757,7 +774,7 @@ smtpmail-via-smtp (setq result (open-network-stream "smtpmail" process-buffer host port - :type smtpmail-stream-type + :type (or (caddr server) smtpmail-stream-type) :return-list t :warn-unless-encrypted ask-for-password :capability-command (format "EHLO %s\r\n" (smtpmail-fqdn)) -- 2.34.0 --=-=-= Content-Type: text/plain -- Philip Kaludercic --=-=-=--