From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 11151 invoked from network); 13 Feb 2021 21:37:11 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 13 Feb 2021 21:37:11 -0000 Received: from outgoing.selfhost.de ([82.98.82.6]) by 1ess; Sat Feb 13 16:32:33 -0500 2021 Received: (qmail 23648 invoked from network); 13 Feb 2021 21:25:36 -0000 Received: from unknown (HELO mx03.bss-wf.de) (postmaster@emdtgvmf.mail.selfhost.de@84.150.39.186) by mailout.selfhost.de with ESMTPA; 13 Feb 2021 21:25:36 -0000 Received: by mx03.bss-wf.de (Postfix, from userid 1000) id 6DF4D3DD76; Sat, 13 Feb 2021 22:25:36 +0100 (CET) Received: from 9pi.pala (p5b3bcb58.dip0.t-ipconnect.de [91.59.203.88]) by mx03.bss-wf.de (Postfix) with ESMTPSA id 861A03DD74 for <9front@9front.org>; Sat, 13 Feb 2021 22:25:34 +0100 (CET) Message-ID: <24F3DAD837016D50611A75FC8848645C@bss-wf.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit To: 9front@9front.org Date: Sat, 13 Feb 2021 22:25:33 +0100 From: theinicke@bss-wf.de In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: virtual reduce/map session ActivityPub descriptor polling API Subject: Re: [9front] Mail rewrite; open path with stored mails Reply-To: 9front@9front.org Precedence: bulk Sorry - please consider following patch instead, as it also attempts to close opened mailbox, if Mail exits due to plumber being gone. -- Tobias Heinicke diff -r 02e3059af5bc sys/src/cmd/upas/Mail/mbox.c --- a/sys/src/cmd/upas/Mail/mbox.c Thu Feb 11 09:37:36 2021 +0100 +++ b/sys/src/cmd/upas/Mail/mbox.c Sat Feb 13 22:21:29 2021 +0100 @@ -32,6 +32,8 @@ Reprog *mesgpat; +int openedmbox = 0; + int threadsort = 1; int sender; @@ -45,14 +47,44 @@ static void showmesg(Biobuf*, Mesg*, int, int); +static int +openctlfile(void) +{ + int fd; + char *path; + + path = estrjoin(maildir, "/ctl", nil); + fd = open(path, OWRITE); + free(path); + return fd; +} + +static void +removeopened(void) +{ + int fd; + char buf[256]; + + if(!openedmbox) + return; + fd = openctlfile(); + if(fd == -1) + return; + + snprint(buf, sizeof buf, "close %s", mailbox); + write(fd, buf, strlen(buf)); +} + static void plumbloop(Channel *ch, int fd) { Plumbmsg *m; while(1){ - if((m = plumbrecv(fd)) == nil) + if((m = plumbrecv(fd)) == nil) { + removeopened(); threadexitsall("plumber gone"); + } sendp(ch, m); } } @@ -676,13 +708,10 @@ mbflush(char **, int) { int i, j, ln, fd; - char *path; Mesg *m, *p; i = 0; - path = estrjoin(maildir, "/ctl", nil); - fd = open(path, OWRITE); - free(path); + fd = openctlfile(); if(fd == -1) sysfatal("open mbox: %r"); while(i < mbox.nmesg){ @@ -768,6 +797,7 @@ for(c = mbox.opencomp; c != nil; c = c->qnext) fprint(c->ctl, "del\n"); fprint(mbox.ctl, "del\n"); + removeopened(); threadexitsall(nil); } @@ -975,15 +1005,80 @@ static void usage(void) { - fprint(2, "usage: %s [-T] [-m mailfs] [-s] [-f format] [mbox]\n", argv0); + fprint(2, "usage: %s [-T] [-m mailfs] [-s] [-f format] [-d path] [mbox]\n", argv0); exits("usage"); } +static void +openmbox(char *path, char *mboxname) +{ + int fd, i; + char buf[512], err[ERRMAX]; + char *name, *fsname, *s1, *s2, *abspath; + + /* if path is already absolute, leave it as it is - to allow /imap... + otherwise get absolute path from relative one */ + if(*path == '/'){ + i = strlen(path); + if(path[i-1] == '/') + path[i-1] = '\0'; + abspath = estrdup(path); + }else{ + fd = open(path, OREAD); + if(fd < 0) + sysfatal("can't open %s: %r", path); + + if(fd2path(fd, buf, sizeof buf) != 0) + sysfatal("fd2path %s: %r", path); + close(fd); + abspath = estrdup(buf); + } + + if(mboxname != nil) + name = mboxname; + else{ + s1 = strrchr(abspath, '/'); + if(s1 == nil) + name = abspath; + else{ + *s1++ = '\0'; + name = s1; + *--s1 = '/'; + } + } + + fd = openctlfile(); + if(fd == -1) + sysfatal("open mbox: %r"); + fsname = estrdup(name); + s2 = emalloc(5+strlen(abspath)+1+strlen(fsname)+2+1); + for(i=0; i<10; i++){ + sprint(s2, "open %s %s", abspath, fsname); + if(write(fd, s2, strlen(s2)) >= 0) + break; + err[0] = '\0'; + errstr(err, sizeof err); + if(strstr(err, "mbox name in use") == nil) + sysfatal("can't create directory %s for mail: %s", name, err); + free(fsname); + fsname = emalloc(strlen(name)+3); + sprint(fsname, "%s-%d", name, i); + } + if(i == 10) + sysfatal("can't open %s: %r", abspath); + mailbox = fsname; + openedmbox = 1; + free(s2); + free(abspath); + close(fd); +} + void threadmain(int argc, char **argv) { Fmt fmt; char *cmd; + char *path = nil, *mboxname = nil; int i; mbox.view = Vgroup; @@ -1017,6 +1112,9 @@ case 'o': savebox = EARGF(usage()); break; + case 'd': + path = EARGF(usage()); + break; default: usage(); break; @@ -1024,8 +1122,13 @@ if(argc > 1) usage(); - if(argc == 1) + if(argc == 1) { mailbox = argv[0]; + mboxname = mailbox; + } + + if(path != nil) + openmbox(path, mboxname); mesgpat = regcomp("([0-9]+)(/.*)?"); cwait = threadwaitchan(); diff -r 02e3059af5bc sys/man/1/acmemail --- a/sys/man/1/acmemail Thu Feb 11 09:37:36 2021 +0100 +++ b/sys/man/1/acmemail Sat Feb 13 22:23:35 2021 +0100 @@ -20,6 +20,10 @@ .B -o .I outbox ] +[ +.B -d +.I path +] .SH DESCRIPTION .PP @@ -64,6 +68,10 @@ Save a copy of outgoing messages to the mailbox .IR outbox , instead of discarding them after they're enqueued. +.TP +.BI -d " path +Opens new mailbox for the given path, +closes it on exit. .PP Mail presents and acme interface for a upas/fs mailbox.