This time I'm just attaching a patch file (unified diff format) for reference -- hopefully it's relatively clear how to read it. I've never used Shell.pm, but I do know perl. With the exception of the first patch (Shell.pm, line 127), which I don't understand, these all seem fairly reasonable (I've included my notes below the patch line numbers)

~/perl/imap/IMAP/Shell.pm git/perl/imap/IMAP/Shell.pm
-----------------------------------------------------
@@ -127,7 +127,7 @@

I'm not sure what this one does......

@@ -439,7 +439,7 @@

Most people/distros don't seem to use /usr/local much any more, which lsb reserves for machine-local files (don't know about BSD or Solaris, which probably uses /opt). The patch + location (/etc/cyradmrc.pl) is not so great, either. Maybe this file should go here: /etc/cyrus/cyradmrc.pl? Seems like any hardwired rc file location is probably a bad idea.

@@ -472,7 +472,7 @@

check to see if $mech is defined for a better error message when not.

@@ -1437,7 +1437,7 @@
@@ -1446,7 +1446,7 @@

these are related to the first patch on Line 127


~/perl/sieve/scripts/sieveshell.pl
---------------------------------
(there should probably be a separate patch file for each file being patched, especially when there are only 2 and they live in different trees; I'll fix this when the patches get updated)

@@ -61,7 +61,9 @@
@@ -69,7 +71,9 @@
@@ -84,20 +88,24 @@
@@ -122,6 +130,8 @@

All these patches deal with adding the ability to pass a password and/or execution file on the command line

@@ -172,6 +182,8 @@
@@ -198,6 +210,9 @@
@@ -207,6 +222,9 @@
...
@@ -256,25 +283,32 @@

These set and use a local exitcode variable for clearer/cleaner exit code handling.

@@ -284,7 +318,8 @@
etc

update perldoc strings to reflect adding command line password and execution file options.


#! /bin/sh /usr/share/dpatch/dpatch-run
## 65-sieveshell-enhancements.dpatch by Sven Mueller <deb...@incase.de>
## Hacked up to 2.3.13 by Duncan Gibb <duncan.g...@siriusit.co.uk>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Adds some enhancements to sieveshell and fixes some paths.

@DPATCH@
diff -urNad git~/perl/imap/IMAP/Shell.pm git/perl/imap/IMAP/Shell.pm
--- git~/perl/imap/IMAP/Shell.pm        2010-01-16 19:21:09.000000000 -0200
+++ git/perl/imap/IMAP/Shell.pm 2010-01-16 19:34:33.976091619 -0200
@@ -127,7 +127,7 @@
                  [\&_sc_info, '[mailbox]',
                   'display mailbox/server metadata'],
                mboxcfg =>
-                 [\&_sc_mboxcfg, 'mailbox 
[comment|condstore|expire|news2mail|sharedseen|sieve|squat] value',
+                 [\&_sc_mboxcfg, 'mailbox 
[comment|condstore|expire|news2mail|sharedseen|sieve|squat|/<explicit 
annotation>] value',
                   'configure mailbox'],
                mboxconfig => 'mboxcfg',
                reconstruct =>
@@ -439,7 +439,7 @@
 sub shell {
   my ($server, $port, $authz, $auth, $systemrc, $userrc, $dorc, $mech, $pw,
       $tlskey, $notls) =
-    ('', 143, undef, $ENV{USER} || $ENV{LOGNAME}, '/usr/local/etc/cyradmrc.pl',
+    ('', 143, undef, $ENV{USER} || $ENV{LOGNAME}, '/etc/cyradmrc.pl',
      "$ENV{HOME}/.cyradmrc.pl", 1, undef, undef, undef, undef);
   GetOptions('user|u=s' => \$auth,
             'authz|z=s' => \$authz,
@@ -472,7 +472,7 @@
     $cyradm->authenticate(-authz => $authz, -user => $auth,
                          -mechanism => $mech, -password => $pw,
                          -tlskey => $tlskey, -notls => $notls)
-      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) {
@@ -1437,7 +1437,7 @@
   while (defined ($opt = shift(@argv))) {
     last if $opt eq '--';
     if ($opt =~ /^-/) {
-      die "usage: mboxconfig mailbox 
[comment|condstore|expire|news2mail|sharedseen|sieve|squat] value\n";
+      die "usage: mboxconfig mailbox 
[comment|condstore|expire|news2mail|sharedseen|sieve|squat|/<explicit 
annotation>] value\n";
     }
     else {
       push(@nargv, $opt);
@@ -1446,7 +1446,7 @@
   }
   push(@nargv, @argv);
   if (@nargv < 2) {
-    die "usage: mboxconfig mailbox 
[comment|condstore|expire|news2mail|sharedseen|sieve|squat] value\n";
+    die "usage: mboxconfig mailbox 
[comment|condstore|expire|news2mail|sharedseen|sieve|squat|/<explicit 
annotation>] value\n";
   }
   if (!$cyrref || !$$cyrref) {
     die "mboxconfig: no connection to server\n";
diff -urNad git~/perl/sieve/scripts/sieveshell.pl 
git/perl/sieve/scripts/sieveshell.pl
--- git~/perl/sieve/scripts/sieveshell.pl       2010-01-16 19:34:33.822091652 
-0200
+++ git/perl/sieve/scripts/sieveshell.pl        2010-01-16 19:34:33.976091619 
-0200
@@ -61,7 +61,9 @@
 my $username = $ENV{USER};
 my $authname = $ENV{USER};
 my $realm = "";
+my $password;
 my $ex = "";
+my $exfile = "";
 my $help = 0;
 my $man = 0;
 my $ret;
@@ -69,7 +71,9 @@
 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;
@@ -84,20 +88,24 @@
 my $filehandle;
 my $interactive;
 
-if (! $ex eq "") {
-    $filehandle = tempfile();
-
-    if (!$filehandle) { die "unable to open tmp file: $?"; }
-
-    print $filehandle $ex;
-    seek $filehandle, 0, 0; # rewind file
+if (! $exfile eq "") {
+    open(FILEH,"<$exfile") || die "unable to open file: $?";
+    $filehandle = *FILEH;
     $interactive = 0;
 } else {
-    $filehandle = *STDIN;
-    $interactive = 1;
-}
+    if (! $ex eq "") {
+       $filehandle = tempfile();
 
+       if (!$filehandle) { die "unable to open tmp file: $?"; }
 
+       print $filehandle $ex;
+       seek $filehandle, 0, 0; # rewind file
+       $interactive = 0;
+    } else {
+       $filehandle = *STDIN;
+       $interactive = 1;
+    }
+}
 
 sub list_cb {
 
@@ -122,6 +130,8 @@
       return $authname;
   } elsif (($type eq "realm") && (defined $realm)) {
       return $realm;
+  } elsif (($type eq "password") && (defined $password)) {
+      return $password;
   }
 
   my $ostty;
@@ -172,6 +182,8 @@
 
 my $term = Term::ReadLine->new("sieveshell");
 
+my $exitcode = 0;
+
 $term->ornaments(0);
 
 while(defined($_  = ($interactive ? $term->readline('> ') : <$filehandle>))){
@@ -198,6 +210,9 @@
        my $errstr = sieve_get_error($obj);
        $errstr = "unknown error" if(!defined($errstr));
        print "upload failed: $errstr\n"; 
+       $exitcode = 1;
+      } else {
+        $exitcode = 0;
       }
     } elsif (($words[0] eq "list") || 
             ($words[0] eq "l") || 
@@ -207,6 +222,9 @@
            my $errstr = sieve_get_error($obj);
            $errstr = "unknown error" if(!defined($errstr));
            print "list failed: $errstr\n";
+           $exitcode = 1;
+       } else {
+           $exitcode = 0;
        }
     } elsif (($words[0] eq "activate") || 
             ($words[0] eq "a")) {
@@ -219,6 +237,9 @@
            my $errstr = sieve_get_error($obj);
            $errstr = "unknown error" if(!defined($errstr));
            print "activate failed: $errstr\n";
+           $exitcode = 1;
+       } else {
+           $exitcode = 0;
        }
     } elsif (($words[0] eq "deactivate") || 
             ($words[0] eq "da")) {
@@ -231,6 +252,9 @@
            my $errstr = sieve_get_error($obj);
            $errstr = "unknown error" if(!defined($errstr));
            print "deactivate failed: $errstr\n";
+           $exitcode = 1;
+       } else {
+           $exitcode = 0;
        }
     } elsif (($words[0] eq "delete") || 
             ($words[0] eq "d")) {    
@@ -243,6 +267,9 @@
            my $errstr = sieve_get_error($obj);
            $errstr = "unknown error" if(!defined($errstr));
            print "delete failed: $errstr\n"; 
+           $exitcode = 1;
+       } else {
+           $exitcode = 0;
        }
     } elsif (($words[0] eq "get") || 
             ($words[0] eq "g")) {
@@ -256,25 +283,32 @@
            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]";
                print OUTPUT $str;
                close(OUTPUT);
+               $exitcode = 0;
            } else {
                print $str;
+               $exitcode = 0;
            }
        }
     } elsif (($words[0] eq "quit") || ($words[0] eq "q")) {
         sieve_logout($obj);
-       exit 0;
+       exit $exitcode;
     } elsif (($words[0] eq "help") || ($words[0] eq "?")) {
        show_help();
+       $exitcode = 0;
     } else {
        print "Invalid command: $words[0]\n";
+       $exitcode = 1;
     } 
 }
 
+exit $exitcode;
+
 __END__
 
 =head1 NAME
@@ -284,7 +318,8 @@
 =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>
 
@@ -328,11 +363,21 @@
 
 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

Reply via email to