misc(emailer): Use constants for email types (#1794)

This commit is contained in:
Roman Kelesidis 2025-02-04 20:47:44 +03:00 committed by GitHub
commit c95d414ef6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 10 deletions

View file

@ -309,6 +309,9 @@ define('HTML_DISABLED', ' disabled ');
define('HTML_READONLY', ' readonly ');
define('HTML_SELECTED', ' selected ');
define('EMAIL_TYPE_HTML', 'text/html');
define('EMAIL_TYPE_TEXT', 'text/plain');
// $GPC
define('KEY_NAME', 0); // position in $GPC['xxx']
define('DEF_VAL', 1);

View file

@ -9,6 +9,8 @@
namespace TorrentPier;
use Exception;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport\SendmailTransport;
@ -119,6 +121,7 @@ class Emailer
* @param string $email_format
*
* @return bool
* @throws Exception
*/
public function send(string $email_format = 'text/plain'): bool
{
@ -176,10 +179,15 @@ class Emailer
$message->getHeaders()
->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply');
if ($email_format == 'text/html') {
$message->html($this->message);
} else {
$message->text($this->message);
switch ($email_format) {
case EMAIL_TYPE_HTML:
$message->html($this->message);
break;
case EMAIL_TYPE_TEXT:
$message->text($this->message);
break;
default:
throw new Exception('Unknown email format: ' . $email_format);
}
/** Send message */

View file

@ -50,6 +50,9 @@ class IndexNow
'naver' => 'searchadvisor.naver.com'
];
/**
* IndexNow constructor
*/
public function __construct()
{
global $bb_cfg;

View file

@ -130,14 +130,14 @@ class Updater
}
/**
* Returns information of latest TorrentPier version
* Returns information of latest TorrentPier version available
*
* @param bool $allowRC
* @param bool $allowPreReleases
* @return array
*/
public function getLastVersion(bool $allowRC = true): array
public function getLastVersion(bool $allowPreReleases = true): array
{
if (!$allowRC) {
if (!$allowPreReleases) {
foreach ($this->jsonResponse as $index) {
if (isset($index['prerelease']) && $index['prerelease']) {
continue;

View file

@ -16,8 +16,8 @@
<td class="row1 tRight"><b>{L_MASS_EMAIL_MESSAGE_TYPE}</b></td>
<td class="row2">
<select name="message_type">
<option value="text/plain" selected>text/plain</option>
<option value="text/html">text/html</option>
<option value="{#EMAIL_TYPE_TEXT#}" selected>{#EMAIL_TYPE_TEXT#}</option>
<option value="{#EMAIL_TYPE_HTML#}">{#EMAIL_TYPE_HTML#}</option>
</select>
</td>
</tr>