9front - general discussion about 9front
 help / color / mirror / Atom feed
From: risto.salminen@gmx.com
To: 9front@9front.org
Subject: [9front] upas/nedmail: copy messages between IMAP folders
Date: Fri, 28 May 2021 18:25:41 +0300
Message-ID: <971EAFFF76D75B465FE8AE28F208FAB9@gmx.com> (raw)

Dear 9front community,

the following patch makes nedmail to take advantage
of the message copy support introduced in my previous
mail.  This is useful when one wants to archive
messages from inbox to another IMAP folder.  I have
been using this for half a year now, as the upas/fs
part of the changes too.

Would this be useful for the broader audience?

Thanks,
rsal

diff -r 7c895ae504fa sys/man/1/nedmail
--- a/sys/man/1/nedmail	Fri May 28 13:02:58 2021 +0200
+++ b/sys/man/1/nedmail	Fri May 28 16:57:27 2021 +0300
@@ -153,6 +153,10 @@
 .B b
 Print the headers for the next ten messages.
 .TP
+.BI c " mbox
+Copy message to the named mailbox.
+At the moment only supported with IMAP mailboxes.
+.TP
 .B d
 Mark message to be deleted upon exiting
 .IR nedmail .
@@ -184,6 +188,16 @@
 but allow the user to type in text to be included
 with the forwarded message.
 .TP
+.BI move " mbox
+Copy message to the named mailbox
+and mark it as deleted.
+This is just
+.B c
+followed by
+.B d
+for convenience.
+At the moment only supported with IMAP mailboxes.
+.TP
 .B p
 Print message.
 An interrupt stops the printing.
diff -r 7c895ae504fa sys/src/cmd/upas/ned/nedmail.c
--- a/sys/src/cmd/upas/ned/nedmail.c	Fri May 28 13:02:58 2021 +0200
+++ b/sys/src/cmd/upas/ned/nedmail.c	Fri May 28 16:57:27 2021 +0300
@@ -93,6 +93,7 @@
 Mfn	acmd;
 Mfn	bangcmd;
 Mfn	bcmd;
+Mfn	ccmd;
 Mfn	dcmd;
 Mfn	eqcmd;
 Mfn	Fcmd;
@@ -106,6 +107,7 @@
 Mfn	kcmd;
 Mfn	mbcmd;
 Mfn	mcmd;
+Mfn	movecmd;
 Mfn	Pcmd;
 Mfn	pcmd;
 Mfn	pipecmd;
@@ -130,6 +132,7 @@
 	{ "a",	1, 1,	acmd,	"a\t"		"reply to sender and recipients" },
 	{ "A",	1, 0,	acmd,	"A\t"		"reply to sender and recipients with copy" },
 	{ "b",	0, 0,	bcmd,	"b\t"		"print the next 10 headers" },
+	{ "c",  1, 1,   ccmd,   "c mbox\t"		"copy message to mailbox" },
 	{ "d",	0, 1,	dcmd,	"d\t"		"mark for deletion" },
 	{ "F",	1, 1,	Fcmd,	"f\t"		"set message flags [+-][aDdfrSs]" },
 	{ "f",	0, 1,	fcmd,	"f\t"		"file message by from address" },
@@ -143,6 +146,7 @@
 	{ "m",	1, 1,	mcmd,	"m addr\t"	"forward mail" },
 	{ "M",	1, 0,	mcmd,	"M addr\t"	"forward mail with message" },
 	{ "mb",	1, 0,	mbcmd,	"mb mbox\t"	"switch mailboxes" },
+	{ "move", 1, 1, movecmd, "move mbox\t"	"move message to mailbox" },
 	{ "p",	1, 0,	pcmd,	"p\t"		"print the processed message" },
 	{ "P",	0, 0,	Pcmd,	"P\t"		"print the raw message" },
 	{ "\"",	0, 0,	quotecmd, "\"\t"		"print a quoted version of msg" },
@@ -2406,6 +2410,57 @@
 	return m;
 }

+Message*
+ccmd(Cmd *c, Message *m)
+{
+	char buf[1024], *dest, *e, *p, *msg;
+	int fd;
+
+	if(c->an != 2){
+		eprint("!usage: c mailbox\n");
+		return nil;
+	}
+	dest = c->av[1];
+	fd = open("/mail/fs/ctl", OWRITE);
+	if(fd < 0){
+		eprint("can't open /mail/fs/ctl: %r\n");
+		return nil;
+	}
+	while(m->parent != &top)
+		m = m->parent;
+	msg = strrchr(m->path, '/');
+	if(msg == nil)
+		msg = m->path;
+	else
+		msg++;
+	p = buf;
+	e = buf + sizeof buf;
+	p = seprint(p, e, "copy %s %s %s", mbname, msg, dest);
+	if(write(fd, buf, p - buf) < 0){
+		eprint("!error %r\n");
+		close(fd);
+		return nil;
+	}
+	eprint("!copied to %s\n", dest);
+	setflags(m, "S");
+	close(fd);
+	return m;
+}
+
+Message*
+movecmd(Cmd *c, Message *m)
+{
+	Message *r;
+
+	r = ccmd(c, m);
+	if(r == nil)
+		return nil;
+	r = dcmd(c, m);
+	if(r == nil)
+		return nil;
+	return r;
+}
+
 int
 appendtofile(Message *m, char *part, char *base, int mbox, int f)
 {

             reply	other threads:[~2021-05-28 15:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28 15:25 risto.salminen [this message]
2021-05-31 11:52 ` Risto Salminen

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=971EAFFF76D75B465FE8AE28F208FAB9@gmx.com \
    --to=risto.salminen@gmx.com \
    --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

9front - general discussion about 9front

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/9front

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 9front 9front/ http://inbox.vuxu.org/9front \
		9front@9front.org
	public-inbox-index 9front

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.9front


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git