GECOS field parsing Lassi Kortela 17 Aug 2019 08:51 UTC

>> Should & substitution be done on all parts, or only the full name proper?
>
> I don't know. I'll ask on Unix Stack Exchange.

Well, I didn't get an answer from there but GitHub code search is
awesome. A simple search for "gecos" across the entire FreeBSD source
tree and behold: sendmail expands that stuff!

<https://github.com/freebsd/freebsd/blob/1d6e4247415d264485ee94b59fdbc12e0c566fd0/contrib/sendmail/libsm/mbdb.c#L206>

Thie is probably as canonical as anything. Delivering the world's mail
traffic provides ample test data and mail is a high priority to fix.

So it splits GECOS into fields - not only at commas, but also at
semicolons and percent signs. Perhaps as a security measure if those are
problematic for mail headers.

It expands an arbitrary number of ampersands in the first GECOS field
(but the output buffer size is limited; if it overflows, sendmail just
uses the Unix username instead of the full name).

Since sendmail only needs the first field, we unfortunately don't get an
answer to ampersands in the other fields.