9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Risto Salminen <risto.salminen@gmx.com>
To: 9front@9front.org
Subject: Re: [9front] upas/nedmail: copy messages between IMAP folders
Date: Mon, 31 May 2021 14:52:41 +0300
Message-ID: <FB860DAC14F3219FF89080D47C4633A1@gmx.com> (raw)
In-Reply-To: <971EAFFF76D75B465FE8AE28F208FAB9@gmx.com>

Hello,

this second iteration of the nedmail patch
uses the functionality of moving messages
between IMAP folders provided by the second
iteration of the upas/fs patch.

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	Mon May 31 14:00:43 2021 +0300
@@ -184,6 +184,10 @@
 but allow the user to type in text to be included
 with the forwarded message.
 .TP
+.BI move " mbox
+Move message to the named mailbox.
+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	Mon May 31 14:00:43 2021 +0300
@@ -106,6 +106,7 @@
 Mfn	kcmd;
 Mfn	mbcmd;
 Mfn	mcmd;
+Mfn	movecmd;
 Mfn	Pcmd;
 Mfn	pcmd;
 Mfn	pipecmd;
@@ -143,6 +144,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 +2408,44 @@
 	return m;
 }

+Message*
+movecmd(Cmd *c, Message *m)
+{
+	char buf[1024], *dest, *e, *p, *msg;
+	int fd;
+
+	if(c->an != 2){
+		eprint("!usage: move 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, "move %s %s %s", mbname, msg, dest);
+	if(write(fd, buf, p - buf) < 0){
+		eprint("!error %r\n");
+		close(fd);
+		return nil;
+	}
+	eprint("!moved to %s\n", dest);
+	m->flags |= Fdeleted;
+	m->flags |= Fstored;
+	close(fd);
+	return m;
+}
+
 int
 appendtofile(Message *m, char *part, char *base, int mbox, int f)
 {

      reply	other threads:[~2021-05-31 18:23 UTC|newest]

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

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=FB860DAC14F3219FF89080D47C4633A1@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