Skip to content

Commit

Permalink
sieveshell: add --password and --execfile options
Browse files Browse the repository at this point in the history
based on patch from Debian in #3281
  • Loading branch information
guimard authored and elliefm committed Nov 11, 2020
1 parent 996da70 commit 4f3d911
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion perl/imap/IMAP/Shell.pm
Expand Up @@ -483,7 +483,7 @@ sub shell {
-mechanism => $mech, -password => $pw,
-tlskey => $tlskey, -notls => $notls,
-cafile => $cacert, -capath => $capath)
or die "cyradm: cannot authenticate to server with $mech as $auth\n";
or die "cyradm: cannot authenticate to server" . (defined($mech)?" with $mech":"") . " as $auth\n";
}
my $fstk = [*STDIN, *STDOUT, *STDERR];
if ($dorc && $systemrc ne '' && -f $systemrc) {
Expand Down
39 changes: 34 additions & 5 deletions perl/sieve/scripts/sieveshell.pl
Expand Up @@ -62,15 +62,19 @@
my $username = $ENV{USER};
my $authname = $ENV{USER};
my $realm = "";
my $password;
my $ex = "";
my $exfile = "";
my $help = 0;
my $man = 0;
my $ret;

GetOptions("a|authname:s" => \$authname,
"u|username:s" => \$username,
"r|realm:s" => \$realm,
"p|password:s" => \$password,
"e|exec:s" => \$ex,
"f|execfile:s" => \$exfile,
"help|?" => \$help,
man => \$man) or pod2usage(2);
pod2usage(1) if $help;
Expand All @@ -85,7 +89,11 @@
my $filehandle;
my $interactive;

if (! $ex eq "") {
if (! $exfile eq "") {
open(FILEH,"<$exfile") || die "unable to open file: $?";
$filehandle = *FILEH;
$interactive = 0;
} elsif (! $ex eq "") {
$filehandle = tempfile();

if (!$filehandle) { die "unable to open tmp file: $?"; }
Expand All @@ -98,8 +106,6 @@
$interactive = 1;
}



sub list_cb {

my($name, $isactive) = @_ ;
Expand All @@ -123,6 +129,8 @@ sub prompt {
return $authname;
} elsif (($type eq "realm") && (defined $realm)) {
return $realm;
} elsif (($type eq "password") && (defined $password)) {
return $password;
}

my $ostty;
Expand Down Expand Up @@ -173,6 +181,8 @@ sub show_help {

my $term = Term::ReadLine->new("sieveshell");

my $exitcode = 0;

$term->ornaments(0);

while(defined($_ = ($interactive ? $term->readline('> ') : <$filehandle>))){
Expand All @@ -199,6 +209,7 @@ sub show_help {
my $errstr = sieve_get_error($obj);
$errstr = "unknown error" if(!defined($errstr));
print "upload failed: $errstr\n";
$exitcode = 1;
}
} elsif (($words[0] eq "list") ||
($words[0] eq "l") ||
Expand All @@ -208,6 +219,7 @@ sub show_help {
my $errstr = sieve_get_error($obj);
$errstr = "unknown error" if(!defined($errstr));
print "list failed: $errstr\n";
$exitcode = 1;
}
} elsif (($words[0] eq "activate") ||
($words[0] eq "a")) {
Expand All @@ -220,6 +232,7 @@ sub show_help {
my $errstr = sieve_get_error($obj);
$errstr = "unknown error" if(!defined($errstr));
print "activate failed: $errstr\n";
$exitcode = 1;
}
} elsif (($words[0] eq "deactivate") ||
($words[0] eq "da")) {
Expand All @@ -232,6 +245,7 @@ sub show_help {
my $errstr = sieve_get_error($obj);
$errstr = "unknown error" if(!defined($errstr));
print "deactivate failed: $errstr\n";
$exitcode = 1;
}
} elsif (($words[0] eq "delete") ||
($words[0] eq "d")) {
Expand All @@ -244,6 +258,7 @@ sub show_help {
my $errstr = sieve_get_error($obj);
$errstr = "unknown error" if(!defined($errstr));
print "delete failed: $errstr\n";
$exitcode = 1;
}
} elsif (($words[0] eq "get") ||
($words[0] eq "g")) {
Expand All @@ -257,6 +272,7 @@ sub show_help {
my $errstr = sieve_get_error($obj);
$errstr = "unknown error" if(!defined($errstr));
print "get failed: $errstr\n";
$exitcode = 1;
} else {
if ($words[2]) {
open (OUTPUT,">$words[2]") || die "Unable to open $words[2]";
Expand All @@ -268,14 +284,16 @@ sub show_help {
}
} elsif (($words[0] eq "quit") || ($words[0] eq "q")) {
sieve_logout($obj);
exit 0;
} elsif (($words[0] eq "help") || ($words[0] eq "?")) {
show_help();
} else {
print "Invalid command: $words[0]\n";
$exitcode = 1;
}
}

exit $exitcode

__END__
=for pod2rst .. DO NOT EDIT sieveshell.rst: Autogenerated by tools/perl2rst from perl/sieve/scripts/sieveshell.pl
Expand All @@ -291,7 +309,8 @@ =head1 NAME
=head1 SYNOPSIS
sieveshell [B<--user>=I<user>] [B<--authname>=I<authname>]
[B<--realm>=I<realm>] [B<--exec>=I<script>] I<server>[B<:>I<port>]
[B<--realm>=I<realm>] [B<--password>=I<password>]
[B<--exec>=I<script>] [B<--execfile>=I<file>] I<server>[B<:>I<port>]
sieveshell B<--help>
Expand Down Expand Up @@ -336,11 +355,21 @@ =head1 OPTIONS
The realm to attempt authentication in.
=item B<-p> I<password>, B<--password>=I<password>
The password to use when authenticating to server. Note that this
parameter can be seen in the process list. B<Use with caution!>
=item B<-e> I<script>, B<--exec>=I<script>
Instead of working interactively, run commands from I<script>, and
exit when done.
=item B<-f> I<file>, B<--execfile>=I<file>
Instead of working interactively, run commands from file I<file> and
exit when done.
=back
=head1 REFERENCES
Expand Down

0 comments on commit 4f3d911

Please sign in to comment.