9front - general discussion about 9front
 help / color / mirror / Atom feed
From: theinicke@bss-wf.de
To: 9front@9front.org
Subject: Re: [9front] Mail rewrite; open path with stored mails
Date: Sat, 13 Feb 2021 21:47:28 +0100	[thread overview]
Message-ID: <BF6929917AD38CA49CD5644CD08A22AC@bss-wf.de> (raw)
In-Reply-To: <562F53FC1768DE07BE3E1B6416200AEC@eigenstate.org>

Quoth ori@eigenstate.org:
> Quoth theinicke@bss-wf.de:
> > I have noticed that Mail/Nail does no longer open additional mailboxes if passed a path [containing mails as undecoded MIME messages]. Now I am wondering whether this is by design or it is desirable to reintroduce this.
> > 
> > That said I can imagine some possibilities for reintroduction:
> > 
> > 1) change argv parsing to interpret argument like old Mail did (e.g. mbox | path)
> > 1a) also reintroduce second optional argument to open mailbox with given mboxname - imho unnecessary, but backwards compatibility?
> > 2) introduce this via an additional parameter
> > 3) just do it using a script
> 
> The goal wasn't for perfect compatibility,
> but I have nothing against the feature. I
> just didn't use it, and nobody complained
> that it was gone until now.
> 
> I'd be happy to take a patch for this.

Thank you for your reply and sorry for the noise of accidentally sending multiple mails, I have inlined a patch which introduces it via a new parameter. Compared to old Mail this allows us to work with relative paths (on fs).

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 21:40:11 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.
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 21:39:50 2021 +0100
@@ -32,6 +32,8 @@
 
 Reprog	*mesgpat;
 
+int	openedmbox = 0;
+
 int	threadsort = 1;
 int	sender;
 
@@ -51,8 +53,9 @@
 	Plumbmsg *m;
 
 	while(1){
-		if((m = plumbrecv(fd)) == nil)
+		if((m = plumbrecv(fd)) == nil) {
 			threadexitsall("plumber gone");
+		}
 		sendp(ch, m);
 	}
 }
@@ -672,17 +675,26 @@
 	}
 }
 
+static int
+openctlfile(void)
+{
+	int fd;
+	char *path;
+
+	path = estrjoin(maildir, "/ctl", nil);
+	fd = open(path, OWRITE);
+	free(path);
+	return fd;
+}
+
 static void
 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){
@@ -753,6 +765,22 @@
 }
 
 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
 quitall(char **, int)
 {
 	Mesg *m;
@@ -768,6 +796,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 +1004,81 @@
 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();


  reply	other threads:[~2021-02-13 20:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 20:54 theinicke
2021-02-12 21:10 ` ori
2021-02-13 20:47   ` theinicke [this message]
2021-02-13 21:25     ` theinicke
2021-02-13 23:59       ` Alex Musolino
2021-02-14 10:42         ` theinicke
2021-02-14 20:57           ` ori
2021-02-14 22:05             ` theinicke
2021-02-14 22:55           ` Alex Musolino
2021-02-15  8:15             ` theinicke
2021-02-15  9:56               ` theinicke
  -- strict thread matches above, loose matches on Subject: below --
2021-02-12 20:50 [9front] Mail rewrite " theinicke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BF6929917AD38CA49CD5644CD08A22AC@bss-wf.de \
    --to=theinicke@bss-wf.de \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).