Re: [PATCH] Implementing IncludeCmd (feature request #17)

2023-08-31 Thread Oswald Buddenhagen

On Thu, Aug 31, 2023 at 10:58:27AM +0200, Michiel van den Heuvel wrote:

so if you think it would be a good use of *your* time, then go ahead.


After some somewhat more synchronous communication, it might be.


are you asking for a chat channel?
i'm @ossi:kde.org on matrix, ossi on libera.chat irc (if the matrix 
bridge feels like working), and @ossilator on various social media and 
chat sites.
i could create an official project channel (on matrix?), but 
historically it seems a bit ... superfluous.



On the subject of more things I could do, is there a way to reproduce
the 2 regressions?

congrats, you forced me to actually research what the regressions are.  
*grumble* :-D


for the imap thing, i suspect any mail with a large enough attachment 
will do. maybe the imap compress extension needs to be in use, and/or 
tls. no idea.

(possibly) related threads:
https://sourceforge.net/p/isync/mailman/isync-devel/thread/Y00lhIm7VdrJzG/D%40ugly/#msg37721793
https://sourceforge.net/p/isync/mailman/isync-devel/thread/87h740x2xe.fsf%40wavexx.thregr.org/#msg37675548
https://sourceforge.net/p/isync/mailman/isync-devel/thread/87edk45p9o.fsf%40b3l.xyz/#msg37883904

for the other problem, there is 
https://sourceforge.net/p/isync/mailman/isync-devel/thread/f4d61b60-7a93-6b78-90d1-b96b285caa9c%40quaternum.net/#msg37708463 
which contains a speculative analysis.


there is https://sourceforge.net/p/isync/bugs/69/ which may be actually 
the same thing (sounds similar, but i'm not going to think about it at 
this time of day). it has a patch attached, which is certainly 
under-tested, and needs a sanity check, possibly resulting in a complete 
rewrite.


speaking of tested, if you _really_ wanted to go overboard, you could 
add a proper unit testing suite. so far only the core syncing algo is 
tested, in a way that is really an integration test (which has the 
advantage of testing a bit more as a side effect, but it's slow and 
inelegant). this would also nicely fit with formalizing the error 
reporting.



Subject: [PATCH] Add IncludeCmd directive to config parser

+static char *
+check_excess_tokens( conffile_t *cfile )
+{
+   char *arg = NULL;
+

i generally prefer early returns (and even goto) over temporaries.


int
getcline( conffile_t *cfile )
{
...
+   else if ((arg = check_excess_tokens( cfile )))
+   conf_error( cfile, "excess token '%s', not executing 
"
+   "potentially malformed command\n", 
arg );

my thinking was that the error message would be printed already by the 
check function (hence "check", not "get"). i don't think the extra 
verbosity about the specific consequence adds all that much value.

then the check function can just return an int.

oh, one thing i totally failed to notice: this is a noteworthy new 
feature, so it should get an entry in NEWS. something like "Added 
support for scripting arbitrary parts of the config file.", before the 
currently last two entries, i think.


and you should add yourself to the end of the main contributor list in 
AUTHORS.


regards


___
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel


Re: Restore after crash

2023-08-31 Thread Robert Bower

My situation is actually the oppisiate.

My Ubuntu machine was running 1.3 and the mint machine is running 1.4.

But I did copy over the .mbsync directory.

That is why I asked if I needed to redownload all my mail.

---
Thanks,

Robert Bower
W9RWB
WRPH745

On 2023-08-31 01:02, Oswald Buddenhagen wrote:

On Wed, Aug 30, 2023 at 11:16:47AM -0700, Robert Bower wrote:

Error: incompatible journal version (got 3, expected 4)

it means you downgraded isync. you need to build a newer version (1.4) 
yourself if there are no backports for your mint version.


regards


___
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel



___
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel


Re: Restore after crash

2023-08-31 Thread Oswald Buddenhagen

On Thu, Aug 31, 2023 at 06:54:06AM -0700, Robert Bower wrote:

My situation is actually the oppisiate.

My Ubuntu machine was running 1.3 and the mint machine is running 1.4.

right, the journal handling is not backward compatible, unlike that of 
the proper state file. so you need to install the older version and run 
it (only!) over the mailbox(es) that didn't finish properly. afterwards 
everything should work fine with the new version.


regards


___
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel


Re: [PATCH] Implementing IncludeCmd (feature request #17)

2023-08-31 Thread Michiel van den Heuvel
> that depends on whose perspective you're assuming here.
> i'm likely not going to get it done anytime soon. pushing patches on me 
> prompts me into action, so it's good for the project (not so much for my 
> other projects, but the trade-off isn't that bad, as i'm actually much 
> more efficient at reviewing than hacking myself).
> so if you think it would be a good use of *your* time, then go ahead.

After some somewhat more synchronous communication, it might be. This
project has been a nice refresher course on C.

> i implied that you need to do that anyway to handle things properly.  
> also note that you'd save the duplicated check for the command.
> 
> but looking at it again, duplication probably isn't even necessary: you 
> can factor out check_excess_tokens() and make it also return a value.

I hope this is what you meant. 

> the first patch is now Perfect (TM), so no need to re-send it.

Nice! Progress.

On the subject of more things I could do, is there a way to reproduce
the 2 regressions? I am not familiar with IMAP, but do know how to fix
a regression. I'm not in any hurry, and do not want to promise
anything. But I'd like to take a look.

Cheers, Michiel>From 8f4c551449e90f80cdbf31fd6a0b207e9802c3e7 Mon Sep 17 00:00:00 2001
From: Michiel van den Heuvel 
Date: Thu, 17 Aug 2023 20:25:51 +0200
Subject: [PATCH] Add IncludeCmd directive to config parser

---
 src/config.c | 88 
 src/config.h |  3 ++
 src/mbsync.1 |  8 +
 3 files changed, 93 insertions(+), 6 deletions(-)

diff --git a/src/config.c b/src/config.c
index ac90c25..a7476a9 100644
--- a/src/config.c
+++ b/src/config.c
@@ -61,12 +61,21 @@ expand_strdup( const char *s, const conffile_t *cfile )
 	}
 }
 
