2008-04-26 08:32:31 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-06-15 15:33:53 +02:00
|
|
|
* @subpackage email
|
2008-04-26 08:32:31 +02:00
|
|
|
*/
|
|
|
|
class TestMailer extends Mailer {
|
|
|
|
protected $emailsSent = array();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-04-26 08:32:31 +02:00
|
|
|
/**
|
|
|
|
* Send a plain-text email.
|
|
|
|
* TestMailer will merely record that the email was asked to be sent, without sending anything.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function sendPlain($to, $from, $subject, $plainContent, $attachedFiles = false, $customHeaders = false) {
|
2008-04-26 08:32:31 +02:00
|
|
|
$this->emailsSent[] = array(
|
|
|
|
'type' => 'plain',
|
|
|
|
'to' => $to,
|
|
|
|
'from' => $from,
|
|
|
|
'subject' => $subject,
|
|
|
|
|
|
|
|
'content' => $plainContent,
|
|
|
|
'plainContent' => $plainContent,
|
|
|
|
|
|
|
|
'attachedFiles' => $attachedFiles,
|
|
|
|
'customHeaders' => $customHeaders,
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-06-26 06:28:47 +02:00
|
|
|
return true;
|
2008-04-26 08:32:31 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-04-26 08:32:31 +02:00
|
|
|
/**
|
|
|
|
* Send a multi-part HTML email
|
|
|
|
* TestMailer will merely record that the email was asked to be sent, without sending anything.
|
|
|
|
*/
|
2012-09-26 23:34:00 +02:00
|
|
|
public function sendHTML($to, $from, $subject, $htmlContent, $attachedFiles = false, $customHeaders = false,
|
|
|
|
$plainContent = false, $inlineImages = false) {
|
|
|
|
|
2008-04-26 08:32:31 +02:00
|
|
|
$this->emailsSent[] = array(
|
|
|
|
'type' => 'html',
|
|
|
|
'to' => $to,
|
|
|
|
'from' => $from,
|
|
|
|
'subject' => $subject,
|
|
|
|
|
|
|
|
'content' => $htmlContent,
|
|
|
|
'plainContent' => $plainContent,
|
|
|
|
'htmlContent' => $htmlContent,
|
|
|
|
|
|
|
|
'attachedFiles' => $attachedFiles,
|
|
|
|
'customHeaders' => $customHeaders,
|
|
|
|
'inlineImages' => $inlineImages,
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-06-26 06:28:47 +02:00
|
|
|
return true;
|
2008-04-26 08:32:31 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-04-26 08:32:31 +02:00
|
|
|
/**
|
|
|
|
* Clear the log of emails sent
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function clearEmails() {
|
2008-04-26 08:32:31 +02:00
|
|
|
$this->emailsSent = array();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-04-26 08:32:31 +02:00
|
|
|
/**
|
|
|
|
* Search for an email that was sent.
|
|
|
|
* All of the parameters can either be a string, or, if they start with "/", a PREG-compatible regular expression.
|
|
|
|
* @param $to
|
|
|
|
* @param $from
|
|
|
|
* @param $subject
|
|
|
|
* @param $content
|
2012-09-26 23:34:00 +02:00
|
|
|
* @return array Contains the keys: 'type', 'to', 'from', 'subject', 'content', 'plainContent', 'attachedFiles',
|
|
|
|
* 'customHeaders', 'htmlContent', 'inlineImages'
|
2008-04-26 08:32:31 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function findEmail($to, $from = null, $subject = null, $content = null) {
|
2008-04-26 08:32:31 +02:00
|
|
|
foreach($this->emailsSent as $email) {
|
|
|
|
$matched = true;
|
2009-06-26 06:28:47 +02:00
|
|
|
|
2008-04-26 08:32:31 +02:00
|
|
|
foreach(array('to','from','subject','content') as $field) {
|
|
|
|
if($value = $$field) {
|
|
|
|
if($value[0] == '/') $matched = preg_match($value, $email[$field]);
|
|
|
|
else $matched = ($value == $email[$field]);
|
|
|
|
if(!$matched) break;
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-04-26 08:32:31 +02:00
|
|
|
if($matched) return $email;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|