ref: 1d3858eee15e06ebca88004ac454d1f534a2322f
parent: e3d7f2d9f73bc96ced073200e7001ecf29c3256e
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Nov 14 12:19:31 EST 2020
improve quoting: quote what we show in the message window.
--- a/comp.c
+++ b/comp.c
@@ -149,13 +149,32 @@
threadexits(nil);
}
+static Biobuf*
+openbody(Mesg *r)
+{
+ Biobuf *f;
+ int q0, q1;
+ char *s;
+
+ assert(r->state & Sopen);
+
+ wingetsel(r, &q0, &q1);
+ if(q1 - q0 != 0){
+ s = smprint("/mnt/acme/%d/xdata", r->id);
+ f = Bopen(s, OREAD);
+ free(s);
+ }else
+ f = mesgopenbody(r);
+ return f;
+}
+
void
compose(char *to, Mesg *r, int quote, int all)
{
static int ncompose;
- char *path, *ln;
Biobuf *rfd, *wfd;
Comp *c;
+ char *ln;
c = emalloc(sizeof(Comp));
if(r != nil)
@@ -189,9 +208,8 @@
Bprint(wfd, "Re: ");
Bprint(wfd, "%s\n\n", r->subject);
if(quote){
- path = estrjoin(mbox.path, r->name, "body", nil);
- rfd = Bopen(path, OREAD);
- free(path);
+ Bprint(wfd, "Quoth %s:\n", r->fromcolon);
+ rfd = openbody(r);
if(rfd != nil)
while((ln = Brdstr(rfd, '\n', 0)) != nil)
if(Bprint(wfd, "> %s", ln) == -1)
--- a/mail.h
+++ b/mail.h
@@ -164,7 +164,6 @@
void wintagwrite(Win*, char*);
int winevent(Win*, Event*);
void winreturn(Win*, Event*);
-int wineval(Win*, char*, ...);
int winread(Win*, int, int, char*, int);
int matchmesg(Win*, char*);
char *winreadsel(Win*);
@@ -181,7 +180,7 @@
void mesgfree(Mesg*);
void mesgpath2name(char*, int, char*);
int mesgflagparse(char*, int*);
-
+Biobuf* mesgopenbody(Mesg*);
/* mailbox */
void mbredraw(Mesg*, int, int);
--- a/mesg.c
+++ b/mesg.c
@@ -140,9 +140,12 @@
{
char *dpath, *apath;
int n, i, dfd;
- Mesg *a, *sub, *best;
+ Mesg *a, *sub;
Dir *d;
+ if(m->body != nil)
+ return m->body;
+
dpath = estrjoin(mbox.path, m->name, nil);
dfd = open(dpath, OREAD);
free(dpath);
@@ -154,7 +157,7 @@
if(n == -1)
sysfatal("%s read: %r", mbox.path);
- best = nil;
+ m->body = nil;
m->parts = erealloc(m->parts, (m->nparts + n)*sizeof(Mesg*));
for(i = 0; i < n; i++){
if(d[i].qid.type != QTDIR)
@@ -168,7 +171,7 @@
if(strncmp(a->type, "multipart/", strlen("multipart/")) == 0){
sub = readparts(a);
if(sub != a)
- best = sub;
+ m->body = sub;
continue;
}
m->parts[m->nparts++] = a;
@@ -175,14 +178,14 @@
if(a->filename != nil || a->disposition != nil && strcmp(a->disposition, "inline") != 0)
continue;
if(strcmp(a->type, "text/plain") == 0)
- best = a;
- else if(best == nil && strcmp(a->type, "text/html") == 0)
- best = a;
+ m->body = a;
+ else if(m->body == nil && strcmp(a->type, "text/html") == 0)
+ m->body = a;
}
free(d);
- if(best == nil)
- return m;
- return best;
+ if(m->body == nil)
+ m->body = m;
+ return m->body;
}
static void
@@ -213,7 +216,7 @@
}
static void
-copy(int wfd, int rfd)
+copy(Biobuf *wfd, Biobuf *rfd)
{
char *buf;
int n;
@@ -220,10 +223,10 @@
buf = emalloc(Bufsz);
while(1){
- n = read(rfd, buf, Bufsz);
+ n = Bread(rfd, buf, Bufsz);
if(n <= 0)
break;
- if(write(wfd, buf, n) != n)
+ if(Bwrite(wfd, buf, n) != n)
break;
}
free(buf);
@@ -233,54 +236,49 @@
mesgshow(Mesg *m)
{
char *path, *home, *name;
- int i, rfd, wfd;
- Mesg *a, *b;
+ Biobuf *rfd, *wfd;
+ Mesg *a;
+ int i;
- if((wfd = winopen(m, "body", OWRITE)) == -1)
+ if((wfd = bwinopen(m, "body", OWRITE)) == nil)
return -1;
if(m->parent != nil || m->nchild != 0) {
- fprint(wfd, "Thread:");
+ Bprint(wfd, "Thread:");
if(m->parent && !(m->parent->state & Sdummy))
- fprint(wfd, " ↑ %s", m->parent->name);
+ Bprint(wfd, " ↑ %s", m->parent->name);
for(i = 0; i < m->nchild; i++)
- fprint(wfd, " ↓ %s", m->child[i]->name);
- fprint(wfd, "\n");
+ Bprint(wfd, " ↓ %s", m->child[i]->name);
+ Bprint(wfd, "\n");
}
- fprint(wfd, "From: %s\n", m->fromcolon);
- fprint(wfd, "To: %s\n", m->to);
- fprint(wfd, "Date: %s\n", m->date);
- fprint(wfd, "Subject: %s\n\n", m->subject);
+ Bprint(wfd, "From: %s\n", m->fromcolon);
+ Bprint(wfd, "To: %s\n", m->to);
+ Bprint(wfd, "Date: %s\n", m->date);
+ Bprint(wfd, "Subject: %s\n\n", m->subject);
- b = readparts(m);
- path = estrjoin(mbox.path, b->name, "body", nil);
- if(strcmp(b->type, "text/html") == 0)
- rfd = htmlfmt(m, path);
- else
- rfd = open(path, OREAD);
- free(path);
- if(rfd != -1){
+ rfd = mesgopenbody(m);
+ if(rfd != nil){
copy(wfd, rfd);
- close(rfd);
+ Bterm(rfd);
}
home = getenv("home");
if(m->nparts != 0)
- fprint(wfd, "\n");
+ Bprint(wfd, "\n");
for(i = 0; i < m->nparts; i++){
a = m->parts[i];
- if(a == b)
+ if(a == m)
continue;
name = a->name;
if(strncmp(a->name, m->name, strlen(m->name)) == 0)
name += strlen(m->name);
- fprint(wfd, "\n===> %s (%s)\n", name, a->type);
+ Bprint(wfd, "\n===> %s (%s)\n", name, a->type);
if(a->disposition != nil
&& strcmp(a->disposition, "inline") == 0
&& strcmp(a->type, "text/plain") == 0){
path = estrjoin(mbox.path, a->name, "body", nil);
- if((rfd = open(path, OREAD)) != -1){
+ if((rfd = Bopen(path, OREAD)) != nil){
copy(wfd, rfd);
- close(rfd);
+ Bterm(rfd);
}
free(path);
continue;
@@ -288,10 +286,10 @@
name = a->filename;
if(name == nil)
name = "body";
- fprint(wfd, "\tcp %s%sbody %s/%s\n", mbox.path, a->name, home, name);
+ Bprint(wfd, "\tcp %s%sbody %s/%s\n", mbox.path, a->name, home, name);
continue;
}
- close(wfd);
+ Bterm(wfd);
free(home);
fprint(m->ctl, "clean\n");
return 0;
@@ -540,4 +538,23 @@
}
threadcreate(mesgmain, m, Stack);
return m;
+}
+
+Biobuf*
+mesgopenbody(Mesg *m)
+{
+ char *path;
+ int rfd;
+ Mesg *b;
+
+ b = readparts(m);
+ path = estrjoin(mbox.path, b->name, "body", nil);
+ if(strcmp(b->type, "text/html") == 0)
+ rfd = htmlfmt(m, path);
+ else
+ rfd = open(path, OREAD);
+ free(path);
+ if(rfd == -1)
+ return nil;
+ return Bfdopen(rfd, OREAD);
}
--- a/win.c
+++ b/win.c
@@ -186,21 +186,6 @@
}
int
-wineval(Win *w, char *s, ...)
-{
- char buf[25];
- va_list arg;
-
- va_start(arg, s);
- vfprint(w->addr, s, arg);
- va_end(arg);
- if(pread(w->addr, buf, 24, 0) != 24)
- return -1;
- buf[24] = 0;
- return strtol(buf, nil, 10);
-}
-
-int
winread(Win *w, int q0, int q1, char *data, int ndata)
{
int m, n, nr;