Subject: Re: bug#68686: [Bug] smtpmail-send-queued-mail ignores some headers of the message it's sending!

From: [email-masked]
Date: Sat, 27 Jan 2024 01:09:19 +0000

On 26.01.2024 16:37, Manuel Giraud wrote:
> 
>> Please do, because 29.2 is not packaged for guix, so I don't know how
>> to install it. Otherwise I would test myself with 29.2...
> 
> Hi,
> 
> So I did the following test on 29.1 (built from source from the
> emacs-29.1 branch):
> 
>       - emacs -Q
>       - M-: (setq send-mail-function 'smtpmail-send-it
>                   smtpmail-queue-mail t
>                   smtpmail-smtp-server "ledu-giraud.fr")
>       - M-: (compose-mail)
>       [ manually change "To:" and "From:" to [email-masked] ]
>       - C-c C-c
>       - M-: (smtpmail-send-queued-mail)
> 
> And this mail is correctly delivered.  The only trace left of the local
> hostname is in "Message-ID:" which was set to
> <[email-masked]>
> 
> So, I cannot see evidence of a bug in Emacs here.

Ok I think I solved the conundrum! It has to do with the "envelope 
 From", and I think the reason why you can't reproduce the error is 
because your smtp server allows envelope-from which are different from 
the From: header (and my smtp server doesn't). So you don't _see_ the 
bug. Let's keep start emacs -Q and let's set the parameters we 
discussed.

For some reason, the envelope-from when sending via 
smtpmail-send-queued-mail is assigned to the value of user-mail-address 
(which for me was user@fedora) independently of the From: header. But 
with "immediate sending" this doesn't happen (I wonder if it's assigned 
to the same value as the header, or is not assigned at all and the smtp 
server assigns it? I don't know much about how these protocols work). In 
fact, if I just set a valid email for user-mail-address, then I get a 
different error, that is "envelope-from mismatches the From: header". 
Now, I could solve it by fiddling with

'(mail-envelope-from 'header)
'(mail-specify-envelope-from t)

and at this point I can send queued email, but this is really a fishy 
business and this fact that the value assigned to envelope-from changes 
between using "immediate sending" and queued-sending I think is the real 
core of the bug. Because I don't want the envelopes which I prescribed 
above to insert a header X-Authentication-Warning in my message, then I 
set '(message-sendmail-f-is-evil t), and looking at the description of 
this variable I discover it mentions bug#36937 which is very similar to 
the strange behaviour I described.

I will try to explore, with more calm and over the next few weeks, what 
is going on. But this is really a fishy business!