1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Fixes #5498 CC emails are now added correctly. DKIM identity corrected. Core prefs are no longer stored in the instance.

This commit is contained in:
camer0n
2025-05-14 05:50:23 -07:00
parent 5ada15f720
commit 5e933e8fec
2 changed files with 100 additions and 75 deletions

View File

@@ -168,7 +168,7 @@ class e107Email extends PHPMailer
public $legacyBody = false; // true enables legacy conversion of plain text body to HTML in HTML emails
private $debug = false; // echos various debug info when set to true.
private $pref = array(); // Store code prefs.
private $previewMode = false;
private $previewAttachments = array();
private $overrides = array(
@@ -218,7 +218,6 @@ class e107Email extends PHPMailer
$this->Debugoutput = 'handlePHPMailerDebug';
}
$this->pref = $pref;
$this->CharSet = 'utf-8';
$this->setLanguage(CORE_LC);
@@ -356,7 +355,7 @@ class e107Email extends PHPMailer
$this->DKIM_private = $privatekeyfile;
$this->DKIM_selector = 'phpmailer';
$this->DKIM_passphrase = ''; //key is not encrypted
$this->DKIM_identifier = $this->From;
$this->DKIM_identity = $this->From;
}
@@ -513,86 +512,82 @@ class e107Email extends PHPMailer
* If the name field for an entry is blank, or there are not enough entries, the address is substituted
* @return bool true if list accepted, false if invalid list name
*/
public function AddAddressList($list = 'to',$addresses='',$names = '')
public function AddAddressList($list = 'to', $addresses = '', $names = '')
{
$list = trim(strtolower($list));
$tmp = explode(',',$addresses);
if (strpos($names,',') === false)
$list = trim(strtolower($list));
$tmp = explode(',', $addresses);
if(strpos($names, ',') === false)
{
$names = array_fill(0,count($tmp),$names); // Same value for all addresses
$names = array_fill(0, count($tmp), $names); // Same value for all addresses
}
else
{
$names = explode(',',$names);
$names = explode(',', $names);
}
foreach($tmp as $k => $adr)
{
$to_name = ($names[$k]) ? $names[$k] : $adr;
switch ($list)
switch($list)
{
case 'to' :
try
{
$this->addAddress($adr, $to_name);
}
catch (Exception $e)
catch(Exception $e)
{
$this->logLine($e->getMessage());
}
break;
case 'replyto' :
try
{
$this->addReplyTo($adr, $to_name);
}
catch (Exception $e)
catch(Exception $e)
{
$this->logLine($e->getMessage());
}
break;
case 'cc' :
if($this->Mailer == 'mail')
{
$this->addCustomHeader('Cc: '.$adr);
}
else
{
try
{
$this->addCC($adr, $to_name);
}
catch (Exception $e)
{
$this->logLine($e->getMessage());
}
try
{
$this->addCC($adr, $to_name);
}
catch(Exception $e)
{
$this->logLine($e->getMessage());
}
break;
case 'bcc' :
if($this->Mailer == 'mail')
{
$this->addCustomHeader('Bcc: '.$adr);
}
else
{
try
{
$this->addBCC($adr, $to_name);
}
catch (Exception $e)
{
$this->logLine($e->getMessage());
}
try
{
$this->addBCC($adr, $to_name);
}
catch(Exception $e)
{
$this->logLine($e->getMessage());
}
break;
default :
return false;
}
}
return true;
}
@@ -842,9 +837,12 @@ class e107Email extends PHPMailer
$eml['shortcodes']['BODY'] = !empty($eml['body']) ? $tp->toEmail($eml['body']) : '';
}
*/
$siteTheme = e107::getConfig()->get('site_theme');
$eml['shortcodes']['BODY'] = !empty($eml['body']) ? $eml['body'] : ''; // $tp->toEmail($eml['body']) : '';
$eml['shortcodes']['SUBJECT'] = !empty($eml['subject']) ? $eml['subject'] : '';
$eml['shortcodes']['THEME'] = ($this->previewMode == true) ? e_THEME_ABS.$this->pref['sitetheme'].'/' : e_THEME.$this->pref['sitetheme'].'/'; // Always use front-end theme path.
$eml['shortcodes']['THEME'] = ($this->previewMode) ? e_THEME_ABS.$siteTheme.'/' : e_THEME.$siteTheme.'/'; // Always use front-end theme path.

View File

@@ -24,7 +24,7 @@
}
catch(Exception $e)
{
$this->fail("Couldn't load e107Email object");
$this::fail("Couldn't load e107Email object");
}
@@ -60,12 +60,39 @@
$this->eml->arraySet($eml);
$this->assertStringContainsString("noreply@test.com", $this->eml->From);
$this->assertStringContainsString("Test Person", $this->eml->FromName);
$this->assertStringContainsString("e107: [URGENT EXAMPLE] ", $this->eml->Subject);
$this->assertStringContainsString("This is the body text", $this->eml->Body);
$this->assertStringContainsString("<h4 class='sitename'><a href='", $this->eml->Body);
$this->assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
$this::assertStringContainsString("noreply@test.com", $this->eml->From);
$this::assertStringContainsString("Test Person", $this->eml->FromName);
$this::assertStringContainsString("e107: [URGENT EXAMPLE] ", $this->eml->Subject);
$this::assertStringContainsString("This is the body text", $this->eml->Body);
$this::assertStringContainsString("<h4 class='sitename'><a href='", $this->eml->Body);
$this::assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
}
public function testArraySetCC()
{
$eml = array(
'subject' => "[CC EXAMPLE]",
'sender_email' => "noreply@test.com",
'sender_name' => "Test Person",
'replyto' => "",
'html' => true,
'priority' => 1,
'template' => 'default',
'body' => "This is the body text",
'cc' => 'email1@example.com,email2@example.com,email3@example.com'
);
$this->eml->Mailer = 'mail';
$this->eml->arraySet($eml);
$result = $this->eml->getCcAddresses();
$this::assertIsArray($result);
$this::assertNotEmpty($result, 'CC Array is empty' );;
$this::assertEquals('email1@example.com', $result[0][0]);
$this::assertEquals('email2@example.com', $result[1][0]);
$this::assertEquals('email3@example.com', $result[2][0]);
}
/**
@@ -92,14 +119,14 @@
$this->eml->arraySet($eml);
$this->assertStringContainsString("noreply@test.com", $this->eml->From);
$this->assertStringContainsString("Test Person", $this->eml->FromName);
$this->assertStringContainsString("[CUSTOM TEMPLATE EXAMPLE]", $this->eml->Subject);
$this::assertStringContainsString("noreply@test.com", $this->eml->From);
$this::assertStringContainsString("Test Person", $this->eml->FromName);
$this::assertStringContainsString("[CUSTOM TEMPLATE EXAMPLE]", $this->eml->Subject);
$this->assertStringContainsString('<html lang="en"><body>', $this->eml->Body);
$this::assertStringContainsString('<html lang="en"><body>', $this->eml->Body);
$this->assertStringContainsString('<div><span>TestName</span> <small>Jan 1st, 2020</small></div><div>This is the body text</div>', $this->eml->Body);
$this->assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
$this::assertStringContainsString('<div><span>TestName</span> <small>Jan 1st, 2020</small></div><div>This is the body text</div>', $this->eml->Body);
$this::assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
}
@@ -127,14 +154,14 @@
$this->eml->arraySet($eml);
$this->assertStringContainsString("noreply@test.com", $this->eml->From);
$this->assertStringContainsString("Test Person", $this->eml->FromName);
$this->assertStringContainsString("[PLUGIN TEMPLATE EXAMPLE]", $this->eml->Subject);
$this::assertStringContainsString("noreply@test.com", $this->eml->From);
$this::assertStringContainsString("Test Person", $this->eml->FromName);
$this::assertStringContainsString("[PLUGIN TEMPLATE EXAMPLE]", $this->eml->Subject);
$this->assertStringContainsString('<html lang="en"><body>', $this->eml->Body);
$this::assertStringContainsString('<html lang="en"><body>', $this->eml->Body);
$this->assertStringContainsString('<div><span>TestName</span> <small>Jan 1st, 2020</small></div><div>This is the body text</div>', $this->eml->Body);
$this->assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
$this::assertStringContainsString('<div><span>TestName</span> <small>Jan 1st, 2020</small></div><div>This is the body text</div>', $this->eml->Body);
$this::assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
}
@@ -156,12 +183,12 @@
$this->eml->arraySet($eml);
$this->assertStringContainsString("noreply@test.com", $this->eml->From);
$this->assertStringContainsString("Test Person", $this->eml->FromName);
$this->assertStringContainsString("e107: [URGENT EXAMPLE] ", $this->eml->Subject);
$this->assertStringContainsString("This is the body text", $this->eml->Body);
$this->assertStringContainsString("<div class='unsubscribe'></div>", $this->eml->Body);
$this->assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
$this::assertStringContainsString("noreply@test.com", $this->eml->From);
$this::assertStringContainsString("Test Person", $this->eml->FromName);
$this::assertStringContainsString("e107: [URGENT EXAMPLE] ", $this->eml->Subject);
$this::assertStringContainsString("This is the body text", $this->eml->Body);
$this::assertStringContainsString("<div class='unsubscribe'></div>", $this->eml->Body);
$this::assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
}
/*
public function testMakePrintableAddress()
@@ -198,7 +225,7 @@ Admin<br />
$result = json_encode($this->eml->AltBody);
$expected = '"Hi Joe\r\nCheck out https:\/\/e107.org\r\n\r\nThanks,\r\nAdmin\r\n\r\nWebsite:\thttps:\/\/e107.org\t\r\nGithub:\thttps:\/\/github.com\/e107inc\/"';
$this->assertSame($expected, $result);
$this::assertSame($expected, $result);
}
/*
@@ -268,11 +295,11 @@ Admin<br />
$result = $this->eml->getSentMIMEMessage();
$this->assertStringContainsString('Content-Type: text/plain;', $result);
$this->assertStringContainsString('This is the body text', $result);
$this::assertStringContainsString('Content-Type: text/plain;', $result);
$this::assertStringContainsString('This is the body text', $result);
$this->assertStringContainsString('Content-Type: text/html;', $result);
$this->assertStringContainsString('Hi,<br />This is the <b>body</b> text', $result);
$this::assertStringContainsString('Content-Type: text/html;', $result);
$this::assertStringContainsString('Hi,<br />This is the <b>body</b> text', $result);
}
@@ -287,8 +314,8 @@ Admin<br />
$randomString1 = uniqid();
$randomString2 = uniqid();
$this->assertFalse($this->fileContainsString($logFilePath, $randomString1));
$this->assertFalse($this->fileContainsString($logFilePath, $randomString2));
$this::assertFalse($this->fileContainsString($logFilePath, $randomString1));
$this::assertFalse($this->fileContainsString($logFilePath, $randomString2));
$eml = $this->make('e107Email', ['send' => function() { return true; }]);
$eml->logEnable(2);
@@ -297,13 +324,13 @@ Admin<br />
"$randomString1 Example",
['body' => 'Message body'],
);
$this->assertTrue($this->fileContainsString($logFilePath, $randomString1));
$this::assertTrue($this->fileContainsString($logFilePath, $randomString1));
$eml->sendEmail(
'nobody2@example.com',
"$randomString2 Example",
['body' => 'Message body'],
);
$this->assertTrue($this->fileContainsString($logFilePath, $randomString2));
$this::assertTrue($this->fileContainsString($logFilePath, $randomString2));
}
/**