aboutsummaryrefslogtreecommitdiffstats
path: root/interimap
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2019-05-19 14:53:08 +0200
committerGuilhem Moulin <guilhem@fripost.org>2019-05-27 00:07:30 +0200
commitce35ea5f320184a9626f945fdf5a1648062d3e18 (patch)
treec30261c449d1a4b303da40d444aa33f8c0ea5d85 /interimap
parent646300f60aaae976d49cf524b66feba2dda2d2ee (diff)
interimap: Refactor --target handling.
Also, accept comma-separated values for --target.
Diffstat (limited to 'interimap')
-rwxr-xr-xinterimap22
1 files changed, 15 insertions, 7 deletions
diff --git a/interimap b/interimap
index c09d51f..07c2b24 100755
--- a/interimap
+++ b/interimap
@@ -129,6 +129,15 @@ my ($DBFILE, $LOGGER_FD, %LIST);
# RFC 5819 - Returning STATUS Information in Extended LIST
unless $CONFIG{notify};
}
+ if (defined (my $t = $CONFIG{target})) {
+ @$t = map { split(",", $_) } @$t;
+ die "Invalid target $_\n" foreach grep !/^(?:local|remote|database)$/, @$t;
+ $CONFIG{target} = {};
+ $CONFIG{target}->{$_} = 1 foreach @$t;
+ } else {
+ $CONFIG{target} = {};
+ $CONFIG{target}->{$_} = 1 foreach qw/local remote database/;
+ }
}
my $DBH;
@@ -384,11 +393,11 @@ if (defined $COMMAND and $COMMAND eq 'delete') {
# there is a race condition where the mailbox could have
# appeared meanwhile
foreach my $name (qw/local remote/) {
- next if defined $CONFIG{target} and !grep {$_ eq $name} @{$CONFIG{target}};
+ next unless $CONFIG{target}->{$name};
$IMAP->{$name}->{client}->delete($mailbox) if mbx_exists($name, $mailbox);
}
- if (defined $idx and (!defined $CONFIG{target} or grep {$_ eq 'database'} @{$CONFIG{target}})) {
+ if (defined $idx and $CONFIG{target}->{database}) {
my $r1 = $sth_delete_mapping->execute($idx);
msg('database', "WARNING: `DELETE FROM mapping WHERE idx = $idx` failed") unless $r1;
my $r2 = $sth_delete_local->execute($idx);
@@ -422,7 +431,7 @@ elsif (defined $COMMAND and $COMMAND eq 'rename') {
# issue the RENAME command, then the server would reply with a
# tagged NO response
foreach my $name (qw/local remote/) {
- next if defined $CONFIG{target} and !grep {$_ eq $name} @{$CONFIG{target}};
+ next unless $CONFIG{target}->{$name};
fail($name, "Mailbox $to exists. Run `$NAME --target=$name --delete $to` to delete.")
if mbx_exists($name, $to);
}
@@ -430,20 +439,19 @@ elsif (defined $COMMAND and $COMMAND eq 'rename') {
# ensure the target name doesn't already exist in the database
$STH_GET_INDEX->execute($to);
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}});
+ if defined $STH_GET_INDEX->fetch() and $CONFIG{target}->{database};
# rename $from to $to on servers where $from exists. again there is
# a race condition, but if $to has been created meanwhile the server
# will reply with a tagged NO response
foreach my $name (qw/local remote/) {
- next if defined $CONFIG{target} and !grep {$_ eq $name} @{$CONFIG{target}};
+ next unless $CONFIG{target}->{$name};
$IMAP->{$name}->{client}->rename($from, $to) if mbx_exists($name, $from);
}
# rename from to $to in the database
- if (defined $idx and (!defined $CONFIG{target} or grep {$_ eq 'database'} @{$CONFIG{target}})) {
+ if (defined $idx and $CONFIG{target}->{database}) {
my $sth_rename_mailbox = $DBH->prepare(q{UPDATE mailboxes SET mailbox = ? WHERE idx = ?});
my $r = $sth_rename_mailbox->execute($to, $idx);
msg('database', "WARNING: `UPDATE mailboxes SET mailbox = ".$DBH->quote($to)." WHERE idx = $idx` failed") unless $r;