Commit | Line | Data |
---|---|---|
2e173144 CBW |
1 | #!perl |
2 | ||
3 | use 5.008001; | |
4 | ||
5 | use strict; | |
6 | use warnings; | |
7 | ||
8 | use Config; | |
9 | use File::Temp 'tempfile'; | |
10 | use Net::POP3; | |
11 | use Test::More; | |
12 | ||
13 | my $debug = 0; # Net::POP3->new( Debug => .. ) | |
14 | ||
15 | my $inet6class = Net::POP3->can_inet6; | |
16 | plan skip_all => "no IPv6 support found in Net::POP3" if ! $inet6class; | |
17 | ||
18 | plan skip_all => "fork not supported on this platform" | |
19 | unless $Config::Config{d_fork} || $Config::Config{d_pseudofork} || | |
20 | (($^O eq 'MSWin32' || $^O eq 'NetWare') and | |
21 | $Config::Config{useithreads} and | |
22 | $Config::Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/); | |
23 | ||
24 | my $srv = $inet6class->new( | |
25 | LocalAddr => '::1', | |
26 | Listen => 10 | |
27 | ); | |
28 | plan skip_all => "cannot create listener on ::1: $!" if ! $srv; | |
29 | my $saddr = "[".$srv->sockhost."]".':'.$srv->sockport; | |
162b417c | 30 | note("server on $saddr"); |
2e173144 CBW |
31 | |
32 | plan tests => 1; | |
33 | ||
34 | defined( my $pid = fork()) or die "fork failed: $!"; | |
35 | exit(pop3_server()) if ! $pid; | |
36 | ||
37 | my $cl = Net::POP3->new($saddr, Debug => $debug); | |
162b417c | 38 | note("created Net::POP3 object"); |
2e173144 CBW |
39 | if (!$cl) { |
40 | fail("IPv6 POP3 connect failed"); | |
41 | } else { | |
42 | $cl->quit; | |
43 | pass("IPv6 success"); | |
44 | } | |
45 | wait; | |
46 | ||
47 | sub pop3_server { | |
48 | my $cl = $srv->accept or die "accept failed: $!"; | |
49 | print $cl "+OK localhost ready\r\n"; | |
50 | while (<$cl>) { | |
51 | my ($cmd,$arg) = m{^(\S+)(?: +(.*))?\r\n} or die $_; | |
52 | $cmd = uc($cmd); | |
53 | if ($cmd eq 'QUIT' ) { | |
54 | print $cl "+OK bye\r\n"; | |
55 | last; | |
56 | } elsif ( $cmd eq 'CAPA' ) { | |
57 | print $cl "+OK\r\n". | |
a4f8ff46 | 58 | ".\r\n"; |
2e173144 CBW |
59 | } else { |
60 | diag("received unknown command: $cmd"); | |
61 | print "-ERR unknown cmd\r\n"; | |
62 | } | |
63 | } | |
64 | ||
162b417c | 65 | note("POP3 dialog done"); |
2e173144 | 66 | } |