$prefix .= "$name: " if defined $name;
$LOGGER_FD->say($prefix, @_);
}
+sub fail($@) {
+ my $name = shift;
+ msg($name, "ERROR: ", @_);
+ exit 1;
+}
logger(undef, ">>> $NAME $VERSION");
# tagged NO response
foreach my $name (qw/local remote/) {
next if defined $CONFIG{target} and !grep {$_ eq $name} @{$CONFIG{target}};
- if (mbx_exists($name, $to)) {
- msg($name, "ERROR: Mailbox $to exists. Run `$NAME --delete $to` to delete.");
- exit 1;
- }
+ fail($name, "Mailbox $to exists. Run `$NAME --target=$name --delete $to` to delete.")
+ if mbx_exists($name, $to);
}
# ensure the target name doesn't already exist in the database
$STH_GET_INDEX->execute($to);
- if (defined $STH_GET_INDEX->fetch() and
- (!defined $CONFIG{target} or grep {$_ eq 'database'} @{$CONFIG{target}})) {
- msg('database', "ERROR: Mailbox $to exists. Run `$NAME --delete $to` to delete.");
- exit 1;
- }
+ fail("database", "Mailbox $to exists. Run `$NAME --target=database --delete $to` to delete.")
+ if defined $STH_GET_INDEX->fetch()
+ and (!defined $CONFIG{target} or grep {$_ eq 'database'} @{$CONFIG{target}});
# rename $from to $to on servers where $from exists. again there is
}
elsif ($lExists and !$rExists) {
# $mailbox is on 'local' only
- if (defined $idx) {
- msg('database', "ERROR: Mailbox $mailbox exists. Run `$NAME --delete $mailbox` to delete.");
- exit 1;
- }
+ fail("database", "Mailbox $mailbox exists. Run `$NAME --target=database --delete $mailbox` to delete.")
+ if defined $idx;
my $subscribed = mbx_subscribed('local', $mailbox);
$STH_INSERT_MAILBOX->execute($mailbox, $subscribed);
$IMAP->{remote}->{client}->create($mailbox, 1);
}
elsif (!$lExists and $rExists) {
# $mailbox is on 'remote' only
- if (defined $idx) {
- msg('database', "ERROR: Mailbox $mailbox exists. Run `$NAME --delete $mailbox` to delete.");
- exit 1;
- }
+ fail("database", "Mailbox $mailbox exists. Run `$NAME --target=database --delete $mailbox` to delete.")
+ if defined $idx;
my $subscribed = mbx_subscribed('remote', $mailbox);
$STH_INSERT_MAILBOX->execute($mailbox, $subscribed);
$IMAP->{local}->{client}->create($mailbox, 1);