aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/upas
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-03-31 17:51:10 +0000
committerrsc <devnull@localhost>2006-03-31 17:51:10 +0000
commit3d038c325b6c5ac906092c81d282afa5bfefabc6 (patch)
treed98737d659b113cdc3a51d2d3935882d2db31c4e /src/cmd/upas
parent0b10ae3815e71a7125b29ae5ae71479549619cdc (diff)
downloadplan9port-3d038c325b6c5ac906092c81d282afa5bfefabc6.tar.gz
plan9port-3d038c325b6c5ac906092c81d282afa5bfefabc6.tar.bz2
plan9port-3d038c325b6c5ac906092c81d282afa5bfefabc6.zip
utf in subject
Diffstat (limited to 'src/cmd/upas')
-rw-r--r--src/cmd/upas/marshal/marshal.c54
1 files changed, 53 insertions, 1 deletions
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;
+}