**Cassandane::Net::FakeManageSieve**
************************************


NAME
====

Cassandane::Net::FakeManageSieve - scripted ManageSieve server for
client tests


SYNOPSIS
========

   my $srv = Cassandane::Net::FakeManageSieve->new(
       main => {
           LISTSCRIPTS => sub ($srv, $line, $literal) {
               my $port = $srv->port('other');
               qq{BYE (REFERRAL "sieve://127.0.0.1:$port") "moved"\r\n};
           },
       },
       other => {
           auth => sub ($authzid, $authcid, $password) { "OK\r\n" },
           LISTSCRIPTS => sub { qq{"s1" ACTIVE\r\nOK\r\n} },
       },
   );
   my ($status, $output) = $srv->run_client($instance, $code, @args);


DESCRIPTION
===========

Each role named in the constructor gets its own listener on 127.0.0.1,
served by a forked process.  A role is a hash:

* greeting

   Text sent on connect.  Defaults to capabilities offering only
   PLAIN.

* auth

   Called with the PLAIN credentials of each AUTHENTICATE; returns the
   reply. Defaults to accepting everything.

* *COMMAND*

   Called for that command with the server, the command line and any
   literal that followed it; returns the reply.  Commands without a
   handler get NO.

The connection closes after any greeting or reply that doesn't end in
CRLF, after the reply to STARTTLS, and after LOGOUT.


METHODS
=======


port($role)
-----------

The port that the listener for "$role" is on.


run_client($instance, $code, @args)
-----------------------------------

Runs "$code" as a Perl program with Cyrus::SIEVE::managesieve loaded,
"@args" in "@ARGV", and a 60 second alarm.  Returns its exit status
("ok", "exit N" or "signal N") and its combined stdout and stderr.


stop()
------

Stops the server.  Also called when the object is destroyed.
