~rjarry/aerc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH aerc v2] compose,viewer: do not always wrap people names in quotes

Details
Message ID
<20240311204806.146091-3-robin@jarry.cc>
DKIM signature
pass
Download raw message
Patch: +6 -8
Currently, names of recipients in From, To, Cc and Bcc headers are
(almost) always wrapped in quotes. Even if they are pure ASCII and
contain one upper case letter. E.g.:

	From: "Foo" <foo@baz.org>

There is no valid reason to add these quotes unless the name contains
special characters as specified by RFC 5322, section 3.2.3:

   specials        =   "(" / ")" /        ; Special characters that do
                       "<" / ">" /        ;  not appear in atext
                       "[" / "]" /
                       ":" / ";" /
                       "@" / "\" /
                       "," / "." /
                       DQUOTE

Adapt the check accordingly.

Link: https://datatracker.ietf.org/doc/html/rfc5322#section-3.2.3
Signed-off-by: Robin Jarry <robin@jarry.cc>
---

Notes:
    v2:
    
    - Fixed comment (bandali).
    - Updated the list of characters that require quoting according to
      RFC 5322 (Matěj).

 lib/format/format.go | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/lib/format/format.go b/lib/format/format.go
index a8600009443a..430abf75392c 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -2,7 +2,6 @@ package format

import (
	"fmt"
	"regexp"
	"strings"
	"time"
	"unicode"
@@ -10,24 +9,23 @@ import (
	"github.com/emersion/go-message/mail"
)

// AddressForHumans formats the address. If the address's name
// contains non-ASCII characters it will be quoted but not encoded.
const rfc5322specials string = `()<>[]:;@\,."`

// AddressForHumans formats the address.
// Meant for display purposes to the humans, not for sending over the wire.
func AddressForHumans(a *mail.Address) string {
	if a.Name != "" {
		if atom.MatchString(a.Name) {
			return fmt.Sprintf("%s <%s>", a.Name, a.Address)
		} else {
		if strings.ContainsAny(a.Name, rfc5322specials) {
			return fmt.Sprintf("\"%s\" <%s>",
				strings.ReplaceAll(a.Name, "\"", "'"), a.Address)
		} else {
			return fmt.Sprintf("%s <%s>", a.Name, a.Address)
		}
	} else {
		return fmt.Sprintf("<%s>", a.Address)
	}
}

var atom *regexp.Regexp = regexp.MustCompile("^[a-z0-9!#$%7'*+-/=?^_`{}|~ ]+$")

// FormatAddresses formats a list of addresses into a human readable string
func FormatAddresses(l []*mail.Address) string {
	formatted := make([]string, len(l))
-- 
2.44.0

[aerc/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CZR7UUA44WY2.2M42S233KGN59@fra01>
In-Reply-To
<20240311204806.146091-3-robin@jarry.cc> (view parent)
DKIM signature
missing
Download raw message
aerc/patches: SUCCESS in 2m7s

[compose,viewer: do not always wrap people names in quotes][0] v2 from [Robin Jarry][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/50149
[1]: robin@jarry.cc

✓ #1166525 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1166525
✓ #1166524 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1166524
Details
Message ID
<D0J9O9OGP8ZG.1UVIR59YRV6W3@ferdinandy.com>
In-Reply-To
<20240311204806.146091-3-robin@jarry.cc> (view parent)
DKIM signature
missing
Download raw message
On Mon Mar 11, 2024 at 21:48, Robin Jarry <robin@jarry.cc> wrote:
> Currently, names of recipients in From, To, Cc and Bcc headers are
> (almost) always wrapped in quotes. Even if they are pure ASCII and
> contain one upper case letter. E.g.:
>
> 	From: "Foo" <foo@baz.org>
>
> There is no valid reason to add these quotes unless the name contains
> special characters as specified by RFC 5322, section 3.2.3:
>
>    specials        =   "(" / ")" /        ; Special characters that do
>                        "<" / ">" /        ;  not appear in atext
>                        "[" / "]" /
>                        ":" / ";" /
>                        "@" / "\" /
>                        "," / "." /
>                        DQUOTE
>
> Adapt the check accordingly.
>
> Link: https://datatracker.ietf.org/doc/html/rfc5322#section-3.2.3
> Signed-off-by: Robin Jarry <robin@jarry.cc>
> ---

Checked on a couple of weirder looking names.

Tested-by: Bence Ferdinandy <bence@ferdinandy.com>



-- 
+36305425054
bence.ferdinandy.com
Details
Message ID
<D0JA8KHEQ6IS.3NFXCNZ1X5Y4G@ringo>
In-Reply-To
<D0J9O9OGP8ZG.1UVIR59YRV6W3@ferdinandy.com> (view parent)
DKIM signature
pass
Download raw message
Bence Ferdinandy, Apr 13, 2024 at 22:12:
>
> On Mon Mar 11, 2024 at 21:48, Robin Jarry <robin@jarry.cc> wrote:
> > Currently, names of recipients in From, To, Cc and Bcc headers are
> > (almost) always wrapped in quotes. Even if they are pure ASCII and
> > contain one upper case letter. E.g.:
> >
> > 	From: "Foo" <foo@baz.org>
> >
> > There is no valid reason to add these quotes unless the name contains
> > special characters as specified by RFC 5322, section 3.2.3:
> >
> >    specials        =   "(" / ")" /        ; Special characters that do
> >                        "<" / ">" /        ;  not appear in atext
> >                        "[" / "]" /
> >                        ":" / ";" /
> >                        "@" / "\" /
> >                        "," / "." /
> >                        DQUOTE
> >
> > Adapt the check accordingly.
> >
> > Link: https://datatracker.ietf.org/doc/html/rfc5322#section-3.2.3
> > Signed-off-by: Robin Jarry <robin@jarry.cc>
> > ---
>
> Checked on a couple of weirder looking names.
>
> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>

Applied. Thanks!
Reply to thread Export thread (mbox)