Esempio n. 1
0
 public function testEvent()
 {
     $server = new Server('', 0);
     $server->setLog(new Logger('test_application'));
     $server->init();
     $testData = 21;
     $event1 = new Event(Event::TRIGGER_MAIL_NEW, null, function ($event, $from, $rcpt, $mail) use(&$testData) {
         #fwrite(STDOUT, 'my function: '.$event->getTrigger().', '.$testData."\n");
         $testData = 24;
         $this->assertEquals('*****@*****.**', $from);
         $this->assertEquals(array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'), $rcpt);
         $current = array();
         foreach ($mail->getTo() as $n => $address) {
             $current[] = $address->toString();
         }
         $this->assertEquals(array('Joe User <*****@*****.**>', '<*****@*****.**>'), $current);
         $this->assertEquals('Here is the subject', $mail->getSubject());
         return 42;
     });
     $server->eventAdd($event1);
     $mail = '';
     $mail .= 'Date: Thu, 31 Jul 2014 22:18:51 +0200' . Client::MSG_SEPARATOR;
     $mail .= 'To: Joe User <*****@*****.**>, to2@example.com' . Client::MSG_SEPARATOR;
     $mail .= 'From: Mailer <*****@*****.**>' . Client::MSG_SEPARATOR;
     $mail .= 'Cc: cc@example.com' . Client::MSG_SEPARATOR;
     $mail .= 'Reply-To: Information <*****@*****.**>' . Client::MSG_SEPARATOR;
     $mail .= 'Subject: Here is the subject' . Client::MSG_SEPARATOR;
     $mail .= 'MIME-Version: 1.0' . Client::MSG_SEPARATOR;
     $mail .= 'Content-Type: text/plain; charset=iso-8859-1' . Client::MSG_SEPARATOR;
     $mail .= 'Content-Transfer-Encoding: 8bit' . Client::MSG_SEPARATOR;
     $mail .= '' . Client::MSG_SEPARATOR;
     $mail .= 'This is the message body.' . Client::MSG_SEPARATOR;
     $mail .= 'END' . Client::MSG_SEPARATOR;
     $zmail = Message::fromString($mail);
     $rcpt = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**');
     $server->mailNew('*****@*****.**', $rcpt, $zmail);
     $this->assertEquals(24, $testData);
     $this->assertEquals(42, $event1->getReturnValue());
 }
Esempio n. 2
0
 public function testEventAuthWithAllTrue()
 {
     $server = new Server('', 0);
     $server->setLog(new Logger('test_application'));
     $server->init();
     $username = '******';
     $password = '******';
     $phpunit = $this;
     $event1 = new Event(Event::TRIGGER_AUTH_ATTEMPT, null, function ($event, $method, $credentials) {
         return true;
     });
     $server->eventAdd($event1);
     $testObj = new TestObj();
     $event2 = new Event(Event::TRIGGER_AUTH_ATTEMPT, $testObj, 'test2');
     $server->eventAdd($event2);
     $method = 'LOGIN';
     $credentials = array('user' => base64_encode($username), 'password' => base64_encode($password));
     $authenticated = $server->authenticateUser($method, $credentials);
     $this->assertTrue($authenticated);
 }
Esempio n. 3
0
$sendEvent = new Event(Event::TRIGGER_MAIL_NEW, null, function ($event, $from, $rcpts, $mail) {
    // Do stuff: DNS lookup the MX record for the recipient's domain, ...
    // For example, use PHPMailer to reply the mail through mail servers.
    $mailer = new PHPMailer();
    $mailer->IsSMTP();
    $mailer->SMTPAuth = true;
    $mailer->SMTPSecure = 'tls';
    $mailer->Host = 'smtp.example.com';
    $mailer->Port = 587;
    $mailer->Username = '******';
    $mailer->Password = '******';
    $mailer->SetFrom('*****@*****.**', 'John Doe');
    $mailer->Subject = $mail->getSubject();
    $mailer->AltBody = $mail->getBody();
    $mailer->MsgHTML($mail->getBody());
    foreach ($rcpts as $rcptId => $rcpt) {
        $mailer->AddAddress($rcpt);
    }
    if (!$mailer->Send()) {
        throw new Exception($mailer->ErrorInfo);
    }
});
$authEvent = new Event(Event::TRIGGER_AUTH_ATTEMPT, null, function ($event, $type, $credentials) {
    // Do stuff: Check credentials against database, ...
    return true;
});
$server->eventAdd($sendEvent);
$server->eventAdd($authEvent);
// `loop()` is only a loop with `run()` executed.
// So you need to execute `run()` in your own project to keep the SMTP server updated.
$server->loop();