GNU bug report logs - #63311
30.0.50; [PATCH] smtpmail-send-it split

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Manuel Giraud <manuel@HIDDEN>; Keywords: patch; dated Fri, 5 May 2023 15:10:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 63311 <at> debbugs.gnu.org:


Received: (at 63311) by debbugs.gnu.org; 11 May 2023 20:59:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu May 11 16:59:29 2023
Received: from localhost ([127.0.0.1]:53534 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pxDNp-0005Tc-3a
	for submit <at> debbugs.gnu.org; Thu, 11 May 2023 16:59:29 -0400
Received: from ledu-giraud.fr ([51.159.28.247]:23771)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <manuel@HIDDEN>) id 1pxDNm-0005TR-R6
 for 63311 <at> debbugs.gnu.org; Thu, 11 May 2023 16:59:28 -0400
DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=JdZz0fp4
 QDd3QDQXEkvkh8zkdJGNgMxSLPaL++51mog=;
 h=date:references:in-reply-to:
 subject:cc:to:from; d=ledu-giraud.fr; b=l4fWshQ2D+osptB5PtBoYlteQt4fEX
 oIfmTnVsNppquO0bbNllV+SzQvRYQSZrWqSjePdfHO2E8Zg73ca4KNDA==
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=JdZz0fp4QDd3QDQX
 Ekvkh8zkdJGNgMxSLPaL++51mog=;
 h=date:references:in-reply-to:subject:
 cc:to:from; d=ledu-giraud.fr; b=d9hZ3DCeSovTHAEoFKR2+jPNIFKNEvau6IY/hK
 dpXZ8xFVMyvq2LnfWlSnadpKThRMH5gyXzwavXZKlah7Q0QxzG/BklJE9GE0wFnh5smuLJ
 qlKc2cpqtvKrSZ66+ofuoM/ZbHYEVftH3mUhUnWtKVhuC52DVUHGi6g4PU0APY5bpdPUWE
 vVLoXDbRLeb+0VD2YNWzAIzS8iU7oXLUINTf5iKT6q/k7MvAgmSlGZuI7uqcK+vRK3kkDG
 woC/F9LbQ382Svr99m9r1i5zFeBzXsYe0osKhUJdgIBo1MphIMSV0YJolj7ryvTWgZFIec
 pbChHSz2cBdocokC8ttf4fVg==
Received: from computer (<unknown> [10.1.1.1])
 by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id c209fb75
 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); 
 Thu, 11 May 2023 22:59:24 +0200 (CEST)
From: Manuel Giraud <manuel@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#63311: 30.0.50; [PATCH] smtpmail-send-it split
In-Reply-To: <837ctf575q.fsf@HIDDEN> (Eli Zaretskii's message of "Thu, 11 May
 2023 16:28:33 +0300")
References: <87jzxmsyyr.fsf@HIDDEN> <83ttwqhahy.fsf@HIDDEN>
 <874joq34bk.fsf@HIDDEN> <83o7mygevr.fsf@HIDDEN>
 <87wn1hzv9j.fsf@HIDDEN> <871qjoe7cw.fsf@HIDDEN>
 <837ctf575q.fsf@HIDDEN>
Date: Thu, 11 May 2023 22:59:20 +0200
Message-ID: <87ilcypot3.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 63311
Cc: 63311 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Eli Zaretskii <eliz@HIDDEN> writes:

>> From: Manuel Giraud <manuel@HIDDEN>
>> Cc: 63311 <at> debbugs.gnu.org
>> Date: Wed, 10 May 2023 13:47:11 +0200
>> 
>> So I guess, my question is how does one mix Lisp thread with
>> unwind-protect?
>
> I'm not sure I understand why you need to.  The two unwind-protect
> handlers will run at different times and most probably will need to
> unwind different stuff, although there could be overlap.  So why is it
> a problem to have two separate unwind forms?

I was not talking about two separate unwind forms.  I was talking about
*thread* and unwind.  Here is a minimal example that exhibits my
problem:

--8<---------------cut here---------------start------------->8---
(setq-local lexical-binding t)

(defun my-problem ()
  (interactive)
  (let ((buf (generate-new-buffer "*foo*")))
    (with-current-buffer buf
      (insert "secret message"))
    (unwind-protect
	(make-thread #'(lambda ()
			 (with-current-buffer buf
			   (sit-for 10)
			   (message (buffer-string)))))
      (kill-buffer buf))))
--8<---------------cut here---------------end--------------->8---

The thread won't have a chance to do its job since the buffer will
already be dead.
-- 
Manuel Giraud




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#63311; Package emacs. Full text available.

Message received at 63311 <at> debbugs.gnu.org:


