upas/marshal: interpret Attach: and Inline: headers only when -8 flag is given

This commit is contained in:
cinap_lenrek 2013-01-01 15:56:36 +01:00
parent cc3b91ca27
commit be01be80cc
2 changed files with 28 additions and 22 deletions

View file

@ -157,6 +157,10 @@ reads recipients (
.B To: .B To:
and and
.B Cc: .B Cc:
) and attachments (
.B Attach:
and
.B Inline:
) from RFC 822 header of the message ) from RFC 822 header of the message
.PD .PD
.PP .PP

View file

@ -116,6 +116,7 @@ void freealias(Alias*);
void freealiases(Alias*); void freealiases(Alias*);
Attach* mkattach(char*, char*, int); Attach* mkattach(char*, char*, int);
char* mkboundary(void); char* mkboundary(void);
char* hdrval(char*);
char* mksubject(char*); char* mksubject(char*);
int pgpfilter(int*, int, int); int pgpfilter(int*, int, int);
int pgpopts(char*); int pgpopts(char*);
@ -308,7 +309,7 @@ main(int argc, char **argv)
*/ */
holding = holdon(); holding = holdon();
headersrv = readheaders(&in, &flags, &hdrstring, headersrv = readheaders(&in, &flags, &hdrstring,
eightflag? &to: nil, eightflag? &cc: nil, eightflag? &bcc: nil, l, 1); eightflag? &to: nil, eightflag? &cc: nil, eightflag? &bcc: nil, eightflag? l: nil, 1);
if(rfc822syntaxerror){ if(rfc822syntaxerror){
Bdrain(&in); Bdrain(&in);
fatal("rfc822 syntax error, message not sent"); fatal("rfc822 syntax error, message not sent");
@ -349,7 +350,7 @@ main(int argc, char **argv)
mboxpath("headers", user, file, 0); mboxpath("headers", user, file, 0);
b = Bopen(s_to_c(file), OREAD); b = Bopen(s_to_c(file), OREAD);
if(b != nil){ if(b != nil){
if (readheaders(b, &flags, &hdrstring, nil, nil, nil, l, 0) == Error) if (readheaders(b, &flags, &hdrstring, nil, nil, nil, nil, 0) == Error)
fatal("reading"); fatal("reading");
Bterm(b); Bterm(b);
bwritesfree(&out, &hdrstring); bwritesfree(&out, &hdrstring);
@ -449,16 +450,15 @@ pgpopts(char *s)
* remove Bcc: line. * remove Bcc: line.
*/ */
int int
readheaders(Biobuf *in, int *fp, String **sp, Addr **top, Addr **ccp, Addr **bccp, Attach **l, int strict) readheaders(Biobuf *in, int *fp, String **sp, Addr **top, Addr **ccp, Addr **bccp, Attach **att, int strict)
{ {
int i, seen, hdrtype, flags; int i, seen, hdrtype;
char *p; Addr *to, *cc, *bcc;
Addr *to, *cc, *bcc, *attachment;
Attach *a;
String *s, *sline; String *s, *sline;
char *p;
s = s_new(); s = s_new();
to = cc = bcc = attachment = nil; to = cc = bcc = nil;
sline = nil; sline = nil;
hdrtype = -1; hdrtype = -1;
seen = 0; seen = 0;
@ -501,17 +501,12 @@ readheaders(Biobuf *in, int *fp, String **sp, Addr **top, Addr **ccp, Addr **bcc
s_append(s, "\n"); s_append(s, "\n");
break; break;
case Hattach: case Hattach:
flags = 0;
goto afile;
case Hinline: case Hinline:
flags = 1; if(att == nil)
afile: goto Addhdr;
attachment = expandline(&sline, attachment); *att = mkattach(hdrval(s_to_c(sline)), nil, hdrtype == Hinline);
a = mkattach(attachment->v, nil, flags); if(*att != nil)
if(a == nil) att = &(*att)->next;
exits("bad args");
*l = a;
l = &a->next;
break; break;
} }
s_free(sline); s_free(sline);
@ -876,7 +871,7 @@ mkattach(char *file, char *type, int ainline)
return nil; return nil;
} }
a = emalloc(sizeof(*a)); a = emalloc(sizeof(*a));
a->path = file; a->path = estrdup(file);
a->next = nil; a->next = nil;
a->type = type; a->type = type;
a->ainline = ainline; a->ainline = ainline;
@ -1937,15 +1932,22 @@ hard:
return 0; return 0;
} }
char*
hdrval(char *p)
{
p = strchr(p, ':') + 1;
while(*p == ' ' || *p == '\t')
p++;
return p;
}
char* char*
mksubject(char *line) mksubject(char *line)
{ {
char *p, *q; char *p, *q;
static char buf[1024]; static char buf[1024];
p = strchr(line, ':') + 1; p = hdrval(line);
while(*p == ' ')
p++;
for(q = p; *q; q++) for(q = p; *q; q++)
if((uchar)*q >= 0x80) if((uchar)*q >= 0x80)
goto hard; goto hard;