mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
utf in subject
This commit is contained in:
parent
0b10ae3815
commit
3d038c325b
1 changed files with 53 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue