char* fullurl(URLwin *u, Rune *rhref) { char *base, *href, *hrefbase; char *result; if(rhref == nil) return estrdup("NULL URL"); href = runetobyte(rhref, runestrlen(rhref)); hrefbase = baseurl(href); result = nil; if(hrefbase==nil && (base = baseurl(u->url))!=nil){ result = estrdup(base); if(base[strlen(base)-1]!='/' && (href==nil || href[0]!='/')) result = eappend(result, "/", ""); free(base); } if(href){ if(result) result = eappend(result, "", href); else result = estrdup(href); } free(hrefbase); if(result == nil) return estrdup("***unknown***"); return result; }
char* info(Message *m, int ind, int ogf) { char *i; int j, len, lens; char *p; char fmt[80], s[80]; if (ogf) p=m->to; else p=m->fromcolon; if(ind==0 && shortmenu){ len = 30; lens = 30; if(shortmenu > 1){ len = 10; lens = 25; } if(ind==0 && m->subject[0]=='\0'){ snprint(fmt, sizeof fmt, " %%-%d.%ds", len, len); snprint(s, sizeof s, fmt, p); }else{ snprint(fmt, sizeof fmt, " %%-%d.%ds %%-%d.%ds", len, len, lens, lens); snprint(s, sizeof s, fmt, p, m->subject); } i = estrdup(s); return i; } i = estrdup(""); i = eappend(i, "\t", p); i = egrow(i, "\t", stripdate(m->date)); if(ind == 0){ if(strcmp(m->type, "text")!=0 && strncmp(m->type, "text/", 5)!=0 && strncmp(m->type, "multipart/", 10)!=0) i = egrow(i, "\t(", estrstrdup(m->type, ")")); }else if(strncmp(m->type, "multipart/", 10) != 0) i = egrow(i, "\t(", estrstrdup(m->type, ")")); if(m->subject[0] != '\0'){ i = eappend(i, "\n", nil); for(j=0; j<ind; j++) i = eappend(i, "\t", nil); i = eappend(i, "\t", m->subject); } return i; }
char* egrow(char *s, char *sep, char *t) { s = eappend(s, sep, t); free(t); return s; }
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); } }
void mimedisplay(Message *m, char *name, char *rootdir, Window *w, int fileonly) { char *dest, *maildest; if(strcmp(m->disposition, "file")==0 || strlen(m->filename)!=0){ if(strlen(m->filename) == 0){ dest = estrdup(m->name); dest[strlen(dest)-1] = '\0'; }else dest = estrdup(m->filename); if(maildest = getenv("maildest")){ maildest = eappend(maildest, "/", dest); Bprint(w->body, "\tcp %s%sbody%s %q\n", rootdir, name, ext(m->type), maildest); free(maildest); } if(m->filename[0] != '/'){ dest = egrow(estrdup(home), "/", dest); } Bprint(w->body, "\tcp %s%sbody%s %q\n", rootdir, name, ext(m->type), dest); free(dest); }else if(!fileonly) Bprint(w->body, "\tfile is %s%sbody%s\n", rootdir, name, ext(m->type)); }
int mesgcommand(Message *m, char *cmd) { char *s; char *args[10]; int ok, ret, nargs; s = cmd; ret = 1; nargs = tokenize(s, args, nelem(args)); if(nargs == 0) return 0; if(strcmp(args[0], "Post") == 0){ mesgsend(m); goto Return; } if(strncmp(args[0], "Save", 4) == 0){ if(m->isreply) goto Return; s = estrdup("\t[saved"); if(nargs==1 || strcmp(args[1], "")==0){ ok = mesgsave(m, "stored"); }else{ ok = mesgsave(m, args[1]); s = eappend(s, " ", args[1]); } if(ok){ s = egrow(s, "]", nil); mesgmenumark(mbox.w, m->name, s); } free(s); goto Return; } if(strcmp(args[0], "Reply")==0){ if(nargs>=2 && strcmp(args[1], "all")==0) mkreply(m, "Replyall", nil, nil, nil); else mkreply(m, "Reply", nil, nil, nil); goto Return; } if(strcmp(args[0], "Q") == 0){ s = winselection(m->w); /* will be freed by mkreply */ if(nargs>=3 && strcmp(args[1], "Reply")==0 && strcmp(args[2], "all")==0) mkreply(m, "QReplyall", nil, nil, s); else mkreply(m, "QReply", nil, nil, s); goto Return; } if(strcmp(args[0], "Del") == 0){ if(windel(m->w, 0)){ chanfree(m->w->cevent); free(m->w); m->w = nil; if(m->isreply) delreply(m); else{ m->opened = 0; m->tagposted = 0; } free(cmd); threadexits(nil); } goto Return; } if(strcmp(args[0], "Delmesg") == 0){ if(!m->isreply){ mesgmenumarkdel(wbox, &mbox, m, 1); free(cmd); /* mesgcommand might not return */ mesgcommand(m, estrdup("Del")); return 1; } goto Return; } if(strcmp(args[0], "UnDelmesg") == 0){ if(!m->isreply && m->deleted) mesgmenumarkundel(wbox, &mbox, m); goto Return; } // if(strcmp(args[0], "Headers") == 0){ // m->showheaders(); // return True; // } ret = 0; Return: free(cmd); return ret; }
int mboxcommand(Window *w, char *s) { char *args[10], **targs, *save; Window *sbox; Message *m, *next; int ok, nargs, i, j; CFid *searchfd; char buf[128], *res; nargs = tokenize(s, args, nelem(args)); if(nargs == 0) return 0; if(strcmp(args[0], "Mail") == 0){ if(nargs == 1) mkreply(nil, "Mail", "", nil, nil); else mkreply(nil, "Mail", args[1], nil, nil); return 1; } if(strcmp(s, "Del") == 0){ if(mbox.dirty){ mbox.dirty = 0; fprint(2, "mail: mailbox not written\n"); return 1; } if(w != mbox.w){ windel(w, 1); return 1; } ok = 1; for(m=mbox.head; m!=nil; m=next){ next = m->next; if(m->w){ if(windel(m->w, 0)) m->w = nil; else ok = 0; } } for(m=replies.head; m!=nil; m=next){ next = m->next; if(m->w){ if(windel(m->w, 0)) m->w = nil; else ok = 0; } } if(ok){ windel(w, 1); removeupasfs(); threadexitsall(nil); } return 1; } if(strcmp(s, "Put") == 0){ rewritembox(wbox, &mbox); return 1; } if(strcmp(s, "Get") == 0){ fswrite(mbox.ctlfd, "refresh", 7); return 1; } if(strcmp(s, "Delmesg") == 0){ save = nil; if(nargs > 1) save = args[1]; s = winselection(w); if(s == nil) return 1; nargs = 1; for(i=0; s[i]; i++) if(s[i] == '\n') nargs++; targs = emalloc(nargs*sizeof(char*)); /* could be too many for a local array */ nargs = getfields(s, targs, nargs, 1, "\n"); for(i=0; i<nargs; i++){ if(!isdigit(targs[i][0])) continue; j = atoi(targs[i]); /* easy way to parse the number! */ if(j == 0) continue; snprint(buf, sizeof buf, "%s%d", mbox.name, j); delmesg(buf, nil, 1, save); } free(s); free(targs); return 1; } if(strcmp(s, "Search") == 0){ if(nargs <= 1) return 1; s = estrstrdup(mboxname, "/search"); searchfd = fsopen(mailfs, s, ORDWR); if(searchfd == nil) return 1; save = estrdup(args[1]); for(i=2; i<nargs; i++) save = eappend(save, " ", args[i]); fswrite(searchfd, save, strlen(save)); fsseek(searchfd, 0, 0); j = fsread(searchfd, buf, sizeof buf - 1); if(j == 0){ fprint(2, "[%s] search %s: no results found\n", mboxname, save); fsclose(searchfd); free(save); return 1; } free(save); buf[j] = '\0'; res = estrdup(buf); j = fsread(searchfd, buf, sizeof buf - 1); for(; j != 0; j = fsread(searchfd, buf, sizeof buf - 1), buf[j] = '\0') res = eappend(res, "", buf); fsclose(searchfd); sbox = newwindow(); winname(sbox, s); free(s); threadcreate(mainctl, sbox, STACK); winopenbody(sbox, OWRITE); /* show results in reverse order */ m = mbox.tail; save = nil; for(s=strrchr(res, ' '); s!=nil || save!=res; s=strrchr(res, ' ')){ if(s != nil){ save = s+1; *s = '\0'; } else save = res; save = estrstrdup(save, "/"); for(; m && strcmp(save, m->name) != 0; m=m->prev); free(save); if(m == nil) break; fsprint(sbox->body, "%s%s\n", m->name, info(m, 0, 0)); m = m->prev; } free(res); winclean(sbox); winclosebody(sbox); return 1; } return 0; }
void threadmain(int argc, char *argv[]) { int i, j; char *dir, *tag, *name; char buf[1024], **av; quotefmtinstall(); rfork(RFNAMEG); ARGBEGIN{ case 'd': debug = 1; chatty9p++; break; case 'e': eraseinput = 1; break; case 'D': {extern int _threaddebuglevel; _threaddebuglevel = 1<<20; } }ARGEND if(argc == 0){ av = emalloc(3*sizeof(char*)); av[0] = "rc"; av[1] = "-i"; name = getenv("sysname"); }else{ av = argv; name = utfrrune(av[0], '/'); if(name) name++; else name = av[0]; } if(getwd(buf, sizeof buf) == 0) dir = "/"; else dir = buf; dir = estrdup(dir); tag = estrdup(dir); tag = eappend(estrdup(tag), "/-", name); win = newwindow(); snprint(buf, sizeof buf, "%d", win->id); putenv("winid", buf); winname(win, tag); wintagwrite(win, "Send Noscroll", 5+8); threadcreate(mainctl, win, STACK); mountcons(); threadcreate(fsloop, nil, STACK); startpipe(); startcmd(av, ¬epg); strcpy(buf, "win"); j = 3; for(i=0; i<argc && j+1+strlen(argv[i])+1<sizeof buf; i++){ strcpy(buf+j, " "); strcpy(buf+j+1, argv[i]); j += 1+strlen(argv[i]); } ctlprint(win->ctl, "scroll"); winsetdump(win, dir, buf); }