# git send-email splits name with comma

6 messages from 2021-10-04 to 2021-10-04. Participants: Geert Uytterhoeven, Andreas Schwab, Junio C Hamano, Ævar Arnfjörð Bjarmason.
Thread: https://gitlist.dev/t/56643

## Geert Uytterhoeven, 2021-10-04 14:11

Subject: git send-email splits name with comma
Message-ID: <CAMuHMdXuTqUu6-b0y6VSFbEz7HKdH6U+__n7B8JRnO_ZWNeeLQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMuHMdXuTqUu6-b0y6VSFbEz7HKdH6U%2B__n7B8JRnO_ZWNeeLQ%40mail.gmail.com

```
Hi all,

If the name of an email address contains a comma, it will be split
incorrectly into multiple addresses.  A public example can be found
at[1].  I originally say this with git 2.25.1, as packaged by my distro,
but I could reproduce it with the latest version from git:

    $ git send-email  --to "foo bar, geert <geert@linux-m68k.org>"
/tmp/dummy.patch
    /tmp/dummy.patch
    (mbox) Adding cc: Geert Uytterhoeven <geert@linux-m68k.org> from
line 'From: Geert Uytterhoeven <geert@linux-m68k.org>'

    From: Geert Uytterhoeven <geert@linux-m68k.org>
    To: foo,
            bar,
            geert <geert@linux-m68k.org>
    Subject: [PATCH] dummy test
    Date: Mon,  4 Oct 2021 15:52:53 +0200
    Message-Id: <git-2.33.0.610.3.git.geert@linux-m68k.org
    X-Mailer: git-send-email 2.33.0.610.gcefe983a320c03d7
    MIME-Version: 1.0
    Content-Transfer-Encoding: 8bit

        The Cc list above has been expanded by additional
        addresses found in the patch commit message. By default
        send-email prompts before sending whenever this occurs.
        This behavior is controlled by the sendemail.confirm
        configuration setting.

        For additional information, run 'git send-email --help'.
        To retain the current behavior, but squelch this message,
        run 'git config --global sendemail.confirm auto'.

    Send this email? ([y]es|[n]o|[e]dit|[q]uit|[a]ll):
    OK. Log says:
    Sendmail: /usr/sbin/sendmail -i foo bar geert@linux-m68k.org
    From: Geert Uytterhoeven <geert@linux-m68k.org>
    To: foo,
            bar,
            geert <geert@linux-m68k.org>
    Subject: [PATCH] dummy test
    Date: Mon,  4 Oct 2021 15:52:53 +0200
    Message-Id: <git-2.33.0.610.3.git.geert@linux-m68k.org
    X-Mailer: git-send-email 2.33.0.610.gcefe983a320c03d7
    MIME-Version: 1.0
    Content-Transfer-Encoding: 8bit

    Result: OK

So "foo bar, geert <geert@linux-m68k.org>" is split in three parts,
and /usr/sbin/sendmail (exim 4.93 in my case) will have sent the email to
"foo" and "bar" (both  extended with my local non-public domain) and
"geert <geert@linux-m68k.org>".

Thanks!

[1] "Enrico Weigelt, metux IT consult <lkml@metux.net>" is split in 3 parts
    https://lore.kernel.org/linux-gpio/c987d0bf744150ca05bd952f5f9e5fb3244d27b0.1633350340.git.geert+renesas@glider.be/raw

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

```

## Andreas Schwab, 2021-10-04 14:31

Subject: Re: git send-email splits name with comma
Message-ID: <87r1d0svy4.fsf@igel.home>
URL: https://gitlist.dev/e/87r1d0svy4.fsf%40igel.home
In-Reply-To: <CAMuHMdXuTqUu6-b0y6VSFbEz7HKdH6U+__n7B8JRnO_ZWNeeLQ@mail.gmail.com>

```
On Okt 04 2021, Geert Uytterhoeven wrote:

> If the name of an email address contains a comma, it will be split
> incorrectly into multiple addresses.

If you want to include a comma in the display-name part of an address,
you need to use the quoted-string form of the phrase.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

```

## Geert Uytterhoeven, 2021-10-04 17:18

Subject: Re: git send-email splits name with comma
Message-ID: <CAMuHMdUk5=sqFvy51nxv5g3UFPhQnZ-6dBOS=xVDWdTxuLKuRQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMuHMdUk5%3DsqFvy51nxv5g3UFPhQnZ-6dBOS%3DxVDWdTxuLKuRQ%40mail.gmail.com
In-Reply-To: <87r1d0svy4.fsf@igel.home>

```
Hi Andreas,

On Mon, Oct 4, 2021 at 4:31 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
> On Okt 04 2021, Geert Uytterhoeven wrote:
> > If the name of an email address contains a comma, it will be split
> > incorrectly into multiple addresses.
>
> If you want to include a comma in the display-name part of an address,
> you need to use the quoted-string form of the phrase.

Adding more quoting like:

    git send-email --to "\"foo bar, geert\" <geert@linux-m68k.org>"

indeed works.  But I feel git send-email could do better, given it already
receives the full email address in a single argv[] entry.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

```

## Junio C Hamano, 2021-10-04 18:47

Subject: Re: git send-email splits name with comma
Message-ID: <xmqqczokwrt9.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqczokwrt9.fsf%40gitster.g
In-Reply-To: <CAMuHMdUk5=sqFvy51nxv5g3UFPhQnZ-6dBOS=xVDWdTxuLKuRQ@mail.gmail.com>

