From 963cfc9a6f6e721f52aa949e6d1af0c3e8dc2ecc Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 12 Mar 2017 17:15:03 +0100 Subject: merging erik quanstros nupas --- acme/mail/src/reply.c | 567 -------------------------------------------------- 1 file changed, 567 deletions(-) delete mode 100644 acme/mail/src/reply.c (limited to 'acme/mail/src/reply.c') diff --git a/acme/mail/src/reply.c b/acme/mail/src/reply.c deleted file mode 100644 index 65841c570..000000000 --- a/acme/mail/src/reply.c +++ /dev/null @@ -1,567 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "dat.h" - -static int replyid; - -int -quote(Message *m, Biobuf *b, char *dir, char *quotetext) -{ - char *body, *type; - int i, n, nlines; - char **lines; - - if(quotetext){ - body = quotetext; - n = strlen(body); - type = nil; - }else{ - /* look for first textual component to quote */ - type = readfile(dir, "type", &n); - if(type == nil){ - print("no type in %s\n", dir); - return 0; - } - if(strncmp(type, "multipart/", 10)==0 || strncmp(type, "message/", 8)==0){ - dir = estrstrdup(dir, "1/"); - if(quote(m, b, dir, nil)){ - free(type); - free(dir); - return 1; - } - free(dir); - } - if(strncmp(type, "text", 4) != 0){ - free(type); - return 0; - } - body = readbody(m->type, dir, &n); - if(body == nil) - return 0; - } - nlines = 0; - for(i=0; i%s%s\n", lines[i][0]=='>'? "" : " ", lines[i]); - i++; - } - free(lines); - free(body); /* will free quotetext if non-nil */ - free(type); - return 1; -} - -void -mkreply(Message *m, char *label, char *to, Plumbattr *attr, char *quotetext) -{ - Message *r; - char *dir, *t; - int quotereply; - Plumbattr *a; - - quotereply = (label[0] == 'Q'); - r = emalloc(sizeof(Message)); - r->isreply = 1; - if(m != nil) - r->replyname = estrdup(m->name); - r->next = replies.head; - r->prev = nil; - if(replies.head != nil) - replies.head->prev = r; - replies.head = r; - if(replies.tail == nil) - replies.tail = r; - r->name = emalloc(strlen(mbox.name)+strlen(label)+10); - sprint(r->name, "%s%s%d", mbox.name, label, ++replyid); - r->w = newwindow(); - winname(r->w, r->name); - ctlprint(r->w->ctl, "cleartag"); - wintagwrite(r->w, "fmt Look Post Undo", 4+5+5+4); - r->tagposted = 1; - threadcreate(mesgctl, r, STACK); - winopenbody(r->w, OWRITE); - if(to!=nil && to[0]!='\0') - Bprint(r->w->body, "%s\n", to); - for(a=attr; a; a=a->next) - Bprint(r->w->body, "%s: %s\n", a->name, a->value); - dir = nil; - if(m != nil){ - dir = estrstrdup(mbox.name, m->name); - if(to == nil && attr == nil){ - /* Reply goes to replyto; Reply all goes to From and To and CC */ - if(strstr(label, "all") == nil) - Bprint(r->w->body, "To: %s\n", m->replyto); - else{ /* Replyall */ - if(strlen(m->from) > 0) - Bprint(r->w->body, "To: %s\n", m->from); - if(strlen(m->to) > 0) - Bprint(r->w->body, "To: %s\n", m->to); - if(strlen(m->cc) > 0) - Bprint(r->w->body, "CC: %s\n", m->cc); - } - } - if(strlen(m->subject) > 0){ - t = "Subject: Re: "; - if(strlen(m->subject) >= 3) - if(tolower(m->subject[0])=='r' && tolower(m->subject[1])=='e' && m->subject[2]==':') - t = "Subject: "; - Bprint(r->w->body, "%s%s\n", t, m->subject); - } - if(!quotereply){ - Bprint(r->w->body, "Include: %sraw\n", dir); - free(dir); - } - } - Bprint(r->w->body, "\n"); - if(m == nil) - Bprint(r->w->body, "\n"); - else if(quotereply){ - quote(m, r->w->body, dir, quotetext); - free(dir); - } - winclosebody(r->w); - if(m==nil && (to==nil || to[0]=='\0')) - winselect(r->w, "0", 0); - else - winselect(r->w, "$", 0); - winclean(r->w); - windormant(r->w); -} - -void -delreply(Message *m) -{ - if(m->next == nil) - replies.tail = m->prev; - else - m->next->prev = m->prev; - if(m->prev == nil) - replies.head = m->next; - else - m->prev->next = m->next; - mesgfreeparts(m); - free(m); -} - -/* copy argv to stack and free the incoming strings, so we don't leak argument vectors */ -void -buildargv(char **inargv, char *argv[NARGS+1], char args[NARGCHAR]) -{ - int i, n; - char *s, *a; - - s = args; - for(i=0; i= NARGCHAR) /* too many characters */ - break; - argv[i] = s; - memmove(s, a, n); - s += n; - free(a); - } - argv[i] = nil; -} - -void -execproc(void *v) -{ - struct Exec *e; - int p[2], q[2]; - char *prog; - char *argv[NARGS+1], args[NARGCHAR]; - - e = v; - p[0] = e->p[0]; - p[1] = e->p[1]; - q[0] = e->q[0]; - q[1] = e->q[1]; - prog = e->prog; /* known not to be malloc'ed */ - rfork(RFFDG); - sendul(e->sync, 1); - buildargv(e->argv, argv, args); - free(e->argv); - chanfree(e->sync); - free(e); - dup(p[0], 0); - close(p[0]); - close(p[1]); - if(q[0]){ - dup(q[1], 1); - close(q[0]); - close(q[1]); - } - procexec(nil, prog, argv); -//fprint(2, "exec: %s", e->prog); -//{int i; -//for(i=0; argv[i]; i++) print(" '%s'", argv[i]); -//print("\n"); -//} -//argv[0] = "cat"; -//argv[1] = nil; -//procexec(nil, "/bin/cat", argv); - fprint(2, "Mail: can't exec %s: %r\n", prog); - threadexits("can't exec"); -} - -enum{ - ATTACH, - BCC, - CC, - FROM, - INCLUDE, - TO, -}; - -char *headers[] = { - "attach:", - "bcc:", - "cc:", - "from:", - "include:", - "to:", - nil, -}; - -int -whichheader(char *h) -{ - int i; - - for(i=0; headers[i]!=nil; i++) - if(cistrcmp(h, headers[i]) == 0) - return i; - return -1; -} - -char *tolist[200]; -char *cclist[200]; -char *bcclist[200]; -int ncc, nbcc, nto; -char *attlist[200]; -char included[200]; - -int -addressed(char *name) -{ - int i; - - for(i=0; i 0) - write(ofd, s, m); - return n; -} - -void -write2(int fd, int ofd, char *buf, int n, int nofrom) -{ - char *from, *p; - int m; - - write(fd, buf, n); - - if(ofd <= 0) - return; - - if(nofrom == 0){ - write(ofd, buf, n); - return; - } - - /* need to escape leading From lines to avoid corrupting 'outgoing' mailbox */ - for(p=buf; *p; p+=m){ - from = cistrstr(p, "from"); - if(from == nil) - m = n; - else - m = from - p; - if(m > 0) - write(ofd, p, m); - if(from){ - if(p==buf || from[-1]=='\n') - write(ofd, " ", 1); /* escape with space if From is at start of line */ - write(ofd, from, 4); - m += 4; - } - n -= m; - } -} - -void -mesgsend(Message *m) -{ - char *s, *body, *to; - int i, j, h, n, natt, p[2]; - struct Exec *e; - Channel *sync; - int first, nfld, delit, ofd; - char *copy, *fld[100], *now; - - body = winreadbody(m->w, &n); - /* assemble to: list from first line, to: line, and cc: line */ - nto = 0; - natt = 0; - ncc = 0; - nbcc = 0; - first = 1; - to = body; - for(;;){ - for(s=to; *s!='\n'; s++) - if(*s == '\0'){ - free(body); - return; - } - if(s++ == to) /* blank line */ - break; - /* make copy of line to tokenize */ - copy = emalloc(s-to); - memmove(copy, to, s-to); - copy[s-to-1] = '\0'; - nfld = tokenizec(copy, fld, nelem(fld), ", \t"); - if(nfld == 0){ - free(copy); - break; - } - n -= s-to; - switch(h = whichheader(fld[0])){ - case TO: - case FROM: - delit = 1; - commas(to+strlen(fld[0]), s-1); - for(i=1; i 0){ - /* From dhog Fri Aug 24 22:13:00 EDT 2001 */ - now = ctime(time(0)); - fprint(ofd, "From %s %s", user, now); - fprint(ofd, "From: %s\n", user); - fprint(ofd, "Date: %s", now); - for(i=0; ip[0] = p[0]; - e->p[1] = p[1]; - e->prog = "/bin/upas/marshal"; - e->argv = emalloc((1+1+2+4*natt+1)*sizeof(char*)); - e->argv[0] = estrdup("marshal"); - e->argv[1] = estrdup("-8"); - j = 2; - if(m->replyname){ - e->argv[j++] = estrdup("-R"); - e->argv[j++] = estrstrdup(mbox.name, m->replyname); - } - for(i=0; iargv[j++] = estrdup("-A"); - else - e->argv[j++] = estrdup("-a"); - e->argv[j++] = estrdup(attlist[i]); - } - sync = chancreate(sizeof(int), 0); - e->sync = sync; - proccreate(execproc, e, EXECSTACK); - recvul(sync); - close(p[0]); - - /* using marshal -8, so generate rfc822 headers */ - if(nto > 0){ - print2(p[1], ofd, "To: "); - for(i=0; i 0){ - print2(p[1], ofd, "CC: "); - for(i=0; i 0){ - print2(p[1], ofd, "BCC: "); - for(i=0; i 0) - write2(p[1], ofd, body, i, 1); - - /* guarantee a blank line, to ensure attachments are separated from body */ - if(i==0 || body[i-1]!='\n') - write2(p[1], ofd, "\n\n", 2, 0); - else if(i>1 && body[i-2]!='\n') - write2(p[1], ofd, "\n", 1, 0); - - /* these look like pseudo-attachments in the "outgoing" box */ - if(ofd>0 && natt>0){ - for(i=0; i Include: %s\n", attlist[i]); - else - fprint(ofd, "=====> Attach: %s\n", attlist[i]); - } - if(ofd > 0) - write(ofd, "\n", 1); - - for(i=0; ireplyname != nil) - mesgmenumark(mbox.w, m->replyname, "\t[replied]"); - if(m->name[0] == '/') - s = estrdup(m->name); - else - s = estrstrdup(mbox.name, m->name); - s = egrow(s, "-R", nil); - winname(m->w, s); - free(s); - winclean(m->w); - /* mark message unopened because it's no longer the original message */ - m->opened = 0; -} -- cgit v1.2.3