ref: de53a2e1ed55e81c0f9823f14304f85f6531a49b
parent: 2d076037d8dddd20eaeb72f6ed31c8a359ce978b
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Nov 3 13:13:12 EST 2020
bugfixes: fix new messages, crashes on empty fields.
--- a/mbox.c
+++ b/mbox.c
@@ -24,7 +24,7 @@
char *maildir = "/mail/fs";
-char *mailbox = "tmptest";
+char *mailbox = "mbox";
Mesg dead = {.messageid="", .hash=42};
Reprog *addrpat;
@@ -324,16 +324,17 @@
load(char *name, char *digest, int ins)
{
Mesg *m, *p, **c;
- char *n;
int nc;
- if((n = strrchr(name, '/')) == nil)
- n = name;
- if((m = mesgload(n)) == nil)
+ if(strncmp(name, mbox.path, strlen(mbox.path)) == 0)
+ name += strlen(mbox.path);
+ if((m = mesgload(name)) == nil)
goto error;
- if(digest != nil && strcmp(digest, m->digest) != 0)
+ if(digest != nil && strcmp(digest, m->digest) != 0){
+ fprint(2, "mismatched digest: %s %s\n", m->digest, digest);
goto error;
+ }
/* if we already have a dummy, populate it */
if((p = lookupid(m->messageid)) != nil){
c = p->child;
@@ -350,7 +351,7 @@
if(!threadsort || m->inreplyto == nil){
m->flags |= Ftoplev;
- return 0;
+ return m;
}
p = lookupid(m->inreplyto);
@@ -371,12 +372,14 @@
int ln, depth;
ln = mesglineno(m, &depth);
- werrstr("");
fprint(mbox.addr, "%d%s", ln+1, add ? "-#0" : "");
- fprint(mbox.ctl, "dot=addr\n");
bfd = bwindata(&mbox, OWRITE);
showmesg(bfd, m, depth, rec);
- Bterm(bfd);
+ Bterm(bfd);
+
+ /* highlight the redrawn message */
+ fprint(mbox.addr, "%d%s", ln+1, add ? "-#0" : "");
+ fprint(mbox.ctl, "dot=addr\n");
}
static void
@@ -420,7 +423,7 @@
flag = " ";
sep = depth ? "\t" : "";
width = depth ? Subjlen - 4 : Subjlen;
- if(m->flags & Funseen) flag = "★";
+ if(m->flags & Funseen) flag = "•";
if(m->flags & Fresp) flag = "←";
if(m->flags & Fdel) flag = "∉";
if(m->flags & Ftodel) flag = "∉";
@@ -610,7 +613,7 @@
digest = plumblookup(pm->attr, "digest");
action = plumblookup(pm->attr, "mailtype");
- fprint(2, "changing message %s, %s %s\n", action, pm->data, digest);
+// fprint(2, "changing message %s, %s %s\n", action, pm->data, digest);
if(strcmp(action, "new") == 0){
m = load(pm->data, digest, 1);
add = 1;
@@ -635,8 +638,9 @@
{"Mark", mbmarkmesg},
{"Del", mbquit},
#ifdef NOTYET
+ {"Redisplay", redisplay},
+ {"Filter", filter},
{"Get", mbrefresh},
- {"Sort", mbsort},
{"Next", mboxnext},
#endif
{nil}
@@ -692,10 +696,8 @@
wininit(&mbox, mbox.path);
wintagwrite(&mbox, "Put Mail Delmesg Save Next ");
mbshow();
- fprint(2, "shown\n");
fprint(mbox.ctl, "clean\n");
proccreate(eventread, nil, Stack);
- fprint(2, "started\n");
while(1){
switch(alt(a)){
case Cevent:
--- a/mesg.c
+++ b/mesg.c
@@ -44,7 +44,7 @@
}
static char*
-line(char *data, char **pp)
+line(char *data, char **pp, int z)
{
char *p, *q;
@@ -54,7 +54,7 @@
*pp = p+1;
else
*pp = p;
- if(p == data)
+ if(z && p == data)
return nil;
q = emalloc(p-data + 1);
memmove(q, data, p-data);
@@ -92,26 +92,26 @@
return nil;
p = info;
- m->from = line(p, &p);
- m->to = line(p, &p);
- m->cc = line(p, &p);
- m->replyto = line(p, &p);
- m->date = line(p, &p);
- m->subject = line(p, &p);
- m->type = line(p, &p);
- m->disposition = line(p, &p);
- m->filename = line(p, &p);
- m->digest = line(p, &p);
- /* m->bcc = */ free(line(p, &p));
- m->inreplyto = line(p, &p);
- /* m->date = */ free(line(p, &p));
- /* m->sender = */ free(line(p, &p));
- m->messageid = line(p, &p);
- /* m->lines = */ free(line(p, &p));
- /* m->size = */ free(line(p, &p));
- m->mflags = line(p, &p);
- /* m->fileid = */ free(line(p, &p));
- m->fromcolon = fc(m, line(p, &p));
+ m->from = line(p, &p, 0);
+ m->to = line(p, &p, 0);
+ m->cc = line(p, &p, 0);
+ m->replyto = line(p, &p, 1);
+ m->date = line(p, &p, 0);
+ m->subject = line(p, &p, 0);
+ m->type = line(p, &p, 1);
+ m->disposition = line(p, &p, 1);
+ m->filename = line(p, &p, 1);
+ m->digest = line(p, &p, 1);
+ /* m->bcc = */ free(line(p, &p, 1));
+ m->inreplyto = line(p, &p, 1);
+ /* m->date = */ free(line(p, &p, 1));
+ /* m->sender = */ free(line(p, &p, 1));
+ m->messageid = line(p, &p, 0);
+ /* m->lines = */ free(line(p, &p, 1));
+ /* m->size = */ free(line(p, &p, 1));
+ m->mflags = line(p, &p, 0);
+ /* m->fileid = */ free(line(p, &p, 1));
+ m->fromcolon = fc(m, line(p, &p, 0));
free(info);
m->flags = Funseen;
@@ -187,6 +187,18 @@
}
static void
+delmesg(Mesg *m, char **, int nf)
+{
+ if(nf != 0){
+ fprint(2, "Delmesg: too many args\n");
+ return;
+ }
+ m->flags |= Ftodel;
+ m->quitting = 1;
+ mbredraw(m, 0, 0);
+}
+
+static void
mesgquit(Mesg *m, char **, int)
{
m->quitting = 1;
@@ -195,7 +207,7 @@
static Fn mesgfn[] = {
{"Q", qreply},
{"Reply", reply},
-// {"Delmesg", delmesg},
+ {"Delmesg", delmesg},
{"Save", nil},
{"Del", mesgquit},
{nil}
@@ -224,7 +236,6 @@
while(!m->quitting){
if(winevent(m, &ev) != 'M')
continue;
- fprint(2, "%s\n", ev.text);
if(strcmp(ev.text, "Del") == 0)
break;
switch(ev.type){