Subject: Re: bug#38200: 26.2; sendmail.el needlessly munging headers by inserting backslashes

From: Lars Ingebrigtsen <[email-masked]>
Date: Thu, 14 Nov 2019 05:59:37 +0100

Ed Sabol <[email-masked]> writes:

> 1. Evaluate the following:
> (setq mail-user-agent 'sendmail-user-agent)
> (setq send-mail-function 'sendmail-send-it)

[...]

> "LastName\, FirstName I. \(CODE-999.9\)\[CONTRACTING COMPANY INC\]"
>         <[email-masked]>
>
> It should like like this:
>
> "LastName, FirstName I. (CODE-999.9)[CONTRACTING COMPANY INC]"
>         <[email-masked]>

This isn't due to sendmail or anything, but because

(defcustom rfc2047-header-encoding-alist

[...]

    ("\\(Resent-\\)?\\(From\\|Cc\\|To\\|Bcc\\|\\(In-\\)?Reply-To\\|Sender\
\\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\)" . address-mime)

and

		    (when (eq method 'address-mime)
		      (rfc2047-quote-special-characters-in-quoted-strings))

> At some point, something in sendmail.el changed between Emacs version
> 21.2 and 26.2 that resulted in these backslashes being
> added. According to RFC822 and other email standards, these
> backslashes are not needed. Emacs should not be modifying the headers
> of emails needlessly.

I've been perusing the relevant RFCs, but I can't find anything about
having to quote commas and parentheses in quoted-strings.  It's not
disallowed, either -- the RFC says

3.2.1.  Quoted characters

   Some characters are reserved for special interpretation, such as
   delimiting lexical tokens.  To permit use of these characters as
   uninterpreted data, a quoting mechanism is provided.

   quoted-pair     =   ("\" (VCHAR / WSP)) / obs-qp

   Where any quoted-pair appears, it is to be interpreted as the
   character alone.  That is to say, the "\" character that appears as
   part of a quoted-pair is semantically "invisible".

so you can put a backslash in anywhere you want, basically, and it
should make no semantic difference.

But I'm not sure why this was added (in 2006).  Perhaps some MTAs/MUAs
react negatively to having those characters unquoted in strings?  It
looks like this was added by Katsumi, but the changelog doesn't say what
problem it's trying to fix.

Katsumi, do you remember?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no