aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/acme/mail/html.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-10-29 16:21:34 +0000
committerrsc <devnull@localhost>2005-10-29 16:21:34 +0000
commit9f1fdc128738b2ed76258ac22a8574c681f3df3a (patch)
treecd768899b5507cb00c072a3b80450da60bfbfeff /src/cmd/acme/mail/html.c
parenta078ffc8ab1d8f499b02b1dda2dfe2e9a3f6674d (diff)
downloadplan9port-9f1fdc128738b2ed76258ac22a8574c681f3df3a.tar.gz
plan9port-9f1fdc128738b2ed76258ac22a8574c681f3df3a.tar.bz2
plan9port-9f1fdc128738b2ed76258ac22a8574c681f3df3a.zip
Add mail (John Cummings)
Diffstat (limited to 'src/cmd/acme/mail/html.c')
-rw-r--r--src/cmd/acme/mail/html.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/cmd/acme/mail/html.c b/src/cmd/acme/mail/html.c
new file mode 100644
index 00000000..d07a33fe
--- /dev/null
+++ b/src/cmd/acme/mail/html.c
@@ -0,0 +1,76 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include <thread.h>
+#include <ctype.h>
+#include <plumb.h>
+#include <9pclient.h>
+#include "dat.h"
+
+
+char*
+formathtml(char *body, int *np)
+{
+ int i, j, p[2], q[2];
+ Exec *e;
+ char buf[1024];
+ Channel *sync;
+
+ e = emalloc(sizeof(struct Exec));
+ if(pipe(p) < 0 || pipe(q) < 0)
+ error("can't create pipe: %r");
+
+ e->p[0] = p[0];
+ e->p[1] = p[1];
+ e->q[0] = q[0];
+ e->q[1] = q[1];
+ e->argv = emalloc(3*sizeof(char*));
+ e->argv[0] = estrdup("htmlfmt");
+ e->argv[1] = estrdup("-cutf-8");
+ e->argv[2] = nil;
+ e->prog = unsharp("#9/bin/htmlfmt");
+ sync = chancreate(sizeof(int), 0);
+ e->sync = sync;
+ proccreate(execproc, e, EXECSTACK);
+ recvul(sync);
+ // close(p[0]);
+ close(q[1]);
+
+ if((i=write(p[1], body, *np)) != *np){
+ fprint(2, "Mail: warning: htmlfmt failed: wrote %d of %d: %r\n", i, *np);
+ close(p[1]);
+ close(q[0]);
+ return body;
+ }
+ close(p[1]);
+
+ free(body);
+ body = nil;
+ i = 0;
+ for(;;){
+ j = read(q[0], buf, sizeof buf);
+ if(j <= 0)
+ break;
+ body = realloc(body, i+j+1);
+ if(body == nil)
+ error("realloc failed: %r");
+ memmove(body+i, buf, j);
+ i += j;
+ body[i] = '\0';
+ }
+ close(q[0]);
+
+ *np = i;
+ return body;
+}
+
+char*
+readbody(char *type, char *dir, int *np)
+{
+ char *body;
+
+ body = readfile(dir, "body", np);
+ if(body != nil && strcmp(type, "text/html") == 0)
+ return formathtml(body, np);
+ return body;
+}