Sieve vacation script?

Leena Heino Leena.Heino at uta.fi
Thu Jan 21 11:22:55 EST 2016


On Sat, 26 Dec 2015, Patrick Goetz via Info-cyrus wrote:

> I've been struggling with figuring out how to set up a sieve vacation reply 
> script.  The documentation on this is pretty sparse, and the stuff I do find 
> doesn't work.  For example,

I have a script that kind of does that. We needed in our organization a 
script that would convert old $HOME/.vacation.msg files to sieve script. 
The script would then install and activate the script on the mail server 
using the mail server admin rights.

The script uses Cyrus::SIEVE::managesieve and blocks of code borrowed from 
sieveshell.

Attached is a perl script that install two files to server: common.script 
and vacation.script. The common.script is just a script that includes 
vacation.script and ingo.script among others.

> First question:  is there step by step explanation for manually creating and 
> invoking a cyrus sieve script for a particular user?

I think there is no documentation to do it, but all the bits are there in 
sieveshell code.

-- 
   Leena Heino              University of Tampere / Computer Centre
   ( liinu at uta.fi )      ( http://www.uta.fi/laitokset/tkk )
-------------- next part --------------
#!/usr/bin/perl

use Cyrus::SIEVE::managesieve;

my $rc = 0;
my $commonrc = 0;
my $horderc = 0;
my $vacationrc = 0;
my $realm = "";
my $server = "";
my $user = "";
my $authz = "";
my $pass = "";

$realm = "";
$server = "imapserver.example.com";
$user = "exampleuser";
$authz = "cyrusadm";
$pass = "adminpassword";

sub prompt {
    my($type, $prompt) = @_ ;

    if (($type eq "username") && (defined $user)) {
        return $user;
    } elsif (($type eq "authname") && (defined $authz)) {
        return $authz;
    } elsif (($type eq "realm") && (defined $realm)) {
        return $realm;
    }

    if (($type eq "password") && (defined $pass)) {
        return $pass;
    } elsif ($type eq "password") {
        my $ostty;
        my $str = "";
        chomp($ostty = `stty -g`);

        system "stty -echo -icanon min 1 time 0 2>/dev/null || " .
               "stty -echo cbreak";
        $str = "\n";

        print "$prompt: ";

        $b = <STDIN>;
        chop($b);

        print $str;
        system "stty $ostty";

        return $b;
    }
}

sub list_cb {

    my($name, $isactive) = @_ ;

    print "$name ";
    if ($isactive == 1) {
      print " <- active script\n";
    } else {
      print "\n";
    }
}

my $obj = sieve_get_handle($server, "prompt", "prompt", "prompt", "prompt");

if (!defined $obj) {
    die "unable to connect to server";
}

$rc = sieve_activate($obj, "");
if ($rc != 0) {
    my $errstr = sieve_get_error($obj);
    $errstr = "unknown error" if(!defined($errstr));
    #print "deactivate failed: $errstr\n";
}

$rc = sieve_delete($obj, "common");
if ($rc != 0) {
    my $errstr = sieve_get_error($obj);
    $errstr = "unknown error" if(!defined($errstr));
    #print "delete failed: $errstr\n";
}

$rc = sieve_put_file($obj, "/tmp/cyrus_sieve.181426.21062.tmpdir/common.script");
if ($rc != 0) {
    my $errstr = sieve_get_error($obj);
    $errstr = "unknown error" if(!defined($errstr));
    print "upload failed: $errstr\n";
}
$commonrc += $rc;

$rc = sieve_activate($obj, "common");
if ($rc != 0) {
    my $errstr = sieve_get_error($obj);
    $errstr = "unknown error" if(!defined($errstr));
    print "activate failed: $errstr\n";
}
$commonrc += $rc;

$rc = sieve_delete($obj, "vacation");
if ($rc != 0) {
    my $errstr = sieve_get_error($obj);
    $errstr = "unknown error" if(!defined($errstr));
    #print "delete failed: $errstr\n";
}

$rc = sieve_put_file($obj, "/tmp/cyrus_sieve.181426.21062.tmpdir/vacation.script");
if ($rc != 0) {
    my $errstr = sieve_get_error($obj);
    $errstr = "unknown error" if(!defined($errstr));
    print "upload failed: $errstr\n";
}
$vacationrc += $rc;

my $listrc = sieve_list($obj, "list_cb");
if ($listrc != 0) {
    my $errstr = sieve_get_error($obj);
    $errstr = "unknown error" if(!defined($errstr));
    print "list failed: $errstr\n";
}

$scriptrc = $commonrc + $horderc + $vacationrc;
exit $scriptrc;


More information about the Info-cyrus mailing list