]> git.lizzy.rs Git - plan9front.git/commitdiff
Mail: revert 096538d64724
authorOri Bernstein <ori@eigenstate.org>
Tue, 2 Mar 2021 03:23:13 +0000 (19:23 -0800)
committerOri Bernstein <ori@eigenstate.org>
Tue, 2 Mar 2021 03:23:13 +0000 (19:23 -0800)
sys/src/cmd/upas/Mail/mbox.c

index b32c9b6a481429268d31e767c5789be5a9476b18..5b05dc52913b0bc2f183fc4c99c4186819d344cf 100644 (file)
@@ -260,15 +260,13 @@ addmesg(Mesg *m, int ins)
                mbox.mesgsz *= 2;
                mbox.mesg = erealloc(mbox.mesg, mbox.mesgsz*sizeof(Mesg*));
        }
-       if(ins >= 0){
-               if(ins == 0)
-                       idx = slotfor(m);
-               else
-                       idx = mbox.nmesg;
-               memmove(&mbox.mesg[idx + 1], &mbox.mesg[idx], (mbox.nmesg - idx)*sizeof(Mesg*));
-               mbox.mesg[idx] = m;
-               mbox.nmesg++;
-       }
+       if(ins)
+               idx = slotfor(m);
+       else
+               idx = mbox.nmesg;
+       memmove(&mbox.mesg[idx + 1], &mbox.mesg[idx], (mbox.nmesg - idx)*sizeof(Mesg*));
+       mbox.mesg[idx] = m;
+       mbox.nmesg++;
        if(m->messageid == nil)
                return;
 
@@ -298,7 +296,7 @@ addmesg(Mesg *m, int ins)
 }
 
 static Mesg *
-placeholder(char *msgid, vlong time)
+placeholder(char *msgid, vlong time, int ins)
 {
        Mesg *m;
 
@@ -307,6 +305,7 @@ placeholder(char *msgid, vlong time)
        m->messageid = estrdup(msgid);
        m->hash = strhash(msgid);
        m->time = time;
+       addmesg(m, ins);
        return m;
 }
 
@@ -382,10 +381,8 @@ load(char *name, char *digest, int ins)
                return m;
        }
        p = lookupid(m->inreplyto);
-       if(p == nil){
-               p = placeholder(m->inreplyto, m->time);
-               addmesg(m, ins);
-       }
+       if(p == nil)
+               p = placeholder(m->inreplyto, m->time, ins);
        if(!addchild(p, m, d))
                m->state |= Stoplev;
        return m;
@@ -659,8 +656,6 @@ relinkmsg(Mesg *p, Mesg *m)
 
        /* remove child, preserving order */
        j = 0;
-       if(p == nil || m == nil)
-               return;
        for(i = 0; p && i < p->nchild; i++){
                if(p->child[i] != m)
                        p->child[j++] = p->child[i];
@@ -680,7 +675,7 @@ relinkmsg(Mesg *p, Mesg *m)
 static void
 mbflush(char **, int)
 {
-       int i, j, ln, fd, dummy;
+       int i, j, ln, fd;
        char *path;
        Mesg *m, *p;
 
@@ -692,7 +687,7 @@ mbflush(char **, int)
                sysfatal("open mbox: %r");
        while(i < mbox.nmesg){
                m = mbox.mesg[i];
-               if((m->state & (Sopen|Sdummy)) || !(m->flags & (Fdel|Ftodel))){
+               if((m->state & Sopen) || !(m->flags & (Fdel|Ftodel))){
                        i++;
                        continue;
                }
@@ -703,23 +698,18 @@ mbflush(char **, int)
                        fprint(fd, "delete %s %d", mailbox, atoi(m->name));
 
                p = m->parent;
-               dummy = 0;
                removeid(m);
                if(p == nil && m->nsub != 0){
-                       p = placeholder(m->messageid, m->time);
+                       p = placeholder(m->messageid, m->time, 1);
                        p->nsub = m->nsub + 1;
-                       addmesg(p, -1);
                        mbox.mesg[i] = p;
-                       dummy = 1;
                }
-               relinkmsg(p, m);
+               if(p != nil)
+                       relinkmsg(p, m);
                for(j = 0; j < m->nchild; j++)
                        mbredraw(m->child[j], 1, 1);
-               if(!dummy){
-                       memmove(&mbox.mesg[i], &mbox.mesg[i+1], (mbox.nmesg - i)*sizeof(Mesg*));
-                       mbox.nmesg--;
-               }
-               mesgfree(m);
+               memmove(&mbox.mesg[i], &mbox.mesg[i+1], (mbox.nmesg - i)*sizeof(Mesg*));
+               mbox.nmesg--;
        }
        close(fd);
        fprint(mbox.ctl, "clean\n");