aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2019-05-15 17:08:07 +0200
committerGuilhem Moulin <guilhem@fripost.org>2019-05-27 00:07:29 +0200
commitb59e3b1416c54a2ce8be7f4aaa9c04ff52ff65a9 (patch)
tree046ad86f7163e059dd4045459a690434a5e51e67
parent735c861de4d662f5bfe4fddff9fbfa8bc5a503c1 (diff)
interimap: Factor out error throwing.
Also, write which --target to use in --delete command suggestions.
-rw-r--r--Changelog2
-rwxr-xr-xinterimap31
2 files changed, 16 insertions, 17 deletions
diff --git a/Changelog b/Changelog
index 587dc9b..f261a98 100644
--- a/Changelog
+++ b/Changelog
@@ -1,5 +1,7 @@
interimap (0.5) upstream;
+ + interimap: write which --target to use in --delete command
+ suggestions.
- libinterimap: bugfix: hierarchy delimiters in LIST responses were
returned as an escaped quoted special, like "\\", not as a single
character (backslash in this case).
diff --git a/interimap b/interimap
index bb7013d..fa65241 100755
--- a/interimap
+++ b/interimap
@@ -216,6 +216,11 @@ sub logger($@) {
$prefix .= "$name: " if defined $name;
$LOGGER_FD->say($prefix, @_);
}
+sub fail($@) {
+ my $name = shift;
+ msg($name, "ERROR: ", @_);
+ exit 1;
+}
logger(undef, ">>> $NAME $VERSION");
@@ -355,19 +360,15 @@ elsif (defined $COMMAND and $COMMAND eq 'rename') {
# 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
@@ -467,10 +468,8 @@ sub sync_mailbox_list() {
}
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);
@@ -479,10 +478,8 @@ sub sync_mailbox_list() {
}
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);