Add tests for e-mail actions, and cleanup the new logic a bit.

This commit is contained in:
Vlad Grigorescu 2021-04-26 23:01:34 -05:00
parent 6d0f48abfc
commit ac720a1313
17 changed files with 353 additions and 16 deletions

View file

@ -18,19 +18,28 @@ export {
};
}
# Run before ACTION_PAGE
hook notice(n: Notice::Info) &priority=5
hook notice(n: Notice::Info)
{
if ( |Site::local_admins| > 0 &&
ACTION_EMAIL_ADMIN in n$actions )
{
local email = "";
if ( n?$src && |Site::get_emails(n$src)| > 0 )
email = fmt("%s, %s", email, Site::get_emails(n$src));
email = Site::get_emails(n$src);
if ( n?$dst && |Site::get_emails(n$dst)| > 0 )
email = fmt("%s, %s", email, Site::get_emails(n$dst));
{
if ( email != "" )
email = fmt("%s, %s", email, Site::get_emails(n$dst));
else
email = Site::get_emails(n$dst);
}
if ( email != "" )
n$email_dest = email;
{
if ( ! n?$email_dest )
n$email_dest = set();
add n$email_dest[email];
}
}
}

View file

@ -17,9 +17,13 @@ export {
option mail_page_dest = "";
}
# Runs after EMAIL_ADMIN (assume page supercedes), but before hostnames are added.
hook notice(n: Notice::Info) &priority=4
hook notice(n: Notice::Info)
{
if ( ACTION_PAGE in n$actions )
n$email_dest = mail_page_dest;
{
if ( ! n?$email_dest )
n$email_dest = set();
add n$email_dest[mail_page_dest];
}
}

View file

@ -5,6 +5,7 @@
##! the notice framework can be found in :doc:`/frameworks/notice`.
@load base/frameworks/cluster
@load base/utils/strings
module Notice;
@ -136,8 +137,8 @@ export {
## The actions which have been applied to this notice.
actions: ActionSet &log &default=ActionSet();
## The email address where to send this notice
email_dest: string &log &optional;
## The email address(es) where to send this notice
email_dest: set[string] &log &optional;
## By adding chunks of text into this element, other scripts
## can expand on notices that are being emailed. The normal
@ -513,14 +514,22 @@ hook Notice::policy(n: Notice::Info) &priority=10
add n$actions[ACTION_LOG];
}
hook Notice::notice(n: Notice::Info)
{
if ( ACTION_EMAIL in n$actions )
{
if ( ! n?$email_dest )
n$email_dest = set();
add n$email_dest[mail_dest];
}
}
hook Notice::notice(n: Notice::Info) &priority=-5
{
# Send to requested address if set
if ( n?$email_dest )
email_notice_to(n, n$email_dest, T);
# Otherwise Send to default address
else if ( ACTION_EMAIL in n$actions )
email_notice_to(n, mail_dest, T);
for ( dest in n$email_dest )
email_notice_to(n, dest, T);
if ( ACTION_LOG in n$actions )
Log::write(Notice::LOG, n);