From: Risto Salminen <risto.salminen@gmx.com>
To: 9front@9front.org
Subject: Re: [9front] upas/fs: copy messages between IMAP folders
Date: Mon, 31 May 2021 14:41:33 +0300 [thread overview]
Message-ID: <ABB51871899F04B440C9A23EFBA6F1A7@gmx.com> (raw)
In-Reply-To: <DE80C2698084EB406F696B6B608A8851@gmx.com>
Hello,
another iteration of the patch only but simply
allows one to move, and not copy, messages
inside a IMAP server from a folder to another
folder. This simplifies the MUA's, for example
nedmail's, duties, as it does not have to
separately delete the moved mail anymore.
Would this be useful for the broader audience?
Thanks,
rsal
diff -r 7c895ae504fa sys/man/4/upasfs
--- a/sys/man/4/upasfs Fri May 28 13:02:58 2021 +0200
+++ b/sys/man/4/upasfs Mon May 31 13:55:01 2021 +0300
@@ -206,7 +206,7 @@
.I fs
to open, close, rename, create or remove new mailboxes,
and also to
-delete or flag groups of messages atomically.
+delete, flag, or move groups of messages atomically.
The messages that can be written to this file are:
.TP 2i
.PD 0
@@ -260,6 +260,13 @@
.TP
.B "flag \fImboxname flags number ...\fP
flag the given messages.
+.TP
+.B "move \fImboxname number ... target\fP
+Move the given messages from
+.IR mboxname
+to mailbox named
+.IR target.
+At the moment only supported with IMAP mailboxes.
.PD
.PP
The
diff -r 7c895ae504fa sys/src/cmd/upas/fs/dat.h
--- a/sys/src/cmd/upas/fs/dat.h Fri May 28 13:02:58 2021 +0200
+++ b/sys/src/cmd/upas/fs/dat.h Mon May 31 13:55:01 2021 +0300
@@ -174,6 +174,7 @@
void (*decache)(Mailbox*, Message*);
int (*fetch)(Mailbox*, Message*, uvlong, ulong);
void (*delete)(Mailbox*, Message*);
+ char *(*move)(Mailbox*, Message*, char*);
char *(*ctl)(Mailbox*, int, char**);
char *(*remove)(Mailbox *, int);
char *(*rename)(Mailbox*, char*, int);
@@ -215,6 +216,7 @@
void unnewmessage(Mailbox*, Message*, Message*);
char* delmessages(int, char**);
char *flagmessages(int, char**);
+char* movemessages(int, char**);
void digestmessage(Mailbox*, Message*);
int wraptls(int, char*);
diff -r 7c895ae504fa sys/src/cmd/upas/fs/fs.c
--- a/sys/src/cmd/upas/fs/fs.c Fri May 28 13:02:58 2021 +0200
+++ b/sys/src/cmd/upas/fs/fs.c Mon May 31 13:55:01 2021 +0300
@@ -1242,6 +1242,11 @@
return nil;
return flagmessages(argc - 1, argv + 1);
}
+ if(strcmp(argv[0], "move") == 0){
+ if(argc < 4)
+ return nil;
+ return movemessages(argc - 1, argv + 1);
+ }
if(strcmp(argv[0], "remove") == 0){
v0 = argv0;
flags = 0;
diff -r 7c895ae504fa sys/src/cmd/upas/fs/imap.c
--- a/sys/src/cmd/upas/fs/imap.c Fri May 28 13:02:58 2021 +0200
+++ b/sys/src/cmd/upas/fs/imap.c Mon May 31 13:55:01 2021 +0300
@@ -1025,6 +1025,29 @@
}
static char*
+imap4move(Mailbox *mb, Message *m, char *dest)
+{
+ char *r;
+ Imap *imap;
+
+ imap = mb->aux;
+ imap4cmd(imap, "uid copy %lud %s", (ulong)m->imapuid, dest);
+ r = imap4resp(imap);
+ if(!isokay(r))
+ return r;
+ imap4cmd(imap, "uid store %lud +flags (\\Deleted)", (ulong)m->imapuid);
+ r = imap4resp(imap);
+ if(!isokay(r))
+ return r;
+ imap4cmd(imap, "expunge");
+ r = imap4resp(imap);
+ if(!isokay(r))
+ return r;
+ m->inmbox = 0;
+ return 0;
+}
+
+static char*
imap4sync(Mailbox *mb)
{
char *err;
@@ -1183,6 +1206,7 @@
mb->delete = imap4delete;
mb->rename = imap4rename;
mb->modflags = imap4modflags;
+ mb->move = imap4move;
mb->addfrom = 1;
return nil;
}
diff -r 7c895ae504fa sys/src/cmd/upas/fs/mbox.c
--- a/sys/src/cmd/upas/fs/mbox.c Fri May 28 13:02:58 2021 +0200
+++ b/sys/src/cmd/upas/fs/mbox.c Mon May 31 13:55:01 2021 +0300
@@ -1137,6 +1137,37 @@
return rerr;
}
+char*
+movemessages(int argc, char **argv)
+{
+ char *err, *dest, *rerr;
+ int i, needwrite;
+ Mailbox *mb;
+ Message *m;
+
+ rerr = 0;
+ for(mb = mbl; mb != nil; mb = mb->next)
+ if(strcmp(*argv, mb->name) == 0)
+ break;
+ if(mb == nil)
+ return "no such mailbox";
+ if(mb->move == nil)
+ return "move not supported";
+ dest = argv[argc - 1];
+ needwrite = 0;
+ for(i = 1; i < argc - 1; i++)
+ for(m = mb->root->part; m; m = m->next)
+ if(strcmp(m->name, argv[i]) == 0){
+ if(err = mb->move(mb, m, dest))
+ rerr = err;
+ else
+ needwrite = 1;
+ }
+ if(needwrite)
+ syncmbox(mb, 1);
+ return rerr;
+}
+
void
msgincref(Mailbox *mb, Message *m)
{
diff -r 7c895ae504fa sys/src/cmd/upas/fs/mdir.c
--- a/sys/src/cmd/upas/fs/mdir.c Fri May 28 13:02:58 2021 +0200
+++ b/sys/src/cmd/upas/fs/mdir.c Mon May 31 13:55:01 2021 +0300
@@ -294,5 +294,6 @@
mb->idxread = idxr;
mb->idxwrite = idxw;
mb->ctl = mdirctl;
+ mb->move = nil;
return nil;
}
diff -r 7c895ae504fa sys/src/cmd/upas/fs/plan9.c
--- a/sys/src/cmd/upas/fs/plan9.c Fri May 28 13:02:58 2021 +0200
+++ b/sys/src/cmd/upas/fs/plan9.c Mon May 31 13:55:01 2021 +0300
@@ -411,5 +411,6 @@
mb->remove = localremove;
mb->rename = localrename;
mb->decache = plan9decache;
+ mb->move = nil;
return nil;
}
diff -r 7c895ae504fa sys/src/cmd/upas/fs/pop3.c
--- a/sys/src/cmd/upas/fs/pop3.c Fri May 28 13:02:58 2021 +0200
+++ b/sys/src/cmd/upas/fs/pop3.c Mon May 31 13:55:01 2021 +0300
@@ -624,6 +624,7 @@
mb->sync = pop3sync;
mb->close = pop3close;
mb->ctl = pop3ctl;
+ mb->move = nil;
mb->addfrom = 1;
return nil;
}
next prev parent reply other threads:[~2021-05-31 16:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-28 15:10 risto.salminen
2021-05-28 15:29 ` Stanley Lieber
2021-05-28 16:26 ` risto.salminen
2021-05-29 3:50 ` Stanley Lieber
2021-05-29 9:44 ` risto.salminen
2021-05-29 21:41 ` Lyndon Nerenberg (VE7TFX/VE6BBM)
2021-05-31 11:31 ` Risto Salminen
2021-05-31 22:34 ` Lyndon Nerenberg (VE7TFX/VE6BBM)
2021-05-28 22:11 ` kjn
2021-05-31 11:41 ` Risto Salminen [this message]
2021-06-09 21:41 ` igor
2021-06-10 11:02 ` 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=ABB51871899F04B440C9A23EFBA6F1A7@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
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).