mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
* can set mail from in notifications extension
This commit is contained in:
parent
c42143a17d
commit
a6bde46cc3
5 changed files with 30 additions and 7 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.",
|
||||
|
|
|
|||
|
|
@ -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
|
|||
</div>
|
||||
<div class="td"> <input name="emails" value="$emails" class="in350" autocomplete="off" /> </div>
|
||||
</div>
|
||||
<div class="tr">
|
||||
<div class="th"> {$e('notifications.h_mailfrom')}
|
||||
<div class="descr">{$e('notifications.d_mailfrom')}</div>
|
||||
</div>
|
||||
<div class="td"> <input name="mailfrom" value="$mailfrom" class="in350" autocomplete="email" placeholder="$mailfromDefault" /> </div>
|
||||
</div>
|
||||
<div class="tr">
|
||||
<div class="th"> {$e('notifications.h_telegram')} </div>
|
||||
</div>
|
||||
|
|
@ -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 != '') {
|
||||
|
|
|
|||
Loading…
Reference in a new issue