ref: 88d2711854dfdf65900d9001bf7ee9c78f46ee6a
parent: 6092354e9384faab64454e7f6b1c9ead84676f90
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Nov 3 20:06:53 EST 2020
deletion: finish implementation
--- a/mbox.c
+++ b/mbox.c
@@ -24,7 +24,7 @@
char *maildir = "/mail/fs";
-char *mailbox = "mbox";
+char *mailbox = "tmptest";
Mesg dead = {.messageid="", .hash=42};
Reprog *addrpat;
@@ -251,7 +251,7 @@
idx = slotfor(m);
else
idx = mbox.nmesg;
- memmove(&mbox.mesg[idx + 1], &mbox.mesg[idx], mbox.nmesg - idx);
+ memmove(&mbox.mesg[idx + 1], &mbox.mesg[idx], (mbox.nmesg - idx)*sizeof(Mesg*));
mbox.mesg[idx] = m;
mbox.nmesg++;
if(m->messageid == nil)
@@ -506,7 +506,7 @@
for(i = 0; i < m->nchild; i++){
c = m->child[i];
c->parent = nil;
- if(c->parent != nil)
+ if(p != nil)
addchild(p, c);
else
c->flags |= Ftoplev;
@@ -516,30 +516,39 @@
static void
mbflush(char **, int)
{
- Mesg *m, **p;
- int i, j, ln;
+ int i, j, ln, fd;
+ char *path;
+ Mesg *m;
- p = mbox.mesg;
- for(i = 0; i < mbox.nmesg; i++){
+ i = 0;
+ path = estrjoin(maildir, "/ctl", nil);
+ fd = open(path, OWRITE);
+ free(path);
+ if(fd == -1)
+ sysfatal("open mbox: %r");
+ while(i < mbox.nmesg){
m = mbox.mesg[i];
if((m->flags & Fopen) || !(m->flags & (Fdel|Ftodel))){
- *p++ = m;
+ i++;
continue;
}
ln = mesglineno(m, nil);
+ fprint(2, "remove %s@%d,%d\n", m->name, ln+1, ln+1+m->nsub);
fprint(mbox.addr, "%d,%d", ln+1, ln+1+m->nsub);
write(mbox.data, "", 0);
+ if(m->flags & Ftodel)
+ fprint(fd, "delete %s %d", mailbox, atoi(m->name));
removemesg(m);
removeid(m);
for(j = 0; j < m->nchild; j++)
mbredraw(m->child[j], 1, 1);
- // if(m->flags & Ftodel)
- // deletemesg(m);
mesgfree(m);
-
- *p = m;
+ memmove(&mbox.mesg[i], &mbox.mesg[i+1], (mbox.nmesg - i)*sizeof(Mesg*));
+ mbox.nmesg--;
}
+ close(fd);
+
}
static void
@@ -603,9 +612,10 @@
static void
mbquit(char **, int)
{
- if(mbox.nopen == 0)
- threadexitsall(nil);
- fprint(2, "Del: %d open messages", mbox.nopen);
+ if(mbox.nopen > 0)
+ fprint(2, "Del: %d open messages", mbox.nopen);
+ winclose(&mbox);
+ threadexitsall(nil);
}
static void