Received: (at 63311) by debbugs.gnu.org; 11 May 2023 13:27:33 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu May 11 09:27:33 2023
Received: from localhost ([127.0.0.1]:50062 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1px6KT-0008El-5Z
	for submit <at> debbugs.gnu.org; Thu, 11 May 2023 09:27:33 -0400
Received: from eggs.gnu.org ([209.51.188.92]:39500)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1px6KR-0008EU-7M
 for 63311 <at> debbugs.gnu.org; Thu, 11 May 2023 09:27:31 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1px6KL-0003il-Dw; Thu, 11 May 2023 09:27:25 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=lHzpoiKqdx7uMy6G5XMP32Db7x3jrgTDuv1qnA0wFrw=; b=Yc2Tdp8gGkuy
 A7aQIm4p6dBXLEvaPRzuLo+hE/dPtwfzVpbdNgusvEteodZ/vAa1yLGBN3ytUfyuxCq4N1KIEHzai
 h92pJCgKiSI6/H/zh+wBgOkiAGLNEyTE2b19L3kv9Gr05uk8GXMVLT/BxGdzPxXSH2JDZulW8WpKB
 INXDHwSpSRVbYABQ/2Xg6BEIvIUpcMKkcmzf+3vpPXxGTvtBpEv77uFRLZY6Kqb0JTQ3BCi+LaMb/
 hRrRtFJJPLRk/dYs/aN3XTMgsqtyEZk6uHaMRD6lr1osEhmWJZWMflwR9EcNPwWMaZ9L83m9xqRNV
 BIcwlIw3Nk6ohyAAVsvDCQ==;
Received: from [87.69.77.57] (helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1px6KK-0002tX-Tm; Thu, 11 May 2023 09:27:25 -0400
Date: Thu, 11 May 2023 16:28:33 +0300
Message-Id: <837ctf575q.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Manuel Giraud <manuel@HIDDEN>
In-Reply-To: <871qjoe7cw.fsf@HIDDEN> (message from Manuel Giraud on
 Wed, 10 May 2023 13:47:11 +0200)
Subject: Re: bug#63311: 30.0.50; [PATCH] smtpmail-send-it split
References: <87jzxmsyyr.fsf@HIDDEN> <83ttwqhahy.fsf@HIDDEN>
 <874joq34bk.fsf@HIDDEN> <83o7mygevr.fsf@HIDDEN>
 <87wn1hzv9j.fsf@HIDDEN> <871qjoe7cw.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 63311
Cc: 63311 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Manuel Giraud <manuel@HIDDEN>
> Cc: 63311 <at> debbugs.gnu.org
> Date: Wed, 10 May 2023 13:47:11 +0200
> 
> So I guess, my question is how does one mix Lisp thread with
> unwind-protect?

I'm not sure I understand why you need to.  The two unwind-protect
handlers will run at different times and most probably will need to
unwind different stuff, although there could be overlap.  So why is it
a problem to have two separate unwind forms?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#63311; Package emacs. Full text available.

Message received at 63311 <at> debbugs.gnu.org:


Received: (at 63311) by debbugs.gnu.org; 10 May 2023 11:47:19 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed May 10 07:47:19 2023
Received: from localhost ([127.0.0.1]:45416 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pwiHu-0002TI-UC
	for submit <at> debbugs.gnu.org; Wed, 10 May 2023 07:47:19 -0400
Received: from ledu-giraud.fr ([51.159.28.247]:31282)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <manuel@HIDDEN>) id 1pwiHq-0002T4-Kv
 for 63311 <at> debbugs.gnu.org; Wed, 10 May 2023 07:47:18 -0400
DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=47OcNKKi
 q2TcJtDlE4ysxolI6y6BzPDEZtU+QgNTT5s=;
 h=date:references:in-reply-to:
 subject:cc:to:from; d=ledu-giraud.fr; b=CJu11UiJ8WXJGDz0iDH0k/bEY44zTu
 Y5PR5sSbmO+CzTdzdDq1Mwuo878rhzFMvaccHHnOKaQ+JcgolN5Ni8AA==
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=47OcNKKiq2TcJtDl
 E4ysxolI6y6BzPDEZtU+QgNTT5s=;
 h=date:references:in-reply-to:subject:
 cc:to:from; d=ledu-giraud.fr; b=TDYOpt1o/sW18EMfOkGzsGp/fb8dk9mWAb4Gnd
 Ox9gR1WIG6xRxaPYCEX9WHRftuRW9wHO/GZLyS55NhGx+AmvVmxUrVuDOyEe4yFQV1mOGP
 zNWAw+llEnpqKVccdTuR/LOsqxXa5nDXH9OrxgLmLB//GGMD+sEQZQSvNq2GaAReEV2Opa
 RONYsoctRM3sqHtWUzz3Hgl9mJ9uy6j7jESE7g7wDqsft239xJS4L+BP1R668MRIRvL9rx
 4eqzbajD4gyy0L0GnmAwMEWEjXN1z0PFFccF8q33Wkkn/hQMkPgPAdJijrU1b0QKG+J8/8
 7LtiE+JWyhUkbOcvpcr3vQOg==
Received: from computer (<unknown> [10.1.1.1])
 by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id ef4a89a5
 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); 
 Wed, 10 May 2023 13:47:12 +0200 (CEST)
From: Manuel Giraud <manuel@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#63311: 30.0.50; [PATCH] smtpmail-send-it split
In-Reply-To: <87wn1hzv9j.fsf@HIDDEN> (Manuel Giraud's message of "Tue, 
 09 May 2023 11:52:56 +0200")
References: <87jzxmsyyr.fsf@HIDDEN> <83ttwqhahy.fsf@HIDDEN>
 <874joq34bk.fsf@HIDDEN> <83o7mygevr.fsf@HIDDEN>
 <87wn1hzv9j.fsf@HIDDEN>
Date: Wed, 10 May 2023 13:47:11 +0200
Message-ID: <871qjoe7cw.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 63311
Cc: 63311 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi Eli,

My strategy after the previous patch is summed up by this function:

--8<---------------cut here---------------start------------->8---
(defun smtpmail-async-send-it (cleanups)
  (let ((tembuf (generate-new-buffer " smtpmail temp"))
        (smtpmail-code-conv-from
	       (if enable-multibyte-characters
	           (let ((sendmail-coding-system smtpmail-code-conv-from))
	             (select-message-coding-system)))))
    (smtpmail-prepare-mail tembuf smtpmail-code-conv-from)
    (push #'(lambda () (kill-buffer tembuf)) cleanups)
    (make-thread #'(lambda ()
                     (smtpmail-send-mail tembuf)
                     (mapc #'funcall cleanups)))))
--8<---------------cut here---------------end--------------->8---

That is, I'd like carry around a 'cleanups' list that holds all the
functions that needed to be called after the mail was sent.

I then need to propagate this 'cleanups' parameter to callers of
'smtpmail-send-it'.  The problem is that encounter code with the
following form:

--8<---------------cut here---------------start------------->8---
(unwind-protect
    (let (haha)
      (do)
      (many)
      (things)
      (smtpmail-send-it-or-one-of-its-caller)
      (run)
      (other)
      (stuff))
  (kill-some-top-level-buffer))
--8<---------------cut here---------------end--------------->8---

I'm tempted to put '(run)(other)(stuff)(kill-some-top-level-buffer)'
into the cleanups list and remove the unwind-protect but then if
something goes wrong before sending the mail the
'(kill-some-top-level-buffer)' part won't be called.  OTOH, if I let the
'(unwind-protect=E2=80=A6  (kill-some-top-level-buffer)' in place I could s=
hoot
myself in the foot with the code that use this buffer into the thread.

So I guess, my question is how does one mix Lisp thread with
unwind-protect?

Best regards,
--=20
Manuel Giraud




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#63311; Package emacs. Full text available.

Message received at 63311 <at> debbugs.gnu.org:


Received: (at 63311) by debbugs.gnu.org; 9 May 2023 09:53:03 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue May 09 05:53:03 2023
Received: from localhost ([127.0.0.1]:42448 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pwK1m-0005yB-0y
	for submit <at> debbugs.gnu.org; Tue, 09 May 2023 05:53:03 -0400
Received: from ledu-giraud.fr ([51.159.28.247]:47396)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <manuel@HIDDEN>) id 1pwK1j-0005xu-3Q
 for 63311 <at> debbugs.gnu.org; Tue, 09 May 2023 05:53:00 -0400
DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=qI2V5tKd
 ylBtRXadS2wMZZO4QUxAItVwhZFO7pys6ms=;
 h=date:references:in-reply-to:
 subject:cc:to:from; d=ledu-giraud.fr; b=AqdHC1Yp5dZRfU8/h9Psx7FBgSo7bt
 mQRElHC61Tz6ejU/Y1n97SAx09KCRLNQ1+bcZ25+Mt5CyofdTHyQd1Aw==
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=qI2V5tKdylBtRXad
 S2wMZZO4QUxAItVwhZFO7pys6ms=;
 h=date:references:in-reply-to:subject:
 cc:to:from; d=ledu-giraud.fr; b=hc13BnzbFwJNGR8Ifrk32Wtp14A63NTNLHGwXx
 7xbf+n0gZgvwhZY61sgHOOlJXAvWzrDTJijowkUUb/UHV0W+hkR+Gnqu4cu+BO9VIwAepm
 dBXtAObQ+Od9ylGb0NeC9c2XNXCJg2PlusEwZdbOKW0Gt/M23oJVHf3lPxmR20fNVPocAF
 5xVSqZ1wtoKxeracd5Houn5rw2oUWUtQdSXRAUmlitPYE8L72LoaHp2jBd0cykSb0jZ9HO
 gQrbaaPBNtGUxiuRthC4j0xg/qXECA4et4hn/H3fXdK6vlHCIHGrbCrxeDy7t10JXpCYMk
 Ao1Sh+7R808t3m8ljXiwOXZQ==
Received: from computer (<unknown> [10.1.1.1])
 by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id a88c1b56
 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); 
 Tue, 9 May 2023 11:52:57 +0200 (CEST)
From: Manuel Giraud <manuel@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#63311: 30.0.50; [PATCH] smtpmail-send-it split
In-Reply-To: <83o7mygevr.fsf@HIDDEN> (Eli Zaretskii's message of "Sat, 06 May
 2023 09:20:24 +0300")
References: <87jzxmsyyr.fsf@HIDDEN> <83ttwqhahy.fsf@HIDDEN>
 <874joq34bk.fsf@HIDDEN> <83o7mygevr.fsf@HIDDEN>
Date: Tue, 09 May 2023 11:52:56 +0200
Message-ID: <87wn1hzv9j.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 63311
Cc: 63311 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Hi,

I forgot to "declare" 'result' in smtpmail-send-it.  Here is an updated
version.

--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=0001-smtpmail-send-it-split.patch

From a7786a443abebe38acd968dcd7ea2c2f2364d4a0 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@HIDDEN>
Date: Fri, 5 May 2023 14:35:01 +0200
Subject: [PATCH] smtpmail-send-it split

* lisp/mail/smtpmail.el (smtpmail-prepare-mail): New function that
prepares the mail with current buffer content.
(smtpmail-queue-mail): New function to queue a mail (prepared by
'smtpmail-prepare-mail').
(smtpmail-send-mail): New function to send a mail (prepared by
'smtpmail-send-mail').
(smtpmail-send-it): Use all three previous functions.  While here,
remove 'errbuf' leftovers.
---
 lisp/mail/smtpmail.el | 412 +++++++++++++++++++++---------------------
 1 file changed, 205 insertions(+), 207 deletions(-)

diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
index 78688d170cc..714f1e14eaf 100644
--- a/lisp/mail/smtpmail.el
+++ b/lisp/mail/smtpmail.el
@@ -205,217 +205,215 @@ smtpmail-mail-address
   "Value to use for envelope-from address for mail from ambient buffer.")
 
 ;;; Functions
+(defun smtpmail-prepare-mail (tembuf smtpmail-code-conv-from)
+    (let ((case-fold-search nil)
+	  delimline
+	  (mailbuf (current-buffer))
+         ;; Examine this variable now, so that
+	 ;; local binding in the mail buffer will take effect.
+	 (smtpmail-mail-address
+          (save-restriction
+            ;; Only look at the headers when fetching the
+            ;; envelope address.
+            (message-narrow-to-headers)
+            (or (and mail-specify-envelope-from (mail-envelope-from))
+                (let ((from (mail-fetch-field "from")))
+	          (and from
+		       (cadr (mail-extract-address-components from))))
+	        (smtpmail-user-mail-address)))))
+    (with-current-buffer tembuf
+      (erase-buffer)
+      ;; Use the same `buffer-file-coding-system' as in the mail
+      ;; buffer, otherwise any `write-region' invocations (e.g., in
+      ;; mail-do-fcc below) will annoy with asking for a suitable
+      ;; encoding.
+      (set-buffer-file-coding-system smtpmail-code-conv-from nil t)
+      (insert-buffer-substring mailbuf)
+      (goto-char (point-max))
+      ;; require one newline at the end.
+      (or (= (preceding-char) ?\n)
+	  (insert ?\n))
+      ;; Change header-delimiter to be what sendmail expects.
+      (mail-sendmail-undelimit-header)
+      (setq delimline (point-marker))
+      (if mail-aliases
+	  (expand-mail-aliases (point-min) delimline))
+      (goto-char (point-min))
+      ;; ignore any blank lines in the header
+      (while (and (re-search-forward "\n\n\n*" delimline t)
+		  (< (point) delimline))
+	(replace-match "\n"))
+      (let ((case-fold-search t))
+	;; We used to process Resent-... headers here,
+	;; but it was not done properly, and the job
+	;; is done correctly in `smtpmail-deduce-address-list'.
+	;; Don't send out a blank subject line
+	(goto-char (point-min))
+	(if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
+	    (replace-match "")
+	  ;; This one matches a Subject just before the header delimiter.
+	  (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
+		   (= (match-end 0) delimline))
+	      (replace-match "")))
+	;; Put the "From:" field in unless for some odd reason
+	;; they put one in themselves.
+	(goto-char (point-min))
+	(if (not (re-search-forward "^From:" delimline t))
+	    (let* ((login smtpmail-mail-address)
+		   (fullname (user-full-name)))
+	      (cond ((eq mail-from-style 'angles)
+		     (insert "From: " fullname)
+		     (let ((fullname-start (+ (point-min) 6))
+			   (fullname-end (point-marker)))
+		       (goto-char fullname-start)
+		       ;; Look for a character that cannot appear unquoted
+		       ;; according to RFC 822 or its successors.
+		       (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
+					      fullname-end 1)
+			   (progn
+			     ;; Quote fullname, escaping specials.
+			     (goto-char fullname-start)
+			     (insert "\"")
+			     (while (re-search-forward "[\"\\]"
+						       fullname-end 1)
+			       (replace-match "\\\\\\&" t))
+			     (insert "\""))))
+		     (insert " <" login ">\n"))
+		    ((eq mail-from-style 'parens)
+		     (insert "From: " login " (")
+		     (let ((fullname-start (point)))
+		       (insert fullname)
+		       (let ((fullname-end (point-marker)))
+			 (goto-char fullname-start)
+			 ;; RFC 822 and its successors say \ and
+			 ;; nonmatching parentheses must be
+			 ;; escaped in comments.
+			 ;; Escape every instance of ()\ ...
+			 (while (re-search-forward "[()\\]" fullname-end 1)
+			   (replace-match "\\\\\\&" t))
+			 ;; ... then undo escaping of matching parentheses,
+			 ;; including matching nested parentheses.
+			 (goto-char fullname-start)
+			 (while (re-search-forward
+				 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
+				 fullname-end 1)
+			   (replace-match "\\1(\\3)" t)
+			   (goto-char fullname-start))))
+		     (insert ")\n"))
+		    ((null mail-from-style)
+		     (insert "From: " login "\n")))))
+	;; Insert a `Message-Id:' field if there isn't one yet.
+	(goto-char (point-min))
+	(unless (re-search-forward "^Message-Id:" delimline t)
+	  (insert "Message-Id: " (message-make-message-id) "\n"))
+	;; Insert a `Date:' field if there isn't one yet.
+	(goto-char (point-min))
+	(unless (re-search-forward "^Date:" delimline t)
+	  (insert "Date: " (message-make-date) "\n"))
+	;; Possibly add a MIME header for the current coding system
+	(let (charset)
+	  (goto-char (point-min))
+	  (and (eq mail-send-nonascii 'mime)
+	       (not (re-search-forward "^MIME-version:" delimline t))
+	       (progn (skip-chars-forward "\0-\177")
+		      (/= (point) (point-max)))
+	       smtpmail-code-conv-from
+	       (setq charset
+		     (coding-system-get smtpmail-code-conv-from
+					'mime-charset))
+	       (goto-char delimline)
+	       (insert "MIME-version: 1.0\n"
+		       "Content-type: text/plain; charset="
+		       (symbol-name charset)
+		       "\nContent-Transfer-Encoding: 8bit\n")))
+	;; Insert an extra newline if we need it to work around
+	;; Sun's bug that swallows newlines.
+	(goto-char (1+ delimline))
+	;; Find and handle any Fcc fields.
+	(goto-char (point-min))
+	(if (re-search-forward "^Fcc:" delimline t)
+	    ;; Force `mail-do-fcc' to use the encoding of the mail
+	    ;; buffer to encode outgoing messages on Fcc files.
+	    (let ((coding-system-for-write
+		   ;; mbox files must have Unix EOLs.
+		   (coding-system-change-eol-conversion
+		    smtpmail-code-conv-from 'unix)))
+	      (mail-do-fcc delimline))))
+      ;; Encode the header according to RFC2047.
+      (mail-encode-header (point-min) delimline)
+      ;;
+      (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*"))
+      (setq smtpmail-recipient-address-list
+            (smtpmail-deduce-address-list tembuf (point-min) delimline))
+      (kill-buffer smtpmail-address-buffer)
+
+      (smtpmail-do-bcc delimline))))
+
+(defun smtpmail-queue-mail (tembuf smtpmail-code-conv-from)
+  (let* ((file-data
+	  (expand-file-name
+	   (format "%s_%i"
+		   (format-time-string "%Y-%m-%d_%H:%M:%S")
+		   (setq smtpmail-queue-counter
+			 (1+ smtpmail-queue-counter)))
+	   smtpmail-queue-dir))
+	 (file-data (convert-standard-filename file-data))
+	 (file-elisp (concat file-data ".el"))
+	 (buffer-data (create-file-buffer file-data)))
+    (unless (file-exists-p smtpmail-queue-dir)
+      (make-directory smtpmail-queue-dir t))
+    (with-current-buffer buffer-data
+      (erase-buffer)
+      (set-buffer-file-coding-system
+       ;; We will be reading the file with no-conversion in
+       ;; smtpmail-send-queued-mail below, so write it out
+       ;; with Unix EOLs.
+       (coding-system-change-eol-conversion
+	(or smtpmail-code-conv-from 'undecided)
+	'unix)
+       nil t)
+      (insert-buffer-substring tembuf)
+      (write-file file-data)
+      (let ((coding-system-for-write 'utf-8))
+        (with-temp-buffer
+          (insert "(setq ")
+          (dolist (var (cons 'smtpmail-recipient-address-list
+                             ;; Perhaps store the server etc.
+                             (and smtpmail-store-queue-variables
+                                  smtpmail--stored-queue-variables)))
+            (insert (format "     %s %S\n" var (symbol-value var))))
+          (insert ")\n")
+          (write-region (point-min) (point-max) file-elisp
+                        nil 'silent)))
+      (write-region (concat file-data "\n") nil
+                    (expand-file-name smtpmail-queue-index-file
+                                      smtpmail-queue-dir)
+                    t 'silent))
+    (kill-buffer buffer-data)))
+
+(defun smtpmail-send-mail (tembuf)
+  (let (result)
+    (if (not (null smtpmail-recipient-address-list))
+        (when (setq result
+                    (smtpmail-via-smtp
+                     smtpmail-recipient-address-list tembuf))
+          (error "Sending failed: %s"
+                 (smtpmail--sanitize-error-message result)))
+      (error "Sending failed; no recipients"))))
 
 ;;;###autoload
 (defun smtpmail-send-it ()
-  (let ((errbuf (if mail-interactive
-		    (generate-new-buffer " smtpmail errors")
-		  0))
-	(tembuf (generate-new-buffer " smtpmail temp"))
-	(case-fold-search nil)
-	delimline
-	result
-	(mailbuf (current-buffer))
-        ;; Examine this variable now, so that
-	;; local binding in the mail buffer will take effect.
-	(smtpmail-mail-address
-         (save-restriction
-           ;; Only look at the headers when fetching the
-           ;; envelope address.
-           (message-narrow-to-headers)
-           (or (and mail-specify-envelope-from (mail-envelope-from))
-               (let ((from (mail-fetch-field "from")))
-	         (and from
-		      (cadr (mail-extract-address-components from))))
-	       (smtpmail-user-mail-address))))
-	(smtpmail-code-conv-from
-	 (if enable-multibyte-characters
-	     (let ((sendmail-coding-system smtpmail-code-conv-from))
-	       (select-message-coding-system)))))
+  (let ((tembuf (generate-new-buffer " smtpmail temp")))
     (unwind-protect
-	(with-current-buffer tembuf
-	  (erase-buffer)
-	  ;; Use the same `buffer-file-coding-system' as in the mail
-	  ;; buffer, otherwise any `write-region' invocations (e.g., in
-	  ;; mail-do-fcc below) will annoy with asking for a suitable
-	  ;; encoding.
-	  (set-buffer-file-coding-system smtpmail-code-conv-from nil t)
-	  (insert-buffer-substring mailbuf)
-	  (goto-char (point-max))
-	  ;; require one newline at the end.
-	  (or (= (preceding-char) ?\n)
-	      (insert ?\n))
-	  ;; Change header-delimiter to be what sendmail expects.
-	  (mail-sendmail-undelimit-header)
-	  (setq delimline (point-marker))
-          ;; (sendmail-synch-aliases)
-	  (if mail-aliases
-	      (expand-mail-aliases (point-min) delimline))
-	  (goto-char (point-min))
-	  ;; ignore any blank lines in the header
-	  (while (and (re-search-forward "\n\n\n*" delimline t)
-		      (< (point) delimline))
-	    (replace-match "\n"))
-	  (let ((case-fold-search t))
-	    ;; We used to process Resent-... headers here,
-	    ;; but it was not done properly, and the job
-	    ;; is done correctly in `smtpmail-deduce-address-list'.
-	    ;; Don't send out a blank subject line
-	    (goto-char (point-min))
-	    (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
-		(replace-match "")
-	      ;; This one matches a Subject just before the header delimiter.
-	      (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
-		       (= (match-end 0) delimline))
-		  (replace-match "")))
-	    ;; Put the "From:" field in unless for some odd reason
-	    ;; they put one in themselves.
-	    (goto-char (point-min))
-	    (if (not (re-search-forward "^From:" delimline t))
-		(let* ((login smtpmail-mail-address)
-		       (fullname (user-full-name)))
-		  (cond ((eq mail-from-style 'angles)
-			 (insert "From: " fullname)
-			 (let ((fullname-start (+ (point-min) 6))
-			       (fullname-end (point-marker)))
-			   (goto-char fullname-start)
-			   ;; Look for a character that cannot appear unquoted
-			   ;; according to RFC 822 or its successors.
-			   (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
-						  fullname-end 1)
-			       (progn
-				 ;; Quote fullname, escaping specials.
-				 (goto-char fullname-start)
-				 (insert "\"")
-				 (while (re-search-forward "[\"\\]"
-							   fullname-end 1)
-				   (replace-match "\\\\\\&" t))
-				 (insert "\""))))
-			 (insert " <" login ">\n"))
-			((eq mail-from-style 'parens)
-			 (insert "From: " login " (")
-			 (let ((fullname-start (point)))
-			   (insert fullname)
-			   (let ((fullname-end (point-marker)))
-			     (goto-char fullname-start)
-			     ;; RFC 822 and its successors say \ and
-			     ;; nonmatching parentheses must be
-			     ;; escaped in comments.
-			     ;; Escape every instance of ()\ ...
-			     (while (re-search-forward "[()\\]" fullname-end 1)
-			       (replace-match "\\\\\\&" t))
-			     ;; ... then undo escaping of matching parentheses,
-			     ;; including matching nested parentheses.
-			     (goto-char fullname-start)
-			     (while (re-search-forward
-				     "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
-				     fullname-end 1)
-			       (replace-match "\\1(\\3)" t)
-			       (goto-char fullname-start))))
-			 (insert ")\n"))
-			((null mail-from-style)
-			 (insert "From: " login "\n")))))
-	    ;; Insert a `Message-Id:' field if there isn't one yet.
-	    (goto-char (point-min))
-	    (unless (re-search-forward "^Message-Id:" delimline t)
-	      (insert "Message-Id: " (message-make-message-id) "\n"))
-	    ;; Insert a `Date:' field if there isn't one yet.
-	    (goto-char (point-min))
-	    (unless (re-search-forward "^Date:" delimline t)
-	      (insert "Date: " (message-make-date) "\n"))
-	    ;; Possibly add a MIME header for the current coding system
-	    (let (charset)
-	      (goto-char (point-min))
-	      (and (eq mail-send-nonascii 'mime)
-		   (not (re-search-forward "^MIME-version:" delimline t))
-		   (progn (skip-chars-forward "\0-\177")
-			  (/= (point) (point-max)))
-		   smtpmail-code-conv-from
-		   (setq charset
-			 (coding-system-get smtpmail-code-conv-from
-					    'mime-charset))
-		   (goto-char delimline)
-		   (insert "MIME-version: 1.0\n"
-			   "Content-type: text/plain; charset="
-			   (symbol-name charset)
-			   "\nContent-Transfer-Encoding: 8bit\n")))
-	    ;; Insert an extra newline if we need it to work around
-	    ;; Sun's bug that swallows newlines.
-	    (goto-char (1+ delimline))
-	    ;; Find and handle any Fcc fields.
-	    (goto-char (point-min))
-	    (if (re-search-forward "^Fcc:" delimline t)
-		;; Force `mail-do-fcc' to use the encoding of the mail
-		;; buffer to encode outgoing messages on Fcc files.
-		(let ((coding-system-for-write
-		       ;; mbox files must have Unix EOLs.
-		       (coding-system-change-eol-conversion
-			smtpmail-code-conv-from 'unix)))
-		  (mail-do-fcc delimline)))
-	    (if mail-interactive
-		(with-current-buffer errbuf
-		  (erase-buffer))))
-	  ;; Encode the header according to RFC2047.
-	  (mail-encode-header (point-min) delimline)
-	  ;;
-	  (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*"))
-	  (setq smtpmail-recipient-address-list
-                (smtpmail-deduce-address-list tembuf (point-min) delimline))
-	  (kill-buffer smtpmail-address-buffer)
-
-	  (smtpmail-do-bcc delimline)
-          ;; Send or queue
-	  (if (not smtpmail-queue-mail)
-	      (if (not (null smtpmail-recipient-address-list))
-		  (when (setq result
-			      (smtpmail-via-smtp
-			       smtpmail-recipient-address-list tembuf))
-		    (error "Sending failed: %s"
-                           (smtpmail--sanitize-error-message result)))
-		(error "Sending failed; no recipients"))
-	    (let* ((file-data
-		    (expand-file-name
-		     (format "%s_%i"
-			     (format-time-string "%Y-%m-%d_%H:%M:%S")
-			     (setq smtpmail-queue-counter
-				   (1+ smtpmail-queue-counter)))
-		     smtpmail-queue-dir))
-		   (file-data (convert-standard-filename file-data))
-		   (file-elisp (concat file-data ".el"))
-		   (buffer-data (create-file-buffer file-data)))
-	      (unless (file-exists-p smtpmail-queue-dir)
-		(make-directory smtpmail-queue-dir t))
-	      (with-current-buffer buffer-data
-		(erase-buffer)
-		(set-buffer-file-coding-system
-		 ;; We will be reading the file with no-conversion in
-		 ;; smtpmail-send-queued-mail below, so write it out
-		 ;; with Unix EOLs.
-		 (coding-system-change-eol-conversion
-		  (or smtpmail-code-conv-from 'undecided)
-		  'unix)
-		 nil t)
-		(insert-buffer-substring tembuf)
-		(write-file file-data)
-                (let ((coding-system-for-write 'utf-8))
-                  (with-temp-buffer
-                    (insert "(setq ")
-                    (dolist (var (cons 'smtpmail-recipient-address-list
-                                       ;; Perhaps store the server etc.
-                                       (and smtpmail-store-queue-variables
-                                            smtpmail--stored-queue-variables)))
-                      (insert (format "     %s %S\n" var (symbol-value var))))
-                    (insert ")\n")
-                    (write-region (point-min) (point-max) file-elisp
-                                  nil 'silent)))
-		(write-region (concat file-data "\n") nil
-                              (expand-file-name smtpmail-queue-index-file
-                                                smtpmail-queue-dir)
-                              t 'silent))
-	      (kill-buffer buffer-data))))
-      (kill-buffer tembuf)
-      (if (bufferp errbuf)
-	  (kill-buffer errbuf)))))
+        (let ((smtpmail-code-conv-from
+	       (if enable-multibyte-characters
+	           (let ((sendmail-coding-system smtpmail-code-conv-from))
+	             (select-message-coding-system)))))
+          (smtpmail-prepare-mail tembuf smtpmail-code-conv-from)
+          (if smtpmail-queue-mail
+              (smtpmail-queue-mail tembuf smtpmail-code-conv-from)
+            (smtpmail-send-mail tembuf)))
+      (kill-buffer tembuf))))
 
 ;;;###autoload
 (defun smtpmail-send-queued-mail ()
-- 
2.40.0


--=-=-=
Content-Type: text/plain

-- 
Manuel Giraud

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#63311; Package emacs. Full text available.

Message received at 63311 <at> debbugs.gnu.org:


Received: (at 63311) by debbugs.gnu.org; 6 May 2023 09:34:23 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 06 05:34:23 2023
Received: from localhost ([127.0.0.1]:59427 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pvEJ4-0007T8-HA
	for submit <at> debbugs.gnu.org; Sat, 06 May 2023 05:34:23 -0400
Received: from ledu-giraud.fr ([51.159.28.247]:28751)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <manuel@HIDDEN>) id 1pvEIz-0007Sw-Lg
 for 63311 <at> debbugs.gnu.org; Sat, 06 May 2023 05:34:21 -0400
DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=IHbD4ji3
 DET+oGd4yOMMqhh/IihYCvzJHmTqb42o92k=;
 h=date:references:in-reply-to:
 subject:cc:to:from; d=ledu-giraud.fr; b=R73/n5egnWRrNleWm9LYlqgKz/XNkZ
 vJDl0kTFKfm8+c/NJhfthwnIygmsW+NOCYlL1L3otS4s/JSzqBZhTfBg==
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=IHbD4ji3DET+oGd4
 yOMMqhh/IihYCvzJHmTqb42o92k=;
 h=date:references:in-reply-to:subject:
 cc:to:from; d=ledu-giraud.fr; b=Bfagf6/wWFR6rJfub4BHEhX8GWnKNQ7Z/C4ked
 dOOlMbMg3GrC8Ps+6Ips9qb7vDf0N6NIjBjuOkIxZnSPU00u2xkMUN7tpTcwKfBS8P8fYe
 SkZJdkDWUTqP5iVy6NlwJC6Y8AUABDfQqzFCdBYb1zITW+pLOwYFBOkXd2ekI5YkIWbTWi
 sR5MhIbVXomMZ9MnY6IdbE5Fr9iQQIHp01h8PpAxD/n1v8SAY5Poqq/mPCZzBeU/pROEff
 TDKjir0t5jVnM5PPcVCmxk1+DJG3k0V/5VQPtnhCyHWQ5o1h5iSnGt1G0wjcs6WdZlhwQ2
 jK1pfDlbbig3NDZX13nQldNg==
Received: from computer (<unknown> [10.1.1.1])
 by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id c8a3e500
 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); 
 Sat, 6 May 2023 11:34:15 +0200 (CEST)
From: Manuel Giraud <manuel@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#63311: 30.0.50; [PATCH] smtpmail-send-it split
In-Reply-To: <83o7mygevr.fsf@HIDDEN> (Eli Zaretskii's message of "Sat, 06 May
 2023 09:20:24 +0300")
References: <87jzxmsyyr.fsf@HIDDEN> <83ttwqhahy.fsf@HIDDEN>
 <874joq34bk.fsf@HIDDEN> <83o7mygevr.fsf@HIDDEN>
Date: Sat, 06 May 2023 11:34:14 +0200
Message-ID: <87zg6h2489.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 63311
Cc: 63311 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Eli Zaretskii <eliz@HIDDEN> writes:

[...]

>> Ok.  Do you want me to upgrade this patch removing errbuf?
>
> Sure, that's a good cleanup.

Ok.  Here is the modified patch.

> (And please use Reply All, to have this discussion recorded by the
> tracker.)

Sure.  Sorry about that.

--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=0001-smtpmail-send-it-split.patch

From dfcaa8d0b9ec3fa0087326bb06dcdda5895f7142 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@HIDDEN>
Date: Fri, 5 May 2023 14:35:01 +0200
Subject: [PATCH] smtpmail-send-it split

* lisp/mail/smtpmail.el (smtpmail-prepare-mail): New function that
prepares the mail with current buffer content.
(smtpmail-queue-mail): New function to queue a mail (prepared by
'smtpmail-prepare-mail').
(smtpmail-send-mail): New function to send a mail (prepared by
'smtpmail-send-mail').
(smtpmail-send-it): Use all three previous functions.  While here,
remove 'errbuf' leftovers.
---
 lisp/mail/smtpmail.el | 411 +++++++++++++++++++++---------------------
 1 file changed, 204 insertions(+), 207 deletions(-)

diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
index 78688d170cc..2c23e97afd0 100644
--- a/lisp/mail/smtpmail.el
+++ b/lisp/mail/smtpmail.el
@@ -205,217 +205,214 @@ smtpmail-mail-address
   "Value to use for envelope-from address for mail from ambient buffer.")
 
 ;;; Functions
+(defun smtpmail-prepare-mail (tembuf smtpmail-code-conv-from)
+    (let ((case-fold-search nil)
+	  delimline
+	  (mailbuf (current-buffer))
+         ;; Examine this variable now, so that
+	 ;; local binding in the mail buffer will take effect.
+	 (smtpmail-mail-address
+          (save-restriction
+            ;; Only look at the headers when fetching the
+            ;; envelope address.
+            (message-narrow-to-headers)
+            (or (and mail-specify-envelope-from (mail-envelope-from))
+                (let ((from (mail-fetch-field "from")))
+	          (and from
+		       (cadr (mail-extract-address-components from))))
+	        (smtpmail-user-mail-address)))))
+    (with-current-buffer tembuf
+      (erase-buffer)
+      ;; Use the same `buffer-file-coding-system' as in the mail
+      ;; buffer, otherwise any `write-region' invocations (e.g., in
+      ;; mail-do-fcc below) will annoy with asking for a suitable
+      ;; encoding.
+      (set-buffer-file-coding-system smtpmail-code-conv-from nil t)
+      (insert-buffer-substring mailbuf)
+      (goto-char (point-max))
+      ;; require one newline at the end.
+      (or (= (preceding-char) ?\n)
+	  (insert ?\n))
+      ;; Change header-delimiter to be what sendmail expects.
+      (mail-sendmail-undelimit-header)
+      (setq delimline (point-marker))
+      (if mail-aliases
+	  (expand-mail-aliases (point-min) delimline))
+      (goto-char (point-min))
+      ;; ignore any blank lines in the header
+      (while (and (re-search-forward "\n\n\n*" delimline t)
+		  (< (point) delimline))
+	(replace-match "\n"))
+      (let ((case-fold-search t))
+	;; We used to process Resent-... headers here,
+	;; but it was not done properly, and the job
+	;; is done correctly in `smtpmail-deduce-address-list'.
+	;; Don't send out a blank subject line
+	(goto-char (point-min))
+	(if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
+	    (replace-match "")
+	  ;; This one matches a Subject just before the header delimiter.
+	  (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
+		   (= (match-end 0) delimline))
+	      (replace-match "")))
+	;; Put the "From:" field in unless for some odd reason
+	;; they put one in themselves.
+	(goto-char (point-min))
+	(if (not (re-search-forward "^From:" delimline t))
+	    (let* ((login smtpmail-mail-address)
+		   (fullname (user-full-name)))
+	      (cond ((eq mail-from-style 'angles)
+		     (insert "From: " fullname)
+		     (let ((fullname-start (+ (point-min) 6))
+			   (fullname-end (point-marker)))
+		       (goto-char fullname-start)
+		       ;; Look for a character that cannot appear unquoted
+		       ;; according to RFC 822 or its successors.
+		       (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
+					      fullname-end 1)
+			   (progn
+			     ;; Quote fullname, escaping specials.
+			     (goto-char fullname-start)
+			     (insert "\"")
+			     (while (re-search-forward "[\"\\]"
+						       fullname-end 1)
+			       (replace-match "\\\\\\&" t))
+			     (insert "\""))))
+		     (insert " <" login ">\n"))
+		    ((eq mail-from-style 'parens)
+		     (insert "From: " login " (")
+		     (let ((fullname-start (point)))
+		       (insert fullname)
+		       (let ((fullname-end (point-marker)))
+			 (goto-char fullname-start)
+			 ;; RFC 822 and its successors say \ and
+			 ;; nonmatching parentheses must be
+			 ;; escaped in comments.
+			 ;; Escape every instance of ()\ ...
+			 (while (re-search-forward "[()\\]" fullname-end 1)
+			   (replace-match "\\\\\\&" t))
+			 ;; ... then undo escaping of matching parentheses,
+			 ;; including matching nested parentheses.
+			 (goto-char fullname-start)
+			 (while (re-search-forward
+				 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
+				 fullname-end 1)
+			   (replace-match "\\1(\\3)" t)
+			   (goto-char fullname-start))))
+		     (insert ")\n"))
+		    ((null mail-from-style)
+		     (insert "From: " login "\n")))))
+	;; Insert a `Message-Id:' field if there isn't one yet.
+	(goto-char (point-min))
+	(unless (re-search-forward "^Message-Id:" delimline t)
+	  (insert "Message-Id: " (message-make-message-id) "\n"))
+	;; Insert a `Date:' field if there isn't one yet.
+	(goto-char (point-min))
+	(unless (re-search-forward "^Date:" delimline t)
+	  (insert "Date: " (message-make-date) "\n"))
+	;; Possibly add a MIME header for the current coding system
+	(let (charset)
+	  (goto-char (point-min))
+	  (and (eq mail-send-nonascii 'mime)
+	       (not (re-search-forward "^MIME-version:" delimline t))
+	       (progn (skip-chars-forward "\0-\177")
+		      (/= (point) (point-max)))
+	       smtpmail-code-conv-from
+	       (setq charset
+		     (coding-system-get smtpmail-code-conv-from
+					'mime-charset))
+	       (goto-char delimline)
+	       (insert "MIME-version: 1.0\n"
+		       "Content-type: text/plain; charset="
+		       (symbol-name charset)
+		       "\nContent-Transfer-Encoding: 8bit\n")))
+	;; Insert an extra newline if we need it to work around
+	;; Sun's bug that swallows newlines.
+	(goto-char (1+ delimline))
+	;; Find and handle any Fcc fields.
+	(goto-char (point-min))
+	(if (re-search-forward "^Fcc:" delimline t)
+	    ;; Force `mail-do-fcc' to use the encoding of the mail
+	    ;; buffer to encode outgoing messages on Fcc files.
+	    (let ((coding-system-for-write
+		   ;; mbox files must have Unix EOLs.
+		   (coding-system-change-eol-conversion
+		    smtpmail-code-conv-from 'unix)))
+	      (mail-do-fcc delimline))))
+      ;; Encode the header according to RFC2047.
+      (mail-encode-header (point-min) delimline)
+      ;;
+      (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*"))
+      (setq smtpmail-recipient-address-list
+            (smtpmail-deduce-address-list tembuf (point-min) delimline))
+      (kill-buffer smtpmail-address-buffer)
+
+      (smtpmail-do-bcc delimline))))
+
+(defun smtpmail-queue-mail (tembuf smtpmail-code-conv-from)
+  (let* ((file-data
+	  (expand-file-name
+	   (format "%s_%i"
+		   (format-time-string "%Y-%m-%d_%H:%M:%S")
+		   (setq smtpmail-queue-counter
+			 (1+ smtpmail-queue-counter)))
+	   smtpmail-queue-dir))
+	 (file-data (convert-standard-filename file-data))
+	 (file-elisp (concat file-data ".el"))
+	 (buffer-data (create-file-buffer file-data)))
+    (unless (file-exists-p smtpmail-queue-dir)
+      (make-directory smtpmail-queue-dir t))
+    (with-current-buffer buffer-data
+      (erase-buffer)
+      (set-buffer-file-coding-system
+       ;; We will be reading the file with no-conversion in
+       ;; smtpmail-send-queued-mail below, so write it out
+       ;; with Unix EOLs.
+       (coding-system-change-eol-conversion
+	(or smtpmail-code-conv-from 'undecided)
+	'unix)
+       nil t)
+      (insert-buffer-substring tembuf)
+      (write-file file-data)
+      (let ((coding-system-for-write 'utf-8))
+        (with-temp-buffer
+          (insert "(setq ")
+          (dolist (var (cons 'smtpmail-recipient-address-list
+                             ;; Perhaps store the server etc.
+                             (and smtpmail-store-queue-variables
+                                  smtpmail--stored-queue-variables)))
+            (insert (format "     %s %S\n" var (symbol-value var))))
+          (insert ")\n")
+          (write-region (point-min) (point-max) file-elisp
+                        nil 'silent)))
+      (write-region (concat file-data "\n") nil
+                    (expand-file-name smtpmail-queue-index-file
+                                      smtpmail-queue-dir)
+                    t 'silent))
+    (kill-buffer buffer-data)))
+
+(defun smtpmail-send-mail (tembuf)
+  (if (not (null smtpmail-recipient-address-list))
+      (when (setq result
+                  (smtpmail-via-smtp
+                   smtpmail-recipient-address-list tembuf))
+        (error "Sending failed: %s"
+               (smtpmail--sanitize-error-message result)))
+    (error "Sending failed; no recipients")))
 
 ;;;###autoload
 (defun smtpmail-send-it ()
-  (let ((errbuf (if mail-interactive
-		    (generate-new-buffer " smtpmail errors")
-		  0))
-	(tembuf (generate-new-buffer " smtpmail temp"))
-	(case-fold-search nil)
-	delimline
-	result
-	(mailbuf (current-buffer))
-        ;; Examine this variable now, so that
-	;; local binding in the mail buffer will take effect.
-	(smtpmail-mail-address
-         (save-restriction
-           ;; Only look at the headers when fetching the
-           ;; envelope address.
-           (message-narrow-to-headers)
-           (or (and mail-specify-envelope-from (mail-envelope-from))
-               (let ((from (mail-fetch-field "from")))
-	         (and from
-		      (cadr (mail-extract-address-components from))))
-	       (smtpmail-user-mail-address))))
-	(smtpmail-code-conv-from
-	 (if enable-multibyte-characters
-	     (let ((sendmail-coding-system smtpmail-code-conv-from))
-	       (select-message-coding-system)))))
+  (let ((tembuf (generate-new-buffer " smtpmail temp")))
     (unwind-protect
-	(with-current-buffer tembuf
-	  (erase-buffer)
-	  ;; Use the same `buffer-file-coding-system' as in the mail
-	  ;; buffer, otherwise any `write-region' invocations (e.g., in
-	  ;; mail-do-fcc below) will annoy with asking for a suitable
-	  ;; encoding.
-	  (set-buffer-file-coding-system smtpmail-code-conv-from nil t)
-	  (insert-buffer-substring mailbuf)
-	  (goto-char (point-max))
-	  ;; require one newline at the end.
-	  (or (= (preceding-char) ?\n)
-	      (insert ?\n))
-	  ;; Change header-delimiter to be what sendmail expects.
-	  (mail-sendmail-undelimit-header)
-	  (setq delimline (point-marker))
-          ;; (sendmail-synch-aliases)
-	  (if mail-aliases
-	      (expand-mail-aliases (point-min) delimline))
-	  (goto-char (point-min))
-	  ;; ignore any blank lines in the header
-	  (while (and (re-search-forward "\n\n\n*" delimline t)
-		      (< (point) delimline))
-	    (replace-match "\n"))
-	  (let ((case-fold-search t))
-	    ;; We used to process Resent-... headers here,
-	    ;; but it was not done properly, and the job
-	    ;; is done correctly in `smtpmail-deduce-address-list'.
-	    ;; Don't send out a blank subject line
-	    (goto-char (point-min))
-	    (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
-		(replace-match "")
-	      ;; This one matches a Subject just before the header delimiter.
-	      (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
-		       (= (match-end 0) delimline))
-		  (replace-match "")))
-	    ;; Put the "From:" field in unless for some odd reason
-	    ;; they put one in themselves.
-	    (goto-char (point-min))
-	    (if (not (re-search-forward "^From:" delimline t))
-		(let* ((login smtpmail-mail-address)
-		       (fullname (user-full-name)))
-		  (cond ((eq mail-from-style 'angles)
-			 (insert "From: " fullname)
-			 (let ((fullname-start (+ (point-min) 6))
-			       (fullname-end (point-marker)))
-			   (goto-char fullname-start)
-			   ;; Look for a character that cannot appear unquoted
-			   ;; according to RFC 822 or its successors.
-			   (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
-						  fullname-end 1)
-			       (progn
-				 ;; Quote fullname, escaping specials.
-				 (goto-char fullname-start)
-				 (insert "\"")
-				 (while (re-search-forward "[\"\\]"
-							   fullname-end 1)
-				   (replace-match "\\\\\\&" t))
-				 (insert "\""))))
-			 (insert " <" login ">\n"))
-			((eq mail-from-style 'parens)
-			 (insert "From: " login " (")
-			 (let ((fullname-start (point)))
-			   (insert fullname)
-			   (let ((fullname-end (point-marker)))
-			     (goto-char fullname-start)
-			     ;; RFC 822 and its successors say \ and
-			     ;; nonmatching parentheses must be
-			     ;; escaped in comments.
-			     ;; Escape every instance of ()\ ...
-			     (while (re-search-forward "[()\\]" fullname-end 1)
-			       (replace-match "\\\\\\&" t))
-			     ;; ... then undo escaping of matching parentheses,
-			     ;; including matching nested parentheses.
-			     (goto-char fullname-start)
-			     (while (re-search-forward
-				     "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
-				     fullname-end 1)
-			       (replace-match "\\1(\\3)" t)
-			       (goto-char fullname-start))))
-			 (insert ")\n"))
-			((null mail-from-style)
-			 (insert "From: " login "\n")))))
-	    ;; Insert a `Message-Id:' field if there isn't one yet.
-	    (goto-char (point-min))
-	    (unless (re-search-forward "^Message-Id:" delimline t)
-	      (insert "Message-Id: " (message-make-message-id) "\n"))
-	    ;; Insert a `Date:' field if there isn't one yet.
-	    (goto-char (point-min))
-	    (unless (re-search-forward "^Date:" delimline t)
-	      (insert "Date: " (message-make-date) "\n"))
-	    ;; Possibly add a MIME header for the current coding system
-	    (let (charset)
-	      (goto-char (point-min))
-	      (and (eq mail-send-nonascii 'mime)
-		   (not (re-search-forward "^MIME-version:" delimline t))
-		   (progn (skip-chars-forward "\0-\177")
-			  (/= (point) (point-max)))
-		   smtpmail-code-conv-from
-		   (setq charset
-			 (coding-system-get smtpmail-code-conv-from
-					    'mime-charset))
-		   (goto-char delimline)
-		   (insert "MIME-version: 1.0\n"
-			   "Content-type: text/plain; charset="
-			   (symbol-name charset)
-			   "\nContent-Transfer-Encoding: 8bit\n")))
-	    ;; Insert an extra newline if we need it to work around
-	    ;; Sun's bug that swallows newlines.
-	    (goto-char (1+ delimline))
-	    ;; Find and handle any Fcc fields.
-	    (goto-char (point-min))
-	    (if (re-search-forward "^Fcc:" delimline t)
-		;; Force `mail-do-fcc' to use the encoding of the mail
-		;; buffer to encode outgoing messages on Fcc files.
-		(let ((coding-system-for-write
-		       ;; mbox files must have Unix EOLs.
-		       (coding-system-change-eol-conversion
-			smtpmail-code-conv-from 'unix)))
-		  (mail-do-fcc delimline)))
-	    (if mail-interactive
-		(with-current-buffer errbuf
-		  (erase-buffer))))
-	  ;; Encode the header according to RFC2047.
-	  (mail-encode-header (point-min) delimline)
-	  ;;
-	  (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*"))
-	  (setq smtpmail-recipient-address-list
-                (smtpmail-deduce-address-list tembuf (point-min) delimline))
-	  (kill-buffer smtpmail-address-buffer)
-
-	  (smtpmail-do-bcc delimline)
-          ;; Send or queue
-	  (if (not smtpmail-queue-mail)
-	      (if (not (null smtpmail-recipient-address-list))
-		  (when (setq result
-			      (smtpmail-via-smtp
-			       smtpmail-recipient-address-list tembuf))
-		    (error "Sending failed: %s"
-                           (smtpmail--sanitize-error-message result)))
-		(error "Sending failed; no recipients"))
-	    (let* ((file-data
-		    (expand-file-name
-		     (format "%s_%i"
-			     (format-time-string "%Y-%m-%d_%H:%M:%S")
-			     (setq smtpmail-queue-counter
-				   (1+ smtpmail-queue-counter)))
-		     smtpmail-queue-dir))
-		   (file-data (convert-standard-filename file-data))
-		   (file-elisp (concat file-data ".el"))
-		   (buffer-data (create-file-buffer file-data)))
-	      (unless (file-exists-p smtpmail-queue-dir)
-		(make-directory smtpmail-queue-dir t))
-	      (with-current-buffer buffer-data
-		(erase-buffer)
-		(set-buffer-file-coding-system
-		 ;; We will be reading the file with no-conversion in
-		 ;; smtpmail-send-queued-mail below, so write it out
-		 ;; with Unix EOLs.
-		 (coding-system-change-eol-conversion
-		  (or smtpmail-code-conv-from 'undecided)
-		  'unix)
-		 nil t)
-		(insert-buffer-substring tembuf)
-		(write-file file-data)
-                (let ((coding-system-for-write 'utf-8))
-                  (with-temp-buffer
-                    (insert "(setq ")
-                    (dolist (var (cons 'smtpmail-recipient-address-list
-                                       ;; Perhaps store the server etc.
-                                       (and smtpmail-store-queue-variables
-                                            smtpmail--stored-queue-variables)))
-                      (insert (format "     %s %S\n" var (symbol-value var))))
-                    (insert ")\n")
-                    (write-region (point-min) (point-max) file-elisp
-                                  nil 'silent)))
-		(write-region (concat file-data "\n") nil
-                              (expand-file-name smtpmail-queue-index-file
-                                                smtpmail-queue-dir)
-                              t 'silent))
-	      (kill-buffer buffer-data))))
-      (kill-buffer tembuf)
-      (if (bufferp errbuf)
-	  (kill-buffer errbuf)))))
+        (let ((smtpmail-code-conv-from
+	       (if enable-multibyte-characters
+	           (let ((sendmail-coding-system smtpmail-code-conv-from))
+	             (select-message-coding-system)))))
+          (smtpmail-prepare-mail tembuf smtpmail-code-conv-from)
+          (if smtpmail-queue-mail
+              (smtpmail-queue-mail tembuf smtpmail-code-conv-from)
+            (smtpmail-send-mail tembuf)))
+      (kill-buffer tembuf))))
 
 ;;;###autoload
 (defun smtpmail-send-queued-mail ()
-- 
2.40.0


--=-=-=
Content-Type: text/plain

-- 
Manuel Giraud

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#63311; Package emacs. Full text available.

Message received at 63311 <at> debbugs.gnu.org:


Received: (at 63311) by debbugs.gnu.org; 6 May 2023 06:19:37 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 06 02:19:37 2023
Received: from localhost ([127.0.0.1]:58056 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pvBGb-0001wk-3b
	for submit <at> debbugs.gnu.org; Sat, 06 May 2023 02:19:37 -0400
Received: from eggs.gnu.org ([209.51.188.92]:58308)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1pvBGY-0001wS-Me
 for 63311 <at> debbugs.gnu.org; Sat, 06 May 2023 02:19:35 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1pvBGT-0000nI-CK; Sat, 06 May 2023 02:19:29 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=/p6mjfozqPsjPkL7lLpvhN8NZUdpVzsFTQ2e6YT17DI=; b=AZkV9mpT4Sio
 qqCw4np9QJxZP7iWU3huv8/Fr1YfxoODJVCUbGof+S8U4umD3rO7Ez5E3HlP70CqR2ESM07cJZ1Po
 H8khxX7bgreQvsqyoA7H0L6ZHhAgXteoY6GcBnLvnMDwdBygckKOumuTQylOy3hdjEQ1934lNqbec
 7OXWd7cLQqFuMOFOfXnsx3A8/Sz4tWAr45OcsLVapExgdtXnCjWtypNY4n+Tm9Ye6qiOxL3oaBKp/
 Cx126o1hfpKWl5ydQbX1iUnZi0Jk4cluSLshtDR4k1NtCCerc5tHtgUCk8bi+uvXyjxYco9PiYGPB
 QyyOsPNoORo4aMoi+imqoQ==;
Received: from [87.69.77.57] (helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1pvBGT-0008Va-0S; Sat, 06 May 2023 02:19:29 -0400
Date: Sat, 06 May 2023 09:20:24 +0300
Message-Id: <83o7mygevr.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Manuel Giraud <manuel@HIDDEN>
In-Reply-To: <874joq34bk.fsf@HIDDEN> (message from Manuel Giraud on
 Fri, 05 May 2023 22:34:39 +0200)
Subject: Re: bug#63311: 30.0.50; [PATCH] smtpmail-send-it split
References: <87jzxmsyyr.fsf@HIDDEN> <83ttwqhahy.fsf@HIDDEN>
 <874joq34bk.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 63311
Cc: 63311 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Manuel Giraud <manuel@HIDDEN>
> Date: Fri, 05 May 2023 22:34:39 +0200
> 
> Eli Zaretskii <eliz@HIDDEN> writes:
> 
> >> Date: Fri, 05 May 2023 15:13:32 +0200
> >> From:  Manuel Giraud via "Bug reports for GNU Emacs,
> >>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> >> 
> >> BTW, does anyone know the purpose of 'errbuf': I see it is created then
> >> erased and then killed?
> >
> > Looks like a left-over from when this function was written.  It is
> > basically a rewrite of sendmail-send-it, which does use that variable.
> 
> Ok.  Do you want me to upgrade this patch removing errbuf?

Sure, that's a good cleanup.

(And please use Reply All, to have this discussion recorded by the
tracker.)




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#63311; Package emacs. Full text available.

Message received at 63311 <at> debbugs.gnu.org:


Received: (at 63311) by debbugs.gnu.org; 5 May 2023 18:56:49 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri May 05 14:56:49 2023
Received: from localhost ([127.0.0.1]:57559 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pv0bo-00044q-UD
	for submit <at> debbugs.gnu.org; Fri, 05 May 2023 14:56:49 -0400
Received: from eggs.gnu.org ([209.51.188.92]:43158)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1pv0bj-00044Z-OA
 for 63311 <at> debbugs.gnu.org; Fri, 05 May 2023 14:56:47 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1pv0be-0003y7-3H; Fri, 05 May 2023 14:56:38 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=3bZAxrR+JSC6NS0Q9HIN+TeqtywoqMZDvu1H3utTcZU=; b=OpK4qd19J/C3
 aLr8Sh6OqwG1CANd/H0dMJQF1Mh1B+Ml9tjFMmykTDY0Qr0ZEcZoV/m520v/871AHbBQJlpAh7OJ8
 UD384xQWFXFS9Yow3N6DrqgAmEuoWoR2XuuR64qLYApdKZy87twNFSS2VqkXSkXgittJUsdvYsD27
 YzrHr1In7y5lJs3moKUeJeYfbSGXMkXAkxJTSg1o51UgTkamDgavbTJXzRW4VyWe+5JjPxibv9oBU
 3oQm2+6ZyltSQAzL48z6gZH66xB4yh1HgSVUUrnElKT3PsML8nUzn4ZtEYF6BffSbQbmYu/DG5p2V
 ENIqEDM+SaIcKubPGEbaaQ==;
Received: from [87.69.77.57] (helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1pv0bc-00070o-OA; Fri, 05 May 2023 14:56:37 -0400
Date: Fri, 05 May 2023 21:57:29 +0300
Message-Id: <83ttwqhahy.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Manuel Giraud <manuel@HIDDEN>
In-Reply-To: <87jzxmsyyr.fsf@HIDDEN> (bug-gnu-emacs@HIDDEN)
Subject: Re: bug#63311: 30.0.50; [PATCH] smtpmail-send-it split
References: <87jzxmsyyr.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 63311
Cc: 63311 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Date: Fri, 05 May 2023 15:13:32 +0200
> From:  Manuel Giraud via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> 
> BTW, does anyone know the purpose of 'errbuf': I see it is created then
> erased and then killed?

Looks like a left-over from when this function was written.  It is
basically a rewrite of sendmail-send-it, which does use that variable.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#63311; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 5 May 2023 15:09:31 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri May 05 11:09:31 2023
Received: from localhost ([127.0.0.1]:57253 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pux3p-0003Lk-W1
	for submit <at> debbugs.gnu.org; Fri, 05 May 2023 11:09:31 -0400
Received: from lists.gnu.org ([209.51.188.17]:45464)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <manuel@HIDDEN>) id 1pux3l-0003LY-Dv
 for submit <at> debbugs.gnu.org; Fri, 05 May 2023 11:09:28 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <manuel@HIDDEN>)
 id 1pux3l-0007wB-8R
 for bug-gnu-emacs@HIDDEN; Fri, 05 May 2023 11:09:25 -0400
Received: from ledu-giraud.fr ([51.159.28.247])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <manuel@HIDDEN>)
 id 1pux3h-0007pg-H7
 for bug-gnu-emacs@HIDDEN; Fri, 05 May 2023 11:09:25 -0400
DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=AfeXw1q/
 JOIEcjJ9DuxJHQJ1tlkfe93aGWYxcvEioeg=; h=date:subject:to:from; 
 d=ledu-giraud.fr;
 b=M/9PkJbF2dkkukgFBUrIP1SuAMOJSQV62v5hawxilWkn9xYpqY
 bZuSNvMrqJsqZ2wcXnlSpxGzGv8BIGsjD9Cw==
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=AfeXw1q/JOIEcjJ9
 DuxJHQJ1tlkfe93aGWYxcvEioeg=; h=date:subject:to:from;
 d=ledu-giraud.fr; b=ntRD5YdVDoSjwa/8BtCmr3KQBhoK30HkciCzsjfuXcn2Ls2PQD
 vuCgUbdh4EvFcfUi6izJP6hbhisAT+kZhp7rCDXQngrEigK9c1UH9BWjfjE1ZO06doQBcV
 MLCCLWJ9WPH2bVyo4tEp4JPfNKgSsrGp/OHak4mvoWe5ZQ8cHDGzNFf90B1zy7/50yN0lo
 OvlvKPR3Uy5VM+lPtXTrHLw6hd9B3dx9Zp/TQf/jBW59GjrsgavJr5mmHTdjOxpB74iY0i
 o1ewd6X3AGjv0xTfjF/okuUB/lfF8kv08Gmv5r0fr3M+Rhtjcld0P7cUtkY/wepRIUgE/Y
 9TBz0XR5fZHw==
Received: from computer (<unknown> [10.1.1.1])
 by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id ba6276bf
 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); 
 Fri, 5 May 2023 17:09:17 +0200 (CEST)
From: Manuel Giraud <manuel@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 30.0.50; [PATCH] smtpmail-send-it split
Date: Fri, 05 May 2023 15:13:32 +0200
Message-ID: <87jzxmsyyr.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=51.159.28.247; envelope-from=manuel@HIDDEN;
 helo=ledu-giraud.fr
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.4 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.4 (--)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable


Hi,

I'm trying to make sending mail over SMTP asynchronous.  For this, I'm
working on 'smtpmail-send-it'=E2=80=A6 but I think that that function does =
too
much and is hard to reason about.

This patch just splits 'smtpmail-send-it' work into three functions:
prepare a mail and queue it or send it.  There should be no change in
functionality (it is mostly code refactoring).  I've tested it a bit
with sending and queueing and this seems to work correctly but this
needs way more eyes and tests.

BTW, does anyone know the purpose of 'errbuf': I see it is created then
erased and then killed?


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=0001-smtpmail-send-it-split.patch

From 6481038443deae8bf4e309a641f5ce77717be712 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@HIDDEN>
Date: Fri, 5 May 2023 14:35:01 +0200
Subject: [PATCH] smtpmail-send-it split

* lisp/mail/smtpmail.el (smtpmail-prepare-mail): New function that
prepares the mail with current buffer content.
(smtpmail-queue-mail): New function to queue a mail (prepared by
'smtpmail-prepare-mail').
(smtpmail-send-mail): New function to send a mail (prepared by
'smtpmail-send-mail').
(smtpmail-send-it): Use all three previous functions.
---
 lisp/mail/smtpmail.el | 407 +++++++++++++++++++++---------------------
 1 file changed, 206 insertions(+), 201 deletions(-)

diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
index 78688d170cc..7c61ca29de6 100644
--- a/lisp/mail/smtpmail.el
+++ b/lisp/mail/smtpmail.el
@@ -205,214 +205,219 @@ smtpmail-mail-address
   "Value to use for envelope-from address for mail from ambient buffer.")
 
 ;;; Functions
+(defun smtpmail-prepare-mail (tembuf errbuf smtpmail-code-conv-from)
+    (let ((case-fold-search nil)
+	  delimline
+	  (mailbuf (current-buffer))
+         ;; Examine this variable now, so that
+	 ;; local binding in the mail buffer will take effect.
+	 (smtpmail-mail-address
+          (save-restriction
+            ;; Only look at the headers when fetching the
+            ;; envelope address.
+            (message-narrow-to-headers)
+            (or (and mail-specify-envelope-from (mail-envelope-from))
+                (let ((from (mail-fetch-field "from")))
+	          (and from
+		       (cadr (mail-extract-address-components from))))
+	        (smtpmail-user-mail-address)))))
+    (with-current-buffer tembuf
+      (erase-buffer)
+      ;; Use the same `buffer-file-coding-system' as in the mail
+      ;; buffer, otherwise any `write-region' invocations (e.g., in
+      ;; mail-do-fcc below) will annoy with asking for a suitable
+      ;; encoding.
+      (set-buffer-file-coding-system smtpmail-code-conv-from nil t)
+      (insert-buffer-substring mailbuf)
+      (goto-char (point-max))
+      ;; require one newline at the end.
+      (or (= (preceding-char) ?\n)
+	  (insert ?\n))
+      ;; Change header-delimiter to be what sendmail expects.
+      (mail-sendmail-undelimit-header)
+      (setq delimline (point-marker))
+      (if mail-aliases
+	  (expand-mail-aliases (point-min) delimline))
+      (goto-char (point-min))
+      ;; ignore any blank lines in the header
+      (while (and (re-search-forward "\n\n\n*" delimline t)
+		  (< (point) delimline))
+	(replace-match "\n"))
+      (let ((case-fold-search t))
+	;; We used to process Resent-... headers here,
+	;; but it was not done properly, and the job
+	;; is done correctly in `smtpmail-deduce-address-list'.
+	;; Don't send out a blank subject line
+	(goto-char (point-min))
+	(if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
+	    (replace-match "")
+	  ;; This one matches a Subject just before the header delimiter.
+	  (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
+		   (= (match-end 0) delimline))
+	      (replace-match "")))
+	;; Put the "From:" field in unless for some odd reason
+	;; they put one in themselves.
+	(goto-char (point-min))
+	(if (not (re-search-forward "^From:" delimline t))
+	    (let* ((login smtpmail-mail-address)
+		   (fullname (user-full-name)))
+	      (cond ((eq mail-from-style 'angles)
+		     (insert "From: " fullname)
+		     (let ((fullname-start (+ (point-min) 6))
+			   (fullname-end (point-marker)))
+		       (goto-char fullname-start)
+		       ;; Look for a character that cannot appear unquoted
+		       ;; according to RFC 822 or its successors.
+		       (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
+					      fullname-end 1)
+			   (progn
+			     ;; Quote fullname, escaping specials.
+			     (goto-char fullname-start)
+			     (insert "\"")
+			     (while (re-search-forward "[\"\\]"
+						       fullname-end 1)
+			       (replace-match "\\\\\\&" t))
+			     (insert "\""))))
+		     (insert " <" login ">\n"))
+		    ((eq mail-from-style 'parens)
+		     (insert "From: " login " (")
+		     (let ((fullname-start (point)))
+		       (insert fullname)
+		       (let ((fullname-end (point-marker)))
+			 (goto-char fullname-start)
+			 ;; RFC 822 and its successors say \ and
+			 ;; nonmatching parentheses must be
+			 ;; escaped in comments.
+			 ;; Escape every instance of ()\ ...
+			 (while (re-search-forward "[()\\]" fullname-end 1)
+			   (replace-match "\\\\\\&" t))
+			 ;; ... then undo escaping of matching parentheses,
+			 ;; including matching nested parentheses.
+			 (goto-char fullname-start)
+			 (while (re-search-forward
+				 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
+				 fullname-end 1)
+			   (replace-match "\\1(\\3)" t)
+			   (goto-char fullname-start))))
+		     (insert ")\n"))
+		    ((null mail-from-style)
+		     (insert "From: " login "\n")))))
+	;; Insert a `Message-Id:' field if there isn't one yet.
+	(goto-char (point-min))
+	(unless (re-search-forward "^Message-Id:" delimline t)
+	  (insert "Message-Id: " (message-make-message-id) "\n"))
+	;; Insert a `Date:' field if there isn't one yet.
+	(goto-char (point-min))
+	(unless (re-search-forward "^Date:" delimline t)
+	  (insert "Date: " (message-make-date) "\n"))
+	;; Possibly add a MIME header for the current coding system
+	(let (charset)
+	  (goto-char (point-min))
+	  (and (eq mail-send-nonascii 'mime)
+	       (not (re-search-forward "^MIME-version:" delimline t))
+	       (progn (skip-chars-forward "\0-\177")
+		      (/= (point) (point-max)))
+	       smtpmail-code-conv-from
+	       (setq charset
+		     (coding-system-get smtpmail-code-conv-from
+					'mime-charset))
+	       (goto-char delimline)
+	       (insert "MIME-version: 1.0\n"
+		       "Content-type: text/plain; charset="
+		       (symbol-name charset)
+		       "\nContent-Transfer-Encoding: 8bit\n")))
+	;; Insert an extra newline if we need it to work around
+	;; Sun's bug that swallows newlines.
+	(goto-char (1+ delimline))
+	;; Find and handle any Fcc fields.
+	(goto-char (point-min))
+	(if (re-search-forward "^Fcc:" delimline t)
+	    ;; Force `mail-do-fcc' to use the encoding of the mail
+	    ;; buffer to encode outgoing messages on Fcc files.
+	    (let ((coding-system-for-write
+		   ;; mbox files must have Unix EOLs.
+		   (coding-system-change-eol-conversion
+		    smtpmail-code-conv-from 'unix)))
+	      (mail-do-fcc delimline)))
+	(if mail-interactive
+	    (with-current-buffer errbuf
+	      (erase-buffer))))
+      ;; Encode the header according to RFC2047.
+      (mail-encode-header (point-min) delimline)
+      ;;
+      (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*"))
+      (setq smtpmail-recipient-address-list
+            (smtpmail-deduce-address-list tembuf (point-min) delimline))
+      (kill-buffer smtpmail-address-buffer)
+
+      (smtpmail-do-bcc delimline))))
+
+(defun smtpmail-queue-mail (tembuf smtpmail-code-conv-from)
+  (let* ((file-data
+	  (expand-file-name
+	   (format "%s_%i"
+		   (format-time-string "%Y-%m-%d_%H:%M:%S")
+		   (setq smtpmail-queue-counter
+			 (1+ smtpmail-queue-counter)))
+	   smtpmail-queue-dir))
+	 (file-data (convert-standard-filename file-data))
+	 (file-elisp (concat file-data ".el"))
+	 (buffer-data (create-file-buffer file-data)))
+    (unless (file-exists-p smtpmail-queue-dir)
+      (make-directory smtpmail-queue-dir t))
+    (with-current-buffer buffer-data
+      (erase-buffer)
+      (set-buffer-file-coding-system
+       ;; We will be reading the file with no-conversion in
+       ;; smtpmail-send-queued-mail below, so write it out
+       ;; with Unix EOLs.
+       (coding-system-change-eol-conversion
+	(or smtpmail-code-conv-from 'undecided)
+	'unix)
+       nil t)
+      (insert-buffer-substring tembuf)
+      (write-file file-data)
+      (let ((coding-system-for-write 'utf-8))
+        (with-temp-buffer
+          (insert "(setq ")
+          (dolist (var (cons 'smtpmail-recipient-address-list
+                             ;; Perhaps store the server etc.
+                             (and smtpmail-store-queue-variables
+                                  smtpmail--stored-queue-variables)))
+            (insert (format "     %s %S\n" var (symbol-value var))))
+          (insert ")\n")
+          (write-region (point-min) (point-max) file-elisp
+                        nil 'silent)))
+      (write-region (concat file-data "\n") nil
+                    (expand-file-name smtpmail-queue-index-file
+                                      smtpmail-queue-dir)
+                    t 'silent))
+    (kill-buffer buffer-data)))
+
+(defun smtpmail-send-mail (tembuf)
+  (if (not (null smtpmail-recipient-address-list))
+      (when (setq result
+                  (smtpmail-via-smtp
+                   smtpmail-recipient-address-list tembuf))
+        (error "Sending failed: %s"
+               (smtpmail--sanitize-error-message result)))
+    (error "Sending failed; no recipients")))
 
 ;;;###autoload
 (defun smtpmail-send-it ()
   (let ((errbuf (if mail-interactive
 		    (generate-new-buffer " smtpmail errors")
 		  0))
-	(tembuf (generate-new-buffer " smtpmail temp"))
-	(case-fold-search nil)
-	delimline
-	result
-	(mailbuf (current-buffer))
-        ;; Examine this variable now, so that
-	;; local binding in the mail buffer will take effect.
-	(smtpmail-mail-address
-         (save-restriction
-           ;; Only look at the headers when fetching the
-           ;; envelope address.
-           (message-narrow-to-headers)
-           (or (and mail-specify-envelope-from (mail-envelope-from))
-               (let ((from (mail-fetch-field "from")))
-	         (and from
-		      (cadr (mail-extract-address-components from))))
-	       (smtpmail-user-mail-address))))
-	(smtpmail-code-conv-from
-	 (if enable-multibyte-characters
-	     (let ((sendmail-coding-system smtpmail-code-conv-from))
-	       (select-message-coding-system)))))
+        (tembuf (generate-new-buffer " smtpmail temp")))
     (unwind-protect
-	(with-current-buffer tembuf
-	  (erase-buffer)
-	  ;; Use the same `buffer-file-coding-system' as in the mail
-	  ;; buffer, otherwise any `write-region' invocations (e.g., in
-	  ;; mail-do-fcc below) will annoy with asking for a suitable
-	  ;; encoding.
-	  (set-buffer-file-coding-system smtpmail-code-conv-from nil t)
-	  (insert-buffer-substring mailbuf)
-	  (goto-char (point-max))
-	  ;; require one newline at the end.
-	  (or (= (preceding-char) ?\n)
-	      (insert ?\n))
-	  ;; Change header-delimiter to be what sendmail expects.
-	  (mail-sendmail-undelimit-header)
-	  (setq delimline (point-marker))
-          ;; (sendmail-synch-aliases)
-	  (if mail-aliases
-	      (expand-mail-aliases (point-min) delimline))
-	  (goto-char (point-min))
-	  ;; ignore any blank lines in the header
-	  (while (and (re-search-forward "\n\n\n*" delimline t)
-		      (< (point) delimline))
-	    (replace-match "\n"))
-	  (let ((case-fold-search t))
-	    ;; We used to process Resent-... headers here,
-	    ;; but it was not done properly, and the job
-	    ;; is done correctly in `smtpmail-deduce-address-list'.
-	    ;; Don't send out a blank subject line
-	    (goto-char (point-min))
-	    (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
-		(replace-match "")
-	      ;; This one matches a Subject just before the header delimiter.
-	      (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
-		       (= (match-end 0) delimline))
-		  (replace-match "")))
-	    ;; Put the "From:" field in unless for some odd reason
-	    ;; they put one in themselves.
-	    (goto-char (point-min))
-	    (if (not (re-search-forward "^From:" delimline t))
-		(let* ((login smtpmail-mail-address)
-		       (fullname (user-full-name)))
-		  (cond ((eq mail-from-style 'angles)
-			 (insert "From: " fullname)
-			 (let ((fullname-start (+ (point-min) 6))
-			       (fullname-end (point-marker)))
-			   (goto-char fullname-start)
-			   ;; Look for a character that cannot appear unquoted
-			   ;; according to RFC 822 or its successors.
-			   (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
-						  fullname-end 1)
-			       (progn
-				 ;; Quote fullname, escaping specials.
-				 (goto-char fullname-start)
-				 (insert "\"")
-				 (while (re-search-forward "[\"\\]"
-							   fullname-end 1)
-				   (replace-match "\\\\\\&" t))
-				 (insert "\""))))
-			 (insert " <" login ">\n"))
-			((eq mail-from-style 'parens)
-			 (insert "From: " login " (")
-			 (let ((fullname-start (point)))
-			   (insert fullname)
-			   (let ((fullname-end (point-marker)))
-			     (goto-char fullname-start)
-			     ;; RFC 822 and its successors say \ and
-			     ;; nonmatching parentheses must be
-			     ;; escaped in comments.
-			     ;; Escape every instance of ()\ ...
-			     (while (re-search-forward "[()\\]" fullname-end 1)
-			       (replace-match "\\\\\\&" t))
-			     ;; ... then undo escaping of matching parentheses,
-			     ;; including matching nested parentheses.
-			     (goto-char fullname-start)
-			     (while (re-search-forward
-				     "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
-				     fullname-end 1)
-			       (replace-match "\\1(\\3)" t)
-			       (goto-char fullname-start))))
-			 (insert ")\n"))
-			((null mail-from-style)
-			 (insert "From: " login "\n")))))
-	    ;; Insert a `Message-Id:' field if there isn't one yet.
-	    (goto-char (point-min))
-	    (unless (re-search-forward "^Message-Id:" delimline t)
-	      (insert "Message-Id: " (message-make-message-id) "\n"))
-	    ;; Insert a `Date:' field if there isn't one yet.
-	    (goto-char (point-min))
-	    (unless (re-search-forward "^Date:" delimline t)
-	      (insert "Date: " (message-make-date) "\n"))
-	    ;; Possibly add a MIME header for the current coding system
-	    (let (charset)
-	      (goto-char (point-min))
-	      (and (eq mail-send-nonascii 'mime)
-		   (not (re-search-forward "^MIME-version:" delimline t))
-		   (progn (skip-chars-forward "\0-\177")
-			  (/= (point) (point-max)))
-		   smtpmail-code-conv-from
-		   (setq charset
-			 (coding-system-get smtpmail-code-conv-from
-					    'mime-charset))
-		   (goto-char delimline)
-		   (insert "MIME-version: 1.0\n"
-			   "Content-type: text/plain; charset="
-			   (symbol-name charset)
-			   "\nContent-Transfer-Encoding: 8bit\n")))
-	    ;; Insert an extra newline if we need it to work around
-	    ;; Sun's bug that swallows newlines.
-	    (goto-char (1+ delimline))
-	    ;; Find and handle any Fcc fields.
-	    (goto-char (point-min))
-	    (if (re-search-forward "^Fcc:" delimline t)
-		;; Force `mail-do-fcc' to use the encoding of the mail
-		;; buffer to encode outgoing messages on Fcc files.
-		(let ((coding-system-for-write
-		       ;; mbox files must have Unix EOLs.
-		       (coding-system-change-eol-conversion
-			smtpmail-code-conv-from 'unix)))
-		  (mail-do-fcc delimline)))
-	    (if mail-interactive
-		(with-current-buffer errbuf
-		  (erase-buffer))))
-	  ;; Encode the header according to RFC2047.
-	  (mail-encode-header (point-min) delimline)
-	  ;;
-	  (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*"))
-	  (setq smtpmail-recipient-address-list
-                (smtpmail-deduce-address-list tembuf (point-min) delimline))
-	  (kill-buffer smtpmail-address-buffer)
-
-	  (smtpmail-do-bcc delimline)
-          ;; Send or queue
-	  (if (not smtpmail-queue-mail)
-	      (if (not (null smtpmail-recipient-address-list))
-		  (when (setq result
-			      (smtpmail-via-smtp
-			       smtpmail-recipient-address-list tembuf))
-		    (error "Sending failed: %s"
-                           (smtpmail--sanitize-error-message result)))
-		(error "Sending failed; no recipients"))
-	    (let* ((file-data
-		    (expand-file-name
-		     (format "%s_%i"
-			     (format-time-string "%Y-%m-%d_%H:%M:%S")
-			     (setq smtpmail-queue-counter
-				   (1+ smtpmail-queue-counter)))
-		     smtpmail-queue-dir))
-		   (file-data (convert-standard-filename file-data))
-		   (file-elisp (concat file-data ".el"))
-		   (buffer-data (create-file-buffer file-data)))
-	      (unless (file-exists-p smtpmail-queue-dir)
-		(make-directory smtpmail-queue-dir t))
-	      (with-current-buffer buffer-data
-		(erase-buffer)
-		(set-buffer-file-coding-system
-		 ;; We will be reading the file with no-conversion in
-		 ;; smtpmail-send-queued-mail below, so write it out
-		 ;; with Unix EOLs.
-		 (coding-system-change-eol-conversion
-		  (or smtpmail-code-conv-from 'undecided)
-		  'unix)
-		 nil t)
-		(insert-buffer-substring tembuf)
-		(write-file file-data)
-                (let ((coding-system-for-write 'utf-8))
-                  (with-temp-buffer
-                    (insert "(setq ")
-                    (dolist (var (cons 'smtpmail-recipient-address-list
-                                       ;; Perhaps store the server etc.
-                                       (and smtpmail-store-queue-variables
-                                            smtpmail--stored-queue-variables)))
-                      (insert (format "     %s %S\n" var (symbol-value var))))
-                    (insert ")\n")
-                    (write-region (point-min) (point-max) file-elisp
-                                  nil 'silent)))
-		(write-region (concat file-data "\n") nil
-                              (expand-file-name smtpmail-queue-index-file
-                                                smtpmail-queue-dir)
-                              t 'silent))
-	      (kill-buffer buffer-data))))
+        (let ((smtpmail-code-conv-from
+	       (if enable-multibyte-characters
+	           (let ((sendmail-coding-system smtpmail-code-conv-from))
+	             (select-message-coding-system)))))
+          (smtpmail-prepare-mail tembuf errbuf smtpmail-code-conv-from)
+          (if smtpmail-queue-mail
+              (smtpmail-queue-mail tembuf smtpmail-code-conv-from)
+            (smtpmail-send-mail tembuf)))
       (kill-buffer tembuf)
       (if (bufferp errbuf)
 	  (kill-buffer errbuf)))))
-- 
2.40.0


--=-=-=
Content-Type: text/plain



In GNU Emacs 30.0.50 (build 1, x86_64-unknown-openbsd7.3, cairo version
 1.17.8) of 2023-05-05 built on computer
Repository revision: f204c4a6cfa77fdbb2573b728110576e206b0b20
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101006
System Description: OpenBSD computer 7.3 GENERIC.MP#1125 amd64

Configured using:
 'configure --prefix=/home/manuel/emacs --bindir=/home/manuel/bin
 --with-x-toolkit=no --without-sound --without-compress-install
 CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBOTF LIBXML2 MODULES NOTIFY KQUEUE OLDXMENU PDUMPER PNG RSVG
SQLITE3 THREADS TIFF TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM ZLIB

Important settings:
  value of $LC_ALL: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Magit

Minor modes in effect:
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  display-time-mode: t
  display-battery-mode: t
  server-mode: t
  shell-dirtrack-mode: t
  override-global-mode: t
  repeat-mode: t
  desktop-save-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/manuel/.emacs.d/elpa/ef-themes-0.11.0/theme-loaddefs hides /home/manuel/emacs/share/emacs/30.0.50/lisp/theme-loaddefs
/home/manuel/.emacs.d/elpa/transient-0.3.7/transient hides /home/manuel/emacs/share/emacs/30.0.50/lisp/transient

Features:
(shadow goto-addr dabbrev emacsbug whitespace magit-patch misearch
multi-isearch magit-extras face-remap magit-submodule magit-obsolete
magit-blame magit-stash magit-reflog magit-bisect magit-push magit-pull
magit-fetch magit-clone magit-remote magit-commit magit-sequence
magit-notes magit-worktree magit-tag magit-merge magit-branch
magit-reset magit-files magit-refs magit-status magit magit-repos
magit-apply magit-wip magit-log which-func imenu magit-diff smerge-mode
diff git-commit log-edit add-log magit-core magit-autorevert
magit-margin magit-transient magit-process with-editor magit-mode
transient magit-git magit-section magit-utils dash shr-color gnus-cite
gnus-async gnus-bcklg gnus-ml gnus-topic mm-archive url-cache qp utf-7
imap rfc2104 nndoc nndraft nnmh nnfolder nnml gnus-agent gnus-srvr
gnus-score score-mode nnvirtual nntp gnus-cache nnrss mm-url
network-stream mailalias textsec uni-scripts idna-mapping ucs-normalize
uni-confusable textsec-check sort mail-extr pulse tabify cus-edit
cus-start cl-print smtpmail help-fns radix-tree vc-bzr vc-src vc-sccs
vc-cvs vc-rcs log-view pcvs-util sh-script smie treesit executable vc-hg
conf-mode view pascal vc mule-util hi-lock autorevert filenotify vc-git
diff-mode vc-dispatcher vc-svn bug-reference paredit gnus-dired time
battery cus-load exwm-randr xcb-randr exwm-config ido exwm exwm-input
xcb-keysyms xcb-xkb exwm-manage exwm-floating xcb-cursor xcb-render
exwm-layout exwm-workspace exwm-core xcb-ewmh xcb-icccm xcb xcb-xproto
xcb-types xcb-debug server modus-operandi-theme modus-themes zone
speed-type url-http url-auth url-gw nsm compat ytdious mingus libmpdee
reporter edebug debug backtrace transmission color calc-bin calc-ext
calc calc-loaddefs rect calc-macs supercite regi ebdb-message ebdb-gnus
gnus-msg gnus-art mm-uu mml2015 mm-view mml-smime smime gnutls dig
gnus-sum shr pixel-fill kinsoku url-file svg dom gnus-group gnus-undo
gnus-start gnus-dbus gnus-cloud nnimap nnmail mail-source utf7 nnoo
gnus-spec gnus-int gnus-range message sendmail yank-media puny rfc822
mml mml-sec epa epg rfc6068 epg-config mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 ietf-drums gmm-utils mailheader
gnus-win gnus nnheader gnus-util mail-utils range mm-util mail-prsvr
wid-edit ebdb-mua ebdb-com crm ebdb-format ebdb mailabbrev eieio-opt
speedbar ezimage dframe find-func eieio-base pcase timezone
visual-basic-mode cl web-mode derived disp-table erlang-start
smart-tabs-mode skeleton cc-mode cc-fonts cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs slime-asdf grep slime-tramp
tramp rx tramp-loaddefs trampver tramp-integration files-x tramp-compat
xdg shell pcomplete parse-time iso8601 time-date ls-lisp format-spec
slime-fancy slime-indentation slime-cl-indent cl-indent
slime-trace-dialog slime-fontifying-fu slime-package-fu slime-references
slime-compiler-notes-tree advice slime-scratch slime-presentations
bridge slime-macrostep macrostep slime-mdot-fu slime-enclosing-context
slime-fuzzy slime-fancy-trace slime-fancy-inspector slime-c-p-c
slime-editing-commands slime-autodoc slime-repl slime-parse slime
apropos compile text-property-search etags fileloop generator xref
project arc-mode archive-mode noutline outline icons pp comint ansi-osc
ansi-color ring hyperspec thingatpt slime-autoloads edmacro kmacro
use-package-bind-key bind-key appt diary-lib diary-loaddefs cal-menu
calendar cal-loaddefs dired-x dired-aux dired dired-loaddefs
notifications dbus xml cl-extra help-mode use-package-core repeat
easy-mmode desktop frameset rust-mode-autoloads speed-type-autoloads
osm-autoloads ebdb-autoloads compat-autoloads magit-autoloads
debbugs-autoloads git-commit-autoloads magit-section-autoloads
ef-themes-autoloads with-editor-autoloads paredit-autoloads
dash-autoloads ytdious-autoloads transmission-autoloads
transient-autoloads exwm-autoloads hyperbole-autoloads
detached-autoloads info package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie generate-lisp-file
url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs password-cache json subr-x map byte-opt gv
bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind kqueue lcms2
dynamic-setting system-font-setting font-render-setting cairo xinput2 x
multi-tty make-network-process emacs)

Memory information:
((conses 16 933133 308956)
 (symbols 48 55180 35)
 (strings 32 272198 12320)
 (string-bytes 1 8555283)
 (vectors 16 173055)
 (vector-slots 8 2925695 155806)
 (floats 8 544 5262)
 (intervals 56 18111 2469)
 (buffers 984 113))

-- 
Manuel Giraud

--=-=-=--




Acknowledgement sent to Manuel Giraud <manuel@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#63311; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 11 May 2023 21:15:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.