diff -r d8d00747375b sys/src/cmd/upas/ned/nedmail.c --- a/sys/src/cmd/upas/ned/nedmail.c Thu Sep 29 03:00:00 2011 +0200 +++ b/sys/src/cmd/upas/ned/nedmail.c Tue Nov 29 00:00:00 2011 +0100 @@ -61,6 +61,7 @@ { "text/rtf", "rtf", 1, 0 }, { "text", "txt", 1, 0 }, { "message/rfc822", "msg", 0, 0 }, + { "message/delivery-status", "txt", 1, 0 }, { "image/bmp", "bmp", 0, "image" }, { "image/jpeg", "jpg", 0, "image" }, { "image/gif", "gif", 0, "image" }, @@ -131,12 +132,12 @@ { "|", 1, pipecmd, "|cmd pipe message body to a command" }, { "||", 1, rpipecmd, "||cmd pipe raw message to a command" }, { "!", 1, bangcmd, "!cmd run a command" }, - { nil, 0, nil, nil }, + { nil, 0, nil, nil } }; enum { - NARG= 32, + NARG= 32 }; struct Cmd { @@ -266,7 +267,7 @@ av[0] = "fs"; av[1] = "-p"; av[2] = 0; - system("/bin/upas/fs", av, -1); + system("/bin/upas/nfs", av, -1); } switchmb(file, singleton); @@ -353,6 +354,38 @@ qcmd(nil, nil); } +static char* +mkaddrs(char *t) +{ + int i, nf, inquote; + char **f, *s; + Fmt fmt; + + inquote = 0; + nf = 2; + for(s=t; *s; s++){ + if(*s == '\'') + inquote = !inquote; + if(*s == ' ' && !inquote) + nf++; + } + f = malloc(nf*sizeof f[0]); + if(f == nil) + return nil; + nf = tokenize(t, f, nf); + fmtstrinit(&fmt); + for(i=0; i+1 0) + fmtprint(&fmt, " "); + /* if(f[i][0] == 0 || strcmp(f[i], f[i+1]) == 0) */ + fmtprint(&fmt, "%s", f[i+1]); + /* else */ + /* fmtprint(&fmt, "%s <%s>", f[i], f[i+1]); */ + } + free(f); + return fmtstrflush(&fmt); +} + // // read the message info // @@ -361,24 +394,51 @@ { Message *m; String *path; - char *f[10]; - + char *f[30], *s, *t; + int i, nf; + m = mallocz(sizeof(Message), 1); if(m == nil) return nil; m->path = path = extendpath(parent->path, name); m->fileno = atoi(name); m->info = file2string(path, "info"); - lineize(s_to_c(m->info), f, nelem(f)); - m->from = f[0]; - m->to = f[1]; - m->cc = f[2]; - m->replyto = f[3]; - m->date = f[4]; - m->subject = f[5]; - m->type = f[6]; - m->disposition = f[7]; - m->filename = f[8]; + m->from = ""; + m->to = ""; + m->cc = ""; + m->replyto = ""; + m->date = ""; + m->subject = ""; + m->type = ""; + m->disposition = ""; + m->filename = ""; + nf = lineize(s_to_c(m->info), f, nelem(f)); + for(i=0; ifrom = mkaddrs(t); + else if(strcmp(s, "to") == 0) + m->to = mkaddrs(t); + else if(strcmp(s, "cc") == 0) + m->cc = mkaddrs(t); + else if(strcmp(s, "replyto") == 0) + m->replyto = mkaddrs(t); + else if(strcmp(s, "unixdate") == 0 && (t=strchr(t, ' ')) != nil) + m->date = t; + else if(strcmp(s, "subject") == 0) + m->subject = t; + else if(strcmp(s, "type") == 0) + m->type = t; + else if(strcmp(s, "disposition") == 0) + m->disposition = t; + else if(strcmp(s, "filename") == 0) + m->filename = t; + } m->len = filelen(path, "raw"); if(strstr(m->type, "multipart") != nil || strcmp(m->type, "message/rfc822") == 0) dir2message(m, 0); @@ -719,7 +779,11 @@ dup(pfd[0], 0); close(1); dup(pfd[0], 1); +#ifdef PLAN9PORT + execl(unsharp("#9/bin/file"), "file", "-m", s_to_c(extendpath(m->path, "body")), nil); +#else execl("/bin/file", "file", "-m", s_to_c(extendpath(m->path, "body")), nil); +#endif exits(0); default: close(pfd[0]); @@ -1353,7 +1417,11 @@ Cmd c; c.an = 3; +#ifdef PLAN9PORT + c.av[1] = "htmlfmt"; +#elese c.av[1] = "/bin/htmlfmt"; +#endif c.av[2] = "-l 40 -cutf-8"; Bprint(&out, "!%s\n", c.av[1]); Bflush(&out); @@ -1542,13 +1610,14 @@ doflush = 0; deld = 0; - fd = open("/mail/fs/ctl", ORDWR); + snprint(buf, sizeof buf, "/mail/fs/%s/ctl", mbname); + fd = open(buf, OWRITE); if(fd < 0){ - fprint(2, "!can't delete mail, opening /mail/fs/ctl: %r\n"); + fprint(2, "!can't delete mail, opening %s: %r\n", buf); exitfs(0); } e = &buf[sizeof(buf)]; - p = seprint(buf, e, "delete %s", mbname); + p = seprint(buf, e, "delete"); n = 0; for(l = &top.child; *l != nil;){ m = *l; @@ -1570,7 +1639,7 @@ if(e-p < 10){ write(fd, buf, p-buf); n = 0; - p = seprint(buf, e, "delete %s", mbname); + p = seprint(buf, e, "delete"); } p = seprint(p, e, " %s", msg); n++; @@ -1673,8 +1742,15 @@ Message* icmd(Cmd*, Message *m) { - int n; + int n, fd; + char buf[1024]; + snprint(buf, sizeof buf, "/mail/fs/%s/ctl", mbname); + fd = open(buf, OWRITE); + if(fd){ + write(fd, "refresh", 7); + close(fd); + } n = dir2message(&top, reverse); if(n > 0) Bprint(&out, "%d new message%s\n", n, plural(n)); @@ -1699,16 +1775,24 @@ int tomailer(char **av) { + static char *marshal; Waitmsg *w; int pid, i; - // start the mailer and get out of the way + if(marshal == nil) +#ifdef PLAN9PORT + marshal = unsharp("#9/bin/upas/marshal"); +#else + marshal = "/bin/upas/marshal"; +#endif + + /* start the mailer and get out of the way */ switch(pid = fork()){ case -1: fprint(2, "can't fork: %r\n"); return -1; case 0: - Bprint(&out, "!/bin/upas/marshal"); + Bprint(&out, "!%s", marshal); for(i = 1; av[i]; i++){ if(strchr(av[i], ' ') != nil) Bprint(&out, " '%s'", av[i]); @@ -1719,8 +1803,8 @@ Bflush(&out); av[0] = "marshal"; chdir(wd); - exec("/bin/upas/marshal", av); - fprint(2, "couldn't exec /bin/upas/marshal\n"); + exec(marshal, av); + fprint(2, "couldn't exec %s\n", marshal); exits(0); default: w = wait(); @@ -2037,7 +2121,9 @@ Message* scmd(Cmd *c, Message *m) { - char *file; + char buf[256]; + int fd; + char *file, *msg; if(m == &top){ Bprint(&out, "!address\n"); @@ -2056,9 +2142,24 @@ return nil; } - if(appendtofile(m, "raw", file, 1) < 0) - return nil; - + if(file[0] == '/' || (file[0]=='.' && file[1]=='/')){ + if(appendtofile(m, "raw", file, 1) < 0) + return nil; + }else{ + snprint(buf, sizeof buf, "/mail/fs/%s/ctl", mbname); + if((fd = open(buf, OWRITE)) < 0) + return nil; + msg = strrchr(s_to_c(m->path), '/'); + if(msg == nil) + msg = s_to_c(m->path); + else + msg++; + if(fprint(fd, "save %s %s", file, msg) < 0){ + close(fd); + return nil; + } + close(fd); + } m->stored = 1; return m; } @@ -2209,6 +2310,12 @@ case -1: return; case 0: + if(strcmp(cmd, "rc") == 0) +#ifdef PLAN9PORT + cmd = unsharp("#9/bin/rc"); +#else + cmd = "/bin/rc"; +#endif if(in >= 0){ close(0); dup(in, 0); @@ -2249,7 +2356,7 @@ av[1] = "-c"; av[2] = cmd; av[3] = 0; - system("/bin/rc", av, -1); + system("rc", av, -1); Bprint(&out, "!\n"); return m; } @@ -2295,7 +2402,7 @@ av[1] = "-c"; av[2] = cmd; av[3] = 0; - system("/bin/rc", av, fd); /* system closes fd */ + system("rc", av, fd); /* system closes fd */ Bprint(&out, "!\n"); return m; } @@ -2317,7 +2424,7 @@ { int fd; - fd = open("/mail/fs/ctl", ORDWR); + fd = open("/mail/fs/ctl", OWRITE); if(fd < 0) sysfatal("can't open /mail/fs/ctl: %r"); @@ -2410,9 +2517,12 @@ path = s_reset(nil); mboxpath(mbname, user, path, 0); }else{ + if(file) + strecpy(mbname, mbname+sizeof mbname, file); + else + strcpy(mbname, "mbox"); path = s_reset(nil); - mboxpath("mbox", user, path, 0); - strcpy(mbname, "mbox"); + mboxpath(mbname, user, path, 0); } snprint(root, sizeof root, "/mail/fs/%s", mbname);