void plumb(Message *m, char *dir) { int i; char *port; Plumbmsg *pm; if(strlen(m->type) == 0) return; i = plumbport(m->type, m->filename); if(i < 0) fprint(2, "can't find destination for message subpart\n"); else{ port = ports[i].port; pm = emalloc(sizeof(Plumbmsg)); pm->src = estrdup("Mail"); if(port) pm->dst = estrdup(port); else pm->dst = nil; pm->wdir = nil; pm->type = estrdup("text"); pm->ndata = -1; pm->data = estrstrdup(dir, "body"); pm->data = eappend(pm->data, "", ports[i].suffix); if(plumbsend(plumbsendfd, pm) < 0) fprint(2, "error writing plumb message: %r\n"); plumbfree(pm); } }
static void plumbsendproc(void *x) { Plumbmsg *m; m = x; plumbsend(plumbsendfd, m); freeattrs(m); free(m->data); free(m); }
int replytoaddr(Window *w, Message *m, Event *e, char *s) { int did; char *buf; Plumbmsg *pm; buf = nil; did = 0; if(e->flag & 2){ /* autoexpanded; use our own bigger expansion */ buf = expandaddr(w, e); if(buf == nil) return 0; s = buf; } if(isemail(s)){ did = 1; pm = emalloc(sizeof(Plumbmsg)); pm->src = estrdup("Mail"); pm->dst = estrdup("sendmail"); pm->data = estrdup(s); pm->ndata = -1; if(m->subject && m->subject[0]){ pm->attr = emalloc(sizeof(Plumbattr)); pm->attr->name = estrdup("Subject"); if(tolower(m->subject[0]) != 'r' || tolower(m->subject[1]) != 'e' || m->subject[2] != ':') pm->attr->value = estrstrdup("Re: ", m->subject); else pm->attr->value = estrdup(m->subject); pm->attr->next = nil; } if(plumbsend(plumbsendfd, pm) < 0) fprint(2, "error writing plumb message: %r\n"); plumbfree(pm); } free(buf); return did; }
int plumbrunestr(Runestr *rs, char *attr) { Plumbmsg *m; int i; i = -1; if(plumbsendfd >= 0) { m = emalloc(sizeof(Plumbmsg)); m->src = estrdup("abaco"); m->dst = nil; m->wdir = estrdup("/tmp"); m->type = estrdup("text"); if(attr) m->attr = plumbunpackattr(attr); else m->attr = nil; m->data = smprint("%.*S", rs->nr, rs->r); m->ndata = -1; i = plumbsend(plumbsendfd, m); plumbfree(m); } return i; }
void threadmain(int argc, char *argv[]) { char buf[1024], *p; int fd, i, input; input = 0; m.src = "plumb"; m.dst = nil; m.wdir = getwd(buf, sizeof buf); m.type = "text"; m.attr = nil; ARGBEGIN{ case '9': chatty9pclient = 1; break; case 'a': p = ARGF(); if(p == nil) usage(); m.attr = plumbaddattr(m.attr, plumbunpackattr(p)); break; case 'd': m.dst = ARGF(); if(m.dst == nil) usage(); break; case 'i': input++; break; case 't': case 'k': /* for backwards compatibility */ m.type = ARGF(); if(m.type == nil) usage(); break; case 'p': plumbfile = ARGF(); if(plumbfile == nil) usage(); break; case 's': m.src = ARGF(); if(m.src == nil) usage(); break; case 'w': m.wdir = ARGF(); if(m.wdir == nil) usage(); break; }ARGEND if((input && argc>0) || (!input && argc<1)) usage(); if(plumbfile != nil) fd = open(plumbfile, OWRITE); else fd = plumbopen("send", OWRITE); if(fd < 0){ fprint(2, "plumb: can't open plumb file: %r\n"); threadexitsall("open"); } if(input){ gather(); if(plumblookup(m.attr, "action") == nil) m.attr = plumbaddattr(m.attr, plumbunpackattr("action=showdata")); if(plumbsend(fd, &m) < 0){ fprint(2, "plumb: can't send message: %r\n"); threadexitsall("error"); } threadexitsall(nil); } for(i=0; i<argc; i++){ if(input == 0){ m.data = argv[i]; m.ndata = -1; } if(plumbsend(fd, &m) < 0){ fprint(2, "plumb: can't send message: %r\n"); threadexitsall("error"); } } threadexitsall(nil); }