From: Philip Kaludercic <philipk@posteo.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 52205@debbugs.gnu.org
Subject: bug#52205: Allow configuring multiple mail accounts for smtpmail.el
Date: Sun, 19 Dec 2021 21:59:27 +0000 [thread overview]
Message-ID: <871r28mf28.fsf@posteo.net> (raw)
In-Reply-To: <87bl1cyi8k.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 19 Dec 2021 11:57:47 +0100")
[-- Attachment #1: Type: text/plain, Size: 1338 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Philip Kaludercic <philipk@posteo.net> writes:
>
>>>>> Or we could add a command like `message-update-smtp-method-header' and
>>>>> people could call that (or add it to their hooks) after altering their
>>>>> From (or whatever) headers.
>>>>
>>>> So if the mechanism is supposed to be kept general (instead of just
>>>> checking the From header), how would this differ from the already
>>>> existing message-send-mail-hook?
>>>
>>> How a command would differ from a hook? I'm not sure I understand the
>>> question.
>>
>> Oh, sorry I misunderstood your suggestion. So you are thinking of
>> something that would be configured like:
>>
>> ;; `message-server-alist' would match the From header[0] if it is a string,
>> ;; or call a function in the current message buffer if it is a function.
>> (setq message-server-alist
>> '(("foo@mail.com" . "smtp.mail.com")
>> ("bar@post.de" . "post-spuep.de")))
>>
>> (add-hook 'message-send-mail-hook #'message-update-smtp-method-header)
>
> No, I meant:
>
>>>>> Or we could add a command like `message-update-smtp-method-header' and
>>>>> people could call that
>
>> If so, then couldn't the add-hook just be dropped, and message always
>> checks message-server-alist before sending a message?
>
> Yes.
Ok, so how does this look like?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Automatically-insert-X-Message-SMTP-Method-headers.patch --]
[-- Type: text/x-diff, Size: 3119 bytes --]
From c1dec09a725b440380a01c71435b24fc4cd905c0 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Sun, 19 Dec 2021 22:53:59 +0100
Subject: [PATCH] Automatically insert X-Message-SMTP-Method headers
* message.el (message-server-alist): Add user option
(message-update-smtp-method-header): Add function
(message-send): Call message-update-smtp-method-header
---
lisp/gnus/message.el | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 285369b84c..24a12af3c9 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -1,4 +1,4 @@
-;;; message.el --- composing mail and news messages -*- lexical-binding: t -*-
+;;; message.el --- composing mail and news messages -*- lexical- t -*-
;; Copyright (C) 1996-2021 Free Software Foundation, Inc.
@@ -4335,6 +4335,43 @@ message-bury
(autoload 'mml-secure-bcc-is-safe "mml-sec")
+(defcustom message-server-alist nil
+ "Alist of rules to generate \"X-Message-SMTP-Method\" headers.
+If any entry of the form (COND . METHOD) matches, the header will
+be inserted just before the message is sent. If COND is a
+string, METHOD will be inserted if the \"From\" header matches
+COND. If COND is a function, METHOD will be inserted if COND
+returns a non-nil value, when called in the message buffer
+without any arguments. If METHOD is nil in the last case, the
+return value of the function will be returned instead. None of
+this applies if the buffer already has a\"X-Message-SMTP-Method\"
+header."
+ :type '(alist :key-type '(choice
+ (string :tag "From Address")
+ (function :tag "Predicate"))
+ :value-type 'string)
+ :version "29.1"
+ :group 'message-sending)
+
+(defun message-update-smtp-method-header ()
+ "Check `message-server-alist' to insert a SMTP-Method header."
+ (unless (message-fetch-field "X-Message-SMTP-Method")
+ (let ((from (mail-extract-address-components (message-fetch-field "From")))
+ method)
+ (catch 'exit
+ (dolist (server message-server-alist)
+ (cond ((functionp (car server))
+ (let ((res (funcall (car server))))
+ (when res
+ (setq method (or (cdr server) res))
+ (throw 'exit nil))))
+ ((and (stringp (car server))
+ (string= (car server) from))
+ (setq method (cdr server))
+ (throw 'exit nil)))))
+ (when method
+ (message-add-header (concat "X-Message-SMTP-Method: " method))))))
+
(defun message-send (&optional arg)
"Send the message in the current buffer.
If `message-interactive' is non-nil, wait for success indication or
@@ -4348,6 +4385,7 @@ message-send
(undo-boundary)
(let ((inhibit-read-only t))
(put-text-property (point-min) (point-max) 'read-only nil))
+ (message-update-smtp-method-header)
(message-fix-before-sending)
(run-hooks 'message-send-hook)
(mml-secure-bcc-is-safe)
--
2.30.2
[-- Attachment #3: Type: text/plain, Size: 225 bytes --]
This calls message-update-smtp-method-header before message-send-hook,
but I could also see adding message-update-smtp-method-header to the
hook in message.el, so that a user may remove it if needed.
--
Philip Kaludercic
next prev parent reply other threads:[~2021-12-19 21:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-30 19:45 bug#52205: Allow configuring multiple mail accounts for smtpmail.el Philip Kaludercic
2021-12-01 4:08 ` Lars Ingebrigtsen
2021-12-01 9:01 ` Philip Kaludercic
2021-12-01 19:21 ` Lars Ingebrigtsen
2021-12-01 20:15 ` Philip Kaludercic
2021-12-01 20:24 ` Lars Ingebrigtsen
2021-12-02 23:06 ` Philip Kaludercic
2021-12-03 16:17 ` Lars Ingebrigtsen
2021-12-04 9:12 ` Philip Kaludercic
2021-12-04 19:01 ` Lars Ingebrigtsen
2021-12-13 19:20 ` Philip Kaludercic
2021-12-14 13:41 ` Lars Ingebrigtsen
2021-12-18 13:45 ` Philip Kaludercic
2021-12-19 10:57 ` Lars Ingebrigtsen
2021-12-19 21:59 ` Philip Kaludercic [this message]
2021-12-22 12:20 ` Lars Ingebrigtsen
2022-09-09 17:53 ` Lars Ingebrigtsen
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=871r28mf28.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=52205@debbugs.gnu.org \
--cc=larsi@gnus.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.