mod/notification-email: properly truncate the body

Truned out that the size limit for e-mail message/body is anywhere just
below 64kB... So truncate  at about 62.000 bytes.
This commit is contained in:
Christian Hesse 2025-05-08 13:29:01 +02:00
parent ff218e4ce5
commit 74dc809b98

View file

@ -181,6 +181,7 @@
:global IfThenElse; :global IfThenElse;
:global NotificationEMailSignature; :global NotificationEMailSignature;
:global NotificationEMailSubject; :global NotificationEMailSubject;
:global SymbolForNotification;
:local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ]; :local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ];
:local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ]; :local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ];
@ -193,13 +194,22 @@
:if ([ :typeof $EmailQueue ] = "nothing") do={ :if ([ :typeof $EmailQueue ] = "nothing") do={
:set EmailQueue ({}); :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 ] ]; :local Signature [ $EitherOr [ $NotificationEMailSignature ] [ /system/note/get note ] ];
:set Body ($Body . "\n" . \
[ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n" . ($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 ]) { :set ($EmailQueue->[ :len $EmailQueue ]) {
to=$To; cc=$Cc; to=$To; cc=$Cc;
subject=[ $NotificationEMailSubject ($Notification->"subject") ]; subject=[ $NotificationEMailSubject ($Notification->"subject") ];
body=(($Notification->"message") . \ body=$Body; \
[ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \
[ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]); \
attach=($Notification->"attach"); remove-attach=($Notification->"remove-attach") }; attach=($Notification->"attach"); remove-attach=($Notification->"remove-attach") };
:if ([ :len [ /system/scheduler/find where name="_FlushEmailQueue" ] ] = 0) do={ :if ([ :len [ /system/scheduler/find where name="_FlushEmailQueue" ] ] = 0) do={
/system/scheduler/add name="_FlushEmailQueue" interval=1s start-time=startup \ /system/scheduler/add name="_FlushEmailQueue" interval=1s start-time=startup \