SYNOPSIS

    use Net::ManageSieve;

    # Constructors
    $sieve = Net::ManageSieve->new('localhost');
    $sieve = Net::ManageSieve->new('localhost', Timeout => 60);

DESCRIPTION

This module implements a client interface to the ManageSieve protocol (<http://tools.ietf.org/html/draft-martin-managesieve-09>). This documentation assumes that you are familiar with the concepts of the protocol.

A new Net::ManageSieve object must be created with the new method. Once this has been done, all ManageSieve commands are accessed through this object.

Note: ManageSieve allows to manipulate scripts on a host running a ManageSieve service, this module does not perform, validate or something like that Sieve scipts themselves.

This module works in taint mode.

EXAMPLES

This example prints the capabilities of the server known as mailhost:

#!/usr/local/bin/perl -w

use Net::ManageSieve;

$sieve = Net::ManageSieve->new('mailhost'); print "$k=$v\n" while ($k, $v) = each %{ $sieve->capabilities }; $sieve->logout;

This example lists all storred scripts on the server and requires \s-1TLS:\s0

#!/usr/local/bin/perl -w

use Net::ManageSieve;

my $sieve = Net::ManageSieve->new('mailhost', tls => 'require') or die "$@\n"; print "Cipher: ", $sieve->get_cipher(), "\n"; $sieve->login('user', 'password') or die "Login: ".$sieve->error()."\n"; my $scripts = $sieve->listscripts or die "List: ".$sieve->error()."\n"; my $activeScript = pop(@$scripts); print "$_\n" for sort @$scripts; print $activeScript ? 'active script: ' . $activeScript : 'no script active' , "\n"; $sieve->logout;

ERROR HANDLING

By default all functions return \*(C`undef\*(C' on failure and set an error description into $@, which can be retrieved with the method \*(C`error()\*(C' as well.

The constructor accepts the setting \*(C`on_fail\*(C', which alters this behaviour by changing the step to assign $@: If its value is: the program carps the error description. If \*(C`debug\*(C' is enabled, too, the description is printed twice. the program croaks.

is a \s-1CODE\s0 ref

this subroutine is called with the arguments: &code_ref ( $object, $error_message ) The return value controls, whether or not the error message will be assigned to $@. Private functions may just signal that an error occured, but keep $@ unchanged. In this case $@ remains unchanged, if code_ref returns true. Note: Even if the code ref returns false, $@ might bi clobberred by called modules. This is especially true in the \*(C`new()\*(C' constructor.

otherwise

the default behaviour is retained by setting $@.

CONSTRUCTOR

new ( [ \s-1HOST\s0 ] [, \s-1OPTIONS\s0 ] )

This is the constructor for a new Net::ManageSieve object. \*(C`HOST\*(C' is the name of the remote host to which an ManageSieve connection is required. \*(C`HOST\*(C' is optional. If \*(C`HOST\*(C' is not given then it may instead be passed as the \*(C`Host\*(C' option described below. If neither is given then \*(C`localhost\*(C' will be used. \*(C`OPTIONS\*(C' are passed in a hash like fashion, using key and value pairs. Possible options are: Host - ManageSieve host to connect to. It may be a single scalar, as defined for the \*(C`PeerAddr\*(C' option in IO::Socket::INET, or a reference to an array with hosts to try in turn. The \*(L"host\*(R" method will return the value which was used to connect to the host. LocalAddr and LocalPort - These parameters are passed directly to IO::Socket to allow binding the socket to a local port. Timeout - Maximum time, in seconds, to wait for a response from the ManageSieve server (default: 120) Port - Select a port on the remote host to connect to (default is 2000) Debug or debug - enable debugging if true (default \s-1OFF\s0) Note: All of the above options are passed through to IO::Socket::INET. tls - issue \s-1STARTTLS\s0 right after connect. If tls is a \s-1HASH\s0 ref, the mode is in member \*(C`mode\*(C', otherwise \*(C`tls\*(C' itself is the mode and an empty \s-1SSL\s0 option \s-1HASH\s0 is passed to starttls(). The \*(C`mode\*(C' may be one of \*(C`require\*(C' to fail, if \s-1TLS\s0 negotiation fails, or \*(C`auto\*(C', \*(C`on\*(C' or \*(C`yes\*(C', if \s-1TLS\s0 is to attempt, but a failure is ignored. (Aliases: \s-1TLS\s0, Tls) on_fail - Changes the error handling of all functions that would otherwise return undef and set $@. See section \s-1ERROR\s0 \s-1HANDLING\s0 (Aliases: On_fail) Example: $sieve = Net::ManageSieve->new('mailhost', Timeout => 30, ); use the first host one can connect to successfully \*(C`mailhost\*(C' on port 2000, the default port, then \*(C`localhost\*(C' on port 2008. $sieve = Net::ManageSieve->new(Host => [ 'mailhost', 'localhost:2008' ], Timeout => 30, tls => { mode => require, SSL_ca_path => '/usr/ssl/cert', } );

METHODS

Unless otherwise stated all methods return either a true or false value, with true meaning that the operation was a success. When a method states that it returns a value, failure will be returned as undef or an empty list. The error is specified in $@ and can be returned with the \*(L"error\*(R" method. Please see section \s-1ERROR\s0 \s-1HANDLING\s0 for an alternative error handling scheme.

close ()

Closes the connection to the server. Any already cached data is kept active, though, there should be no pending data, if an user calls this function. Initiates a \s-1TLS\s0 session, may be used only before any authentication. The \*(C`SSL_opts\*(C' is a \s-1HASH\s0 containing any options you can pass to IO::Socket::SSL->new(). No one is passed by default. In order to detect in the later run, if the connection is encrypted, use the \*(C`encrypted()\*(C' function. Return: $self or \*(C`undef\*(C' on failure - the socket is still functioning, but is not encrypted.

encrypted ()

Returns \*(C`undef\*(C', if the connection is not encrypted, otherwise \*(C`true\*(C'.

get_cipher (), dump_peer_certificate (), peer_certificate ($field)

Returns \*(C`undef\*(C', if the connection is not encrypted, otherwise the functions directly calls the equally named function of IO::Socket::SSL.

auth (\s-1USER\s0 [, \s-1PASSWORD\s0 [, \s-1AUTHNAME\s0 ] ])

Authentificates as \*(C`USER\*(C'. If the module Authen::SASL is available, this module is tried first. In this case, the \*(C`USER\*(C' parameter may be a \*(C`Authen::SASL\*(C' object, that is not furtherly modified. If \*(C`USER\*(C' is no \*(C`Authen::SASL\*(C' object, \*(C`USER\*(C' is passed as \*(C`user\*(C', \*(C`PASSWORD\*(C' as \*(C`pass\*(C' and \*(C`AUTHNAME\*(C' as \*(C`authname\*(C' to \*(C`Authen::SASL->new()\*(C'. If \*(C`AUTHNAME\*(C' is undefined, \*(C`USER\*(C' is passed as \*(C`authname\*(C'. This way you can authentificate against Cyrus: \*(C`auth('cyrus', $password, $username)\*(C'. If Authen::SASL is not available or the initialization of it fails, this function attempts to authentificate via the \*(C`PLAIN\*(C' method. Aliases: \*(C`login\*(C', \*(C`authentificate\*(C'.

logout ()

Sends the \*(C`LOGOUT\*(C' command to the server and closes the connection to the server. Aliases: \*(C`quit\*(C', \*(C`bye\*(C'.

host ()

Returns the remote host of the connection.

capabilities ([reget])

Returns the capabilities as \s-1HASH\s0 ref, e.g.: { 'starttls' => 1, 'sasl' => 'PLAIN LOGIN', 'implementation' => 'dovecot', 'sieve' => 'fileinto reject envelope vacation imapflags notify subaddress relational comparator-i;ascii-numeric regex' }; If the argument \*(C`bool\*(C' is specified and is boolean \*(C`TRUE\*(C', the capabilities are reaquired from the server using the \s-1CAPABILITY\s0 command. Note: The initial capabilities may be different from the set acquired later.

havespace (\s-1NAME\s0, \s-1SIZE\s0)

Return whether or not a script with the specified size (and name) might fit into the space of the user on the server. Due to various reasons, the result of this function is not very reliable, because in the meantime lots of changes may take place on the server.

putscript (\s-1NAME\s0, \s-1SCRIPT\s0)

Stores the \*(C`SCRIPT\*(C' as name \*(C`NAME\*(C' on the server, the script is not activated by default. \*(C`SCRIPT\*(C' is a scalar in \s-1UTF-8\s0. The script must not be empty.

listscripts ()

returns an \s-1ARRAY\s0 ref of the names of the scripts. The last entry in the list, specifies the active script, it is an empty string "", if there is none. e.g.: [ "script1", "script2", "script1" ] means that \*(C`script1\*(C' is active currently.

setactive (\s-1NAME\s0)

Activates the script named \*(C`NAME\*(C'.

getscript (\s-1NAME\s0)

Returns the named script. The contents is in perl-internal \s-1UTF8\s0.

deletescript (\s-1NAME\s0)

Deletes the script named \*(C`NAME\*(C'.

error ()

Returns the locally cached error information in the form: error description respn=last server response

debug ( [state] )

Returns the current state of debugging. If \*(C`state\*(C' is given, the boolean value enables or disables debugging. Encodes the string into internal \s-1UTF8\s0. If encoding is specified, it is tried first; then \*(C`utf-8-strict\*(C', and, if all fails, \*(C`Latin1\*(C', which is not fail.

BUGS

The modules tries hard to pass valid \s-1UTF8\s0 data to the server and transforms the results into perl internal \s-1UTF8\s0. If latter fails, the transmitted octets are decoded using Latin1.

Script names, user names and passwords are not checked or \*(L"SASLprep\*(R"'ed (\s-1RFC\s0 4013/3454). Script names with \*(C`[\0\r\n]\*(C' are rejected.

We accept non-synchronizing literals \*(C`{num+}\*(C' from the server.

RELATED TO Net::ManageSieve…

<http://tools.ietf.org/html/draft-martin-managesieve-09>

AUTHOR

Steffen Kaiser This module heavily bases on Net::SMTP and Net::Cmd.

COPYRIGHT

Copyright (c) 2008-2010 Steffen Kaiser. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.