upas: handle Bcc: header

when -8 flag is given, upas/marshal override To:, Cc: and Bcc: headers.
add -B option for Bcc. it is also now valid to pass recipient list
on upas/marshal arguments and have -8 flag set. make nedmail and
/rc/bin/mail call upas/marshal with -8 now to make it effective.
This commit is contained in:
cinap_lenrek 2012-11-27 21:10:55 +01:00
parent 539f74db81
commit 87ab441ab4
4 changed files with 92 additions and 57 deletions

View file

@ -8,5 +8,5 @@ switch($1){
case -f* -r* -c* -m* case -f* -r* -c* -m*
exec upas/nedmail $* exec upas/nedmail $*
case * case *
exec upas/marshal $* exec upas/marshal -8 $*
} }

View file

@ -10,6 +10,9 @@ marshal \- formatting and sending mail
.B -C .B -C
.I copyaddr .I copyaddr
] [ ] [
.B -B
.I copyaddr
] [
.B -Fr#xn .B -Fr#xn
] [ ] [
.B -p[es] .B -p[es]
@ -86,8 +89,12 @@ directing any mail reader to display the attachment
(if it can) when the mail message is read. (if it can) when the mail message is read.
.TP .TP
.BI -C copyaddr .BI -C copyaddr
or
.BI -B copyaddr
adds a adds a
.B Cc: .B Cc:
or
.B Bcc:
header with header with
.I copyaddr .I copyaddr
and also adds and also adds

View file

@ -122,10 +122,10 @@ int printinreplyto(Biobuf*, char*);
int printsubject(Biobuf*, char*); int printsubject(Biobuf*, char*);
int printto(Biobuf*, Addr*); int printto(Biobuf*, Addr*);
Alias* readaliases(void); Alias* readaliases(void);
int readheaders(Biobuf*, int*, String**, Addr**, int); int readheaders(Biobuf*, int*, String**, Addr**, Addr**, Addr**, int);
void readmimetypes(void); void readmimetypes(void);
int rfc2047fmt(Fmt*); int rfc2047fmt(Fmt*);
int sendmail(Addr*, Addr*, int*, char*); int sendmail(Addr*, Addr*, Addr*, int*, char*);
char* waitforsubprocs(void); char* waitforsubprocs(void);
int rflag, lbflag, xflag, holding, nflag, Fflag, eightflag, dflag; int rflag, lbflag, xflag, holding, nflag, Fflag, eightflag, dflag;
@ -188,10 +188,10 @@ bwritesfree(Biobuf *bp, String **str)
void void
main(int argc, char **argv) main(int argc, char **argv)
{ {
int ccargc, flags, fd, noinput, headersrv; int ccargc, bccargc, flags, fd, noinput, headersrv;
char *subject, *type, *boundary; char *subject, *type, *boundary;
char *ccargv[32]; char *ccargv[32], *bccargv[32];
Addr *cc, *to; Addr *to, *cc, *bcc;
Attach *first, **l, *a; Attach *first, **l, *a;
Biobuf in, out, *b; Biobuf in, out, *b;
String *file, *hdrstring; String *file, *hdrstring;
@ -202,7 +202,7 @@ main(int argc, char **argv)
l = &first; l = &first;
type = nil; type = nil;
hdrstring = nil; hdrstring = nil;
ccargc = 0; ccargc = bccargc = 0;
quotefmtinstall(); quotefmtinstall();
fmtinstall('Z', doublequote); fmtinstall('Z', doublequote);
@ -227,6 +227,11 @@ main(int argc, char **argv)
sysfatal("too many cc's"); sysfatal("too many cc's");
ccargv[ccargc++] = EARGF(usage()); ccargv[ccargc++] = EARGF(usage());
break; break;
case 'B':
if(bccargc >= nelem(bccargv)-1)
sysfatal("too many bcc's");
bccargv[bccargc++] = EARGF(usage());
break;
case 'd': case 'd':
dflag = 1; /* for sendmail */ dflag = 1; /* for sendmail */
break; break;
@ -278,17 +283,17 @@ main(int argc, char **argv)
if(nflag && eightflag) if(nflag && eightflag)
sysfatal("can't use both -n and -8"); sysfatal("can't use both -n and -8");
if(eightflag && argc >= 1) if(!eightflag && argc < 1)
usage();
else if(!eightflag && argc < 1)
usage(); usage();
aliases = readaliases(); aliases = readaliases();
if(!eightflag){ to = cc = bcc = nil;
if(argc > 0)
to = expand(argc, argv); to = expand(argc, argv);
if(ccargc > 0)
cc = expand(ccargc, ccargv); cc = expand(ccargc, ccargv);
} else if(bccargc > 0)
to = cc = nil; bcc = expand(bccargc, bccargv);
flags = 0; flags = 0;
headersrv = Nomessage; headersrv = Nomessage;
@ -299,7 +304,7 @@ main(int argc, char **argv)
*/ */
holding = holdon(); holding = holdon();
headersrv = readheaders(&in, &flags, &hdrstring, headersrv = readheaders(&in, &flags, &hdrstring,
eightflag? &to: nil, 1); eightflag? &to: nil, eightflag? &cc: nil, eightflag? &bcc: nil, 1);
if(rfc822syntaxerror){ if(rfc822syntaxerror){
Bdrain(&in); Bdrain(&in);
fatal("rfc822 syntax error, message not sent"); fatal("rfc822 syntax error, message not sent");
@ -321,7 +326,7 @@ main(int argc, char **argv)
} }
} }
fd = sendmail(to, cc, &pid, Fflag ? argv[0] : nil); fd = sendmail(to, cc, bcc, &pid, Fflag ? argv[0] : nil);
if(fd < 0) if(fd < 0)
sysfatal("execing sendmail: %r\n:"); sysfatal("execing sendmail: %r\n:");
if(xflag || lbflag || dflag){ if(xflag || lbflag || dflag){
@ -340,7 +345,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, 0) == Error) if (readheaders(b, &flags, &hdrstring, nil, nil, nil, 0) == Error)
fatal("reading"); fatal("reading");
Bterm(b); Bterm(b);
bwritesfree(&out, &hdrstring); bwritesfree(&out, &hdrstring);
@ -440,16 +445,16 @@ pgpopts(char *s)
* remove Bcc: line. * remove Bcc: line.
*/ */
int int
readheaders(Biobuf *in, int *fp, String **sp, Addr **top, int strict) readheaders(Biobuf *in, int *fp, String **sp, Addr **top, Addr **ccp, Addr **bccp, int strict)
{ {
int i, seen, hdrtype; int i, seen, hdrtype;
char *p; char *p;
Addr *to; Addr *to, *cc, *bcc;
String *s, *sline; String *s, *sline;
s = s_new(); s = s_new();
to = cc = bcc = nil;
sline = nil; sline = nil;
to = nil;
hdrtype = -1; hdrtype = -1;
seen = 0; seen = 0;
for(;;) { for(;;) {
@ -468,22 +473,28 @@ readheaders(Biobuf *in, int *fp, String **sp, Addr **top, int strict)
/* process the current header, it's all been read */ /* process the current header, it's all been read */
if(sline) { if(sline) {
assert(hdrtype != -1);
if(top){
switch(hdrtype){ switch(hdrtype){
case Hto: default:
case Hcc: Addhdr:
case Hbcc:
to = expandline(&sline, to);
break;
}
}
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, s_to_c(sline));
s_append(s, "\n"); s_append(s, "\n");
break;
case Hto:
if(top)
to = expandline(&sline, to);
goto Addhdr;
case Hcc:
if(ccp)
cc = expandline(&sline, cc);
goto Addhdr;
case Hbcc:
if(bccp)
bcc = expandline(&sline, bcc);
break;
case Hsubject:
s_append(s, mksubject(s_to_c(sline)));
s_append(s, "\n");
break;
} }
s_free(sline); s_free(sline);
sline = nil; sline = nil;
@ -530,8 +541,24 @@ readheaders(Biobuf *in, int *fp, String **sp, Addr **top, int strict)
} }
*sp = s; *sp = s;
if(top)
if(to){
freeaddrs(*top);
*top = to; *top = to;
}else
freeaddrs(to);
if(cc){
freeaddrs(*ccp);
*ccp = cc;
}else
freeaddrs(cc);
if(bcc){
freeaddrs(*bccp);
*bccp = bcc;
}else
freeaddrs(bcc);
if(seen == 0){ if(seen == 0){
if(Blinelen(in) == 0) if(Blinelen(in) == 0)
@ -760,11 +787,13 @@ printfrom(Biobuf *b)
} }
int int
printto(Biobuf *b, Addr *a) printaddr(Biobuf *b, char *s, Addr *a)
{ {
int i; int i;
if(Bprint(b, "To: %s", a->v) < 0) if(a == nil)
return 0;
if(Bprint(b, "%s %s", s, a->v) < 0)
return -1; return -1;
i = 0; i = 0;
for(a = a->next; a != nil; a = a->next) for(a = a->next; a != nil; a = a->next)
@ -775,22 +804,16 @@ printto(Biobuf *b, Addr *a)
return 0; return 0;
} }
int
printto(Biobuf *b, Addr *a)
{
return printaddr(b, "To:", a);
}
int int
printcc(Biobuf *b, Addr *a) printcc(Biobuf *b, Addr *a)
{ {
int i; return printaddr(b, "Cc:", a);
if(a == nil)
return 0;
if(Bprint(b, "CC: %s", a->v) < 0)
return -1;
i = 0;
for(a = a->next; a != nil; a = a->next)
if(Bprint(b, "%s%s", ((i++ & 7) == 7)?",\n\t":", ", a->v) < 0)
return -1;
if(Bprint(b, "\n") < 0)
return -1;
return 0;
} }
int int
@ -1032,7 +1055,7 @@ openfolder(char *rcvr)
/* start up sendmail and return an fd to talk to it with */ /* start up sendmail and return an fd to talk to it with */
int int
sendmail(Addr *to, Addr *cc, int *pid, char *rcvr) sendmail(Addr *to, Addr *cc, Addr *bcc, int *pid, char *rcvr)
{ {
int ac, fd; int ac, fd;
int pfd[2]; int pfd[2];
@ -1049,6 +1072,8 @@ sendmail(Addr *to, Addr *cc, int *pid, char *rcvr)
ac++; ac++;
for(a = cc; a != nil; a = a->next) for(a = cc; a != nil; a = a->next)
ac++; ac++;
for(a = bcc; a != nil; a = a->next)
ac++;
v = av = emalloc(sizeof(char*)*(ac+20)); v = av = emalloc(sizeof(char*)*(ac+20));
ac = 0; ac = 0;
v[ac++] = "sendmail"; v[ac++] = "sendmail";
@ -1064,6 +1089,8 @@ sendmail(Addr *to, Addr *cc, int *pid, char *rcvr)
v[ac++] = a->v; v[ac++] = a->v;
for(a = cc; a != nil; a = a->next) for(a = cc; a != nil; a = a->next)
v[ac++] = a->v; v[ac++] = a->v;
for(a = bcc; a != nil; a = a->next)
v[ac++] = a->v;
v[ac] = 0; v[ac] = 0;
if(pipe(pfd) < 0) if(pipe(pfd) < 0)

View file

@ -1819,6 +1819,7 @@ rcmd(Cmd *c, Message *m)
return nil; return nil;
} }
av[ai++] = "-8";
for(nm = m; nm != &top; nm = nm->parent){ for(nm = m; nm != &top; nm = nm->parent){
if(*nm->subject){ if(*nm->subject){
av[ai++] = "-s"; av[ai++] = "-s";
@ -1862,8 +1863,8 @@ rcmd(Cmd *c, Message *m)
Message* Message*
mcmd(Cmd *c, Message *m) mcmd(Cmd *c, Message *m)
{ {
char **av; char *av[128];
int i, ai; int i, ai = 1;
String *path; String *path;
if(m == &top){ if(m == &top){
@ -1876,8 +1877,7 @@ mcmd(Cmd *c, Message *m)
return nil; return nil;
} }
ai = 1; av[ai++] = "-8";
av = malloc(sizeof(char*)*(c->an + 8));
av[ai++] = "-t"; av[ai++] = "-t";
if(m->parent == &top) if(m->parent == &top)
@ -1892,7 +1892,7 @@ mcmd(Cmd *c, Message *m)
if(strchr(c->av[0], 'M') == nil) if(strchr(c->av[0], 'M') == nil)
av[ai++] = "-n"; av[ai++] = "-n";
for(i = 1; i < c->an; i++) for(i = 1; i < c->an && ai < nelem(av)-1; i++)
av[ai++] = c->av[i]; av[ai++] = c->av[i];
av[ai] = 0; av[ai] = 0;
@ -1900,7 +1900,6 @@ mcmd(Cmd *c, Message *m)
m = nil; m = nil;
if(path != nil) if(path != nil)
s_free(path); s_free(path);
free(av);
return m; return m;
} }
@ -1917,6 +1916,8 @@ acmd(Cmd *c, Message *m)
return nil; return nil;
} }
av[ai++] = "-8";
if(*m->subject){ if(*m->subject){
av[ai++] = "-s"; av[ai++] = "-s";
subject = addrecolon(m->subject); subject = addrecolon(m->subject);