From 3d038c325b6c5ac906092c81d282afa5bfefabc6 Mon Sep 17 00:00:00 2001 From: rsc Date: Fri, 31 Mar 2006 17:51:10 +0000 Subject: utf in subject --- src/cmd/upas/marshal/marshal.c | 54 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/cmd/upas/marshal/marshal.c b/src/cmd/upas/marshal/marshal.c index fbc06cf6..da54c760 100644 --- a/src/cmd/upas/marshal/marshal.c +++ b/src/cmd/upas/marshal/marshal.c @@ -134,6 +134,8 @@ void freealiases(Alias*); int doublequote(Fmt*); int mountmail(void); int nprocexec; +int rfc2047fmt(Fmt*); +char* mksubject(char*); int rflag, lbflag, xflag, holding, nflag, Fflag, eightflag, dflag; int pgpflag = 0; @@ -207,6 +209,7 @@ threadmain(int argc, char **argv) quotefmtinstall(); fmtinstall('Z', doublequote); + fmtinstall('U', rfc2047fmt); threadwaitchan(); ARGBEGIN{ @@ -487,7 +490,10 @@ readheaders(Biobuf *in, int *fp, String **sp, Addr **top, int strict) break; } } - if(top==nil || hdrtype!=Hbcc){ + if(hdrtype == Hsubject){ + s_append(s, mksubject(s_to_c(sline))); + s_append(s, "\n"); + }else if(top==nil || hdrtype!=Hbcc){ s_append(s, s_to_c(sline)); s_append(s, "\n"); } @@ -1865,3 +1871,49 @@ mountmail(void) return -1; return 0; } + +int +rfc2047fmt(Fmt *fmt) +{ + char *s, *p; + + s = va_arg(fmt->args, char*); + if(s == nil) + return fmtstrcpy(fmt, ""); + for(p=s; *p; p++) + if((uchar)*p >= 0x80) + goto hard; + return fmtstrcpy(fmt, s); + +hard: + fmtprint(fmt, "=?utf-8?q?"); + for(p=s; *p; p++){ + if(*p == ' ') + fmtrune(fmt, '_'); + else if(*p == '_' || *p == '\t' || *p == '=' || *p == '?' || (uchar)*p >= 0x80) + fmtprint(fmt, "=%.2uX", (uchar)*p); + else + fmtrune(fmt, (uchar)*p); + } + fmtprint(fmt, "?="); + return 0; +} + +char* +mksubject(char *line) +{ + char *p, *q; + static char buf[1024]; + + p = strchr(line, ':')+1; + while(*p == ' ') + p++; + for(q=p; *q; q++) + if((uchar)*q >= 0x80) + goto hard; + return line; + +hard: + snprint(buf, sizeof buf, "Subject: %U", p); + return buf; +} -- cgit v1.2.3