diff options
author | Sigrid Solveig Haflínudóttir <sigrid@ftrv.se> | 2022-11-08 00:53:52 +0000 |
---|---|---|
committer | Sigrid Solveig Haflínudóttir <sigrid@ftrv.se> | 2022-11-08 00:53:52 +0000 |
commit | 4d1d8c342fc391cc8cf4b966a3c4f1d0c756d128 (patch) | |
tree | f9c580ea703f888fe50f846433e1fe0fa74597e7 /sys/src/cmd/upas | |
parent | c6e2c07ffbe754be9eeb64be8cf6da19a7a7ee02 (diff) |
upas/marshal: rfc2047-encode name of the sender (fixes non-ascii names in From: header)
Diffstat (limited to 'sys/src/cmd/upas')
-rw-r--r-- | sys/src/cmd/upas/marshal/marshal.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/sys/src/cmd/upas/marshal/marshal.c b/sys/src/cmd/upas/marshal/marshal.c index 476bde70a..bca3885c5 100644 --- a/sys/src/cmd/upas/marshal/marshal.c +++ b/sys/src/cmd/upas/marshal/marshal.c @@ -812,6 +812,14 @@ printdate(Biobuf *b) int printfrom(Biobuf *b) { + char *s; + int n; + + if((n = strlen(user)) > 4 && user[n-1] == '>'){ + if((s = strrchr(user, '<')) != nil && s != user && isspace(s[-1])) + return Bprint(b, "From: %.*U%s\n", (int)(s-user-1), user, s-1); + } + return Bprint(b, "From: %s\n", user); } @@ -1766,19 +1774,20 @@ doublequote(Fmt *f) int rfc2047fmt(Fmt *fmt) { - char *s, *p; + char *s, *p, *e; s = va_arg(fmt->args, char*); if(s == nil) return fmtstrcpy(fmt, ""); - for(p=s; *p; p++) + e = s + ((fmt->flags & FmtPrec) ? fmt->prec : strlen(s)); + for(p=s; *p && p != e; p++) if((uchar)*p >= 0x80) goto hard; - return fmtstrcpy(fmt, s); + return fmtprint(fmt, "%.*s", (int)(e-s), s); hard: fmtprint(fmt, "=?utf-8?q?"); - for(p = s; *p; p++){ + for(p = s; *p && p != e; p++){ if(*p == ' ') fmtrune(fmt, '_'); else if(*p == '_' || *p == '\t' || *p == '=' || *p == '?' || |