```
Geert Uytterhoeven <geert@linux-m68k.org> writes:

> Hi Andreas,
>
> On Mon, Oct 4, 2021 at 4:31 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>> On Okt 04 2021, Geert Uytterhoeven wrote:
>> > If the name of an email address contains a comma, it will be split
>> > incorrectly into multiple addresses.
>>
>> If you want to include a comma in the display-name part of an address,
>> you need to use the quoted-string form of the phrase.
>
> Adding more quoting like:
>
>     git send-email --to "\"foo bar, geert\" <geert@linux-m68k.org>"
>
> indeed works.  But I feel git send-email could do better, given it already
> receives the full email address in a single argv[] entry.

Sorry, but I do not quite follow.

If I were to send a message both to the list and to you, wouldn't

    git send-email --to "l-k@vger.k.org, geert <g@l-m68k.o>"

a valid way to do so?

```

## Geert Uytterhoeven, 2021-10-04 19:56

Subject: Re: git send-email splits name with comma
Message-ID: <CAMuHMdVHuxzKv7z+oVnPXSBi8bLnGMZDcXdgtGR4N15UQttciQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMuHMdVHuxzKv7z%2BoVnPXSBi8bLnGMZDcXdgtGR4N15UQttciQ%40mail.gmail.com
In-Reply-To: <xmqqczokwrt9.fsf@gitster.g>

```
Hi Junio,

On Mon, Oct 4, 2021 at 8:47 PM Junio C Hamano <gitster@pobox.com> wrote:
> Geert Uytterhoeven <geert@linux-m68k.org> writes:
> > On Mon, Oct 4, 2021 at 4:31 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >> On Okt 04 2021, Geert Uytterhoeven wrote:
> >> > If the name of an email address contains a comma, it will be split
> >> > incorrectly into multiple addresses.
> >>
> >> If you want to include a comma in the display-name part of an address,
> >> you need to use the quoted-string form of the phrase.
> >
> > Adding more quoting like:
> >
> >     git send-email --to "\"foo bar, geert\" <geert@linux-m68k.org>"
> >
> > indeed works.  But I feel git send-email could do better, given it already
> > receives the full email address in a single argv[] entry.
>
> Sorry, but I do not quite follow.
>
> If I were to send a message both to the list and to you, wouldn't
>
>     git send-email --to "l-k@vger.k.org, geert <g@l-m68k.o>"
>
> a valid way to do so?

Oh wait, I never realized --to and --cc take multiple email addresses;
I also use multiple --to/--cc options instead.
So the behavior I see is actually the expected behavior.
Thanks, and sorry for the noise.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

```

## Ævar Arnfjörð Bjarmason, 2021-10-04 23:47

Subject: Re: git send-email splits name with comma
Message-ID: <87pmskl508.fsf@evledraar.gmail.com>
URL: https://gitlist.dev/e/87pmskl508.fsf%40evledraar.gmail.com
In-Reply-To: <CAMuHMdVHuxzKv7z+oVnPXSBi8bLnGMZDcXdgtGR4N15UQttciQ@mail.gmail.com>

```

On Mon, Oct 04 2021, Geert Uytterhoeven wrote:

> Hi Junio,
>
> On Mon, Oct 4, 2021 at 8:47 PM Junio C Hamano <gitster@pobox.com> wrote:
>> Geert Uytterhoeven <geert@linux-m68k.org> writes:
>> > On Mon, Oct 4, 2021 at 4:31 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>> >> On Okt 04 2021, Geert Uytterhoeven wrote:
>> >> > If the name of an email address contains a comma, it will be split
>> >> > incorrectly into multiple addresses.
>> >>
>> >> If you want to include a comma in the display-name part of an address,
>> >> you need to use the quoted-string form of the phrase.
>> >
>> > Adding more quoting like:
>> >
>> >     git send-email --to "\"foo bar, geert\" <geert@linux-m68k.org>"
>> >
>> > indeed works.  But I feel git send-email could do better, given it already
>> > receives the full email address in a single argv[] entry.
>>
>> Sorry, but I do not quite follow.
>>
>> If I were to send a message both to the list and to you, wouldn't
>>
>>     git send-email --to "l-k@vger.k.org, geert <g@l-m68k.o>"
>>
>> a valid way to do so?
>
> Oh wait, I never realized --to and --cc take multiple email addresses;
> I also use multiple --to/--cc options instead.
> So the behavior I see is actually the expected behavior.
> Thanks, and sorry for the noise.
>
> Gr{oetje,eeting}s,

FWIW git-send-email just defers to Perl's Mail::Address module here:

perl -MMail::Address -MData::Dumper -wE 'warn qq[For @ARGV got: ] .
     Dumper [map { $_->format } map { Mail::Address->parse($_) } @ARGV]
' 'foo, bar <x@example.com>'
For foo, bar <x@example.com> got: $VAR1 = [
          'foo',
          'bar <x@example.com>'
        ];

As has been noted the quotes are needed, and the same should go for yor
mailer.

Anyway, that's covered already, but if anyone cared to make it
friendlier I don't see why it couldn't be made to be nicer.

I.e. we could loop over the list, use $_->address to see that the "foo"
doesn't even have an "@" in it, and either fix it up to what th user
probably meant, or do so conditionally, warn or whatever.

```
