ref: 4d1d8c342fc391cc8cf4b966a3c4f1d0c756d128
parent: c6e2c07ffbe754be9eeb64be8cf6da19a7a7ee02
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Nov 7 19:53:52 EST 2022
upas/marshal: rfc2047-encode name of the sender (fixes non-ascii names in From: header)
--- a/sys/src/cmd/upas/marshal/marshal.c
+++ b/sys/src/cmd/upas/marshal/marshal.c
@@ -812,6 +812,14 @@
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 @@
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 == '?' ||