# Clean after us
sub cleanup() {
- logger("Cleaning up...") if $CONFIG{debug};
+ logger(undef, "Cleaning up...") if $CONFIG{debug};
unlink $LOCKFILE if defined $LOCKFILE and -f $LOCKFILE;
close $LOGGER_FD if defined $LOGGER_FD;
$DBH->disconnect() if defined $DBH;
}
-$SIG{$_} = sub { cleanup(); msg(undef, $!); exit 1; } foreach qw/INT TERM/;
-$SIG{$_} = sub { cleanup(); msg(undef, $!); exit 0; } foreach qw/HUP/;
+$SIG{$_} = sub { msg(undef, $!); cleanup(); exit 1; } foreach qw/INT TERM/;
+$SIG{$_} = sub { msg(undef, $!); cleanup(); exit 0; } foreach qw/HUP/;
#############################################################################
# Solve a flag update conflict (by taking the union of the two flag lists).
sub flag_conflict($$$$$) {
- my ($mailbox, $lUID, $lFlags, $rUID, $rFlags);
+ my ($mailbox, $lUID, $lFlags, $rUID, $rFlags) = @_;
my %flags = map {$_ => 1} (split(/ /, $lFlags), split(/ /, $rFlags));
my $flags = join ' ', sort(keys %flags);
my ($lUIDs, $rUIDs) = $name eq 'local' ? (\@sUID,\@tUID) : (\@tUID,\@sUID);
for (my $k=0; $k<=$#messages; $k++) {
- logger("Adding mapping (lUID,rUID) = ($lUIDs->[$k],$rUIDs->[$k]) for $mailbox") if $CONFIG{debug};
+ logger(undef, "Adding mapping (lUID,rUID) = ($lUIDs->[$k],$rUIDs->[$k]) for $mailbox")
+ if $CONFIG{debug};
$STH_INSERT_MAPPING->execute($idx, $lUIDs->[$k], $rUIDs->[$k]);
}
$DBH->commit(); # commit only once per batch
$rIMAP->select($MAILBOX);
repair($IDX, $MAILBOX);
}
-if ($CONFIG{repair}) {
- cleanup();
- exit 0;
-}
+exit 0 if $CONFIG{repair};
while(1) {
}
}
# clean state!
- if ($CONFIG{oneshot}) {
- cleanup();
- exit 0;
- }
+ exit 0 if $CONFIG{oneshot};
wait_notifications(900);
}