+static void
+conf_print_loc( const conffile_t *cfile )
+{
+	if (cfile->eval_fp)
+		fprintf( stderr, "%s:%d:included:%d: ", cfile->file, cfile->line, cfile->eval_line );
+	else
+		fprintf( stderr, "%s:%d: ", cfile->file, cfile->line );
+}
+
 void
 conf_error( conffile_t *cfile, const char *fmt, ... )
 {
 	va_list va;
 
-	fprintf( stderr, "%s:%d: ", cfile->file, cfile->line );
+	conf_print_loc( cfile );
 	va_start( va, fmt );
 	vfprintf( stderr, fmt, va );
 	va_end( va );
@@ -79,7 +88,7 @@ conf_sys_error( conffile_t *cfile, const char *fmt, ... )
 	va_list va;
 
 	int errno_bak = errno;
-	fprintf( stderr, "%s:%d: ", cfile->file, cfile->line );
+	conf_print_loc( cfile );
 	errno = errno_bak;
 	va_start( va, fmt );
 	vsys_error( fmt, va );
@@ -318,17 +327,72 @@ getopt_helper( conffile_t *cfile, int *cops, channel_conf_t *conf )
 	return 1;
 }
 
+static void
+eval_cmd_popen( conffile_t *cfile, const char *cmd )
+{
+	if (!(cfile->eval_fp = popen( cmd, "r" ))) {
+		sys_error( "popen" );
+		cfile->err = 1;
+		return;
+	}
+	cfile->eval_line = 0;
+	cfile->eval_command = nfstrdup( cmd );
+}
+
+static void
+eval_cmd_pclose( conffile_t *cfile )
+{
+	int ret;
+
+	if ((ret = pclose( cfile->eval_fp ))) {
+		if (ret < 0) {
+			sys_error( "pclose" );
+			cfile->err = 1;
+		} else if (WIFSIGNALED( ret )) {
+			conf_error( cfile, "command \"%s\" crashed with signal %d\n",
+			cfile->eval_command, WTERMSIG( ret ) );
+		} else {
+			conf_error( cfile, "command \"%s\" exited with status %d\n",
+			cfile->eval_command, WEXITSTATUS( ret ) );
+		}
+	}
+	free( cfile->eval_command );
+	cfile->eval_fp = NULL;
+	cfile->eval_command = NULL;
+}
+
+static int
+read_cline( conffile_t *cfile )
+{
+	if (cfile->eval_fp) {
+		cfile->eval_line++;
+		if ((cfile->rest = fgets( cfile->buf, cfile->bufl, cfile->eval_fp )))
+			return 1;
+		eval_cmd_pclose( cfile );
+	}
+	cfile->line++;
+	return (cfile->rest = fgets( cfile->buf, cfile->bufl, cfile->fp )) != NULL;
+}
+
+static char *
+check_excess_tokens( conffile_t *cfile )
+{
+	char *arg = NULL;
+
+	if (cfile->rest)
+		arg = get_arg( cfile, ARG_OPTIONAL, NULL );
+	return arg;
+}
+
 int
 getcline( conffile_t *cfile )
 {
 	char *arg;
 	int comment;
 
-	if (cfile->rest && (arg = get_arg( cfile, ARG_OPTIONAL, NULL )))
+	if ((arg = check_excess_tokens( cfile )))
 		conf_error( cfile, "excess token '%s'\n", arg );
-	while (fgets( cfile->buf, cfile->bufl, cfile->fp )) {
-		cfile->line++;
-		cfile->rest = cfile->buf;
+	while (read_cline( cfile )) {
 		if (!(cfile->cmd = get_arg( cfile, ARG_OPTIONAL, &comment ))) {
 			if (comment)
 continue;
@@ -336,6 +400,16 @@ getcline( conffile_t *cfile )
 		}
 		if (!(cfile->val = get_arg( cfile, ARG_REQUIRED, NULL )))
 			continue;
+		if (!strcasecmp( cfile->cmd, "IncludeCmd" )) {
+			if (cfile->eval_fp)
+conf_error( cfile, "nested IncludeCmd\n" );
+			else if ((arg = check_excess_tokens( cfile )))
+conf_error( cfile, "excess token '%s', not executing "
+"potentially malformed command\n", arg );
+			else
+eval_cmd_popen( cfile, cfile->val );
+			continue;
+		}
 		return 1;
 	}
 	return 0;
@@ -488,6 +562,7 @@ load_config( const char *where )
 		return 1;
 	}
 	buf[sizeof(buf) - 1] = 0;
+	

Re: Restore after crash

2023-08-31 Thread Oswald Buddenhagen

On Wed, Aug 30, 2023 at 11:16:47AM -0700, Robert Bower wrote:

Error: incompatible journal version (got 3, expected 4)

it means you downgraded isync. you need to build a newer version (1.4) 
yourself if there are no backports for your mint version.


regards


___
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel