Browse Source

re-nest conditions for trashing messages

this makes the logic easier to follow and document in place.

also add some debug statements.
wip/maildir-path-under-inbox
Oswald Buddenhagen 3 years ago
parent
commit
f7650993b7
  1. 71
      src/sync.c

71
src/sync.c

@ -1534,6 +1534,7 @@ static void
msgs_flags_set( sync_vars_t *svars, int t ) msgs_flags_set( sync_vars_t *svars, int t )
{ {
message_t *tmsg; message_t *tmsg;
sync_rec_t *srec;
trash_vars_t *tv; trash_vars_t *tv;
copy_vars_t *cv; copy_vars_t *cv;
@ -1542,15 +1543,44 @@ msgs_flags_set( sync_vars_t *svars, int t )
sync_ref( svars ); sync_ref( svars );
if ((svars->chan->ops[t] & OP_EXPUNGE) && if (!(svars->chan->ops[t] & OP_EXPUNGE))
(svars->ctx[t]->conf->trash || (svars->ctx[t^1]->conf->trash && svars->ctx[t^1]->conf->trash_remote_new))) { goto skip;
debug( "trashing on %s\n", str_fn[t] ); int remote, only_new;
for (tmsg = svars->msgs[t]; tmsg; tmsg = tmsg->next) {
if ((tmsg->flags & F_DELETED) && !find_uint_array( svars->trashed_msgs[t].array, tmsg->uid ) &&
(t == F || !tmsg->srec || !(tmsg->srec->status & (S_EXPIRE|S_EXPIRED)))) {
if (svars->ctx[t]->conf->trash) { if (svars->ctx[t]->conf->trash) {
if (!svars->ctx[t]->conf->trash_only_new || !tmsg->srec || (tmsg->srec->status & (S_PENDING | S_SKIPPED))) { only_new = svars->ctx[t]->conf->trash_only_new;
debug( "%s: trashing message %u\n", str_fn[t], tmsg->uid ); 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) {
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;
}
if (only_new && !(srec->status & (S_PENDING | S_SKIPPED))) {
debug( "is not new\n" );
continue;
}
}
if (find_uint_array( svars->trashed_msgs[t].array, tmsg->uid )) {
debug( "was already trashed\n" );
continue;
}
if (!remote) {
debug( "- trashing\n" );
trash_total[t]++; trash_total[t]++;
stats(); stats();
svars->trash_pending[t]++; svars->trash_pending[t]++;
@ -1558,15 +1588,15 @@ msgs_flags_set( sync_vars_t *svars, int t )
tv->aux = AUX; tv->aux = AUX;
tv->msg = tmsg; tv->msg = tmsg;
svars->drv[t]->trash_msg( svars->ctx[t], tmsg, msg_trashed, tv ); svars->drv[t]->trash_msg( svars->ctx[t], tmsg, msg_trashed, tv );
if (check_cancel( svars ))
goto out;
} else { } else {
debug( "%s: not trashing message %u - not new\n", str_fn[t], tmsg->uid ); if (tmsg->size > svars->ctx[t^1]->conf->max_size) {
// This is questionable, as these messages are actually lost
// (no upgradable dummies here).
// However, this is an unlikely configuration to start with ...
debug( "is too big\n" );
continue;
} }
} else { debug( "- trashing\n" );
if (!tmsg->srec || (tmsg->srec->status & (S_PENDING | S_SKIPPED))) {
if (tmsg->size <= svars->ctx[t^1]->conf->max_size) {
debug( "%s: remote trashing message %u\n", str_fn[t], tmsg->uid );
trash_total[t]++; trash_total[t]++;
stats(); stats();
svars->trash_pending[t]++; svars->trash_pending[t]++;
@ -1577,18 +1607,11 @@ msgs_flags_set( sync_vars_t *svars, int t )
cv->msg = tmsg; cv->msg = tmsg;
cv->minimal = 0; cv->minimal = 0;
copy_msg( cv ); copy_msg( cv );
}
if (check_cancel( svars )) if (check_cancel( svars ))
goto out; goto out;
} else {
debug( "%s: not remote trashing message %u - too big\n", str_fn[t], tmsg->uid );
}
} else {
debug( "%s: not remote trashing message %u - not new\n", str_fn[t], tmsg->uid );
}
}
}
}
} }
skip:
svars->state[t] |= ST_SENT_TRASH; svars->state[t] |= ST_SENT_TRASH;
sync_close( svars, t ); sync_close( svars, t );

Loading…
Cancel
Save