1Test::POP3(3) User Contributed Perl Documentation Test::POP3(3)
2
3
4
6 Test::POP3 - Automate Email Delivery Tests
7
9 use Test::POP3;
10
11 my $pop = Test::POP3->new({
12 host => $host,
13 user => $user,
14 pass => $pass,
15 });
16
17 # this will delete all messages from the server!
18 ok($count == $pop->wait_for_email_count($count,$timeout),"got $count");
19
20 # find and delete a single email message which matches these rules
21 # see Test::Email for more information
22 $pop->ok({
23 # optional search parameters
24 to => ($is or qr/is like/),
25 from => ($is or qr/is like/),
26 subject => ($is or qr/is like/),
27 body => ($is or qr/is like/),
28 headername => ($is or qr/is like/),
29 }, "got message");
30
31 ok($pop->get_email_count() == $count, "$count emails in cache");
32
33 # get the Test::Email object
34 my @email = $pop->get_email();
35
36 ok($pop->delete_all() == 2, "deleted 2 messages");
37
38 # tweak MIME::Parser settings
39 my $parser = $pop->get_parser();
40
42 Please note that this is ALPHA CODE. As such, the interface is likely
43 to change.
44
45 This module can help you to create automated tests of email delivered
46 to a POP3 account.
47
48 Messages retrieved from the server but not yet matched by a test will
49 be cached until either that message is the first to pass a test, or is
50 returned by "$pop3->get_email()". Messages returned are Test::Email
51 objects.
52
54 "my $pop = Test::Email->new($href);"
55 The arguments passed in the href are host, user, and pass.
56
57 "my $count = $pop->wait_for_email_count($count, $timeout_seconds?);"
58 Calling this method will result in all messages being deleted from
59 the server. This will wait up to $timeout seconds for there to be
60 $count unprocessed messages found on the server. After $count or
61 more messages are found, or after $timeout seconds, the current
62 email count will be returned. $timeout_seconds defaults to 30. All
63 messages will be deleted from the server.
64
65 "my @email = $pop->get_email();"
66 Get all of the email messages currently in local cache. You should
67 call "$pop3->wait_for_email_count($count)" before calling this
68 method if you think that there may be messages on the server yet to
69 be retrieved. Calling this method will cause the local cache to be
70 emptied. Email messages returned will be Test::Email objects.
71
72 "my $count = $pop->get_email_count($check_server);"
73 This will return the number of email messages in the cache. If
74 $check_server is true, then the server will be checked once before
75 the count is determined. If you would like to wait for messages to
76 arrive on the server, and then be downloaded prior to counting, use
77 "$pop3->wait_for_email_count()".
78
79 "my $ok = $pop->ok($test_href, $description);"
80 Calling this method will cause the email in the local cache to be
81 tested, according to the contents of $test_href. The first email
82 which passes all tests will be deleted from the local cache. Since
83 this method only checks the local cache, you will want to call
84 "$pop3->wait_for_email_count()" before calling this method. "ok"
85 will produce TAP output, identical to "Test::Simple::ok" and
86 "Test::More::ok".
87
88 "my $parser = $pop->get_parser();"
89 Test::POP3 uses MIME::Parser to process the messages. (MIME is not
90 yet handled by "Test::Email", it will be soon.) Use this method if
91 you want to manage the parser.
92
94 None.
95
97 Test::Builder, Test::Simple, Test::More, MIME::Parser
98
100 James Tolley, <james@cpan.org>
101
103 Copyright (C) 2007 by James Tolley
104
105 This library is free software; you can redistribute it and/or modify it
106 under the same terms as Perl itself, either Perl version 5.8.8 or, at
107 your option, any later version of Perl 5 you may have available.
108
109
110
111perl v5.12.0 2007-06-09 Test::POP3(3)