Subject: Re: bug#75628: 31.0.50; Error sending mail using SMTP - base64 encoding fails

From: Ingo Brunberg <[email-masked]>
Date: Fri, 17 Jan 2025 16:51:15 +0100

Hello Robert,

yes, your patch does indeed fix the issue. I also guess there are more
places which need that treatment. Glad, it works for me again.

Thanks
Ingo

Robert Pluim <[email-masked]> writes:

>>>>>> On Fri, 17 Jan 2025 10:18:52 +0000, Ingo Brunberg via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email-masked]> said:
>
>     Ingo> When I try to send mail with emacs using SMTP, I get error "Multibyte character
>     Ingo> in data for base64 encoding".
>
>     Ingo> In the current code I have narrowed it down to line 637 in smtpmail.el, where an
>     Ingo> attempt is made to base64 encode a string containing the password which, of
>     Ingo> course, can contain multibyte characters.
>
>     Ingo> With a simple password some time ago, I could send mail.
>
> Does this fix it? I guess at least "AUTH LOGIN" needs similar
> treatment, and probably "AUTH CRAM-MD5". I donʼt think XOAUTH2 needs
> it, but Iʼll check.
>
> diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
> index 6cb576fe72b..5aebbec14d0 100644
> --- a/lisp/mail/smtpmail.el
> +++ b/lisp/mail/smtpmail.el
> @@ -631,11 +631,12 @@ smtpmail-try-auth-method
>    ;; violate a SHOULD in RFC 2222 paragraph 5.1.  Note that this
>    ;; is not sent if the server did not advertise AUTH PLAIN in
>    ;; the EHLO response.  See RFC 2554 for more info.
> +  (let ((password (encode-coding-string password 'utf-8)))
>    (smtpmail-command-or-throw
>     process
>     (concat "AUTH PLAIN "
>  	   (base64-encode-string (concat "\0" user "\0" password) t))
> -   235))
> +   235)))
>  
>  (cl-defmethod smtpmail-try-auth-method
>    (process (_mech (eql 'xoauth2)) user password)
>
>
>
>
>
>
> Robert