aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-10-03 23:43:59 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-10-03 23:43:59 +0200
commitce9ac3aff4bd2fe58132c3ec194269abe4fda4a7 (patch)
tree21a91364194e6ce6a091625d6f7a2200503316f6
parent5ff71ace36fb4d2962b5b8f2085aceaf841eaff1 (diff)
downloadmblaze-ce9ac3aff4bd2fe58132c3ec194269abe4fda4a7.tar.gz
blaze822: blaze822_addr: quote local-part if needed
-rw-r--r--blaze822.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/blaze822.c b/blaze822.c
index a06eb24..6434055 100644
--- 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;