* [9front] upas/nedmail: copy messages between IMAP folders
@ 2021-05-28 15:25 risto.salminen
2021-05-31 11:52 ` Risto Salminen
0 siblings, 1 reply; 2+ messages in thread
From: risto.salminen @ 2021-05-28 15:25 UTC (permalink / raw)
To: 9front
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)
{
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [9front] upas/nedmail: copy messages between IMAP folders
2021-05-28 15:25 [9front] upas/nedmail: copy messages between IMAP folders risto.salminen
@ 2021-05-31 11:52 ` Risto Salminen
0 siblings, 0 replies; 2+ messages in thread
From: Risto Salminen @ 2021-05-31 11:52 UTC (permalink / raw)
To: 9front
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)
{
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-31 18:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28 15:25 [9front] upas/nedmail: copy messages between IMAP folders risto.salminen
2021-05-31 11:52 ` Risto Salminen
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).