ref: f07f9eee353fe4e8407878fd16e42cc7485cf45b
parent: 04958e2fa0963c0787388f06733cd9a0d5b0661f
author: Ori Bernstein <[email protected]>
date: Tue Nov 3 23:59:14 EST 2020
htmlfmt html messages
--- a/comp.c
+++ b/comp.c
@@ -43,14 +43,13 @@
fprint(2, "open body: %r\n");
return;
}
- if(pipe(c->fd) == -1){
- fprint(2, "pipe: %r\n");
- close(fd);
- return;
- }
+ if(pipe(c->fd) == -1)
+ sysfatal("pipe: %r\n");
+ c->sync = chancreate(sizeof(ulong), 0);
proccreate(execmarshal, c, Stack);
recvul(c->sync);
+ chanfree(c->sync);
close(c->fd[0]);
buf = emalloc(Bufsz);
@@ -142,7 +141,6 @@
int i;
c = emalloc(sizeof(Comp));
- c->sync = chancreate(sizeof(ulong), 0);
if(r != nil)
path = esmprint("%s%s%s.%d", mbox.path, r->name, "Reply", ncompose++);
else
--- a/mail.h
+++ b/mail.h
@@ -84,6 +84,11 @@
Mesg *hnext;
char quitting;
+ /* exec setup */
+ Channel *sync;
+ char *path;
+ int fd[2];
+
Mesg *parent;
Mesg **child;
int nchild;
--- a/mesg.c
+++ b/mesg.c
@@ -174,6 +174,34 @@
}
static void
+execfmt(void *pm)
+{
+ Mesg *m;
+
+ m = pm;
+ rfork(RFFDG);
+ dup(m->fd[1], 1);
+ close(m->fd[0]);
+ close(m->fd[1]);
+ sendul(m->sync, 0);
+ procexecl(nil, "/bin/htmlfmt", "-a", "-cutf-8", m->path, nil);
+}
+
+static int
+htmlfmt(Mesg *m, char *path)
+{
+ if(pipe(m->fd) == -1)
+ sysfatal("pipe: %r");
+ m->sync = chancreate(sizeof(ulong), 0);
+ m->path = path;
+ proccreate(execfmt, m, Stack);
+ recvul(m->sync);
+ chanfree(m->sync);
+ close(m->fd[1]);
+ return m->fd[0];
+}
+
+static void
copy(int wfd, int rfd)
{
char *buf;
@@ -205,8 +233,8 @@
b = readparts(m);
path = estrjoin(mbox.path, b->name, "body", nil);
- if(strcmp(b->type, "text/html"))
- rfd = open(path, OREAD);//htmlfmt(path);
+ if(strcmp(b->type, "text/html") == 0)
+ rfd = htmlfmt(m, path);
else
rfd = open(path, OREAD);
free(path);
@@ -216,11 +244,16 @@
}
home = getenv("home");
+ if(m->nattachments != 0)
+ fprint(wfd, "\n\n");
for(i = 0; i < m->nattachments; i++){
a = m->attachments[i];
if(a == b)
continue;
- fprint(wfd, "===> %s (%s)\n", a->name, a->type);
+ name = a->name;
+ if(strncmp(a->name, m->name, strlen(m->name)) == 0)
+ name += strlen(m->name);
+ fprint(wfd, "===> %s (%s)\n", name, a->type);
if(a->disposition != nil && strcmp(a->disposition, "inline") == 0){
path = estrjoin(mbox.path, b->name, "body", nil);
if((rfd = open(path, OREAD)) != -1){