| 1 |
#!perl |
| 2 |
use strict; |
| 3 |
use warnings FATAL => 'all'; |
| 4 |
|
| 5 |
use Data::Dumper; |
| 6 |
use Mail::Sendmail; |
| 7 |
use Test::More tests => 5; |
| 8 |
BEGIN { use_ok('Test::POP3') }; |
| 9 |
|
| 10 |
######################### |
| 11 |
|
| 12 |
my ($host, $user, $pass, $smtp, $email) = get_info(); |
| 13 |
|
| 14 |
|
| 15 |
SKIP: { |
| 16 |
skip 'No POP3 settings found', 5 unless $host; |
| 17 |
|
| 18 |
my $pop3 = Test::POP3->new({ |
| 19 |
host => $host, |
| 20 |
user => $user, |
| 21 |
pass => $pass, |
| 22 |
}); |
| 23 |
|
| 24 |
# no tmpfiles |
| 25 |
my $parser = $pop3->get_parser(); |
| 26 |
$parser->output_to_core(1); |
| 27 |
|
| 28 |
# no messages |
| 29 |
$pop3->delete_all(); |
| 30 |
my $msg_count = $pop3->get_email_count(0); |
| 31 |
is($msg_count, 0, 'no messages'); |
| 32 |
|
| 33 |
# send 3 messages |
| 34 |
sendmail( |
| 35 |
to => $email, |
| 36 |
from => $email, |
| 37 |
subject => 'test 1', |
| 38 |
message => 'message 1', |
| 39 |
smtp => $smtp, |
| 40 |
); |
| 41 |
sendmail( |
| 42 |
to => $email, |
| 43 |
from => $email, |
| 44 |
subject => 'test 2', |
| 45 |
message => 'message 2', |
| 46 |
smtp => $smtp, |
| 47 |
); |
| 48 |
sendmail( |
| 49 |
to => $email, |
| 50 |
from => $email, |
| 51 |
subject => 'test 3', |
| 52 |
message => 'message 3', |
| 53 |
smtp => $smtp, |
| 54 |
); |
| 55 |
|
| 56 |
# then wait for them |
| 57 |
is($pop3->wait_for_email_count(3,30), 3, 'waited for 3 messages'); |
| 58 |
|
| 59 |
is($pop3->delete_all(), 3, 'deleted 3 messages'); |
| 60 |
|
| 61 |
# then timeout waiting for a message that's not there |
| 62 |
is($pop3->wait_for_email_count(1,10), 0, 'timed out'); |
| 63 |
}; |
| 64 |
|
| 65 |
sub get_info { |
| 66 |
return map $ENV{"TEST_POP3_$_"}, map uc, qw(host user pass smtp email); |
| 67 |
} |
| 68 |
|
| 69 |
__END__ |
| 70 |
|