aboutsummaryrefslogtreecommitdiffstats
path: root/mod/notification-email.rsc
diff options
context:
space:
mode:
Diffstat (limited to 'mod/notification-email.rsc')
-rw-r--r--mod/notification-email.rsc86
1 files changed, 52 insertions, 34 deletions
diff --git a/mod/notification-email.rsc b/mod/notification-email.rsc
index 7b89d98..ad9762a 100644
--- a/mod/notification-email.rsc
+++ b/mod/notification-email.rsc
@@ -35,14 +35,16 @@
}
# flush e-mail queue
-:set FlushEmailQueue do={ :do {
+:set FlushEmailQueue do={ :onerror Err {
:global EmailQueue;
:global EitherOr;
:global EMailGenerateFrom;
+ :global FileExists;
:global IsDNSResolving;
:global IsTimeSync;
:global LogPrint;
+ :global RmFile;
:local AllDone true;
:local QueueLen [ :len $EmailQueue ];
@@ -89,35 +91,40 @@
:foreach Id,Message in=$EmailQueue do={
:if ([ :typeof $Message ] = "array" ) do={
- :local Attach ({});
:while ([ /tool/e-mail/get last-status ] = "in-progress") do={ :delay 1s; }
- :foreach File in=[ :toarray [ $EitherOr ($Message->"attach") "" ] ] do={
- :if ([ :len [ /file/find where name=$File ] ] = 1) do={
- :set Attach ($Attach, $File);
- } else={
- $LogPrint warning $0 ("File '" . $File . "' does not exist, can not attach.");
+ :onerror Err {
+ :local Attach ({});
+ :foreach File in=[ :toarray [ $EitherOr ($Message->"attach") "" ] ] do={
+ :if ([ $FileExists $File ] = true) do={
+ :set Attach ($Attach, $File);
+ } else={
+ $LogPrint warning $0 ("File '" . $File . "' does not exist, can not attach.");
+ }
}
- }
- /tool/e-mail/send from=[ $EMailGenerateFrom ] to=($Message->"to") cc=($Message->"cc") \
- subject=($Message->"subject") body=($Message->"body") file=$Attach;
- :local Wait true;
- :do {
- :delay 1s;
- :local Status [ /tool/e-mail/get last-status ];
- :if ($Status = "succeeded") do={
- :set ($EmailQueue->$Id);
- :set Wait false;
- :if (($Message->"remove-attach") = true) do={
- :foreach File in=$Attach do={
- /file/remove $File;
+ /tool/e-mail/send from=[ $EMailGenerateFrom ] to=($Message->"to") cc=($Message->"cc") \
+ subject=($Message->"subject") body=($Message->"body") file=$Attach;
+ :local Wait true;
+ :do {
+ :delay 1s;
+ :local Status [ /tool/e-mail/get last-status ];
+ :if ($Status = "succeeded") do={
+ :set ($EmailQueue->$Id);
+ :set Wait false;
+ :if (($Message->"remove-attach") = true) do={
+ :foreach File in=$Attach do={
+ $RmFile $File;
+ }
}
}
- }
- :if ($Status = "failed") do={
- :set AllDone false;
- :set Wait false;
- }
- } while=($Wait = true);
+ :if ($Status = "failed") do={
+ :set AllDone false;
+ :set Wait false;
+ }
+ } while=($Wait = true);
+ } do={
+ $LogPrint warning $0 ("Sending queued mail failed: " . $Err);
+ :set AllDone false;
+ }
}
}
@@ -135,8 +142,8 @@
/system/scheduler/set interval=(($SchedVal->"run-count") . "m") \
comment="Waiting for retry..." $Scheduler;
-} on-error={
- :global ExitError; $ExitError false $0;
+} do={
+ :global ExitError; $ExitError false $0 $Err;
} }
# generate filter for log-forward
@@ -176,6 +183,7 @@
:global IfThenElse;
:global NotificationEMailSignature;
:global NotificationEMailSubject;
+ :global SymbolForNotification;
:local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ];
:local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ];
@@ -188,13 +196,23 @@
:if ([ :typeof $EmailQueue ] = "nothing") do={
:set EmailQueue ({});
}
+ :local Truncated false;
+ :local Body ($Notification->"message");
+ :if ([ :len $Body ] > 62000) do={
+ :set Body ([ :pick $Body 0 62000 ] . "...");
+ :set Truncated true;
+ }
:local Signature [ $EitherOr [ $NotificationEMailSignature ] [ /system/note/get note ] ];
+ :set Body ($Body . "\n" . \
+ [ $IfThenElse ([ :len ($Notification->"link") ] > 0) \
+ ("\n" . [ $SymbolForNotification "link" ] . ($Notification->"link")) ] . \
+ [ $IfThenElse ($Truncated = true) ("\n" . [ $SymbolForNotification "scissors" ] . \
+ "The message was too long and has been truncated!") ] . \
+ [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]);
:set ($EmailQueue->[ :len $EmailQueue ]) {
to=$To; cc=$Cc;
subject=[ $NotificationEMailSubject ($Notification->"subject") ];
- body=(($Notification->"message") . \
- [ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \
- [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]); \
+ body=$Body; \
attach=($Notification->"attach"); remove-attach=($Notification->"remove-attach") };
:if ([ :len [ /system/scheduler/find where name="_FlushEmailQueue" ] ] = 0) do={
/system/scheduler/add name="_FlushEmailQueue" interval=1s start-time=startup \
@@ -248,12 +266,12 @@
}
# send notification via e-mail - expects at least two string arguments
-:set SendEMail do={ :do {
+:set SendEMail do={ :onerror Err {
:global SendEMail2;
$SendEMail2 ({ origin=$0; subject=$1; message=$2; link=$3 });
-} on-error={
- :global ExitError; $ExitError false $0;
+} do={
+ :global ExitError; $ExitError false $0 $Err;
} }
# send notification via e-mail - expects one array argument