From 8c74e3cbd737146b22d7c59f23669e9e0017e91d Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Sat, 19 Aug 2023 18:47:18 +0300 Subject: [PATCH] little update of notifications extension --- src/ext/notifications/class.sender.php | 20 ++++++++++++-------- src/ext/notifications/lang/ru.json | 2 ++ src/ext/notifications/loader.php | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ext/notifications/class.sender.php b/src/ext/notifications/class.sender.php index b705030..74358c8 100644 --- a/src/ext/notifications/class.sender.php +++ b/src/ext/notifications/class.sender.php @@ -111,14 +111,7 @@ class Sender $fromAddr = str_replace( ["\r", "\n", ":", "\"", "'", "?"], '', $this->prefs['mailfrom']); } else { - $host = parse_url(get_unsafe_mttinfo('url'), PHP_URL_HOST); - $host = preg_replace('/^(www\.)/', '', $host); - if (function_exists('posix_getuid') && false !== ($userinfo = posix_getpwuid(posix_getuid())) ) { - $fromAddr = $userinfo['name']. '@'. $host; - } - else { - $fromAddr = "mytinytodo@$host"; - } + $fromAddr = self::suggestedMailFrom(); } $from = "myTinyTodo <$fromAddr>"; $mttTitle = str_replace( ["\r","\n"], '', get_unsafe_mttinfo('title') ); @@ -195,4 +188,15 @@ class Sender fclose($fh); } + public static function suggestedMailFrom(): string + { + $host = parse_url(get_unsafe_mttinfo('url'), PHP_URL_HOST); + $host = preg_replace('/^(www\.)/', '', $host); + //$host = gethostname(); + if (function_exists('posix_getuid') && false !== ($userinfo = posix_getpwuid(posix_getuid())) ) { + return $userinfo['name']. '@'. $host; + } + return "mytinytodo@$host"; + } + } diff --git a/src/ext/notifications/lang/ru.json b/src/ext/notifications/lang/ru.json index c35924f..5944e2c 100644 --- a/src/ext/notifications/lang/ru.json +++ b/src/ext/notifications/lang/ru.json @@ -5,6 +5,8 @@ "notifications.bot_not_configured": "Бот не настроен", "notifications.h_email": "E-Mail:", "notifications.d_email": "Разделите несколько адресов c помощью запятой.", + "notifications.h_mailfrom": "Адрес отправителя:", + "notifications.d_mailfrom": "Этот адрес будет указан как адрес отправителя в письмах с уведомлениями.", "notifications.h_telegram": "Telegram", "notifications.h_token": "Токен для бота:", "notifications.d_token": "Токен для телеграм-бота, полученный от @BotFather.", diff --git a/src/ext/notifications/loader.php b/src/ext/notifications/loader.php index ff75776..8c430c9 100644 --- a/src/ext/notifications/loader.php +++ b/src/ext/notifications/loader.php @@ -74,7 +74,7 @@ class NotificationsExtension extends MTTExtension implements MTTHttpApiExtender, $prefs = self::preferences(); $emails = htmlspecialchars( implode(', ', $prefs['emails']) ); $mailfrom = htmlspecialchars($prefs['mailfrom'] ?? ''); - $mailfromDefault = htmlspecialchars( ini_get('sendmail_from') ?: '' ); + $mailfromDefault = htmlspecialchars(Notify\Sender::suggestedMailFrom()); $numberOfChats = count($prefs['chats']); $token = $prefs['token'] ?? '';