mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit ce9ac3aff4bd2fe58132c3ec194269abe4fda4a7
parent 5ff71ace36fb4d2962b5b8f2085aceaf841eaff1
Author: Leah Neukirchen <leah@vuxu.org>
Date:   Tue,  3 Oct 2017 23:43:59 +0200

blaze822: blaze822_addr: quote local-part if needed

Diffstat:
blaze822.c | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/blaze822.c b/blaze822.c @@ -231,6 +231,32 @@ startover: *disp = 0; } + char *host = strrchr(addr, '@'); + ssize_t hlen = strlen(host); + char *u; + if (host && (u = strpbrk(addr, "()<>[]:;@\\,\"")) && u < host) { + // need to "-quote local-part + + char addr2[sizeof addr]; + char *e = addr2 + sizeof addr2 - 1; + char *t; + + u = addr; + t = addr2; + *t++ = '"'; + while (u < host && e - t > 2) { + if (*u == '"' || *u == '\\') + *t++ = '\\'; + *t++ = *u++; + } + *t++ = '"'; + if (e - t > hlen + 1) { + memcpy(t, host, hlen); + *(t + hlen) = 0; + memcpy(addr, addr2, sizeof addr); + } + } + if (dispo) *dispo = *disp ? disp : 0; if (addro) *addro = *addr ? addr : 0;