9front - general discussion about 9front
 help / color / mirror / Atom feed
From: kjn@9project.net
To: 9front@9front.org
Subject: Re: [9front] upas/fs: copy messages between IMAP folders
Date: Fri, 28 May 2021 17:11:32 -0500	[thread overview]
Message-ID: <4D7FA5D61E1F603FA532CC77D395BC31@gmail.com> (raw)
In-Reply-To: <DE80C2698084EB406F696B6B608A8851@gmx.com>

Quoth risto.salminen@gmx.com:
> Dear 9front community,
> 
> it is currently not possible to copy messages between
> IMAP folders in any way using upas, if I understand
> correctly.  upas/fs does not support putting messages
> to the mailbox directories in /mail/fs/.  The need for
> this arises when someone wants to archive messages
> from inbox to another IMAP folder.
> 
> The following patch attempts to implement the support
> for copying messages between IMAP folders in a similar
> way in which flagging and deleting messages are handled.
> The same functionality could be extended to other mailbox
> types too, although it seems that currently this is only
> useful with IMAP.  I have been using this for half a year
> now without any problems.
> 
> The alternative way to achieve the same result would
> be to make upas/fs support writing files to the
> /mail/fs/ folders.  Then perhaps upas/mbappend could
> be used to write messages to these folders in the same
> way as it can currently be used to write messages to
> the /mail/box/ folders.  However, the message numbering
> schemes are different between these two folder
> hierarchies, so there would have to be some special
> casing for that, which would complicate things.
> Implementing the feature that way would seem to be
> more challenging in other ways too, which is why I am
> presenting a simpler approach.
> 
> 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	Fri May 28 16:40:56 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 copy 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 "copy \fImboxname number ... target\fP
> +Copy 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	Fri May 28 16:40:56 2021 +0300
> @@ -174,6 +174,7 @@
>  	void	(*decache)(Mailbox*, Message*);
>  	int	(*fetch)(Mailbox*, Message*, uvlong, ulong);
>  	void	(*delete)(Mailbox*, Message*);
> +	char	*(*copy)(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*		copymessages(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	Fri May 28 16:40:56 2021 +0300
> @@ -1242,6 +1242,11 @@
>  				return nil;
>  			return flagmessages(argc - 1, argv + 1);
>  		}
> +		if(strcmp(argv[0], "copy") == 0){
> +			if(argc < 4)
> +				return nil;
> +			return copymessages(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	Fri May 28 16:40:56 2021 +0300
> @@ -1025,6 +1025,22 @@
>  }
> 
>  static char*
> +imap4copy(Mailbox *mb, Message *m, char *dest)
> +{
> +	char *r;
> +	Imap *imap;
> +
> +	imap = mb->aux;
> +	if((ulong)(m->imapuid>>32) == imap->validity){
> +		imap4cmd(imap, "uid copy %lud %s", (ulong)m->imapuid, dest);
> +		r = imap4resp(imap);
> +		if(!isokay(r))
> +			return r;
> +	}
> +	return 0;
> +}
> +
> +static char*
>  imap4sync(Mailbox *mb)
>  {
>  	char *err;
> @@ -1183,6 +1199,7 @@
>  	mb->delete = imap4delete;
>  	mb->rename = imap4rename;
>  	mb->modflags = imap4modflags;
> +	mb->copy = imap4copy;
>  	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	Fri May 28 16:40:56 2021 +0300
> @@ -1137,6 +1137,31 @@
>  	return rerr;
>  }
> 
> +char*
> +copymessages(int argc, char **argv)
> +{
> +	char *err, *dest, *rerr;
> +	int i;
> +	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->copy == nil)
> +		return "copy not supported";
> +	dest = argv[argc - 1];
> +	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->copy(mb, m, dest))
> +					rerr = err;
> +	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	Fri May 28 16:40:56 2021 +0300
> @@ -294,5 +294,6 @@
>  	mb->idxread = idxr;
>  	mb->idxwrite = idxw;
>  	mb->ctl = mdirctl;
> +	mb->copy = 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	Fri May 28 16:40:56 2021 +0300
> @@ -411,5 +411,6 @@
>  	mb->remove = localremove;
>  	mb->rename = localrename;
>  	mb->decache = plan9decache;
> +	mb->copy = 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	Fri May 28 16:40:56 2021 +0300
> @@ -624,6 +624,7 @@
>  	mb->sync = pop3sync;
>  	mb->close = pop3close;
>  	mb->ctl = pop3ctl;
> +	mb->copy = nil;
>  	mb->addfrom = 1;
>  	return nil;
>  }

I have not tried out the patch, but I definitely have a use for
copying messages from one imap folder to another.  That's one
remaining critical feature that I miss with mail on 9front.

-- Kyle


  parent reply	other threads:[~2021-05-28 22:26 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 [this message]
2021-05-31 11:41 ` Risto Salminen
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=4D7FA5D61E1F603FA532CC77D395BC31@gmail.com \
    --to=kjn@9project.net \
    --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).