2025-05-06 21:07:38 +02:00
|
|
|
/*
|
|
|
|
This file is part of »munin«.
|
|
|
|
|
|
|
|
Copyright 2025 'Fenris Wolf' <fenris@folksprak.org>
|
|
|
|
|
|
|
|
»munin« is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
»munin« is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with »munin«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
namespace _munin.targets.email
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export type type_parameters = {
|
|
|
|
smtp_host : string;
|
|
|
|
smtp_port : int;
|
|
|
|
smtp_username : string;
|
|
|
|
smtp_password : string;
|
|
|
|
sender : string;
|
|
|
|
receivers : Array<string>;
|
2025-05-18 07:42:04 +02:00
|
|
|
hide_tags : boolean;
|
2025-06-28 06:27:46 +02:00
|
|
|
reminders : Array<_munin.type_reminder>;
|
2025-05-06 21:07:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
async function send(
|
|
|
|
parameters : type_parameters,
|
|
|
|
labels : _munin.type_labels,
|
|
|
|
event : _munin.type_event
|
|
|
|
) : Promise<void>
|
|
|
|
{
|
|
|
|
await lib_plankton.email.send(
|
|
|
|
{
|
|
|
|
"host": parameters.smtp_host,
|
|
|
|
"port": parameters.smtp_port,
|
|
|
|
"username": parameters.smtp_username,
|
|
|
|
"password": parameters.smtp_password,
|
|
|
|
},
|
|
|
|
parameters.sender,
|
|
|
|
parameters.receivers,
|
|
|
|
lib_plankton.string.coin(
|
2025-05-06 22:12:02 +02:00
|
|
|
"[{{head}}] {{date}} : {{macro_tags}}{{title}}",
|
2025-05-06 21:07:38 +02:00
|
|
|
{
|
|
|
|
"head": labels.head,
|
2025-05-13 19:19:51 +02:00
|
|
|
"date": lib_plankton.pit.date_format(
|
|
|
|
event.begin.date
|
|
|
|
),
|
2025-05-06 22:12:02 +02:00
|
|
|
"macro_tags": (
|
|
|
|
(event.tags === null)
|
|
|
|
?
|
|
|
|
""
|
|
|
|
:
|
|
|
|
(event.tags.map(tag => ("{" + tag + "}")).join(" ") + " ")
|
|
|
|
),
|
2025-05-06 21:07:38 +02:00
|
|
|
"title": event.title,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
lib_plankton.string.coin(
|
2025-06-12 07:25:15 +02:00
|
|
|
"{{title_label}} | {{macro_tags}}{{title_value}}\n{{time_label}} | {{time_value}}{{macro_location}}{{macro_description}}",
|
2025-05-06 21:07:38 +02:00
|
|
|
{
|
|
|
|
"title_label": labels.title.toUpperCase(),
|
2025-05-06 22:12:02 +02:00
|
|
|
"macro_tags": (
|
2025-05-18 07:42:04 +02:00
|
|
|
(parameters.hide_tags || (event.tags === null))
|
2025-05-06 22:12:02 +02:00
|
|
|
?
|
|
|
|
""
|
|
|
|
:
|
|
|
|
(event.tags.map(tag => ("{" + tag + "}")).join(" ") + " ")
|
|
|
|
),
|
2025-05-06 21:07:38 +02:00
|
|
|
"title_value": event.title,
|
|
|
|
"time_label": labels.time.toUpperCase(),
|
2025-05-13 19:19:51 +02:00
|
|
|
"time_value": lib_plankton.pit.timespan_format(
|
|
|
|
event.begin,
|
|
|
|
event.end,
|
|
|
|
{
|
|
|
|
"adjust_to_ce": true,
|
|
|
|
}
|
|
|
|
),
|
2025-05-06 21:07:38 +02:00
|
|
|
"macro_location": (
|
|
|
|
(event.location === null)
|
|
|
|
?
|
|
|
|
""
|
|
|
|
:
|
|
|
|
lib_plankton.string.coin(
|
|
|
|
"\n{{location_label}} | {{location_value}}",
|
|
|
|
{
|
|
|
|
"location_label": labels.location.toUpperCase(),
|
|
|
|
"location_value": event.location,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
),
|
2025-06-12 07:25:15 +02:00
|
|
|
"macro_description": (
|
|
|
|
(event.description === null)
|
|
|
|
?
|
|
|
|
""
|
|
|
|
:
|
|
|
|
lib_plankton.string.coin(
|
|
|
|
"\n\n{{description_value}}",
|
|
|
|
{
|
|
|
|
"description_value": event.description,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
),
|
2025-05-06 21:07:38 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export function implementation_target(
|
|
|
|
parameters : type_parameters
|
|
|
|
) : _munin.type_target
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
"reminders": parameters.reminders,
|
|
|
|
"show": () => lib_plankton.string.coin(
|
|
|
|
"email:{{receivers}}",
|
|
|
|
{
|
|
|
|
"receivers": parameters.receivers.join(","),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
"send": (labels, event) => send(parameters, labels, event),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|