public function testProcessMailbox()
 {
     $testData = array('bouncehammer/17-messages.eml' => array(37, 35, 2, 35, 0), 'bouncehammer/double-messages.eml' => array(2, 2, 0, 2, 0));
     $bmh = new BounceMailHandler();
     $bmh->testMode = true;
     foreach ($testData as $testFile => $expected) {
         list($fetched, $processed, $unprocessed, $deleted, $moved) = $expected;
         ob_start();
         $rc = $bmh->openLocal($this->getMailboxPath(__DIR__ . '/../../fixtures/' . $testFile));
         ob_end_clean();
         $this->assertTrue($rc, $testFile . ': openLocal');
         $bmh->actionFunction = function ($msgnum, $bounceType, $email, $subject, $xheader, $remove, $ruleNo, $ruleCat, $totalFetched, $body) use($expected) {
             return $remove === true || $remove === 1;
         };
         ob_start();
         $rc = $bmh->processMailbox();
         $output = ob_get_contents();
         ob_end_clean();
         $this->assertTrue($rc, $testFile . ': processMailbox');
         preg_match('/Read: ([0-9]+) messages/', $output, $matches);
         $this->assertEquals($fetched, $matches[1], $testFile . ': messages read');
         preg_match('/([0-9]+) action taken/', $output, $matches);
         $this->assertEquals($processed, $matches[1], $testFile . ': action taken');
         preg_match('/([0-9]+) no action taken/', $output, $matches);
         $this->assertEquals($unprocessed, $matches[1], $testFile . ': no action taken');
         preg_match('/([0-9]+) messages deleted/', $output, $matches);
         $this->assertEquals($deleted, $matches[1], $testFile . ': messages deleted');
         preg_match('/([0-9]+) messages moved/', $output, $matches);
         $this->assertEquals($moved, $matches[1], $testFile . ': messages moved');
     }
 }
Exemplo n.º 2
0
 public function testProcessMailbox()
 {
     $testData = array('bounce-email/tt_1234175799.txt' => array(1, 1, 0, 1, 0, '0238', 'dns_unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_1234177688.txt' => array(1, 1, 0, 1, 0, '0148', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_1234210655.txt' => array(1, 1, 0, 1, 0, '0103', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_1234211357.txt' => array(1, 1, 0, 1, 0, '0205', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_1234211929.txt' => array(1, 1, 0, 1, 0, '0105', 'full', 'soft', '*****@*****.**'), 'bounce-email/tt_1234211931.txt' => array(1, 1, 0, 1, 0, '0245', 'dns_loop', 'hard', '*****@*****.**'), 'bounce-email/tt_1234211932.txt' => array(1, 1, 0, 1, 0, '0123', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_1234241664.txt' => array(1, 0, 1, 0, 0, '0000', 'unrecognized', false, '*****@*****.**'), 'bounce-email/tt_1234241665.txt' => array(1, 1, 0, 1, 0, '0128', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_1234285532.txt' => array(1, 1, 0, 1, 0, '0127', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_1234285668.txt' => array(1, 1, 0, 1, 0, '0246', 'full', 'soft', '*****@*****.**'), 'bounce-email/tt_bounce_01.txt' => array(1, 1, 0, 1, 0, '0247', 'dns_unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_bounce_03.txt' => array(1, 1, 0, 1, 0, '0248', 'content_reject', 'soft', '*****@*****.**'), 'bounce-email/tt_bounce_05.txt' => array(1, 1, 0, 1, 0, '0249', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_bounce_05.eml' => array(1, 1, 0, 1, 0, '0193', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_bounce_06.txt' => array(1, 1, 0, 1, 0, '0250', 'antispam', 'blocked', '*****@*****.**'), 'bounce-email/tt_bounce_07.txt' => array(1, 1, 0, 1, 0, '0236', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_bounce_08.txt' => array(1, 1, 0, 1, 0, '0251', 'dns_unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_bounce_12_soft.txt' => array(1, 1, 0, 1, 0, '0252', 'delayed', 'temporary', '*****@*****.**'), 'bounce-email/tt_bounce_13.txt' => array(1, 1, 0, 1, 0, '0013', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_bounce_14.txt' => array(1, 1, 0, 1, 0, '0253', 'full', 'soft', '*****@*****.**'), 'bounce-email/tt_bounce_15.txt' => array(1, 1, 0, 1, 0, '0254', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_bounce_16.txt' => array(1, 1, 0, 1, 0, '0182', 'full', 'soft', '*****@*****.**'), 'bounce-email/tt_bounce_17.txt' => array(1, 1, 0, 1, 0, '0157', 'unknown', 'hard', '*****@*****.**'), 'bounce-email/tt_bounce_18.txt' => array(1, 1, 0, 1, 0, '0256', 'delayed', 'temporary', '*****@*****.**'), 'bounce-email/tt_bounce_23.txt' => array(1, 1, 0, 1, 0, '0236', 'unknown', 'hard', '*****@*****.**'));
     $self = $this;
     $bmh = new BounceMailHandler();
     $bmh->testMode = true;
     foreach ($testData as $testFile => $expected) {
         list($fetched, $processed, $unprocessed, $deleted, $moved, $ruleNo, $ruleCat, $bounceType, $email) = $expected;
         ob_start();
         $rc = $bmh->openLocal($this->getMailboxPath(__DIR__ . '/../../fixtures/' . $testFile));
         ob_end_clean();
         $this->assertTrue($rc, $testFile . ': openLocal');
         $bmh->actionFunction = function ($msgnum, $bounceType, $email, $subject, $xheader, $remove, $ruleNo, $ruleCat, $totalFetched, $body) use($self, $testFile, $expected) {
             return $remove === true || $remove === 1;
         };
         ob_start();
         $rc = $bmh->processMailbox();
         $output = ob_get_contents();
         ob_end_clean();
         $this->assertTrue($rc, $testFile . ': processMailbox');
         preg_match('/Read: ([0-9]+) messages/', $output, $matches);
         $this->assertEquals($fetched, $matches[1], $testFile . ': messages read');
         preg_match('/([0-9]+) action taken/', $output, $matches);
         $this->assertEquals($processed, $matches[1], $testFile . ': action taken');
         preg_match('/([0-9]+) no action taken/', $output, $matches);
         $this->assertEquals($unprocessed, $matches[1], $testFile . ': no action taken');
         preg_match('/([0-9]+) messages deleted/', $output, $matches);
         $this->assertEquals($deleted, $matches[1], $testFile . ': messages deleted');
         preg_match('/([0-9]+) messages moved/', $output, $matches);
         $this->assertEquals($moved, $matches[1], $testFile . ': messages moved');
         preg_match('/Match: ([^:]+):([^;]+); ([^;]*); <?([^<]*)/', $output, $matches);
         $this->assertEquals($ruleNo, $matches[1], $testFile . ': rule_no');
         $this->assertEquals($ruleCat, $matches[2], $testFile . ': rule_cat');
         $this->assertEquals($bounceType, $matches[3], $testFile . ': bounce_type');
         $this->assertEquals($email, $matches[4], $testFile . ': email');
     }
 }