2022-06-16 10:44:35 +00:00
|
|
|
// SPDX-FileCopyrightText: 2000-2002 Michael R. Elkins <me@mutt.org>
|
|
|
|
// SPDX-FileCopyrightText: 2002-2022 Oswald Buddenhagen <ossi@users.sf.net>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later WITH LicenseRef-isync-GPL-exception
|
2004-03-27 16:07:20 +00:00
|
|
|
/*
|
|
|
|
* mbsync - mailbox synchronizer
|
2000-12-20 21:41:21 +00:00
|
|
|
*/
|
|
|
|
|
2022-05-31 07:58:41 +00:00
|
|
|
#include "sync_p.h"
|
2022-05-31 12:05:28 +00:00
|
|
|
#include "sync_c_enum.h"
|
2019-11-25 19:55:41 +00:00
|
|
|
|
2013-12-08 19:46:40 +00:00
|
|
|
channel_conf_t global_conf;
|
|
|
|
channel_conf_t *channels;
|
|
|
|
group_conf_t *groups;
|
|
|
|
|
2022-04-24 12:30:10 +00:00
|
|
|
uint BufferLimit = 10 * 1024 * 1024;
|
|
|
|
|
|
|
|
int new_total[2], new_done[2];
|
|
|
|
int flags_total[2], flags_done[2];
|
|
|
|
int trash_total[2], trash_done[2];
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void sync_ref( sync_vars_t *svars ) { ++svars->ref_count; }
|
2013-12-11 15:13:49 +00:00
|
|
|
static void sync_deref( sync_vars_t *svars );
|
2012-07-29 21:14:48 +00:00
|
|
|
static int check_cancel( sync_vars_t *svars );
|
|
|
|
|
2006-03-21 20:03:21 +00:00
|
|
|
#define AUX &svars->t[t]
|
2022-04-12 11:06:55 +00:00
|
|
|
#define INV_AUX &svars->t[t^1]
|
2012-06-17 12:52:46 +00:00
|
|
|
#define DECL_SVARS \
|
|
|
|
int t; \
|
|
|
|
sync_vars_t *svars
|
|
|
|
#define INIT_SVARS(aux) \
|
|
|
|
t = *(int *)aux; \
|
|
|
|
svars = (sync_vars_t *)(((char *)(&((int *)aux)[-t])) - offsetof(sync_vars_t, t))
|
|
|
|
#define DECL_INIT_SVARS(aux) \
|
2006-03-21 20:03:21 +00:00
|
|
|
int t = *(int *)aux; \
|
2012-06-17 12:52:46 +00:00
|
|
|
sync_vars_t *svars = (sync_vars_t *)(((char *)(&((int *)aux)[-t])) - offsetof(sync_vars_t, t))
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
/* operation dependencies:
|
2013-12-11 15:29:02 +00:00
|
|
|
select(x): -
|
|
|
|
load(x): select(x)
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
new(F), new(N), flags(F), flags(N): load(F) & load(N)
|
2006-03-21 20:03:21 +00:00
|
|
|
find_new(x): new(x)
|
|
|
|
trash(x): flags(x)
|
2022-02-06 13:56:16 +00:00
|
|
|
close(x): trash(x) & flags(!x) & find_new(x) & new(!x) // with expunge
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
cleanup: close(F) & close(N)
|
2006-03-21 20:03:21 +00:00
|
|
|
*/
|
|
|
|
|
2022-05-31 12:05:28 +00:00
|
|
|
BIT_ENUM(
|
|
|
|
ST_PRESENT,
|
|
|
|
ST_CONFIRMED,
|
|
|
|
ST_SELECTED,
|
|
|
|
ST_FIND_OLD,
|
|
|
|
ST_LOADED,
|
|
|
|
ST_SENT_FLAGS,
|
|
|
|
ST_SENDING_NEW,
|
|
|
|
ST_SENT_NEW,
|
|
|
|
ST_FIND_NEW,
|
|
|
|
ST_FOUND_NEW,
|
|
|
|
ST_SENT_TRASH,
|
|
|
|
ST_CLOSING,
|
|
|
|
ST_CLOSED,
|
|
|
|
ST_DID_EXPUNGE,
|
|
|
|
ST_SENT_CANCEL,
|
|
|
|
ST_CANCELED,
|
|
|
|
)
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2020-01-08 17:22:48 +00:00
|
|
|
static uchar
|
|
|
|
sanitize_flags( uchar tflags, sync_vars_t *svars, int t )
|
|
|
|
{
|
2022-06-06 10:29:48 +00:00
|
|
|
if (Verbosity >= TERSE) {
|
2020-01-08 17:22:48 +00:00
|
|
|
// We complain only once per flag per store - even though _theoretically_
|
|
|
|
// each mailbox can support different flags according to the IMAP spec.
|
|
|
|
uchar bflags = tflags & ~(svars->good_flags[t] | svars->bad_flags[t]);
|
|
|
|
if (bflags) {
|
2022-06-15 15:17:23 +00:00
|
|
|
notice( "Notice: %s store does not support flag(s) '%s'; not propagating.\n",
|
|
|
|
str_fn[t], fmt_flags( bflags ).str );
|
2020-01-08 17:22:48 +00:00
|
|
|
svars->bad_flags[t] |= bflags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tflags & svars->good_flags[t];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-21 20:03:21 +00:00
|
|
|
typedef struct copy_vars {
|
2017-03-21 19:05:29 +00:00
|
|
|
void (*cb)( int sts, uint uid, struct copy_vars *vars );
|
2006-03-21 20:03:21 +00:00
|
|
|
void *aux;
|
|
|
|
sync_rec_t *srec; /* also ->tuid */
|
|
|
|
message_t *msg;
|
|
|
|
msg_data_t data;
|
2019-12-29 13:37:53 +00:00
|
|
|
int minimal;
|
2006-03-21 20:03:21 +00:00
|
|
|
} copy_vars_t;
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void msg_fetched( int sts, void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
copy_msg( copy_vars_t *vars )
|
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_INIT_SVARS(vars->aux);
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
t ^= 1;
|
2006-03-21 20:03:21 +00:00
|
|
|
vars->data.flags = vars->msg->flags;
|
2013-07-28 13:55:13 +00:00
|
|
|
vars->data.date = svars->chan->use_internal_date ? -1 : 0;
|
2019-12-29 13:37:53 +00:00
|
|
|
svars->drv[t]->fetch_msg( svars->ctx[t], vars->msg, &vars->data, vars->minimal, msg_fetched, vars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-21 19:05:29 +00:00
|
|
|
static void msg_stored( int sts, uint uid, void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2016-11-05 17:32:49 +00:00
|
|
|
static void
|
2020-07-08 15:27:37 +00:00
|
|
|
copy_msg_bytes( char **out_ptr, const char *in_buf, uint *in_idx, uint in_len, int in_cr, int out_cr )
|
2016-11-05 17:32:49 +00:00
|
|
|
{
|
|
|
|
char *out = *out_ptr;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint idx = *in_idx;
|
2016-11-05 17:32:49 +00:00
|
|
|
if (out_cr != in_cr) {
|
|
|
|
char c;
|
|
|
|
if (out_cr) {
|
|
|
|
for (; idx < in_len; idx++) {
|
|
|
|
if ((c = in_buf[idx]) != '\r') {
|
|
|
|
if (c == '\n')
|
|
|
|
*out++ = '\r';
|
|
|
|
*out++ = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (; idx < in_len; idx++) {
|
|
|
|
if ((c = in_buf[idx]) != '\r')
|
|
|
|
*out++ = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memcpy( out, in_buf + idx, in_len - idx );
|
|
|
|
out += in_len - idx;
|
|
|
|
idx = in_len;
|
|
|
|
}
|
|
|
|
*out_ptr = out;
|
|
|
|
*in_idx = idx;
|
|
|
|
}
|
|
|
|
|
2016-11-05 17:33:16 +00:00
|
|
|
static int
|
2021-11-24 16:46:43 +00:00
|
|
|
copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars, int t )
|
2016-11-05 17:33:16 +00:00
|
|
|
{
|
|
|
|
char *in_buf = vars->data.data;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint in_len = vars->data.len;
|
2021-11-22 19:57:24 +00:00
|
|
|
uint idx = 0, sbreak = 0, ebreak = 0, break2 = UINT_MAX;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint lines = 0, hdr_crs = 0, bdy_crs = 0, app_cr = 0, extra = 0;
|
2019-12-29 13:37:53 +00:00
|
|
|
uint add_subj = 0;
|
|
|
|
|
2016-11-05 17:33:16 +00:00
|
|
|
if (vars->srec) {
|
|
|
|
nloop: ;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint start = idx;
|
|
|
|
uint line_crs = 0;
|
2016-11-05 17:33:16 +00:00
|
|
|
while (idx < in_len) {
|
|
|
|
char c = in_buf[idx++];
|
|
|
|
if (c == '\r') {
|
|
|
|
line_crs++;
|
|
|
|
} else if (c == '\n') {
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!ebreak && starts_with_upper( in_buf + start, (int)(in_len - start), "X-TUID: ", 8 )) {
|
2016-11-05 17:33:16 +00:00
|
|
|
extra = (sbreak = start) - (ebreak = idx);
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!vars->minimal)
|
|
|
|
goto oke;
|
|
|
|
} else {
|
2021-11-26 22:05:30 +00:00
|
|
|
if (break2 == UINT_MAX && vars->minimal &&
|
|
|
|
starts_with_upper( in_buf + start, (int)(in_len - start), "SUBJECT:", 8 )) {
|
2019-12-29 13:37:53 +00:00
|
|
|
break2 = start + 8;
|
2021-11-26 22:05:30 +00:00
|
|
|
if (break2 < in_len && in_buf[break2] == ' ')
|
2019-12-29 13:37:53 +00:00
|
|
|
break2++;
|
|
|
|
}
|
|
|
|
lines++;
|
|
|
|
hdr_crs += line_crs;
|
2016-11-05 17:33:16 +00:00
|
|
|
}
|
|
|
|
if (idx - line_crs - 1 == start) {
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!ebreak)
|
|
|
|
sbreak = ebreak = start;
|
|
|
|
if (vars->minimal) {
|
|
|
|
in_len = idx;
|
2021-11-22 19:57:24 +00:00
|
|
|
if (break2 == UINT_MAX) {
|
2019-12-29 13:37:53 +00:00
|
|
|
break2 = start;
|
|
|
|
add_subj = 1;
|
|
|
|
}
|
|
|
|
}
|
2016-11-05 17:33:16 +00:00
|
|
|
goto oke;
|
|
|
|
}
|
|
|
|
goto nloop;
|
|
|
|
}
|
|
|
|
}
|
2021-11-24 16:46:43 +00:00
|
|
|
warn( "Warning: message %u from %s has incomplete header; skipping.\n",
|
2022-04-12 11:06:55 +00:00
|
|
|
vars->msg->uid, str_fn[t^1] );
|
2016-11-05 17:33:16 +00:00
|
|
|
free( in_buf );
|
|
|
|
return 0;
|
|
|
|
oke:
|
2016-11-05 17:33:47 +00:00
|
|
|
app_cr = out_cr && (!in_cr || hdr_crs);
|
|
|
|
extra += 8 + TUIDL + app_cr + 1;
|
2016-11-05 17:33:16 +00:00
|
|
|
}
|
|
|
|
if (out_cr != in_cr) {
|
|
|
|
for (; idx < in_len; idx++) {
|
|
|
|
char c = in_buf[idx];
|
|
|
|
if (c == '\r')
|
|
|
|
bdy_crs++;
|
|
|
|
else if (c == '\n')
|
|
|
|
lines++;
|
|
|
|
}
|
|
|
|
extra -= hdr_crs + bdy_crs;
|
|
|
|
if (out_cr)
|
|
|
|
extra += lines;
|
|
|
|
}
|
|
|
|
|
2019-12-29 13:37:53 +00:00
|
|
|
uint dummy_msg_len = 0;
|
2022-06-17 14:49:33 +00:00
|
|
|
char dummy_msg_buf[256];
|
2019-12-29 13:37:53 +00:00
|
|
|
static const char dummy_pfx[] = "[placeholder] ";
|
|
|
|
static const char dummy_subj[] = "Subject: [placeholder] (No Subject)";
|
|
|
|
static const char dummy_msg[] =
|
|
|
|
"Having a size of %s, this message is over the MaxSize limit.%s"
|
2022-01-12 11:49:17 +00:00
|
|
|
"Flag it and sync again (Sync mode Upgrade) to fetch its real contents.%s";
|
2022-06-17 14:49:33 +00:00
|
|
|
static const char dummy_flag[] =
|
|
|
|
"%s"
|
|
|
|
"The original message is flagged as important.%s";
|
2019-12-29 13:37:53 +00:00
|
|
|
|
|
|
|
if (vars->minimal) {
|
|
|
|
char sz[32];
|
|
|
|
|
|
|
|
if (vars->msg->size < 1024000)
|
|
|
|
sprintf( sz, "%dKiB", (int)(vars->msg->size >> 10) );
|
|
|
|
else
|
|
|
|
sprintf( sz, "%.1fMiB", vars->msg->size / 1048576. );
|
|
|
|
const char *nl = app_cr ? "\r\n" : "\n";
|
|
|
|
dummy_msg_len = (uint)sprintf( dummy_msg_buf, dummy_msg, sz, nl, nl );
|
2022-06-17 14:49:33 +00:00
|
|
|
if (vars->data.flags & F_FLAGGED) {
|
|
|
|
vars->data.flags &= ~F_FLAGGED;
|
|
|
|
dummy_msg_len += (uint)sprintf( dummy_msg_buf + dummy_msg_len, dummy_flag, nl, nl );
|
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
extra += dummy_msg_len;
|
|
|
|
extra += add_subj ? strlen(dummy_subj) + app_cr + 1 : strlen(dummy_pfx);
|
|
|
|
}
|
|
|
|
|
2016-11-05 17:33:16 +00:00
|
|
|
vars->data.len = in_len + extra;
|
2021-11-24 16:51:06 +00:00
|
|
|
if (vars->data.len > INT_MAX) {
|
|
|
|
warn( "Warning: message %u from %s is too big after conversion; skipping.\n",
|
2022-04-12 11:06:55 +00:00
|
|
|
vars->msg->uid, str_fn[t^1] );
|
2021-11-24 16:51:06 +00:00
|
|
|
free( in_buf );
|
|
|
|
return 0;
|
|
|
|
}
|
2016-11-05 17:33:16 +00:00
|
|
|
char *out_buf = vars->data.data = nfmalloc( vars->data.len );
|
|
|
|
idx = 0;
|
|
|
|
if (vars->srec) {
|
2021-11-22 19:57:24 +00:00
|
|
|
if (break2 < sbreak) {
|
2019-12-29 13:37:53 +00:00
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, break2, in_cr, out_cr );
|
|
|
|
memcpy( out_buf, dummy_pfx, strlen(dummy_pfx) );
|
|
|
|
out_buf += strlen(dummy_pfx);
|
|
|
|
}
|
2016-11-05 17:33:16 +00:00
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, sbreak, in_cr, out_cr );
|
|
|
|
|
|
|
|
memcpy( out_buf, "X-TUID: ", 8 );
|
|
|
|
out_buf += 8;
|
|
|
|
memcpy( out_buf, vars->srec->tuid, TUIDL );
|
|
|
|
out_buf += TUIDL;
|
2016-11-05 17:33:47 +00:00
|
|
|
if (app_cr)
|
2016-11-05 17:33:16 +00:00
|
|
|
*out_buf++ = '\r';
|
|
|
|
*out_buf++ = '\n';
|
|
|
|
idx = ebreak;
|
2019-12-29 13:37:53 +00:00
|
|
|
|
2021-11-22 19:57:24 +00:00
|
|
|
if (break2 != UINT_MAX && break2 >= sbreak) {
|
2019-12-29 13:37:53 +00:00
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, break2, in_cr, out_cr );
|
|
|
|
if (!add_subj) {
|
|
|
|
memcpy( out_buf, dummy_pfx, strlen(dummy_pfx) );
|
|
|
|
out_buf += strlen(dummy_pfx);
|
|
|
|
} else {
|
|
|
|
memcpy( out_buf, dummy_subj, strlen(dummy_subj) );
|
|
|
|
out_buf += strlen(dummy_subj);
|
|
|
|
if (app_cr)
|
|
|
|
*out_buf++ = '\r';
|
|
|
|
*out_buf++ = '\n';
|
|
|
|
}
|
|
|
|
}
|
2016-11-05 17:33:16 +00:00
|
|
|
}
|
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, in_len, in_cr, out_cr );
|
|
|
|
|
2019-12-29 13:37:53 +00:00
|
|
|
if (vars->minimal)
|
|
|
|
memcpy( out_buf, dummy_msg_buf, dummy_msg_len );
|
|
|
|
|
2016-11-05 17:33:16 +00:00
|
|
|
free( in_buf );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
msg_fetched( int sts, void *aux )
|
|
|
|
{
|
|
|
|
copy_vars_t *vars = (copy_vars_t *)aux;
|
2019-12-29 11:31:10 +00:00
|
|
|
sync_rec_t *srec = vars->srec;
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_SVARS;
|
2016-11-05 17:33:16 +00:00
|
|
|
int scr, tcr;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
switch (sts) {
|
|
|
|
case DRV_OK:
|
2012-06-17 12:52:46 +00:00
|
|
|
INIT_SVARS(vars->aux);
|
2012-07-29 21:15:12 +00:00
|
|
|
if (check_cancel( svars )) {
|
|
|
|
free( vars->data.data );
|
|
|
|
vars->cb( SYNC_CANCELED, 0, vars );
|
|
|
|
return;
|
|
|
|
}
|
2012-06-17 12:52:46 +00:00
|
|
|
|
2022-06-17 13:57:56 +00:00
|
|
|
if (srec && (srec->status & S_UPGRADE)) {
|
|
|
|
vars->data.flags = (srec->pflags | srec->aflags[t]) & ~srec->dflags[t];
|
|
|
|
if (srec->aflags[t] || srec->dflags[t]) {
|
|
|
|
JLOG( "$ %u %u %u %u", (srec->uid[F], srec->uid[N], srec->aflags[t], srec->dflags[t]),
|
|
|
|
"%sing upgrade with flags: +%s -%s",
|
|
|
|
(str_hl[t], fmt_flags( srec->aflags[t] ).str, fmt_flags( srec->dflags[t] ).str) );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vars->data.flags = sanitize_flags( vars->data.flags, svars, t );
|
|
|
|
if (srec) {
|
2022-06-17 14:49:33 +00:00
|
|
|
if (srec->status & S_DUMMY(t))
|
|
|
|
vars->data.flags &= ~F_FLAGGED;
|
2022-06-17 13:57:56 +00:00
|
|
|
if (vars->data.flags) {
|
|
|
|
srec->pflags = vars->data.flags;
|
|
|
|
JLOG( "%% %u %u %u", (srec->uid[F], srec->uid[N], srec->pflags),
|
|
|
|
"%sing with flags %s", (str_hl[t], fmt_lone_flags( srec->pflags ).str) );
|
|
|
|
}
|
2022-02-07 19:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2021-11-26 19:39:45 +00:00
|
|
|
scr = svars->can_crlf[t^1];
|
|
|
|
tcr = svars->can_crlf[t];
|
2019-12-29 11:31:10 +00:00
|
|
|
if (srec || scr != tcr) {
|
2021-11-24 16:46:43 +00:00
|
|
|
if (!copy_msg_convert( scr, tcr, vars, t )) {
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_NOGOOD, 0, vars );
|
|
|
|
return;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-29 11:31:10 +00:00
|
|
|
svars->drv[t]->store_msg( svars->ctx[t], &vars->data, !srec, msg_stored, vars );
|
2012-07-29 21:14:48 +00:00
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
case DRV_CANCELED:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_CANCELED, 0, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
case DRV_MSG_BAD:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_NOGOOD, 0, vars );
|
|
|
|
break;
|
2021-12-08 12:55:33 +00:00
|
|
|
default: // DRV_BOX_BAD
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_FAIL, 0, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-21 19:05:29 +00:00
|
|
|
msg_stored( int sts, uint uid, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
|
|
|
copy_vars_t *vars = (copy_vars_t *)aux;
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_SVARS;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
switch (sts) {
|
|
|
|
case DRV_OK:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_OK, uid, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
case DRV_CANCELED:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_CANCELED, 0, vars );
|
|
|
|
break;
|
2010-02-06 09:32:10 +00:00
|
|
|
case DRV_MSG_BAD:
|
2012-06-17 12:52:46 +00:00
|
|
|
INIT_SVARS(vars->aux);
|
|
|
|
(void)svars;
|
2017-03-21 19:05:29 +00:00
|
|
|
warn( "Warning: %s refuses to store message %u from %s.\n",
|
2022-04-12 11:06:55 +00:00
|
|
|
str_fn[t], vars->msg->uid, str_fn[t^1] );
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_NOGOOD, 0, vars );
|
|
|
|
break;
|
2021-12-08 12:55:33 +00:00
|
|
|
default: // DRV_BOX_BAD
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_FAIL, 0, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sync_bail( sync_vars_t *svars );
|
|
|
|
static void sync_bail2( sync_vars_t *svars );
|
2012-08-18 11:58:14 +00:00
|
|
|
static void sync_bail3( sync_vars_t *svars );
|
2012-07-22 15:32:32 +00:00
|
|
|
static void cancel_done( void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
cancel_sync( sync_vars_t *svars )
|
|
|
|
{
|
2022-05-20 10:33:51 +00:00
|
|
|
int state1 = svars->state[1];
|
|
|
|
for (int t = 0; ; t++) {
|
2012-07-22 15:32:32 +00:00
|
|
|
if (svars->ret & SYNC_BAD(t)) {
|
|
|
|
cancel_done( AUX );
|
2011-04-03 14:29:18 +00:00
|
|
|
} else if (!(svars->state[t] & ST_SENT_CANCEL)) {
|
|
|
|
/* ignore subsequent failures from in-flight commands */
|
|
|
|
svars->state[t] |= ST_SENT_CANCEL;
|
2014-12-27 21:13:24 +00:00
|
|
|
svars->drv[t]->cancel_cmds( svars->ctx[t], cancel_done, AUX );
|
2012-07-22 15:32:32 +00:00
|
|
|
}
|
2022-05-20 10:33:51 +00:00
|
|
|
if (t || (state1 & ST_CANCELED))
|
2012-07-22 15:46:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-22 15:32:32 +00:00
|
|
|
cancel_done( void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_INIT_SVARS(aux);
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
svars->state[t] |= ST_CANCELED;
|
2022-04-12 11:06:55 +00:00
|
|
|
if (svars->state[t^1] & ST_CANCELED) {
|
2014-12-27 22:50:31 +00:00
|
|
|
if (svars->nfp) {
|
2012-09-15 11:25:50 +00:00
|
|
|
Fclose( svars->nfp, 0 );
|
|
|
|
Fclose( svars->jfp, 0 );
|
2011-07-23 14:06:32 +00:00
|
|
|
}
|
2014-12-27 22:50:31 +00:00
|
|
|
sync_bail( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-15 10:55:04 +00:00
|
|
|
static void
|
|
|
|
store_bad( void *aux )
|
|
|
|
{
|
|
|
|
DECL_INIT_SVARS(aux);
|
|
|
|
|
|
|
|
svars->drv[t]->cancel_store( svars->ctx[t] );
|
|
|
|
svars->ret |= SYNC_BAD(t);
|
|
|
|
cancel_sync( svars );
|
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static int
|
|
|
|
check_cancel( sync_vars_t *svars )
|
|
|
|
{
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
return (svars->state[F] | svars->state[N]) & (ST_SENT_CANCEL | ST_CANCELED);
|
2012-07-29 21:14:48 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
static int
|
2012-06-17 12:52:46 +00:00
|
|
|
check_ret( int sts, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_SVARS;
|
|
|
|
|
2012-07-29 21:15:12 +00:00
|
|
|
if (sts == DRV_CANCELED)
|
2006-03-21 20:03:21 +00:00
|
|
|
return 1;
|
2012-07-29 21:15:12 +00:00
|
|
|
INIT_SVARS(aux);
|
|
|
|
if (sts == DRV_BOX_BAD) {
|
2006-03-21 20:03:21 +00:00
|
|
|
svars->ret |= SYNC_FAIL;
|
|
|
|
cancel_sync( svars );
|
|
|
|
return 1;
|
|
|
|
}
|
2012-07-29 21:15:12 +00:00
|
|
|
return check_cancel( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 12:52:46 +00:00
|
|
|
#define SVARS_CHECK_RET \
|
|
|
|
DECL_SVARS; \
|
|
|
|
if (check_ret( sts, aux )) \
|
2012-07-29 21:14:48 +00:00
|
|
|
return; \
|
2012-06-17 12:52:46 +00:00
|
|
|
INIT_SVARS(aux)
|
|
|
|
|
|
|
|
#define SVARS_CHECK_RET_VARS(type) \
|
|
|
|
type *vars = (type *)aux; \
|
|
|
|
DECL_SVARS; \
|
|
|
|
if (check_ret( sts, vars->aux )) { \
|
|
|
|
free( vars ); \
|
2012-07-29 21:14:48 +00:00
|
|
|
return; \
|
2012-06-17 12:52:46 +00:00
|
|
|
} \
|
|
|
|
INIT_SVARS(vars->aux)
|
|
|
|
|
|
|
|
#define SVARS_CHECK_CANCEL_RET \
|
|
|
|
DECL_SVARS; \
|
|
|
|
if (sts == SYNC_CANCELED) { \
|
|
|
|
free( vars ); \
|
2012-07-29 21:14:48 +00:00
|
|
|
return; \
|
2012-06-17 12:52:46 +00:00
|
|
|
} \
|
|
|
|
INIT_SVARS(vars->aux)
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2022-01-07 21:58:38 +00:00
|
|
|
static void
|
|
|
|
message_expunged( message_t *msg, void *aux )
|
|
|
|
{
|
|
|
|
DECL_INIT_SVARS(aux);
|
|
|
|
(void)svars;
|
|
|
|
|
|
|
|
if (msg->srec) {
|
|
|
|
msg->srec->msg[t] = NULL;
|
|
|
|
msg->srec = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:45:06 +00:00
|
|
|
static void box_confirmed( int sts, uint uidvalidity, void *aux );
|
2014-12-29 01:08:48 +00:00
|
|
|
static void box_confirmed2( sync_vars_t *svars, int t );
|
|
|
|
static void box_deleted( int sts, void *aux );
|
2014-12-29 00:42:17 +00:00
|
|
|
static void box_created( int sts, void *aux );
|
2020-07-08 11:45:06 +00:00
|
|
|
static void box_opened( int sts, uint uidvalidity, void *aux );
|
2014-12-29 00:42:17 +00:00
|
|
|
static void box_opened2( sync_vars_t *svars, int t );
|
2017-03-21 19:05:29 +00:00
|
|
|
static void load_box( sync_vars_t *svars, int t, uint minwuid, uint_array_t mexcs );
|
2014-12-27 22:13:45 +00:00
|
|
|
|
|
|
|
void
|
2019-07-28 19:13:28 +00:00
|
|
|
sync_boxes( store_t *ctx[], const char * const names[], int present[], channel_conf_t *chan,
|
2014-12-27 22:13:45 +00:00
|
|
|
void (*cb)( int sts, void *aux ), void *aux )
|
|
|
|
{
|
|
|
|
sync_vars_t *svars;
|
|
|
|
int t;
|
|
|
|
|
2022-04-12 11:00:54 +00:00
|
|
|
svars = nfzalloc( sizeof(*svars) );
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->t[1] = 1;
|
|
|
|
svars->ref_count = 1;
|
|
|
|
svars->cb = cb;
|
|
|
|
svars->aux = aux;
|
|
|
|
svars->ctx[0] = ctx[0];
|
|
|
|
svars->ctx[1] = ctx[1];
|
|
|
|
svars->chan = chan;
|
2014-12-27 22:50:31 +00:00
|
|
|
svars->lfd = -1;
|
2017-01-29 14:39:36 +00:00
|
|
|
svars->uidval[0] = svars->uidval[1] = UIDVAL_BAD;
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->srecadd = &svars->srecs;
|
|
|
|
|
|
|
|
for (t = 0; t < 2; t++) {
|
|
|
|
svars->orig_name[t] =
|
|
|
|
(!names[t] || (ctx[t]->conf->map_inbox && !strcmp( ctx[t]->conf->map_inbox, names[t] ))) ?
|
|
|
|
"INBOX" : names[t];
|
2017-10-15 14:14:20 +00:00
|
|
|
if (!ctx[t]->conf->flat_delim[0]) {
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->box_name[t] = nfstrdup( svars->orig_name[t] );
|
|
|
|
} else if (map_name( svars->orig_name[t], &svars->box_name[t], 0, "/", ctx[t]->conf->flat_delim ) < 0) {
|
|
|
|
error( "Error: canonical mailbox name '%s' contains flattened hierarchy delimiter\n", svars->orig_name[t] );
|
2015-05-01 17:16:23 +00:00
|
|
|
bail3:
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail3( svars );
|
|
|
|
return;
|
|
|
|
}
|
2017-04-02 12:57:17 +00:00
|
|
|
svars->drv[t] = ctx[t]->driver;
|
2022-01-07 21:58:38 +00:00
|
|
|
svars->drv[t]->set_callbacks( ctx[t], message_expunged, store_bad, AUX );
|
2021-11-26 19:39:45 +00:00
|
|
|
svars->can_crlf[t] = (svars->drv[t]->get_caps( svars->ctx[t] ) / DRV_CRLF) & 1;
|
2014-12-27 22:13:45 +00:00
|
|
|
}
|
|
|
|
/* Both boxes must be fully set up at this point, so that error exit paths
|
|
|
|
* don't run into uninitialized variables. */
|
2014-12-27 22:39:55 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2015-05-01 17:16:23 +00:00
|
|
|
switch (svars->drv[t]->select_box( ctx[t], svars->box_name[t] )) {
|
2020-08-03 22:23:33 +00:00
|
|
|
case DRV_STORE_BAD:
|
2014-12-27 22:39:55 +00:00
|
|
|
store_bad( AUX );
|
|
|
|
return;
|
2015-05-01 17:16:23 +00:00
|
|
|
case DRV_BOX_BAD:
|
|
|
|
goto bail3;
|
2014-12-27 22:39:55 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 22:16:20 +00:00
|
|
|
|
|
|
|
if (!prepare_state( svars )) {
|
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail2( svars );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!load_state( svars )) {
|
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail( svars );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
sync_ref( svars );
|
2015-01-03 22:16:20 +00:00
|
|
|
for (t = 0; ; t++) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
info( "Opening %s box %s...\n", str_fn[t], svars->orig_name[t] );
|
2014-12-30 14:16:38 +00:00
|
|
|
if (present[t] == BOX_ABSENT)
|
2014-12-29 01:08:48 +00:00
|
|
|
box_confirmed2( svars, t );
|
2014-12-30 14:16:38 +00:00
|
|
|
else
|
|
|
|
svars->drv[t]->open_box( ctx[t], box_confirmed, AUX );
|
2015-01-03 22:16:20 +00:00
|
|
|
if (t || check_cancel( svars ))
|
2014-12-27 22:13:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sync_deref( svars );
|
|
|
|
}
|
|
|
|
|
2014-12-29 00:42:17 +00:00
|
|
|
static void
|
2020-07-08 11:45:06 +00:00
|
|
|
box_confirmed( int sts, uint uidvalidity, void *aux )
|
2014-12-29 00:42:17 +00:00
|
|
|
{
|
|
|
|
DECL_SVARS;
|
|
|
|
|
|
|
|
if (sts == DRV_CANCELED)
|
|
|
|
return;
|
|
|
|
INIT_SVARS(aux);
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
return;
|
|
|
|
|
2017-03-24 18:24:30 +00:00
|
|
|
if (sts == DRV_OK) {
|
2014-12-29 01:08:48 +00:00
|
|
|
svars->state[t] |= ST_PRESENT;
|
2017-03-24 18:24:30 +00:00
|
|
|
svars->newuidval[t] = uidvalidity;
|
|
|
|
}
|
2014-12-29 01:08:48 +00:00
|
|
|
box_confirmed2( svars, t );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_confirmed2( sync_vars_t *svars, int t )
|
|
|
|
{
|
|
|
|
svars->state[t] |= ST_CONFIRMED;
|
2022-04-12 11:06:55 +00:00
|
|
|
if (!(svars->state[t^1] & ST_CONFIRMED))
|
2014-12-29 01:08:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
sync_ref( svars );
|
|
|
|
for (t = 0; ; t++) {
|
|
|
|
if (!(svars->state[t] & ST_PRESENT)) {
|
2022-04-12 11:06:55 +00:00
|
|
|
if (!(svars->state[t^1] & ST_PRESENT)) {
|
2014-12-29 01:08:48 +00:00
|
|
|
if (!svars->existing) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
error( "Error: channel %s: both far side %s and near side %s cannot be opened.\n",
|
|
|
|
svars->chan->name, svars->orig_name[F], svars->orig_name[N] );
|
2014-12-29 01:08:48 +00:00
|
|
|
bail:
|
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
} else {
|
|
|
|
/* This can legitimately happen if a deletion propagation was interrupted.
|
|
|
|
* We have no place to record this transaction, so we just assume it.
|
|
|
|
* Of course this bears the danger of clearing the state if both mailboxes
|
|
|
|
* temorarily cannot be opened for some weird reason (while the stores can). */
|
|
|
|
delete_state( svars );
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
sync_bail( svars );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (svars->existing) {
|
2022-04-12 11:06:55 +00:00
|
|
|
if (!(svars->chan->ops[t^1] & OP_REMOVE)) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
error( "Error: channel %s: %s box %s cannot be opened.\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t] );
|
2014-12-29 01:08:48 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
2022-04-12 11:06:55 +00:00
|
|
|
if (svars->drv[t^1]->confirm_box_empty( svars->ctx[t^1] ) != DRV_OK) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
warn( "Warning: channel %s: %s box %s cannot be opened and %s box %s is not empty.\n",
|
2022-04-12 11:06:55 +00:00
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t], str_fn[t^1], svars->orig_name[t^1] );
|
2014-12-29 01:08:48 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2022-04-12 11:06:55 +00:00
|
|
|
info( "Deleting %s box %s...\n", str_fn[t^1], svars->orig_name[t^1] );
|
|
|
|
svars->drv[t^1]->delete_box( svars->ctx[t^1], box_deleted, INV_AUX );
|
2014-12-29 01:08:48 +00:00
|
|
|
} else {
|
|
|
|
if (!(svars->chan->ops[t] & OP_CREATE)) {
|
2017-03-24 18:24:30 +00:00
|
|
|
box_opened( DRV_BOX_BAD, UIDVAL_BAD, AUX );
|
2014-12-29 01:08:48 +00:00
|
|
|
} else {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
info( "Creating %s box %s...\n", str_fn[t], svars->orig_name[t] );
|
2014-12-29 01:08:48 +00:00
|
|
|
svars->drv[t]->create_box( svars->ctx[t], box_created, AUX );
|
|
|
|
}
|
|
|
|
}
|
2014-12-29 00:42:17 +00:00
|
|
|
} else {
|
2014-12-29 01:08:48 +00:00
|
|
|
box_opened2( svars, t );
|
2014-12-29 00:42:17 +00:00
|
|
|
}
|
2014-12-29 01:08:48 +00:00
|
|
|
if (t || check_cancel( svars ))
|
|
|
|
break;
|
2014-12-29 00:42:17 +00:00
|
|
|
}
|
2014-12-29 01:08:48 +00:00
|
|
|
sync_deref( svars );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_deleted( int sts, void *aux )
|
|
|
|
{
|
|
|
|
DECL_SVARS;
|
|
|
|
|
|
|
|
if (check_ret( sts, aux ))
|
|
|
|
return;
|
|
|
|
INIT_SVARS(aux);
|
|
|
|
|
|
|
|
delete_state( svars );
|
|
|
|
svars->drv[t]->finish_delete_box( svars->ctx[t] );
|
|
|
|
sync_bail( svars );
|
2014-12-29 00:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_created( int sts, void *aux )
|
|
|
|
{
|
|
|
|
DECL_SVARS;
|
|
|
|
|
|
|
|
if (check_ret( sts, aux ))
|
|
|
|
return;
|
|
|
|
INIT_SVARS(aux);
|
|
|
|
|
|
|
|
svars->drv[t]->open_box( svars->ctx[t], box_opened, AUX );
|
|
|
|
}
|
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
static void
|
2020-07-08 11:45:06 +00:00
|
|
|
box_opened( int sts, uint uidvalidity, void *aux )
|
2014-12-27 22:13:45 +00:00
|
|
|
{
|
|
|
|
DECL_SVARS;
|
2014-12-29 00:42:17 +00:00
|
|
|
|
|
|
|
if (sts == DRV_CANCELED)
|
|
|
|
return;
|
|
|
|
INIT_SVARS(aux);
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sts == DRV_BOX_BAD) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
error( "Error: channel %s: %s box %s cannot be opened.\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t] );
|
2014-12-29 00:42:17 +00:00
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail( svars );
|
|
|
|
} else {
|
2017-03-24 18:24:30 +00:00
|
|
|
svars->newuidval[t] = uidvalidity;
|
2014-12-29 00:42:17 +00:00
|
|
|
box_opened2( svars, t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_opened2( sync_vars_t *svars, int t )
|
|
|
|
{
|
2014-12-27 22:13:45 +00:00
|
|
|
store_t *ctx[2];
|
|
|
|
channel_conf_t *chan;
|
2015-01-03 22:16:20 +00:00
|
|
|
sync_rec_t *srec;
|
2017-03-21 19:05:29 +00:00
|
|
|
uint_array_alloc_t mexcs;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint opts[2], fails, minwuid;
|
2014-12-27 22:13:45 +00:00
|
|
|
|
|
|
|
svars->state[t] |= ST_SELECTED;
|
2022-04-12 11:06:55 +00:00
|
|
|
if (!(svars->state[t^1] & ST_SELECTED))
|
2014-12-27 22:13:45 +00:00
|
|
|
return;
|
2015-01-03 22:16:20 +00:00
|
|
|
ctx[0] = svars->ctx[0];
|
|
|
|
ctx[1] = svars->ctx[1];
|
|
|
|
chan = svars->chan;
|
2011-07-23 14:06:32 +00:00
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
fails = 0;
|
2011-07-23 14:06:32 +00:00
|
|
|
for (t = 0; t < 2; t++)
|
2017-03-24 18:24:30 +00:00
|
|
|
if (svars->uidval[t] != UIDVAL_BAD && svars->uidval[t] != svars->newuidval[t])
|
2014-12-27 22:13:45 +00:00
|
|
|
fails++;
|
2021-02-20 21:52:49 +00:00
|
|
|
// If only one side changed UIDVALIDITY, we will try to re-approve it further down.
|
2016-12-18 19:50:20 +00:00
|
|
|
if (fails == 2) {
|
2021-02-20 21:52:01 +00:00
|
|
|
error( "Error: channel %s: UIDVALIDITY of both far side %s and near side %s changed.\n",
|
|
|
|
svars->chan->name, svars->orig_name[F], svars->orig_name[N]);
|
2014-12-27 22:13:45 +00:00
|
|
|
bail:
|
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail( svars );
|
|
|
|
return;
|
|
|
|
}
|
2011-07-23 14:06:32 +00:00
|
|
|
|
2014-12-27 22:50:31 +00:00
|
|
|
if (!lock_state( svars ))
|
|
|
|
goto bail;
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2022-02-18 16:45:01 +00:00
|
|
|
int any_dummies[2] = { 0, 0 };
|
2022-03-19 16:35:52 +00:00
|
|
|
int any_purges[2] = { 0, 0 };
|
|
|
|
int any_upgrades[2] = { 0, 0 };
|
|
|
|
int any_new[2] = { 0, 0 };
|
|
|
|
int any_tuids[2] = { 0, 0 };
|
2022-01-12 11:49:17 +00:00
|
|
|
if (svars->replayed || ((chan->ops[F] | chan->ops[N]) & OP_UPGRADE)) {
|
2022-03-19 16:35:52 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
2022-02-18 16:45:01 +00:00
|
|
|
if (srec->status & S_DUMMY(F))
|
|
|
|
any_dummies[F]++;
|
|
|
|
else if (srec->status & S_DUMMY(N))
|
|
|
|
any_dummies[N]++;
|
|
|
|
else if (srec->status & S_SKIPPED)
|
|
|
|
any_dummies[!srec->uid[F] ? F : N]++;
|
|
|
|
if (!svars->replayed)
|
|
|
|
continue;
|
2021-12-10 17:37:28 +00:00
|
|
|
if ((shifted_bit(srec->status, S_EXPIRE, S_EXPIRED) ^ srec->status) & S_EXPIRED)
|
|
|
|
svars->any_expiring = 1;
|
2022-03-19 16:35:52 +00:00
|
|
|
if (srec->status & S_PURGE) {
|
|
|
|
any_purges[srec->uid[F] ? F : N]++;
|
|
|
|
} else if (srec->status & S_PENDING) {
|
|
|
|
t = !srec->uid[F] ? F : N;
|
|
|
|
if (srec->status & S_UPGRADE)
|
|
|
|
any_upgrades[t]++;
|
|
|
|
else
|
|
|
|
any_new[t]++;
|
|
|
|
if (srec->tuid[0])
|
|
|
|
any_tuids[t]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
opts[F] = opts[N] = 0;
|
2016-12-18 19:50:20 +00:00
|
|
|
if (fails)
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
opts[F] = opts[N] = OPEN_OLD|OPEN_OLD_IDS;
|
2006-01-29 11:35:22 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2022-03-19 16:35:52 +00:00
|
|
|
if (any_purges[t]) {
|
|
|
|
debug( "resuming %d %s purge(s)\n", any_purges[t], str_fn[t] );
|
|
|
|
opts[t] |= OPEN_SETFLAGS;
|
|
|
|
}
|
|
|
|
if (any_tuids[t]) {
|
|
|
|
debug( "finding %d %sed message(s)\n", any_tuids[t], str_hl[t] );
|
|
|
|
opts[t] |= OPEN_NEW | OPEN_FIND;
|
|
|
|
svars->state[t] |= ST_FIND_OLD;
|
|
|
|
}
|
2022-05-18 17:03:22 +00:00
|
|
|
if (chan->ops[t] & (OP_GONE | OP_FLAGS)) {
|
2006-01-29 11:35:22 +00:00
|
|
|
opts[t] |= OPEN_SETFLAGS;
|
2022-04-12 11:06:55 +00:00
|
|
|
opts[t^1] |= OPEN_OLD;
|
2006-01-29 11:35:22 +00:00
|
|
|
if (chan->ops[t] & OP_FLAGS)
|
2022-04-12 11:06:55 +00:00
|
|
|
opts[t^1] |= OPEN_FLAGS;
|
2006-01-29 11:35:22 +00:00
|
|
|
}
|
2022-01-12 11:49:17 +00:00
|
|
|
if (!any_dummies[t] && (chan->ops[t] & OP_UPGRADE)) {
|
|
|
|
chan->ops[t] &= ~OP_UPGRADE;
|
|
|
|
debug( "no %s dummies; masking Upgrade\n", str_fn[t] );
|
2022-02-18 16:45:01 +00:00
|
|
|
}
|
2022-01-12 11:49:17 +00:00
|
|
|
if ((chan->ops[t] & (OP_NEW | OP_UPGRADE)) || any_new[t] || any_upgrades[t]) {
|
2006-01-29 11:35:22 +00:00
|
|
|
opts[t] |= OPEN_APPEND;
|
2022-03-19 16:35:52 +00:00
|
|
|
if ((chan->ops[t] & OP_NEW) || any_new[t]) {
|
|
|
|
debug( "resuming %s of %d new message(s)\n", str_hl[t], any_new[t] );
|
2022-04-12 11:06:55 +00:00
|
|
|
opts[t^1] |= OPEN_NEW;
|
2019-12-29 13:37:53 +00:00
|
|
|
if (chan->stores[t]->max_size != UINT_MAX)
|
2022-06-17 14:49:33 +00:00
|
|
|
opts[t^1] |= OPEN_NEW_SIZE;
|
2016-12-18 20:22:52 +00:00
|
|
|
}
|
2022-01-12 11:49:17 +00:00
|
|
|
if ((chan->ops[t] & OP_UPGRADE) || any_upgrades[t]) {
|
2022-03-19 16:35:52 +00:00
|
|
|
debug( "resuming %s of %d upgrade(s)\n", str_hl[t], any_upgrades[t] );
|
2022-01-12 11:49:17 +00:00
|
|
|
if (chan->ops[t] & OP_UPGRADE)
|
2022-03-19 16:35:52 +00:00
|
|
|
opts[t] |= OPEN_OLD | OPEN_FLAGS | OPEN_SETFLAGS;
|
|
|
|
opts[t^1] |= OPEN_OLD;
|
2019-12-29 13:37:53 +00:00
|
|
|
}
|
2022-02-10 19:27:31 +00:00
|
|
|
if ((chan->ops[t] | chan->ops[t^1]) & OP_EXPUNGE) // Don't propagate doomed msgs
|
2022-04-12 11:06:55 +00:00
|
|
|
opts[t^1] |= OPEN_FLAGS;
|
2006-01-29 11:35:22 +00:00
|
|
|
}
|
|
|
|
if (chan->ops[t] & OP_EXPUNGE) {
|
|
|
|
opts[t] |= OPEN_EXPUNGE;
|
|
|
|
if (chan->stores[t]->trash) {
|
|
|
|
if (!chan->stores[t]->trash_only_new)
|
|
|
|
opts[t] |= OPEN_OLD;
|
|
|
|
opts[t] |= OPEN_NEW|OPEN_FLAGS;
|
2022-04-12 11:06:55 +00:00
|
|
|
} else if (chan->stores[t^1]->trash && chan->stores[t^1]->trash_remote_new) {
|
2006-01-29 11:35:22 +00:00
|
|
|
opts[t] |= OPEN_NEW|OPEN_FLAGS;
|
2022-01-08 13:12:18 +00:00
|
|
|
}
|
2006-01-29 11:35:22 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-08 12:55:33 +00:00
|
|
|
// While only new messages can cause expiration due to displacement,
|
|
|
|
// updating flags can cause expiration of already overdue messages.
|
|
|
|
// The latter would also apply when the expired box is the source,
|
|
|
|
// but it's more natural to treat it as read-only in that case.
|
2022-01-12 11:49:17 +00:00
|
|
|
// OP_UPGRADE makes sense only for legacy S_SKIPPED entries.
|
|
|
|
if ((chan->ops[N] & (OP_NEW | OP_UPGRADE | OP_FLAGS)) && chan->max_messages)
|
2021-12-10 17:37:28 +00:00
|
|
|
svars->any_expiring = 1;
|
|
|
|
if (svars->any_expiring) {
|
2022-02-18 17:48:06 +00:00
|
|
|
opts[N] |= OPEN_OLD | OPEN_FLAGS;
|
2022-02-22 15:42:22 +00:00
|
|
|
if (any_dummies[N])
|
|
|
|
opts[F] |= OPEN_OLD | OPEN_FLAGS;
|
2022-01-12 11:49:17 +00:00
|
|
|
else if (chan->ops[N] & (OP_NEW | OP_UPGRADE))
|
2022-02-20 11:39:19 +00:00
|
|
|
opts[F] |= OPEN_FLAGS;
|
2021-12-10 17:37:28 +00:00
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
svars->opts[F] = svars->drv[F]->prepare_load_box( ctx[F], opts[F] );
|
|
|
|
svars->opts[N] = svars->drv[N]->prepare_load_box( ctx[N], opts[N] );
|
2006-01-29 11:35:22 +00:00
|
|
|
|
2016-11-04 20:48:58 +00:00
|
|
|
ARRAY_INIT( &mexcs );
|
2022-06-01 17:32:58 +00:00
|
|
|
if ((svars->opts[F] & OPEN_OLD) && chan->max_messages) {
|
|
|
|
/* When messages have been expired on the near side, the far side fetch is split into
|
|
|
|
* two ranges: The bulk fetch which corresponds with the most recent messages, and an
|
|
|
|
* exception list of messages which would have been expired if they weren't important. */
|
|
|
|
debug( "preparing far side selection - max expired far uid is %u\n", svars->maxxfuid );
|
|
|
|
/* First, find out the lower bound for the bulk fetch. */
|
|
|
|
minwuid = svars->maxxfuid + 1;
|
|
|
|
/* Next, calculate the exception fetch. */
|
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
|
|
|
if (!srec->uid[F])
|
|
|
|
continue; // No message; other state is irrelevant
|
|
|
|
if (srec->uid[F] >= minwuid)
|
|
|
|
continue; // Message is in non-expired range
|
|
|
|
if ((svars->opts[F] & OPEN_NEW) && srec->uid[F] > svars->maxuid[F])
|
|
|
|
continue; // Message is in expired range, but new range overlaps that
|
|
|
|
if (!srec->uid[N] && !(srec->status & S_PENDING))
|
|
|
|
continue; // Only actually paired up messages matter
|
|
|
|
// The pair is alive, but outside the bulk range
|
|
|
|
*uint_array_append( &mexcs ) = srec->uid[F];
|
2013-11-17 10:23:44 +00:00
|
|
|
}
|
2022-06-01 17:32:58 +00:00
|
|
|
sort_uint_array( mexcs.array );
|
2013-11-17 10:23:44 +00:00
|
|
|
} else {
|
2022-06-01 17:32:58 +00:00
|
|
|
minwuid = 1;
|
2013-11-17 10:23:44 +00:00
|
|
|
}
|
2013-12-11 15:13:49 +00:00
|
|
|
sync_ref( svars );
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
load_box( svars, F, minwuid, mexcs.array );
|
2013-12-11 15:13:49 +00:00
|
|
|
if (!check_cancel( svars ))
|
2022-06-01 17:32:58 +00:00
|
|
|
load_box( svars, N, 1, (uint_array_t){ NULL, 0 } );
|
2013-12-11 15:13:49 +00:00
|
|
|
sync_deref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:45:06 +00:00
|
|
|
static uint
|
2016-12-18 20:22:52 +00:00
|
|
|
get_seenuid( sync_vars_t *svars, int t )
|
|
|
|
{
|
2017-03-21 19:05:29 +00:00
|
|
|
uint seenuid = 0;
|
2016-12-18 20:22:52 +00:00
|
|
|
for (sync_rec_t *srec = svars->srecs; srec; srec = srec->next)
|
|
|
|
if (!(srec->status & S_DEAD) && seenuid < srec->uid[t])
|
|
|
|
seenuid = srec->uid[t];
|
|
|
|
return seenuid;
|
|
|
|
}
|
|
|
|
|
2017-03-24 17:09:40 +00:00
|
|
|
static void box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
static void
|
2017-03-21 19:05:29 +00:00
|
|
|
load_box( sync_vars_t *svars, int t, uint minwuid, uint_array_t mexcs )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2019-12-29 10:52:26 +00:00
|
|
|
uint maxwuid = 0, pairuid = UINT_MAX;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2017-03-24 13:18:41 +00:00
|
|
|
if (svars->opts[t] & OPEN_NEW) {
|
2022-06-01 17:32:58 +00:00
|
|
|
if (!(svars->opts[t] & OPEN_OLD) || (minwuid > svars->maxuid[t] + 1))
|
2006-03-21 20:03:21 +00:00
|
|
|
minwuid = svars->maxuid[t] + 1;
|
2017-03-21 19:05:29 +00:00
|
|
|
maxwuid = UINT_MAX;
|
2019-12-29 10:52:26 +00:00
|
|
|
if (svars->opts[t] & OPEN_OLD_IDS) // Implies OPEN_OLD
|
|
|
|
pairuid = get_seenuid( svars, t );
|
2017-03-24 13:18:41 +00:00
|
|
|
} else if (svars->opts[t] & OPEN_OLD) {
|
2019-12-29 10:52:26 +00:00
|
|
|
maxwuid = get_seenuid( svars, t );
|
2022-06-01 17:32:58 +00:00
|
|
|
} else {
|
|
|
|
minwuid = UINT_MAX;
|
2016-12-18 20:22:52 +00:00
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
info( "Loading %s box...\n", str_fn[t] );
|
2019-12-29 10:52:26 +00:00
|
|
|
svars->drv[t]->load_box( svars->ctx[t], minwuid, maxwuid, svars->finduid[t], pairuid, svars->maxuid[t], mexcs, box_loaded, AUX );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:20:35 +00:00
|
|
|
typedef struct {
|
|
|
|
sync_rec_t *srec;
|
|
|
|
uchar flags;
|
|
|
|
} alive_srec_t;
|
|
|
|
|
|
|
|
static int
|
|
|
|
cmp_srec_far( const void *a, const void *b )
|
|
|
|
{
|
|
|
|
uint au = (*(const alive_srec_t *)a).srec->uid[F];
|
|
|
|
uint bu = (*(const alive_srec_t *)b).srec->uid[F];
|
|
|
|
assert( au && bu );
|
|
|
|
assert( au != bu );
|
|
|
|
return au > bu ? 1 : -1; // Can't subtract, the result might not fit into signed int.
|
|
|
|
}
|
|
|
|
|
2006-03-21 20:03:21 +00:00
|
|
|
typedef struct {
|
|
|
|
void *aux;
|
|
|
|
sync_rec_t *srec;
|
|
|
|
int aflags, dflags;
|
|
|
|
} flag_vars_t;
|
|
|
|
|
2013-11-24 14:58:32 +00:00
|
|
|
static void flags_set( int sts, void *aux );
|
|
|
|
static void flags_set_p2( sync_vars_t *svars, sync_rec_t *srec, int t );
|
2013-12-11 15:13:49 +00:00
|
|
|
static void msgs_flags_set( sync_vars_t *svars, int t );
|
2017-03-21 19:05:29 +00:00
|
|
|
static void msg_copied( int sts, uint uid, copy_vars_t *vars );
|
2012-07-29 21:14:48 +00:00
|
|
|
static void msgs_copied( sync_vars_t *svars, int t );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-24 17:09:40 +00:00
|
|
|
box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2011-04-10 11:06:07 +00:00
|
|
|
DECL_SVARS;
|
2022-01-06 11:44:33 +00:00
|
|
|
sync_rec_t *srec, **srecmap;
|
2006-03-21 20:03:21 +00:00
|
|
|
message_t *tmsg;
|
|
|
|
flag_vars_t *fv;
|
2022-04-23 12:20:35 +00:00
|
|
|
int no[2], del[2];
|
2019-07-28 19:24:17 +00:00
|
|
|
uchar sflags, nflags, aflags, dflags;
|
2014-12-07 12:19:30 +00:00
|
|
|
uint hashsz, idx;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2011-04-10 11:06:07 +00:00
|
|
|
if (check_ret( sts, aux ))
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2011-04-10 11:06:07 +00:00
|
|
|
INIT_SVARS(aux);
|
|
|
|
svars->state[t] |= ST_LOADED;
|
2017-03-24 17:09:40 +00:00
|
|
|
svars->msgs[t] = msgs;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
info( "%s: %d messages, %d recent\n", str_fn[t], total_msgs, recent_msgs );
|
2011-04-10 11:06:07 +00:00
|
|
|
|
2013-11-02 11:57:39 +00:00
|
|
|
if (svars->state[t] & ST_FIND_OLD) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "matching previously copied messages on %s\n", str_fn[t] );
|
2021-12-29 21:38:50 +00:00
|
|
|
for (; msgs && msgs->uid < svars->finduid[t]; msgs = msgs->next) {}
|
2017-03-26 16:44:43 +00:00
|
|
|
match_tuids( svars, t, msgs );
|
2011-04-10 11:06:07 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "matching messages on %s against sync records\n", str_fn[t] );
|
2012-08-26 11:36:12 +00:00
|
|
|
hashsz = bucketsForSize( svars->nsrecs * 3 );
|
2022-04-12 11:00:54 +00:00
|
|
|
srecmap = nfzalloc( hashsz * sizeof(*srecmap) );
|
2012-08-26 11:36:12 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
2017-03-21 19:05:29 +00:00
|
|
|
uint uid = srec->uid[t];
|
2017-03-11 12:20:53 +00:00
|
|
|
if (!uid)
|
2017-03-11 12:27:53 +00:00
|
|
|
continue;
|
2017-03-21 19:05:29 +00:00
|
|
|
idx = (uint)(uid * 1103515245U) % hashsz;
|
2022-01-06 11:44:33 +00:00
|
|
|
while (srecmap[idx])
|
2012-08-26 11:36:12 +00:00
|
|
|
if (++idx == hashsz)
|
|
|
|
idx = 0;
|
2022-01-06 11:44:33 +00:00
|
|
|
srecmap[idx] = srec;
|
2012-08-26 11:36:12 +00:00
|
|
|
}
|
2017-03-24 17:09:40 +00:00
|
|
|
for (tmsg = svars->msgs[t]; tmsg; tmsg = tmsg->next) {
|
2011-04-10 11:06:07 +00:00
|
|
|
if (tmsg->srec) /* found by TUID */
|
|
|
|
continue;
|
2017-03-21 19:05:29 +00:00
|
|
|
uint uid = tmsg->uid;
|
|
|
|
idx = (uint)(uid * 1103515245U) % hashsz;
|
2022-01-06 11:44:33 +00:00
|
|
|
while ((srec = srecmap[idx])) {
|
|
|
|
if (srec->uid[t] == uid)
|
2006-03-21 20:03:21 +00:00
|
|
|
goto found;
|
2012-08-26 11:36:12 +00:00
|
|
|
if (++idx == hashsz)
|
|
|
|
idx = 0;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
found:
|
|
|
|
tmsg->srec = srec;
|
|
|
|
srec->msg[t] = tmsg;
|
|
|
|
}
|
2012-08-26 11:36:12 +00:00
|
|
|
free( srecmap );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2022-04-12 11:06:55 +00:00
|
|
|
if (!(svars->state[t^1] & ST_LOADED))
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2016-12-18 19:50:20 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2017-03-24 18:24:30 +00:00
|
|
|
if (svars->uidval[t] != UIDVAL_BAD && svars->uidval[t] != svars->newuidval[t]) {
|
2021-02-20 21:52:49 +00:00
|
|
|
// This code checks whether the messages with known UIDs are actually the
|
|
|
|
// same messages, as recognized by their Message-IDs.
|
2016-12-18 19:50:20 +00:00
|
|
|
unsigned need = 0, got = 0;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "trying to re-approve uid validity of %s\n", str_fn[t] );
|
2016-12-18 19:50:20 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
2021-02-20 21:52:49 +00:00
|
|
|
need++;
|
2016-12-18 19:50:20 +00:00
|
|
|
if (!srec->msg[t])
|
|
|
|
continue; // Message disappeared.
|
2021-02-20 21:52:49 +00:00
|
|
|
// Present paired messages require re-validation.
|
2016-12-18 19:50:20 +00:00
|
|
|
if (!srec->msg[t]->msgid)
|
|
|
|
continue; // Messages without ID are useless for re-validation.
|
2022-04-12 11:06:55 +00:00
|
|
|
if (!srec->msg[t^1])
|
2016-12-18 19:50:20 +00:00
|
|
|
continue; // Partner disappeared.
|
2022-04-12 11:06:55 +00:00
|
|
|
if (!srec->msg[t^1]->msgid || strcmp( srec->msg[F]->msgid, srec->msg[N]->msgid )) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
error( "Error: channel %s, %s box %s: UIDVALIDITY genuinely changed (at UID %u).\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t], srec->uid[t] );
|
2016-12-18 19:50:20 +00:00
|
|
|
uvchg:
|
|
|
|
svars->ret |= SYNC_FAIL;
|
|
|
|
cancel_sync( svars );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
got++;
|
|
|
|
}
|
2021-02-20 21:52:49 +00:00
|
|
|
// We encountered no messages that contradict the hypothesis that the
|
|
|
|
// UIDVALIDITY change was spurious.
|
|
|
|
// If we got enough messages confirming the hypothesis, we just accept it.
|
|
|
|
// If there aren't quite enough messages, we check that at least 80% of
|
|
|
|
// those previously present are still there and confirm the hypothesis;
|
|
|
|
// this also covers the case of a box that was already empty.
|
2016-12-18 19:50:20 +00:00
|
|
|
if (got < 20 && got * 5 < need * 4) {
|
|
|
|
// Too few confirmed messages. This is very likely in the drafts folder.
|
|
|
|
// A proper fallback would be fetching more headers (which potentially need
|
|
|
|
// normalization) or the message body (which should be truncated for sanity)
|
|
|
|
// and comparing.
|
2021-02-20 21:52:01 +00:00
|
|
|
error( "Error: channel %s, %s box %s: Unable to recover from UIDVALIDITY change.\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t] );
|
2016-12-18 19:50:20 +00:00
|
|
|
goto uvchg;
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
notice( "Notice: channel %s, %s box %s: Recovered from change of UIDVALIDITY.\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t] );
|
2017-01-29 14:39:36 +00:00
|
|
|
svars->uidval[t] = UIDVAL_BAD;
|
2016-12-18 19:50:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (svars->uidval[F] == UIDVAL_BAD || svars->uidval[N] == UIDVAL_BAD) {
|
|
|
|
svars->uidval[F] = svars->newuidval[F];
|
|
|
|
svars->uidval[N] = svars->newuidval[N];
|
|
|
|
JLOG( "| %u %u", (svars->uidval[F], svars->uidval[N]), "new UIDVALIDITYs" );
|
2001-11-15 23:59:27 +00:00
|
|
|
}
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2021-12-10 20:45:51 +00:00
|
|
|
svars->oldmaxuid[F] = svars->newmaxuid[F];
|
|
|
|
svars->oldmaxuid[N] = svars->newmaxuid[N];
|
2019-11-25 19:55:41 +00:00
|
|
|
|
2005-12-28 10:02:22 +00:00
|
|
|
info( "Synchronizing...\n" );
|
2020-01-08 17:22:48 +00:00
|
|
|
for (t = 0; t < 2; t++)
|
|
|
|
svars->good_flags[t] = (uchar)svars->drv[t]->get_supported_flags( svars->ctx[t] );
|
2006-01-29 15:52:49 +00:00
|
|
|
|
2019-11-25 19:55:41 +00:00
|
|
|
int any_new[2] = { 0, 0 };
|
|
|
|
|
2004-03-27 16:07:20 +00:00
|
|
|
debug( "synchronizing old entries\n" );
|
2013-11-24 17:26:11 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
2004-03-27 16:07:20 +00:00
|
|
|
continue;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "pair (%u,%u)\n", srec->uid[F], srec->uid[N] );
|
2017-04-02 15:21:39 +00:00
|
|
|
assert( !srec->tuid[0] );
|
2017-03-10 16:40:54 +00:00
|
|
|
// no[] means that a message is known to be not there.
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
no[F] = !srec->msg[F] && (svars->opts[F] & OPEN_OLD);
|
|
|
|
no[N] = !srec->msg[N] && (svars->opts[N] & OPEN_OLD);
|
|
|
|
if (no[F] && no[N]) {
|
2017-03-10 16:40:54 +00:00
|
|
|
// It does not matter whether one side was already known to be missing
|
|
|
|
// (never stored [skipped or failed] or expunged [possibly expired]) -
|
|
|
|
// now both are missing, so the entry is superfluous.
|
2004-03-27 16:07:20 +00:00
|
|
|
srec->status = S_DEAD;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "both missing" );
|
2004-03-27 16:07:20 +00:00
|
|
|
} else {
|
2017-03-10 16:40:54 +00:00
|
|
|
// del[] means that a message becomes known to have been expunged.
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
del[F] = no[F] && srec->uid[F];
|
|
|
|
del[N] = no[N] && srec->uid[N];
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2022-06-17 14:49:33 +00:00
|
|
|
sync_rec_t *nsrec = srec;
|
2005-12-28 10:02:22 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2022-06-17 14:49:33 +00:00
|
|
|
// Do this before possibly upgrading that side.
|
2006-02-02 17:03:01 +00:00
|
|
|
if (srec->msg[t] && (srec->msg[t]->flags & F_DELETED))
|
2022-06-16 08:40:34 +00:00
|
|
|
srec->status |= S_DEL(t);
|
2022-06-17 14:49:33 +00:00
|
|
|
// Flagging the message on the target side causes an upgrade of the dummy.
|
|
|
|
// We do this first in a separate loop, so flag propagation sees the upgraded
|
|
|
|
// state for both sides. After a journal replay, that would be the case anyway.
|
2022-01-12 11:49:17 +00:00
|
|
|
if ((svars->chan->ops[t] & OP_UPGRADE) && (srec->status & S_DUMMY(t)) && srec->uid[t^1] && srec->msg[t]) {
|
2022-06-17 14:49:33 +00:00
|
|
|
sflags = srec->msg[t]->flags;
|
|
|
|
if (sflags & F_FLAGGED) {
|
2022-02-24 13:32:55 +00:00
|
|
|
sflags &= ~(F_SEEN | F_FLAGGED) | (srec->flags & F_SEEN); // As below.
|
2022-06-17 14:49:33 +00:00
|
|
|
// We save away the dummy's flags, because after an
|
|
|
|
// interruption it may be already gone.
|
|
|
|
srec->pflags = sflags;
|
|
|
|
JLOG( "^ %u %u %u", (srec->uid[F], srec->uid[N], srec->pflags),
|
|
|
|
"upgrading %s placeholder, dummy's flags %s",
|
|
|
|
(str_fn[t], fmt_lone_flags( srec->pflags ).str) );
|
|
|
|
nsrec = upgrade_srec( svars, srec, t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (t = 0; t < 2; t++) {
|
2022-06-17 13:57:56 +00:00
|
|
|
if (srec->status & S_UPGRADE) {
|
|
|
|
// Such records hold orphans by definition, so the del[] cases are irrelevant.
|
|
|
|
if (srec->uid[t]) {
|
|
|
|
// Direction towards the source message.
|
|
|
|
// The placeholder was already detached, so use its saved flags instead.
|
|
|
|
sflags = srec->pflags;
|
|
|
|
goto doflags;
|
|
|
|
}
|
|
|
|
// Direction towards the copy.
|
|
|
|
if (srec->msg[t^1]) {
|
|
|
|
// Flag propagation along placeholder upgrades must be explicitly requested,
|
|
|
|
// and is, at the source, handled like any other flag update.
|
|
|
|
sflags = srec->msg[t^1]->flags;
|
|
|
|
goto doflags;
|
|
|
|
}
|
|
|
|
debug( " no %s\n", str_fn[t^1] );
|
|
|
|
} else if (del[t]) {
|
2017-03-10 16:40:54 +00:00
|
|
|
// The target was newly expunged, so there is nothing to update.
|
|
|
|
// The deletion is propagated in the opposite iteration.
|
2022-06-01 12:04:12 +00:00
|
|
|
srec->status |= S_GONE(t);
|
2017-03-11 12:20:53 +00:00
|
|
|
} else if (!srec->uid[t]) {
|
2017-03-10 16:40:54 +00:00
|
|
|
// The target was never stored, or was previously expunged, so there
|
|
|
|
// is nothing to update.
|
|
|
|
// Note: the opposite UID must be valid, as otherwise the entry would
|
|
|
|
// have been pruned already.
|
2022-04-12 11:06:55 +00:00
|
|
|
} else if (del[t^1]) {
|
2017-03-10 16:40:54 +00:00
|
|
|
// The source was newly expunged, so possibly propagate the deletion.
|
|
|
|
// The target may be in an unknown state (not fetched).
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((t == F) && (srec->status & (S_EXPIRE|S_EXPIRED))) {
|
2013-11-17 08:06:20 +00:00
|
|
|
/* Don't propagate deletion resulting from expiration. */
|
2022-01-07 17:25:16 +00:00
|
|
|
if (~srec->status & (S_EXPIRE | S_EXPIRED)) {
|
|
|
|
// An expiration was interrupted, but the message was expunged since.
|
|
|
|
srec->status |= S_EXPIRE | S_EXPIRED; // Override failed unexpiration attempts.
|
|
|
|
JLOG( "~ %u %u %u", (srec->uid[F], srec->uid[N], srec->status), "forced expiration commit" );
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "> %u %u 0", (srec->uid[F], srec->uid[N]), "near side expired, orphaning far side" );
|
|
|
|
srec->uid[N] = 0;
|
2013-11-17 08:06:20 +00:00
|
|
|
} else {
|
2021-12-01 10:25:06 +00:00
|
|
|
if (srec->msg[t] && (srec->msg[t]->status & M_FLAGS) &&
|
|
|
|
// Ignore deleted flag, as that's what we'll change ourselves ...
|
|
|
|
(((srec->msg[t]->flags & ~F_DELETED) != (srec->flags & ~F_DELETED)) ||
|
|
|
|
// ... except for undeletion, as that's the opposite.
|
|
|
|
(!(srec->msg[t]->flags & F_DELETED) && (srec->flags & F_DELETED))))
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
notice( "Notice: conflicting changes in (%u,%u)\n", srec->uid[F], srec->uid[N] );
|
2022-05-18 17:03:22 +00:00
|
|
|
if (svars->chan->ops[t] & OP_GONE) {
|
2013-11-17 08:06:20 +00:00
|
|
|
debug( " %sing delete\n", str_hl[t] );
|
2013-11-24 14:58:32 +00:00
|
|
|
srec->aflags[t] = F_DELETED;
|
2022-06-16 08:40:34 +00:00
|
|
|
srec->status |= S_DELETE;
|
2013-11-17 08:06:20 +00:00
|
|
|
} else {
|
|
|
|
debug( " not %sing delete\n", str_hl[t] );
|
|
|
|
}
|
|
|
|
}
|
2022-04-12 11:06:55 +00:00
|
|
|
} else if (!srec->msg[t^1]) {
|
2017-03-10 16:40:54 +00:00
|
|
|
// We have no source to work with, because it was never stored,
|
|
|
|
// it was previously expunged, or we did not fetch it.
|
2022-04-12 11:06:55 +00:00
|
|
|
debug( " no %s\n", str_fn[t^1] );
|
2017-03-10 16:40:54 +00:00
|
|
|
} else {
|
|
|
|
// We have a source. The target may be in an unknown state.
|
2022-06-17 13:57:56 +00:00
|
|
|
sflags = srec->msg[t^1]->flags;
|
|
|
|
|
|
|
|
doflags:
|
2006-03-21 15:53:43 +00:00
|
|
|
if (svars->chan->ops[t] & OP_FLAGS) {
|
2022-06-17 13:57:56 +00:00
|
|
|
sflags = sanitize_flags( sflags, svars, t );
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((t == F) && (srec->status & (S_EXPIRE|S_EXPIRED))) {
|
2013-11-02 19:06:08 +00:00
|
|
|
/* Don't propagate deletion resulting from expiration. */
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( " near side expiring\n" );
|
2006-02-02 17:03:01 +00:00
|
|
|
sflags &= ~F_DELETED;
|
2013-11-02 19:06:08 +00:00
|
|
|
}
|
2022-04-12 11:06:55 +00:00
|
|
|
if (srec->status & S_DUMMY(t^1)) {
|
2022-06-17 14:49:33 +00:00
|
|
|
// From placeholders, don't propagate:
|
2022-02-24 13:32:55 +00:00
|
|
|
// - Seen, because the real contents were obviously not seen yet.
|
|
|
|
// However, we do propagate un-seeing.
|
2019-12-29 13:37:53 +00:00
|
|
|
// - Flagged, because it's just a request to upgrade
|
2022-02-24 13:32:55 +00:00
|
|
|
sflags &= ~(F_SEEN | F_FLAGGED) | (srec->flags & F_SEEN);
|
2022-06-17 14:49:33 +00:00
|
|
|
} else if (srec->status & S_DUMMY(t)) {
|
|
|
|
// Don't propagate Flagged to placeholders, as that would be
|
|
|
|
// misunderstood as a request to upgrade next time around. We
|
|
|
|
// could replace the placeholder with one with(out) the flag
|
|
|
|
// notice line (we can't modify the existing one due to IMAP
|
|
|
|
// semantics), but that seems like major overkill, esp. as the
|
|
|
|
// user likely wouldn't even notice the change. So the flag
|
|
|
|
// won't be seen until the placeholder is upgraded - tough luck.
|
|
|
|
sflags &= ~F_FLAGGED;
|
2019-12-29 13:37:53 +00:00
|
|
|
}
|
2006-02-02 17:03:01 +00:00
|
|
|
srec->aflags[t] = sflags & ~srec->flags;
|
|
|
|
srec->dflags[t] = ~sflags & srec->flags;
|
2022-06-15 15:17:23 +00:00
|
|
|
if (srec->aflags[t] || srec->dflags[t]) {
|
|
|
|
debug( " %sing flags: +%s -%s\n", str_hl[t],
|
|
|
|
fmt_flags( srec->aflags[t] ).str, fmt_flags( srec->dflags[t] ).str );
|
2006-02-02 11:23:57 +00:00
|
|
|
}
|
2017-03-10 16:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-28 10:02:22 +00:00
|
|
|
}
|
2021-12-08 12:55:33 +00:00
|
|
|
srec = nsrec; // Minor optimization: skip freshly created placeholder entry.
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2001-11-15 23:59:27 +00:00
|
|
|
}
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2013-11-24 17:26:11 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2022-04-12 11:06:55 +00:00
|
|
|
debug( "synchronizing new messages on %s\n", str_fn[t^1] );
|
2021-12-10 20:45:51 +00:00
|
|
|
int topping = 1;
|
2022-04-12 11:06:55 +00:00
|
|
|
for (tmsg = svars->msgs[t^1]; tmsg; tmsg = tmsg->next) {
|
2022-01-03 15:53:43 +00:00
|
|
|
if (tmsg->status & M_DEAD)
|
|
|
|
continue;
|
2013-11-24 17:26:11 +00:00
|
|
|
srec = tmsg->srec;
|
2020-07-08 12:37:57 +00:00
|
|
|
if (srec) {
|
2021-12-10 20:45:51 +00:00
|
|
|
// This covers legacy (or somehow corrupted) state files which
|
|
|
|
// failed to track maxuid properly.
|
|
|
|
// Note that this doesn't work in the presence of skipped or
|
|
|
|
// failed messages. We could start keeping zombie entries, but
|
|
|
|
// this wouldn't help with legacy state files.
|
|
|
|
if (topping && svars->newmaxuid[t^1] < tmsg->uid)
|
|
|
|
svars->newmaxuid[t^1] = tmsg->uid;
|
|
|
|
|
2020-07-08 12:37:57 +00:00
|
|
|
if (srec->status & S_SKIPPED) {
|
2019-12-29 13:37:53 +00:00
|
|
|
// Pre-1.4 legacy only: The message was skipped due to being too big.
|
2022-01-12 11:49:17 +00:00
|
|
|
if (!(svars->chan->ops[t] & OP_UPGRADE))
|
2020-07-08 12:37:57 +00:00
|
|
|
continue;
|
2019-12-29 13:37:53 +00:00
|
|
|
// The message size was not queried, so this won't be dummified below.
|
2022-06-17 14:49:33 +00:00
|
|
|
srec->status = S_PENDING | S_DUMMY(t);
|
|
|
|
JLOG( "_ %u %u", (srec->uid[F], srec->uid[N]), "placeholder only - was previously skipped" );
|
2020-07-08 12:37:57 +00:00
|
|
|
} else {
|
2022-06-17 13:57:56 +00:00
|
|
|
if (!(svars->chan->ops[t] & OP_NEW) && !(srec->status & S_UPGRADE))
|
2020-07-08 12:37:57 +00:00
|
|
|
continue;
|
|
|
|
if (!(srec->status & S_PENDING))
|
|
|
|
continue; // Nothing to do - the message is paired or expired
|
|
|
|
// Propagation was scheduled, but we got interrupted
|
2019-12-29 13:37:53 +00:00
|
|
|
debug( "unpropagated old message %u\n", tmsg->uid );
|
2022-06-17 13:57:56 +00:00
|
|
|
|
|
|
|
if (srec->status & S_UPGRADE) {
|
2022-02-10 19:27:31 +00:00
|
|
|
if (((svars->chan->ops[t] & OP_EXPUNGE) &&
|
|
|
|
((srec->pflags | srec->aflags[t]) & ~srec->dflags[t] & F_DELETED)) ||
|
|
|
|
((svars->chan->ops[t^1] & OP_EXPUNGE) &&
|
|
|
|
((srec->msg[t^1]->flags | srec->aflags[t^1]) & ~srec->dflags[t^1] & F_DELETED))) {
|
2022-06-17 13:57:56 +00:00
|
|
|
// We can't just kill the entry, as we may be propagating flags
|
|
|
|
// (in particular, F_DELETED) towards the real message.
|
|
|
|
// No dummy is actually present, but pretend there is, so the
|
|
|
|
// real message is considered new when trashing.
|
|
|
|
srec->status = (srec->status & ~(S_PENDING | S_UPGRADE)) | S_DUMMY(t);
|
|
|
|
JLOG( "~ %u %u %d", (srec->uid[F], srec->uid[N], srec->status & S_LOGGED),
|
|
|
|
"canceling placeholder upgrade - would be expunged anyway" );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Prevent the driver from "completing" the flags, as we'll ignore them anyway.
|
|
|
|
tmsg->status |= M_FLAGS;
|
|
|
|
any_new[t] = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-08 12:37:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-12-10 20:45:51 +00:00
|
|
|
// The 1st unknown message which should be known marks the end
|
|
|
|
// of the synced range; more known messages may follow (from an
|
|
|
|
// unidirectional sync in the opposite direction).
|
|
|
|
if (t == F || tmsg->uid > svars->maxxfuid)
|
|
|
|
topping = 0;
|
|
|
|
|
2020-07-08 12:37:57 +00:00
|
|
|
if (!(svars->chan->ops[t] & OP_NEW))
|
|
|
|
continue;
|
2022-04-12 11:06:55 +00:00
|
|
|
if (tmsg->uid <= svars->maxuid[t^1]) {
|
2020-07-08 12:37:57 +00:00
|
|
|
// The message should be already paired. It's not, so it was:
|
|
|
|
// - previously paired, but the entry was expired and pruned => ignore
|
|
|
|
// - attempted, but failed => ignore (the wisdom of this is debatable)
|
|
|
|
// - ignored, as it would have been expunged anyway => ignore (even if undeleted)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
debug( "new message %u\n", tmsg->uid );
|
|
|
|
|
2022-04-12 11:00:54 +00:00
|
|
|
srec = nfzalloc( sizeof(*srec) );
|
2020-07-08 12:37:57 +00:00
|
|
|
*svars->srecadd = srec;
|
|
|
|
svars->srecadd = &srec->next;
|
|
|
|
svars->nsrecs++;
|
|
|
|
srec->status = S_PENDING;
|
2022-04-12 11:06:55 +00:00
|
|
|
srec->uid[t^1] = tmsg->uid;
|
|
|
|
srec->msg[t^1] = tmsg;
|
2020-07-08 12:37:57 +00:00
|
|
|
tmsg->srec = srec;
|
2021-12-10 20:45:51 +00:00
|
|
|
if (svars->newmaxuid[t^1] < tmsg->uid)
|
|
|
|
svars->newmaxuid[t^1] = tmsg->uid;
|
2020-07-08 12:37:57 +00:00
|
|
|
JLOG( "+ %u %u", (srec->uid[F], srec->uid[N]), "fresh" );
|
|
|
|
}
|
2022-02-10 19:27:31 +00:00
|
|
|
if (((svars->chan->ops[t] | svars->chan->ops[t^1]) & OP_EXPUNGE) && (tmsg->flags & F_DELETED)) {
|
2021-12-10 20:45:51 +00:00
|
|
|
// Yes, we may nuke fresh entries, created only for newmaxuid tracking.
|
|
|
|
// It would be lighter on the journal to log a (compressed) skip, but
|
|
|
|
// this rare case does not justify additional complexity.
|
|
|
|
JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "killing - would be expunged anyway" );
|
|
|
|
tmsg->srec = NULL;
|
|
|
|
srec->status = S_DEAD;
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-17 14:49:33 +00:00
|
|
|
if (tmsg->size > svars->chan->stores[t]->max_size && !(srec->status & (S_DUMMY(F) | S_DUMMY(N)))) {
|
2019-12-29 13:37:53 +00:00
|
|
|
srec->status |= S_DUMMY(t);
|
|
|
|
JLOG( "_ %u %u", (srec->uid[F], srec->uid[N]), "placeholder only - too big" );
|
2013-11-24 17:26:11 +00:00
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
any_new[t] = 1;
|
2013-11-24 17:26:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-10 17:37:28 +00:00
|
|
|
if (svars->any_expiring) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
// Note: When this branch is entered, we have loaded all near side messages.
|
2013-11-10 18:57:08 +00:00
|
|
|
/* Expire excess messages. Important (flagged, unread, or unpropagated) messages
|
|
|
|
* older than the first not expired message are not counted towards the total. */
|
2013-11-23 11:01:23 +00:00
|
|
|
debug( "preparing message expiration\n" );
|
2022-04-23 12:20:35 +00:00
|
|
|
alive_srec_t *arecs = nfmalloc( sizeof(*arecs) * svars->nsrecs );
|
|
|
|
int alive = 0;
|
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
2013-05-20 16:53:22 +00:00
|
|
|
continue;
|
2022-04-23 12:20:35 +00:00
|
|
|
// We completely ignore unpaired near-side messages, as we cannot expire
|
|
|
|
// them without data loss; consequently, we also don't count them.
|
|
|
|
// Note that we also ignore near-side messages we're currently propagating,
|
|
|
|
// which delays expiration of some messages by one cycle. Otherwise, we'd
|
|
|
|
// have to sequence flag updating after message propagation to avoid a race
|
|
|
|
// with external expunging, and that seems unreasonably expensive.
|
|
|
|
if (!srec->uid[F])
|
2020-07-16 12:47:30 +00:00
|
|
|
continue;
|
|
|
|
if (!(srec->status & S_PENDING)) {
|
2022-04-23 12:20:35 +00:00
|
|
|
// We ignore unpaired far-side messages, as there is obviously nothing
|
|
|
|
// to expire in the first place.
|
2020-07-16 12:47:30 +00:00
|
|
|
if (!srec->msg[N])
|
2022-04-23 12:20:35 +00:00
|
|
|
continue;
|
2022-02-22 15:42:22 +00:00
|
|
|
nflags = srec->msg[N]->flags;
|
|
|
|
if (srec->status & S_DUMMY(N)) {
|
|
|
|
if (!srec->msg[F])
|
|
|
|
continue;
|
|
|
|
// We need to pull in the real Flagged and Seen even if flag
|
|
|
|
// propagation was not requested, as the placeholder's ones are
|
|
|
|
// useless (except for un-seeing).
|
|
|
|
// This results in the somewhat weird situation that messages
|
|
|
|
// which are not visibly flagged remain unexpired.
|
|
|
|
sflags = srec->msg[F]->flags;
|
|
|
|
aflags = (sflags & ~srec->flags) & (F_SEEN | F_FLAGGED);
|
|
|
|
dflags = (~sflags & srec->flags) & F_SEEN;
|
|
|
|
nflags = (nflags & (~(F_SEEN | F_FLAGGED) | (srec->flags & F_SEEN)) & ~dflags) | aflags;
|
|
|
|
}
|
|
|
|
nflags = (nflags | srec->aflags[N]) & ~srec->dflags[N];
|
2013-11-23 11:01:23 +00:00
|
|
|
} else {
|
2022-02-22 15:42:22 +00:00
|
|
|
if (srec->status & S_UPGRADE) {
|
|
|
|
// The dummy's F & S flags are mostly masked out anyway,
|
|
|
|
// but we may be pulling in the real ones.
|
|
|
|
nflags = (srec->pflags | srec->aflags[N]) & ~srec->dflags[N];
|
|
|
|
} else {
|
|
|
|
nflags = srec->msg[F]->flags;
|
|
|
|
}
|
2013-11-23 11:01:23 +00:00
|
|
|
}
|
2022-01-08 13:12:18 +00:00
|
|
|
if (!(nflags & F_DELETED) || (srec->status & (S_EXPIRE | S_EXPIRED))) {
|
2020-07-16 12:47:30 +00:00
|
|
|
// The message is not deleted, or it is, but only due to being expired.
|
2022-04-23 12:20:35 +00:00
|
|
|
arecs[alive++] = (alive_srec_t){ srec, nflags };
|
2022-01-08 13:12:18 +00:00
|
|
|
}
|
2013-11-30 12:03:12 +00:00
|
|
|
}
|
2022-04-23 12:20:35 +00:00
|
|
|
// Sort such that the messages which have been in the
|
|
|
|
// complete store longest expire first.
|
|
|
|
qsort( arecs, alive, sizeof(*arecs), cmp_srec_far );
|
|
|
|
int todel = alive - svars->chan->max_messages;
|
2013-11-23 11:01:23 +00:00
|
|
|
debug( "%d alive messages, %d excess - expiring\n", alive, todel );
|
2022-04-23 12:20:35 +00:00
|
|
|
int unseen = 0;
|
|
|
|
for (int sri = 0; sri < alive; sri++) {
|
|
|
|
srec = arecs[sri].srec;
|
|
|
|
nflags = arecs[sri].flags;
|
|
|
|
if ((nflags & F_FLAGGED) ||
|
|
|
|
!((nflags & F_SEEN) || ((void)(todel > 0 && unseen++), svars->chan->expire_unread > 0))) {
|
|
|
|
// Important messages are always fetched/kept.
|
|
|
|
debug( " pair(%u,%u) is important\n", srec->uid[F], srec->uid[N] );
|
|
|
|
todel--;
|
|
|
|
} else if (todel > 0 ||
|
|
|
|
((srec->status & (S_EXPIRE | S_EXPIRED)) == (S_EXPIRE | S_EXPIRED)) ||
|
|
|
|
((srec->status & (S_EXPIRE | S_EXPIRED)) && (srec->msg[N]->flags & F_DELETED))) {
|
|
|
|
/* The message is excess or was already (being) expired. */
|
|
|
|
srec->status |= S_NEXPIRE;
|
|
|
|
debug( " expiring pair(%u,%u)\n", srec->uid[F], srec->uid[N] );
|
|
|
|
todel--;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-02 17:03:01 +00:00
|
|
|
debug( "%d excess messages remain\n", todel );
|
2022-04-23 12:20:35 +00:00
|
|
|
if (svars->chan->expire_unread < 0 && unseen * 2 > svars->chan->max_messages) {
|
2013-11-24 19:26:33 +00:00
|
|
|
error( "%s: %d unread messages in excess of MaxMessages (%d).\n"
|
|
|
|
"Please set ExpireUnread to decide outcome. Skipping mailbox.\n",
|
2022-04-23 12:20:35 +00:00
|
|
|
svars->orig_name[N], unseen, svars->chan->max_messages );
|
2013-11-24 19:26:33 +00:00
|
|
|
svars->ret |= SYNC_FAIL;
|
|
|
|
cancel_sync( svars );
|
|
|
|
return;
|
|
|
|
}
|
2022-04-23 12:20:35 +00:00
|
|
|
for (int sri = 0; sri < alive; sri++) {
|
|
|
|
srec = arecs[sri].srec;
|
2017-04-02 15:21:39 +00:00
|
|
|
if (!(srec->status & S_PENDING)) {
|
2022-06-16 08:40:34 +00:00
|
|
|
uchar nex = (srec->status / S_NEXPIRE) & 1;
|
2013-11-30 12:03:12 +00:00
|
|
|
if (nex != ((srec->status / S_EXPIRED) & 1)) {
|
|
|
|
/* The record needs a state change ... */
|
|
|
|
if (nex != ((srec->status / S_EXPIRE) & 1)) {
|
|
|
|
/* ... and we need to start a transaction. */
|
|
|
|
srec->status = (srec->status & ~S_EXPIRE) | (nex * S_EXPIRE);
|
2022-06-16 08:40:34 +00:00
|
|
|
JLOG( "~ %u %u %d", (srec->uid[F], srec->uid[N], srec->status & S_LOGGED),
|
|
|
|
"expire %u - begin", nex );
|
2013-11-30 12:03:12 +00:00
|
|
|
} else {
|
|
|
|
/* ... but the "right" transaction is already pending. */
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "-> pair(%u,%u): expire %u (pending)\n", srec->uid[F], srec->uid[N], nex );
|
2013-11-30 12:03:12 +00:00
|
|
|
}
|
2013-11-17 16:36:08 +00:00
|
|
|
} else {
|
2013-11-30 12:03:12 +00:00
|
|
|
/* Note: the "wrong" transaction may be pending here,
|
2022-06-16 08:40:34 +00:00
|
|
|
* e.g.: S_NEXPIRE = 0, S_EXPIRE = 1, S_EXPIRED = 0. */
|
2013-11-17 16:36:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-06-16 08:40:34 +00:00
|
|
|
if (srec->status & S_NEXPIRE) {
|
2022-02-26 17:24:04 +00:00
|
|
|
srec->status = S_EXPIRE | S_EXPIRED;
|
|
|
|
JLOG( "~ %u %u %u", (srec->uid[F], srec->uid[N], srec->status), "expire unborn" );
|
2017-04-02 12:04:43 +00:00
|
|
|
// If we have so many new messages that some of them are instantly expired,
|
|
|
|
// but some are still propagated because they are important, we need to
|
|
|
|
// ensure explicitly that the bulk fetch limit is upped.
|
2020-07-20 18:53:21 +00:00
|
|
|
if (svars->maxxfuid < srec->uid[F])
|
|
|
|
svars->maxxfuid = srec->uid[F];
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
srec->msg[F]->srec = NULL;
|
2013-11-30 12:03:12 +00:00
|
|
|
}
|
2006-02-02 17:03:01 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-23 12:20:35 +00:00
|
|
|
free( arecs );
|
2006-02-02 17:03:01 +00:00
|
|
|
}
|
2006-03-21 15:53:43 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
sync_ref( svars );
|
|
|
|
|
2006-02-02 17:03:01 +00:00
|
|
|
debug( "synchronizing flags\n" );
|
2013-11-24 17:26:11 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
2019-12-29 13:37:53 +00:00
|
|
|
if (srec->status & S_DEAD)
|
2006-02-02 17:03:01 +00:00
|
|
|
continue;
|
|
|
|
for (t = 0; t < 2; t++) {
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!srec->uid[t])
|
|
|
|
continue;
|
2022-06-01 12:04:12 +00:00
|
|
|
if (srec->status & S_GONE(t)) {
|
2022-01-07 21:58:38 +00:00
|
|
|
// The message was expunged. No need to call flags_set(), because:
|
|
|
|
// - for S_DELETE and S_PURGE, the entry will be pruned due to both sides being gone
|
|
|
|
// - for regular flag propagations, there is nothing to do
|
|
|
|
// - expirations were already handled above
|
|
|
|
continue;
|
|
|
|
}
|
2006-02-02 17:03:01 +00:00
|
|
|
aflags = srec->aflags[t];
|
|
|
|
dflags = srec->dflags[t];
|
2022-06-16 08:40:34 +00:00
|
|
|
if (srec->status & (S_DELETE | S_PURGE)) {
|
2013-11-24 14:58:32 +00:00
|
|
|
if (!aflags) {
|
2019-12-29 13:37:53 +00:00
|
|
|
// This deletion propagation goes the other way round, or
|
|
|
|
// this deletion of a dummy happens on the other side.
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-24 14:58:32 +00:00
|
|
|
} else {
|
2013-11-17 16:36:08 +00:00
|
|
|
/* The trigger is an expiration transaction being ongoing ... */
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((t == N) && ((shifted_bit(srec->status, S_EXPIRE, S_EXPIRED) ^ srec->status) & S_EXPIRED)) {
|
2021-12-08 12:55:33 +00:00
|
|
|
// ... but the actual action derives from the wanted state -
|
|
|
|
// so that canceled transactions are rolled back as well.
|
2022-06-16 08:40:34 +00:00
|
|
|
if (srec->status & S_NEXPIRE)
|
2013-11-24 14:58:32 +00:00
|
|
|
aflags |= F_DELETED;
|
|
|
|
else
|
|
|
|
dflags |= F_DELETED;
|
|
|
|
}
|
2006-02-02 17:03:01 +00:00
|
|
|
}
|
2006-03-21 15:53:43 +00:00
|
|
|
if ((svars->chan->ops[t] & OP_EXPUNGE) && (((srec->msg[t] ? srec->msg[t]->flags : 0) | aflags) & ~dflags & F_DELETED) &&
|
|
|
|
(!svars->ctx[t]->conf->trash || svars->ctx[t]->conf->trash_only_new))
|
2006-02-02 17:03:01 +00:00
|
|
|
{
|
2013-11-02 19:06:08 +00:00
|
|
|
/* If the message is going to be expunged, don't propagate anything but the deletion. */
|
2006-02-02 17:03:01 +00:00
|
|
|
srec->aflags[t] &= F_DELETED;
|
|
|
|
aflags &= F_DELETED;
|
|
|
|
srec->dflags[t] = dflags = 0;
|
|
|
|
}
|
|
|
|
if (srec->msg[t] && (srec->msg[t]->status & M_FLAGS)) {
|
2013-11-02 19:06:08 +00:00
|
|
|
/* If we know the target message's state, optimize away non-changes. */
|
2006-02-02 17:03:01 +00:00
|
|
|
aflags &= ~srec->msg[t]->flags;
|
|
|
|
dflags &= srec->msg[t]->flags;
|
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
if (aflags | dflags) {
|
2015-03-28 16:26:08 +00:00
|
|
|
flags_total[t]++;
|
|
|
|
stats();
|
|
|
|
svars->flags_pending[t]++;
|
2006-03-21 20:03:21 +00:00
|
|
|
fv = nfmalloc( sizeof(*fv) );
|
|
|
|
fv->aux = AUX;
|
|
|
|
fv->srec = srec;
|
|
|
|
fv->aflags = aflags;
|
|
|
|
fv->dflags = dflags;
|
2014-12-27 21:13:24 +00:00
|
|
|
svars->drv[t]->set_msg_flags( svars->ctx[t], srec->msg[t], srec->uid[t], aflags, dflags, flags_set, fv );
|
2013-12-11 15:13:49 +00:00
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2022-01-08 13:12:18 +00:00
|
|
|
} else {
|
2013-11-24 14:58:32 +00:00
|
|
|
flags_set_p2( svars, srec, t );
|
2022-01-08 13:12:18 +00:00
|
|
|
}
|
2000-12-21 18:16:44 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
for (t = 0; t < 2; t++) {
|
2014-12-27 21:13:24 +00:00
|
|
|
svars->drv[t]->commit_cmds( svars->ctx[t] );
|
2006-03-21 20:03:21 +00:00
|
|
|
svars->state[t] |= ST_SENT_FLAGS;
|
2013-12-11 15:13:49 +00:00
|
|
|
msgs_flags_set( svars, t );
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
2013-11-23 14:55:02 +00:00
|
|
|
|
|
|
|
debug( "propagating new messages\n" );
|
|
|
|
for (t = 0; t < 2; t++) {
|
2019-11-25 19:55:41 +00:00
|
|
|
if (any_new[t]) {
|
2022-01-08 11:53:02 +00:00
|
|
|
// fsync'ing the UIDNEXT bump is not strictly necessary, but advantageous.
|
2019-11-25 19:55:41 +00:00
|
|
|
svars->finduid[t] = svars->drv[t]->get_uidnext( svars->ctx[t] );
|
|
|
|
JLOG( "F %d %u", (t, svars->finduid[t]), "save UIDNEXT of %s", str_fn[t] );
|
2022-04-12 11:06:55 +00:00
|
|
|
svars->new_msgs[t] = svars->msgs[t^1];
|
2019-11-25 19:55:41 +00:00
|
|
|
} else {
|
|
|
|
svars->state[t] |= ST_SENT_NEW;
|
|
|
|
}
|
2022-01-08 11:53:02 +00:00
|
|
|
}
|
|
|
|
if (any_new[F] | any_new[N]) {
|
|
|
|
// TUID assignment needs to be fsync'd, as otherwise a system crash may
|
|
|
|
// lead to the newly propagated messages becoming duplicated.
|
|
|
|
// Of course, we could assign each TUID only after fetching the message
|
|
|
|
// and fsync it separately, but that would be horribly inefficient.
|
|
|
|
for (srec = svars->srecs; srec; srec = srec->next)
|
|
|
|
if (srec->status & S_PENDING)
|
|
|
|
assign_tuid( svars, srec );
|
|
|
|
if (UseFSync && svars->jfp)
|
|
|
|
fdatasync( fileno( svars->jfp ) );
|
|
|
|
}
|
|
|
|
for (t = 0; t < 2; t++) {
|
2013-11-23 14:55:02 +00:00
|
|
|
msgs_copied( svars, t );
|
2013-12-11 15:13:49 +00:00
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2013-11-23 14:55:02 +00:00
|
|
|
}
|
2013-12-11 15:13:49 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
sync_deref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-21 19:05:29 +00:00
|
|
|
msg_copied( int sts, uint uid, copy_vars_t *vars )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
SVARS_CHECK_CANCEL_RET;
|
2019-12-29 11:31:10 +00:00
|
|
|
sync_rec_t *srec = vars->srec;
|
2006-03-21 20:03:21 +00:00
|
|
|
switch (sts) {
|
|
|
|
case SYNC_OK:
|
2022-01-08 13:12:18 +00:00
|
|
|
if (!uid) // Stored to a non-UIDPLUS mailbox
|
2013-11-02 11:57:39 +00:00
|
|
|
svars->state[t] |= ST_FIND_NEW;
|
2022-01-08 13:12:18 +00:00
|
|
|
else
|
2019-12-29 13:41:45 +00:00
|
|
|
ASSIGN_UID( srec, t, uid, "%sed message", str_hl[t] );
|
2006-03-21 20:03:21 +00:00
|
|
|
break;
|
|
|
|
case SYNC_NOGOOD:
|
2019-12-29 11:31:10 +00:00
|
|
|
srec->status = S_DEAD;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "%s failed", str_hl[t] );
|
2006-03-21 20:03:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cancel_sync( svars );
|
|
|
|
free( vars );
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
free( vars );
|
2015-03-28 16:26:08 +00:00
|
|
|
new_done[t]++;
|
|
|
|
stats();
|
|
|
|
svars->new_pending[t]--;
|
2012-07-29 21:14:48 +00:00
|
|
|
msgs_copied( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 16:44:43 +00:00
|
|
|
static void msgs_found_new( int sts, message_t *msgs, void *aux );
|
2011-04-10 11:06:07 +00:00
|
|
|
static void msgs_new_done( sync_vars_t *svars, int t );
|
2012-07-29 21:14:48 +00:00
|
|
|
static void sync_close( sync_vars_t *svars, int t );
|
2005-12-28 10:02:22 +00:00
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
msgs_copied( sync_vars_t *svars, int t )
|
|
|
|
{
|
2015-02-15 17:13:05 +00:00
|
|
|
message_t *tmsg;
|
|
|
|
sync_rec_t *srec;
|
|
|
|
copy_vars_t *cv;
|
|
|
|
|
|
|
|
if (svars->state[t] & ST_SENDING_NEW)
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2013-12-11 15:25:30 +00:00
|
|
|
sync_ref( svars );
|
|
|
|
|
2015-02-15 17:13:05 +00:00
|
|
|
if (!(svars->state[t] & ST_SENT_NEW)) {
|
|
|
|
for (tmsg = svars->new_msgs[t]; tmsg; tmsg = tmsg->next) {
|
2022-01-03 15:53:43 +00:00
|
|
|
if (tmsg->status & M_DEAD)
|
|
|
|
continue;
|
2017-04-02 15:21:39 +00:00
|
|
|
if ((srec = tmsg->srec) && (srec->status & S_PENDING)) {
|
2017-03-19 12:46:03 +00:00
|
|
|
if (svars->drv[t]->get_memory_usage( svars->ctx[t] ) >= BufferLimit) {
|
2015-02-15 17:13:05 +00:00
|
|
|
svars->new_msgs[t] = tmsg;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-03-28 16:26:08 +00:00
|
|
|
new_total[t]++;
|
|
|
|
stats();
|
|
|
|
svars->new_pending[t]++;
|
2015-02-15 17:13:05 +00:00
|
|
|
svars->state[t] |= ST_SENDING_NEW;
|
|
|
|
cv = nfmalloc( sizeof(*cv) );
|
|
|
|
cv->cb = msg_copied;
|
|
|
|
cv->aux = AUX;
|
|
|
|
cv->srec = srec;
|
|
|
|
cv->msg = tmsg;
|
2019-12-29 13:37:53 +00:00
|
|
|
cv->minimal = (srec->status & S_DUMMY(t));
|
2015-02-15 17:13:05 +00:00
|
|
|
copy_msg( cv );
|
|
|
|
svars->state[t] &= ~ST_SENDING_NEW;
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svars->state[t] |= ST_SENT_NEW;
|
|
|
|
}
|
|
|
|
|
2015-03-28 16:26:08 +00:00
|
|
|
if (svars->new_pending[t])
|
2015-02-15 17:13:05 +00:00
|
|
|
goto out;
|
|
|
|
|
2022-04-12 11:06:55 +00:00
|
|
|
sync_close( svars, t^1 );
|
2013-12-11 15:25:30 +00:00
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2013-11-02 19:47:20 +00:00
|
|
|
|
2013-11-02 11:57:39 +00:00
|
|
|
if (svars->state[t] & ST_FIND_NEW) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "finding just copied messages on %s\n", str_fn[t] );
|
2019-12-29 10:52:26 +00:00
|
|
|
svars->drv[t]->find_new_msgs( svars->ctx[t], svars->finduid[t], msgs_found_new, AUX );
|
2011-04-10 11:06:07 +00:00
|
|
|
} else {
|
|
|
|
msgs_new_done( svars, t );
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2013-12-11 15:25:30 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
sync_deref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-26 16:44:43 +00:00
|
|
|
msgs_found_new( int sts, message_t *msgs, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2011-04-10 11:06:07 +00:00
|
|
|
SVARS_CHECK_RET;
|
2022-02-02 12:06:43 +00:00
|
|
|
debug( "matching just copied messages on %s\n", str_fn[t] );
|
|
|
|
int num_lost = match_tuids( svars, t, msgs );
|
|
|
|
if (num_lost)
|
|
|
|
warn( "Warning: lost track of %d %sed message(s)\n", num_lost, str_hl[t] );
|
2011-04-10 11:06:07 +00:00
|
|
|
msgs_new_done( svars, t );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
msgs_new_done( sync_vars_t *svars, int t )
|
|
|
|
{
|
|
|
|
svars->state[t] |= ST_FOUND_NEW;
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_close( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2013-11-24 14:58:32 +00:00
|
|
|
flags_set( int sts, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
SVARS_CHECK_RET_VARS(flag_vars_t);
|
2019-12-29 11:31:10 +00:00
|
|
|
sync_rec_t *srec = vars->srec;
|
2006-03-21 20:03:21 +00:00
|
|
|
switch (sts) {
|
|
|
|
case DRV_OK:
|
|
|
|
if (vars->aflags & F_DELETED)
|
2022-06-16 08:40:34 +00:00
|
|
|
srec->status |= S_DEL(t);
|
2006-03-21 20:03:21 +00:00
|
|
|
else if (vars->dflags & F_DELETED)
|
2022-06-16 08:40:34 +00:00
|
|
|
srec->status &= ~S_DEL(t);
|
2019-12-29 11:31:10 +00:00
|
|
|
flags_set_p2( svars, srec, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
free( vars );
|
2015-03-28 16:26:08 +00:00
|
|
|
flags_done[t]++;
|
|
|
|
stats();
|
|
|
|
svars->flags_pending[t]--;
|
2012-07-29 21:14:48 +00:00
|
|
|
msgs_flags_set( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-24 14:58:32 +00:00
|
|
|
flags_set_p2( sync_vars_t *svars, sync_rec_t *srec, int t )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2022-04-04 19:41:18 +00:00
|
|
|
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;
|
2022-06-01 12:04:12 +00:00
|
|
|
} else if (!(srec->status & S_DELETE)) {
|
2019-07-28 19:24:17 +00:00
|
|
|
uchar nflags = (srec->flags | srec->aflags[t]) & ~srec->dflags[t];
|
2013-11-24 14:58:32 +00:00
|
|
|
if (srec->flags != nflags) {
|
2021-12-12 13:51:30 +00:00
|
|
|
JLOG( "* %u %u %u", (srec->uid[F], srec->uid[N], nflags), "%sed flags %s; were %s",
|
|
|
|
(str_hl[t], fmt_lone_flags( nflags ).str, fmt_lone_flags( srec->flags ).str) );
|
2013-11-24 14:58:32 +00:00
|
|
|
srec->flags = nflags;
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (t == N) {
|
2021-12-10 17:37:28 +00:00
|
|
|
uchar ex = (srec->status / S_EXPIRE) & 1;
|
|
|
|
uchar exd = (srec->status / S_EXPIRED) & 1;
|
|
|
|
if (ex != exd) {
|
|
|
|
uchar nex = (srec->status / S_NEXPIRE) & 1;
|
|
|
|
if (nex == ex) {
|
|
|
|
if (nex && svars->maxxfuid < srec->uid[F])
|
|
|
|
svars->maxxfuid = srec->uid[F];
|
|
|
|
srec->status = (srec->status & ~S_EXPIRED) | (nex * S_EXPIRED);
|
|
|
|
JLOG( "~ %u %u %d", (srec->uid[F], srec->uid[N], srec->status & S_LOGGED),
|
|
|
|
"expired %d - commit", nex );
|
|
|
|
} else {
|
|
|
|
srec->status = (srec->status & ~S_EXPIRE) | (nex * S_EXPIRE);
|
|
|
|
JLOG( "~ %u %u %d", (srec->uid[F], srec->uid[N], srec->status & S_LOGGED),
|
|
|
|
"expire %d - cancel", nex );
|
|
|
|
}
|
2013-11-24 14:58:32 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 20:23:39 +00:00
|
|
|
typedef struct {
|
|
|
|
void *aux;
|
|
|
|
message_t *msg;
|
|
|
|
} trash_vars_t;
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void msg_trashed( int sts, void *aux );
|
2017-03-21 19:05:29 +00:00
|
|
|
static void msg_rtrashed( int sts, uint uid, copy_vars_t *vars );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
msgs_flags_set( sync_vars_t *svars, int t )
|
|
|
|
{
|
|
|
|
message_t *tmsg;
|
2022-02-20 14:27:59 +00:00
|
|
|
sync_rec_t *srec;
|
2016-11-04 20:23:39 +00:00
|
|
|
trash_vars_t *tv;
|
2006-03-21 20:03:21 +00:00
|
|
|
copy_vars_t *cv;
|
|
|
|
|
2015-03-28 16:26:08 +00:00
|
|
|
if (!(svars->state[t] & ST_SENT_FLAGS) || svars->flags_pending[t])
|
2013-12-11 15:13:49 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
sync_ref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2022-02-06 13:56:16 +00:00
|
|
|
sync_close( svars, t^1 );
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
|
|
|
|
2022-02-20 14:27:59 +00:00
|
|
|
if (!(svars->chan->ops[t] & OP_EXPUNGE))
|
|
|
|
goto skip;
|
|
|
|
int remote, only_new;
|
|
|
|
if (svars->ctx[t]->conf->trash) {
|
|
|
|
only_new = svars->ctx[t]->conf->trash_only_new;
|
|
|
|
debug( "trashing %s on %s locally\n", only_new ? "new" : "all", str_fn[t] );
|
|
|
|
remote = 0;
|
|
|
|
} else if (svars->ctx[t^1]->conf->trash && svars->ctx[t^1]->conf->trash_remote_new) {
|
|
|
|
debug( "trashing new on %s remotely\n", str_fn[t] );
|
|
|
|
only_new = 1;
|
|
|
|
remote = 1;
|
|
|
|
} else {
|
|
|
|
goto skip;
|
|
|
|
}
|
|
|
|
for (tmsg = svars->msgs[t]; tmsg; tmsg = tmsg->next) {
|
2022-01-03 15:53:43 +00:00
|
|
|
if (tmsg->status & M_DEAD)
|
|
|
|
continue;
|
2022-02-20 14:27:59 +00:00
|
|
|
if (!(tmsg->flags & F_DELETED)) {
|
|
|
|
//debug( " message %u is not deleted\n", tmsg->uid ); // Too noisy
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
debugn( " message %u ", tmsg->uid );
|
|
|
|
if ((srec = tmsg->srec)) {
|
|
|
|
if (t == N && (srec->status & (S_EXPIRE | S_EXPIRED))) {
|
|
|
|
// Don't trash messages that are deleted only due to expiring.
|
|
|
|
// However, this is an unlikely configuration to start with ...
|
|
|
|
debug( "is expired\n" );
|
|
|
|
continue;
|
|
|
|
}
|
2022-04-04 19:41:18 +00:00
|
|
|
if (srec->status & S_DUMMY(t)) {
|
|
|
|
// This is mostly academical, as trashing being done on the side
|
|
|
|
// where placeholders reside is rather unlikely.
|
|
|
|
debug( "is dummy\n" );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (srec->status & S_PURGED) {
|
|
|
|
// As above.
|
|
|
|
debug( "is deleted dummy\n" );
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-10 19:27:31 +00:00
|
|
|
if (only_new && !(srec->status & (S_DUMMY(t^1) | S_SKIPPED))) {
|
2022-02-20 14:27:59 +00:00
|
|
|
debug( "is not new\n" );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (find_uint_array( svars->trashed_msgs[t].array, tmsg->uid )) {
|
|
|
|
debug( "was already trashed\n" );
|
|
|
|
continue;
|
|
|
|
}
|
2022-04-12 10:18:09 +00:00
|
|
|
debug( "- trashing\n" );
|
|
|
|
trash_total[t]++;
|
|
|
|
stats();
|
|
|
|
svars->trash_pending[t]++;
|
2022-02-20 14:27:59 +00:00
|
|
|
if (!remote) {
|
|
|
|
tv = nfmalloc( sizeof(*tv) );
|
|
|
|
tv->aux = AUX;
|
|
|
|
tv->msg = tmsg;
|
|
|
|
svars->drv[t]->trash_msg( svars->ctx[t], tmsg, msg_trashed, tv );
|
|
|
|
} else {
|
|
|
|
cv = nfmalloc( sizeof(*cv) );
|
|
|
|
cv->cb = msg_rtrashed;
|
|
|
|
cv->aux = INV_AUX;
|
|
|
|
cv->srec = NULL;
|
|
|
|
cv->msg = tmsg;
|
|
|
|
cv->minimal = 0;
|
|
|
|
copy_msg( cv );
|
2022-01-08 13:12:18 +00:00
|
|
|
}
|
2022-02-20 14:27:59 +00:00
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
2022-02-20 14:27:59 +00:00
|
|
|
skip:
|
2006-03-21 20:03:21 +00:00
|
|
|
svars->state[t] |= ST_SENT_TRASH;
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_close( svars, t );
|
2013-12-11 15:13:49 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
sync_deref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
msg_trashed( int sts, void *aux )
|
|
|
|
{
|
2016-11-04 20:23:39 +00:00
|
|
|
trash_vars_t *vars = (trash_vars_t *)aux;
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_SVARS;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
if (sts == DRV_MSG_BAD)
|
|
|
|
sts = DRV_BOX_BAD;
|
2016-11-04 20:23:39 +00:00
|
|
|
if (check_ret( sts, vars->aux ))
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2016-11-04 20:23:39 +00:00
|
|
|
INIT_SVARS(vars->aux);
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "T %d %u", (t, vars->msg->uid), "trashed on %s", str_fn[t] );
|
2016-11-04 20:23:39 +00:00
|
|
|
free( vars );
|
2015-03-28 16:26:08 +00:00
|
|
|
trash_done[t]++;
|
|
|
|
stats();
|
|
|
|
svars->trash_pending[t]--;
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_close( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-21 19:05:29 +00:00
|
|
|
msg_rtrashed( int sts, uint uid ATTR_UNUSED, copy_vars_t *vars )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
SVARS_CHECK_CANCEL_RET;
|
2006-03-21 20:03:21 +00:00
|
|
|
switch (sts) {
|
|
|
|
case SYNC_OK:
|
|
|
|
case SYNC_NOGOOD: /* the message is gone or heavily busted */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cancel_sync( svars );
|
|
|
|
free( vars );
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
2012-09-22 15:35:39 +00:00
|
|
|
t ^= 1;
|
2022-04-12 11:06:55 +00:00
|
|
|
JLOG( "T %d %u", (t, vars->msg->uid), "trashed remotely on %s", str_fn[t^1] );
|
2016-11-04 20:23:39 +00:00
|
|
|
free( vars );
|
2015-03-28 16:26:08 +00:00
|
|
|
trash_done[t]++;
|
|
|
|
stats();
|
|
|
|
svars->trash_pending[t]--;
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_close( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void box_closed( int sts, void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
static void box_closed_p2( sync_vars_t *svars, int t );
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
sync_close( sync_vars_t *svars, int t )
|
|
|
|
{
|
2015-03-28 16:26:08 +00:00
|
|
|
if ((~svars->state[t] & (ST_FOUND_NEW|ST_SENT_TRASH)) || svars->trash_pending[t] ||
|
2022-02-06 13:56:16 +00:00
|
|
|
(~svars->state[t^1] & (ST_SENT_NEW | ST_SENT_FLAGS)) || svars->new_pending[t^1] || svars->flags_pending[t^1])
|
2013-12-11 15:25:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (svars->state[t] & ST_CLOSING)
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2013-12-11 15:25:30 +00:00
|
|
|
svars->state[t] |= ST_CLOSING;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2022-03-17 11:58:05 +00:00
|
|
|
if ((svars->chan->ops[t] & OP_EXPUNGE) && !(DFlags & FAKEEXPUNGE)
|
|
|
|
/*&& !(svars->state[t] & ST_TRASH_BAD)*/) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "expunging %s\n", str_fn[t] );
|
2014-12-27 21:13:24 +00:00
|
|
|
svars->drv[t]->close_box( svars->ctx[t], box_closed, AUX );
|
2012-07-29 21:14:48 +00:00
|
|
|
} else {
|
|
|
|
box_closed_p2( svars, t );
|
2006-12-09 10:39:30 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
box_closed( int sts, void *aux )
|
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
SVARS_CHECK_RET;
|
2006-03-21 20:03:21 +00:00
|
|
|
svars->state[t] |= ST_DID_EXPUNGE;
|
|
|
|
box_closed_p2( svars, t );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_closed_p2( sync_vars_t *svars, int t )
|
|
|
|
{
|
|
|
|
sync_rec_t *srec;
|
|
|
|
|
|
|
|
svars->state[t] |= ST_CLOSED;
|
2022-04-12 11:06:55 +00:00
|
|
|
if (!(svars->state[t^1] & ST_CLOSED))
|
2006-03-21 20:03:21 +00:00
|
|
|
return;
|
|
|
|
|
2022-03-01 14:16:07 +00:00
|
|
|
// All logging done in this function is merely for the journal replay
|
|
|
|
// autotest - the operations are idempotent, and we're about to commit
|
|
|
|
// the new state right afterwards anyway. Therefore, it would also
|
|
|
|
// make no sense to cover it by the interrupt-resume autotest (which
|
|
|
|
// would also add unreasonable complexity, as the maxuid bumps and entry
|
|
|
|
// purge must be consistent).
|
|
|
|
|
|
|
|
if (DFlags & KEEPJOURNAL)
|
|
|
|
printf( "### %d steps, %d entries ###\n", -JLimit, JCount );
|
2017-04-02 12:04:43 +00:00
|
|
|
|
2020-07-20 18:53:21 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
|
|
|
// Committing maxuid is delayed until all messages were propagated, to
|
|
|
|
// ensure that all pending messages are still loaded next time in case
|
2021-12-08 12:55:33 +00:00
|
|
|
// of interruption - in particular skipping messages would otherwise
|
2020-07-20 18:53:21 +00:00
|
|
|
// up the limit too early.
|
2021-12-10 20:45:51 +00:00
|
|
|
svars->maxuid[t] = svars->newmaxuid[t];
|
2019-11-25 19:55:41 +00:00
|
|
|
if (svars->maxuid[t] != svars->oldmaxuid[t])
|
2021-12-11 14:43:21 +00:00
|
|
|
PC_JLOG( "N %d %u", (t, svars->maxuid[t]), "up maxuid of %s", str_fn[t] );
|
2020-07-20 18:53:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 12:04:12 +00:00
|
|
|
debug( "purging obsolete entries\n" );
|
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
|
|
|
if ((srec->status & S_DEL(F)) && (svars->state[F] & ST_DID_EXPUNGE))
|
|
|
|
srec->status |= S_GONE(F);
|
|
|
|
if ((srec->status & S_DEL(N)) && (svars->state[N] & ST_DID_EXPUNGE))
|
|
|
|
srec->status |= S_GONE(N);
|
|
|
|
if (!srec->uid[N] || (srec->status & S_GONE(N))) {
|
|
|
|
if (!srec->uid[F] || (srec->status & S_GONE(F)) ||
|
|
|
|
((srec->status & S_EXPIRED) && svars->maxuid[F] >= srec->uid[F] && svars->maxxfuid >= srec->uid[F])) {
|
|
|
|
PC_JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "killing" );
|
|
|
|
srec->status = S_DEAD;
|
|
|
|
} else if (srec->uid[N] && (srec->status & S_DEL(F))) {
|
|
|
|
PC_JLOG( "> %u %u 0", (srec->uid[F], srec->uid[N]), "orphaning" );
|
|
|
|
srec->uid[N] = 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2022-06-01 12:04:12 +00:00
|
|
|
} else if (srec->uid[F] && (srec->status & S_GONE(F)) && (srec->status & S_DEL(N))) {
|
|
|
|
PC_JLOG( "< %u %u 0", (srec->uid[F], srec->uid[N]), "orphaning" );
|
|
|
|
srec->uid[F] = 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2001-10-31 19:50:01 +00:00
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
save_state( svars );
|
2002-12-28 04:12:07 +00:00
|
|
|
|
2006-03-21 20:03:21 +00:00
|
|
|
sync_bail( svars );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_bail( sync_vars_t *svars )
|
|
|
|
{
|
|
|
|
sync_rec_t *srec, *nsrec;
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
free( svars->trashed_msgs[F].array.data );
|
|
|
|
free( svars->trashed_msgs[N].array.data );
|
2006-03-21 15:53:43 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = nsrec) {
|
2004-03-27 16:07:20 +00:00
|
|
|
nsrec = srec->next;
|
|
|
|
free( srec );
|
|
|
|
}
|
2014-12-27 22:50:31 +00:00
|
|
|
if (svars->lfd >= 0) {
|
|
|
|
unlink( svars->lname );
|
|
|
|
close( svars->lfd );
|
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
sync_bail2( svars );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_bail2( sync_vars_t *svars )
|
|
|
|
{
|
2006-03-21 15:53:43 +00:00
|
|
|
free( svars->lname );
|
|
|
|
free( svars->nname );
|
|
|
|
free( svars->jname );
|
|
|
|
free( svars->dname );
|
2012-08-18 11:58:14 +00:00
|
|
|
sync_bail3( svars );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_bail3( sync_vars_t *svars )
|
|
|
|
{
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
free( svars->box_name[F] );
|
|
|
|
free( svars->box_name[N] );
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_deref( svars );
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
static void
|
|
|
|
sync_deref( sync_vars_t *svars )
|
2012-07-29 21:14:48 +00:00
|
|
|
{
|
|
|
|
if (!--svars->ref_count) {
|
|
|
|
void (*cb)( int sts, void *aux ) = svars->cb;
|
|
|
|
void *aux = svars->aux;
|
|
|
|
int ret = svars->ret;
|
|
|
|
free( svars );
|
|
|
|
cb( ret, aux );
|
|
|
|
}
|
|
|
|
}
|