App-Siesh
view release on metacpan or search on metacpan
lib/Net/ManageSieve/Siesh.pm view on Meta::CPAN
sub edit_script {
my ( $sieve, $script ) = @_;
my ( $fh, $filename ) = $sieve->temp_scriptfile( $script, 1 );
my $editor = $ENV{'VISUAL'} || $ENV{'EDITOR'} || "vi";
while (1) {
system( $editor, $filename );
eval { $sieve->putfile( $filename, $script ); 1; } or do {
print "$@\n";
## There was maybe a parse error, if the user enters yes
## we reedit the file, otherwise we leave it by the next last
next if prompt( "Re-edit script? ", -yn );
};
## There was either no error with putfile or the user entered no
last;
}
return close $fh;
}
sub activate {
my ( $self, $script ) = @_;
return $self->setactive($script);
}
sub deactivate {
my $self = shift;
return $self->setactive("");
}
sub is_active {
my ( $self, $script ) = @_;
return $self->get_active() eq $script;
}
sub get_active {
my ($self) = @_;
return $self->SUPER::listscripts()->[-1];
}
sub script_exists {
my ( $self, $scriptname ) = @_;
my %script = map { $_ => 1 } $self->listscripts;
return defined( $script{$scriptname} );
}
1; # End of Net::ManageSieve::Siesh
__END__
=head1 NAME
Net::ManageSieve::Siesh - Expanding Net::ManagieSieve beyond the pure protocol
=head1 VERSION
Version 0.05
=head1 SYNOPSIS
Net::ManageSieve::Siesh expands Net::ManagieSieve beyond just implementing
the core RFC protocol. There are functions to upload and download files,
deactivating scripts, copy and move them etc.
use Net::ManageSieve::Siesh;
my $sieve = Net::ManageSieve::Siesh->new();
$sieve->copy('script1','script2');
$sieve->mv('script2','script3');
$sieve->put('../script.txt','script4');
$sieve->get('script1','../script.txt');
If you're just searching for a comamnd line interface to ManageSieve,
please take a look at C<siesh(1)>.
=head1 ERROR HANDLING
Unlike L<Net::ManagieSieve> this library just croaks in the case of error. Nothing wrong with that!
=head1 METHODS
=over 4
=item C<deactivate()>
Deactivates all active scripts on the server. This has
the same effect as using the function setactive with an empty string
as argument.
=item C<activate()>
Activates the scripts. This is identical to call setactive, but is easier
to remember.
=item C<movescript($oldscriptname,$newscriptname)>
Renames the script. This functions is equivalent to copying a script and
then deleting the source script. In case you try to move the currently
active script, it's deactivated first and later reactivated unter it's
new name.
=item C<copyscript($oldscriptname,$newscriptname)>
Copy the script C<$oldscriptname> to C<$newscriptname>.
=item C<temp_scriptfile($scriptname,$create)>
Calls tempfile from File::Temp and writes the content of C<$scriptname>
into the returned file. Returns the opened filehandle and the
filename. Unless C<$create> is true, return undef if the requested script
does not exist.
=item C<putfile($file,$scriptname)>
Uploads C<$file> with the name C<$scriptname> to the server.
=item C<getfile($scriptname,$file)>
Downloads the script names <$scriptname> to the file specified by C<$file>.
=item C<listscripts()>
( run in 2.273 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )