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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
# This code is part of Perl distribution Mail-Box-POP3 version 3.008.
# The POD got stripped from this file by OODoc version 3.05.
# For contributors see file ChangeLog.
# This software is copyright (c) 2001-2025 by Mark Overmeer.
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
package Mail::Box::POP3::Test;{
our $VERSION = '3.008';
}
use base 'Exporter';
use strict;
use warnings;
use List::Util 'first';
use File::Spec ();
use Mail::Transport::POP3 ();
our @EXPORT = qw/start_pop3_server start_pop3_client/;
#
# Start POP3 server for tests
#
sub start_pop3_server($;$)
{ my $popbox = shift;
my $setting = shift || '';
my $serverscript = File::Spec->catfile('t', 'server');
# Some complications to find-out $perl, which must be absolute and
# untainted for perl5.6.1, but not for the other Perl's.
my $perl = $^X;
unless(File::Spec->file_name_is_absolute($perl))
{ my @path = split /\:|\;/, $ENV{PATH};
$perl = first { -x $_ } map File::Spec->catfile($_, $^X), @path;
}
$perl =~ m/(.*)/;
$perl = $1;
%ENV = ();
open my $server, "$perl $serverscript $popbox $setting|"
or die "Could not start POP3 server\n";
my $line = <$server>;
my $port = $line =~ m/(\d+)/ ? $1 : die "Did not get port specification, but '$line'";
($server, $port);
}
#
# START_POP3_CLIENT PORT, OPTIONS
#
sub start_pop3_client($@)
{ my ($port, @options) = @_;
Mail::Transport::POP3->new(
hostname => '127.0.0.1',
port => $port,
username => 'user',
password => 'password',
@options,
);
}
1;
|