diff options
author | Christian Hesse <mail@eworm.de> | 2021-03-03 10:42:14 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-03-03 14:54:22 +0100 |
commit | e65802007fc95613d9b2e0dbe68dd55c70f97fd1 (patch) | |
tree | 6320682a2d917a82514738f5dd48ca0911ecd945 /global-functions | |
parent | 7829a6c33adfc0391a88d05e070d3c30397b4444 (diff) |
global-functions: introduce and use $QuotedPrintable
Some mail clients do not like unencoded utf-8 in subject... Let's
encode in quoted-printable to fix.
Diffstat (limited to 'global-functions')
-rw-r--r-- | global-functions | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/global-functions b/global-functions index 382722a..177cd4f 100644 --- a/global-functions +++ b/global-functions @@ -35,6 +35,7 @@ :global LogPrintExit2; :global MkDir; :global ParseKeyValueStore; +:global QuotedPrintable; :global RandomDelay; :global RequiredRouterOS; :global ScriptFromTerminal; @@ -550,6 +551,42 @@ :return $Result; } +# convert string to quoted-printable +:global QuotedPrintable do={ + :local Input [ :tostr $1 ]; + + :if ([ :len $Input ] = 0) do={ + :return $Input; + } + + :local Return ""; + :local Chars ("\80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\90\91\92\93\94\95\96\97" . \ + "\98\99\9A\9B\9C\9D\9E\9F\A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\B0\B1\B2\B3" . \ + "\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF" . \ + "\D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB" . \ + "\EC\ED\EE\EF\F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"); + :local Hex { "0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9"; "A"; "B"; "C"; "D"; "E"; "F" }; + + :for I from=0 to=([ :len $Input ] - 1) do={ + :local Char [ :pick $Input $I ]; + :local Replace [ :find $Chars $Char ]; + + :if ($Char = "=") do={ + :set Char "=3D"; + } + :if ([ :typeof $Replace ] = "num") do={ + :set Char ("=" . ($Hex->($Replace / 16 + 8)) . ($Hex->($Replace % 16))); + } + :set Return ($Return . $Char); + } + + :if ($Input = $Return) do={ + :return $Input; + } + + :return ("=\?utf-8\?Q\?" . $Return . "\?="); +} + # delay a random amount of seconds :set RandomDelay do={ :global GetRandomNumber; @@ -806,8 +843,9 @@ :global EmailGeneralCc; :global EmailQueue; - :global LogPrintExit2; :global IfThenElse; + :global LogPrintExit2; + :global QuotedPrintable; :if ([ :len $EmailGeneralTo ] = 0) do={ :return false; @@ -818,7 +856,8 @@ } :local Signature [ / system note get note ]; :set ($EmailQueue->[ :len $EmailQueue ]) { - to=$EmailGeneralTo; cc=$EmailGeneralCc; subject=("[" . $Identity . "] " . $Subject); + to=$EmailGeneralTo; cc=$EmailGeneralCc; + subject=[ $QuotedPrintable ("[" . $Identity . "] " . $Subject) ]; body=($Message . \ [ $IfThenElse ([ :len $Link ] > 0) ("\n\n" . $Link) "" ] . \ [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]) }; |