From b67cd7dca1ca7fc10c15d51aac4a6075eb01fa15 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 20 Jun 2022 16:34:56 +0200 Subject: [PATCH] *** introduce NotifierCmd *** actually implement most of it this could take advantage of wip/better-stderr. to be actually useful, this would need to report both internally generated and detected events, but typically only for one side. this is contrary to how a natural implementation would work, which would report detected events as internal events for the opposite side, but of course only if a corresponding sync action was actually executed. => a directory watcher seems more appropriate in the end --- TODO | 2 -- src/config.c | 2 ++ src/main_sync.c | 6 ++++++ src/sync.c | 10 ++++++++++ src/sync.h | 3 +++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 43f0c0d..44d3bf8 100644 --- a/TODO +++ b/TODO @@ -25,8 +25,6 @@ add alternative treatments of expired messages. ExpiredMessageMode: Prune (delete messages like now), Keep (just don't sync) and Archive (move to separate folder - ArchiveSuffix, default .archive). -add support for event notification callbacks. - make it possible to have different mailbox names for far and near side in Patterns. - use far:near for the pattern diff --git a/src/config.c b/src/config.c index 456bd47..c0b77e6 100644 --- a/src/config.c +++ b/src/config.c @@ -642,6 +642,8 @@ load_config( const char *where ) error( "%s:%d: BufferLimit cannot be zero\n", cfile.file, cfile.line ); cfile.err = 1; } + } else if (!strcasecmp( "NotifierCmd", cfile.cmd )) { + NotifierCmd = nfstrdup( cfile.val ); } else if (!getopt_helper( &cfile, &gcops, &global_conf )) { error( "%s:%d: '%s' is not a recognized section-starting or global keyword\n", cfile.file, cfile.line, cfile.cmd ); diff --git a/src/main_sync.c b/src/main_sync.c index 9c38d20..39703cc 100644 --- a/src/main_sync.c +++ b/src/main_sync.c @@ -379,6 +379,12 @@ sync_chans( core_vars_t *cvars, char **argv ) } mvars->chanptr = chans; + if (NotifierCmd && !(notifier_pipe = popen( NotifierCmd, "w" ))) { + sys_error( "Failed to launch notifier command '%s'", NotifierCmd ); + cvars->ret = 1; + return; + } + if (!cvars->list && (DFlags & PROGRESS)) { init_wakeup( &stats_wakeup, stats_timeout, NULL ); stats_timeout( NULL ); diff --git a/src/sync.c b/src/sync.c index bff3684..89c3917 100644 --- a/src/sync.c +++ b/src/sync.c @@ -13,6 +13,9 @@ channel_conf_t *channels; group_conf_t *groups; uint BufferLimit = 10 * 1024 * 1024; +const char *NotifierCmd; + +FILE *notifier_pipe; int new_total[2], new_done[2]; int flags_total[2], flags_done[2]; @@ -1544,6 +1547,13 @@ flags_set( int sts, void *aux ) static void flags_set_p2( sync_vars_t *svars, sync_rec_t *srec, int t ) { + if (notifier_pipe) { + fprintf( notifier_pipe, + "Event flags\n" + "Store %s\n" + "Box %s\n" + "UID %u\n"); + } if (srec->status & S_PURGE) { JLOG( "P %u %u", (srec->uid[F], srec->uid[N]), "deleted dummy" ); srec->status = (srec->status & ~S_PURGE) | S_PURGED; diff --git a/src/sync.h b/src/sync.h index ced07e7..cd605fd 100644 --- a/src/sync.h +++ b/src/sync.h @@ -73,6 +73,9 @@ extern channel_conf_t *channels; extern group_conf_t *groups; extern uint BufferLimit; +extern const char *NotifierCmd; + +extern FILE *notifier_pipe; extern int new_total[2], new_done[2]; extern int flags_total[2], flags_done[2];