diff --git a/src/ext/notifications/class.observer.php b/src/ext/notifications/class.observer.php index b1b7f0c..1b0db2a 100644 --- a/src/ext/notifications/class.observer.php +++ b/src/ext/notifications/class.observer.php @@ -48,7 +48,7 @@ class NotificationObserver implements \MTTNotificationObserverInterface private function processDelayed() { - $db = DBConnection::instance(); + //$db = DBConnection::instance(); $useCli = !function_exists('fastcgi_finish_request'); $sender = new Sender( $this->prefs, $useCli ); foreach ($this->delayedNotifications as $item) { diff --git a/src/ext/notifications/class.sender.php b/src/ext/notifications/class.sender.php index cb00a75..b705030 100644 --- a/src/ext/notifications/class.sender.php +++ b/src/ext/notifications/class.sender.php @@ -106,9 +106,20 @@ class Sender private function sendEmails(string $text, string $subject) { - $host = parse_url(get_unsafe_mttinfo('url'), PHP_URL_HOST); - $host = preg_replace('/^(www\.)/', '', $host); - $fromAddr = "mytinytodo@$host"; + $fromAddr = ''; + if (isset($this->prefs['mailfrom']) && $this->prefs['mailfrom'] != '') { + $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"; + } + } $from = "myTinyTodo <$fromAddr>"; $mttTitle = str_replace( ["\r","\n"], '', get_unsafe_mttinfo('title') ); $subject = "[$mttTitle] $subject"; @@ -126,7 +137,7 @@ class Sender $headers[] = 'Content-Transfer-Encoding: 8bit'; } foreach ($this->prefs['emails'] as $email) { - mail($email, $subject, $text, implode("\r\n", $headers), "-f$fromAddr"); + mail($email, $subject, $text, implode("\r\n", $headers)); } } diff --git a/src/ext/notifications/extension.json b/src/ext/notifications/extension.json index 84218dc..71bc31d 100644 --- a/src/ext/notifications/extension.json +++ b/src/ext/notifications/extension.json @@ -1,6 +1,6 @@ { "bundleId": "notifications", "name": "Notifications", - "version": "1.0.3", + "version": "1.1", "description": "Notify about new tasks and lists on e-mail or telegram" } diff --git a/src/ext/notifications/lang/en.json b/src/ext/notifications/lang/en.json index c65c38d..aed93b0 100644 --- a/src/ext/notifications/lang/en.json +++ b/src/ext/notifications/lang/en.json @@ -5,6 +5,8 @@ "notifications.bot_not_configured": "Bot is not configured", "notifications.h_email": "E-Mail:", "notifications.d_email": "Separate multiple addresses with comma.", + "notifications.h_mailfrom": "Mail from:", + "notifications.d_mailfrom": "Use this e-mail as sender's address.", "notifications.h_telegram": "Telegram", "notifications.h_token": "Bot token:", "notifications.d_token": "Telegram Bot API token from @BotFather.", diff --git a/src/ext/notifications/loader.php b/src/ext/notifications/loader.php index 6b293ed..ff75776 100644 --- a/src/ext/notifications/loader.php +++ b/src/ext/notifications/loader.php @@ -73,6 +73,8 @@ class NotificationsExtension extends MTTExtension implements MTTHttpApiExtender, $ext = htmlspecialchars(self::bundleId); $prefs = self::preferences(); $emails = htmlspecialchars( implode(', ', $prefs['emails']) ); + $mailfrom = htmlspecialchars($prefs['mailfrom'] ?? ''); + $mailfromDefault = htmlspecialchars( ini_get('sendmail_from') ?: '' ); $numberOfChats = count($prefs['chats']); $token = $prefs['token'] ?? ''; @@ -117,6 +119,12 @@ $warning
+
+
{$e('notifications.h_mailfrom')} +
{$e('notifications.d_mailfrom')}
+
+
+
{$e('notifications.h_telegram')}
@@ -154,7 +162,8 @@ EOD; } $token = $params['token'] ?? ''; $emails = $params['emails'] ?? ''; - if (!is_string($token) || !is_string($emails)) { + $mailfrom = $params['mailfrom'] ?? ''; + if (!is_string($token) || !is_string($emails) || !is_string($mailfrom)) { throw new Exception("Invalid format"); } @@ -167,6 +176,7 @@ EOD; $prefs['token'] = $token; $prefs['code'] = null; $prefs['emails'] = []; + $prefs['mailfrom'] = str_replace(["\r", "\n", ":", "\"", "'", "?"], '', trim($mailfrom)); // validate emails if ($emails != '') {