upas/marshal: encode UTF8 in subject lines [rsc] --rw-rw-r-- M 128579 glenda sys 33818 Mar 31 12:48 sys/src/cmd/upas/marshal/marshal.c [diffs elided - too long] [diff -c /n/sourcesdump/2006/0331/plan9/sys/src/cmd/upas/marshal/marshal.c /n/sourcesdump/2006/0401/plan9/sys/src/cmd/upas/marshal/marshal.c] [rsc] --rw-rw-r-- M 128579 glenda sys 4272 Mar 31 17:59 sys/src/cmd/upas/fs/dat.h /n/sourcesdump/2006/0331/plan9/sys/src/cmd/upas/fs/dat.h:134,140 - /n/sourcesdump/2006/0401/plan9/sys/src/cmd/upas/fs/dat.h:134,140 int cistrcmp(char*, char*); int latin1toutf(char*, char*, char*); int windows1257toutf(char*, char*, char*); - int decquoted(char*, char*, char*); + int decquoted(char*, char*, char*, int); int xtoutf(char*, char**, char*, char*); void countlines(Message*); int headerlen(Message*); [rsc] --rw-rw-r-- M 128579 glenda sys 27463 Mar 31 17:59 sys/src/cmd/upas/fs/fs.c /n/sourcesdump/2006/0331/plan9/sys/src/cmd/upas/fs/fs.c:1403,1409 - /n/sourcesdump/2006/0401/plan9/sys/src/cmd/upas/fs/fs.c:1403,1409 decoded[len] = 0; } else if(cistrncmp(token, "q?", 2) == 0){ token += 2; - len = decquoted(decoded, token, e); + len = decquoted(decoded, token, e, 1); if(len > 0 && decoded[len-1] == '\n') len--; decoded[len] = 0; [rsc] --rw-rw-r-- M 128579 glenda sys 29022 Mar 31 17:59 sys/src/cmd/upas/fs/mbox.c /n/sourcesdump/2006/0331/plan9/sys/src/cmd/upas/fs/mbox.c:1042,1048 - /n/sourcesdump/2006/0401/plan9/sys/src/cmd/upas/fs/mbox.c:1042,1048 case Equoted: len = m->bend - m->body; x = emalloc(len+2); // room for null and possible extra nl - len = decquoted(x, m->body, m->bend); + len = decquoted(x, m->body, m->bend, 0); if(m->ballocd) free(m->body); m->body = x; /n/sourcesdump/2006/0331/plan9/sys/src/cmd/upas/fs/mbox.c:1189,1195 - /n/sourcesdump/2006/0401/plan9/sys/src/cmd/upas/fs/mbox.c:1189,1195 } static char* - decquotedline(char *out, char *in, char *e) + decquotedline(char *out, char *in, char *e, int uscores) { int c, soft; /n/sourcesdump/2006/0331/plan9/sys/src/cmd/upas/fs/mbox.c:1208,1213 - /n/sourcesdump/2006/0401/plan9/sys/src/cmd/upas/fs/mbox.c:1208,1215 c = (*in++) & 0xff; switch(tableqp[c]){ case Self: + if(uscores && c == '_') + c = ' '; *out++ = c; break; case Hex: /n/sourcesdump/2006/0331/plan9/sys/src/cmd/upas/fs/mbox.c:1225,1231 - /n/sourcesdump/2006/0401/plan9/sys/src/cmd/upas/fs/mbox.c:1227,1233 } int - decquoted(char *out, char *in, char *e) + decquoted(char *out, char *in, char *e, int uscores) { char *p, *nl; /n/sourcesdump/2006/0331/plan9/sys/src/cmd/upas/fs/mbox.c:1234,1244 - /n/sourcesdump/2006/0401/plan9/sys/src/cmd/upas/fs/mbox.c:1236,1246 p = out; while((nl = strchr(in, '\n')) != nil && nl < e){ - p = decquotedline(p, in, nl); + p = decquotedline(p, in, nl, uscores); in = nl + 1; } if(in < e) - p = decquotedline(p, in, e-1); + p = decquotedline(p, in, e-1, uscores); // make sure we end with a new line if(*(p-1) != '\n'){