File: lmtp.t

package info (click to toggle)
libnet-server-mail-perl 0.28-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 268 kB
  • sloc: perl: 1,299; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,316 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use strict;
use Test::More;
use IO::Socket;

plan tests => 10;

eval('use Net::LMTP');
SKIP: {

    if ($@) {
        skip( "You don't seem to have Net::LMTP installed on your system", 10 );
    }
    else{
    use_ok('Net::Server::Mail::LMTP');

    my $server_port = 2525;
    my $server;

    while ( not defined $server && $server_port < 4000 ) {
        $server = IO::Socket::INET->new(
            Listen    => 1,
            LocalPort => ++$server_port,
        );
    }

    my $pid = fork;
    if ( !$pid ) {
        while ( my $conn = $server->accept ) {
            my $m = Net::Server::Mail::LMTP->new(
              socket       => $conn,
              idle_timeout => 5
            ) or die "can't start server on port 2525";
            $m->set_callback( 'DATA', sub { return $_[1] !~ /bad/ } );
            $m->process;
        }
      SKIP: {
            skip( 'This is the son', 10 );
        }
    }

    my $lmtp = Net::LMTP->new( 'localhost', $server_port, Debug => 0 );
    ok( defined $lmtp );

    ok( $lmtp->mail("test\@bla.com") );
    ok( !$lmtp->mail("test\@bla.com") );
    ok( $lmtp->to('bad') );
    ok( $lmtp->to('postmaster') );
    ok( $lmtp->data );
    ok( $lmtp->datasend('To: postmaster') );
    ok( $lmtp->dataend );
    ok( $lmtp->quit );

    kill 1, $pid;
    wait;
    }
}