Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jelix-1.7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentj committed Dec 28, 2016
2 parents 954036a + 6e41d59 commit 8afadb2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -19,7 +19,7 @@
"php": ">=5.6",
"jelix/fakeserverconf": "1.0.*",
"jelix/composer-module-setup": "0.*",
"phpmailer/phpmailer": "5.2.9",
"phpmailer/phpmailer": "^5.2.18",
"jelix/soap-server-module": "^1.7.5",
"jelix/castor": "1.0.*",
"jelix/feeds-module": "1.7.*",
Expand Down
61 changes: 35 additions & 26 deletions lib/Jelix/Mailer/Mailer.php
Expand Up @@ -7,7 +7,7 @@
*
* @author Laurent Jouanneau
* @contributor Kévin Lepeltier, GeekBay, Julien Issler
* @copyright 2006-2015 Laurent Jouanneau
* @copyright 2006-2016 Laurent Jouanneau
* @copyright 2008 Kévin Lepeltier, 2009 Geekbay
* @copyright 2010-2015 Julien Issler
* @link http://jelix.org
Expand Down Expand Up @@ -44,7 +44,7 @@ class Mailer extends \PHPMailer {
/**
* indicates if mails should be copied into files, so the developer can verify that all mails are sent.
*/
protected $copyTofile = false;
protected $copyToFiles = false;

/**
* initialize some member
Expand All @@ -54,8 +54,9 @@ function __construct($exception = true){
$this->defaultLang = $config->locale;
$this->CharSet = $config->charset;
$this->Mailer = $config->mailer['mailerType'];
if ($config->mailer['mailerType'])
if ($config->mailer['mailerType']) {
$this->Mailer = $config->mailer['mailerType'];
}
$this->Hostname = $config->mailer['hostname'];
$this->Sendmail = $config->mailer['sendmailPath'];
$this->Host = $config->mailer['smtpHost'];
Expand All @@ -66,7 +67,7 @@ function __construct($exception = true){
$this->Username = $config->mailer['smtpUsername'];
$this->Password = $config->mailer['smtpPassword'];
$this->Timeout = $config->mailer['smtpTimeout'];
if($config->mailer['webmasterEmail'] != '') {
if ($config->mailer['webmasterEmail'] != '') {
$this->From = $config->mailer['webmasterEmail'];
}

Expand All @@ -91,6 +92,7 @@ public function IsFile() {
/**
* Find the name and address in the form "name<address@hop.tld>"
* @param string $address
* @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
* @return array( $name, $address )
*/
function getAddrName($address, $kind = false) {
Expand All @@ -102,10 +104,10 @@ function getAddrName($address, $kind = false) {
$name = '';
$addr = $address;
}
if (!$kind) {
return array($addr, $name);
if ($kind) {
$this->addAnAddress($kind, $addr, $name);
}
$this->AddAnAddress($kind, $addr, $name);
return array($addr, $name);
}

protected $tpl = null;
Expand All @@ -120,7 +122,7 @@ function getAddrName($address, $kind = false) {
public function Tpl( $selector, $isHtml = false ) {
$this->bodyTpl = $selector;
$this->tpl = new \jTpl();
$this->IsHTML($isHtml);
$this->isHTML($isHtml);
return $this->tpl;
}

Expand All @@ -138,40 +140,51 @@ public function send() {
$mailtpl = $this->tpl;
$metas = $mailtpl->meta( $this->bodyTpl , ($this->ContentType == 'text/html'?'html':'text') );

if (isset($metas['Subject']))
if (isset($metas['Subject'])) {
$this->Subject = $metas['Subject'];
}

if (isset($metas['Priority']))
if (isset($metas['Priority'])) {
$this->Priority = $metas['Priority'];
}
$mailtpl->assign('Priority', $this->Priority );

if (isset($metas['Sender']))
if (isset($metas['Sender'])) {
$this->Sender = $metas['Sender'];
}
$mailtpl->assign('Sender', $this->Sender );

if (isset($metas['to']))
foreach( $metas['to'] as $val )
$this->getAddrName( $val, 'to' );
if (isset($metas['to'])) {
foreach ($metas['to'] as $val) {
$this->getAddrName($val, 'to');
}
}
$mailtpl->assign('to', $this->to );

if (isset($metas['cc']))
foreach( $metas['cc'] as $val )
if (isset($metas['cc'])) {
foreach ($metas['cc'] as $val) {
$this->getAddrName($val, 'cc');
}
}
$mailtpl->assign('cc', $this->cc );

if (isset($metas['bcc']))
foreach( $metas['bcc'] as $val )
if (isset($metas['bcc'])) {
foreach ($metas['bcc'] as $val) {
$this->getAddrName($val, 'bcc');
}
}
$mailtpl->assign('bcc', $this->bcc);

if (isset($metas['ReplyTo']))
foreach( $metas['ReplyTo'] as $val )
if (isset($metas['ReplyTo'])) {
foreach ($metas['ReplyTo'] as $val) {
$this->getAddrName($val, 'Reply-To');
}
}
$mailtpl->assign('ReplyTo', $this->ReplyTo );

if (isset($metas['From'])) {
$adr = $this->getAddrName($metas['From']);
$this->SetFrom($adr[0], $adr[1]);
$this->setFrom($adr[0], $adr[1]);
}

$mailtpl->assign('From', $this->From );
Expand Down Expand Up @@ -222,11 +235,7 @@ protected function lang($key) {
if(count($this->language) < 1) {
$this->SetLanguage($this->defaultLang); // set the default language
}
if(isset($this->language[$key])) {
return $this->language[$key];
} else {
return 'Language string failed to load: ' . $key;
}
return parent::lang($key);
}

protected function sendmailSend($header, $body) {
Expand Down
2 changes: 1 addition & 1 deletion lib/composer.json
Expand Up @@ -6,7 +6,7 @@
"require": {
"jelix/fakeserverconf": "1.0.*",
"jelix/composer-module-setup": "0.*",
"phpmailer/phpmailer": "5.2.9",
"phpmailer/phpmailer": "^5.2.18",
"jelix/soap-server-module": "^1.7.5",
"jelix/castor": "1.0.*",
"jelix/feeds-module": "1.7.*",
Expand Down
5 changes: 5 additions & 0 deletions lib/jelix-tests/classes/command.php
Expand Up @@ -48,6 +48,11 @@ public static function main($exit = TRUE)
}


protected function showMessage($message)
{
echo $message;
}

protected function createRunner()
{
if ($this->version36) {
Expand Down
4 changes: 3 additions & 1 deletion testapp/tests-jelix/jelix/utils/jMailerTest.php
Expand Up @@ -26,6 +26,9 @@ class jMailerTest extends PHPUnit_Framework_TestCase {

public function testFileMail() {

if (file_exists(jApp::varPath().'mails/mail.txt')) {
unlink(jApp::varPath() . 'mails/mail.txt');
}
$mail = new testJMailer();

$mail->From = 'toto@truc.local';
Expand All @@ -48,7 +51,6 @@ public function testFileMail() {
$this->assertTrue(strpos($content, 'To: titi@machin.local, toto@machin.local') !== false);
$this->assertTrue(strpos($content, 'From: Super Me <toto@truc.local>') !== false);
$this->assertTrue(strpos($content, 'Subject: Email test') !== false);
$this->assertTrue(strpos($content, 'Content-Transfer-Encoding: 8bit') !== false);
$this->assertTrue(strpos($content, 'Content-Type: text/plain; charset=UTF-8') !== false);
$this->assertTrue(strpos($content, 'This is a test mail') !== false);
}
Expand Down

0 comments on commit 8afadb2

Please sign in to comment.