sub register_tests { my ($self) = @_; $self->register_test("test", 11); $self->register_test("bad_subject", 3); } sub test { my ($self) = @_; my $connection = $self->qp->connection; my $transaction = $self->transaction(); my $header = Mail::Header->new(Modify => 0, MailFrom => "COERCE"); $header->extract( [ "Subject: test\n", "Date: Sun, 08 Jun 2008 19:57:01 +0000\n", ] ); $transaction->sender(Qpsmtpd::Address->parse('')); $transaction->recipients( Qpsmtpd::Address->parse(''), Qpsmtpd::Address->parse(''), ); $transaction->header($header); my $t0 = time; $self->hook_queue($transaction); my $t1 = time; ok(-f $self->{_archive_state}, "state file exists"); cmp_ok(-M $self->{_archive_state}, '<=', 0, "state file was modified"); my $rc = open (my $state_fh, '<', $self->{_archive_state}); ok($rc, "$self->{_archive_state} can be opened"); my $digest = <$state_fh>; chomp($digest); close($state_fh); my $msgdir = $self->{_archive_dir} . strftime("/%Y/%m/%d", localtime); my $archivefile = $msgdir . "/" . $digest; ok(-f $archivefile, "archive file exists"); my $dbh = DBI->connect($self->{_archive_index_connect}, $self->{_archive_index_user}, $self->{_archive_index_password}, { AutoCommit => 0 }); my $dbentry = $dbh->selectrow_hashref("select * from messages where filename=?", {}, $archivefile); ok($dbentry->{id}, "id is not null"); is($dbentry->{subject}, "test", "subject is test"); cmp_ok($dbentry->{date}, '>=', $t0, "date is after start"); cmp_ok($dbentry->{date}, '<=', $t1, "date is before finish"); my $dbrcpts = $dbh->selectcol_arrayref("select rcptto from recipients where message=?", {}, $dbentry->{id}); cmp_ok(scalar(@$dbrcpts), '==', 2, "number of recipients"); is($dbrcpts->[0], 'rcpt1@example.com', "first recipient"); is($dbrcpts->[1], 'rcpt2@example.net', "second recipient"); } sub bad_subject { my ($self) = @_; my $connection = $self->qp->connection; my $transaction = $self->transaction(); my $header = Mail::Header->new(Modify => 0, MailFrom => "COERCE"); $header->extract( [ "Subject: test Sun, 15 Jun 2008 20:34:23 +0200\n", "Date: Sun, 08 Jun 2008 19:57:01 +0000\n", "Message-Id: <20080615183423.E84BA201F\@hermes.wsr.ac.at>\n", ] ); $transaction->sender(Qpsmtpd::Address->parse('')); $transaction->recipients( Qpsmtpd::Address->parse(''), Qpsmtpd::Address->parse(''), ); $transaction->header($header); my $t0 = time; $self->hook_queue($transaction); my $t1 = time; ok(1, "we didn't crash"); my $rc = open (my $state_fh, '<', $self->{_archive_state}); ok($rc, "$self->{_archive_state} can be opened"); my $digest = <$state_fh>; chomp($digest); close($state_fh); my $msgdir = $self->{_archive_dir} . strftime("/%Y/%m/%d", localtime); my $archivefile = $msgdir . "/" . $digest; my $dbh = DBI->connect($self->{_archive_index_connect}, $self->{_archive_index_user}, $self->{_archive_index_password}, { AutoCommit => 0 }); my $dbentry = $dbh->selectrow_hashref("select * from messages where filename=?", {}, $archivefile); is($dbentry->{subject}, "test Sun, 15 Jun 2008 20:34:23 +0200", "subject is correct"); }